diff --git a/.editorconfig b/.editorconfig index 9b7352176a..46c1eafce3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000000..a063d1ee1d --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,104 @@ +name: Default +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@master + - name: Install Dependencies + run: npm ci + - name: Build + run: npm run build + - name: Archive Production Artifact + uses: actions/upload-artifact@master + with: + name: build + path: build + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@master + - name: Install Dependencies + run: npm ci + - name: Test + run: npm run test.coverage + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@master + - name: Install Dependencies + run: npm ci + - name: Lint + run: npm run lint + prettier: + name: Prettier + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@master + - name: Install Dependencies + run: npm ci + - name: Prettier + run: npm run style + demos: + name: Run Demos + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@master + - name: Install Dependencies + run: npm ci + - name: Download Artifact + uses: actions/download-artifact@master + with: + name: build + path: build + - name: Run demos + run: | + npm run ts-node -- ./demo/1-basic.ts + npm run ts-node -- ./demo/2-declaritive-styles.ts + npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts + npm run ts-node -- ./demo/4-basic-table.ts + npm run ts-node -- ./demo/5-images.ts + npm run ts-node -- ./demo/6-page-borders.ts + npm run ts-node -- ./demo/7-landscape.ts + npm run ts-node -- ./demo/8-header-footer.ts + npm run ts-node -- ./demo/9-images-in-header-and-footer.ts + npm run ts-node -- ./demo/10-my-cv.ts + npm run ts-node -- ./demo/11-declaritive-styles-2.ts + npm run ts-node -- ./demo/12-scaling-images.ts + npm run ts-node -- ./demo/13-xml-styles.ts + npm run ts-node -- ./demo/14-page-numbers.ts + npm run ts-node -- ./demo/15-page-break-before.ts + npm run ts-node -- ./demo/16-multiple-sections.ts + npm run ts-node -- ./demo/17-footnotes.ts + npm run ts-node -- ./demo/18-image-from-buffer.ts + npm run ts-node -- ./demo/19-export-to-base64.ts + npm run ts-node -- ./demo/20-table-cell-borders.ts + npm run ts-node -- ./demo/21-bookmarks.ts + npm run ts-node -- ./demo/22-right-to-left-text.ts + npm run ts-node -- ./demo/23-base64-images.ts + npm run ts-node -- ./demo/24-images-to-table-cell.ts + npm run ts-node -- ./demo/26-paragraph-borders.ts + npm run ts-node -- ./demo/27-declaritive-styles-3.ts + npm run ts-node -- ./demo/28-table-of-contents.ts + npm run ts-node -- ./demo/29-numbered-lists.ts + npm run ts-node -- ./demo/30-template-document.ts + npm run ts-node -- ./demo/31-tables.ts + npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts + npm run ts-node -- ./demo/33-sequential-captions.ts + npm run ts-node -- ./demo/34-floating-tables.ts diff --git a/.nvmrc b/.nvmrc index 469d080845..e338b86593 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v8 \ No newline at end of file +v10 diff --git a/.nycrc b/.nycrc index 41a461385e..3a897e4c79 100644 --- a/.nycrc +++ b/.nycrc @@ -1,14 +1,15 @@ { "check-coverage": true, - "lines": 93.53, - "functions": 89.63, - "branches": 88.57, - "statements": 93.34, + "lines": 97.77, + "functions": 93.89, + "branches": 94.83, + "statements": 97.75, "include": [ "src/**/*.ts" ], "exclude": [ - "src/**/*.spec.ts" + "src/**/*.spec.ts", + "src/import-dotx/import-dotx.ts" ], "reporter": [ "lcov", diff --git a/.travis.yml b/.travis.yml index 3bf1b47690..3d4166c482 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 9 + - 10 install: - npm install - npm install -g codecov @@ -10,7 +10,7 @@ script: - npm run style - npm run build - npm run ts-node -- ./demo/1-basic.ts - - npm run e2e "My Document.docx" +# - npm run e2e "My Document.docx" - npm run ts-node -- ./demo/2-declaritive-styles.ts - npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts - npm run ts-node -- ./demo/4-basic-table.ts @@ -20,7 +20,7 @@ script: - npm run ts-node -- ./demo/8-header-footer.ts - npm run ts-node -- ./demo/9-images-in-header-and-footer.ts - npm run ts-node -- ./demo/10-my-cv.ts - - npm run e2e "My Document.docx" +# - npm run e2e "My Document.docx" - npm run ts-node -- ./demo/11-declaritive-styles-2.ts - npm run ts-node -- ./demo/12-scaling-images.ts - npm run ts-node -- ./demo/13-xml-styles.ts diff --git a/README.md b/README.md index 3a421f93f4..1df764e12c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ [![NPM version][npm-image]][npm-url] [![Downloads per month][downloads-image]][downloads-url] [![Build Status][travis-image]][travis-url] +[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Known Vulnerabilities][snky-image]][snky-url] [![Chat on Gitter][gitter-image]][gitter-url] @@ -27,13 +28,22 @@ Here are examples of `docx` being used with basic `HTML/JS` in a browser environment: -* https://codepen.io/anon/pen/dqoVgQ -* https://jsfiddle.net/3xhezb5w/2 +* https://codepen.io/dolanmiu/pen/RwNeObg +* https://jsfiddle.net/dolanmiu/kqxrj35u/1/ Here is an example of `docx` working in `Angular`: * https://stackblitz.com/edit/angular-afvxtz +Here is an example of `docx` working in `React`: + +* https://stackblitz.com/edit/react-ts-qq25sp +* https://stackblitz.com/edit/react-ts-qdqu7z (adding images to Word Document) + +Here is an example of `docx` working in `Vue.js`: + +* https://stackblitz.com/edit/vuejs-docx + ## Node Press `endpoint` on the `RunKit` website: @@ -50,7 +60,7 @@ Press `endpoint` on the `RunKit` website: * https://runkit.com/dolanmiu/docx-demo8 - Header and Footer * https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx** -More [here](https://docx.js.org/#/examples) and [here](https://github.com/dolanmiu/docx/tree/master/demo) +More [here](https://github.com/dolanmiu/docx/tree/master/demo) # How to use & Documentation @@ -58,7 +68,7 @@ Please refer to the [documentation at https://docx.js.org/](https://docx.js.org/ # Examples -Check the `examples` section in the [documentation](https://docx.js.org/#/examples) and the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples. +Check the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples. # Contributing @@ -74,7 +84,11 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide [drawing](https://turbopatent.com/) [drawing](http://www.madisoncres.com/) [drawing](https://www.beekast.com/) -[drawing](https://herraizsoto.com/) +[drawing](https://herraizsoto.com/) +[drawing](http://www.ativer.com.br/) +[drawing](https://www.arity.co/) +[drawing](https://www.circadianrisk.com/) + ...and many more! @@ -91,6 +105,8 @@ Made with ๐Ÿ’– [downloads-url]: https://npmjs.org/package/docx [travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master [travis-url]: https://travis-ci.org/dolanmiu/docx +[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg +[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions [daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io [daviddm-url]: https://david-dm.org/dolanmiu/docx [snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg diff --git a/demo/10-my-cv.ts b/demo/10-my-cv.ts index b91ca318bb..484a9c249c 100644 --- a/demo/10-my-cv.ts +++ b/demo/10-my-cv.ts @@ -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, + }), ], }); } diff --git a/demo/11-declaritive-styles-2.ts b/demo/11-declaritive-styles-2.ts index 3a0154a0fb..2f4ed78098 100644 --- a/demo/11-declaritive-styles-2.ts +++ b/demo/11-declaritive-styles-2.ts @@ -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, - }, ], }, }); diff --git a/demo/2-declaritive-styles.ts b/demo/2-declaritive-styles.ts index 472b916091..deada8198a 100644 --- a/demo/2-declaritive-styles.ts +++ b/demo/2-declaritive-styles.ts @@ -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, }, @@ -161,11 +162,26 @@ doc.addSection({ text: "and then underlined ", underline: {}, }), + new TextRun({ + text: "and then emphasis-mark ", + emphasisMark: {}, + }), new TextRun({ text: "and back to normal.", }), ], }), + new Paragraph({ + style: "Strong", + children: [ + new TextRun({ + text: "Strong Style", + }), + new TextRun({ + text: " - Very strong.", + }), + ], + }), ], }); diff --git a/demo/21-bookmarks.ts b/demo/21-bookmarks.ts index 689ff30ae4..b004f48690 100644 --- a/demo/21-bookmarks.ts +++ b/demo/21-bookmarks.ts @@ -1,7 +1,7 @@ // This demo shows how to create bookmarks then link to them with internal hyperlinks // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Bookmark, Document, HeadingLevel, HyperlinkRef, HyperlinkType, Packer, PageBreak, Paragraph, TextRun } from "../build"; +import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun } from "../build"; const LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante."; @@ -10,15 +10,26 @@ const doc = new Document({ creator: "Clippy", title: "Sample Document", description: "A brief example of using docx with bookmarks and internal hyperlinks", - hyperlinks: { - myAnchorId: { - text: "Hyperlink", - type: HyperlinkType.INTERNAL, - }, - }, }); doc.addSection({ + footers: { + default: new Footer({ + children: [ + new Paragraph({ + children: [ + new InternalHyperlink({ + child: new TextRun({ + text: "Click here!", + style: "Hyperlink", + }), + anchor: "myAnchorId", + }), + ], + }), + ], + }), + }, children: [ new Paragraph({ heading: HeadingLevel.HEADING_1, @@ -35,7 +46,15 @@ doc.addSection({ children: [new PageBreak()], }), new Paragraph({ - children: [new HyperlinkRef("myAnchorId")], + children: [ + new InternalHyperlink({ + child: new TextRun({ + text: "Anchor Text", + style: "Hyperlink", + }), + anchor: "myAnchorId", + }), + ], }), ], }); diff --git a/demo/22-right-to-left-text.ts b/demo/22-right-to-left-text.ts index 2c3984fb46..4ee344391c 100644 --- a/demo/22-right-to-left-text.ts +++ b/demo/22-right-to-left-text.ts @@ -1,7 +1,7 @@ // This demo shows right to left for special languages // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Packer, Paragraph, TextRun } from "../build"; +import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build"; const doc = new Document(); @@ -36,6 +36,31 @@ doc.addSection({ }), ], }), + new Table({ + visuallyRightToLeft: true, + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("ืฉืœื•ื ืขื•ืœื")], + }), + new TableCell({ + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [], + }), + new TableCell({ + children: [new Paragraph("ืฉืœื•ื ืขื•ืœื")], + }), + ], + }), + ], + }), ], }); diff --git a/demo/27-declaritive-styles-3.ts b/demo/27-declaritive-styles-3.ts index 8419467799..8737c69101 100644 --- a/demo/27-declaritive-styles-3.ts +++ b/demo/27-declaritive-styles-3.ts @@ -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, diff --git a/demo/29-numbered-lists.ts b/demo/29-numbered-lists.ts index 5cd3966015..77f50381d1 100644 --- a/demo/29-numbered-lists.ts +++ b/demo/29-numbered-lists.ts @@ -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, + }, + }), ], }); diff --git a/demo/3-numbering-and-bullet-points.ts b/demo/3-numbering-and-bullet-points.ts index 58c0a4f5a6..375c1439a7 100644 --- a/demo/3-numbering-and-bullet-points.ts +++ b/demo/3-numbering-and-bullet-points.ts @@ -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: { diff --git a/demo/31-tables.ts b/demo/31-tables.ts index 7daec1506d..24fc6030f8 100644 --- a/demo/31-tables.ts +++ b/demo/31-tables.ts @@ -1,7 +1,7 @@ // Example of how you would create a table and add data to it // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build"; +import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build"; const doc = new Document(); @@ -17,6 +17,14 @@ const table = new Table({ 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({ @@ -38,6 +46,22 @@ const table = new Table({ ], 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, + }), ], }), ], diff --git a/demo/32-merge-and-shade-table-cells.ts b/demo/32-merge-and-shade-table-cells.ts index db3174aeaf..284b456e05 100644 --- a/demo/32-merge-and-shade-table-cells.ts +++ b/demo/32-merge-and-shade-table-cells.ts @@ -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, 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), }, }); @@ -184,7 +197,7 @@ const table5 = new Table({ new TableRow({ children: [ new TableCell({ - children: [], + children: [new Paragraph("1,0")], }), new TableCell({ children: [new Paragraph("1,2")], @@ -195,10 +208,10 @@ const table5 = new Table({ new TableRow({ children: [ new TableCell({ - children: [], + children: [new Paragraph("2,0")], }), new TableCell({ - children: [], + children: [new Paragraph("2,1")], }), ], }), @@ -209,6 +222,161 @@ const table5 = new Table({ }, }); +const 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", + }, +}; + +const table6 = new Table({ + rows: [ + new TableRow({ + children: [ + new TableCell({ + borders, + children: [new Paragraph("0,0")], + rowSpan: 2, + }), + new TableCell({ + borders, + children: [new Paragraph("0,1")], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + borders, + children: [new Paragraph("1,1")], + rowSpan: 2, + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + borders, + children: [new Paragraph("2,0")], + }), + ], + }), + ], + width: { + size: 100, + type: WidthType.PERCENTAGE, + }, +}); + +const table7 = new Table({ + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("0,0")], + }), + new TableCell({ + children: [new Paragraph("0,1")], + }), + new TableCell({ + children: [new Paragraph("0,2")], + rowSpan: 2, + }), + new TableCell({ + children: [new Paragraph("0,3")], + rowSpan: 3, + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("1,0")], + columnSpan: 2, + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("2,0")], + columnSpan: 2, + }), + new TableCell({ + children: [new Paragraph("2,2")], + rowSpan: 2, + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("3,0")], + }), + new TableCell({ + children: [new Paragraph("3,1")], + }), + new TableCell({ + children: [new Paragraph("3,3")], + }), + ], + }), + ], + width: { + size: 100, + type: WidthType.PERCENTAGE, + }, +}); + +const table8 = new Table({ + rows: [ + new TableRow({ + children: [ + new TableCell({ children: [new Paragraph("1,1")] }), + new TableCell({ children: [new Paragraph("1,2")] }), + new TableCell({ children: [new Paragraph("1,3")] }), + new TableCell({ children: [new Paragraph("1,4")], rowSpan: 4, borders }), + ], + }), + new TableRow({ + children: [ + new TableCell({ children: [new Paragraph("2,1")] }), + new TableCell({ children: [new Paragraph("2,2")] }), + new TableCell({ children: [new Paragraph("2,3")], rowSpan: 3 }), + ], + }), + new TableRow({ + children: [ + new TableCell({ children: [new Paragraph("3,1")] }), + new TableCell({ children: [new Paragraph("3,2")], rowSpan: 2 }), + ], + }), + new TableRow({ + children: [new TableCell({ children: [new Paragraph("4,1")] })], + }), + ], + width: { + size: 100, + type: WidthType.PERCENTAGE, + }, +}); + doc.addSection({ children: [ table, @@ -222,10 +390,16 @@ doc.addSection({ heading: HeadingLevel.HEADING_2, }), table3, - new Paragraph("Merging columns"), + new Paragraph("Merging columns 1"), table4, - new Paragraph("More Merging columns"), + new Paragraph("Merging columns 2"), table5, + new Paragraph("Merging columns 3"), + table6, + new Paragraph("Merging columns 4"), + table7, + new Paragraph("Merging columns 5"), + table8, ], }); diff --git a/demo/35-hyperlinks.ts b/demo/35-hyperlinks.ts index fb84f13099..3e45e4c342 100644 --- a/demo/35-hyperlinks.ts +++ b/demo/35-hyperlinks.ts @@ -1,22 +1,91 @@ // Example on how to add hyperlinks to websites // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph } from "../build"; +import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, Media, Packer, Paragraph, TextRun } from "../build"; const doc = new Document({ - hyperlinks: { - myCoolLink: { - link: "http://www.example.com", - text: "Hyperlink", - type: HyperlinkType.EXTERNAL, - }, - }, + footnotes: [ + new Paragraph({ + children: [ + new TextRun("Click here for the "), + new ExternalHyperlink({ + child: new TextRun({ + text: "Footnotes external hyperlink", + style: "Hyperlink", + }), + link: "http://www.example.com", + }), + ], + }), + ], }); +const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg")); + doc.addSection({ + footers: { + default: new Footer({ + children: [ + new Paragraph({ + children: [ + new TextRun("Click here for the "), + new ExternalHyperlink({ + child: new TextRun({ + text: "Footer external hyperlink", + style: "Hyperlink", + }), + link: "http://www.example.com", + }), + ], + }), + ], + }), + }, + headers: { + default: new Footer({ + children: [ + new Paragraph({ + children: [ + new TextRun("Click here for the "), + new ExternalHyperlink({ + child: new TextRun({ + text: "Header external hyperlink", + style: "Hyperlink", + }), + link: "http://www.google.com", + }), + ], + }), + ], + }), + }, children: [ new Paragraph({ - children: [new HyperlinkRef("myCoolLink")], + children: [ + new ExternalHyperlink({ + child: new TextRun({ + text: "Anchor Text", + style: "Hyperlink", + }), + link: "http://www.example.com", + }), + new FootnoteReferenceRun(1) + ], + }), + new Paragraph({ + children: [ + new ExternalHyperlink({ + child: image1, + link: "http://www.google.com", + }), + new ExternalHyperlink({ + child: new TextRun({ + text: "BBC News Link", + style: "Hyperlink", + }), + link: "https://www.bbc.co.uk/news", + }), + ], }), ], }); diff --git a/demo/4-basic-table.ts b/demo/4-basic-table.ts index 593fe821a5..287e54808a 100644 --- a/demo/4-basic-table.ts +++ b/demo/4-basic-table.ts @@ -1,11 +1,95 @@ // Example of how you would create a table and add data to it // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; +import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build"; const doc = new Document(); const table = new Table({ + columnWidths: [3505, 5505], + rows: [ + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [new Paragraph("Hello")], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [new Paragraph("World")], + }), + ], + }), + ], +}); + +const table2 = new Table({ + columnWidths: [4505, 4505], + rows: [ + new TableRow({ + children: [ + new TableCell({ + width: { + size: 4505, + type: WidthType.DXA, + }, + children: [new Paragraph("Hello")], + }), + new TableCell({ + width: { + size: 4505, + type: WidthType.DXA, + }, + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + width: { + size: 4505, + type: WidthType.DXA, + }, + children: [], + }), + new TableCell({ + width: { + size: 4505, + type: WidthType.DXA, + }, + children: [new Paragraph("World")], + }), + ], + }), + ], +}); + +const table3 = new Table({ rows: [ new TableRow({ children: [ @@ -31,7 +115,14 @@ const table = new Table({ }); doc.addSection({ - children: [table], + children: [ + new Paragraph({ text: "Table with skewed widths" }), + table, + new Paragraph({ text: "Table with equal widths" }), + table2, + new Paragraph({ text: "Table without setting widths" }), + table3, + ], }); Packer.toBuffer(doc).then((buffer) => { diff --git a/demo/44-multiple-columns.ts b/demo/44-multiple-columns.ts index 3985486620..6e01e874e7 100644 --- a/demo/44-multiple-columns.ts +++ b/demo/44-multiple-columns.ts @@ -35,6 +35,22 @@ doc.addSection({ ], }); +doc.addSection({ + properties: { + column: { + space: 708, + count: 2, + separate: true, + }, + }, + children: [ + new Paragraph("This text will be split into 2 columns on a page."), + new Paragraph( + "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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + ), + ], +}); + Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); }); diff --git a/demo/46-shading-text.ts b/demo/46-shading-text.ts index 61f3f3d984..e662e6dffe 100644 --- a/demo/46-shading-text.ts +++ b/demo/46-shading-text.ts @@ -28,6 +28,18 @@ doc.addSection({ }), ], }), + new Paragraph({ + shading: { + type: ShadingType.DIAGONAL_CROSS, + color: "00FFFF", + fill: "FF0000", + }, + children: [ + new TextRun({ + text: "Hello World for entire paragraph", + }), + ], + }), ], }), }, diff --git a/demo/48-table-xml-styles.ts b/demo/48-table-xml-styles.ts new file mode 100644 index 0000000000..e993c5be34 --- /dev/null +++ b/demo/48-table-xml-styles.ts @@ -0,0 +1,50 @@ +// Example of how you would create a table and add data to it +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build"; + +const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8"); +const doc = new Document({ + title: "Title", + externalStyles: styles +}); + + +// Create a table and pass the XML Style +const table = new Table({ + style: 'MyCustomTableStyle', + width: { + size: 9070, + type: WidthType.DXA + }, + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("Header Colum 1")], + }), + new TableCell({ + children: [new Paragraph("Header Colum 2")], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("Column Content 3")], + }), + new TableCell({ + children: [new Paragraph("Column Content 2")], + }), + ], + }), + ], +}); + +doc.addSection({ + children: [table], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/49-table-borders.ts b/demo/49-table-borders.ts index 2aebf1feb1..75dd89c49f 100644 --- a/demo/49-table-borders.ts +++ b/demo/49-table-borders.ts @@ -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); diff --git a/demo/5-images.ts b/demo/5-images.ts index 260fd25f15..3c752d9a58 100644 --- a/demo/5-images.ts +++ b/demo/5-images.ts @@ -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, diff --git a/demo/51-character-styles.ts b/demo/51-character-styles.ts new file mode 100644 index 0000000000..a6064a4ddc --- /dev/null +++ b/demo/51-character-styles.ts @@ -0,0 +1,57 @@ +// Custom character styles using JavaScript configuration +// 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({ + styles: { + characterStyles: [ + { + id: "myRedStyle", + name: "My Wonky Style", + basedOn: "Normal", + run: { + color: "990000", + italics: true, + }, + }, + { + id: "strong", + name: "Strong", + basedOn: "Normal", + run: { + bold: true, + }, + }, + ], + }, +}); + +doc.addSection({ + children: [ + new Paragraph({ + children: [ + new TextRun({ + text: "Foo bar", + style: "myRedStyle", + }), + ], + }), + 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.", + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/52-japanese.ts b/demo/52-japanese.ts new file mode 100644 index 0000000000..5339c4b3a9 --- /dev/null +++ b/demo/52-japanese.ts @@ -0,0 +1,37 @@ +// Japanese text - Need to use a Japanese font +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, HeadingLevel, Packer, Paragraph } from "../build"; + +const doc = new Document({ + styles: { + paragraphStyles: [ + { + id: "Normal", + name: "Normal", + basedOn: "Normal", + next: "Normal", + quickFormat: true, + run: { + font: "MS Gothic", + }, + }, + ], + }, +}); + +doc.addSection({ + children: [ + new Paragraph({ + text: "KFCใ‚’้ฃŸในใ‚‹ใฎใŒๅฅฝใ", + heading: HeadingLevel.HEADING_1, + }), + new Paragraph({ + text: "ใ“ใ‚“ใซใกใฏ", + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/53-chinese.ts b/demo/53-chinese.ts new file mode 100644 index 0000000000..eee6eb9032 --- /dev/null +++ b/demo/53-chinese.ts @@ -0,0 +1,55 @@ +// Chinese text - Chinese text need to use a Chinese font. And ascii text need to use a ascii font. +// Different from the `52-japanese.ts`. +// `52-japanese.ts` will set all characters to use Japanese font. +// `53-chinese.ts` will set Chinese characters to use Chinese font, and set ascii characters to use ascii font. + +// Note that if the OS have not install `KaiTi` font, this demo doesn't work. + +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build"; + +const doc = new Document({ + styles: { + paragraphStyles: [ + { + id: "Normal", + name: "Normal", + basedOn: "Normal", + next: "Normal", + quickFormat: true, + run: { + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }, + }, + ], + }, +}); + +doc.addSection({ + children: [ + new Paragraph({ + text: "ไธญๆ–‡ๅ’Œ่‹ฑๆ–‡ Chinese and English", + heading: HeadingLevel.HEADING_1, + }), + new Paragraph({ + text: "ไธญๆ–‡ๅ’Œ่‹ฑๆ–‡ Chinese and English", + }), + new Paragraph({ + children: [ + new TextRun({ + text: "ไธญๆ–‡ๅ’Œ่‹ฑๆ–‡ Chinese and English", + font: { eastAsia: "SimSun" }, // set eastAsia to "SimSun". + // The ascii characters will use the default font ("Times") specified in paragraphStyles + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/54-custom-properties.ts b/demo/54-custom-properties.ts new file mode 100644 index 0000000000..4aad3864c9 --- /dev/null +++ b/demo/54-custom-properties.ts @@ -0,0 +1,30 @@ +// Custom Properties +// Custom properties are incredibly useful if you want to be able to apply quick parts or custom cover pages +// to the document in Word after the document has been generated. Standard properties (such as creator, title +// and subject) cover typical use cases, but sometimes custom properties are required. + +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Packer } from "../build"; + +const doc = new Document( + // Standard properties + { + creator: "Creator", + title: "Title", + subject: "Subject", + description: "Description", + customProperties: [ + { name: "Subtitle", value: "Subtitle" }, + { name: "Address", value: "Address" }, + ], + }, + // No file properties + {}, + // No sections + [], +); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/54-track-revisions.ts b/demo/54-track-revisions.ts new file mode 100644 index 0000000000..e035fbb18a --- /dev/null +++ b/demo/54-track-revisions.ts @@ -0,0 +1,146 @@ +// Track Revisions aka. "Track Changes" +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { + AlignmentType, + DeletedTextRun, + Document, + Footer, + FootnoteReferenceRun, + InsertedTextRun, + Packer, + PageNumber, + Paragraph, + ShadingType, + TextRun, +} from "../build"; + +/* + For reference, see + - https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.insertedrun + - https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.deletedrun + + The method `addTrackRevisions()` adds an element `` to the `settings.xml` file. This specifies that the application shall track *new* revisions made to the existing document. + See also https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.trackrevisions + + Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it. +*/ + +const doc = new Document({ + footnotes: [ + new Paragraph({ + children: [ + new TextRun("This is a footnote"), + new DeletedTextRun({ + text: " with some extra text which was deleted", + id: 0, + author: "Firstname Lastname", + date: "2020-10-06T09:05:00Z", + }), + new InsertedTextRun({ + text: " and new content", + id: 1, + author: "Firstname Lastname", + date: "2020-10-06T09:05:00Z", + }), + ], + }), + ], + features: { + trackRevisions: true, + }, +}); + +const paragraph = new Paragraph({ + children: [ + new TextRun("This is a simple demo "), + new TextRun({ + text: "on how to ", + }), + new InsertedTextRun({ + text: "mark a text as an insertion ", + id: 0, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }), + new DeletedTextRun({ + text: "or a deletion.", + id: 1, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }), + ], +}); + +doc.addSection({ + properties: {}, + children: [ + paragraph, + new Paragraph({ + children: [ + new TextRun("This is a demo "), + new DeletedTextRun({ + break: 1, + text: "in order", + color: "red", + bold: true, + size: 24, + font: { + name: "Garamond", + }, + shading: { + type: ShadingType.REVERSE_DIAGONAL_STRIPE, + color: "00FFFF", + fill: "FF0000", + }, + id: 2, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }), + new InsertedTextRun({ + text: "to show how to ", + bold: false, + id: 3, + author: "Firstname Lastname", + date: "2020-10-06T09:05:00Z", + }), + new TextRun({ + bold: true, + children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)], + }), + ], + }), + ], + footers: { + default: new Footer({ + children: [ + new Paragraph({ + alignment: AlignmentType.CENTER, + children: [ + new TextRun("Awesome LLC"), + new TextRun({ + children: ["Page Number: ", PageNumber.CURRENT], + }), + new DeletedTextRun({ + children: [" to ", PageNumber.TOTAL_PAGES], + id: 4, + author: "Firstname Lastname", + date: "2020-10-06T09:05:00Z", + }), + new InsertedTextRun({ + children: [" from ", PageNumber.TOTAL_PAGES], + bold: true, + id: 5, + author: "Firstname Lastname", + date: "2020-10-06T09:05:00Z", + }), + ], + }), + ], + }), + }, +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/55-math.ts b/demo/55-math.ts new file mode 100644 index 0000000000..2a240986d0 --- /dev/null +++ b/demo/55-math.ts @@ -0,0 +1,294 @@ +// Simple example to add text to a document +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { + Document, + Math, + MathAngledBrackets, + MathCurlyBrackets, + MathFraction, + MathFunction, + MathPreSubSuperScript, + MathRadical, + MathRoundBrackets, + MathRun, + MathSquareBrackets, + MathSubScript, + MathSubSuperScript, + MathSum, + MathSuperScript, + Packer, + Paragraph, + TextRun, +} from "../build"; + +const doc = new Document(); + +doc.addSection({ + properties: {}, + children: [ + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRun("2+2"), + new MathFraction({ + numerator: [new MathRun("hi")], + denominator: [new MathRun("2")], + }), + ], + }), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFraction({ + numerator: [ + new MathRun("1"), + new MathRadical({ + children: [new MathRun("2")], + }), + ], + denominator: [new MathRun("2")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSum({ + children: [new MathRun("test")], + }), + new MathSum({ + children: [ + new MathSuperScript({ + children: [new MathRun("e")], + superScript: [new MathRun("2")], + }), + ], + subScript: [new MathRun("i")], + }), + new MathSum({ + children: [ + new MathRadical({ + children: [new MathRun("i")], + }), + ], + subScript: [new MathRun("i")], + superScript: [new MathRun("10")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSuperScript({ + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + children: [new MathRun("test")], + subScript: [new MathRun("hello")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + children: [new MathRun("x")], + subScript: [ + new MathSuperScript({ + children: [new MathRun("y")], + superScript: [new MathRun("2")], + }), + ], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubSuperScript({ + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathPreSubSuperScript({ + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + subScript: [new MathRun("4")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + children: [ + new MathRadical({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + degree: [new MathRun("4")], + }), + ], + subScript: [new MathRun("x")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRadical({ + children: [new MathRun("4")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFunction({ + name: [ + new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], + }), + ], + children: [new MathRun("100")], + }), + new MathRun("ร—"), + new MathFunction({ + name: [new MathRun("sin")], + children: [new MathRun("360")], + }), + new MathRun("= x"), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRoundBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + }), + new MathSquareBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + }), + new MathCurlyBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + }), + new MathAngledBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFraction({ + numerator: [ + new MathRadical({ + children: [new MathRun("4")], + }), + ], + denominator: [new MathRun("2a")], + }), + ], + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/56-background-color.ts b/demo/56-background-color.ts new file mode 100644 index 0000000000..6e8658fd00 --- /dev/null +++ b/demo/56-background-color.ts @@ -0,0 +1,33 @@ +// Change background colour of whole document +// 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({ + background: { + color: "C45911", + }, +}); + +doc.addSection({ + properties: {}, + children: [ + new Paragraph({ + 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); +}); diff --git a/demo/57-add-parent-numbered-lists.ts b/demo/57-add-parent-numbered-lists.ts new file mode 100644 index 0000000000..e35cd06a27 --- /dev/null +++ b/demo/57-add-parent-numbered-lists.ts @@ -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); +}); diff --git a/demo/58-section-types.ts b/demo/58-section-types.ts new file mode 100644 index 0000000000..6c16b44600 --- /dev/null +++ b/demo/58-section-types.ts @@ -0,0 +1,93 @@ +// Usage of different Section Types +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Packer, Paragraph, TextRun, SectionType } from "../build"; + +const doc = new Document(); + +doc.addSection({ + properties: {}, + children: [ + new Paragraph({ + children: [ + new TextRun("Hello World"), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +doc.addSection({ + properties: { + type: SectionType.CONTINUOUS, + }, + children: [ + new Paragraph({ + children: [ + new TextRun("Hello World"), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +doc.addSection({ + properties: { + type: SectionType.ODD_PAGE, + }, + children: [ + new Paragraph({ + children: [ + new TextRun("Hello World"), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +doc.addSection({ + properties: { + type: SectionType.EVEN_PAGE, + }, + children: [ + new Paragraph({ + children: [ + new TextRun("Hello World"), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +doc.addSection({ + properties: { + type: SectionType.NEXT_PAGE, + }, + children: [ + new Paragraph({ + children: [ + new TextRun("Hello World"), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/demo/assets/custom-styles.xml b/demo/assets/custom-styles.xml index 76159f2985..2b6f2508a3 100644 --- a/demo/assets/custom-styles.xml +++ b/demo/assets/custom-styles.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/docs/README.md b/docs/README.md index dae964d87a..9d2150a441 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,13 +1,3 @@ -

- clippy the assistant -

- -

- Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100: -

- ---- - # Welcome ## Installation @@ -63,17 +53,11 @@ Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer); }); -// Done! A file called 'My First Document.docx' will be in your file system. +// Done! A file called 'My Document.docx' will be in your file system. ``` -## Honoured Mentions - -[@felipeochoa](https://github.com/felipeochoa) - -[@h4buli](https://github.com/h4buli) -

- clippy the assistant + clippy the assistant

--- diff --git a/docs/_coverpage.md b/docs/_coverpage.md new file mode 100644 index 0000000000..c3db65386d --- /dev/null +++ b/docs/_coverpage.md @@ -0,0 +1,10 @@ +drawing + +> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100: + +- Simple, declarative API +- 50+ usage examples +- Battle tested, mature, 97%+ coverage + +[GitHub](https://github.com/dolanmiu/docx) +[Get Started](#Welcome) diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 9e329b6448..2538e975c7 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -1,6 +1,6 @@ * [Getting Started](/) -* [Examples](examples.md) +* [Examples](https://github.com/dolanmiu/docx/tree/master/demo) * API @@ -20,12 +20,16 @@ * [Tab Stops](usage/tab-stops.md) * [Table of Contents](usage/table-of-contents.md) * [Page Numbers](usage/page-numbers.md) + * [Change Tracking](usage/change-tracking.md) + * [Math](usage/math.md) * Styling * [Styling with JS](usage/styling-with-js.md) * [Styling with XML](usage/styling-with-xml.md) * Exporting * [Packers](usage/packers.md) +* Utility + + * [Convenience functions](usage/convenience-functions.md) * [Contribution Guidelines](contribution-guidelines.md) - diff --git a/docs/clippy.png b/docs/clippy.png new file mode 100644 index 0000000000..97bd4af2df Binary files /dev/null and b/docs/clippy.png differ diff --git a/docs/clippy.psd b/docs/clippy.psd new file mode 100644 index 0000000000..0d32ab12d0 Binary files /dev/null and b/docs/clippy.psd differ diff --git a/docs/contribution-guidelines.md b/docs/contribution-guidelines.md index 1305c4c4bd..f9963bd644 100644 --- a/docs/contribution-guidelines.md +++ b/docs/contribution-guidelines.md @@ -1,25 +1,23 @@ # Contribution Guidelines -* Include documentation reference(s) at the top of each file: +- Include documentation reference(s) at the top of each file: ```ts // http://officeopenxml.com/WPdocument.php ``` -* Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin. +- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin. -* Follow the `TSLint` rules +- Follow the `TSLint` rules ## Always think about the user -The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`. - Put yourself in their position, and imagine how they would feel about your feature you wrote. 1. Is it easy to use? 2. Has it been documented well? 3. Is it intuitive? -4. Is it consistent with the rest of the API? +4. Is it declarative? 5. Is it fun to use? ## Good Commit Names @@ -27,6 +25,7 @@ Put yourself in their position, and imagine how they would feel about your featu Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/ **Do not:** + ``` c // What? rtl // Adding acryonyms without explaining anything else is not helpful @@ -35,34 +34,6 @@ demo updated // Getting better, but capitalize the first letter Unesesary coment removed // Make sure to use correct spelling ``` -## No leaky components in API interface - -> This mainly applies to the API the end user will consume. - -Try to make method parameters of the outside API accept primitives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in. - -This is so that: - -1. Imports are much cleaner for the end user, no need for: - ```ts - import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component"; - ``` - -2. This is what I consider "leakage". The code is aware of the underlying implementation of the component. -3. It means the end user does not need to import and create the child component to be injected. - -**Do not** - -`TableFloatProperties` is a class. The outside world would have to `new` up the object, and inject it in like so: - -```ts - public float(tableFloatProperties: TableFloatProperties): Table -``` - -```ts - table.float(new TableFloatProperties(...)); -``` - **Do** `ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals: @@ -71,31 +42,29 @@ This is so that: public float(tableFloatOptions: ITableFloatOptions): Table ``` +## Delcariative API + +Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm + +**Do not:** + ```ts - table.float({...}); +const paragraph = doc.createParagraph(); +const text = paragraph.createText(); +text.contents = "Hello World"; ``` -## Add vs Create +**Do** -This is just a guideline, and the rules can sometimes be broken. - -* Use `create` if the method `new`'s up an element inside: - - ```ts - public createParagraph() { - const paragraph = new Paragraph(); - this.root.push(paragraph); - } - ``` - -* Use `add` if you add the element into the method as a parameter. - *Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document: - - ```ts - public add(paragraph: Paragraph) { - this.root.push(paragraph); - } - ``` +```ts +doc.addSection({ + children: [ + new Paragraph({ + children: [new TextRun("Hello World")], + }), + ], +}); +``` ## Getters and Setters @@ -107,7 +76,7 @@ public get Level() { } ``` -There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly `_`: +This is the convention of this project. There is no performance advantage by doing this. It means we don't need to prefix all private variables with `_`: **Do not:** @@ -121,30 +90,6 @@ private get _level: string; private get level: string; ``` -## Temporal Methods - -Some methods are `non-temporal`, which means regardless of when you call the method, it will have the same affect on the document. For example, setting the width of a table at the end of the document will have the same effect as setting the width at the start: - -```ts -table.setWidth(1000); // now removed as of version 5.0.0 -``` - -Whereas some methods are `temporal`, which means depending on the time-frame they are called, it would produce a difference result. For example, moving `createParagraph()` around your code will physically alter the document. - -```ts -doc.createParagraph("hello"); -``` - -If a method is `non-temporal`, put it in the objects `constructor`. For example: - -```ts -const table = new Table(width: number); -``` - -`Non-temporal` methods are usually methods which can only be used one time and one time only. For example, `.float()`. It does not make sense to call `.float()` again if its already floating. - -I am not sure what the real term is, but this will do. - ## Interfaces over type alias Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it. @@ -152,14 +97,14 @@ Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a > "In general, use what you want ( type alias / interface ) just be consistent" > "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions" > -> * https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c +> - https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c `Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types **Do not:** ```ts -type RelationshipFileInfo = { id: number, target: string }; +type RelationshipFileInfo = { id: number; target: string }; ``` **Do:** @@ -193,26 +138,26 @@ enum WeaponType = { ## Spell correctly, in full and in American English -I am not sure where these habits in software development come from, but I do not believe it is beneficial: - **Do not:** + ```ts -readdy // misspelling -perm // abbreviation -conf // abbreviation -cnty // abbreviation -relationFile // abbreviation -colour // U.K. English +readdy; // misspelling +perm; // abbreviation +conf; // abbreviation +cnty; // abbreviation +relationFile; // abbreviation +colour; // U.K. English ``` **Do:** + ```ts -ready -permission -config -country -relationshipFile -color +ready; +permission; +config; +country; +relationshipFile; +color; ``` ## Keep files small (within reason) diff --git a/docs/examples.md b/docs/examples.md deleted file mode 100644 index f638e1aa25..0000000000 --- a/docs/examples.md +++ /dev/null @@ -1,219 +0,0 @@ -# Examples - -> All examples can run independently and can be found in the `/demo` folder of the project - -All the examples below can be ran locally, to do so, run the following command: - -```sh -npm run demo -``` - -This command will run the `demo selector app` in the `/demo` folder. It will prompt you to select a demo number, which will run a demo from that folder. - -## Simple - -A simple hello world of the `docx` library: - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_ - -## Styles - -### Styling with JS - -This example shows how to customise the look and feel of a document using JS configuration - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_ - -### Styling with XML - -This example shows how to customise the look and feel of a document using XML configuration - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_ - -## Numbering - -This example shows many levels of numbering - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_ - -## Table - -Example of simple table - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_ - -### Styling table borders - -Styling the borders of a table - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_ - -## Images - -### Add image to the document - -Importing Images from file system path - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_ - -### Add images to header and footer - -Example showing how to add image to headers and footers - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_ - -### Scaling images - -Example showing how to scale images - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_ - -### Add Image to media before adding to document - -This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_ - -### Add image to table - -As before, to add an image to a table, you would need to add it to the `Media` object first - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_ - -### Images using Base64 URI - -If you want to use a Base64 image instead - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_ - -## Margins - -Example showing how to set custom margins - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_ - -## Orientation - -Example showing how to set the document to `landscape` or `portrait` - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_ - -## Headers & Footers - -Example showing how to add headers and footers - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_ - -## Multiple headers and footers - -Check out `Sections` for this feature - -## Page Breaks - -### Normal page breaks - -Example showing how to page break - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_ - -### Page break before - -Example showing how to page break before like in Word - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_ - -## Sections - -Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document. -Also you can have different page number formats and starts for different sections. - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_ - -## Footnotes - -Example of how to add footnotes. Good for references - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_ - -## Packers - -## Buffer output - -Example showing how to use the Buffer packer and then write that buffer to the file system - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_ - - -## Bookmarks - -Example showing how to make bookmarks to make internal hyperlinks within the document - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_ - -## Bidirectional text - -Example showing how to use bidirectional text for certain languages such as Hebrew - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_ - -## Showcase - -### My CV - -Example showing how to add headers and footers - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_ - -### Style and Images - -This example shows how to customise the look and feel of a document and add images - -[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ':include') - -_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_ diff --git a/docs/images/math-example.png b/docs/images/math-example.png new file mode 100644 index 0000000000..c92f8806f9 Binary files /dev/null and b/docs/images/math-example.png differ diff --git a/docs/index.html b/docs/index.html index 9af955e10e..13c52ae6da 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,31 +1,36 @@ + + + docx - Generate .docx documents with JavaScript + + + + + - - - docx - Generate .docx documents with JavaScript - - - - - - - -
- - - - - - - - + +
+ + + + + + + + diff --git a/docs/usage/bullet-points.md b/docs/usage/bullet-points.md index 045ec61d1a..159241b3b0 100644 --- a/docs/usage/bullet-points.md +++ b/docs/usage/bullet-points.md @@ -5,12 +5,21 @@ To make a bullet point, simply make a paragraph into a bullet point: ```ts -const text = new TextRun("Bullet points"); -const paragraph = new Paragraph({ - text: "Bullet points", - bullet: { - level: 0, // How deep you want the bullet to me - }, +doc.addSection({ + children: [ + new Paragraph({ + text: "Bullet points", + bullet: { + level: 0 //How deep you want the bullet to be + } + }), + new Paragraph({ + text: "Are awesome", + bullet: { + level: 0 + } + }) + ], }); ``` diff --git a/docs/usage/change-tracking.md b/docs/usage/change-tracking.md new file mode 100644 index 0000000000..a5ca66ebb3 --- /dev/null +++ b/docs/usage/change-tracking.md @@ -0,0 +1,61 @@ +# Change Tracking + +> Instead of adding a `TextRun` into a `Paragraph`, you can also add an `InsertedTextRun` or `DeletedTextRun` where you need to supply an `id`, `author` and `date` for the change. + +```ts +import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx"; + +const paragraph = new Paragraph({ + children: [ + new TextRun("This is a simple demo "), + new TextRun({ + text: "on how to " + }), + new InsertedTextRun({ + text: "mark a text as an insertion ", + id: 0, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }), + new DeletedTextRun({ + text: "or a deletion.", + id: 1, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }) + ], +}); +``` + +Note that for a `InsertedTextRun` and `DeletedTextRun`, it is not possible to simply call it with only a text as in `new TextRun("some text")`, since the additonal fields for change tracking need to be provided. Similar to a normal `TextRun` you can add additional text properties. + +```ts +import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx"; + +const paragraph = new Paragraph({ + children: [ + new TextRun("This is a simple demo"), + new DeletedTextRun({ + text: "with a deletion.", + color: "red", + bold: true, + size: 24, + id: 0, + author: "Firstname Lastname", + date: "2020-10-06T09:00:00Z", + }) + ], +}); +``` + +In addtion to marking text as inserted or deleted, change tracking can also be added via the document settings. This will enable new changes to be tracked as well. + +```ts +import { Document } from "docx"; + +const doc = new Document({ + features: { + trackRevisions: true, + }, +}); +``` diff --git a/docs/usage/convenience-functions.md b/docs/usage/convenience-functions.md new file mode 100644 index 0000000000..76236ca6c4 --- /dev/null +++ b/docs/usage/convenience-functions.md @@ -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 +``` diff --git a/docs/usage/document.md b/docs/usage/document.md index bf06d30613..0f1a12486a 100644 --- a/docs/usage/document.md +++ b/docs/usage/document.md @@ -30,6 +30,24 @@ const doc = new docx.Document({ * keywords * lastModifiedBy * revision +* externalStyles +* styles +* numbering +* footnotes +* hyperlinks +* background + +### Change background color of Document + +Set the hex value in the document like so: + +```ts +const doc = new docx.Document({ + background: { + color: "C45911", + }, +}); +``` You can mix and match whatever properties you want, or provide no properties. diff --git a/docs/usage/images.md b/docs/usage/images.md index 4893348cc0..94e75e75a7 100644 --- a/docs/usage/images.md +++ b/docs/usage/images.md @@ -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: diff --git a/docs/usage/math.md b/docs/usage/math.md new file mode 100644 index 0000000000..1e8ab4f894 --- /dev/null +++ b/docs/usage/math.md @@ -0,0 +1,265 @@ +# Math + +!> Math requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md). + +## Intro + +1. To add math, create a `Math` object +2. Add `MathComponents` inside `Math` +3. `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below +4. Make sure to add the `Math` object inside a `Paragraph` + +## Example + +```ts +new Math({ + children: [ + new MathRun("2+2"), + new MathFraction({ + numerator: [new MathRun("hi")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +This will produce: + +

+ clippy the assistant +

+ +## Math Components + +`MathComponents` are the unit sized building blocks of an equation in `docx`. A `MathComponent` takes in more nested `MathComponents` until you reach `MathRun`, which has no children. `MathRun` is similar to a [TextRun](usage/text.md). + +### Math Run + +`MathRun` is the most basic `MathComponent`. + +#### Example + +```ts +new MathRun("2+2"); +``` + +```ts +new MathRun("hello"); +``` + +An example of it being used inside `Math`: + +```ts +new Math({ + children: [ + new MathRun("2"), + new MathRun("+"), + new MathRun("2"), + ], +}), +``` + +### Math Fraction + +`MathFractions` require a `numerator` and a `demoninator`, which are both a list of `MathComponents` + +#### Example + +```ts +new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], +}), +``` + +```ts +new MathFraction({ + numerator: [ + new MathRun("1"), + new MathRadical({ + children: [new MathRun("2")], + }), + ], + denominator: [new MathRun("2")], +}), +``` + +An example of it being used inside `Math`: + +```ts +new Math({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathText("+"), + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathText("= 1"), + ], +}), +``` + +### Sum + +A `MathComponent` for `ฮฃ`. It can take a `superScript` and/or `subScript` as arguments to add `MathComponents` (usually limits) on the top and bottom + +```ts +new MathSum({ + children: [new MathRun("i")], +}), +``` + +```ts +new MathSum({ + children: [ + new MathSuperScript({ + children: [new MathRun("e")], + superScript: [new MathRun("2")], + }) + ], + subScript: [new MathRun("i")], + superScript: [new MathRun("10")], +}), +``` + +### Radicals + +A `MathComponent` for the `โˆš` symbol. Examples include, square root, cube root etc. There is an optional `degree` parameter to specify the number of times the radicand is multiplied by itself. For example, `3` for cube root. + +```ts +new MathRadical({ + children: [new MathRun("2")], +}), +``` + +Cube root example: + +```ts +new MathRadical({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathRun('+ 1'), + ], + degree: [new MathRun("3")], +}), +``` + +### Super Script + +`MathSuperScripts` are the little numbers written to the top right of numbers or variables. It means the exponent or power if written by itself with the number or variable. + +```ts +new MathSuperScript({ + children: [new MathRun("x")], + superScript: [new MathRun("2")], +}), +``` + +An example with cosine: + +```ts +new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], +}), +``` + +### Sub Script + +`MathSubScripts` are similar to `MathSuperScripts`, except the little number is written below. + +```ts +new MathSubScript({ + children: [new MathRun("F")], + subScript: [new MathRun("n-1")], +}), +``` + +### Sub-Super Script + +`MathSubSuperScripts` are a combination of both `MathSuperScript` and `MathSubScript`. + +```ts +new MathSubSuperScript({ + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], +}), +``` + +### Function + +`MathFunctions` are a way of describing what happens to an input variable, in order to get the output result. It takes a `name` parameter to specify the name of the function. + +```ts +new MathFunction({ + name: [ + new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], + }), + ], + children: [new MathRun("100")], +}), +``` + +### Brackets + +#### Square brackets + +```ts +new MathSquareBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Round brackets + +```ts +new MathRoundBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Curly brackets + +```ts +new MathCurlyBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Angled brackets + +```ts +new MathAngledBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` diff --git a/docs/usage/packers.md b/docs/usage/packers.md index e9b3626015..236494bf96 100644 --- a/docs/usage/packers.md +++ b/docs/usage/packers.md @@ -2,11 +2,7 @@ > Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`. -Packers in `version 4` and above are now one single `Packer`. It works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of version 4, this library will not have options to export to PDF. - -## Version 5 - -Packers in `version 5` and above are now static methods on `Packer`. +Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF. ### Export as Buffer @@ -36,117 +32,3 @@ Packer.toBlob(doc).then((blob) => { saveAs(blob, "example.docx"); }); ``` - -## Version 4 - -The `Packer` in `version 4` requires an instance of `Packer`, so be sure to `new` it. - -### Export as Buffer - -This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead. - -```ts -const packer = new docx.Packer(); - -packer.toBuffer(doc).then((buffer) => { - fs.writeFileSync("My Document.docx", buffer); -}); -``` - -### Export as a `base64` string - -```ts -const packer = new docx.Packer(); - -packer.toBase64String(doc).then((string) => { - console.log(string); -}); -``` - -### Export as Blob - -This is useful if you want to send it as an downloadable in a browser environment. - -```ts -const packer = new docx.Packer(); - -packer.toBlob(doc).then((blob) => { - // saveAs from FileSaver will download the file - saveAs(blob, "example.docx"); -}); -``` - -## Version 3 and below - -### File System Packer - -```ts -const docx = require("docx"); - -const doc = new docx.Document(); -const exporter = new docx.LocalPacker(doc); -exporter.pack("My Document"); -// Word Document is in file system -``` - -### Buffer Packer - -```ts -const docx = require("docx"); - -const doc = new docx.Document(); -const exporter = new docx.BufferPacker(doc); -const buffer = exporter.pack(); -``` - -### Stream Packer - -Creates a `node` `Readable` stream - -```ts -const docx = require("docx"); - -const doc = new docx.Document(); -const exporter = new docx.StreamPacker(doc); -const stream = exporter.pack(); -``` - -### Express Packer - -The old express packer is now deprecated and may disappear soon, so you should upgrade. - -The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns. - -It will still be usable (for now), but it is ill advised. - -I used the express exporter in my [website](http://www.dolan.bio). - -The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library: - -```ts -const docx = require("docx"); - -const doc = new docx.Document(); -const exporter = new docx.StreamPacker(doc); - -const stream = exporter.pack(); - -// Express' response object -res.attachment("yourfile.xlsx"); -stream.pipe(res); -``` - -where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser. - -### PDF Exporting - -You can export your word document as a PDF file like so: - -```ts -const exporter = new docx.LocalPacker(doc); -exporter.packPdf("My Document"); - -// Express -const exporter = new docx.ExpressPacker(doc, res); -exporter.packPdf("My Document"); -``` diff --git a/docs/usage/paragraph.md b/docs/usage/paragraph.md index f6da3ec963..ceb4e0aa34 100644 --- a/docs/usage/paragraph.md +++ b/docs/usage/paragraph.md @@ -142,6 +142,21 @@ const paragraph = new Paragraph({ }); ``` +## Shading + +Add color to an entire paragraph block + +```ts +const paragraph = new Paragraph({ + text: "shading", + shading: { + type: ShadingType.REVERSE_DIAGONAL_STRIPE, + color: "00FFFF", + fill: "FF0000", + }, +}); +``` + ## Spacing Adding spacing between paragraphs diff --git a/docs/usage/sections.md b/docs/usage/sections.md index 5b6d4e9c74..daabb02294 100644 --- a/docs/usage/sections.md +++ b/docs/usage/sections.md @@ -19,3 +19,30 @@ doc.addSection({ ], }); ``` + +## Properties + +You can specify additional properties to the section, by providing a `properties` attribute. + +### Section Type + +Setting the section type determines how the contents of the section will be placed relative to the previous section. E.g., There are five different types: + +- `CONTINUOUS` +- `EVEN_PAGE` +- `NEXT_COLUMN` +- `NEXT_PAGE` +- `ODD_PAGE` + +```ts +doc.addSection({ + properties: { + type: SectionType.CONTINUOUS, + } + children: [ + new Paragraph({ + children: [new TextRun("Hello World")], + }), + ], +}); +``` diff --git a/docs/usage/styling-with-js.md b/docs/usage/styling-with-js.md index 26d294c942..0dafac2904 100644 --- a/docs/usage/styling-with-js.md +++ b/docs/usage/styling-with-js.md @@ -22,10 +22,11 @@ const name = new TextRun({ ### Run formatting - `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true -- `underline(style="single", color=null)`: Set the underline style and color +- `underline({type="single", color=null})`: Set the underline style and color +- `emphasisMark({type="dot"})`: Set the emphasis mark style - `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`) - `size(halfPts)`: Set the font size, measured in half-points -- `font(name)`: Set the run's font +- `font(name)` or `font({ascii, cs, eastAsia, hAnsi, hint})`: Set the run's font - `style(name)`: Apply a named run style - `characterSpacing(value)`: Set the character spacing adjustment (in TWIPs) diff --git a/docs/usage/tables.md b/docs/usage/tables.md index a8e41de58a..637efa2977 100644 --- a/docs/usage/tables.md +++ b/docs/usage/tables.md @@ -51,19 +51,6 @@ const table = new Table({ }); ``` -### Pagination - -#### Prevent row pagination - -To prevent breaking contents of a row across multiple pages, call `cantSplit`: - -```ts -const table = new Table({ - rows: [], - cantSplit: true, -}); -``` - ## Table Row A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so: @@ -103,7 +90,7 @@ Here is a list of options you can add to the `table row`: | children | `Array` | Required | | cantSplit | `boolean` | Optional | | tableHeader | `boolean` | Optional | -| height | `{ value: number, rule: HeightRule }` | Optional | +| height | `{ height: number, rule: HeightRule }` | Optional | ### Repeat row @@ -116,6 +103,19 @@ const row = new TableRow({ }); ``` +### Pagination + +#### Prevent row pagination + +To prevent breaking contents of a row across multiple pages, call `cantSplit`: + +```ts +const row = new Row({ + ..., + cantSplit: true, +}); +``` + ## Table Cells Cells need to be added in the `table row`, you can create a table cell like: @@ -326,6 +326,17 @@ const cell = new TableCell({ }); ``` +### Visual Right to Left Table + +It is possible to reverse how the cells of the table are displayed. The table direction. More info here: https://superuser.com/questions/996912/how-to-change-a-table-direction-in-microsoft-word + +```ts +const table = new Table({ + visuallyRightToLeft: true, +}); +``` + + ## Examples [Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts ':include') diff --git a/docs/usage/text.md b/docs/usage/text.md index 6cbd9da224..0b7b88686b 100644 --- a/docs/usage/text.md +++ b/docs/usage/text.md @@ -68,40 +68,87 @@ const text = new TextRun({ }); ``` +### Emphasis Mark + +```ts +const text = new TextRun({ + text: "and then emphasis mark", + emphasisMark: {}, +}); +``` + +### Shading and Highlighting + +```ts +const text = new TextRun({ + text: "shading", + shading: { + type: ShadingType.REVERSE_DIAGONAL_STRIPE, + color: "00FFFF", + fill: "FF0000", + }, +}); +``` + +```ts +const text = new TextRun({ + text: "highlighting", + highlight: "yellow", +}); +``` + ### Strike through ```ts -text.strike(); +const text = new TextRun({ + text: "strike", + strike: true, +}); ``` ### Double strike through ```ts -text.doubleStrike(); +const text = new TextRun({ + text: "doubleStrike", + doubleStrike: true, +}); ``` ### Superscript ```ts -text.superScript(); +const text = new TextRun({ + text: "superScript", + superScript: true, +}); ``` ### Subscript ```ts -text.subScript(); +const text = new TextRun({ + text: "subScript", + subScript: true, +}); ``` ### All Capitals ```ts -text.allCaps(); +const text = new TextRun({ + text: "allCaps", + allCaps: true, +}); ``` ### Small Capitals ```ts -text.smallCaps(); +const text = new TextRun({ + text: "smallCaps", + smallCaps: true, +}); ``` ## Break @@ -109,13 +156,17 @@ text.smallCaps(); Sometimes you would want to put text underneath another line of text but inside the same paragraph. ```ts -text.break(); +const text = new TextRun({ + text: "break", + break: 1, +}); ``` -## Chaining - -What if you want to create a paragraph which is **_bold_** and **_italic_**? +Adding two breaks: ```ts -paragraph.bold().italics(); +const text = new TextRun({ + text: "break", + break: 2, +}); ``` diff --git a/package-lock.json b/package-lock.json index 974c0fcb0d..183d28b7b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,27 +1,123 @@ { "name": "docx", - "version": "5.0.0", + "version": "5.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", - "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", "dev": true, "requires": { - "@babel/highlight": "^7.0.0" + "@babel/highlight": "^7.10.4" + } + }, + "@babel/core": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.0.tgz", + "integrity": "sha512-mkLq8nwaXmDtFmRkQ8ED/eA2CnVw4zr7dCztKalZXBvdK5EeNUAesrrwUqjQEzFgomJssayzB0aqlOsP1vGLqg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/generator": "^7.11.0", + "@babel/helper-module-transforms": "^7.11.0", + "@babel/helpers": "^7.10.4", + "@babel/parser": "^7.11.0", + "@babel/template": "^7.10.4", + "@babel/traverse": "^7.11.0", + "@babel/types": "^7.11.0", + "convert-source-map": "^1.7.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.1", + "json5": "^2.1.2", + "lodash": "^4.17.19", + "resolve": "^1.3.2", + "semver": "^5.4.1", + "source-map": "^0.5.0" + }, + "dependencies": { + "@babel/code-frame": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", + "dev": true, + "requires": { + "@babel/highlight": "^7.10.4" + } + }, + "@babel/highlight": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + } + }, + "convert-source-map": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz", + "integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, + "json5": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz", + "integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } } }, "@babel/generator": { - "version": "7.6.4", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.6.4.tgz", - "integrity": "sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.11.0.tgz", + "integrity": "sha512-fEm3Uzw7Mc9Xi//qU20cBKatTfs2aOtKqmvy/Vm7RkJEGFQ4xc9myCfbXxqK//ZS8MR/ciOHw6meGASJuKmDfQ==", "dev": true, "requires": { - "@babel/types": "^7.6.3", + "@babel/types": "^7.11.0", "jsesc": "^2.5.1", - "lodash": "^4.17.13", "source-map": "^0.5.0" }, "dependencies": { @@ -40,42 +136,123 @@ } }, "@babel/helper-function-name": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz", - "integrity": "sha512-A95XEoCpb3TO+KZzJ4S/5uW5fNe26DjBGqf1o9ucyLyCmi1dXq/B3c8iaWTfBk3VvetUxl16e8tIrd5teOCfGw==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.10.4.tgz", + "integrity": "sha512-YdaSyz1n8gY44EmN7x44zBn9zQ1Ry2Y+3GTA+3vH6Mizke1Vw0aWDM66FOYEPw8//qKkmqOckrGgTYa+6sceqQ==", "dev": true, "requires": { - "@babel/helper-get-function-arity": "^7.0.0", - "@babel/template": "^7.1.0", - "@babel/types": "^7.0.0" + "@babel/helper-get-function-arity": "^7.10.4", + "@babel/template": "^7.10.4", + "@babel/types": "^7.10.4" } }, "@babel/helper-get-function-arity": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz", - "integrity": "sha512-r2DbJeg4svYvt3HOS74U4eWKsUAMRH01Z1ds1zx8KNTPtpTL5JAsdFv8BNyOpVqdFhHkkRDIg5B4AsxmkjAlmQ==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.4.tgz", + "integrity": "sha512-EkN3YDB+SRDgiIUnNgcmiD361ti+AVbL3f3Henf6dqqUyr5dMsorno0lJWJuLhDhkI5sYEpgj6y9kB8AOU1I2A==", "dev": true, "requires": { - "@babel/types": "^7.0.0" + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.11.0.tgz", + "integrity": "sha512-JbFlKHFntRV5qKw3YC0CvQnDZ4XMwgzzBbld7Ly4Mj4cbFy3KywcR8NtNctRToMWJOVvLINJv525Gd6wwVEx/Q==", + "dev": true, + "requires": { + "@babel/types": "^7.11.0" + } + }, + "@babel/helper-module-imports": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.10.4.tgz", + "integrity": "sha512-nEQJHqYavI217oD9+s5MUBzk6x1IlvoS9WTPfgG43CbMEeStE0v+r+TucWdx8KFGowPGvyOkDT9+7DHedIDnVw==", + "dev": true, + "requires": { + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-module-transforms": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.11.0.tgz", + "integrity": "sha512-02EVu8COMuTRO1TAzdMtpBPbe6aQ1w/8fePD2YgQmxZU4gpNWaL9gK3Jp7dxlkUlUCJOTaSeA+Hrm1BRQwqIhg==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.10.4", + "@babel/helper-replace-supers": "^7.10.4", + "@babel/helper-simple-access": "^7.10.4", + "@babel/helper-split-export-declaration": "^7.11.0", + "@babel/template": "^7.10.4", + "@babel/types": "^7.11.0", + "lodash": "^4.17.19" + } + }, + "@babel/helper-optimise-call-expression": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.10.4.tgz", + "integrity": "sha512-n3UGKY4VXwXThEiKrgRAoVPBMqeoPgHVqiHZOanAJCG9nQUL2pLRQirUzl0ioKclHGpGqRgIOkgcIJaIWLpygg==", + "dev": true, + "requires": { + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-replace-supers": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.10.4.tgz", + "integrity": "sha512-sPxZfFXocEymYTdVK1UNmFPBN+Hv5mJkLPsYWwGBxZAxaWfFu+xqp7b6qWD0yjNuNL2VKc6L5M18tOXUP7NU0A==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.10.4", + "@babel/helper-optimise-call-expression": "^7.10.4", + "@babel/traverse": "^7.10.4", + "@babel/types": "^7.10.4" + } + }, + "@babel/helper-simple-access": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.10.4.tgz", + "integrity": "sha512-0fMy72ej/VEvF8ULmX6yb5MtHG4uH4Dbd6I/aHDb/JVg0bbivwt9Wg+h3uMvX+QSFtwr5MeItvazbrc4jtRAXw==", + "dev": true, + "requires": { + "@babel/template": "^7.10.4", + "@babel/types": "^7.10.4" } }, "@babel/helper-split-export-declaration": { - "version": "7.4.4", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", - "integrity": "sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.11.0.tgz", + "integrity": "sha512-74Vejvp6mHkGE+m+k5vHY93FX2cAtrw1zXrZXRlG4l410Nm9PxfEiVTn1PjDPV5SnmieiueY4AFg2xqhNFuuZg==", "dev": true, "requires": { - "@babel/types": "^7.4.4" + "@babel/types": "^7.11.0" + } + }, + "@babel/helper-validator-identifier": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", + "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", + "dev": true + }, + "@babel/helpers": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.10.4.tgz", + "integrity": "sha512-L2gX/XeUONeEbI78dXSrJzGdz4GQ+ZTA/aazfUsFaWjSe95kiCuOZ5HsXvkiw3iwF+mFHSRUfJU8t6YavocdXA==", + "dev": true, + "requires": { + "@babel/template": "^7.10.4", + "@babel/traverse": "^7.10.4", + "@babel/types": "^7.10.4" } }, "@babel/highlight": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", - "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", "dev": true, "requires": { + "@babel/helper-validator-identifier": "^7.10.4", "chalk": "^2.0.0", - "esutils": "^2.0.2", "js-tokens": "^4.0.0" }, "dependencies": { @@ -88,46 +265,85 @@ } }, "@babel/parser": { - "version": "7.6.4", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.6.4.tgz", - "integrity": "sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.0.tgz", + "integrity": "sha512-qvRvi4oI8xii8NllyEc4MDJjuZiNaRzyb7Y7lup1NqJV8TZHF4O27CcP+72WPn/k1zkgJ6WJfnIbk4jTsVAZHw==", "dev": true }, "@babel/template": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.6.0.tgz", - "integrity": "sha512-5AEH2EXD8euCk446b7edmgFdub/qfH1SN6Nii3+fyXP807QRx9Q73A2N5hNwRRslC2H9sNzaFhsPubkS4L8oNQ==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.10.4.tgz", + "integrity": "sha512-ZCjD27cGJFUB6nmCB1Enki3r+L5kJveX9pq1SvAUKoICy6CZ9yD8xO086YXdYhvNjBdnekm4ZnaP5yC8Cs/1tA==", "dev": true, "requires": { - "@babel/code-frame": "^7.0.0", - "@babel/parser": "^7.6.0", - "@babel/types": "^7.6.0" - } - }, - "@babel/traverse": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.6.3.tgz", - "integrity": "sha512-unn7P4LGsijIxaAJo/wpoU11zN+2IaClkQAxcJWBNCMS6cmVh802IyLHNkAjQ0iYnRS3nnxk5O3fuXW28IMxTw==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.5.5", - "@babel/generator": "^7.6.3", - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-split-export-declaration": "^7.4.4", - "@babel/parser": "^7.6.3", - "@babel/types": "^7.6.3", - "debug": "^4.1.0", - "globals": "^11.1.0", - "lodash": "^4.17.13" + "@babel/code-frame": "^7.10.4", + "@babel/parser": "^7.10.4", + "@babel/types": "^7.10.4" }, "dependencies": { "@babel/code-frame": { - "version": "7.5.5", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", - "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", "dev": true, "requires": { - "@babel/highlight": "^7.0.0" + "@babel/highlight": "^7.10.4" + } + }, + "@babel/highlight": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + } + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + } + } + }, + "@babel/traverse": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.11.0.tgz", + "integrity": "sha512-ZB2V+LskoWKNpMq6E5UUCrjtDUh5IOTAyIl0dTjIEoXum/iKWkoIEKIRDnUucO6f+2FzNkE0oD4RLKoPIufDtg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.10.4", + "@babel/generator": "^7.11.0", + "@babel/helper-function-name": "^7.10.4", + "@babel/helper-split-export-declaration": "^7.11.0", + "@babel/parser": "^7.11.0", + "@babel/types": "^7.11.0", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.19" + }, + "dependencies": { + "@babel/code-frame": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", + "dev": true, + "requires": { + "@babel/highlight": "^7.10.4" + } + }, + "@babel/highlight": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" } }, "debug": { @@ -145,6 +361,12 @@ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -154,13 +376,13 @@ } }, "@babel/types": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.6.3.tgz", - "integrity": "sha512-CqbcpTxMcpuQTMhjI37ZHVgjBkysg5icREQIEZ0eG1yCNwg3oy+5AaLiOKmjsCj6nqOsa6Hf0ObjRVwokb7srA==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.11.0.tgz", + "integrity": "sha512-O53yME4ZZI0jO1EVGtF1ePGl0LHirG4P1ibcD80XyzZcKhcMFeCXmh4Xb1ifGBIV233Qg12x4rBfQgA+tmOukA==", "dev": true, "requires": { - "esutils": "^2.0.2", - "lodash": "^4.17.13", + "@babel/helper-validator-identifier": "^7.10.4", + "lodash": "^4.17.19", "to-fast-properties": "^2.0.0" }, "dependencies": { @@ -172,10 +394,77 @@ } } }, + "@istanbuljs/load-nyc-config": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", + "integrity": "sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==", + "dev": true, + "requires": { + "camelcase": "^5.3.1", + "find-up": "^4.1.0", + "get-package-type": "^0.1.0", + "js-yaml": "^3.13.1", + "resolve-from": "^5.0.0" + }, + "dependencies": { + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + } + } + }, + "@istanbuljs/schema": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.2.tgz", + "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", + "dev": true + }, + "@sindresorhus/is": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", + "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", + "dev": true + }, "@sinonjs/commons": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.4.0.tgz", - "integrity": "sha512-9jHK3YF/8HtJ9wCAbG+j8cD0i0+ATS9A7gXFqS36TblLPNy6rEEc+SB0imo91eCboGaBYGV/MT1/br/J+EE7Tw==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz", + "integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==", "dev": true, "requires": { "type-detect": "4.0.8" @@ -189,24 +478,32 @@ } } }, - "@sinonjs/formatio": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-2.0.0.tgz", - "integrity": "sha512-ls6CAMA6/5gG+O/IdsBcblvnd8qcO/l1TYoNeAzp3wcISOxlPXQEus0mLcdwazEkWjaBdaJ3TaxmNgCLWwvWzg==", + "@sinonjs/fake-timers": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz", + "integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==", "dev": true, "requires": { - "samsam": "1.3.0" + "@sinonjs/commons": "^1.7.0" } }, "@sinonjs/samsam": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.2.tgz", - "integrity": "sha512-ILO/rR8LfAb60Y1Yfp9vxfYAASK43NFC2mLzpvLUbCQY/Qu8YwReboseu8aheCEkyElZF2L2T9mHcR2bgdvZyA==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.1.tgz", + "integrity": "sha512-1Hc0b1TtyfBu8ixF/tpfSHTVWKwCBLY4QJbkgnE7HcwyvT2xArDxb4K7dMgqRm3szI+LJbzmW/s4xxEhv6hwDg==", "dev": true, "requires": { - "@sinonjs/commons": "^1.0.2", - "array-from": "^2.1.1", - "lodash": "^4.17.11" + "@sinonjs/commons": "^1.6.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + }, + "dependencies": { + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + } } }, "@sinonjs/text-encoding": { @@ -215,6 +512,15 @@ "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", "dev": true }, + "@szmarczak/http-timer": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", + "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", + "dev": true, + "requires": { + "defer-to-connect": "^1.0.1" + } + }, "@types/anymatch": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz", @@ -222,9 +528,9 @@ "dev": true }, "@types/bluebird": { - "version": "3.5.27", - "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.27.tgz", - "integrity": "sha512-6BmYWSBea18+tSjjSC3QIyV93ZKAeNWGM7R6aYt1ryTZXrlHF+QLV0G2yV0viEGVyRkyQsWfMoJ0k/YghBX5sQ==", + "version": "3.5.33", + "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.33.tgz", + "integrity": "sha512-ndEo1xvnYeHxm7I/5sF6tBvnsA4Tdi3zj1keRKRs12SP+2ye2A27NDJ1B6PqkfMbGAcT+mqQVqbZRIrhfOp5PQ==", "dev": true }, "@types/caseless": { @@ -234,127 +540,71 @@ "dev": true }, "@types/chai": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-3.5.2.tgz", - "integrity": "sha1-wRzSgX06QBt7oPWkIPNcVhObHB4=", + "version": "4.2.15", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.15.tgz", + "integrity": "sha512-rYff6FI+ZTKAPkJUoyz7Udq3GaoDZnxYDEvdEdFZASiA7PoErltHezDishqQiSDWrGxvxmplH304jyzQmjp0AQ==", "dev": true }, - "@types/events": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", - "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==", - "dev": true - }, - "@types/form-data": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz", - "integrity": "sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, - "@types/fs-extra": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.1.tgz", - "integrity": "sha512-h3wnflb+jMTipvbbZnClgA2BexrT4w0GcfoCz5qyxd0IRsbqhLSyesM6mqZTAnhbVmhyTm5tuxfRu9R+8l+lGw==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, - "@types/glob": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz", - "integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==", - "dev": true, - "requires": { - "@types/events": "*", - "@types/minimatch": "*", - "@types/node": "*" - } - }, - "@types/handlebars": { - "version": "4.0.36", - "resolved": "https://registry.npmjs.org/@types/handlebars/-/handlebars-4.0.36.tgz", - "integrity": "sha512-LjNiTX7TY7wtuC6y3QwC93hKMuqYhgV9A1uXBKNvZtVC8ZvyWAjZkJ5BvT0K7RKqORRYRLMrqCxpw5RgS+MdrQ==", - "dev": true - }, - "@types/highlight.js": { - "version": "9.12.2", - "resolved": "https://registry.npmjs.org/@types/highlight.js/-/highlight.js-9.12.2.tgz", - "integrity": "sha512-y5x0XD/WXDaGSyiTaTcKS4FurULJtSiYbGTeQd0m2LYZGBcZZ/7fM6t5H/DzeUF+kv8y6UfmF6yJABQsHcp9VQ==", + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, "@types/jszip": { - "version": "3.1.6", - "resolved": "https://registry.npmjs.org/@types/jszip/-/jszip-3.1.6.tgz", - "integrity": "sha512-m8uFcI+O2EupCfbEVQWsBM/4nhbegjOHL7cQgBpM95FeF98kdFJXzy9/8yhx4b3lCRl/gMBhcvyh30Qt3X+XPQ==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@types/jszip/-/jszip-3.4.1.tgz", + "integrity": "sha512-TezXjmf3lj+zQ651r6hPqvSScqBLvyPI9FxdXBqpEwBijNGQ2NXpaFW/7joGzveYkKQUil7iiDHLo6LV71Pc0A==", "requires": { - "@types/node": "*" + "jszip": "*" } }, - "@types/lodash": { - "version": "4.14.104", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.104.tgz", - "integrity": "sha512-ufQcVg4daO8xQ5kopxRHanqFdL4AI7ondQkV+2f+7mz3gvp0LkBx2zBRC6hfs3T87mzQFmf5Fck7Fi145Ul6NQ==", - "dev": true - }, - "@types/marked": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@types/marked/-/marked-0.3.0.tgz", - "integrity": "sha512-CSf9YWJdX1DkTNu9zcNtdCcn6hkRtB5ILjbhRId4ZOQqx30fXmdecuaXhugQL6eyrhuXtaHJ7PHI+Vm7k9ZJjg==", - "dev": true - }, - "@types/minimatch": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", - "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", - "dev": true - }, "@types/mocha": { - "version": "2.2.48", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz", - "integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw==", + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.1.tgz", + "integrity": "sha512-NysN+bNqj6E0Hv4CTGWSlPzMW6vTKjDpOteycDkV4IWBsO+PU48JonrPzV9ODjiI2XrjmA05KInLgF5ivZ/YGQ==", "dev": true }, "@types/node": { - "version": "12.0.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz", - "integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ==" + "version": "14.14.31", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.31.tgz", + "integrity": "sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==" }, "@types/request": { - "version": "2.48.1", - "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.1.tgz", - "integrity": "sha512-ZgEZ1TiD+KGA9LiAAPPJL68Id2UWfeSO62ijSXZjFJArVV+2pKcsVHmrcu+1oiE3q6eDGiFiSolRc4JHoerBBg==", + "version": "2.48.5", + "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.5.tgz", + "integrity": "sha512-/LO7xRVnL3DxJ1WkPGDQrp4VTV1reX9RkC85mJ+Qzykj2Bdw+mG15aAfDahc76HtknjzE16SX/Yddn6MxVbmGQ==", "dev": true, "requires": { "@types/caseless": "*", - "@types/form-data": "*", "@types/node": "*", - "@types/tough-cookie": "*" + "@types/tough-cookie": "*", + "form-data": "^2.5.0" + }, + "dependencies": { + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + } } }, "@types/request-promise": { - "version": "4.1.44", - "resolved": "https://registry.npmjs.org/@types/request-promise/-/request-promise-4.1.44.tgz", - "integrity": "sha512-RId7eFsUKxfal1LirDDIcOp9u3MM3NXFDBcC3sqIMcmu7f4U6DsCEMD8RbLZtnPrQlN5Jc79di/WPsIEDO4keg==", + "version": "4.1.47", + "resolved": "https://registry.npmjs.org/@types/request-promise/-/request-promise-4.1.47.tgz", + "integrity": "sha512-eRSZhAS8SMsrWOM8vbhxFGVZhTbWSJvaRKyufJTdIf4gscUouQvOBlfotPSPHbMR3S7kfkyKbhb1SWPmQdy3KQ==", "dev": true, "requires": { "@types/bluebird": "*", "@types/request": "*" } }, - "@types/shelljs": { - "version": "0.7.8", - "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.7.8.tgz", - "integrity": "sha512-M2giRw93PxKS7YjU6GZjtdV9HASdB7TWqizBXe4Ju7AqbKlWvTr0gNO92XH56D/gMxqD/jNHLNfC5hA34yGqrQ==", - "dev": true, - "requires": { - "@types/glob": "*", - "@types/node": "*" - } - }, "@types/shortid": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/shortid/-/shortid-0.0.29.tgz", @@ -362,45 +612,80 @@ "dev": true }, "@types/sinon": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-4.3.3.tgz", - "integrity": "sha512-Tt7w/ylBS/OEAlSCwzB0Db1KbxnkycP/1UkQpbvKFYoUuRn4uYsC3xh5TRPrOjTy0i8TIkSz1JdNL4GPVdf3KQ==", + "version": "9.0.10", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-9.0.10.tgz", + "integrity": "sha512-/faDC0erR06wMdybwI/uR8wEKV/E83T0k4sepIpB7gXuy2gzx2xiOjmztq6a2Y6rIGJ04D+6UU0VBmWy+4HEMA==", + "dev": true, + "requires": { + "@types/sinonjs__fake-timers": "*" + } + }, + "@types/sinonjs__fake-timers": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.2.tgz", + "integrity": "sha512-dIPoZ3g5gcx9zZEszaxLSVTvMReD3xxyyDnQUjA6IYDG9Ba2AV0otMPs+77sG9ojB4Qr2N2Vk5RnKeuA0X/0bg==", + "dev": true + }, + "@types/source-list-map": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz", + "integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==", "dev": true }, "@types/tapable": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.4.tgz", - "integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.6.tgz", + "integrity": "sha512-W+bw9ds02rAQaMvaLYxAbJ6cvguW/iJXNT6lTssS1ps6QdrMKttqEAMEG/b5CR8TZl3/L7/lH0ZV5nNR1LXikA==", "dev": true }, "@types/tough-cookie": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.5.tgz", - "integrity": "sha512-SCcK7mvGi3+ZNz833RRjFIxrn4gI1PPR3NtuIS+6vMkvmsGjosqTJwRt5bAEFLRz+wtJMWv8+uOnZf2hi2QXTg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.0.tgz", + "integrity": "sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==", "dev": true }, "@types/uglify-js": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.0.4.tgz", - "integrity": "sha512-SudIN9TRJ+v8g5pTG8RRCqfqTMNqgWCKKd3vtynhGzkIIjxaicNAMuY5TRadJ6tzDu3Dotf3ngaMILtmOdmWEQ==", + "version": "3.11.1", + "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.11.1.tgz", + "integrity": "sha512-7npvPKV+jINLu1SpSYVWG8KvyJBhBa8tmzMMdDoVc2pWUYHN8KIXlPJhjJ4LT97c4dXJA2SHL/q6ADbDriZN+Q==", "dev": true, "requires": { "source-map": "^0.6.1" } }, "@types/webpack": { - "version": "4.4.34", - "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.4.34.tgz", - "integrity": "sha512-GnEBgjHsfO1M7DIQ0dAupSofcmDItE3Zsu3reK8SQpl/6N0rtUQxUmQzVFAS5ou/FGjsYKjXAWfItLZ0kNFTfQ==", + "version": "4.41.26", + "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.26.tgz", + "integrity": "sha512-7ZyTfxjCRwexh+EJFwRUM+CDB2XvgHl4vfuqf1ZKrgGvcS5BrNvPQqJh3tsZ0P6h6Aa1qClVHaJZszLPzpqHeA==", "dev": true, "requires": { "@types/anymatch": "*", "@types/node": "*", "@types/tapable": "*", "@types/uglify-js": "*", + "@types/webpack-sources": "*", "source-map": "^0.6.0" } }, + "@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==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/source-list-map": "*", + "source-map": "^0.7.3" + }, + "dependencies": { + "source-map": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", + "dev": true + } + } + }, "acorn": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", @@ -424,6 +709,16 @@ } } }, + "aggregate-error": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", + "integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==", + "dev": true, + "requires": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + } + }, "ajv": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", @@ -465,18 +760,46 @@ } }, "ansi-align": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-2.0.0.tgz", - "integrity": "sha1-w2rsy6VjuJzrVW82kPCx2eNUf38=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz", + "integrity": "sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==", "dev": true, "requires": { - "string-width": "^2.0.0" + "string-width": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } } }, - "ansi-escapes": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz", - "integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4=", + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true }, "ansi-regex": { @@ -590,12 +913,12 @@ } }, "append-transform": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", - "integrity": "sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-2.0.0.tgz", + "integrity": "sha512-7yeyCEurROLQJFv5Xj4lEGTy0borxepjFv1g22oAdqFu//SrAlDl1O1Nxx15SH1RoliUml6p8dwJW9jvZughhg==", "dev": true, "requires": { - "default-require-extensions": "^2.0.0" + "default-require-extensions": "^3.0.0" } }, "archy": { @@ -604,6 +927,12 @@ "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", "dev": true }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -631,12 +960,6 @@ "integrity": "sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ=", "dev": true }, - "array-from": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", - "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", - "dev": true - }, "array-union": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", @@ -658,12 +981,6 @@ "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", "dev": true }, - "arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", - "dev": true - }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -741,12 +1058,24 @@ "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==", "dev": true }, + "async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", + "dev": true + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", "dev": true }, + "at-least-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", + "dev": true + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -775,9 +1104,9 @@ "dev": true }, "aws4": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", - "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.0.tgz", + "integrity": "sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA==", "dev": true }, "babel-code-frame": { @@ -851,17 +1180,6 @@ "babel-runtime": "^6.22.0" } }, - "babel-polyfill": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz", - "integrity": "sha1-g2TKYt+Or7gwSZ9pkXdGbDsDSZ0=", - "dev": true, - "requires": { - "babel-runtime": "^6.22.0", - "core-js": "^2.4.0", - "regenerator-runtime": "^0.10.0" - } - }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -1017,9 +1335,9 @@ "dev": true }, "bluebird": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", - "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==", + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", "dev": true }, "bn.js": { @@ -1029,25 +1347,113 @@ "dev": true }, "boxen": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz", - "integrity": "sha512-TNPjfTr432qx7yOjQyaXm3dSR0MH9vXp7eT1BFSl/C51g+EFnOR9hTg1IreahGBmDNCehscshe45f+C1TBZbLw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/boxen/-/boxen-4.2.0.tgz", + "integrity": "sha512-eB4uT9RGzg2odpER62bBwSLvUeGC+WbRjjyyFhGsKnc8wp/m0+hQsMUvUe3H2V0D5vw0nBdO1hCJoZo5mKeuIQ==", "dev": true, "requires": { - "ansi-align": "^2.0.0", - "camelcase": "^4.0.0", - "chalk": "^2.0.1", - "cli-boxes": "^1.0.0", - "string-width": "^2.0.0", - "term-size": "^1.2.0", - "widest-line": "^2.0.0" + "ansi-align": "^3.0.0", + "camelcase": "^5.3.1", + "chalk": "^3.0.0", + "cli-boxes": "^2.2.0", + "string-width": "^4.1.0", + "term-size": "^2.1.0", + "type-fest": "^0.8.1", + "widest-line": "^3.1.0" }, "dependencies": { - "camelcase": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", - "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } } } }, @@ -1225,48 +1631,70 @@ "unset-value": "^1.0.0" } }, - "caching-transform": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-3.0.2.tgz", - "integrity": "sha512-Mtgcv3lh3U0zRii/6qVgQODdPA4G3zhG+jtbCWj39RXuUFTMzH0vcdMtaJS1jPowd+It2Pqr6y3NJMQqOqCE2w==", + "cacheable-request": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", + "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", "dev": true, "requires": { - "hasha": "^3.0.0", - "make-dir": "^2.0.0", - "package-hash": "^3.0.0", - "write-file-atomic": "^2.4.2" + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^3.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^4.1.0", + "responselike": "^1.0.2" }, "dependencies": { - "make-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", - "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", "dev": true, "requires": { - "pify": "^4.0.1", - "semver": "^5.6.0" + "pump": "^3.0.0" } }, - "pify": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", - "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", "dev": true } } }, + "caching-transform": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz", + "integrity": "sha512-kpqOvwXnjjN44D89K5ccQC+RUrsy7jB/XLlRrx0D7/2HNcTPqzsb6XgYoErwko6QsV184CA2YgS1fxDiiDZMWA==", + "dev": true, + "requires": { + "hasha": "^5.0.0", + "make-dir": "^3.0.0", + "package-hash": "^4.0.0", + "write-file-atomic": "^3.0.0" + }, + "dependencies": { + "write-file-atomic": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", + "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", + "dev": true, + "requires": { + "imurmurhash": "^0.1.4", + "is-typedarray": "^1.0.0", + "signal-exit": "^3.0.2", + "typedarray-to-buffer": "^3.1.5" + } + } + } + }, "camelcase": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=", "dev": true }, - "capture-stack-trace": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz", - "integrity": "sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==", - "dev": true - }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -1305,12 +1733,6 @@ "supports-color": "^5.3.0" } }, - "chardet": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", - "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", - "dev": true - }, "chokidar": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz", @@ -1349,9 +1771,9 @@ } }, "ci-info": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.6.0.tgz", - "integrity": "sha512-vsGdkwSCDpWmP80ncATX7iea5DWQemg1UgCW5J8tqjU3lYw4FBYuj89J0CTVomA7BEfvSZd84GmHko+MxFQU2A==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", + "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", "dev": true }, "cipher-base": { @@ -1387,31 +1809,22 @@ } } }, - "cli-boxes": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-1.0.0.tgz", - "integrity": "sha1-T6kXw+WclKAEzWH47lCdplFocUM=", + "clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", "dev": true }, - "cli-cursor": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", - "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", - "dev": true, - "requires": { - "restore-cursor": "^2.0.0" - } - }, - "cli-width": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", - "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "cli-boxes": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.1.tgz", + "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", "dev": true }, "clipboard": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.4.tgz", - "integrity": "sha512-Vw26VSLRpJfBofiVaFb/I8PVfdI1OxKcYShe6fm0sP/DtmiWQNCjhM/okTvdCo0G+lMMm1rMYbk4IK4x1X+kgQ==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.6.tgz", + "integrity": "sha512-g5zbiixBRk/wyKakSwCKd7vQXDjFnAMGHoEyBogG/bw9kTD9GvdAvaoRR1ALcEzt3pVKxZR0pViekPMIS0QyGg==", "dev": true, "optional": true, "requires": { @@ -1453,6 +1866,15 @@ } } }, + "clone-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", + "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", + "dev": true, + "requires": { + "mimic-response": "^1.0.0" + } + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1491,9 +1913,9 @@ "dev": true }, "colors": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", - "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", "dev": true }, "combined-stream": { @@ -1542,17 +1964,17 @@ } }, "configstore": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/configstore/-/configstore-3.1.2.tgz", - "integrity": "sha512-vtv5HtGjcYUgFrXc6Kx747B83MRRVS5R1VTEQoXvuP+kMI+if6uywV0nDGoiydJRy4yk7h9od5Og0kxx4zUXmw==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz", + "integrity": "sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA==", "dev": true, "requires": { - "dot-prop": "^4.1.0", + "dot-prop": "^5.2.0", "graceful-fs": "^4.1.2", - "make-dir": "^1.0.0", - "unique-string": "^1.0.0", - "write-file-atomic": "^2.0.0", - "xdg-basedir": "^3.0.0" + "make-dir": "^3.0.0", + "unique-string": "^2.0.0", + "write-file-atomic": "^3.0.0", + "xdg-basedir": "^4.0.0" } }, "connect": { @@ -1615,16 +2037,15 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "cp-file": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/cp-file/-/cp-file-4.2.0.tgz", - "integrity": "sha1-cVNhZjtx7eC23dvDyA4roC5yXsM=", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/cp-file/-/cp-file-7.0.0.tgz", + "integrity": "sha512-0Cbj7gyvFVApzpK/uhCtQ/9kE9UnYpxMzaq5nQQC/Dh4iaj5fxp7iEFIullrYwzj8nf0qnsI1Qsx34hAeAebvw==", "dev": true, "requires": { "graceful-fs": "^4.1.2", - "make-dir": "^1.0.0", + "make-dir": "^3.0.0", "nested-error-stacks": "^2.0.0", - "pify": "^2.3.0", - "safe-buffer": "^5.0.1" + "p-event": "^4.1.0" } }, "create-ecdh": { @@ -1637,15 +2058,6 @@ "elliptic": "^6.0.0" } }, - "create-error-class": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", - "integrity": "sha1-Br56vvlHo/FKMP1hBnHUAbyot7Y=", - "dev": true, - "requires": { - "capture-stack-trace": "^1.0.0" - } - }, "create-hash": { "version": "1.2.0", "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", @@ -1673,6 +2085,12 @@ "sha.js": "^2.4.8" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -1704,9 +2122,9 @@ } }, "crypto-random-string": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz", - "integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", + "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==", "dev": true }, "cycle": { @@ -1761,6 +2179,15 @@ "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", "dev": true }, + "decompress-response": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", + "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", + "dev": true, + "requires": { + "mimic-response": "^1.0.0" + } + }, "deep-eql": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", @@ -1791,22 +2218,28 @@ "dev": true }, "default-require-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-2.0.0.tgz", - "integrity": "sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.0.tgz", + "integrity": "sha512-ek6DpXq/SCpvjhpFsLFRVtIxJCRw6fUR42lYMVZuUMK7n8eMz4Uh5clckdBjEpLhn/gEBZo7hDJnJcwdKLKQjg==", "dev": true, "requires": { - "strip-bom": "^3.0.0" + "strip-bom": "^4.0.0" }, "dependencies": { "strip-bom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-4.0.0.tgz", + "integrity": "sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==", "dev": true } } }, + "defer-to-connect": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", + "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", + "dev": true + }, "define-property": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/define-property/-/define-property-2.0.2.tgz", @@ -1910,168 +2343,228 @@ } }, "docsify": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/docsify/-/docsify-4.9.4.tgz", - "integrity": "sha512-Xtm6sfrNU7cqOViWMewDhscn0cySF60q2KTKok9OaPmzt6nRkTAIvYU4dj916IT21o/b336Or3vO2hsvmaQzxg==", + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/docsify/-/docsify-4.12.0.tgz", + "integrity": "sha512-oLr48dLeJ8sTVQfL8HLFqd2sPPG8DNAOvYAXXJQr/+/K9uC2KDhoeu+GGj5U2uFGR5czF3oLvqNBxhEElg1wGw==", "dev": true, "requires": { - "marked": "^0.5.1", - "medium-zoom": "^0.4.0", - "opencollective": "^1.0.3", - "prismjs": "^1.15.0", - "tinydate": "^1.0.0", + "dompurify": "^2.2.6", + "marked": "^1.2.9", + "medium-zoom": "^1.0.6", + "opencollective-postinstall": "^2.0.2", + "prismjs": "^1.23.0", + "strip-indent": "^3.0.0", + "tinydate": "^1.3.0", "tweezer.js": "^1.4.0" + }, + "dependencies": { + "dompurify": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.6.tgz", + "integrity": "sha512-7b7ZArhhH0SP6W2R9cqK6RjaU82FZ2UPM7RO8qN1b1wyvC/NY1FNWcX1Pu00fFOAnzEORtwXe4bPaClg6pUybQ==", + "dev": true + }, + "marked": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/marked/-/marked-1.2.9.tgz", + "integrity": "sha512-H8lIX2SvyitGX+TRdtS06m1jHMijKN/XjfH6Ooii9fvxMlh8QdqBfBDkGUpMWH2kQNrtixjzYUa3SH8ROTgRRw==", + "dev": true + }, + "prismjs": { + "version": "1.23.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.23.0.tgz", + "integrity": "sha512-c29LVsqOaLbBHuIbsTxaKENh1N2EQBOHaWv7gkHN4dgRbxSREqDnDbtFJYdpPauS4YCplMSNCABQ6Eeor69bAA==", + "dev": true, + "requires": { + "clipboard": "^2.0.0" + } + } } }, "docsify-cli": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/docsify-cli/-/docsify-cli-4.3.0.tgz", - "integrity": "sha512-88O1sMeoZv4lb5GPSJzDtOAv2KzBjpQaSqVlVqY+6hGJfb2wpz9PvlUhvlgPq54zu4kPDeCCyUYgqa/llhKg3w==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/docsify-cli/-/docsify-cli-4.4.2.tgz", + "integrity": "sha512-iCTRyKjjNiSroo5cgVkb/C86PsUEEsVV30PXp5GkzbcMG+mMxzBPmJ/8xukTLoeaQddEsSeSWW376eC2t4KQJw==", "dev": true, "requires": { - "chalk": "^1.1.3", + "chalk": "^2.4.2", "connect": "^3.6.0", "connect-livereload": "^0.6.0", - "cp-file": "^4.1.1", - "docsify": ">=3", + "cp-file": "^7.0.0", + "docsify": "^4.10.2", "docsify-server-renderer": ">=4", - "fs-extra": "^2.1.2", - "livereload": "^0.7.0", - "lru-cache": "^4.1.1", - "opn": "^5.3.0", + "enquirer": "^2.3.6", + "fs-extra": "^8.1.0", + "get-port": "^5.0.0", + "livereload": "^0.9.1", + "lru-cache": "^5.1.1", + "open": "^6.4.0", "serve-static": "^1.12.1", - "update-notifier": "^2.1.0", - "y18n": "^3.2.1", + "update-notifier": "^4.1.0", "yargonaut": "^1.1.2", - "yargs": "^7.0.2" + "yargs": "^14.2.0" }, "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", "dev": true, "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" } }, - "fs-extra": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-2.1.2.tgz", - "integrity": "sha1-BGxwFjzvmq1GsOSn+kZ/si1x3jU=", + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", "dev": true, "requires": { - "graceful-fs": "^4.1.2", - "jsonfile": "^2.1.0" + "locate-path": "^3.0.0" } }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true + }, + "lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", "dev": true, "requires": { - "number-is-nan": "^1.0.0" + "yallist": "^3.0.2" } }, - "jsonfile": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.6" - } - }, - "opn": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/opn/-/opn-5.5.0.tgz", - "integrity": "sha512-PqHpggC9bLV0VeWcdKhkpxY+3JTzetLSqTCWL/z/tFIbI6G8JCjondXklT1JinczLz2Xib62sSp0T/gKT4KksA==", - "dev": true, - "requires": { - "is-wsl": "^1.1.0" - } + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true }, "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" } }, - "supports-color": { + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + }, + "which-module": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "dev": true + }, + "wrap-ansi": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + } + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "dev": true + }, + "yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", "dev": true }, "yargs": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz", - "integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-14.2.3.tgz", + "integrity": "sha512-ZbotRWhF+lkjijC/VhmOT9wSgyBQ7+zr13+YLkhfsSiTriYsMzkTUFP18pFhWwBeMa5gUc1MzbhrO6/VB7c9Xg==", "dev": true, "requires": { - "camelcase": "^3.0.0", - "cliui": "^3.2.0", - "decamelize": "^1.1.1", - "get-caller-file": "^1.0.1", - "os-locale": "^1.4.0", - "read-pkg-up": "^1.0.1", + "cliui": "^5.0.0", + "decamelize": "^1.2.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", "require-directory": "^2.1.1", - "require-main-filename": "^1.0.1", + "require-main-filename": "^2.0.0", "set-blocking": "^2.0.0", - "string-width": "^1.0.2", - "which-module": "^1.0.0", - "y18n": "^3.2.1", - "yargs-parser": "^5.0.0" + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^15.0.1" } }, "yargs-parser": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.0.tgz", - "integrity": "sha1-J17PDX/+Bcd+ZOfIbkzZS/DhIoo=", + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.1.tgz", + "integrity": "sha512-0OAMV2mAZQrs3FkNpDQcBk1x5HXb8X4twADss4S0Iuk+2dGnLOE/fRHrsYm542GduMveyA77OF4wrNJuanRCWw==", "dev": true, "requires": { - "camelcase": "^3.0.0" + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" } } } }, "docsify-server-renderer": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/docsify-server-renderer/-/docsify-server-renderer-4.9.1.tgz", - "integrity": "sha512-JERMD3yEJq38nSim/o1VGBoyqxsRo1VRscafpkx3mT7g07orOg5UARUgztKQNmv+0xnkWsmu+BMr9nsurXmBMQ==", + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/docsify-server-renderer/-/docsify-server-renderer-4.11.6.tgz", + "integrity": "sha512-IAEM+kKsDfo1qnrEdaBH5pCQFjAWA7B7jWWmfCKzDA/BPcHO+zCR4++Mw/NPR/huJKU58AzuGtEJ/NhF/l0Y6Q==", "dev": true, "requires": { - "debug": "^2.6.8", - "docsify": "^4.8.0", - "node-fetch": "^1.7.0", - "resolve-pathname": "^2.1.0" + "debug": "^4.1.1", + "docsify": "^4.11.4", + "dompurify": "^2.0.8", + "node-fetch": "^2.6.0", + "resolve-pathname": "^3.0.0" }, "dependencies": { - "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", "dev": true, "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" + "ms": "2.1.2" } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true } } }, @@ -2081,13 +2574,19 @@ "integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==", "dev": true }, + "dompurify": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.2.tgz", + "integrity": "sha512-BsGR4nDLaC5CNBnyT5I+d5pOeaoWvgVeg6Gq/aqmKYWMPR07131u60I80BvExLAJ0FQEIBQ1BTicw+C5+jOyrg==", + "dev": true + }, "dot-prop": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", - "integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", "dev": true, "requires": { - "is-obj": "^1.0.0" + "is-obj": "^2.0.0" } }, "duplexer3": { @@ -2113,9 +2612,9 @@ "dev": true }, "elliptic": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz", - "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", + "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", "dev": true, "requires": { "bn.js": "^4.4.0", @@ -2145,15 +2644,6 @@ "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", "dev": true }, - "encoding": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", - "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", - "dev": true, - "requires": { - "iconv-lite": "~0.4.13" - } - }, "end-of-stream": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", @@ -2175,6 +2665,15 @@ "tapable": "^0.2.5" } }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + } + }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -2270,6 +2769,12 @@ "es6-symbol": "^3.1.1" } }, + "escape-goat": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", + "integrity": "sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==", + "dev": true + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -2496,17 +3001,6 @@ } } }, - "external-editor": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", - "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", - "dev": true, - "requires": { - "chardet": "^0.4.0", - "iconv-lite": "^0.4.17", - "tmp": "^0.0.33" - } - }, "extglob": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz", @@ -2597,20 +3091,11 @@ "dev": true }, "figlet": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.2.3.tgz", - "integrity": "sha512-+F5zdvZ66j77b8x2KCPvWUHC0UCKUMWrewxmewgPlagp3wmDpcrHMbyv/ygq/6xoxBPGQA+UJU3SMoBzKoROQQ==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.5.0.tgz", + "integrity": "sha512-ZQJM4aifMpz6H19AW1VqvZ7l4pOE9p7i/3LyxgO2kp+PO/VcDYNqIHEMtkccqIhTXMKci4kjueJr/iCQEaT/Ww==", "dev": true }, - "figures": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", - "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", - "dev": true, - "requires": { - "escape-string-regexp": "^1.0.5" - } - }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", @@ -2656,32 +3141,14 @@ } }, "find-cache-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", - "integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", + "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", "dev": true, "requires": { "commondir": "^1.0.1", - "make-dir": "^2.0.0", - "pkg-dir": "^3.0.0" - }, - "dependencies": { - "make-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", - "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", - "dev": true, - "requires": { - "pify": "^4.0.1", - "semver": "^5.6.0" - } - }, - "pify": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", - "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", - "dev": true - } + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" } }, "find-up": { @@ -2710,23 +3177,54 @@ } }, "foreground-child": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz", - "integrity": "sha1-T9ca0t/elnibmApcCilZN8svXOk=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", + "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", "dev": true, "requires": { - "cross-spawn": "^4", - "signal-exit": "^3.0.0" + "cross-spawn": "^7.0.0", + "signal-exit": "^3.0.2" }, "dependencies": { "cross-spawn": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", - "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "requires": { - "lru-cache": "^4.0.1", - "which": "^1.2.9" + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" } } } @@ -2763,13 +3261,19 @@ "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", "dev": true }, + "fromentries": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.2.1.tgz", + "integrity": "sha512-Xu2Qh8yqYuDhQGOhD5iJGninErSfI9A3FrriD3tjUgV5VbJFeH8vfgZ9HnC6jWN80QDVNQK5vmxRAmEAp7Mevw==", + "dev": true + }, "fs-extra": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-5.0.0.tgz", - "integrity": "sha512-66Pm4RYbjzdyeuqudYqhFiNBbCIuI9kgRqLPSHIlXHidW8NIQtVdkM1yeZ4lXwuhbTETv3EUGMNHAAw6hiundQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", "dev": true, "requires": { - "graceful-fs": "^4.1.2", + "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", "universalify": "^0.1.0" } @@ -3001,13 +3505,6 @@ "dev": true, "optional": true }, - "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true, - "optional": true - }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -3394,12 +3891,30 @@ } } }, + "gensync": { + "version": "1.0.0-beta.1", + "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.1.tgz", + "integrity": "sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg==", + "dev": true + }, "get-caller-file": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", "dev": true }, + "get-package-type": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", + "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", + "dev": true + }, + "get-port": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-5.1.1.tgz", + "integrity": "sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==", + "dev": true + }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", @@ -3425,9 +3940,9 @@ } }, "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -3496,12 +4011,12 @@ } }, "global-dirs": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-0.1.1.tgz", - "integrity": "sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-2.0.1.tgz", + "integrity": "sha512-5HqUqdhkEovj2Of/ms3IeS/EekcO54ytHRLV4PEY2rhRwrHXLQjeVEES0Lhka0xwNDtGYn58wyC4s5+MHsOO6A==", "dev": true, "requires": { - "ini": "^1.3.4" + "ini": "^1.3.5" } }, "globals": { @@ -3534,30 +4049,22 @@ } }, "got": { - "version": "6.7.1", - "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", - "integrity": "sha1-JAzQV4WpoY5WHcG0S0HHY+8ejbA=", + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", + "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", "dev": true, "requires": { - "create-error-class": "^3.0.0", + "@sindresorhus/is": "^0.14.0", + "@szmarczak/http-timer": "^1.1.2", + "cacheable-request": "^6.0.0", + "decompress-response": "^3.3.0", "duplexer3": "^0.1.4", - "get-stream": "^3.0.0", - "is-redirect": "^1.0.0", - "is-retry-allowed": "^1.0.0", - "is-stream": "^1.0.0", - "lowercase-keys": "^1.0.0", - "safe-buffer": "^5.0.1", - "timed-out": "^4.0.0", - "unzip-response": "^2.0.1", - "url-parse-lax": "^1.0.0" - }, - "dependencies": { - "get-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", - "dev": true - } + "get-stream": "^4.1.0", + "lowercase-keys": "^1.0.1", + "mimic-response": "^1.0.1", + "p-cancelable": "^1.0.0", + "to-readable-stream": "^1.0.0", + "url-parse-lax": "^3.0.0" } }, "graceful-fs": { @@ -3573,15 +4080,24 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", "dev": true, "requires": { + "minimist": "^1.2.5", "neo-async": "^2.6.0", - "optimist": "^0.6.1", "source-map": "^0.6.1", - "uglify-js": "^3.1.4" + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + } } }, "har-schema": { @@ -3601,21 +4117,21 @@ }, "dependencies": { "ajv": { - "version": "6.10.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.1.tgz", - "integrity": "sha512-w1YQaVGNC6t2UCPjEawK/vo/dG8OOrVtUmhBT1uJJYxbl5kU2Tj3v6LGqBcsysN1yhuCStJCCA3GqdvKY8sqXQ==", + "version": "6.12.3", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", + "integrity": "sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==", "dev": true, "requires": { - "fast-deep-equal": "^2.0.1", + "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, "json-schema-traverse": { @@ -3673,6 +4189,12 @@ } } }, + "has-yarn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", + "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==", + "dev": true + }, "hash-base": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", @@ -3694,12 +4216,27 @@ } }, "hasha": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/hasha/-/hasha-3.0.0.tgz", - "integrity": "sha1-UqMvq4Vp1BymmmH/GiFPjrfIvTk=", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.0.tgz", + "integrity": "sha512-2W+jKdQbAdSIrggA8Q35Br8qKadTrqCTC8+XZvBWepKDK6m9XkX6Iz1a2yh2KP01kzAR/dpuMeUnocoLYDcskw==", "dev": true, "requires": { - "is-stream": "^1.0.1" + "is-stream": "^2.0.0", + "type-fest": "^0.8.0" + }, + "dependencies": { + "is-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz", + "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==", + "dev": true + }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + } } }, "he": { @@ -3708,12 +4245,6 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, - "highlight.js": { - "version": "9.15.8", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.15.8.tgz", - "integrity": "sha512-RrapkKQWwE+wKdF73VsOa2RQdIoO3mxwJ4P8mhbI6KYJUraUHRKM5w5zQQKXNk0xNL4UVRdulV9SBJcmzJNzVA==", - "dev": true - }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -3731,6 +4262,18 @@ "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, + "html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + }, + "http-cache-semantics": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", + "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==", + "dev": true + }, "http-errors": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", @@ -3767,15 +4310,6 @@ "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0=", "dev": true }, - "iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, - "requires": { - "safer-buffer": ">= 2.1.2 < 3" - } - }, "ieee754": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", @@ -3799,6 +4333,12 @@ "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, + "indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -3815,59 +4355,11 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, - "inquirer": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.0.6.tgz", - "integrity": "sha1-4EqqnQW3o8ubD0B9BDdfBEcZA0c=", - "dev": true, - "requires": { - "ansi-escapes": "^1.1.0", - "chalk": "^1.0.0", - "cli-cursor": "^2.1.0", - "cli-width": "^2.0.0", - "external-editor": "^2.0.1", - "figures": "^2.0.0", - "lodash": "^4.3.0", - "mute-stream": "0.0.7", - "run-async": "^2.2.0", - "rx": "^4.1.0", - "string-width": "^2.0.0", - "strip-ansi": "^3.0.0", - "through": "^2.3.6" - }, - "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - } - } - }, "interpret": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", @@ -3931,12 +4423,12 @@ "dev": true }, "is-ci": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz", - "integrity": "sha512-s6tfsaQaQi3JNciBH6shVqEDvhGut0SUXr31ag8Pd8BBbVVlcGfWhpPmEOoM6RJ5TFhbypvf5yyRw/VXW1IiWg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", + "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", "dev": true, "requires": { - "ci-info": "^1.5.0" + "ci-info": "^2.0.0" } }, "is-data-descriptor": { @@ -4038,19 +4530,19 @@ } }, "is-installed-globally": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.1.0.tgz", - "integrity": "sha1-Df2Y9akRFxbdU13aZJL2e/PSWoA=", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.3.2.tgz", + "integrity": "sha512-wZ8x1js7Ia0kecP/CHM/3ABkAmujX7WPvQk6uu3Fly/Mk44pySulQpnHG46OMjHGXApINnV4QhY3SWnECO2z5g==", "dev": true, "requires": { - "global-dirs": "^0.1.0", - "is-path-inside": "^1.0.0" + "global-dirs": "^2.0.1", + "is-path-inside": "^3.0.1" } }, "is-npm": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-1.0.0.tgz", - "integrity": "sha1-8vtjpl5JBbQGyGBydloaTceTufQ=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-4.0.0.tgz", + "integrity": "sha512-96ECIfh9xtDDlPylNPXhzjsykHsMJZ18ASpaWzQyBr4YRTcVjUvzaHayDAES2oU/3KpljhHUjtSRNiDwi0F0ig==", "dev": true }, "is-number": { @@ -4074,19 +4566,16 @@ } }, "is-obj": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", - "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", "dev": true }, "is-path-inside": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-1.0.1.tgz", - "integrity": "sha1-jvW33lBDej/cprToZe96pVy0gDY=", - "dev": true, - "requires": { - "path-is-inside": "^1.0.1" - } + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.2.tgz", + "integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==", + "dev": true }, "is-plain-object": { "version": "2.0.4", @@ -4109,24 +4598,6 @@ "integrity": "sha1-IHurkWOEmcB7Kt8kCkGochADRXU=", "dev": true }, - "is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", - "dev": true - }, - "is-redirect": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz", - "integrity": "sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ=", - "dev": true - }, - "is-retry-allowed": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz", - "integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=", - "dev": true - }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -4157,6 +4628,12 @@ "integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=", "dev": true }, + "is-yarn-global": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz", + "integrity": "sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==", + "dev": true + }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -4199,12 +4676,12 @@ "dev": true }, "istanbul-lib-hook": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-2.0.7.tgz", - "integrity": "sha512-vrRztU9VRRFDyC+aklfLoeXyNdTfga2EI3udDGn4cZ6fpSXpHLV9X6CHvfoMCPtggg8zvDDmC4b9xfu0z6/llA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-3.0.0.tgz", + "integrity": "sha512-Pt/uge1Q9s+5VAZ+pCo16TYMWPBIl+oaNIjgLQxcX0itS6ueeaA+pEfThZpH8WxhFgCiEb8sAJY6MdUKgiIWaQ==", "dev": true, "requires": { - "append-transform": "^1.0.0" + "append-transform": "^2.0.0" } }, "istanbul-lib-instrument": { @@ -4222,60 +4699,127 @@ "semver": "^5.3.0" } }, - "istanbul-lib-report": { - "version": "2.0.8", - "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-2.0.8.tgz", - "integrity": "sha512-fHBeG573EIihhAblwgxrSenp0Dby6tJMFR/HvlerBsrCTD5bkUuoNtn3gVh29ZCS824cGGBPn7Sg7cNk+2xUsQ==", + "istanbul-lib-processinfo": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-processinfo/-/istanbul-lib-processinfo-2.0.2.tgz", + "integrity": "sha512-kOwpa7z9hme+IBPZMzQ5vdQj8srYgAtaRqeI48NGmAQ+/5yKiHLV0QbYqQpxsdEF0+w14SoB8YbnHKcXE2KnYw==", "dev": true, "requires": { - "istanbul-lib-coverage": "^2.0.5", - "make-dir": "^2.1.0", - "supports-color": "^6.1.0" + "archy": "^1.0.0", + "cross-spawn": "^7.0.0", + "istanbul-lib-coverage": "^3.0.0-alpha.1", + "make-dir": "^3.0.0", + "p-map": "^3.0.0", + "rimraf": "^3.0.0", + "uuid": "^3.3.3" }, "dependencies": { - "istanbul-lib-coverage": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", - "integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==", - "dev": true - }, - "make-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", - "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "requires": { - "pify": "^4.0.1", - "semver": "^5.6.0" + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" } }, - "pify": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", - "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "istanbul-lib-coverage": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", + "dev": true + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "dev": true + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + } + } + }, + "istanbul-lib-report": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", + "integrity": "sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==", + "dev": true, + "requires": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^3.0.0", + "supports-color": "^7.1.0" + }, + "dependencies": { + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "istanbul-lib-coverage": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", "dev": true }, "supports-color": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", - "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" } } } }, "istanbul-lib-source-maps": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.6.tgz", - "integrity": "sha512-R47KzMtDJH6X4/YW9XTx+jrLnZnscW4VpNN+1PViSYTejLVPWv7oov+Duf8YQSPyVRUvueQqz1TcsC6mooZTXw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-4.0.0.tgz", + "integrity": "sha512-c16LpFRkR8vQXyHZ5nLpY35JZtzj1PQY1iZmesUbf1FZHbIupcWfjgOXBY9YHkLEQ6puz1u4Dgj6qmU/DisrZg==", "dev": true, "requires": { "debug": "^4.1.1", - "istanbul-lib-coverage": "^2.0.5", - "make-dir": "^2.1.0", - "rimraf": "^2.6.3", + "istanbul-lib-coverage": "^3.0.0", "source-map": "^0.6.1" }, "dependencies": { @@ -4289,42 +4833,27 @@ } }, "istanbul-lib-coverage": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", - "integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", "dev": true }, - "make-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", - "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", - "dev": true, - "requires": { - "pify": "^4.0.1", - "semver": "^5.6.0" - } - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true - }, - "pify": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", - "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", - "dev": true } } }, "istanbul-reports": { - "version": "2.2.6", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.2.6.tgz", - "integrity": "sha512-SKi4rnMyLBKe0Jy2uUdx28h8oG7ph2PPuQPvIAh31d+Ci+lSiEu4C+h3oBPuJ9+mPKhOyW0M8gY4U5NM1WLeXA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.0.2.tgz", + "integrity": "sha512-9tZvz7AiR3PEDNGiV9vIouQ/EAcqMXFmkcA1CDFTwOB98OZVDL0PH9glHotf5Ugp6GCOTypfzGWI/OqjWNCRUw==", "dev": true, "requires": { - "handlebars": "^4.1.2" + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" } }, "js-tokens": { @@ -4351,22 +4880,22 @@ }, "jsesc": { "version": "1.3.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=", "dev": true }, + "json-buffer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", + "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", + "dev": true + }, "json-loader": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/json-loader/-/json-loader-0.5.7.tgz", "integrity": "sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w==", "dev": true }, - "json-parse-better-errors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", - "dev": true - }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -4416,9 +4945,9 @@ } }, "jszip": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.2.2.tgz", - "integrity": "sha512-NmKajvAFQpbg3taXQXr/ccS2wcucR1AZ+NtyWp2Nq7HHVsXhcJFR8p0Baf32C2yVvBylFWVeKf+WI2AnvlPhpA==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.6.0.tgz", + "integrity": "sha512-jgnQoG9LKnWO3mnVNBnfhkh0QknICd1FGSrXcgrl67zioyJ4wgx25o9ZqwNtrROSflGBCGYnJfjrIyRIby1OoQ==", "requires": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -4427,11 +4956,20 @@ } }, "just-extend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz", - "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.1.1.tgz", + "integrity": "sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==", "dev": true }, + "keyv": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", + "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", + "dev": true, + "requires": { + "json-buffer": "3.0.0" + } + }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", @@ -4439,12 +4977,12 @@ "dev": true }, "latest-version": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-3.1.0.tgz", - "integrity": "sha1-ogU4P+oyKzO1rjsYq+4NwvNW7hU=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", + "integrity": "sha512-weT+r0kTkRQdCdYCNtkMwWXQTMEswKrFBkm4ckQOMVhhqhIMI1UT2hMj+1iigIhgSZm5gTmrRXBNoGUgaTY1xA==", "dev": true, "requires": { - "package-json": "^4.0.0" + "package-json": "^6.3.0" } }, "lazy-cache": { @@ -4471,16 +5009,130 @@ } }, "livereload": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/livereload/-/livereload-0.7.0.tgz", - "integrity": "sha512-PHnIGczQEvmCctDvRTWylA+1wSwE0/eFm+LkNhlmlAFus/aCRlVE97UOLOf6TUGLmZyfg7z7twG37ZiOgNJAyQ==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/livereload/-/livereload-0.9.1.tgz", + "integrity": "sha512-9g7sua11kkyZNo2hLRCG3LuZZwqexoyEyecSlV8cAsfAVVCZqLzVir6XDqmH0r+Vzgnd5LrdHDMyjtFnJQLAYw==", "dev": true, "requires": { - "chokidar": "^1.7.0", + "chokidar": "^3.3.0", + "livereload-js": "^3.1.0", "opts": ">= 1.2.0", - "ws": "^1.1.5" + "ws": "^6.2.1" + }, + "dependencies": { + "anymatch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", + "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "dev": true, + "requires": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + } + }, + "binary-extensions": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.1.0.tgz", + "integrity": "sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ==", + "dev": true + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "chokidar": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.3.tgz", + "integrity": "sha512-DtM3g7juCXQxFVSNPNByEC2+NImtBuxQQvWlHunpJIS5Ocr0lG306cC7FCi7cEA0fzmybPUIl4txBIobk1gGOQ==", + "dev": true, + "requires": { + "anymatch": "~3.1.1", + "braces": "~3.0.2", + "fsevents": "~2.1.2", + "glob-parent": "~5.1.0", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.5.0" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true + }, + "readdirp": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", + "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", + "dev": true, + "requires": { + "picomatch": "^2.2.1" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } } }, + "livereload-js": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/livereload-js/-/livereload-js-3.3.1.tgz", + "integrity": "sha512-CBu1gTEfzVhlOK1WASKAAJ9Qx1fHECTq0SUB67sfxwQssopTyvzqTlgl+c0h9pZ6V+Fzd2rc510ppuNusg9teQ==", + "dev": true + }, "load-json-file": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", @@ -4530,9 +5182,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash.assign": { @@ -4553,12 +5205,6 @@ "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, - "lolex": { - "version": "2.7.5", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.5.tgz", - "integrity": "sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q==", - "dev": true - }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -4590,27 +5236,33 @@ "yallist": "^2.1.2" } }, + "lunr": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", + "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", + "dev": true + }, "make-dir": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", - "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", "dev": true, "requires": { - "pify": "^3.0.0" + "semver": "^6.0.0" }, "dependencies": { - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", "dev": true } } }, "make-error": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", - "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, "map-age-cleaner": { @@ -4638,9 +5290,9 @@ } }, "marked": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.5.2.tgz", - "integrity": "sha512-fdZvBa7/vSQIZCi4uuwo2N3q+7jJURpMVCcbaX0S1Mg65WZ5ilXvC67MviJAsdjqqgD+CEq4RKo5AYGgINkVAA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-2.0.1.tgz", + "integrity": "sha512-5+/fKgMv2hARmMW7DOpykr2iLhl0NgjyELk5yn92iE7z8Se1IS9n3UsFm86hFXIkvMBmVxki8+ckcpjBeyo/hw==", "dev": true }, "math-random": { @@ -4661,9 +5313,9 @@ } }, "medium-zoom": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-0.4.0.tgz", - "integrity": "sha512-0z7yMfd6I1BTCAa8QaR4cp5AqDkQD571GzhHIbbfefKEssGLSvs+4Xai/itOAncm4FBlF5gUoMQ22yW9/f8Sig==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-1.0.6.tgz", + "integrity": "sha512-UdiUWfvz9fZMg1pzf4dcuqA0W079o0mpqbTnOz5ip4VGYX96QjmbM+OgOU/0uOzAytxC0Ny4z+VcYQnhdifimg==", "dev": true }, "mem": { @@ -4695,15 +5347,6 @@ "readable-stream": "^2.0.1" } }, - "merge-source-map": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/merge-source-map/-/merge-source-map-1.1.0.tgz", - "integrity": "sha512-Qkcp7P2ygktpMPh2mCQZaf3jhN6D3Z/qVZHSdWvQ+2Ef5HgRAPBO57A77+ENm0CPx2+1Ce/MYKi3ymqdfuqibw==", - "dev": true, - "requires": { - "source-map": "^0.6.1" - } - }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -4742,18 +5385,18 @@ "dev": true }, "mime-db": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", - "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", "dev": true }, "mime-types": { - "version": "2.1.24", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", - "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", "dev": true, "requires": { - "mime-db": "1.40.0" + "mime-db": "1.44.0" } }, "mimic-fn": { @@ -4762,6 +5405,18 @@ "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, + "mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", + "dev": true + }, + "min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true + }, "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -4929,9 +5584,9 @@ "dev": true }, "mute-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", - "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, "nan": { @@ -4942,9 +5597,9 @@ "optional": true }, "nanoid": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.6.tgz", - "integrity": "sha512-2NDzpiuEy3+H0AVtdt8LoFi7PnqkOnIzYmJQp7xsEU6VexLluHQwKREuiz57XaQC5006seIadPrIZJhyS2n7aw==" + "version": "2.1.11", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz", + "integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==" }, "nanomatch": { "version": "1.2.13", @@ -4996,45 +5651,23 @@ "dev": true }, "nise": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.0.tgz", - "integrity": "sha512-Z3sfYEkLFzFmL8KY6xnSJLRxwQwYBjOXi/24lb62ZnZiGA0JUzGGTI6TBIgfCSMIDl9Jlu8SRmHNACLTemDHww==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz", + "integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==", "dev": true, "requires": { - "@sinonjs/formatio": "^3.1.0", + "@sinonjs/commons": "^1.7.0", + "@sinonjs/fake-timers": "^6.0.0", "@sinonjs/text-encoding": "^0.7.1", "just-extend": "^4.0.2", - "lolex": "^4.1.0", "path-to-regexp": "^1.7.0" - }, - "dependencies": { - "@sinonjs/formatio": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.1.tgz", - "integrity": "sha512-tsHvOB24rvyvV2+zKMmPkZ7dXX6LSLKZ7aOtXY6Edklp0uRcgGpOsQTTGTcWViFyx4uhWc6GV8QdnALbIbIdeQ==", - "dev": true, - "requires": { - "@sinonjs/commons": "^1", - "@sinonjs/samsam": "^3.1.0" - } - }, - "lolex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.1.0.tgz", - "integrity": "sha512-BYxIEXiVq5lGIXeVHnsFzqa1TxN5acnKnPCdlZSpzm8viNEOhiigupA4vTQ9HEFQ6nLTQ9wQOgBknJgzUYQ9Aw==", - "dev": true - } } }, "node-fetch": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.6.3.tgz", - "integrity": "sha1-3CNO3WSJmC1Y6PDbT2lQKavNjAQ=", - "dev": true, - "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" - } + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "dev": true }, "node-libs-browser": { "version": "2.2.1", @@ -5075,6 +5708,15 @@ } } }, + "node-preload": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", + "integrity": "sha512-RM5oyBy45cLEoHqCeh+MNuFAxO0vTFBLskvQbOKnEE7YTTSN4tbN8QWDIPQ6L+WvKsB/qLEGpYe2ZZ9d4W9OIQ==", + "dev": true, + "requires": { + "process-on-spawn": "^1.0.0" + } + }, "nodent-runtime": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/nodent-runtime/-/nodent-runtime-3.2.1.tgz", @@ -5102,6 +5744,12 @@ "remove-trailing-separator": "^1.0.1" } }, + "normalize-url": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", + "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==", + "dev": true + }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", @@ -5118,44 +5766,56 @@ "dev": true }, "nyc": { - "version": "14.1.1", - "resolved": "https://registry.npmjs.org/nyc/-/nyc-14.1.1.tgz", - "integrity": "sha512-OI0vm6ZGUnoGZv/tLdZ2esSVzDwUC88SNs+6JoSOMVxA+gKMB8Tk7jBwgemLx4O40lhhvZCVw1C+OYLOBOPXWw==", + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/nyc/-/nyc-15.1.0.tgz", + "integrity": "sha512-jMW04n9SxKdKi1ZMGhvUTHBN0EICCRkHemEoE5jm6mTYcqcdas0ATzgUgejlQUHMvpnOZqGB5Xxsv9KxJW1j8A==", "dev": true, "requires": { - "archy": "^1.0.0", - "caching-transform": "^3.0.2", - "convert-source-map": "^1.6.0", - "cp-file": "^6.2.0", - "find-cache-dir": "^2.1.0", - "find-up": "^3.0.0", - "foreground-child": "^1.5.6", - "glob": "^7.1.3", - "istanbul-lib-coverage": "^2.0.5", - "istanbul-lib-hook": "^2.0.7", - "istanbul-lib-instrument": "^3.3.0", - "istanbul-lib-report": "^2.0.8", - "istanbul-lib-source-maps": "^3.0.6", - "istanbul-reports": "^2.2.4", - "js-yaml": "^3.13.1", - "make-dir": "^2.1.0", - "merge-source-map": "^1.1.0", - "resolve-from": "^4.0.0", - "rimraf": "^2.6.3", + "@istanbuljs/load-nyc-config": "^1.0.0", + "@istanbuljs/schema": "^0.1.2", + "caching-transform": "^4.0.0", + "convert-source-map": "^1.7.0", + "decamelize": "^1.2.0", + "find-cache-dir": "^3.2.0", + "find-up": "^4.1.0", + "foreground-child": "^2.0.0", + "get-package-type": "^0.1.0", + "glob": "^7.1.6", + "istanbul-lib-coverage": "^3.0.0", + "istanbul-lib-hook": "^3.0.0", + "istanbul-lib-instrument": "^4.0.0", + "istanbul-lib-processinfo": "^2.0.2", + "istanbul-lib-report": "^3.0.0", + "istanbul-lib-source-maps": "^4.0.0", + "istanbul-reports": "^3.0.2", + "make-dir": "^3.0.0", + "node-preload": "^0.2.1", + "p-map": "^3.0.0", + "process-on-spawn": "^1.0.0", + "resolve-from": "^5.0.0", + "rimraf": "^3.0.0", "signal-exit": "^3.0.2", - "spawn-wrap": "^1.4.2", - "test-exclude": "^5.2.3", - "uuid": "^3.3.2", - "yargs": "^13.2.2", - "yargs-parser": "^13.0.0" + "spawn-wrap": "^2.0.0", + "test-exclude": "^6.0.0", + "yargs": "^15.0.2" }, "dependencies": { "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "dev": true }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -5163,36 +5823,54 @@ "dev": true }, "cliui": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", - "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", "dev": true, "requires": { - "string-width": "^3.1.0", - "strip-ansi": "^5.2.0", - "wrap-ansi": "^5.1.0" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" } }, - "cp-file": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/cp-file/-/cp-file-6.2.0.tgz", - "integrity": "sha512-fmvV4caBnofhPe8kOcitBwSn2f39QLjnAnGq3gO9dfd75mUytzKNZB1hde6QHunW2Rt+OwuBOMc3i1tNElbszA==", + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "requires": { - "graceful-fs": "^4.1.2", - "make-dir": "^2.0.0", - "nested-error-stacks": "^2.0.0", - "pify": "^4.0.1", - "safe-buffer": "^5.0.1" + "color-name": "~1.1.4" } }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "convert-source-map": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.7.0.tgz", + "integrity": "sha512-4FJkXzKXEDB1snCFZlLP4gpC3JILicCpGbzG9f9G7tGqGCzETQ2hWPrcinA9oU4wtf2biUaEH5065UnMeR33oA==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, "requires": { - "locate-path": "^3.0.0" + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" } }, "get-caller-file": { @@ -5201,49 +5879,52 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, "istanbul-lib-coverage": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", - "integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", "dev": true }, "istanbul-lib-instrument": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-3.3.0.tgz", - "integrity": "sha512-5nnIN4vo5xQZHdXno/YDXJ0G+I3dAm4XgzfSVTPLQpj/zAV2dV6Juy0yaf10/zrJOJeHoN3fraFe+XRq2bFVZA==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-4.0.3.tgz", + "integrity": "sha512-BXgQl9kf4WTCPCCpmFGoJkz/+uhvm7h7PFKUYxh7qarQd3ER33vHG//qaE8eN25l07YqZPpHXU9I09l/RD5aGQ==", "dev": true, "requires": { - "@babel/generator": "^7.4.0", - "@babel/parser": "^7.4.3", - "@babel/template": "^7.4.0", - "@babel/traverse": "^7.4.3", - "@babel/types": "^7.4.0", - "istanbul-lib-coverage": "^2.0.5", - "semver": "^6.0.0" - }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true - } + "@babel/core": "^7.7.5", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.0.0", + "semver": "^6.3.0" } }, - "make-dir": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", - "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "dev": true, "requires": { - "pify": "^4.0.1", - "semver": "^5.6.0" + "p-locate": "^4.1.0" } }, - "pify": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", - "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, "require-main-filename": { @@ -5252,24 +5933,39 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" + "glob": "^7.1.3" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" } }, "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", "dev": true, "requires": { - "ansi-regex": "^4.1.0" + "ansi-regex": "^5.0.0" } }, "which-module": { @@ -5279,14 +5975,14 @@ "dev": true }, "wrap-ansi": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", - "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", "dev": true, "requires": { - "ansi-styles": "^3.2.0", - "string-width": "^3.0.0", - "strip-ansi": "^5.0.0" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" } }, "y18n": { @@ -5296,27 +5992,28 @@ "dev": true }, "yargs": { - "version": "13.3.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", - "integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", "dev": true, "requires": { - "cliui": "^5.0.0", - "find-up": "^3.0.0", + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", "get-caller-file": "^2.0.1", "require-directory": "^2.1.1", "require-main-filename": "^2.0.0", "set-blocking": "^2.0.0", - "string-width": "^3.0.0", + "string-width": "^4.2.0", "which-module": "^2.0.0", "y18n": "^4.0.0", - "yargs-parser": "^13.1.1" + "yargs-parser": "^18.1.2" } }, "yargs-parser": { - "version": "13.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", - "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", "dev": true, "requires": { "camelcase": "^5.0.0", @@ -5414,94 +6111,51 @@ "wrappy": "1" } }, - "onetime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", - "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "onigasm": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/onigasm/-/onigasm-2.2.5.tgz", + "integrity": "sha512-F+th54mPc0l1lp1ZcFMyL/jTs2Tlq4SqIHKIXGZOR/VkHkF9A7Fr5rRr5+ZG/lWeRsyrClLYRq7s/yFQ/XhWCA==", "dev": true, "requires": { - "mimic-fn": "^1.0.0" - } - }, - "opencollective": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/opencollective/-/opencollective-1.0.3.tgz", - "integrity": "sha1-ruY3K8KBRFg2kMPKja7PwSDdDvE=", - "dev": true, - "requires": { - "babel-polyfill": "6.23.0", - "chalk": "1.1.3", - "inquirer": "3.0.6", - "minimist": "1.2.0", - "node-fetch": "1.6.3", - "opn": "4.0.2" + "lru-cache": "^5.1.1" }, "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", "dev": true, "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" + "yallist": "^3.0.2" } }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", "dev": true } } }, - "opn": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/opn/-/opn-4.0.2.tgz", - "integrity": "sha1-erwi5kTf9jsKltWrfyeQwPAavJU=", + "open": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz", + "integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==", "dev": true, "requires": { - "object-assign": "^4.0.1", - "pinkie-promise": "^2.0.0" + "is-wsl": "^1.1.0" } }, - "optimist": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", - "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", - "dev": true, - "requires": { - "minimist": "~0.0.1", - "wordwrap": "~0.0.2" - }, - "dependencies": { - "minimist": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", - "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", - "dev": true - } - } - }, - "options": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/options/-/options-0.0.6.tgz", - "integrity": "sha1-7CLTEoBrtT5zF3Pnza788cZDEo8=", + "opencollective-postinstall": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", + "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==", "dev": true }, "opts": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/opts/-/opts-1.2.6.tgz", - "integrity": "sha1-0YXAQlz9652h0YKQi2W1wCOP67M=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/opts/-/opts-2.0.2.tgz", + "integrity": "sha512-k41FwbcLnlgnFh69f4qdUfvDQ+5vaSDnVPFI/y5XuhKRq97EnVVneO9F1ESVCdiVu4fCS2L8usX3mU331hB7pg==", "dev": true }, "os-browserify": { @@ -5510,12 +6164,6 @@ "integrity": "sha1-hUNzx/XCMVkU/Jv8a9gjj92h7Cc=", "dev": true }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true - }, "os-locale": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", @@ -5531,10 +6179,10 @@ "integrity": "sha1-a2LDeRz3kJ6jXtRuF2WLtBfLORc=", "dev": true }, - "os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "p-cancelable": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", + "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", "dev": true }, "p-defer": { @@ -5543,6 +6191,15 @@ "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", "dev": true }, + "p-event": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/p-event/-/p-event-4.2.0.tgz", + "integrity": "sha512-KXatOjCRXXkSePPb1Nbi0p0m+gQAwdlbhi4wQKJPI1HsMQS9g+Sqp2o+QHziPr7eYJyOZet836KoHEVM1mwOrQ==", + "dev": true, + "requires": { + "p-timeout": "^3.1.0" + } + }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", @@ -5573,6 +6230,24 @@ "p-limit": "^2.0.0" } }, + "p-map": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz", + "integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==", + "dev": true, + "requires": { + "aggregate-error": "^3.0.0" + } + }, + "p-timeout": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz", + "integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==", + "dev": true, + "requires": { + "p-finally": "^1.0.0" + } + }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -5580,27 +6255,35 @@ "dev": true }, "package-hash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-3.0.0.tgz", - "integrity": "sha512-lOtmukMDVvtkL84rJHI7dpTYq+0rli8N2wlnqUcBuDWCfVhRUfOmnR9SsoHFMLpACvEV60dX7rd0rFaYDZI+FA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-4.0.0.tgz", + "integrity": "sha512-whdkPIooSu/bASggZ96BWVvZTRMOFxnyUG5PnTSGKoJE2gd5mbVNmR2Nj20QFzxYYgAXpoqC+AiXzl+UMRh7zQ==", "dev": true, "requires": { "graceful-fs": "^4.1.15", - "hasha": "^3.0.0", + "hasha": "^5.0.0", "lodash.flattendeep": "^4.4.0", "release-zalgo": "^1.0.0" } }, "package-json": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/package-json/-/package-json-4.0.1.tgz", - "integrity": "sha1-iGmgQBJTZhxMTKPabCEh7VVfXu0=", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/package-json/-/package-json-6.5.0.tgz", + "integrity": "sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==", "dev": true, "requires": { - "got": "^6.7.1", - "registry-auth-token": "^3.0.1", - "registry-url": "^3.0.3", - "semver": "^5.1.0" + "got": "^9.6.0", + "registry-auth-token": "^4.0.0", + "registry-url": "^5.0.0", + "semver": "^6.2.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "pako": { @@ -5699,12 +6382,6 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "path-is-inside": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", - "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", - "dev": true - }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", @@ -5718,9 +6395,9 @@ "dev": true }, "path-to-regexp": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", - "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", "dev": true, "requires": { "isarray": "0.0.1" @@ -5764,6 +6441,12 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "dev": true }, + "picomatch": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", + "dev": true + }, "pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", @@ -5786,31 +6469,50 @@ } }, "pkg-dir": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", - "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", "dev": true, "requires": { - "find-up": "^3.0.0" + "find-up": "^4.0.0" }, "dependencies": { "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, "requires": { - "locate-path": "^3.0.0" + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" } + }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true } } }, - "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", @@ -5829,9 +6531,9 @@ } }, "prepend-http": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz", - "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", + "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", "dev": true }, "preserve": { @@ -5841,20 +6543,11 @@ "dev": true }, "prettier": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", - "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", + "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", "dev": true }, - "prismjs": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.16.0.tgz", - "integrity": "sha512-OA4MKxjFZHSvZcisLGe14THYsug/nF6O1f0pAJc0KN0wTyAcLqmsbE+lTGKSpyh+9pEW57+k6pg2AfYR+coyHA==", - "dev": true, - "requires": { - "clipboard": "^2.0.0" - } - }, "process": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", @@ -5866,6 +6559,15 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, + "process-on-spawn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/process-on-spawn/-/process-on-spawn-1.0.0.tgz", + "integrity": "sha512-1WsPDsUSMmZH5LeMLegqkPDrsGgsWwk1Exipy2hvB0o/F0ASzbpIctSCcZIK1ykJvtTJULEH+20WOFjMvGnCTg==", + "dev": true, + "requires": { + "fromentries": "^1.2.0" + } + }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", @@ -5873,17 +6575,16 @@ "dev": true }, "prompt": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.0.0.tgz", - "integrity": "sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.1.0.tgz", + "integrity": "sha512-ec1vUPXCplDBDUVD8uPa3XGA+OzLrO40Vxv3F1uxoiZGkZhdctlK2JotcHq5X6ExjocDOGwGdCSXloGNyU5L1Q==", "dev": true, "requires": { "colors": "^1.1.2", - "pkginfo": "0.x.x", "read": "1.0.x", "revalidator": "0.1.x", "utile": "0.3.x", - "winston": "2.1.x" + "winston": "2.x" } }, "prr": { @@ -5934,6 +6635,15 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "pupa": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/pupa/-/pupa-2.1.1.tgz", + "integrity": "sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==", + "dev": true, + "requires": { + "escape-goat": "^2.0.0" + } + }, "qs": { "version": "6.5.2", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", @@ -6072,12 +6782,6 @@ "resolve": "^1.1.6" } }, - "regenerator-runtime": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=", - "dev": true - }, "regex-cache": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz", @@ -6098,22 +6802,21 @@ } }, "registry-auth-token": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.4.0.tgz", - "integrity": "sha512-4LM6Fw8eBQdwMYcES4yTnn2TqIasbXuwDx3um+QRs7S55aMKCBKBxvPXl2RiUjHwuJLTyYfxSpmfSAjQpcuP+A==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.2.1.tgz", + "integrity": "sha512-6gkSb4U6aWJB4SF2ZvLb76yCBjcvufXBqvvEx1HbmKPkutswjW1xNVRY0+daljIYRbogN7O0etYSlbiaEQyMyw==", "dev": true, "requires": { - "rc": "^1.1.6", - "safe-buffer": "^5.0.1" + "rc": "^1.2.8" } }, "registry-url": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-3.1.0.tgz", - "integrity": "sha1-PU74cPc93h138M+aOBQyRE4XSUI=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-5.1.0.tgz", + "integrity": "sha512-8acYXXTI0AkQv6RAOjE3vOaIXZkT9wo4LOFbBKYQEEnnMNBpKqdUrI6S4NT0KPIo/WVvJ5tE/X5LF/TQUf0ekw==", "dev": true, "requires": { - "rc": "^1.0.1" + "rc": "^1.2.8" } }, "release-zalgo": { @@ -6308,9 +7011,9 @@ } }, "request": { - "version": "2.88.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", - "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", "dev": true, "requires": { "aws-sign2": "~0.7.0", @@ -6320,7 +7023,7 @@ "extend": "~3.0.2", "forever-agent": "~0.6.1", "form-data": "~2.3.2", - "har-validator": "~5.1.0", + "har-validator": "~5.1.3", "http-signature": "~1.2.0", "is-typedarray": "~1.0.0", "isstream": "~0.1.2", @@ -6330,30 +7033,42 @@ "performance-now": "^2.1.0", "qs": "~6.5.2", "safe-buffer": "^5.1.2", - "tough-cookie": "~2.4.3", + "tough-cookie": "~2.5.0", "tunnel-agent": "^0.6.0", "uuid": "^3.3.2" + }, + "dependencies": { + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "dev": true, + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + } } }, "request-promise": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.4.tgz", - "integrity": "sha512-8wgMrvE546PzbR5WbYxUQogUnUDfM0S7QIFZMID+J73vdFARkFy+HElj4T+MWYhpXwlLp0EQ8Zoj8xUA0he4Vg==", + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.6.tgz", + "integrity": "sha512-HCHI3DJJUakkOr8fNoCc73E5nU5bqITjOYFMDrKHYOXWXrgD/SBaC7LjwuPymUprRyuF06UK7hd/lMHkmUXglQ==", "dev": true, "requires": { "bluebird": "^3.5.0", - "request-promise-core": "1.1.2", + "request-promise-core": "1.1.4", "stealthy-require": "^1.1.1", "tough-cookie": "^2.3.3" } }, "request-promise-core": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", - "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.4.tgz", + "integrity": "sha512-TTbAfBBRdWD7aNNOoVOBH4pN/KigV6LyapYNNlAPA8JwbovRti1E88m3sYAwsLi5ryhPKsE9APwnjFTgdUjTpw==", "dev": true, "requires": { - "lodash": "^4.17.11" + "lodash": "^4.17.19" } }, "require-directory": { @@ -6378,15 +7093,15 @@ } }, "resolve-from": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", + "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", "dev": true }, "resolve-pathname": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-2.2.0.tgz", - "integrity": "sha512-bAFz9ld18RzJfddgrO2e/0S2O81710++chRMUxHjXOYKF6jTAMrUNZrEZ1PvV0zlhfjidm08iRPdTLPno1FuRg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", + "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==", "dev": true }, "resolve-url": { @@ -6395,14 +7110,13 @@ "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=", "dev": true }, - "restore-cursor": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", - "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "responselike": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", + "integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", "dev": true, "requires": { - "onetime": "^2.0.0", - "signal-exit": "^3.0.2" + "lowercase-keys": "^1.0.0" } }, "ret": { @@ -6427,9 +7141,9 @@ } }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, "requires": { "glob": "^7.1.3" @@ -6445,21 +7159,6 @@ "inherits": "^2.0.1" } }, - "run-async": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", - "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", - "dev": true, - "requires": { - "is-promise": "^2.1.0" - } - }, - "rx": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/rx/-/rx-4.1.0.tgz", - "integrity": "sha1-pfE/957zt0D+MKqAP7CfmIBdR4I=", - "dev": true - }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -6480,12 +7179,6 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, - "samsam": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/samsam/-/samsam-1.3.0.tgz", - "integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg==", - "dev": true - }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", @@ -6514,12 +7207,20 @@ "dev": true }, "semver-diff": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-2.1.0.tgz", - "integrity": "sha1-S7uEN8jTfksM8aaP1ybsbWRdbTY=", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-3.1.1.tgz", + "integrity": "sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==", "dev": true, "requires": { - "semver": "^5.0.3" + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "send": { @@ -6635,9 +7336,9 @@ "dev": true }, "shelljs": { - "version": "0.7.8", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz", - "integrity": "sha1-3svPh0sNHl+3LhSxZKloMEjprLM=", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", + "integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==", "dev": true, "requires": { "glob": "^7.0.0", @@ -6645,10 +7346,20 @@ "rechoir": "^0.6.2" } }, + "shiki": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.9.2.tgz", + "integrity": "sha512-BjUCxVbxMnvjs8jC4b+BQ808vwjJ9Q8NtLqPwXShZ307HdXiDFYP968ORSVfaTNNSWYDBYdMnVKJ0fYNsoZUBA==", + "dev": true, + "requires": { + "onigasm": "^2.2.5", + "vscode-textmate": "^5.2.0" + } + }, "shortid": { - "version": "2.2.15", - "resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.15.tgz", - "integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==", + "version": "2.2.16", + "resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.16.tgz", + "integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==", "requires": { "nanoid": "^2.1.0" } @@ -6660,25 +7371,39 @@ "dev": true }, "sinon": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-5.1.1.tgz", - "integrity": "sha512-h/3uHscbt5pQNxkf7Y/Lb9/OM44YNCicHakcq73ncbrIS8lXg+ZGOZbtuU+/km4YnyiCYfQQEwANaReJz7KDfw==", + "version": "9.2.4", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", + "integrity": "sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==", "dev": true, "requires": { - "@sinonjs/formatio": "^2.0.0", - "diff": "^3.5.0", - "lodash.get": "^4.4.2", - "lolex": "^2.4.2", - "nise": "^1.3.3", - "supports-color": "^5.4.0", - "type-detect": "^4.0.8" + "@sinonjs/commons": "^1.8.1", + "@sinonjs/fake-timers": "^6.0.1", + "@sinonjs/samsam": "^5.3.1", + "diff": "^4.0.2", + "nise": "^4.0.4", + "supports-color": "^7.1.0" }, "dependencies": { - "type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } } } }, @@ -6847,23 +7572,32 @@ } }, "spawn-wrap": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-1.4.3.tgz", - "integrity": "sha512-IgB8md0QW/+tWqcavuFgKYR/qIRvJkRLPJDFaoXtLLUaVcCDK0+HeFTkmQHj3eprcYhc+gOl0aEA1w7qZlYezw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-2.0.0.tgz", + "integrity": "sha512-EeajNjfN9zMnULLwhZZQU3GWBoFNkbngTUPfaawT4RkMiviTxcX0qfhVbGey39mfctfDHkWtuecgQ8NJcyQWHg==", "dev": true, "requires": { - "foreground-child": "^1.5.6", - "mkdirp": "^0.5.0", - "os-homedir": "^1.0.1", - "rimraf": "^2.6.2", + "foreground-child": "^2.0.0", + "is-windows": "^1.0.2", + "make-dir": "^3.0.0", + "rimraf": "^3.0.0", "signal-exit": "^3.0.2", - "which": "^1.3.0" + "which": "^2.0.1" }, "dependencies": { + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "requires": { "isexe": "^2.0.0" @@ -7056,6 +7790,15 @@ "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, + "strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "requires": { + "min-indent": "^1.0.0" + } + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -7078,142 +7821,22 @@ "dev": true }, "term-size": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/term-size/-/term-size-1.2.0.tgz", - "integrity": "sha1-RYuDiH8oj8Vtb/+/rSYuJmOO+mk=", - "dev": true, - "requires": { - "execa": "^0.7.0" - }, - "dependencies": { - "execa": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", - "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", - "dev": true, - "requires": { - "cross-spawn": "^5.0.1", - "get-stream": "^3.0.0", - "is-stream": "^1.1.0", - "npm-run-path": "^2.0.0", - "p-finally": "^1.0.0", - "signal-exit": "^3.0.0", - "strip-eof": "^1.0.0" - } - }, - "get-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", - "dev": true - } - } + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz", + "integrity": "sha512-wK0Ri4fOGjv/XPy8SBHZChl8CM7uMc5VML7SqiQ0zG7+J5Vr+RMQDoHa2CNT6KHUnTGIXH34UDMkPzAUyapBZg==", + "dev": true }, "test-exclude": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz", - "integrity": "sha512-M+oxtseCFO3EDtAaGH7iiej3CBkzXqFMbzqYAACdzKui4eZA+pq3tZEwChvOdNfa7xxy8BfbmgJSIr43cC/+2g==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", + "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", "dev": true, "requires": { - "glob": "^7.1.3", - "minimatch": "^3.0.4", - "read-pkg-up": "^4.0.0", - "require-main-filename": "^2.0.0" - }, - "dependencies": { - "find-up": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", - "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", - "dev": true, - "requires": { - "locate-path": "^3.0.0" - } - }, - "load-json-file": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", - "integrity": "sha1-L19Fq5HjMhYjT9U62rZo607AmTs=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.2", - "parse-json": "^4.0.0", - "pify": "^3.0.0", - "strip-bom": "^3.0.0" - } - }, - "parse-json": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", - "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", - "dev": true, - "requires": { - "error-ex": "^1.3.1", - "json-parse-better-errors": "^1.0.1" - } - }, - "path-type": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz", - "integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==", - "dev": true, - "requires": { - "pify": "^3.0.0" - } - }, - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", - "dev": true - }, - "read-pkg": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", - "integrity": "sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=", - "dev": true, - "requires": { - "load-json-file": "^4.0.0", - "normalize-package-data": "^2.3.2", - "path-type": "^3.0.0" - } - }, - "read-pkg-up": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-4.0.0.tgz", - "integrity": "sha512-6etQSH7nJGsK0RbG/2TeDzZFa8shjQ1um+SwQQ5cwKy0dhSXdOncEhb1CPpvQG4h7FyOV6EB6YlV0yJvZQNAkA==", - "dev": true, - "requires": { - "find-up": "^3.0.0", - "read-pkg": "^3.0.0" - } - }, - "require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "dev": true - }, - "strip-bom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", - "dev": true - } + "@istanbuljs/schema": "^0.1.2", + "glob": "^7.1.4", + "minimatch": "^3.0.4" } }, - "through": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true - }, - "timed-out": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", - "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", - "dev": true - }, "timers-browserify": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-2.0.10.tgz", @@ -7231,20 +7854,11 @@ "optional": true }, "tinydate": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/tinydate/-/tinydate-1.1.0.tgz", - "integrity": "sha512-YF6YTOyBRHX4b3EtEI0W/mROcv82Gt6VccmVuSAkRV3FNORug2457wSGvT2cThbfuctQvVSmC5GobGheScxtIw==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tinydate/-/tinydate-1.3.0.tgz", + "integrity": "sha512-7cR8rLy2QhYHpsBDBVYnnWXm8uRTr38RoZakFSW7Bs7PzfMPNZthuMLkwqZv7MTu8lhQ91cOFYS5a7iFj2oR3w==", "dev": true }, - "tmp": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", - "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", - "dev": true, - "requires": { - "os-tmpdir": "~1.0.2" - } - }, "to-arraybuffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz", @@ -7277,6 +7891,12 @@ } } }, + "to-readable-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", + "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", + "dev": true + }, "to-regex": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/to-regex/-/to-regex-3.0.2.tgz", @@ -7336,53 +7956,95 @@ "dev": true }, "ts-node": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", - "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", + "integrity": "sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==", "dev": true, "requires": { - "arrify": "^1.0.0", - "buffer-from": "^1.1.0", - "diff": "^3.1.0", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", "make-error": "^1.1.1", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "source-map-support": "^0.5.6", - "yn": "^2.0.0" + "source-map-support": "^0.5.17", + "yn": "3.1.1" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } } }, "tslib": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, "tslint": { - "version": "5.18.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.18.0.tgz", - "integrity": "sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==", + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-6.1.3.tgz", + "integrity": "sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", "builtin-modules": "^1.1.1", "chalk": "^2.3.0", "commander": "^2.12.1", - "diff": "^3.2.0", + "diff": "^4.0.1", "glob": "^7.1.1", "js-yaml": "^3.13.1", "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", + "mkdirp": "^0.5.3", "resolve": "^1.3.2", "semver": "^5.3.0", - "tslib": "^1.8.0", + "tslib": "^1.13.0", "tsutils": "^2.29.0" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + } } }, "tslint-immutable": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/tslint-immutable/-/tslint-immutable-4.9.1.tgz", - "integrity": "sha512-iIFCq08H4YyNIX0bV5N6fGQtAmjc4OQZKQCgBP5WHgQaITyGAHPVmAw+Yf7qe0zbRCvCDZdrdEC/191fLGFiww==", - "dev": true + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/tslint-immutable/-/tslint-immutable-6.0.1.tgz", + "integrity": "sha512-3GQ6HffN64gLmT/N1YzyVMqyf6uBjMvhNaevK8B0K01/QC0OU5AQZrH4TjMHo1IdG3JpqsZvuRy9IW1LA3zjwA==", + "dev": true, + "requires": { + "tsutils": "^2.28.0 || ^3.0.0" + } }, "tsutils": { "version": "2.29.0", @@ -7432,93 +8094,100 @@ "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", "dev": true }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, - "typedoc": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.11.1.tgz", - "integrity": "sha512-jdNIoHm5wkZqxQTe/g9AQ3LKnZyrzHXqu6A/c9GUOeJyBWLxNr7/Dm3rwFvLksuxRNwTvY/0HRDU9sJTa9WQSg==", + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", "dev": true, "requires": { - "@types/fs-extra": "5.0.1", - "@types/handlebars": "4.0.36", - "@types/highlight.js": "9.12.2", - "@types/lodash": "4.14.104", - "@types/marked": "0.3.0", - "@types/minimatch": "3.0.3", - "@types/shelljs": "0.7.8", - "fs-extra": "^5.0.0", - "handlebars": "^4.0.6", - "highlight.js": "^9.0.0", - "lodash": "^4.17.5", - "marked": "^0.3.17", + "is-typedarray": "^1.0.0" + } + }, + "typedoc": { + "version": "0.20.29", + "resolved": "http://registry.npmjs.org/typedoc/-/typedoc-0.20.29.tgz", + "integrity": "sha512-IyzrbtwNAXtylUJn41FbopQsNSQ1jcM6lUhDL/REOFo31G3Q9fsniZUQP+tIcTX5JaCntRdw3PTMZTQPV52low==", + "dev": true, + "requires": { + "colors": "^1.4.0", + "fs-extra": "^9.1.0", + "handlebars": "^4.7.7", + "lodash": "^4.17.21", + "lunr": "^2.3.9", + "marked": "^2.0.1", "minimatch": "^3.0.0", - "progress": "^2.0.0", - "shelljs": "^0.8.1", - "typedoc-default-themes": "^0.5.0", - "typescript": "2.7.2" + "progress": "^2.0.3", + "shelljs": "^0.8.4", + "shiki": "^0.9.2", + "typedoc-default-themes": "^0.12.8" }, "dependencies": { - "marked": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.19.tgz", - "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==", - "dev": true - }, - "shelljs": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz", - "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==", + "fs-extra": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", "dev": true, "requires": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" } }, - "typescript": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz", - "integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==", + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", "dev": true } } }, "typedoc-default-themes": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.5.0.tgz", - "integrity": "sha1-bcJDPnjti+qOiHo6zeLzF4W9Yic=", + "version": "0.12.8", + "resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.12.8.tgz", + "integrity": "sha512-tyjyDTKy/JLnBSwvhoqd99VIjrP33SdOtwcMD32b+OqnrjZWe8HmZECbfBoacqoxjHd58gfeNw6wA7uvqWFa4w==", "dev": true }, "typescript": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", - "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.0.tgz", + "integrity": "sha512-TWYSWa9T2pPN4DIJYbU9oAjQx+5qdV5RUDxwARg8fmJZrD/V27Zj0JngW5xg1DFz42G0uDYl2XhzF6alSzD62w==", "dev": true, - "optional": true, - "requires": { - "commander": "~2.20.0", - "source-map": "~0.6.1" - }, - "dependencies": { - "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", - "dev": true, - "optional": true - } - } + "optional": true }, "uglify-to-browserify": { "version": "1.0.2", @@ -7598,12 +8267,6 @@ } } }, - "ultron": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz", - "integrity": "sha1-rOEWq1V80Zc4ak6I9GhTeMiy5Po=", - "dev": true - }, "union-value": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", @@ -7617,12 +8280,12 @@ } }, "unique-string": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-1.0.0.tgz", - "integrity": "sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz", + "integrity": "sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg==", "dev": true, "requires": { - "crypto-random-string": "^1.0.0" + "crypto-random-string": "^2.0.0" } }, "universalify": { @@ -7677,12 +8340,6 @@ } } }, - "unzip-response": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-2.0.1.tgz", - "integrity": "sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c=", - "dev": true - }, "upath": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/upath/-/upath-1.1.2.tgz", @@ -7690,21 +8347,75 @@ "dev": true }, "update-notifier": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-2.5.0.tgz", - "integrity": "sha512-gwMdhgJHGuj/+wHJJs9e6PcCszpxR1b236igrOkUofGhqJuG+amlIKwApH1IW1WWl7ovZxsX49lMBWLxSdm5Dw==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.3.tgz", + "integrity": "sha512-Yld6Z0RyCYGB6ckIjffGOSOmHXj1gMeE7aROz4MG+XMkmixBX4jUngrGXNYz7wPKBmtoD4MnBa2Anu7RSKht/A==", "dev": true, "requires": { - "boxen": "^1.2.1", - "chalk": "^2.0.1", - "configstore": "^3.0.0", + "boxen": "^4.2.0", + "chalk": "^3.0.0", + "configstore": "^5.0.1", + "has-yarn": "^2.1.0", "import-lazy": "^2.1.0", - "is-ci": "^1.0.10", - "is-installed-globally": "^0.1.0", - "is-npm": "^1.0.0", - "latest-version": "^3.0.0", - "semver-diff": "^2.0.0", - "xdg-basedir": "^3.0.0" + "is-ci": "^2.0.0", + "is-installed-globally": "^0.3.1", + "is-npm": "^4.0.0", + "is-yarn-global": "^0.3.0", + "latest-version": "^5.0.0", + "pupa": "^2.0.1", + "semver-diff": "^3.1.1", + "xdg-basedir": "^4.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, "uri-js": { @@ -7741,12 +8452,12 @@ } }, "url-parse-lax": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz", - "integrity": "sha1-evjzA2Rem9eaJy56FKxovAYJ2nM=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", + "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", "dev": true, "requires": { - "prepend-http": "^1.0.1" + "prepend-http": "^2.0.0" } }, "use": { @@ -7789,6 +8500,17 @@ "mkdirp": "0.x.x", "ncp": "1.0.x", "rimraf": "2.x.x" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "utils-merge": { @@ -7830,6 +8552,12 @@ "integrity": "sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw==", "dev": true }, + "vscode-textmate": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-5.2.0.tgz", + "integrity": "sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==", + "dev": true + }, "watchpack": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.0.tgz", @@ -8200,12 +8928,52 @@ "dev": true }, "widest-line": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-2.0.1.tgz", - "integrity": "sha512-Ba5m9/Fa4Xt9eb2ELXt77JxVDV8w7qQrH0zS/TWSJdLyAwQjWoOzpzj5lwVftDz6n/EOu3tNACS84v509qwnJA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", + "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", "dev": true, "requires": { - "string-width": "^2.1.1" + "string-width": "^4.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + } } }, "window-size": { @@ -8215,9 +8983,9 @@ "dev": true }, "winston": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz", - "integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=", + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz", + "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==", "dev": true, "requires": { "async": "~1.0.0", @@ -8225,7 +8993,6 @@ "cycle": "1.0.x", "eyes": "0.1.x", "isstream": "0.1.x", - "pkginfo": "0.3.x", "stack-trace": "0.0.x" }, "dependencies": { @@ -8240,19 +9007,13 @@ "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 } } }, "wordwrap": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", - "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", "dev": true }, "wrap-ansi": { @@ -8294,30 +9055,30 @@ "dev": true }, "write-file-atomic": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", - "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", + "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", "dev": true, "requires": { - "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", - "signal-exit": "^3.0.2" + "is-typedarray": "^1.0.0", + "signal-exit": "^3.0.2", + "typedarray-to-buffer": "^3.1.5" } }, "ws": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/ws/-/ws-1.1.5.tgz", - "integrity": "sha512-o3KqipXNUdS7wpQzBHSe180lBGO60SoK0yVo3CYJgb2MkobuWuBX6dhkYP5ORCLd55y+SaflMOV5fqAB53ux4w==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", "dev": true, "requires": { - "options": ">=0.0.5", - "ultron": "1.0.x" + "async-limiter": "~1.0.0" } }, "xdg-basedir": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-3.0.0.tgz", - "integrity": "sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", + "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, "xml": { @@ -8444,9 +9205,9 @@ } }, "yn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true } } diff --git a/package.json b/package.json index a742fc4faf..0817dbbc0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docx", - "version": "5.0.0", + "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": { @@ -50,6 +50,7 @@ "types": "./build/index.d.ts", "dependencies": { "@types/jszip": "^3.1.4", + "@types/node": "^14.0.5", "jszip": "^3.1.5", "shortid": "^2.2.15", "xml": "^1.0.1", @@ -62,11 +63,11 @@ }, "homepage": "https://github.com/dolanmiu/docx#readme", "devDependencies": { - "@types/chai": "^3.4.35", - "@types/mocha": "^2.2.39", + "@types/chai": "^4.2.15", + "@types/mocha": "^8.0.0", "@types/request-promise": "^4.1.42", "@types/shortid": "0.0.29", - "@types/sinon": "^4.3.1", + "@types/sinon": "^9.0.4", "@types/webpack": "^4.4.24", "awesome-typescript-loader": "^3.4.1", "chai": "^3.5.0", @@ -76,24 +77,24 @@ "jszip": "^3.1.5", "mocha": "^5.2.0", "mocha-webpack": "^1.0.1", - "nyc": "^14.1.1", + "nyc": "^15.1.0", "pre-commit": "^1.2.2", - "prettier": "^1.15.2", + "prettier": "^2.1.2", "prompt": "^1.0.0", "replace-in-file": "^3.1.0", "request": "^2.88.0", "request-promise": "^4.2.2", - "rimraf": "^2.5.2", - "shelljs": "^0.7.7", - "sinon": "^5.0.7", - "ts-node": "^7.0.1", - "tslint": "^5.11.0", - "tslint-immutable": "^4.9.0", - "typedoc": "^0.11.1", - "typescript": "2.9.2", + "rimraf": "^3.0.2", + "shelljs": "^0.8.4", + "sinon": "^9.0.2", + "ts-node": "^9.0.0", + "tslint": "^6.1.3", + "tslint-immutable": "^6.0.1", + "typedoc": "^0.20.29", + "typescript": "4.2.3", "webpack": "^3.10.0" }, "engines": { - "node": ">=8" + "node": ">=10" } } diff --git a/src/convenience-functions.spec.ts b/src/convenience-functions.spec.ts new file mode 100644 index 0000000000..3333fdd2d0 --- /dev/null +++ b/src/convenience-functions.spec.ts @@ -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); + }); + }); +}); diff --git a/src/convenience-functions.ts b/src/convenience-functions.ts new file mode 100644 index 0000000000..6fe110b72b --- /dev/null +++ b/src/convenience-functions.ts @@ -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); +}; diff --git a/src/export/formatter.ts b/src/export/formatter.ts index b863ea4b97..a91702212e 100644 --- a/src/export/formatter.ts +++ b/src/export/formatter.ts @@ -1,8 +1,8 @@ +import { IViewWrapper } from "file/document-wrapper"; import { BaseXmlComponent, IXmlableObject } from "file/xml-components"; -import { File } from "../file"; export class Formatter { - public format(input: BaseXmlComponent, file?: File): IXmlableObject { + public format(input: BaseXmlComponent, file?: IViewWrapper): IXmlableObject { const output = input.prepForXml(file); if (output) { diff --git a/src/export/packer/next-compiler.spec.ts b/src/export/packer/next-compiler.spec.ts index 7c48569793..d0dfbf08ae 100644 --- a/src/export/packer/next-compiler.spec.ts +++ b/src/export/packer/next-compiler.spec.ts @@ -16,26 +16,28 @@ describe("Compiler", () => { }); describe("#compile()", () => { - it("should pack all the content", async function() { + it("should pack all the content", async function () { this.timeout(99999999); const zipFile = compiler.compile(file); const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); expect(fileNames).is.an.instanceof(Array); - expect(fileNames).has.length(14); + expect(fileNames).has.length(16); expect(fileNames).to.include("word/document.xml"); expect(fileNames).to.include("word/styles.xml"); expect(fileNames).to.include("docProps/core.xml"); + expect(fileNames).to.include("docProps/custom.xml"); expect(fileNames).to.include("docProps/app.xml"); expect(fileNames).to.include("word/numbering.xml"); expect(fileNames).to.include("word/footnotes.xml"); + expect(fileNames).to.include("word/_rels/footnotes.xml.rels"); expect(fileNames).to.include("word/settings.xml"); expect(fileNames).to.include("word/_rels/document.xml.rels"); expect(fileNames).to.include("[Content_Types].xml"); expect(fileNames).to.include("_rels/.rels"); }); - it("should pack all additional headers and footers", async function() { + it("should pack all additional headers and footers", async function () { file.addSection({ headers: { default: new Header(), @@ -62,7 +64,7 @@ describe("Compiler", () => { const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); expect(fileNames).is.an.instanceof(Array); - expect(fileNames).has.length(22); + expect(fileNames).has.length(24); expect(fileNames).to.include("word/header1.xml"); expect(fileNames).to.include("word/_rels/header1.xml.rels"); @@ -88,7 +90,7 @@ describe("Compiler", () => { const spy = sinon.spy(compiler["formatter"], "format"); compiler.compile(file); - expect(spy.callCount).to.equal(10); + expect(spy.callCount).to.equal(12); }); }); }); diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index a7b5fb617e..e5f66c8d96 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -23,8 +23,10 @@ interface IXmlifyedFileMapping { readonly HeaderRelationships: IXmlifyedFile[]; readonly FooterRelationships: IXmlifyedFile[]; readonly ContentTypes: IXmlifyedFile; + readonly CustomProperties: IXmlifyedFile; readonly AppProperties: IXmlifyedFile; readonly FootNotes: IXmlifyedFile; + readonly FootNotesRelationships: IXmlifyedFile; readonly Settings: IXmlifyedFile; } @@ -69,23 +71,23 @@ export class Compiler { private xmlifyFile(file: File, prettify?: boolean): IXmlifyedFileMapping { file.verifyUpdateFields(); - const documentRelationshipCount = file.DocumentRelationships.RelationshipCount + 1; + const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1; - const documentXmlData = xml(this.formatter.format(file.Document, file), prettify); + const documentXmlData = xml(this.formatter.format(file.Document.View, file.Document), prettify); const documentMediaDatas = this.imageReplacer.getMediaData(documentXmlData, file.Media); return { Relationships: { data: (() => { documentMediaDatas.forEach((mediaData, i) => { - file.DocumentRelationships.createRelationship( + file.Document.Relationships.createRelationship( documentRelationshipCount + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`, ); }); - return xml(this.formatter.format(file.DocumentRelationships, file), prettify); + return xml(this.formatter.format(file.Document.Relationships, file.Document), prettify); })(), path: "word/_rels/document.xml.rels", }, @@ -99,11 +101,11 @@ export class Compiler { path: "word/document.xml", }, Styles: { - data: xml(this.formatter.format(file.Styles, file), prettify), + data: xml(this.formatter.format(file.Styles, file.Document), prettify), path: "word/styles.xml", }, Properties: { - data: xml(this.formatter.format(file.CoreProperties, file), { + data: xml(this.formatter.format(file.CoreProperties, file.Document), { declaration: { standalone: "yes", encoding: "UTF-8", @@ -112,15 +114,15 @@ export class Compiler { path: "docProps/core.xml", }, Numbering: { - data: xml(this.formatter.format(file.Numbering, file), prettify), + data: xml(this.formatter.format(file.Numbering, file.Document), prettify), path: "word/numbering.xml", }, FileRelationships: { - data: xml(this.formatter.format(file.FileRelationships, file), prettify), + data: xml(this.formatter.format(file.FileRelationships, file.Document), prettify), path: "_rels/.rels", }, HeaderRelationships: file.Headers.map((headerWrapper, index) => { - const xmlData = xml(this.formatter.format(headerWrapper.Header, file), prettify); + const xmlData = xml(this.formatter.format(headerWrapper.View, headerWrapper), prettify); const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media); mediaDatas.forEach((mediaData, i) => { @@ -132,12 +134,12 @@ export class Compiler { }); return { - data: xml(this.formatter.format(headerWrapper.Relationships, file), prettify), + data: xml(this.formatter.format(headerWrapper.Relationships, headerWrapper), prettify), path: `word/_rels/header${index + 1}.xml.rels`, }; }), FooterRelationships: file.Footers.map((footerWrapper, index) => { - const xmlData = xml(this.formatter.format(footerWrapper.Footer, file), prettify); + const xmlData = xml(this.formatter.format(footerWrapper.View, footerWrapper), prettify); const mediaDatas = this.imageReplacer.getMediaData(xmlData, file.Media); mediaDatas.forEach((mediaData, i) => { @@ -149,12 +151,12 @@ export class Compiler { }); return { - data: xml(this.formatter.format(footerWrapper.Relationships, file), prettify), + data: xml(this.formatter.format(footerWrapper.Relationships, footerWrapper), prettify), path: `word/_rels/footer${index + 1}.xml.rels`, }; }), Headers: file.Headers.map((headerWrapper, index) => { - const tempXmlData = xml(this.formatter.format(headerWrapper.Header, file), prettify); + const tempXmlData = xml(this.formatter.format(headerWrapper.View, headerWrapper), prettify); const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media); // TODO: 0 needs to be changed when headers get relationships of their own const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0); @@ -165,7 +167,7 @@ export class Compiler { }; }), Footers: file.Footers.map((footerWrapper, index) => { - const tempXmlData = xml(this.formatter.format(footerWrapper.Footer, file), prettify); + const tempXmlData = xml(this.formatter.format(footerWrapper.View, footerWrapper), prettify); const mediaDatas = this.imageReplacer.getMediaData(tempXmlData, file.Media); // TODO: 0 needs to be changed when headers get relationships of their own const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0); @@ -176,19 +178,27 @@ export class Compiler { }; }), ContentTypes: { - data: xml(this.formatter.format(file.ContentTypes, file), prettify), + data: xml(this.formatter.format(file.ContentTypes, file.Document), prettify), path: "[Content_Types].xml", }, + CustomProperties: { + data: xml(this.formatter.format(file.CustomProperties, file.Document), prettify), + path: "docProps/custom.xml", + }, AppProperties: { - data: xml(this.formatter.format(file.AppProperties, file), prettify), + data: xml(this.formatter.format(file.AppProperties, file.Document), prettify), path: "docProps/app.xml", }, FootNotes: { - data: xml(this.formatter.format(file.FootNotes, file), prettify), + data: xml(this.formatter.format(file.FootNotes.View, file.FootNotes), prettify), path: "word/footnotes.xml", }, + FootNotesRelationships: { + data: xml(this.formatter.format(file.FootNotes.Relationships, file.FootNotes), prettify), + path: "word/_rels/footnotes.xml.rels", + }, Settings: { - data: xml(this.formatter.format(file.Settings, file), prettify), + data: xml(this.formatter.format(file.Settings, file.Document), prettify), path: "word/settings.xml", }, }; diff --git a/src/export/packer/packer.spec.ts b/src/export/packer/packer.spec.ts index 8235649f15..18ae459b49 100644 --- a/src/export/packer/packer.spec.ts +++ b/src/export/packer/packer.spec.ts @@ -36,7 +36,7 @@ describe("Packer", () => { }); describe("#toBuffer()", () => { - it("should create a standard docx file", async function() { + it("should create a standard docx file", async function () { this.timeout(99999999); const buffer = await Packer.toBuffer(file); @@ -61,7 +61,7 @@ describe("Packer", () => { }); describe("#toBase64String()", () => { - it("should create a standard docx file", async function() { + it("should create a standard docx file", async function () { this.timeout(99999999); const str = await Packer.toBase64String(file); diff --git a/src/file/content-types/content-types.spec.ts b/src/file/content-types/content-types.spec.ts index 1d8e008f92..57d992f83d 100644 --- a/src/file/content-types/content-types.spec.ts +++ b/src/file/content-types/content-types.spec.ts @@ -54,6 +54,14 @@ describe("ContentTypes", () => { }, }); expect(tree["Types"][11]).to.deep.equal({ + Override: { + _attr: { + ContentType: "application/vnd.openxmlformats-officedocument.custom-properties+xml", + PartName: "/docProps/custom.xml", + }, + }, + }); + expect(tree["Types"][12]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml", @@ -61,7 +69,7 @@ describe("ContentTypes", () => { }, }, }); - expect(tree["Types"][12]).to.deep.equal({ + expect(tree["Types"][13]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", @@ -69,7 +77,7 @@ describe("ContentTypes", () => { }, }, }); - expect(tree["Types"][13]).to.deep.equal({ + expect(tree["Types"][14]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", @@ -77,7 +85,7 @@ describe("ContentTypes", () => { }, }, }); - expect(tree["Types"][14]).to.deep.equal({ + expect(tree["Types"][15]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", @@ -94,7 +102,7 @@ describe("ContentTypes", () => { contentTypes.addFooter(102); const tree = new Formatter().format(contentTypes); - expect(tree["Types"][15]).to.deep.equal({ + expect(tree["Types"][16]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", @@ -103,7 +111,7 @@ describe("ContentTypes", () => { }, }); - expect(tree["Types"][16]).to.deep.equal({ + expect(tree["Types"][17]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", @@ -120,7 +128,7 @@ describe("ContentTypes", () => { contentTypes.addHeader(202); const tree = new Formatter().format(contentTypes); - expect(tree["Types"][15]).to.deep.equal({ + expect(tree["Types"][16]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", @@ -129,7 +137,7 @@ describe("ContentTypes", () => { }, }); - expect(tree["Types"][16]).to.deep.equal({ + expect(tree["Types"][17]).to.deep.equal({ Override: { _attr: { ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", diff --git a/src/file/content-types/content-types.ts b/src/file/content-types/content-types.ts index 86307724fc..34e495d3c0 100644 --- a/src/file/content-types/content-types.ts +++ b/src/file/content-types/content-types.ts @@ -27,6 +27,7 @@ export class ContentTypes extends XmlComponent { this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", "/word/styles.xml")); this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.custom-properties+xml", "/docProps/custom.xml")); this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml")); this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml")); this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", "/word/footnotes.xml")); diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index c6b4f8348d..c12b65ee6d 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -1,22 +1,13 @@ import { XmlComponent } from "file/xml-components"; +import { ICustomPropertyOptions } from "../custom-properties"; +import { IDocumentBackgroundOptions } from "../document"; import { DocumentAttributes } from "../document/document-attributes"; import { INumberingOptions } from "../numbering"; -import { HyperlinkType, Paragraph } from "../paragraph"; +import { Paragraph } from "../paragraph"; import { IStylesOptions } from "../styles"; import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components"; -export interface IInternalHyperlinkDefinition { - readonly text: string; - readonly type: HyperlinkType.INTERNAL; -} - -export interface IExternalHyperlinkDefinition { - readonly link: string; - readonly text: string; - readonly type: HyperlinkType.EXTERNAL; -} - export interface IPropertiesOptions { readonly title?: string; readonly subject?: string; @@ -33,9 +24,12 @@ export interface IPropertiesOptions { readonly children: Paragraph[]; }; }; - readonly hyperlinks?: { - readonly [key: string]: IInternalHyperlinkDefinition | IExternalHyperlinkDefinition; + readonly background?: IDocumentBackgroundOptions; + readonly features?: { + readonly trackRevisions?: boolean; }; + readonly compatabilityModeVersion?: number; + readonly customProperties?: ICustomPropertyOptions[]; } export class CoreProperties extends XmlComponent { diff --git a/src/file/custom-properties/custom-properties-attributes.ts b/src/file/custom-properties/custom-properties-attributes.ts new file mode 100644 index 0000000000..087c9e98a1 --- /dev/null +++ b/src/file/custom-properties/custom-properties-attributes.ts @@ -0,0 +1,13 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export interface ICustomPropertiesAttributes { + readonly xmlns: string; + readonly vt: string; +} + +export class CustomPropertiesAttributes extends XmlAttributeComponent { + protected readonly xmlKeys = { + xmlns: "xmlns", + vt: "xmlns:vt", + }; +} diff --git a/src/file/custom-properties/custom-properties.spec.ts b/src/file/custom-properties/custom-properties.spec.ts new file mode 100644 index 0000000000..a8bc92b7e4 --- /dev/null +++ b/src/file/custom-properties/custom-properties.spec.ts @@ -0,0 +1,66 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { CustomProperties } from "./custom-properties"; + +describe("CustomProperties", () => { + describe("#constructor()", () => { + it("sets the appropriate attributes on the top-level", () => { + const properties = new CustomProperties([]); + const tree = new Formatter().format(properties); + expect(tree).to.deep.equal({ + Properties: { + _attr: { + xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties", + "xmlns:vt": "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", + }, + }, + }); + }); + + it("should create custom properties with all the attributes given", () => { + const properties = new CustomProperties([ + { name: "Address", value: "123" }, + { name: "Author", value: "456" }, + ]); + const tree = new Formatter().format(properties); + expect(tree).to.deep.equal({ + Properties: [ + { + _attr: { + xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties", + "xmlns:vt": "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", + }, + }, + { + property: [ + { + _attr: { + fmtid: "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", + pid: "2", + name: "Address", + }, + }, + { + "vt:lpwstr": ["123"], + }, + ], + }, + { + property: [ + { + _attr: { + fmtid: "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", + pid: "3", + name: "Author", + }, + }, + { + "vt:lpwstr": ["456"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/custom-properties/custom-properties.ts b/src/file/custom-properties/custom-properties.ts new file mode 100644 index 0000000000..c254ceeca8 --- /dev/null +++ b/src/file/custom-properties/custom-properties.ts @@ -0,0 +1,37 @@ +import { IXmlableObject, XmlComponent } from "file/xml-components"; +import { CustomPropertiesAttributes } from "./custom-properties-attributes"; +import { CustomProperty, ICustomPropertyOptions } from "./custom-property"; + +export class CustomProperties extends XmlComponent { + // tslint:disable-next-line:readonly-keyword + private nextId: number; + private readonly properties: CustomProperty[] = []; + + constructor(properties: ICustomPropertyOptions[]) { + super("Properties"); + + this.root.push( + new CustomPropertiesAttributes({ + xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties", + vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", + }), + ); + + // I'm not sure why, but every example I have seen starts with 2 + // https://docs.microsoft.com/en-us/office/open-xml/how-to-set-a-custom-property-in-a-word-processing-document + this.nextId = 2; + + for (const property of properties) { + this.addCustomProperty(property); + } + } + + public prepForXml(): IXmlableObject | undefined { + this.properties.forEach((x) => this.root.push(x)); + return super.prepForXml(); + } + + public addCustomProperty(property: ICustomPropertyOptions): void { + this.properties.push(new CustomProperty(this.nextId++, property)); + } +} diff --git a/src/file/custom-properties/custom-property-attributes.ts b/src/file/custom-properties/custom-property-attributes.ts new file mode 100644 index 0000000000..9b2697fe94 --- /dev/null +++ b/src/file/custom-properties/custom-property-attributes.ts @@ -0,0 +1,15 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export interface ICustomPropertyAttributes { + readonly fmtid: string; + readonly pid: string; + readonly name: string; +} + +export class CustomPropertyAttributes extends XmlAttributeComponent { + protected readonly xmlKeys = { + fmtid: "fmtid", + pid: "pid", + name: "name", + }; +} diff --git a/src/file/custom-properties/custom-property.ts b/src/file/custom-properties/custom-property.ts new file mode 100644 index 0000000000..fc18db2667 --- /dev/null +++ b/src/file/custom-properties/custom-property.ts @@ -0,0 +1,28 @@ +import { XmlComponent } from "file/xml-components"; +import { CustomPropertyAttributes } from "./custom-property-attributes"; + +export interface ICustomPropertyOptions { + readonly name: string; + readonly value: string; +} + +export class CustomProperty extends XmlComponent { + constructor(id: number, properties: ICustomPropertyOptions) { + super("property"); + this.root.push( + new CustomPropertyAttributes({ + fmtid: "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", + pid: id.toString(), + name: properties.name, + }), + ); + this.root.push(new CustomPropertyValue(properties.value)); + } +} + +export class CustomPropertyValue extends XmlComponent { + constructor(value: string) { + super("vt:lpwstr"); + this.root.push(value); + } +} diff --git a/src/file/custom-properties/index.ts b/src/file/custom-properties/index.ts new file mode 100644 index 0000000000..132da63d92 --- /dev/null +++ b/src/file/custom-properties/index.ts @@ -0,0 +1,2 @@ +export * from "./custom-properties"; +export * from "./custom-property"; diff --git a/src/file/document-wrapper.spec.ts b/src/file/document-wrapper.spec.ts new file mode 100644 index 0000000000..344fded379 --- /dev/null +++ b/src/file/document-wrapper.spec.ts @@ -0,0 +1,16 @@ +import { expect } from "chai"; + +import { DocumentWrapper } from "./document-wrapper"; + +describe("DocumentWrapper", () => { + describe("#constructor", () => { + it("should create", () => { + const file = new DocumentWrapper({ background: {} }); + + // tslint:disable-next-line: no-unused-expression + expect(file.View).to.be.ok; + // tslint:disable-next-line: no-unused-expression + expect(file.Relationships).to.be.ok; + }); + }); +}); diff --git a/src/file/document-wrapper.ts b/src/file/document-wrapper.ts new file mode 100644 index 0000000000..a699136727 --- /dev/null +++ b/src/file/document-wrapper.ts @@ -0,0 +1,28 @@ +import { Document, IDocumentOptions } from "./document"; +import { Footer } from "./footer"; +import { FootNotes } from "./footnotes"; +import { Header } from "./header/header"; +import { Relationships } from "./relationships"; + +export interface IViewWrapper { + readonly View: Document | Footer | Header | FootNotes; + readonly Relationships: Relationships; +} + +export class DocumentWrapper implements IViewWrapper { + private readonly document: Document; + private readonly relationships: Relationships; + + constructor(options: IDocumentOptions) { + this.document = new Document(options); + this.relationships = new Relationships(); + } + + public get View(): Document { + return this.document; + } + + public get Relationships(): Relationships { + return this.relationships; + } +} diff --git a/src/file/document/body/body.spec.ts b/src/file/document/body/body.spec.ts index b63a95dcd1..3e2a3155eb 100644 --- a/src/file/document/body/body.spec.ts +++ b/src/file/document/body/body.spec.ts @@ -39,7 +39,7 @@ describe("Body", () => { }, }, }, - { "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } }, + { "w:cols": { _attr: { "w:space": 708, "w:sep": false, "w:num": 1 } } }, { "w:docGrid": { _attr: { "w:linePitch": 360 } } }, ], }, diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index a0b7c27a2c..4b0e588809 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -1,6 +1,7 @@ +import { IViewWrapper } from "file/document-wrapper"; import { IXmlableObject, XmlComponent } from "file/xml-components"; + import { Paragraph, ParagraphProperties, TableOfContents } from "../.."; -import { File } from "../../../file"; import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; export class Body extends XmlComponent { @@ -25,7 +26,7 @@ export class Body extends XmlComponent { this.sections.push(new SectionProperties(options)); } - public prepForXml(file?: File): IXmlableObject | undefined { + public prepForXml(file?: IViewWrapper): IXmlableObject | undefined { if (this.sections.length === 1) { this.root.splice(0, 1); this.root.push(this.sections.pop() as SectionProperties); @@ -45,7 +46,7 @@ export class Body extends XmlComponent { private createSectionParagraph(section: SectionProperties): Paragraph { const paragraph = new Paragraph({}); const properties = new ParagraphProperties({}); - properties.addChildElement(section); + properties.push(section); paragraph.addChildElement(properties); return paragraph; } diff --git a/src/file/document/body/section-properties/columns/columns-attributes.ts b/src/file/document/body/section-properties/columns/columns-attributes.ts index b5a14315cc..40140bd63f 100644 --- a/src/file/document/body/section-properties/columns/columns-attributes.ts +++ b/src/file/document/body/section-properties/columns/columns-attributes.ts @@ -1,13 +1,13 @@ import { XmlAttributeComponent } from "file/xml-components"; -export interface IColumnsAttributes { +export class ColumnsAttributes extends XmlAttributeComponent<{ readonly space?: number; readonly num?: number; -} - -export class ColumnsAttributes extends XmlAttributeComponent { + readonly separate?: boolean; +}> { protected readonly xmlKeys = { space: "w:space", num: "w:num", + separate: "w:sep", }; } diff --git a/src/file/document/body/section-properties/columns/columns.ts b/src/file/document/body/section-properties/columns/columns.ts index d8c7eef577..c074f189d9 100644 --- a/src/file/document/body/section-properties/columns/columns.ts +++ b/src/file/document/body/section-properties/columns/columns.ts @@ -2,12 +2,13 @@ import { XmlComponent } from "file/xml-components"; import { ColumnsAttributes } from "./columns-attributes"; export class Columns extends XmlComponent { - constructor(space: number, num: number) { + constructor(space: number, num: number, separate: boolean) { super("w:cols"); this.root.push( new ColumnsAttributes({ space: space, num: num, + separate: separate, }), ); } diff --git a/src/file/document/body/section-properties/index.ts b/src/file/document/body/section-properties/index.ts index 47e56ec172..ee0820c640 100644 --- a/src/file/document/body/section-properties/index.ts +++ b/src/file/document/body/section-properties/index.ts @@ -6,3 +6,4 @@ export * from "./page-number"; export * from "./page-border"; export * from "./line-number"; export * from "./vertical-align"; +export * from "./type"; diff --git a/src/file/document/body/section-properties/page-number/page-number.ts b/src/file/document/body/section-properties/page-number/page-number.ts index d876c265af..b6bd5a6e86 100644 --- a/src/file/document/body/section-properties/page-number/page-number.ts +++ b/src/file/document/body/section-properties/page-number/page-number.ts @@ -14,6 +14,7 @@ export enum PageNumberFormat { ORDINAL_TEXT = "ordinalText", UPPER_LETTER = "upperLetter", UPPER_ROMAN = "upperRoman", + DECIMAL_FULL_WIDTH = "decimalFullWidth", } export interface IPageNumberTypeAttributes { diff --git a/src/file/document/body/section-properties/section-properties.spec.ts b/src/file/document/body/section-properties/section-properties.spec.ts index 70fc567b83..dea16f5ac3 100644 --- a/src/file/document/body/section-properties/section-properties.spec.ts +++ b/src/file/document/body/section-properties/section-properties.spec.ts @@ -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"; @@ -8,6 +9,7 @@ import { Media } from "file/media"; import { PageBorderOffsetFrom } from "./page-border"; import { PageNumberFormat } from "./page-number"; import { SectionProperties } from "./section-properties"; +import { SectionType } from "./type/section-type-attributes"; import { SectionVerticalAlignValue } from "./vertical-align"; describe("SectionProperties", () => { @@ -18,10 +20,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, @@ -29,8 +31,9 @@ describe("SectionProperties", () => { column: { space: 708, count: 1, + separate: true, }, - linePitch: 360, + linePitch: convertInchesToTwip(0.25), headers: { default: new HeaderWrapper(media, 100), }, @@ -61,7 +64,7 @@ describe("SectionProperties", () => { }, }); - expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } }); + expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:sep": true, "w:num": 1 } } }); expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } }); expect(tree["w:sectPr"][4]).to.deep.equal({ "w:headerReference": { _attr: { "r:id": "rId100", "w:type": "default" } } }); expect(tree["w:sectPr"][5]).to.deep.equal({ "w:footerReference": { _attr: { "r:id": "rId200", "w:type": "even" } } }); @@ -88,7 +91,7 @@ describe("SectionProperties", () => { }, }, }); - expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:num": 1 } } }); + expect(tree["w:sectPr"][2]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:sep": false, "w:num": 1 } } }); expect(tree["w:sectPr"][3]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } }); }); @@ -198,5 +201,17 @@ describe("SectionProperties", () => { const pgNumType = tree["w:sectPr"].find((item) => item["w:pgNumType"] !== undefined); expect(pgNumType).to.equal(undefined); }); + + it("should create section properties with section type", () => { + const properties = new SectionProperties({ + type: SectionType.CONTINUOUS, + }); + const tree = new Formatter().format(properties); + expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); + const type = tree["w:sectPr"].find((item) => item["w:type"] !== undefined); + expect(type).to.deep.equal({ + "w:type": { _attr: { "w:val": "continuous" } }, + }); + }); }); }); diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 37e09e4498..83bb93e580 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -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"; @@ -18,6 +19,8 @@ import { IPageNumberTypeAttributes, PageNumberType } from "./page-number"; import { PageSize } from "./page-size/page-size"; import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes"; import { TitlePage } from "./title-page/title-page"; +import { Type } from "./type/section-type"; +import { SectionType } from "./type/section-type-attributes"; import { ISectionVerticalAlignAttributes, SectionVerticalAlign } from "./vertical-align"; export interface IHeaderFooterGroup { @@ -51,12 +54,16 @@ export type SectionPropertiesOptions = IPageSizeAttributes & readonly column?: { readonly space?: number; readonly count?: number; + readonly separate?: boolean; }; + readonly type?: SectionType; }; // Need to decouple this from the attributes export class SectionProperties extends XmlComponent { - private readonly options: SectionPropertiesOptions; + public readonly width: number; + public readonly rightMargin: number; + public readonly leftMargin: number; constructor(options: SectionPropertiesOptions = { column: {} }) { super("w:sectPr"); @@ -64,10 +71,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, @@ -90,12 +97,16 @@ export class SectionProperties extends XmlComponent { pageBorderLeft, titlePage = false, verticalAlign, + type, } = options; - this.options = options; + this.leftMargin = left; + this.rightMargin = right; + this.width = width; + this.root.push(new PageSize(width, height, orientation)); this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror)); - this.root.push(new Columns(column.space ? column.space : 708, column.count ? column.count : 1)); + this.root.push(new Columns(column.space ? column.space : 708, column.count ? column.count : 1, column.separate ?? false)); this.root.push(new DocumentGrid(linePitch)); this.addHeaders(headers); @@ -128,6 +139,10 @@ export class SectionProperties extends XmlComponent { if (verticalAlign) { this.root.push(new SectionVerticalAlign(verticalAlign)); } + + if (type) { + this.root.push(new Type(type)); + } } private addHeaders(headers?: IHeaderFooterGroup): void { @@ -136,7 +151,7 @@ export class SectionProperties extends XmlComponent { this.root.push( new HeaderReference({ headerType: HeaderReferenceType.DEFAULT, - headerId: headers.default.Header.ReferenceId, + headerId: headers.default.View.ReferenceId, }), ); } @@ -145,7 +160,7 @@ export class SectionProperties extends XmlComponent { this.root.push( new HeaderReference({ headerType: HeaderReferenceType.FIRST, - headerId: headers.first.Header.ReferenceId, + headerId: headers.first.View.ReferenceId, }), ); } @@ -154,7 +169,7 @@ export class SectionProperties extends XmlComponent { this.root.push( new HeaderReference({ headerType: HeaderReferenceType.EVEN, - headerId: headers.even.Header.ReferenceId, + headerId: headers.even.View.ReferenceId, }), ); } @@ -167,7 +182,7 @@ export class SectionProperties extends XmlComponent { this.root.push( new FooterReference({ footerType: FooterReferenceType.DEFAULT, - footerId: footers.default.Footer.ReferenceId, + footerId: footers.default.View.ReferenceId, }), ); } @@ -176,7 +191,7 @@ export class SectionProperties extends XmlComponent { this.root.push( new FooterReference({ footerType: FooterReferenceType.FIRST, - footerId: footers.first.Footer.ReferenceId, + footerId: footers.first.View.ReferenceId, }), ); } @@ -185,14 +200,10 @@ export class SectionProperties extends XmlComponent { this.root.push( new FooterReference({ footerType: FooterReferenceType.EVEN, - footerId: footers.even.Footer.ReferenceId, + footerId: footers.even.View.ReferenceId, }), ); } } } - - public get Options(): SectionPropertiesOptions { - return this.options; - } } diff --git a/src/file/document/body/section-properties/type/index.ts b/src/file/document/body/section-properties/type/index.ts new file mode 100644 index 0000000000..fd7a8abd9c --- /dev/null +++ b/src/file/document/body/section-properties/type/index.ts @@ -0,0 +1,2 @@ +export * from "./section-type"; +export * from "./section-type-attributes"; diff --git a/src/file/document/body/section-properties/type/section-type-attributes.ts b/src/file/document/body/section-properties/type/section-type-attributes.ts new file mode 100644 index 0000000000..4ac8dd60b4 --- /dev/null +++ b/src/file/document/body/section-properties/type/section-type-attributes.ts @@ -0,0 +1,17 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export enum SectionType { + CONTINUOUS = "continuous", + EVEN_PAGE = "evenPage", + NEXT_COLUMN = "nextColumn", + NEXT_PAGE = "nextPage", + ODD_PAGE = "oddPage", +} + +export class SectionTypeAttributes extends XmlAttributeComponent<{ + readonly val: SectionType; +}> { + protected readonly xmlKeys = { + val: "w:val", + }; +} diff --git a/src/file/document/body/section-properties/type/section-type.spec.ts b/src/file/document/body/section-properties/type/section-type.spec.ts new file mode 100644 index 0000000000..7276825fab --- /dev/null +++ b/src/file/document/body/section-properties/type/section-type.spec.ts @@ -0,0 +1,35 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { Type } from "./section-type"; +import { SectionType } from "./section-type-attributes"; + +describe("Type", () => { + it("should create with even page section type", () => { + const sectionType = new Type(SectionType.EVEN_PAGE); + + const tree = new Formatter().format(sectionType); + + expect(tree).to.deep.equal({ + "w:type": { + _attr: { + "w:val": "evenPage", + }, + }, + }); + }); + + it("should create with continuous section type", () => { + const sectionType = new Type(SectionType.CONTINUOUS); + + const tree = new Formatter().format(sectionType); + + expect(tree).to.deep.equal({ + "w:type": { + _attr: { + "w:val": "continuous", + }, + }, + }); + }); +}); diff --git a/src/file/document/body/section-properties/type/section-type.ts b/src/file/document/body/section-properties/type/section-type.ts new file mode 100644 index 0000000000..3a11f2e041 --- /dev/null +++ b/src/file/document/body/section-properties/type/section-type.ts @@ -0,0 +1,10 @@ +// http://officeopenxml.com/WPsection.php +import { XmlComponent } from "file/xml-components"; +import { SectionType, SectionTypeAttributes } from "./section-type-attributes"; + +export class Type extends XmlComponent { + constructor(value: SectionType) { + super("w:type"); + this.root.push(new SectionTypeAttributes({ val: value })); + } +} diff --git a/src/file/document/document-background/document-background.spec.ts b/src/file/document/document-background/document-background.spec.ts new file mode 100644 index 0000000000..83d1fb36b1 --- /dev/null +++ b/src/file/document/document-background/document-background.spec.ts @@ -0,0 +1,53 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { DocumentBackground } from "./document-background"; + +describe("DocumentBackground", () => { + describe("#constructor()", () => { + it("should create a DocumentBackground with no options and set color to auto", () => { + const documentBackground = new DocumentBackground({}); + const tree = new Formatter().format(documentBackground); + expect(tree).to.deep.equal({ + "w:background": { + _attr: { + "w:color": "FFFFFF", + }, + }, + }); + }); + + it("should create a DocumentBackground with no options and set color to value", () => { + const documentBackground = new DocumentBackground({ color: "ffff00" }); + const tree = new Formatter().format(documentBackground); + expect(tree).to.deep.equal({ + "w:background": { + _attr: { + "w:color": "ffff00", + }, + }, + }); + }); + + it("should create a DocumentBackground with no options and set other values", () => { + const documentBackground = new DocumentBackground({ + color: "ffff00", + themeColor: "test", + themeShade: "test", + themeTint: "test", + }); + const tree = new Formatter().format(documentBackground); + expect(tree).to.deep.equal({ + "w:background": { + _attr: { + "w:color": "ffff00", + "w:themeColor": "test", + "w:themeShade": "test", + "w:themeTint": "test", + }, + }, + }); + }); + }); +}); diff --git a/src/file/document/document-background/document-background.ts b/src/file/document/document-background/document-background.ts new file mode 100644 index 0000000000..44b04aabe6 --- /dev/null +++ b/src/file/document/document-background/document-background.ts @@ -0,0 +1,39 @@ +// http://officeopenxml.com/WPdocument.php +// http://www.datypic.com/sc/ooxml/e-w_background-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +export class DocumentBackgroundAttributes extends XmlAttributeComponent<{ + readonly color: string; + readonly themeColor?: string; + readonly themeShade?: string; + readonly themeTint?: string; +}> { + protected readonly xmlKeys = { + color: "w:color", + themeColor: "w:themeColor", + themeShade: "w:themeShade", + themeTint: "w:themeTint", + }; +} + +export interface IDocumentBackgroundOptions { + readonly color?: string; + readonly themeColor?: string; + readonly themeShade?: string; + readonly themeTint?: string; +} + +export class DocumentBackground extends XmlComponent { + constructor(options: IDocumentBackgroundOptions) { + super("w:background"); + + this.root.push( + new DocumentBackgroundAttributes({ + color: options.color ? options.color : "FFFFFF", + themeColor: options.themeColor, + themeShade: options.themeShade, + themeTint: options.themeTint, + }), + ); + } +} diff --git a/src/file/document/document-background/index.ts b/src/file/document/document-background/index.ts new file mode 100644 index 0000000000..604f3da1f2 --- /dev/null +++ b/src/file/document/document-background/index.ts @@ -0,0 +1 @@ +export * from "./document-background"; diff --git a/src/file/document/document.spec.ts b/src/file/document/document.spec.ts index dba489601e..d903ff78aa 100644 --- a/src/file/document/document.spec.ts +++ b/src/file/document/document.spec.ts @@ -8,7 +8,7 @@ describe("Document", () => { let document: Document; beforeEach(() => { - document = new Document(); + document = new Document({ background: {} }); }); describe("#constructor()", () => { @@ -38,6 +38,13 @@ describe("Document", () => { "mc:Ignorable": "w14 w15 wp14", }, }, + { + "w:background": { + _attr: { + "w:color": "FFFFFF", + }, + }, + }, { "w:body": {} }, ], }); diff --git a/src/file/document/document.ts b/src/file/document/document.ts index 80b04a379c..cc33709076 100644 --- a/src/file/document/document.ts +++ b/src/file/document/document.ts @@ -1,15 +1,20 @@ // http://officeopenxml.com/WPdocument.php import { XmlComponent } from "file/xml-components"; -import { Hyperlink, Paragraph } from "../paragraph"; +import { ConcreteHyperlink, Paragraph } from "../paragraph"; import { Table } from "../table"; import { TableOfContents } from "../table-of-contents"; import { Body } from "./body"; import { DocumentAttributes } from "./document-attributes"; +import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background"; + +export interface IDocumentOptions { + readonly background: IDocumentBackgroundOptions; +} export class Document extends XmlComponent { private readonly body: Body; - constructor() { + constructor(options: IDocumentOptions) { super("w:document"); this.root.push( new DocumentAttributes({ @@ -33,10 +38,11 @@ export class Document extends XmlComponent { }), ); this.body = new Body(); + this.root.push(new DocumentBackground(options.background)); this.root.push(this.body); } - public add(item: Paragraph | Table | TableOfContents | Hyperlink): Document { + public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document { this.body.push(item); return this; } diff --git a/src/file/document/index.ts b/src/file/document/index.ts index 3430666623..a93dd86f99 100644 --- a/src/file/document/index.ts +++ b/src/file/document/index.ts @@ -1,3 +1,4 @@ export * from "./document"; export * from "./document-attributes"; export * from "./body"; +export * from "./document-background"; diff --git a/src/file/drawing/anchor/anchor.spec.ts b/src/file/drawing/anchor/anchor.spec.ts index 6b86a31346..10d4b08d13 100644 --- a/src/file/drawing/anchor/anchor.spec.ts +++ b/src/file/drawing/anchor/anchor.spec.ts @@ -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, + }); + }); }); }); diff --git a/src/file/drawing/anchor/anchor.ts b/src/file/drawing/anchor/anchor.ts index d52c349ebb..7eb4487a89 100644 --- a/src/file/drawing/anchor/anchor.ts +++ b/src/file/drawing/anchor/anchor.ts @@ -11,42 +11,32 @@ import { Extent } from "./../extent/extent"; import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties"; import { AnchorAttributes } from "./anchor-attributes"; -const defaultOptions: IFloating = { - allowOverlap: true, - behindDocument: false, - lockAnchor: false, - layoutInCell: true, - verticalPosition: {}, - horizontalPosition: {}, -}; - export class Anchor extends XmlComponent { constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) { super("wp:anchor"); - const floating = { - margins: { - top: 0, - bottom: 0, - left: 0, - right: 0, - }, - ...defaultOptions, + const floating: IFloating = { + allowOverlap: true, + behindDocument: false, + lockAnchor: false, + layoutInCell: true, + verticalPosition: {}, + horizontalPosition: {}, ...drawingOptions.floating, }; this.root.push( new AnchorAttributes({ - distT: floating.margins.top || 0, - distB: floating.margins.bottom || 0, - distL: floating.margins.left || 0, - distR: floating.margins.right || 0, + distT: floating.margins ? floating.margins.top || 0 : 0, + distB: floating.margins ? floating.margins.bottom || 0 : 0, + distL: floating.margins ? floating.margins.left || 0 : 0, + distR: floating.margins ? floating.margins.right || 0 : 0, simplePos: "0", // note: word doesn't fully support - so we use 0 allowOverlap: floating.allowOverlap === true ? "1" : "0", behindDoc: floating.behindDocument === true ? "1" : "0", locked: floating.lockAnchor === true ? "1" : "0", layoutInCell: floating.layoutInCell === true ? "1" : "0", - relativeHeight: dimensions.emus.y, + relativeHeight: floating.zIndex ? floating.zIndex : dimensions.emus.y, }), ); diff --git a/src/file/drawing/floating/floating-position.ts b/src/file/drawing/floating/floating-position.ts index 9191ef1e1b..6c5ad7f332 100644 --- a/src/file/drawing/floating/floating-position.ts +++ b/src/file/drawing/floating/floating-position.ts @@ -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; } diff --git a/src/file/drawing/inline/inline.ts b/src/file/drawing/inline/inline.ts index 7c40e7c3b3..bf83e36764 100644 --- a/src/file/drawing/inline/inline.ts +++ b/src/file/drawing/inline/inline.ts @@ -12,7 +12,7 @@ export class Inline extends XmlComponent { private readonly extent: Extent; private readonly graphic: Graphic; - constructor(readonly mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) { + constructor(mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) { super("wp:inline"); this.root.push( diff --git a/src/file/file.spec.ts b/src/file/file.spec.ts index d9beb46a3c..7b43920dca 100644 --- a/src/file/file.spec.ts +++ b/src/file/file.spec.ts @@ -5,7 +5,7 @@ import { Formatter } from "export/formatter"; import { File } from "./file"; import { Footer, Header } from "./header"; -import { HyperlinkRef, HyperlinkType, Paragraph } from "./paragraph"; +import { Paragraph } from "./paragraph"; import { Table, TableCell, TableRow } from "./table"; import { TableOfContents } from "./table-of-contents"; @@ -18,7 +18,7 @@ describe("File", () => { children: [], }); - const tree = new Formatter().format(doc.Document.Body); + const tree = new Formatter().format(doc.Document.View.Body); expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); @@ -37,7 +37,7 @@ describe("File", () => { children: [], }); - const tree = new Formatter().format(doc.Document.Body); + const tree = new Formatter().format(doc.Document.View.Body); expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default"); @@ -56,7 +56,7 @@ describe("File", () => { children: [], }); - const tree = new Formatter().format(doc.Document.Body); + const tree = new Formatter().format(doc.Document.View.Body); expect(tree["w:body"][0]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); expect(tree["w:body"][0]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("first"); @@ -79,7 +79,7 @@ describe("File", () => { children: [], }); - const tree = new Formatter().format(doc.Document.Body); + const tree = new Formatter().format(doc.Document.View.Body); expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default"); expect(tree["w:body"][0]["w:sectPr"][5]["w:headerReference"]._attr["w:type"]).to.equal("first"); @@ -97,7 +97,7 @@ describe("File", () => { }, ]); - const tree = new Formatter().format(doc.Document.Body); + const tree = new Formatter().format(doc.Document.View.Body); expect(tree).to.deep.equal({ "w:body": [ @@ -148,6 +148,7 @@ describe("File", () => { "w:cols": { _attr: { "w:num": 1, + "w:sep": false, "w:space": 708, }, }, @@ -164,22 +165,12 @@ describe("File", () => { ], }); }); - - it("should add hyperlink child", () => { - const doc = new File(undefined, undefined, [ - { - children: [new HyperlinkRef("test")], - }, - ]); - - expect(doc.HyperlinkCache).to.deep.equal({}); - }); }); describe("#addSection", () => { it("should call the underlying document's add a Paragraph", () => { const file = new File(); - const spy = sinon.spy(file.Document, "add"); + const spy = sinon.spy(file.Document.View, "add"); file.addSection({ children: [new Paragraph({})], }); @@ -187,19 +178,9 @@ describe("File", () => { expect(spy.called).to.equal(true); }); - it("should add hyperlink child", () => { - const doc = new File(); - - doc.addSection({ - children: [new HyperlinkRef("test")], - }); - - expect(doc.HyperlinkCache).to.deep.equal({}); - }); - it("should call the underlying document's add when adding a Table", () => { const file = new File(); - const spy = sinon.spy(file.Document, "add"); + const spy = sinon.spy(file.Document.View, "add"); file.addSection({ children: [ new Table({ @@ -221,7 +202,7 @@ describe("File", () => { it("should call the underlying document's add when adding an Image (paragraph)", () => { const file = new File(); - const spy = sinon.spy(file.Document, "add"); + const spy = sinon.spy(file.Document.View, "add"); // tslint:disable-next-line:no-any file.addSection({ children: [new Paragraph("")], @@ -234,34 +215,25 @@ describe("File", () => { describe("#addSection", () => { it("should call the underlying document's add", () => { const file = new File(); - const spy = sinon.spy(file.Document, "add"); + const spy = sinon.spy(file.Document.View, "add"); file.addSection({ children: [new TableOfContents()], }); expect(spy.called).to.equal(true); }); + }); - it.only("should create hyperlinks", () => { - const wrapper = new File({ - hyperlinks: { - myHyperLink: { - link: "test.com", - text: "test", - type: HyperlinkType.EXTERNAL, - }, + describe("#addTrackRevisionsFeature", () => { + it("should call the underlying document's add", () => { + const file = new File({ + features: { + trackRevisions: true, }, }); - expect(wrapper.HyperlinkCache.myHyperLink).to.not.be.undefined(""); - }); - }); - - describe("#HyperlinkCache", () => { - it("should initially have empty hyperlink cache", () => { - const file = new File(); - - expect(file.HyperlinkCache).to.deep.equal({}); + // tslint:disable-next-line: no-unused-expression no-string-literal + expect(file.Settings["trackRevisions"]).to.exist; }); }); @@ -275,7 +247,7 @@ describe("File", () => { }, }); - const tree = new Formatter().format(wrapper.FootNotes); + const tree = new Formatter().format(wrapper.FootNotes.View); expect(tree).to.deep.equal({ "w:footnotes": [ diff --git a/src/file/file.ts b/src/file/file.ts index 962eefca21..89634a7978 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -1,9 +1,8 @@ -import * as shortid from "shortid"; - import { AppProperties } from "./app-properties/app-properties"; import { ContentTypes } from "./content-types/content-types"; import { CoreProperties, IPropertiesOptions } from "./core-properties"; -import { Document } from "./document"; +import { CustomProperties } from "./custom-properties"; +import { DocumentWrapper } from "./document-wrapper"; import { FooterReferenceType, HeaderReferenceType, @@ -13,14 +12,13 @@ import { import { IPageMarginAttributes } from "./document/body/section-properties/page-margin/page-margin-attributes"; import { IFileProperties } from "./file-properties"; import { FooterWrapper, IDocumentFooter } from "./footer-wrapper"; -import { FootNotes } from "./footnotes"; +import { FootnotesWrapper } from "./footnotes-wrapper"; import { Footer, Header } from "./header"; import { HeaderWrapper, IDocumentHeader } from "./header-wrapper"; import { Media } from "./media"; import { Numbering } from "./numbering"; -import { Hyperlink, HyperlinkRef, HyperlinkType, Paragraph } from "./paragraph"; +import { Paragraph } from "./paragraph"; import { Relationships } from "./relationships"; -import { TargetModeType } from "./relationships/relationship/relationship"; import { Settings } from "./settings"; import { Styles } from "./styles"; import { ExternalStylesFactory } from "./styles/external-styles-factory"; @@ -42,27 +40,26 @@ export interface ISectionOptions { readonly size?: IPageSizeAttributes; readonly margins?: IPageMarginAttributes; readonly properties?: SectionPropertiesOptions; - readonly children: Array; + readonly children: (Paragraph | Table | TableOfContents)[]; } export class File { // tslint:disable-next-line:readonly-keyword private currentRelationshipId: number = 1; - private readonly document: Document; + private readonly documentWrapper: DocumentWrapper; private readonly headers: IDocumentHeader[] = []; private readonly footers: IDocumentFooter[] = []; - private readonly docRelationships: Relationships; private readonly coreProperties: CoreProperties; private readonly numbering: Numbering; private readonly media: Media; private readonly fileRelationships: Relationships; - private readonly footNotes: FootNotes; + private readonly footnotesWrapper: FootnotesWrapper; private readonly settings: Settings; private readonly contentTypes: ContentTypes; + private readonly customProperties: CustomProperties; private readonly appProperties: AppProperties; private readonly styles: Styles; - private readonly hyperlinkCache: { readonly [key: string]: Hyperlink } = {}; constructor( options: IPropertiesOptions = { @@ -81,13 +78,15 @@ export class File { config: [], }, ); - this.docRelationships = new Relationships(); this.fileRelationships = new Relationships(); + this.customProperties = new CustomProperties(options.customProperties ?? []); this.appProperties = new AppProperties(); - this.footNotes = new FootNotes(); + this.footnotesWrapper = new FootnotesWrapper(); this.contentTypes = new ContentTypes(); - this.document = new Document(); - this.settings = new Settings(); + this.documentWrapper = new DocumentWrapper({ background: options.background || {} }); + this.settings = new Settings({ + compatabilityModeVersion: options.compatabilityModeVersion, + }); this.media = fileProperties.template && fileProperties.template.media ? fileProperties.template.media : new Media(); @@ -107,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, @@ -132,16 +131,10 @@ export class File { } for (const section of sections) { - this.document.Body.addSection(section.properties ? section.properties : {}); + this.documentWrapper.View.Body.addSection(section.properties ? section.properties : {}); for (const child of section.children) { - if (child instanceof HyperlinkRef) { - const hyperlink = this.hyperlinkCache[child.id]; - this.document.add(hyperlink); - continue; - } - - this.document.add(child); + this.documentWrapper.View.add(child); } } @@ -151,29 +144,14 @@ export class File { continue; } - this.footNotes.createFootNote(parseFloat(key), options.footnotes[key].children); + this.footnotesWrapper.View.createFootNote(parseFloat(key), options.footnotes[key].children); } } - if (options.hyperlinks) { - const cache = {}; - - for (const key in options.hyperlinks) { - if (!options.hyperlinks[key]) { - continue; - } - - const hyperlinkRef = options.hyperlinks[key]; - - const hyperlink = - hyperlinkRef.type === HyperlinkType.EXTERNAL - ? this.createHyperlink(hyperlinkRef.link, hyperlinkRef.text) - : this.createInternalHyperLink(key, hyperlinkRef.text); - - cache[key] = hyperlink; + if (options.features) { + if (options.features.trackRevisions) { + this.settings.addTrackRevisions(); } - - this.hyperlinkCache = cache; } } @@ -185,7 +163,7 @@ export class File { properties, children, }: ISectionOptions): void { - this.document.Body.addSection({ + this.documentWrapper.View.Body.addSection({ ...properties, headers: { default: headers.default ? this.createHeader(headers.default) : this.createHeader(new Header()), @@ -202,40 +180,16 @@ export class File { }); for (const child of children) { - if (child instanceof HyperlinkRef) { - const hyperlink = this.hyperlinkCache[child.id]; - this.document.add(hyperlink); - continue; - } - - this.document.add(child); + this.documentWrapper.View.add(child); } } public verifyUpdateFields(): void { - if (this.document.getTablesOfContents().length) { + if (this.documentWrapper.View.getTablesOfContents().length) { this.settings.addUpdateFields(); } } - private createHyperlink(link: string, text: string = link): Hyperlink { - const hyperlink = new Hyperlink(text, shortid.generate().toLowerCase()); - this.docRelationships.createRelationship( - hyperlink.linkId, - "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", - link, - TargetModeType.EXTERNAL, - ); - return hyperlink; - } - - private createInternalHyperLink(anchor: string, text: string = anchor): Hyperlink { - const hyperlink = new Hyperlink(text, shortid.generate().toLowerCase(), anchor); - // NOTE: unlike File#createHyperlink(), since the link is to an internal bookmark - // we don't need to create a new relationship. - return hyperlink; - } - private createHeader(header: Header): HeaderWrapper { const wrapper = new HeaderWrapper(this.media, this.currentRelationshipId++); @@ -260,8 +214,8 @@ export class File { private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void { this.headers.push({ header, type }); - this.docRelationships.createRelationship( - header.Header.ReferenceId, + this.documentWrapper.Relationships.createRelationship( + header.View.ReferenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", `header${this.headers.length}.xml`, ); @@ -270,8 +224,8 @@ export class File { private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void { this.footers.push({ footer, type }); - this.docRelationships.createRelationship( - footer.Footer.ReferenceId, + this.documentWrapper.Relationships.createRelationship( + footer.View.ReferenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", `footer${this.footers.length}.xml`, ); @@ -294,31 +248,36 @@ export class File { "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml", ); + this.fileRelationships.createRelationship( + 4, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", + "docProps/custom.xml", + ); - this.docRelationships.createRelationship( + this.documentWrapper.Relationships.createRelationship( this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml", ); - this.docRelationships.createRelationship( + this.documentWrapper.Relationships.createRelationship( this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml", ); - this.docRelationships.createRelationship( + this.documentWrapper.Relationships.createRelationship( this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", "footnotes.xml", ); - this.docRelationships.createRelationship( + this.documentWrapper.Relationships.createRelationship( this.currentRelationshipId++, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings", "settings.xml", ); } - public get Document(): Document { - return this.document; + public get Document(): DocumentWrapper { + return this.documentWrapper; } public get Styles(): Styles { @@ -337,10 +296,6 @@ export class File { return this.media; } - public get DocumentRelationships(): Relationships { - return this.docRelationships; - } - public get FileRelationships(): Relationships { return this.fileRelationships; } @@ -357,19 +312,19 @@ export class File { return this.contentTypes; } + public get CustomProperties(): CustomProperties { + return this.customProperties; + } + public get AppProperties(): AppProperties { return this.appProperties; } - public get FootNotes(): FootNotes { - return this.footNotes; + public get FootNotes(): FootnotesWrapper { + return this.footnotesWrapper; } public get Settings(): Settings { return this.settings; } - - public get HyperlinkCache(): { readonly [key: string]: Hyperlink } { - return this.hyperlinkCache; - } } diff --git a/src/file/footer-wrapper.spec.ts b/src/file/footer-wrapper.spec.ts index 4f3e95acdb..2a32ad7968 100644 --- a/src/file/footer-wrapper.spec.ts +++ b/src/file/footer-wrapper.spec.ts @@ -10,7 +10,7 @@ describe("FooterWrapper", () => { describe("#add", () => { it("should call the underlying footer's addParagraph", () => { const file = new FooterWrapper(new Media(), 1); - const spy = sinon.spy(file.Footer, "add"); + const spy = sinon.spy(file.View, "add"); file.add(new Paragraph({})); expect(spy.called).to.equal(true); @@ -18,7 +18,7 @@ describe("FooterWrapper", () => { it("should call the underlying footer's addParagraph", () => { const file = new FooterWrapper(new Media(), 1); - const spy = sinon.spy(file.Footer, "add"); + const spy = sinon.spy(file.View, "add"); file.add( new Table({ rows: [ @@ -40,7 +40,7 @@ describe("FooterWrapper", () => { describe("#addChildElement", () => { it("should call the underlying footer's addChildElement", () => { const file = new FooterWrapper(new Media(), 1); - const spy = sinon.spy(file.Footer, "addChildElement"); + const spy = sinon.spy(file.View, "addChildElement"); // tslint:disable-next-line:no-any file.addChildElement({} as any); diff --git a/src/file/footer-wrapper.ts b/src/file/footer-wrapper.ts index 8390887ba4..e16a72e974 100644 --- a/src/file/footer-wrapper.ts +++ b/src/file/footer-wrapper.ts @@ -1,6 +1,7 @@ import { XmlComponent } from "file/xml-components"; import { FooterReferenceType } from "./document"; +import { IViewWrapper } from "./document-wrapper"; import { Footer } from "./footer/footer"; import { Media } from "./media"; import { Paragraph } from "./paragraph"; @@ -12,7 +13,7 @@ export interface IDocumentFooter { readonly type: FooterReferenceType; } -export class FooterWrapper { +export class FooterWrapper implements IViewWrapper { private readonly footer: Footer; private readonly relationships: Relationships; @@ -29,7 +30,7 @@ export class FooterWrapper { this.footer.addChildElement(childElement); } - public get Footer(): Footer { + public get View(): Footer { return this.footer; } diff --git a/src/file/footnotes-wrapper.spec.ts b/src/file/footnotes-wrapper.spec.ts new file mode 100644 index 0000000000..6427de6ee6 --- /dev/null +++ b/src/file/footnotes-wrapper.spec.ts @@ -0,0 +1,16 @@ +import { expect } from "chai"; + +import { FootnotesWrapper } from "./footnotes-wrapper"; + +describe("FootnotesWrapper", () => { + describe("#constructor", () => { + it("should create", () => { + const file = new FootnotesWrapper(); + + // tslint:disable-next-line: no-unused-expression + expect(file.View).to.be.ok; + // tslint:disable-next-line: no-unused-expression + expect(file.Relationships).to.be.ok; + }); + }); +}); diff --git a/src/file/footnotes-wrapper.ts b/src/file/footnotes-wrapper.ts new file mode 100644 index 0000000000..c76a8957c2 --- /dev/null +++ b/src/file/footnotes-wrapper.ts @@ -0,0 +1,21 @@ +import { IViewWrapper } from "./document-wrapper"; +import { FootNotes } from "./footnotes/footnotes"; +import { Relationships } from "./relationships"; + +export class FootnotesWrapper implements IViewWrapper { + private readonly footnotess: FootNotes; + private readonly relationships: Relationships; + + constructor() { + this.footnotess = new FootNotes(); + this.relationships = new Relationships(); + } + + public get View(): FootNotes { + return this.footnotess; + } + + public get Relationships(): Relationships { + return this.relationships; + } +} diff --git a/src/file/footnotes/footnote/footnote.ts b/src/file/footnotes/footnote/footnote.ts index b890e5a0c4..19c41824b7 100644 --- a/src/file/footnotes/footnote/footnote.ts +++ b/src/file/footnotes/footnote/footnote.ts @@ -9,8 +9,14 @@ export enum FootnoteType { CONTINUATION_SEPERATOR = "continuationSeparator", } +export interface IFootnoteOptions { + readonly id: number; + readonly type?: FootnoteType; + readonly children: Paragraph[]; +} + export class Footnote extends XmlComponent { - constructor(options: { readonly id: number; readonly type?: FootnoteType; readonly children: Paragraph[] }) { + constructor(options: IFootnoteOptions) { super("w:footnote"); this.root.push( new FootnoteAttributes({ diff --git a/src/file/footnotes/footnotes.ts b/src/file/footnotes/footnotes.ts index 965c587fc9..05af80b6e7 100644 --- a/src/file/footnotes/footnotes.ts +++ b/src/file/footnotes/footnotes.ts @@ -72,6 +72,7 @@ export class FootNotes extends XmlComponent { id: id, children: paragraph, }); + this.root.push(footnote); } } diff --git a/src/file/header-wrapper.spec.ts b/src/file/header-wrapper.spec.ts index 00ee776a95..c6a7272d16 100644 --- a/src/file/header-wrapper.spec.ts +++ b/src/file/header-wrapper.spec.ts @@ -10,7 +10,7 @@ describe("HeaderWrapper", () => { describe("#add", () => { it("should call the underlying header's addChildElement for Paragraph", () => { const wrapper = new HeaderWrapper(new Media(), 1); - const spy = sinon.spy(wrapper.Header, "add"); + const spy = sinon.spy(wrapper.View, "add"); wrapper.add(new Paragraph({})); expect(spy.called).to.equal(true); @@ -18,7 +18,7 @@ describe("HeaderWrapper", () => { it("should call the underlying header's addChildElement for Table", () => { const wrapper = new HeaderWrapper(new Media(), 1); - const spy = sinon.spy(wrapper.Header, "add"); + const spy = sinon.spy(wrapper.View, "add"); wrapper.add( new Table({ rows: [ @@ -40,7 +40,7 @@ describe("HeaderWrapper", () => { describe("#addChildElement", () => { it("should call the underlying header's addChildElement", () => { const file = new HeaderWrapper(new Media(), 1); - const spy = sinon.spy(file.Header, "addChildElement"); + const spy = sinon.spy(file.View, "addChildElement"); // tslint:disable-next-line:no-any file.addChildElement({} as any); diff --git a/src/file/header-wrapper.ts b/src/file/header-wrapper.ts index 407399a8fe..945a9d674a 100644 --- a/src/file/header-wrapper.ts +++ b/src/file/header-wrapper.ts @@ -1,6 +1,7 @@ import { XmlComponent } from "file/xml-components"; import { HeaderReferenceType } from "./document"; +import { IViewWrapper } from "./document-wrapper"; import { Header } from "./header/header"; import { Media } from "./media"; import { Paragraph } from "./paragraph"; @@ -12,7 +13,7 @@ export interface IDocumentHeader { readonly type: HeaderReferenceType; } -export class HeaderWrapper { +export class HeaderWrapper implements IViewWrapper { private readonly header: Header; private readonly relationships: Relationships; @@ -31,7 +32,7 @@ export class HeaderWrapper { this.header.addChildElement(childElement); } - public get Header(): Header { + public get View(): Header { return this.header; } diff --git a/src/file/header.ts b/src/file/header.ts index 05e227d9f8..5f59ae2bec 100644 --- a/src/file/header.ts +++ b/src/file/header.ts @@ -2,7 +2,7 @@ import { Paragraph } from "./paragraph"; import { Table } from "./table"; export interface IHeaderOptions { - readonly children: Array; + readonly children: (Paragraph | Table)[]; } export class Header { diff --git a/src/file/index.ts b/src/file/index.ts index c4ce99e345..18f0a595e4 100644 --- a/src/file/index.ts +++ b/src/file/index.ts @@ -13,3 +13,4 @@ export * from "./header-wrapper"; export * from "./footer-wrapper"; export * from "./header"; export * from "./footnotes"; +export * from "./track-revision"; diff --git a/src/file/media/media.ts b/src/file/media/media.ts index 0d062c6d64..65a7f1bf58 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -1,14 +1,12 @@ import { IDrawingOptions } from "../drawing"; import { File } from "../file"; -import { FooterWrapper } from "../footer-wrapper"; -import { HeaderWrapper } from "../header-wrapper"; import { PictureRun } from "../paragraph"; import { IMediaData } from "./data"; // import { Image } from "./image"; export class Media { public static addImage( - file: File | HeaderWrapper | FooterWrapper, + file: File, buffer: Buffer | string | Uint8Array | ArrayBuffer, width?: number, height?: number, @@ -21,14 +19,7 @@ export class Media { private static generateId(): string { // https://gist.github.com/6174/6062387 - return ( - Math.random() - .toString(36) - .substring(2, 15) + - Math.random() - .toString(36) - .substring(2, 15) - ); + return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); } private readonly map: Map; @@ -89,7 +80,7 @@ export class Media { return imageData; } - public get Array(): IMediaData[] { + public get Array(): readonly IMediaData[] { const array = new Array(); this.map.forEach((data) => { diff --git a/src/file/numbering/abstract-numbering.spec.ts b/src/file/numbering/abstract-numbering.spec.ts index 59655aa40e..df5416f453 100644 --- a/src/file/numbering/abstract-numbering.spec.ts +++ b/src/file/numbering/abstract-numbering.spec.ts @@ -3,10 +3,11 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; import { EMPTY_OBJECT } from "file/xml-components"; -import { AlignmentType, TabStopPosition } from "../paragraph"; +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"; describe("AbstractNumbering", () => { it("stores its ID at its .id property", () => { @@ -19,7 +20,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 3, - format: "lowerLetter", + format: LevelFormat.LOWER_LETTER, text: "%1)", alignment: AlignmentType.END, }, @@ -28,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)" } } }); }); @@ -36,7 +37,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 3, - format: "lowerLetter", + format: LevelFormat.LOWER_LETTER, text: "%1)", }, ]); @@ -44,16 +45,30 @@ 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)" } } }); }); + it("has suffix", () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 3, + format: LevelFormat.LOWER_LETTER, + text: "%1)", + alignment: AlignmentType.END, + suffix: LevelSuffix.SPACE, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:suff": { _attr: { "w:val": "space" } } }); + }); + describe("formatting methods: paragraph properties", () => { it("#indent", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -72,7 +87,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -91,7 +106,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -110,7 +125,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -129,7 +144,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -148,7 +163,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -167,7 +182,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -201,7 +216,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -224,7 +239,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -247,7 +262,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -266,7 +281,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { paragraph: { @@ -283,22 +298,41 @@ describe("AbstractNumbering", () => { }); describe("formatting methods: run properties", () => { - it("#size", () => { - const abstractNumbering = new AbstractNumbering(1, [ - { - level: 0, - format: "lowerRoman", - text: "%0.", - style: { - run: { - size: 24, + const sizeTests = [ + { + size: 24, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: true, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: false, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: 26, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }], + }, + ]; + sizeTests.forEach(({ size, sizeComplexScript, expected }) => { + it(`#size ${size} cs ${sizeComplexScript}`, () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { size, sizeComplexScript }, }, }, - }, - ]); - const tree = new Formatter().format(abstractNumbering); - expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ - "w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }], + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected }); }); }); @@ -306,7 +340,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -325,7 +359,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -344,7 +378,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -364,7 +398,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -383,7 +417,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -402,7 +436,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -417,11 +451,11 @@ describe("AbstractNumbering", () => { }); }); - it("#font", () => { + it("#font by name", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -433,80 +467,31 @@ describe("AbstractNumbering", () => { const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": [ - { "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } }, + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:cs": "Times", + "w:eastAsia": "Times", + "w:hAnsi": "Times", + }, + }, + }, ], }); }); - it("#bold", () => { + it("#font for ascii and eastAsia", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { - bold: true, - }, - }, - }, - ]); - const tree = new Formatter().format(abstractNumbering); - expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ - "w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], - }); - }); - - it("#italics", () => { - const abstractNumbering = new AbstractNumbering(1, [ - { - level: 0, - format: "lowerRoman", - text: "%0.", - style: { - run: { - italics: true, - }, - }, - }, - ]); - const tree = new Formatter().format(abstractNumbering); - expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ - "w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], - }); - }); - - it("#highlight", () => { - const abstractNumbering = new AbstractNumbering(1, [ - { - level: 0, - format: "lowerRoman", - text: "%0.", - style: { - run: { - highlight: "005599", - }, - }, - }, - ]); - const tree = new Formatter().format(abstractNumbering); - expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ - "w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], - }); - }); - - it("#shadow", () => { - const abstractNumbering = new AbstractNumbering(1, [ - { - level: 0, - format: "lowerRoman", - text: "%0.", - style: { - run: { - shadow: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", + font: { + ascii: "Times", + eastAsia: "KaiTi", }, }, }, @@ -514,7 +499,198 @@ describe("AbstractNumbering", () => { ]); const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ - "w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, + ], + }); + }); + + const boldTests = [ + { + bold: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: false, + expected: [{ "w:b": { _attr: { "w:val": true } } }], + }, + ]; + boldTests.forEach(({ bold, boldComplexScript, expected }) => { + it(`#bold ${bold} cs ${boldComplexScript}`, () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { bold, boldComplexScript }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected }); + }); + }); + + const italicsTests = [ + { + italics: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: false, + expected: [{ "w:i": { _attr: { "w:val": true } } }], + }, + ]; + italicsTests.forEach(({ italics, italicsComplexScript, expected }) => { + it(`#italics ${italics} cs ${italicsComplexScript}`, () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { italics, italicsComplexScript }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected }); + }); + }); + + const highlightTests = [ + { + highlight: "005599", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: true, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: false, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: "550099", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }], + }, + ]; + highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => { + it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { highlight, highlightComplexScript }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected }); + }); + }); + + const shadingTests = [ + { + shadow: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: true, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: false, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "00FF00", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } }, + ], + }, + ]; + shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => { + it("#shadow correctly", () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { shadow, shading, shadingComplexScript }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected }); }); }); @@ -523,7 +699,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -542,7 +718,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -563,7 +739,7 @@ describe("AbstractNumbering", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { @@ -582,11 +758,53 @@ describe("AbstractNumbering", () => { }); }); + describe("#emphasisMark", () => { + it("should set emphasisMark to 'dot' if no arguments are given", () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { + emphasisMark: {}, + }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }); + }); + + it("should set the style if given", () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: LevelFormat.LOWER_ROMAN, + text: "%0.", + style: { + run: { + emphasisMark: { + type: EmphasisMarkType.DOT, + }, + }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }); + }); + }); + it("#color", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, - format: "lowerRoman", + format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { run: { diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index cbef58dfc0..22ff07acf3 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -1,19 +1,25 @@ +// http://officeopenxml.com/WPnumbering-numFmt.php import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; -import { - Alignment, - AlignmentType, - Indent, - KeepLines, - KeepNext, - Spacing, - TabStop, - TabStopType, - ThematicBreak, -} from "../paragraph/formatting"; -import { ParagraphProperties } from "../paragraph/properties"; -import * as formatting from "../paragraph/run/formatting"; -import { RunProperties } from "../paragraph/run/properties"; -import { IParagraphStyleOptions2, IRunStyleOptions } from "../styles/style-options"; +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; @@ -79,14 +85,14 @@ export enum LevelSuffix { export interface ILevelsOptions { readonly level: number; - readonly format?: string; + readonly format?: LevelFormat; readonly text?: string; readonly alignment?: AlignmentType; readonly start?: number; readonly suffix?: LevelSuffix; readonly style?: { - readonly run?: IRunStyleOptions; - readonly paragraph?: IParagraphStyleOptions2; + readonly run?: IRunStylePropertiesOptions; + readonly paragraph?: IParagraphStylePropertiesOptions; }; } @@ -125,8 +131,8 @@ export class LevelBase extends XmlComponent { this.root.push(new LevelText(text)); } - this.paragraphProperties = new ParagraphProperties({}); - this.runProperties = new RunProperties(); + this.paragraphProperties = new ParagraphProperties(style && style.paragraph); + this.runProperties = new RunProperties(style && style.run); this.root.push(this.paragraphProperties); this.root.push(this.runProperties); @@ -134,100 +140,6 @@ export class LevelBase extends XmlComponent { if (suffix) { this.root.push(new Suffix(suffix)); } - - if (style) { - if (style.run) { - if (style.run.size) { - this.runProperties.push(new formatting.Size(style.run.size)); - } - - if (style.run.bold) { - this.runProperties.push(new formatting.Bold()); - } - - if (style.run.italics) { - this.runProperties.push(new formatting.Italics()); - } - - if (style.run.smallCaps) { - this.runProperties.push(new formatting.SmallCaps()); - } - - if (style.run.allCaps) { - this.runProperties.push(new formatting.Caps()); - } - - if (style.run.strike) { - this.runProperties.push(new formatting.Strike()); - } - - if (style.run.doubleStrike) { - this.runProperties.push(new formatting.DoubleStrike()); - } - - if (style.run.subScript) { - this.runProperties.push(new formatting.SubScript()); - } - - if (style.run.superScript) { - this.runProperties.push(new formatting.SuperScript()); - } - - if (style.run.underline) { - this.runProperties.push(new formatting.Underline(style.run.underline.type, style.run.underline.color)); - } - - if (style.run.color) { - this.runProperties.push(new formatting.Color(style.run.color)); - } - - if (style.run.font) { - this.runProperties.push(new formatting.RunFonts(style.run.font)); - } - - if (style.run.highlight) { - this.runProperties.push(new formatting.Highlight(style.run.highlight)); - } - - if (style.run.shadow) { - this.runProperties.push(new formatting.Shading(style.run.shadow.type, style.run.shadow.fill, style.run.shadow.color)); - } - } - - if (style.paragraph) { - if (style.paragraph.alignment) { - this.paragraphProperties.push(new Alignment(style.paragraph.alignment)); - } - - if (style.paragraph.thematicBreak) { - this.paragraphProperties.push(new ThematicBreak()); - } - - if (style.paragraph.rightTabStop) { - this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, style.paragraph.rightTabStop)); - } - - if (style.paragraph.leftTabStop) { - this.paragraphProperties.push(new TabStop(TabStopType.LEFT, style.paragraph.leftTabStop)); - } - - if (style.paragraph.indent) { - this.paragraphProperties.push(new Indent(style.paragraph.indent)); - } - - if (style.paragraph.spacing) { - this.paragraphProperties.push(new Spacing(style.paragraph.spacing)); - } - - if (style.paragraph.keepNext) { - this.paragraphProperties.push(new KeepNext()); - } - - if (style.paragraph.keepLines) { - this.paragraphProperties.push(new KeepLines()); - } - } - } } } diff --git a/src/file/numbering/numbering.ts b/src/file/numbering/numbering.ts index b8747991d0..901f13f4bb 100644 --- a/src/file/numbering/numbering.ts +++ b/src/file/numbering/numbering.ts @@ -1,17 +1,18 @@ // 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 { - readonly config: Array<{ + readonly config: { readonly levels: ILevelsOptions[]; readonly reference: string; - }>; + }[]; } export class Numbering extends XmlComponent { @@ -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) }, }, }, }, diff --git a/src/file/paragraph/formatting/bidirectional.spec.ts b/src/file/paragraph/formatting/bidirectional.spec.ts new file mode 100644 index 0000000000..a197ada54e --- /dev/null +++ b/src/file/paragraph/formatting/bidirectional.spec.ts @@ -0,0 +1,15 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { Bidirectional } from "./bidirectional"; + +describe("Bidirectional", () => { + it("should create", () => { + const bidirectional = new Bidirectional(); + const tree = new Formatter().format(bidirectional); + expect(tree).to.deep.equal({ + "w:bidi": {}, + }); + }); +}); diff --git a/src/file/paragraph/index.ts b/src/file/paragraph/index.ts index 68a1b0b800..d68c1d7f03 100644 --- a/src/file/paragraph/index.ts +++ b/src/file/paragraph/index.ts @@ -3,3 +3,4 @@ export * from "./paragraph"; export * from "./properties"; export * from "./run"; export * from "./links"; +export * from "./math"; diff --git a/src/file/paragraph/links/bookmark.spec.ts b/src/file/paragraph/links/bookmark.spec.ts index 7975fefc96..778bdd50c2 100644 --- a/src/file/paragraph/links/bookmark.spec.ts +++ b/src/file/paragraph/links/bookmark.spec.ts @@ -19,7 +19,7 @@ describe("Bookmark", () => { const newJson = Utility.jsonify(bookmark); assert.equal(newJson.rootKey, undefined); assert.equal(newJson.start.rootKey, "w:bookmarkStart"); - assert.equal(newJson.text.rootKey, "w:r"); + assert.equal(newJson.children[0].rootKey, "w:r"); assert.equal(newJson.end.rootKey, "w:bookmarkEnd"); }); @@ -31,7 +31,7 @@ describe("Bookmark", () => { it("should create a bookmark with the correct attributes on the text element", () => { const newJson = Utility.jsonify(bookmark); - assert.equal(JSON.stringify(newJson.text.root[1].root[1]), JSON.stringify("Internal Link")); + assert.equal(JSON.stringify(newJson.children[0].root[1].root[1]), JSON.stringify("Internal Link")); }); it("should create a bookmark with the correct attributes on the bookmark end element", () => { diff --git a/src/file/paragraph/links/hyperlink.spec.ts b/src/file/paragraph/links/hyperlink.spec.ts index 4b06a933f5..50d6aa76aa 100644 --- a/src/file/paragraph/links/hyperlink.spec.ts +++ b/src/file/paragraph/links/hyperlink.spec.ts @@ -2,14 +2,20 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { Hyperlink } from "./"; -import { HyperlinkRef } from "./hyperlink"; +import { TextRun } from "../run"; +import { ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./hyperlink"; -describe("Hyperlink", () => { - let hyperlink: Hyperlink; +describe("ConcreteHyperlink", () => { + let hyperlink: ConcreteHyperlink; beforeEach(() => { - hyperlink = new Hyperlink("https://example.com", "superid"); + hyperlink = new ConcreteHyperlink( + new TextRun({ + text: "https://example.com", + style: "Hyperlink", + }), + "superid", + ); }); describe("#constructor()", () => { @@ -35,7 +41,14 @@ describe("Hyperlink", () => { describe("with optional anchor parameter", () => { beforeEach(() => { - hyperlink = new Hyperlink("Anchor Text", "superid2", "anchor"); + hyperlink = new ConcreteHyperlink( + new TextRun({ + text: "Anchor Text", + style: "Hyperlink", + }), + "superid2", + "anchor", + ); }); it("should create an internal link with anchor tag", () => { @@ -61,10 +74,53 @@ describe("Hyperlink", () => { }); }); -describe("HyperlinkRef", () => { +describe("ExternalHyperlink", () => { describe("#constructor()", () => { - const hyperlinkRef = new HyperlinkRef("test-id"); + it("should create", () => { + const externalHyperlink = new ExternalHyperlink({ + child: new TextRun("test"), + link: "http://www.google.com", + }); - expect(hyperlinkRef.id).to.equal("test-id"); + expect(externalHyperlink.options.link).to.equal("http://www.google.com"); + }); + }); +}); + +describe("InternalHyperlink", () => { + describe("#constructor()", () => { + it("should create", () => { + const internalHyperlink = new InternalHyperlink({ + child: new TextRun("test"), + anchor: "test-id", + }); + + const tree = new Formatter().format(internalHyperlink); + + expect(tree).to.deep.equal({ + "w:hyperlink": [ + { + _attr: { + "w:anchor": "test-id", + "w:history": 1, + }, + }, + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test", + ], + }, + ], + }, + ], + }); + }); }); }); diff --git a/src/file/paragraph/links/hyperlink.ts b/src/file/paragraph/links/hyperlink.ts index 302acfd603..a7512e7beb 100644 --- a/src/file/paragraph/links/hyperlink.ts +++ b/src/file/paragraph/links/hyperlink.ts @@ -1,6 +1,9 @@ // http://officeopenxml.com/WPhyperlink.php +import * as shortid from "shortid"; + import { XmlComponent } from "file/xml-components"; -import { TextRun } from "../run"; + +import { ParagraphChild } from "../paragraph"; import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes"; export enum HyperlinkType { @@ -8,15 +11,10 @@ export enum HyperlinkType { EXTERNAL = "EXTERNAL", } -export class HyperlinkRef { - constructor(public readonly id: string) {} -} - -export class Hyperlink extends XmlComponent { +export class ConcreteHyperlink extends XmlComponent { public readonly linkId: string; - private readonly textRun: TextRun; - constructor(text: string, relationshipId: string, anchor?: string) { + constructor(child: ParagraphChild, relationshipId: string, anchor?: string) { super("w:hyperlink"); this.linkId = relationshipId; @@ -29,14 +27,16 @@ export class Hyperlink extends XmlComponent { const attributes = new HyperlinkAttributes(props); this.root.push(attributes); - this.textRun = new TextRun({ - text: text, - style: "Hyperlink", - }); - this.root.push(this.textRun); - } - - public get TextRun(): TextRun { - return this.textRun; + this.root.push(child); } } + +export class InternalHyperlink extends ConcreteHyperlink { + constructor(options: { readonly child: ParagraphChild; readonly anchor: string }) { + super(options.child, shortid.generate().toLowerCase(), options.anchor); + } +} + +export class ExternalHyperlink { + constructor(public readonly options: { readonly child: ParagraphChild; readonly link: string }) {} +} diff --git a/src/file/paragraph/math/brackets/index.ts b/src/file/paragraph/math/brackets/index.ts new file mode 100644 index 0000000000..e6559cde29 --- /dev/null +++ b/src/file/paragraph/math/brackets/index.ts @@ -0,0 +1,4 @@ +export * from "./math-round-brackets"; +export * from "./math-square-brackets"; +export * from "./math-curly-brackets"; +export * from "./math-angled-brackets"; diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts new file mode 100644 index 0000000000..ccd73b192b --- /dev/null +++ b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathAngledBrackets } from "./math-angled-brackets"; + +describe("MathAngledBrackets", () => { + describe("#constructor()", () => { + it("should create a MathAngledBrackets with correct root key", () => { + const mathAngledBrackets = new MathAngledBrackets({ + children: [new MathRun("60")], + }); + + const tree = new Formatter().format(mathAngledBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "โŒฉ", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "โŒช", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.ts b/src/file/paragraph/math/brackets/math-angled-brackets.ts new file mode 100644 index 0000000000..48fe0d415d --- /dev/null +++ b/src/file/paragraph/math/brackets/math-angled-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathAngledBrackets extends XmlComponent { + constructor(options: { readonly children: MathComponent[] }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "โŒฉ", + endingCharacter: "โŒช", + }), + ); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/brackets/math-beginning-character.spec.ts b/src/file/paragraph/math/brackets/math-beginning-character.spec.ts new file mode 100644 index 0000000000..bf9196c0a9 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-beginning-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathBeginningCharacter } from "./math-beginning-character"; + +describe("MathBeginningCharacter", () => { + describe("#constructor()", () => { + it("should create a MathBeginningCharacter with correct root key", () => { + const mathBeginningCharacter = new MathBeginningCharacter("["); + + const tree = new Formatter().format(mathBeginningCharacter); + expect(tree).to.deep.equal({ + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-beginning-character.ts b/src/file/paragraph/math/brackets/math-beginning-character.ts new file mode 100644 index 0000000000..aa9e06d87a --- /dev/null +++ b/src/file/paragraph/math/brackets/math-beginning-character.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_begChr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathBeginningCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> { + protected readonly xmlKeys = { character: "m:val" }; +} + +export class MathBeginningCharacter extends XmlComponent { + constructor(character: string) { + super("m:begChr"); + + this.root.push(new MathBeginningCharacterAttributes({ character })); + } +} diff --git a/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts b/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts new file mode 100644 index 0000000000..d80976d8f6 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts @@ -0,0 +1,45 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathBracketProperties } from "./math-bracket-properties"; + +describe("MathBracketProperties", () => { + describe("#constructor()", () => { + it("should create a MathBracketProperties with correct root key", () => { + const mathBracketProperties = new MathBracketProperties(); + + const tree = new Formatter().format(mathBracketProperties); + expect(tree).to.deep.equal({ + "m:dPr": {}, + }); + }); + + it("should create a MathBracketProperties with correct root key and add brackets", () => { + const mathBracketProperties = new MathBracketProperties({ + beginningCharacter: "[", + endingCharacter: "]", + }); + + const tree = new Formatter().format(mathBracketProperties); + expect(tree).to.deep.equal({ + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-bracket-properties.ts b/src/file/paragraph/math/brackets/math-bracket-properties.ts new file mode 100644 index 0000000000..5bba7bf935 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-bracket-properties.ts @@ -0,0 +1,16 @@ +// http://www.datypic.com/sc/ooxml/e-m_dPr-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathBeginningCharacter } from "./math-beginning-character"; +import { MathEndingCharacter } from "./math-ending-char"; + +export class MathBracketProperties extends XmlComponent { + constructor(options?: { readonly beginningCharacter: string; readonly endingCharacter: string }) { + super("m:dPr"); + + if (!!options) { + this.root.push(new MathBeginningCharacter(options.beginningCharacter)); + this.root.push(new MathEndingCharacter(options.endingCharacter)); + } + } +} diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts new file mode 100644 index 0000000000..d6defd57ef --- /dev/null +++ b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathCurlyBrackets } from "./math-curly-brackets"; + +describe("MathCurlyBrackets", () => { + describe("#constructor()", () => { + it("should create a MathCurlyBrackets with correct root key", () => { + const mathCurlyBrackets = new MathCurlyBrackets({ + children: [new MathRun("60")], + }); + + const tree = new Formatter().format(mathCurlyBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "{", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "}", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.ts b/src/file/paragraph/math/brackets/math-curly-brackets.ts new file mode 100644 index 0000000000..ccce71e6a7 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-curly-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathCurlyBrackets extends XmlComponent { + constructor(options: { readonly children: MathComponent[] }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "{", + endingCharacter: "}", + }), + ); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/brackets/math-ending-char.ts b/src/file/paragraph/math/brackets/math-ending-char.ts new file mode 100644 index 0000000000..86d0a0a58c --- /dev/null +++ b/src/file/paragraph/math/brackets/math-ending-char.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_endChr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathEndingCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> { + protected readonly xmlKeys = { character: "m:val" }; +} + +export class MathEndingCharacter extends XmlComponent { + constructor(character: string) { + super("m:endChr"); + + this.root.push(new MathEndingCharacterAttributes({ character })); + } +} diff --git a/src/file/paragraph/math/brackets/math-ending-character.spec.ts b/src/file/paragraph/math/brackets/math-ending-character.spec.ts new file mode 100644 index 0000000000..ba28ac7840 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-ending-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathEndingCharacter } from "./math-ending-char"; + +describe("MathEndingCharacter", () => { + describe("#constructor()", () => { + it("should create a MathEndingCharacter with correct root key", () => { + const mathEndingCharacter = new MathEndingCharacter("]"); + + const tree = new Formatter().format(mathEndingCharacter); + expect(tree).to.deep.equal({ + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-round-brackets.spec.ts b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts new file mode 100644 index 0000000000..5138e9d085 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts @@ -0,0 +1,36 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathRoundBrackets } from "./math-round-brackets"; + +describe("MathRoundBrackets", () => { + describe("#constructor()", () => { + it("should create a MathRoundBrackets with correct root key", () => { + const mathRoundBrackets = new MathRoundBrackets({ + children: [new MathRun("60")], + }); + + const tree = new Formatter().format(mathRoundBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-round-brackets.ts b/src/file/paragraph/math/brackets/math-round-brackets.ts new file mode 100644 index 0000000000..6fe60318a4 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-round-brackets.ts @@ -0,0 +1,15 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathRoundBrackets extends XmlComponent { + constructor(options: { readonly children: MathComponent[] }) { + super("m:d"); + + this.root.push(new MathBracketProperties()); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/brackets/math-square-brackets.spec.ts b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts new file mode 100644 index 0000000000..b0e2ec9e26 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSquareBrackets } from "./math-square-brackets"; + +describe("MathSquareBrackets", () => { + describe("#constructor()", () => { + it("should create a MathSquareBrackets with correct root key", () => { + const mathSquareBrackets = new MathSquareBrackets({ + children: [new MathRun("60")], + }); + + const tree = new Formatter().format(mathSquareBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-square-brackets.ts b/src/file/paragraph/math/brackets/math-square-brackets.ts new file mode 100644 index 0000000000..fdfe88a004 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-square-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathSquareBrackets extends XmlComponent { + constructor(options: { readonly children: MathComponent[] }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "[", + endingCharacter: "]", + }), + ); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/fraction/index.ts b/src/file/paragraph/math/fraction/index.ts new file mode 100644 index 0000000000..c8af438329 --- /dev/null +++ b/src/file/paragraph/math/fraction/index.ts @@ -0,0 +1,3 @@ +export * from "./math-fraction"; +export * from "./math-denominator"; +export * from "./math-numerator"; diff --git a/src/file/paragraph/math/fraction/math-denominator.spec.ts b/src/file/paragraph/math/fraction/math-denominator.spec.ts new file mode 100644 index 0000000000..f2e7459e1e --- /dev/null +++ b/src/file/paragraph/math/fraction/math-denominator.spec.ts @@ -0,0 +1,26 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathDenominator } from "./math-denominator"; + +describe("MathDenominator", () => { + describe("#constructor()", () => { + it("should create a MathDenominator with correct root key", () => { + const mathDenominator = new MathDenominator([new MathRun("2+2")]); + const tree = new Formatter().format(mathDenominator); + expect(tree).to.deep.equal({ + "m:den": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts new file mode 100644 index 0000000000..8df68bf4b0 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -0,0 +1,13 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; + +export class MathDenominator extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:den"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/fraction/math-fraction.spec.ts b/src/file/paragraph/math/fraction/math-fraction.spec.ts new file mode 100644 index 0000000000..51cac646bf --- /dev/null +++ b/src/file/paragraph/math/fraction/math-fraction.spec.ts @@ -0,0 +1,44 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathFraction } from "./math-fraction"; + +describe("MathFraction", () => { + describe("#constructor()", () => { + it("should create a MathFraction with correct root key", () => { + const mathFraction = new MathFraction({ + numerator: [new MathRun("2")], + denominator: [new MathRun("2")], + }); + const tree = new Formatter().format(mathFraction); + expect(tree).to.deep.equal({ + "m:f": [ + { + "m:num": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:den": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts new file mode 100644 index 0000000000..84a803a872 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -0,0 +1,19 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathDenominator } from "./math-denominator"; +import { MathNumerator } from "./math-numerator"; + +export interface IMathFractionOptions { + readonly numerator: MathComponent[]; + readonly denominator: MathComponent[]; +} + +export class MathFraction extends XmlComponent { + constructor(options: IMathFractionOptions) { + super("m:f"); + + this.root.push(new MathNumerator(options.numerator)); + this.root.push(new MathDenominator(options.denominator)); + } +} diff --git a/src/file/paragraph/math/fraction/math-numerator.spec.ts b/src/file/paragraph/math/fraction/math-numerator.spec.ts new file mode 100644 index 0000000000..e3aaf35c0e --- /dev/null +++ b/src/file/paragraph/math/fraction/math-numerator.spec.ts @@ -0,0 +1,26 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathNumerator } from "./math-numerator"; + +describe("MathNumerator", () => { + describe("#constructor()", () => { + it("should create a MathNumerator with correct root key", () => { + const mathNumerator = new MathNumerator([new MathRun("2+2")]); + const tree = new Formatter().format(mathNumerator); + expect(tree).to.deep.equal({ + "m:num": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts new file mode 100644 index 0000000000..b7a49d9a75 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -0,0 +1,13 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; + +export class MathNumerator extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:num"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/function/index.ts b/src/file/paragraph/math/function/index.ts new file mode 100644 index 0000000000..58243c2710 --- /dev/null +++ b/src/file/paragraph/math/function/index.ts @@ -0,0 +1,3 @@ +export * from "./math-function"; +export * from "./math-function-name"; +export * from "./math-function-properties"; diff --git a/src/file/paragraph/math/function/math-function-name.spec.ts b/src/file/paragraph/math/function/math-function-name.spec.ts new file mode 100644 index 0000000000..8a37ee998e --- /dev/null +++ b/src/file/paragraph/math/function/math-function-name.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathFunctionName } from "./math-function-name"; + +describe("MathFunctionName", () => { + describe("#constructor()", () => { + it("should create a MathFunctionName with correct root key", () => { + const mathFunctionName = new MathFunctionName([new MathRun("2")]); + + const tree = new Formatter().format(mathFunctionName); + expect(tree).to.deep.equal({ + "m:fName": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function-name.ts b/src/file/paragraph/math/function/math-function-name.ts new file mode 100644 index 0000000000..e58488dd28 --- /dev/null +++ b/src/file/paragraph/math/function/math-function-name.ts @@ -0,0 +1,13 @@ +// http://www.datypic.com/sc/ooxml/e-m_fName-1.html +import { XmlComponent } from "file/xml-components"; +import { MathComponent } from "../math-component"; + +export class MathFunctionName extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:fName"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/function/math-function-properties.spec.ts b/src/file/paragraph/math/function/math-function-properties.spec.ts new file mode 100644 index 0000000000..63ec2e4f60 --- /dev/null +++ b/src/file/paragraph/math/function/math-function-properties.spec.ts @@ -0,0 +1,18 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathFunctionProperties } from "./math-function-properties"; + +describe("MathFunctionProperties", () => { + describe("#constructor()", () => { + it("should create a MathFunctionProperties with correct root key", () => { + const mathFunctionProperties = new MathFunctionProperties(); + + const tree = new Formatter().format(mathFunctionProperties); + expect(tree).to.deep.equal({ + "m:funcPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function-properties.ts b/src/file/paragraph/math/function/math-function-properties.ts new file mode 100644 index 0000000000..f6e8d608ac --- /dev/null +++ b/src/file/paragraph/math/function/math-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathFunctionProperties extends XmlComponent { + constructor() { + super("m:funcPr"); + } +} diff --git a/src/file/paragraph/math/function/math-function.spec.ts b/src/file/paragraph/math/function/math-function.spec.ts new file mode 100644 index 0000000000..6ea02b6c9d --- /dev/null +++ b/src/file/paragraph/math/function/math-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathFunction } from "./math-function"; + +describe("MathFunction", () => { + describe("#constructor()", () => { + it("should create a MathFunction with correct root key", () => { + const mathFunction = new MathFunction({ + name: [new MathRun("sin")], + children: [new MathRun("60")], + }); + + const tree = new Formatter().format(mathFunction); + expect(tree).to.deep.equal({ + "m:func": [ + { + "m:funcPr": {}, + }, + { + "m:fName": [ + { + "m:r": [ + { + "m:t": ["sin"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function.ts b/src/file/paragraph/math/function/math-function.ts new file mode 100644 index 0000000000..86b66392cc --- /dev/null +++ b/src/file/paragraph/math/function/math-function.ts @@ -0,0 +1,22 @@ +// http://www.datypic.com/sc/ooxml/e-m_func-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathFunctionName } from "./math-function-name"; +import { MathFunctionProperties } from "./math-function-properties"; + +export interface IMathFunctionOptions { + readonly children: MathComponent[]; + readonly name: MathComponent[]; +} + +export class MathFunction extends XmlComponent { + constructor(options: IMathFunctionOptions) { + super("m:func"); + + this.root.push(new MathFunctionProperties()); + this.root.push(new MathFunctionName(options.name)); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/index.ts b/src/file/paragraph/math/index.ts new file mode 100644 index 0000000000..b42ec908f6 --- /dev/null +++ b/src/file/paragraph/math/index.ts @@ -0,0 +1,9 @@ +export * from "./math"; +export * from "./math-run"; +export * from "./fraction"; +export * from "./n-ary"; +export * from "./script"; +export * from "./math-component"; +export * from "./radical"; +export * from "./function"; +export * from "./brackets"; diff --git a/src/file/paragraph/math/math-component.ts b/src/file/paragraph/math/math-component.ts new file mode 100644 index 0000000000..8251235455 --- /dev/null +++ b/src/file/paragraph/math/math-component.ts @@ -0,0 +1,27 @@ +import { MathAngledBrackets, MathCurlyBrackets, MathRoundBrackets, MathSquareBrackets } from "./brackets"; +import { MathFraction } from "./fraction"; +import { MathFunction } from "./function"; +import { MathRun } from "./math-run"; +import { MathSum } from "./n-ary"; +import { MathRadical } from "./radical"; +import { MathSubScript, MathSubSuperScript, MathSuperScript } from "./script"; + +export type MathComponent = + | MathRun + | MathFraction + | MathSum + | MathSuperScript + | MathSubScript + | MathSubSuperScript + | MathRadical + | MathFunction + | MathRoundBrackets + | MathCurlyBrackets + | MathAngledBrackets + | MathSquareBrackets; + +// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 +/** + * @ignore + */ +export const WORKAROUND4 = ""; diff --git a/src/file/paragraph/math/math-run.spec.ts b/src/file/paragraph/math/math-run.spec.ts new file mode 100644 index 0000000000..2773a0fb9c --- /dev/null +++ b/src/file/paragraph/math/math-run.spec.ts @@ -0,0 +1,21 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "./math-run"; + +describe("MathRun", () => { + describe("#constructor()", () => { + it("should create a MathRun with correct root key", () => { + const mathRun = new MathRun("2+2"); + const tree = new Formatter().format(mathRun); + expect(tree).to.deep.equal({ + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math-run.ts b/src/file/paragraph/math/math-run.ts new file mode 100644 index 0000000000..0d2c48910f --- /dev/null +++ b/src/file/paragraph/math/math-run.ts @@ -0,0 +1,12 @@ +// http://www.datypic.com/sc/ooxml/e-m_r-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathText } from "./math-text"; + +export class MathRun extends XmlComponent { + constructor(text: string) { + super("m:r"); + + this.root.push(new MathText(text)); + } +} diff --git a/src/file/paragraph/math/math-text.spec.ts b/src/file/paragraph/math/math-text.spec.ts new file mode 100644 index 0000000000..0001816ed1 --- /dev/null +++ b/src/file/paragraph/math/math-text.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathText } from "./math-text"; + +describe("MathText", () => { + describe("#constructor()", () => { + it("should create a MathText with correct root key", () => { + const mathText = new MathText("2+2"); + const tree = new Formatter().format(mathText); + expect(tree).to.deep.equal({ + "m:t": ["2+2"], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math-text.ts b/src/file/paragraph/math/math-text.ts new file mode 100644 index 0000000000..6087c7e611 --- /dev/null +++ b/src/file/paragraph/math/math-text.ts @@ -0,0 +1,9 @@ +import { XmlComponent } from "file/xml-components"; + +export class MathText extends XmlComponent { + constructor(text: string) { + super("m:t"); + + this.root.push(text); + } +} diff --git a/src/file/paragraph/math/math.spec.ts b/src/file/paragraph/math/math.spec.ts new file mode 100644 index 0000000000..d5c4f6f494 --- /dev/null +++ b/src/file/paragraph/math/math.spec.ts @@ -0,0 +1,38 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { Math } from "./math"; +import { MathRun } from "./math-run"; + +describe("Math", () => { + describe("#constructor()", () => { + it("should create a Math with correct root key", () => { + const math = new Math({ + children: [], + }); + const tree = new Formatter().format(math); + expect(tree).to.deep.equal({ + "m:oMath": {}, + }); + }); + + it("should be able to add children", () => { + const math = new Math({ + children: [new MathRun("2+2")], + }); + const tree = new Formatter().format(math); + expect(tree).to.deep.equal({ + "m:oMath": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math.ts b/src/file/paragraph/math/math.ts new file mode 100644 index 0000000000..69ebae4dff --- /dev/null +++ b/src/file/paragraph/math/math.ts @@ -0,0 +1,18 @@ +// http://www.datypic.com/sc/ooxml/e-m_oMath-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "./math-component"; + +export interface IMathOptions { + readonly children: MathComponent[]; +} + +export class Math extends XmlComponent { + constructor(options: IMathOptions) { + super("m:oMath"); + + for (const child of options.children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/n-ary/index.ts b/src/file/paragraph/math/n-ary/index.ts new file mode 100644 index 0000000000..6929544152 --- /dev/null +++ b/src/file/paragraph/math/n-ary/index.ts @@ -0,0 +1,7 @@ +export * from "./math-accent-character"; +export * from "./math-base"; +export * from "./math-limit-location"; +export * from "./math-naray-properties"; +export * from "./math-sub-script"; +export * from "./math-sum"; +export * from "./math-super-script"; diff --git a/src/file/paragraph/math/n-ary/math-accent-character.spec.ts b/src/file/paragraph/math/n-ary/math-accent-character.spec.ts new file mode 100644 index 0000000000..b414f4c744 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-accent-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathAccentCharacter } from "./math-accent-character"; + +describe("MathAccentCharacter", () => { + describe("#constructor()", () => { + it("should create a MathAccentCharacter with correct root key", () => { + const mathAccentCharacter = new MathAccentCharacter("โˆ‘"); + + const tree = new Formatter().format(mathAccentCharacter); + expect(tree).to.deep.equal({ + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-accent-character.ts b/src/file/paragraph/math/n-ary/math-accent-character.ts new file mode 100644 index 0000000000..00182bd1f2 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-accent-character.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_chr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathAccentCharacterAttributes extends XmlAttributeComponent<{ readonly accent: string }> { + protected readonly xmlKeys = { accent: "m:val" }; +} + +export class MathAccentCharacter extends XmlComponent { + constructor(accent: string) { + super("m:chr"); + + this.root.push(new MathAccentCharacterAttributes({ accent })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-base.spec.ts b/src/file/paragraph/math/n-ary/math-base.spec.ts new file mode 100644 index 0000000000..c282537970 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-base.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathBase } from "./math-base"; + +describe("MathBase", () => { + describe("#constructor()", () => { + it("should create a MathBase with correct root key", () => { + const mathBase = new MathBase([new MathRun("2+2")]); + + const tree = new Formatter().format(mathBase); + expect(tree).to.deep.equal({ + "m:e": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-base.ts b/src/file/paragraph/math/n-ary/math-base.ts new file mode 100644 index 0000000000..6c2320439f --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-base.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_e-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; + +export class MathBase extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:e"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/n-ary/math-limit-location.spec.ts b/src/file/paragraph/math/n-ary/math-limit-location.spec.ts new file mode 100644 index 0000000000..426f3d0198 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-limit-location.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathLimitLocation } from "./math-limit-location"; + +describe("MathLimitLocation", () => { + describe("#constructor()", () => { + it("should create a MathLimitLocation with correct root key", () => { + const mathLimitLocation = new MathLimitLocation(); + + const tree = new Formatter().format(mathLimitLocation); + expect(tree).to.deep.equal({ + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-limit-location.ts b/src/file/paragraph/math/n-ary/math-limit-location.ts new file mode 100644 index 0000000000..5504e1890d --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-limit-location.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_limLoc-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathLimitLocationAttributes extends XmlAttributeComponent<{ readonly value: string }> { + protected readonly xmlKeys = { value: "m:val" }; +} + +export class MathLimitLocation extends XmlComponent { + constructor() { + super("m:limLoc"); + + this.root.push(new MathLimitLocationAttributes({ value: "undOvr" })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts new file mode 100644 index 0000000000..70aa74a1c4 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts @@ -0,0 +1,133 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathNArayProperties } from "./math-naray-properties"; + +describe("MathNArayProperties", () => { + describe("#constructor()", () => { + it("should create a MathNArayProperties with correct root key", () => { + const mathNArayProperties = new MathNArayProperties("โˆ‘", true, true); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + ], + }); + }); + + it("should add super-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("โˆ‘", false, true); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + + it("should add sub-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("โˆ‘", true, false); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + + it("should add both super-script and sub-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("โˆ‘", false, false); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }, + { + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.ts b/src/file/paragraph/math/n-ary/math-naray-properties.ts new file mode 100644 index 0000000000..f8e91e746a --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-naray-properties.ts @@ -0,0 +1,24 @@ +// http://www.datypic.com/sc/ooxml/e-m_naryPr-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathAccentCharacter } from "./math-accent-character"; +import { MathLimitLocation } from "./math-limit-location"; +import { MathSubScriptHide } from "./math-sub-script-hide"; +import { MathSuperScriptHide } from "./math-super-script-hide"; + +export class MathNArayProperties extends XmlComponent { + constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean) { + super("m:naryPr"); + + this.root.push(new MathAccentCharacter(accent)); + this.root.push(new MathLimitLocation()); + + if (!hasSuperScript) { + this.root.push(new MathSuperScriptHide()); + } + + if (!hasSubScript) { + this.root.push(new MathSubScriptHide()); + } + } +} diff --git a/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts new file mode 100644 index 0000000000..2e9845172f --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathSubScriptHide } from "./math-sub-script-hide"; + +describe("MathSubScriptHide", () => { + describe("#constructor()", () => { + it("should create a MathSubScriptHide with correct root key", () => { + const mathSubScriptHide = new MathSubScriptHide(); + + const tree = new Formatter().format(mathSubScriptHide); + expect(tree).to.deep.equal({ + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sub-script-hide.ts b/src/file/paragraph/math/n-ary/math-sub-script-hide.ts new file mode 100644 index 0000000000..ef735744e0 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathSubScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathSubScriptHide extends XmlComponent { + constructor() { + super("m:subHide"); + + this.root.push(new MathSubScriptHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts new file mode 100644 index 0000000000..d342946b74 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSubScriptElement } from "./math-sub-script"; + +describe("MathSubScriptElement", () => { + describe("#constructor()", () => { + it("should create a MathSubScriptElement with correct root key", () => { + const mathSubScriptElement = new MathSubScriptElement([new MathRun("2+2")]); + + const tree = new Formatter().format(mathSubScriptElement); + expect(tree).to.deep.equal({ + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sub-script.ts b/src/file/paragraph/math/n-ary/math-sub-script.ts new file mode 100644 index 0000000000..48268312cf --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_sub-3.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; + +export class MathSubScriptElement extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:sub"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/n-ary/math-sum.spec.ts b/src/file/paragraph/math/n-ary/math-sum.spec.ts new file mode 100644 index 0000000000..9a7cbbaaa2 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sum.spec.ts @@ -0,0 +1,130 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSum } from "./math-sum"; + +describe("MathSum", () => { + describe("#constructor()", () => { + it("should create a MathSum with correct root key", () => { + const mathSum = new MathSum({ + children: [new MathRun("1")], + subScript: [new MathRun("2")], + superScript: [new MathRun("3")], + }); + + const tree = new Formatter().format(mathSum); + expect(tree).to.deep.equal({ + "m:nary": [ + { + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["3"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["1"], + }, + ], + }, + ], + }, + ], + }); + }); + + it("should add a hide when there is no subScript or superScript", () => { + const mathSum = new MathSum({ + children: [new MathRun("1")], + }); + + const tree = new Formatter().format(mathSum); + expect(tree).to.deep.equal({ + "m:nary": [ + { + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "โˆ‘", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }, + { + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["1"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sum.ts b/src/file/paragraph/math/n-ary/math-sum.ts new file mode 100644 index 0000000000..af14730bbf --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sum.ts @@ -0,0 +1,32 @@ +// http://www.datypic.com/sc/ooxml/e-m_nary-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "./math-base"; +import { MathNArayProperties } from "./math-naray-properties"; +import { MathSubScriptElement } from "./math-sub-script"; +import { MathSuperScriptElement } from "./math-super-script"; + +export interface IMathSumOptions { + readonly children: MathComponent[]; + readonly subScript?: MathComponent[]; + readonly superScript?: MathComponent[]; +} + +export class MathSum extends XmlComponent { + constructor(options: IMathSumOptions) { + super("m:nary"); + + this.root.push(new MathNArayProperties("โˆ‘", !!options.superScript, !!options.subScript)); + + if (!!options.subScript) { + this.root.push(new MathSubScriptElement(options.subScript)); + } + + if (!!options.superScript) { + this.root.push(new MathSuperScriptElement(options.superScript)); + } + + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts b/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts new file mode 100644 index 0000000000..89a28564ac --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathSuperScriptHide } from "./math-super-script-hide"; + +describe("MathSuperScriptHide", () => { + describe("#constructor()", () => { + it("should create a MathSuperScriptHide with correct root key", () => { + const mathSuperScriptHide = new MathSuperScriptHide(); + + const tree = new Formatter().format(mathSuperScriptHide); + expect(tree).to.deep.equal({ + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-super-script-hide.ts b/src/file/paragraph/math/n-ary/math-super-script-hide.ts new file mode 100644 index 0000000000..a55c15a7ad --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathSuperScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathSuperScriptHide extends XmlComponent { + constructor() { + super("m:supHide"); + + this.root.push(new MathSuperScriptHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-super-script.spec.ts b/src/file/paragraph/math/n-ary/math-super-script.spec.ts new file mode 100644 index 0000000000..10e037eba3 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSuperScriptElement } from "./math-super-script"; + +describe("MathSuperScriptElement", () => { + describe("#constructor()", () => { + it("should create a MathSuperScriptElement with correct root key", () => { + const mathSuperScriptElement = new MathSuperScriptElement([new MathRun("2+2")]); + + const tree = new Formatter().format(mathSuperScriptElement); + expect(tree).to.deep.equal({ + "m:sup": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-super-script.ts b/src/file/paragraph/math/n-ary/math-super-script.ts new file mode 100644 index 0000000000..8d8386addc --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_sup-3.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; + +export class MathSuperScriptElement extends XmlComponent { + constructor(children: MathComponent[]) { + super("m:sup"); + + for (const child of children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/radical/index.ts b/src/file/paragraph/math/radical/index.ts new file mode 100644 index 0000000000..78240ccd13 --- /dev/null +++ b/src/file/paragraph/math/radical/index.ts @@ -0,0 +1,3 @@ +export * from "./math-degree"; +export * from "./math-radical"; +export * from "./math-radical-properties"; diff --git a/src/file/paragraph/math/radical/math-degree-hide.spec.ts b/src/file/paragraph/math/radical/math-degree-hide.spec.ts new file mode 100644 index 0000000000..0c3f335a13 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathDegreeHide } from "./math-degree-hide"; + +describe("MathDegreeHide", () => { + describe("#constructor()", () => { + it("should create a MathDegreeHide with correct root key", () => { + const mathDegreeHide = new MathDegreeHide(); + + const tree = new Formatter().format(mathDegreeHide); + expect(tree).to.deep.equal({ + "m:degHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-degree-hide.ts b/src/file/paragraph/math/radical/math-degree-hide.ts new file mode 100644 index 0000000000..c1b9dd2ae5 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_degHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathDegreeHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathDegreeHide extends XmlComponent { + constructor() { + super("m:degHide"); + + this.root.push(new MathDegreeHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/radical/math-degree.spec.ts b/src/file/paragraph/math/radical/math-degree.spec.ts new file mode 100644 index 0000000000..3d1f17dfa8 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree.spec.ts @@ -0,0 +1,36 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathDegree } from "./math-degree"; + +describe("MathDegree", () => { + describe("#constructor()", () => { + it("should create a MathDegree with correct root key", () => { + const mathDegree = new MathDegree(); + + const tree = new Formatter().format(mathDegree); + expect(tree).to.deep.equal({ + "m:deg": {}, + }); + }); + + it("should create a MathDegree with correct root key with child", () => { + const mathDegree = new MathDegree([new MathRun("2")]); + + const tree = new Formatter().format(mathDegree); + expect(tree).to.deep.equal({ + "m:deg": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-degree.ts b/src/file/paragraph/math/radical/math-degree.ts new file mode 100644 index 0000000000..79923bbde8 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree.ts @@ -0,0 +1,15 @@ +// http://www.datypic.com/sc/ooxml/e-m_deg-1.html +import { XmlComponent } from "file/xml-components"; +import { MathComponent } from "../math-component"; + +export class MathDegree extends XmlComponent { + constructor(children?: MathComponent[]) { + super("m:deg"); + + if (!!children) { + for (const child of children) { + this.root.push(child); + } + } + } +} diff --git a/src/file/paragraph/math/radical/math-radical-properties.spec.ts b/src/file/paragraph/math/radical/math-radical-properties.spec.ts new file mode 100644 index 0000000000..12d29a2962 --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical-properties.spec.ts @@ -0,0 +1,35 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRadicalProperties } from "./math-radical-properties"; + +describe("MathRadicalProperties", () => { + describe("#constructor()", () => { + it("should create a MathRadicalProperties with correct root key", () => { + const mathRadicalProperties = new MathRadicalProperties(true); + + const tree = new Formatter().format(mathRadicalProperties); + expect(tree).to.deep.equal({ + "m:radPr": {}, + }); + }); + + it("should create a MathRadicalProperties with correct root key with degree hide", () => { + const mathRadicalProperties = new MathRadicalProperties(false); + + const tree = new Formatter().format(mathRadicalProperties); + expect(tree).to.deep.equal({ + "m:radPr": [ + { + "m:degHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-radical-properties.ts b/src/file/paragraph/math/radical/math-radical-properties.ts new file mode 100644 index 0000000000..b4e90ed4df --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical-properties.ts @@ -0,0 +1,13 @@ +// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html +import { XmlComponent } from "file/xml-components"; +import { MathDegreeHide } from "./math-degree-hide"; + +export class MathRadicalProperties extends XmlComponent { + constructor(hasDegree: boolean) { + super("m:radPr"); + + if (!hasDegree) { + this.root.push(new MathDegreeHide()); + } + } +} diff --git a/src/file/paragraph/math/radical/math-radical.spec.ts b/src/file/paragraph/math/radical/math-radical.spec.ts new file mode 100644 index 0000000000..e388edece4 --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathRadical } from "./math-radical"; + +describe("MathRadical", () => { + describe("#constructor()", () => { + it("should create a MathRadical with correct root key", () => { + const mathRadical = new MathRadical({ + children: [new MathRun("e")], + degree: [new MathRun("2")], + }); + + const tree = new Formatter().format(mathRadical); + expect(tree).to.deep.equal({ + "m:rad": [ + { + "m:radPr": {}, + }, + { + "m:deg": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-radical.ts b/src/file/paragraph/math/radical/math-radical.ts new file mode 100644 index 0000000000..1469867a5f --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical.ts @@ -0,0 +1,22 @@ +// http://www.datypic.com/sc/ooxml/e-m_rad-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathDegree } from "./math-degree"; +import { MathRadicalProperties } from "./math-radical-properties"; + +export interface IMathRadicalOptions { + readonly children: MathComponent[]; + readonly degree?: MathComponent[]; +} + +export class MathRadical extends XmlComponent { + constructor(options: IMathRadicalOptions) { + super("m:rad"); + + this.root.push(new MathRadicalProperties(!!options.degree)); + this.root.push(new MathDegree(options.degree)); + this.root.push(new MathBase(options.children)); + } +} diff --git a/src/file/paragraph/math/script/index.ts b/src/file/paragraph/math/script/index.ts new file mode 100644 index 0000000000..a83e54975e --- /dev/null +++ b/src/file/paragraph/math/script/index.ts @@ -0,0 +1,4 @@ +export * from "./super-script"; +export * from "./sub-script"; +export * from "./sub-super-script"; +export * from "./pre-sub-super-script"; diff --git a/src/file/paragraph/math/script/pre-sub-super-script/index.ts b/src/file/paragraph/math/script/pre-sub-super-script/index.ts new file mode 100644 index 0000000000..8660a75017 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-pre-sub-super-script-function"; +export * from "./math-pre-sub-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..a6f1d5383e --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; + +describe("MathPreSubSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathPreSubSuperScriptProperties with correct root key", () => { + const mathPreSubSuperScriptProperties = new MathPreSubSuperScriptProperties(); + + const tree = new Formatter().format(mathPreSubSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sPrePr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts new file mode 100644 index 0000000000..fed0cb3564 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sPrePr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathPreSubSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sPrePr"); + } +} diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts new file mode 100644 index 0000000000..20d00a639d --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts @@ -0,0 +1,60 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathPreSubSuperScript } from "./math-pre-sub-super-script-function"; + +describe("MathPreSubScript", () => { + describe("#constructor()", () => { + it("should create a MathPreSubScript with correct root key", () => { + const mathPreSubScript = new MathPreSubSuperScript({ + children: [new MathRun("e")], + subScript: [new MathRun("2")], + superScript: [new MathRun("5")], + }); + + const tree = new Formatter().format(mathPreSubScript); + expect(tree).to.deep.equal({ + "m:sPre": [ + { + "m:sPrePr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["5"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts new file mode 100644 index 0000000000..3a58675b0f --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts @@ -0,0 +1,23 @@ +// http://www.datypic.com/sc/ooxml/e-m_sPre-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary"; +import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; + +export interface IMathPreSubSuperScriptOptions { + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; + readonly superScript: MathComponent[]; +} + +export class MathPreSubSuperScript extends XmlComponent { + constructor(options: IMathPreSubSuperScriptOptions) { + super("m:sPre"); + + this.root.push(new MathPreSubSuperScriptProperties()); + this.root.push(new MathBase(options.children)); + this.root.push(new MathSubScriptElement(options.subScript)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/math/script/sub-script/index.ts b/src/file/paragraph/math/script/sub-script/index.ts new file mode 100644 index 0000000000..0f1c27fe51 --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-sub-script-function"; +export * from "./math-sub-script-function-properties"; diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts new file mode 100644 index 0000000000..be229e066b --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSubScriptProperties } from "./math-sub-script-function-properties"; + +describe("MathSubScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSubScriptProperties with correct root key", () => { + const mathSubScriptProperties = new MathSubScriptProperties(); + + const tree = new Formatter().format(mathSubScriptProperties); + expect(tree).to.deep.equal({ + "m:sSubPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts new file mode 100644 index 0000000000..bf37b1d885 --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSubScriptProperties extends XmlComponent { + constructor() { + super("m:sSubPr"); + } +} diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts new file mode 100644 index 0000000000..a3ea8d680c --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSubScript } from "./math-sub-script-function"; + +describe("MathSubScript", () => { + describe("#constructor()", () => { + it("should create a MathSubScript with correct root key", () => { + const mathSubScript = new MathSubScript({ + children: [new MathRun("e")], + subScript: [new MathRun("2")], + }); + + const tree = new Formatter().format(mathSubScript); + expect(tree).to.deep.equal({ + "m:sSub": [ + { + "m:sSubPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts new file mode 100644 index 0000000000..319d4d1f1a --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts @@ -0,0 +1,21 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSub-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement } from "../../n-ary"; +import { MathSubScriptProperties } from "./math-sub-script-function-properties"; + +export interface IMathSubScriptOptions { + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; +} + +export class MathSubScript extends XmlComponent { + constructor(options: IMathSubScriptOptions) { + super("m:sSub"); + + this.root.push(new MathSubScriptProperties()); + this.root.push(new MathBase(options.children)); + this.root.push(new MathSubScriptElement(options.subScript)); + } +} diff --git a/src/file/paragraph/math/script/sub-super-script/index.ts b/src/file/paragraph/math/script/sub-super-script/index.ts new file mode 100644 index 0000000000..88ddeb69fa --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-sub-super-script-function"; +export * from "./math-sub-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..b0f934823a --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; + +describe("MathSubSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSubSuperScriptProperties with correct root key", () => { + const mathSubSuperScriptProperties = new MathSubSuperScriptProperties(); + + const tree = new Formatter().format(mathSubSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sSubSupPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts new file mode 100644 index 0000000000..b3218a7d3a --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubSupPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSubSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sSubSupPr"); + } +} diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts new file mode 100644 index 0000000000..68a86fb26b --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts @@ -0,0 +1,60 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSubSuperScript } from "./math-sub-super-script-function"; + +describe("MathSubScript", () => { + describe("#constructor()", () => { + it("should create a MathSubScript with correct root key", () => { + const mathSubScript = new MathSubSuperScript({ + children: [new MathRun("e")], + subScript: [new MathRun("2")], + superScript: [new MathRun("5")], + }); + + const tree = new Formatter().format(mathSubScript); + expect(tree).to.deep.equal({ + "m:sSubSup": [ + { + "m:sSubSupPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["5"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts new file mode 100644 index 0000000000..c382c9ff4c --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts @@ -0,0 +1,23 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubSup-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary"; +import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; + +export interface IMathSubSuperScriptOptions { + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; + readonly superScript: MathComponent[]; +} + +export class MathSubSuperScript extends XmlComponent { + constructor(options: IMathSubSuperScriptOptions) { + super("m:sSubSup"); + + this.root.push(new MathSubSuperScriptProperties()); + this.root.push(new MathBase(options.children)); + this.root.push(new MathSubScriptElement(options.subScript)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/math/script/super-script/index.ts b/src/file/paragraph/math/script/super-script/index.ts new file mode 100644 index 0000000000..2864fe9ac5 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-super-script-function"; +export * from "./math-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..f95920f152 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSuperScriptProperties } from "./math-super-script-function-properties"; + +describe("MathSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSuperScriptProperties with correct root key", () => { + const mathSuperScriptProperties = new MathSuperScriptProperties(); + + const tree = new Formatter().format(mathSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sSupPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts new file mode 100644 index 0000000000..ea5dbac20b --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSupPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sSupPr"); + } +} diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts new file mode 100644 index 0000000000..ae3740360b --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSuperScript } from "./math-super-script-function"; + +describe("MathSuperScript", () => { + describe("#constructor()", () => { + it("should create a MathSuperScript with correct root key", () => { + const mathSuperScript = new MathSuperScript({ + children: [new MathRun("e")], + superScript: [new MathRun("2")], + }); + + const tree = new Formatter().format(mathSuperScript); + expect(tree).to.deep.equal({ + "m:sSup": [ + { + "m:sSupPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.ts new file mode 100644 index 0000000000..eeffdf124a --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.ts @@ -0,0 +1,21 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSup-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSuperScriptElement } from "../../n-ary"; +import { MathSuperScriptProperties } from "./math-super-script-function-properties"; + +export interface IMathSuperScriptOptions { + readonly children: MathComponent[]; + readonly superScript: MathComponent[]; +} + +export class MathSuperScript extends XmlComponent { + constructor(options: IMathSuperScriptOptions) { + super("m:sSup"); + + this.root.push(new MathSuperScriptProperties()); + this.root.push(new MathBase(options.children)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 2bbe3c79b1..fe9ab8360e 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -5,8 +5,10 @@ import { stub } from "sinon"; import { Formatter } from "export/formatter"; import { EMPTY_OBJECT } from "file/xml-components"; +import { IViewWrapper } from "../document-wrapper"; +import { ShadingType } from "../table/shading"; import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting"; -import { Bookmark } from "./links"; +import { Bookmark, ExternalHyperlink } from "./links"; import { Paragraph } from "./paragraph"; import { TextRun } from "./run"; @@ -543,14 +545,8 @@ describe("Paragraph", () => { }, }); const tree = new Formatter().format(paragraph); - expect(tree) - .to.have.property("w:p") - .which.is.an("array") - .which.has.length.at.least(1); - expect(tree["w:p"][0]) - .to.have.property("w:pPr") - .which.is.an("array") - .which.has.length.at.least(1); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ "w:pStyle": { _attr: { "w:val": "ListParagraph" } }, }); @@ -563,14 +559,8 @@ describe("Paragraph", () => { }, }); const tree = new Formatter().format(paragraph); - expect(tree) - .to.have.property("w:p") - .which.is.an("array") - .which.has.length.at.least(1); - expect(tree["w:p"][0]) - .to.have.property("w:pPr") - .which.is.an("array") - .which.has.length.at.least(1); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ "w:pStyle": { _attr: { "w:val": "ListParagraph" } }, }); @@ -583,14 +573,8 @@ describe("Paragraph", () => { }, }); const tree = new Formatter().format(paragraph); - expect(tree) - .to.have.property("w:p") - .which.is.an("array") - .which.has.length.at.least(1); - expect(tree["w:p"][0]) - .to.have.property("w:pPr") - .which.is.an("array") - .which.has.length.at.least(2); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2); expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({ "w:numPr": [{ "w:ilvl": { _attr: { "w:val": 1 } } }, { "w:numId": { _attr: { "w:val": 1 } } }], }); @@ -606,14 +590,8 @@ describe("Paragraph", () => { }, }); const tree = new Formatter().format(paragraph); - expect(tree) - .to.have.property("w:p") - .which.is.an("array") - .which.has.length.at.least(1); - expect(tree["w:p"][0]) - .to.have.property("w:pPr") - .which.is.an("array") - .which.has.length.at.least(1); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ "w:pStyle": { _attr: { "w:val": "ListParagraph" } }, }); @@ -789,4 +767,82 @@ describe("Paragraph", () => { }); }); }); + + describe("#shading", () => { + it("should set shading to the given value", () => { + const paragraph = new Paragraph({ + shading: { + type: ShadingType.REVERSE_DIAGONAL_STRIPE, + color: "00FFFF", + fill: "FF0000", + }, + }); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:pPr": [ + { + "w:shd": { + _attr: { + "w:color": "00FFFF", + "w:fill": "FF0000", + "w:val": "reverseDiagStripe", + }, + }, + }, + ], + }, + ], + }); + }); + }); + + describe("#prepForXml", () => { + it("should set Internal Hyperlink", () => { + const paragraph = new Paragraph({ + children: [ + new ExternalHyperlink({ + child: new TextRun("test"), + link: "http://www.google.com", + }), + ], + }); + const fileMock = ({ + Relationships: { + createRelationship: () => ({}), + }, + } as unknown) as IViewWrapper; + paragraph.prepForXml(fileMock); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:hyperlink": [ + { + _attr: { + "r:id": "rIdtest-unique-id", + "w:history": 1, + }, + }, + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "test", + ], + }, + ], + }, + ], + }, + ], + }); + }); + }); }); diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index a61e827be6..ae9d9b5d99 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -1,53 +1,35 @@ // http://officeopenxml.com/WPparagraph.php +import * as shortid from "shortid"; + import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { IXmlableObject, XmlComponent } from "file/xml-components"; -import { File } from "../file"; -import { Alignment, AlignmentType } from "./formatting/alignment"; -import { Bidirectional } from "./formatting/bidirectional"; -import { IBorderOptions, ThematicBreak } from "./formatting/border"; -import { IIndentAttributesProperties, Indent } from "./formatting/indent"; -import { KeepLines, KeepNext } from "./formatting/keep"; -import { PageBreak, PageBreakBefore } from "./formatting/page-break"; -import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing"; -import { HeadingLevel, Style } from "./formatting/style"; -import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop"; -import { NumberProperties } from "./formatting/unordered-list"; -import { Bookmark, HyperlinkRef, OutlineLevel } from "./links"; -import { ParagraphProperties } from "./properties"; +import { IViewWrapper } from "../document-wrapper"; +import { TargetModeType } from "../relationships/relationship/relationship"; +import { DeletedTextRun, InsertedTextRun } from "../track-revision"; +import { PageBreak } from "./formatting/page-break"; +import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./links"; +import { Math } from "./math"; +import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties"; import { PictureRun, Run, SequentialIdentifier, SymbolRun, TextRun } from "./run"; -export interface IParagraphOptions { +export type ParagraphChild = + | TextRun + | PictureRun + | SymbolRun + | Bookmark + | PageBreak + | SequentialIdentifier + | FootnoteReferenceRun + | InternalHyperlink + | ExternalHyperlink + | InsertedTextRun + | DeletedTextRun + | Math; + +export interface IParagraphOptions extends IParagraphPropertiesOptions { readonly text?: string; - readonly border?: IBorderOptions; - readonly spacing?: ISpacingProperties; - readonly outlineLevel?: number; - readonly alignment?: AlignmentType; - readonly heading?: HeadingLevel; - readonly bidirectional?: boolean; - readonly thematicBreak?: boolean; - readonly pageBreakBefore?: boolean; - readonly contextualSpacing?: boolean; - readonly indent?: IIndentAttributesProperties; - readonly keepLines?: boolean; - readonly keepNext?: boolean; - readonly tabStops?: Array<{ - readonly position: number | TabStopPosition; - readonly type: TabStopType; - readonly leader?: LeaderType; - }>; - readonly style?: string; - readonly bullet?: { - readonly level: number; - }; - readonly numbering?: { - readonly reference: string; - readonly level: number; - readonly custom?: boolean; - }; - readonly children?: Array< - TextRun | PictureRun | SymbolRun | Bookmark | PageBreak | SequentialIdentifier | FootnoteReferenceRun | HyperlinkRef - >; + readonly children?: ParagraphChild[]; } export class Paragraph extends XmlComponent { @@ -70,9 +52,7 @@ export class Paragraph extends XmlComponent { return; } - this.properties = new ParagraphProperties({ - border: options.border, - }); + this.properties = new ParagraphProperties(options); this.root.push(this.properties); @@ -80,72 +60,6 @@ export class Paragraph extends XmlComponent { this.root.push(new TextRun(options.text)); } - if (options.spacing) { - this.properties.push(new Spacing(options.spacing)); - } - - if (options.outlineLevel !== undefined) { - this.properties.push(new OutlineLevel(options.outlineLevel)); - } - - if (options.alignment) { - this.properties.push(new Alignment(options.alignment)); - } - - if (options.heading) { - this.properties.push(new Style(options.heading)); - } - - if (options.bidirectional) { - this.properties.push(new Bidirectional()); - } - - if (options.thematicBreak) { - this.properties.push(new ThematicBreak()); - } - - if (options.pageBreakBefore) { - this.properties.push(new PageBreakBefore()); - } - - if (options.contextualSpacing) { - this.properties.push(new ContextualSpacing(options.contextualSpacing)); - } - - if (options.indent) { - this.properties.push(new Indent(options.indent)); - } - - if (options.keepLines) { - this.properties.push(new KeepLines()); - } - - if (options.keepNext) { - this.properties.push(new KeepNext()); - } - - if (options.tabStops) { - for (const tabStop of options.tabStops) { - this.properties.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader)); - } - } - - if (options.style) { - this.properties.push(new Style(options.style)); - } - - if (options.bullet) { - this.properties.push(new Style("ListParagraph")); - this.properties.push(new NumberProperties(1, options.bullet.level)); - } - - if (options.numbering) { - if (!options.numbering.custom) { - this.properties.push(new Style("ListParagraph")); - } - this.properties.push(new NumberProperties(options.numbering.reference, options.numbering.level)); - } - if (options.children) { for (const child of options.children) { if (child instanceof Bookmark) { @@ -162,11 +76,18 @@ export class Paragraph extends XmlComponent { } } - public prepForXml(file: File): IXmlableObject | undefined { + public prepForXml(file: IViewWrapper): IXmlableObject | undefined { for (const element of this.root) { - if (element instanceof HyperlinkRef) { + if (element instanceof ExternalHyperlink) { const index = this.root.indexOf(element); - this.root[index] = file.HyperlinkCache[element.id]; + const concreteHyperlink = new ConcreteHyperlink(element.options.child, shortid.generate().toLowerCase()); + file.Relationships.createRelationship( + concreteHyperlink.linkId, + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", + element.options.link, + TargetModeType.EXTERNAL, + ); + this.root[index] = concreteHyperlink; } } diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 35836ce30e..b12bfedd8e 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -1,19 +1,147 @@ // http://officeopenxml.com/WPparagraphProperties.php import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components"; +import { ShadingType } from "../table/shading"; +import { Alignment, AlignmentType } from "./formatting/alignment"; +import { Bidirectional } from "./formatting/bidirectional"; +import { Border, IBorderOptions, ThematicBreak } from "./formatting/border"; +import { IIndentAttributesProperties, Indent } from "./formatting/indent"; +import { KeepLines, KeepNext } from "./formatting/keep"; +import { PageBreakBefore } from "./formatting/page-break"; +import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing"; +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 { Shading } from "./run/formatting"; -import { Border, IBorderOptions } from "./formatting/border"; +export interface IParagraphStylePropertiesOptions { + readonly alignment?: AlignmentType; + readonly thematicBreak?: boolean; + readonly contextualSpacing?: boolean; + readonly rightTabStop?: number; + readonly leftTabStop?: number; + readonly indent?: IIndentAttributesProperties; + readonly spacing?: ISpacingProperties; + readonly keepNext?: boolean; + readonly keepLines?: boolean; + readonly outlineLevel?: number; +} -interface IParagraphPropertiesOptions { +export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions { readonly border?: IBorderOptions; + readonly heading?: HeadingLevel; + readonly bidirectional?: boolean; + readonly pageBreakBefore?: boolean; + readonly tabStops?: { + readonly position: number | TabStopPosition; + readonly type: TabStopType; + readonly leader?: LeaderType; + }[]; + readonly style?: string; + readonly bullet?: { + readonly level: number; + }; + readonly numbering?: { + readonly reference: string; + readonly level: number; + readonly custom?: boolean; + }; + readonly shading?: { + readonly type: ShadingType; + readonly fill: string; + readonly color: string; + }; } export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { - constructor(options: IParagraphPropertiesOptions) { + constructor(options?: IParagraphPropertiesOptions) { super("w:pPr"); + if (!options) { + return; + } + if (options.border) { this.push(new Border(options.border)); } + + if (options.spacing) { + this.push(new Spacing(options.spacing)); + } + + if (options.outlineLevel !== undefined) { + this.push(new OutlineLevel(options.outlineLevel)); + } + + if (options.alignment) { + this.push(new Alignment(options.alignment)); + } + + if (options.heading) { + this.push(new Style(options.heading)); + } + + if (options.bidirectional) { + this.push(new Bidirectional()); + } + + if (options.thematicBreak) { + this.push(new ThematicBreak()); + } + + if (options.pageBreakBefore) { + this.push(new PageBreakBefore()); + } + + if (options.contextualSpacing) { + this.push(new ContextualSpacing(options.contextualSpacing)); + } + + if (options.indent) { + this.push(new Indent(options.indent)); + } + + if (options.keepLines) { + this.push(new KeepLines()); + } + + if (options.keepNext) { + this.push(new KeepNext()); + } + + if (options.tabStops) { + for (const tabStop of options.tabStops) { + this.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader)); + } + } + + if (options.style) { + this.push(new Style(options.style)); + } + + if (options.bullet) { + this.push(new Style("ListParagraph")); + this.push(new NumberProperties(1, options.bullet.level)); + } + + if (options.numbering) { + if (!options.numbering.custom) { + this.push(new Style("ListParagraph")); + } + this.push(new NumberProperties(options.numbering.reference, options.numbering.level)); + } + + if (options.rightTabStop) { + this.push(new TabStop(TabStopType.RIGHT, options.rightTabStop)); + } + + if (options.leftTabStop) { + this.push(new TabStop(TabStopType.LEFT, options.leftTabStop)); + } + + if (options.shading) { + this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color)); + } } public push(item: XmlComponent): void { diff --git a/src/file/paragraph/run/caps.ts b/src/file/paragraph/run/caps.ts deleted file mode 100644 index 0b9fb510be..0000000000 --- a/src/file/paragraph/run/caps.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { XmlComponent } from "file/xml-components"; - -export class SmallCaps extends XmlComponent { - constructor() { - super("w:smallCaps"); - } -} - -export class Caps extends XmlComponent { - constructor() { - super("w:caps"); - } -} diff --git a/src/file/paragraph/run/emphasis-mark.spec.ts b/src/file/paragraph/run/emphasis-mark.spec.ts new file mode 100644 index 0000000000..4ad4878f64 --- /dev/null +++ b/src/file/paragraph/run/emphasis-mark.spec.ts @@ -0,0 +1,29 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import * as em from "./emphasis-mark"; + +describe("EmphasisMark", () => { + describe("#constructor()", () => { + it("should create a new EmphasisMark object with w:em as the rootKey", () => { + const emphasisMark = new em.EmphasisMark(); + const tree = new Formatter().format(emphasisMark); + expect(tree).to.deep.equal({ + "w:em": { _attr: { "w:val": "dot" } }, + }); + }); + }); +}); + +describe("DotEmphasisMark", () => { + describe("#constructor()", () => { + it("should put value in attribute", () => { + const emphasisMark = new em.DotEmphasisMark(); + const tree = new Formatter().format(emphasisMark); + expect(tree).to.deep.equal({ + "w:em": { _attr: { "w:val": "dot" } }, + }); + }); + }); +}); diff --git a/src/file/paragraph/run/emphasis-mark.ts b/src/file/paragraph/run/emphasis-mark.ts new file mode 100644 index 0000000000..b8af756072 --- /dev/null +++ b/src/file/paragraph/run/emphasis-mark.ts @@ -0,0 +1,28 @@ +import { Attributes, XmlComponent } from "file/xml-components"; + +export enum EmphasisMarkType { + DOT = "dot", +} + +export abstract class BaseEmphasisMark extends XmlComponent { + protected constructor(emphasisMarkType: EmphasisMarkType) { + super("w:em"); + this.root.push( + new Attributes({ + val: emphasisMarkType, + }), + ); + } +} + +export class EmphasisMark extends BaseEmphasisMark { + constructor(emphasisMarkType: EmphasisMarkType = EmphasisMarkType.DOT) { + super(emphasisMarkType); + } +} + +export class DotEmphasisMark extends BaseEmphasisMark { + constructor() { + super(EmphasisMarkType.DOT); + } +} diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index 549f2ae552..3ef041d7d9 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -1,7 +1,9 @@ import { Attributes, XmlComponent } from "file/xml-components"; + export { Underline } from "./underline"; +export { EmphasisMark } from "./emphasis-mark"; export { SubScript, SuperScript } from "./script"; -export { RunFonts } from "./run-fonts"; +export { RunFonts, IFontAttributesProperties } from "./run-fonts"; export class Bold extends XmlComponent { constructor() { @@ -113,17 +115,6 @@ export class Imprint extends XmlComponent { } } -/* export class Shadow extends XmlComponent { - constructor() { - super("w:shadow"); - this.root.push( - new Attributes({ - val: true, - }), - ); - } -} */ - export class SmallCaps extends XmlComponent { constructor() { super("w:smallCaps"); diff --git a/src/file/paragraph/run/index.ts b/src/file/paragraph/run/index.ts index 21df415f35..3bf62d66cf 100644 --- a/src/file/paragraph/run/index.ts +++ b/src/file/paragraph/run/index.ts @@ -1,8 +1,10 @@ export * from "./run"; +export * from "./properties"; export * from "./text-run"; export * from "./symbol-run"; export * from "./picture-run"; export * from "./run-fonts"; export * from "./sequential-identifier"; export * from "./underline"; +export * from "./emphasis-mark"; export * from "./tab"; diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 903282b5a6..0bd082afc5 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -1,8 +1,183 @@ +import { ShadingType } from "file/table"; import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components"; +import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark"; +import { + Bold, + BoldComplexScript, + Caps, + CharacterSpacing, + Color, + DoubleStrike, + Highlight, + HighlightComplexScript, + Italics, + ItalicsComplexScript, + RightToLeft, + Shading, + ShadowComplexScript, + Size, + SizeComplexScript, + SmallCaps, + Strike, +} from "./formatting"; +import { IFontAttributesProperties, RunFonts } from "./run-fonts"; +import { SubScript, SuperScript } from "./script"; +import { Style } from "./style"; +import { Underline, UnderlineType } from "./underline"; + +interface IFontOptions { + readonly name: string; + readonly hint?: string; +} + +export interface IRunStylePropertiesOptions { + readonly bold?: boolean; + readonly boldComplexScript?: boolean; + readonly italics?: boolean; + readonly italicsComplexScript?: boolean; + readonly underline?: { + readonly color?: string; + readonly type?: UnderlineType; + }; + readonly emphasisMark?: { + readonly type?: EmphasisMarkType; + }; + readonly color?: string; + readonly size?: number; + readonly sizeComplexScript?: boolean | number; + readonly rightToLeft?: boolean; + readonly smallCaps?: boolean; + readonly allCaps?: boolean; + readonly strike?: boolean; + readonly doubleStrike?: boolean; + readonly subScript?: boolean; + readonly superScript?: boolean; + readonly font?: string | IFontOptions | IFontAttributesProperties; + readonly highlight?: string; + readonly highlightComplexScript?: boolean | string; + readonly characterSpacing?: number; + readonly shading?: { + readonly type: ShadingType; + readonly fill: string; + readonly color: string; + }; + readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"]; + readonly shadow?: IRunStylePropertiesOptions["shading"]; +} + +export interface IRunPropertiesOptions extends IRunStylePropertiesOptions { + readonly style?: string; +} export class RunProperties extends IgnoreIfEmptyXmlComponent { - constructor() { + constructor(options?: IRunPropertiesOptions) { super("w:rPr"); + + if (!options) { + return; + } + + if (options.bold) { + this.push(new Bold()); + } + if ((options.boldComplexScript === undefined && options.bold) || options.boldComplexScript) { + this.push(new BoldComplexScript()); + } + + if (options.italics) { + this.push(new Italics()); + } + if ((options.italicsComplexScript === undefined && options.italics) || options.italicsComplexScript) { + this.push(new ItalicsComplexScript()); + } + + if (options.underline) { + this.push(new Underline(options.underline.type, options.underline.color)); + } + + if (options.emphasisMark) { + this.push(new EmphasisMark(options.emphasisMark.type)); + } + + if (options.color) { + this.push(new Color(options.color)); + } + + if (options.size) { + this.push(new Size(options.size)); + } + const szCs = + options.sizeComplexScript === undefined || options.sizeComplexScript === true ? options.size : options.sizeComplexScript; + if (szCs) { + this.push(new SizeComplexScript(szCs)); + } + + if (options.rightToLeft) { + this.push(new RightToLeft()); + } + + if (options.smallCaps) { + this.push(new SmallCaps()); + } + + if (options.allCaps) { + this.push(new Caps()); + } + + if (options.strike) { + this.push(new Strike()); + } + + if (options.doubleStrike) { + this.push(new DoubleStrike()); + } + + if (options.subScript) { + this.push(new SubScript()); + } + + if (options.superScript) { + this.push(new SuperScript()); + } + + if (options.style) { + this.push(new Style(options.style)); + } + + if (options.font) { + if (typeof options.font === "string") { + this.push(new RunFonts(options.font)); + } else if ("name" in options.font) { + this.push(new RunFonts(options.font.name, options.font.hint)); + } else { + this.push(new RunFonts(options.font)); + } + } + + if (options.highlight) { + this.push(new Highlight(options.highlight)); + } + const highlightCs = + options.highlightComplexScript === undefined || options.highlightComplexScript === true + ? options.highlight + : options.highlightComplexScript; + if (highlightCs) { + this.push(new HighlightComplexScript(highlightCs)); + } + + if (options.characterSpacing) { + this.push(new CharacterSpacing(options.characterSpacing)); + } + + const shading = options.shading || options.shadow; + if (shading) { + this.push(new Shading(shading.type, shading.fill, shading.color)); + } + const shdCs = + options.shadingComplexScript === undefined || options.shadingComplexScript === true ? shading : options.shadingComplexScript; + if (shdCs) { + this.push(new ShadowComplexScript(shdCs.type, shdCs.fill, shdCs.color)); + } } public push(item: XmlComponent): void { diff --git a/src/file/paragraph/run/run-fonts.spec.ts b/src/file/paragraph/run/run-fonts.spec.ts index 1eacc8ecc9..a0180eae81 100644 --- a/src/file/paragraph/run/run-fonts.spec.ts +++ b/src/file/paragraph/run/run-fonts.spec.ts @@ -21,5 +21,12 @@ describe("RunFonts", () => { }, }); }); + + it("uses the font attrs for ascii and eastAsia", () => { + const tree = new Formatter().format(new RunFonts({ ascii: "Times", eastAsia: "KaiTi" })); + expect(tree).to.deep.equal({ + "w:rFonts": { _attr: { "w:ascii": "Times", "w:eastAsia": "KaiTi" } }, + }); + }); }); }); diff --git a/src/file/paragraph/run/run-fonts.ts b/src/file/paragraph/run/run-fonts.ts index 10a441626c..c1eed32613 100644 --- a/src/file/paragraph/run/run-fonts.ts +++ b/src/file/paragraph/run/run-fonts.ts @@ -1,14 +1,14 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -interface IRunFontAttributesProperties { - readonly ascii: string; - readonly cs: string; - readonly eastAsia: string; - readonly hAnsi: string; +export interface IFontAttributesProperties { + readonly ascii?: string; + readonly cs?: string; + readonly eastAsia?: string; + readonly hAnsi?: string; readonly hint?: string; } -class RunFontAttributes extends XmlAttributeComponent { +class RunFontAttributes extends XmlAttributeComponent { protected readonly xmlKeys = { ascii: "w:ascii", cs: "w:cs", @@ -19,16 +19,26 @@ class RunFontAttributes extends XmlAttributeComponent { }); }); + describe("#emphasisMark()", () => { + it("should default to 'dot'", () => { + const run = new Run({ + emphasisMark: {}, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }] }], + }); + }); + + it("should set the style type if given", () => { + const run = new Run({ + emphasisMark: { + type: EmphasisMarkType.DOT, + }, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }] }], + }); + }); + }); + describe("#smallCaps()", () => { it("it should add smallCaps to the properties", () => { const run = new Run({ @@ -91,7 +116,7 @@ describe("Run", () => { }); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }], + "w:r": [{ "w:rPr": [{ "w:smallCaps": { _attr: { "w:val": true } } }] }], }); }); }); @@ -103,7 +128,7 @@ describe("Run", () => { }); const tree = new Formatter().format(run); expect(tree).to.deep.equal({ - "w:r": [{ "w:rPr": [{ "w:caps": {} }] }], + "w:r": [{ "w:rPr": [{ "w:caps": { _attr: { "w:val": true } } }] }], }); }); }); @@ -214,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()", () => { @@ -235,7 +276,42 @@ describe("Run", () => { "w:r": [ { "w:rPr": [ - { "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } }, + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:cs": "Times", + "w:eastAsia": "Times", + "w:hAnsi": "Times", + }, + }, + }, + ], + }, + ], + }); + }); + + it("should set the font for ascii and eastAsia", () => { + const run = new Run({ + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + { + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, ], }, ], diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index 20777b72a2..461fd9da29 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -1,64 +1,17 @@ // http://officeopenxml.com/WPtext.php -import { ShadingType } from "file/table"; import { XmlComponent } from "file/xml-components"; import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { FieldInstruction } from "file/table-of-contents/field-instruction"; import { Break } from "./break"; -import { Caps, SmallCaps } from "./caps"; import { Begin, End, Separate } from "./field"; -import { - Bold, - BoldComplexScript, - Color, - DoubleStrike, - Highlight, - HighlightComplexScript, - Italics, - ItalicsComplexScript, - RightToLeft, - Shading, - ShadowComplexScript, - Size, - SizeComplexScript, - Strike, -} from "./formatting"; import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number"; -import { RunProperties } from "./properties"; +import { IRunPropertiesOptions, RunProperties } from "./properties"; import { Text } from "./run-components/text"; -import { RunFonts } from "./run-fonts"; -import { SubScript, SuperScript } from "./script"; -import { Style } from "./style"; -import { Underline, UnderlineType } from "./underline"; -export interface IRunOptions { - readonly bold?: true; - readonly italics?: true; - readonly underline?: { - readonly color?: string; - readonly type?: UnderlineType; - }; - readonly color?: string; - readonly size?: number; - readonly rightToLeft?: boolean; - readonly smallCaps?: boolean; - readonly allCaps?: boolean; - readonly strike?: boolean; - readonly doubleStrike?: boolean; - readonly subScript?: boolean; - readonly superScript?: boolean; - readonly style?: string; - readonly font?: { - readonly name: string; - readonly hint?: string; - }; - readonly highlight?: string; - readonly shading?: { - readonly type: ShadingType; - readonly fill: string; - readonly color: string; - }; - readonly children?: Array; +export interface IRunOptions extends IRunPropertiesOptions { + readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[]; + readonly break?: number; readonly text?: string; } @@ -73,78 +26,9 @@ export class Run extends XmlComponent { constructor(options: IRunOptions) { super("w:r"); - this.properties = new RunProperties(); + this.properties = new RunProperties(options); this.root.push(this.properties); - if (options.bold) { - this.properties.push(new Bold()); - this.properties.push(new BoldComplexScript()); - } - - if (options.italics) { - this.properties.push(new Italics()); - this.properties.push(new ItalicsComplexScript()); - } - - if (options.underline) { - this.properties.push(new Underline(options.underline.type, options.underline.color)); - } - - if (options.color) { - this.properties.push(new Color(options.color)); - } - - if (options.size) { - this.properties.push(new Size(options.size)); - this.properties.push(new SizeComplexScript(options.size)); - } - - if (options.rightToLeft) { - this.properties.push(new RightToLeft()); - } - - if (options.smallCaps) { - this.properties.push(new SmallCaps()); - } - - if (options.allCaps) { - this.properties.push(new Caps()); - } - - if (options.strike) { - this.properties.push(new Strike()); - } - - if (options.doubleStrike) { - this.properties.push(new DoubleStrike()); - } - - if (options.subScript) { - this.properties.push(new SubScript()); - } - - if (options.superScript) { - this.properties.push(new SuperScript()); - } - - if (options.style) { - this.properties.push(new Style(options.style)); - } - - if (options.font) { - this.properties.push(new RunFonts(options.font.name, options.font.hint)); - } - - if (options.highlight) { - this.properties.push(new Highlight(options.highlight)); - this.properties.push(new HighlightComplexScript(options.highlight)); - } - - if (options.shading) { - this.properties.push(new Shading(options.shading.type, options.shading.fill, options.shading.color)); - this.properties.push(new ShadowComplexScript(options.shading.type, options.shading.fill, options.shading.color)); - } - if (options.children) { for (const child of options.children) { if (typeof child === "string") { @@ -179,10 +63,11 @@ export class Run extends XmlComponent { } else if (options.text) { this.root.push(new Text(options.text)); } - } - public break(): Run { - this.root.splice(1, 0, new Break()); - return this; + if (options.break) { + for (let i = 0; i < options.break; i++) { + this.root.splice(1, 0, new Break()); + } + } } } diff --git a/src/file/paragraph/run/symbol-run.spec.ts b/src/file/paragraph/run/symbol-run.spec.ts index f3faee8bb0..c41e6e1d51 100644 --- a/src/file/paragraph/run/symbol-run.spec.ts +++ b/src/file/paragraph/run/symbol-run.spec.ts @@ -1,5 +1,7 @@ import { expect } from "chai"; +import { EmphasisMarkType } from "./emphasis-mark"; + import { Formatter } from "export/formatter"; import { UnderlineType } from "./underline"; @@ -44,6 +46,9 @@ describe("SymbolRun", () => { color: "red", type: UnderlineType.DOUBLE, }, + emphasisMark: { + type: EmphasisMarkType.DOT, + }, color: "green", size: 40, highlight: "yellow", @@ -59,6 +64,7 @@ describe("SymbolRun", () => { { "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }, { "w:u": { _attr: { "w:val": "double", "w:color": "red" } } }, + { "w:em": { _attr: { "w:val": "dot" } } }, { "w:color": { _attr: { "w:val": "green" } } }, { "w:sz": { _attr: { "w:val": 40 } } }, { "w:szCs": { _attr: { "w:val": 40 } } }, diff --git a/src/file/relationships/relationship/relationship.ts b/src/file/relationships/relationship/relationship.ts index 82672644c9..2b928de890 100644 --- a/src/file/relationships/relationship/relationship.ts +++ b/src/file/relationships/relationship/relationship.ts @@ -13,6 +13,7 @@ export type RelationshipType = | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" | "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" + | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"; diff --git a/src/file/settings/compatibility-setting/compatibility-setting.spec.ts b/src/file/settings/compatibility-setting/compatibility-setting.spec.ts new file mode 100644 index 0000000000..0f65697cda --- /dev/null +++ b/src/file/settings/compatibility-setting/compatibility-setting.spec.ts @@ -0,0 +1,23 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; + +import { CompatibilitySetting } from "./compatibility-setting"; + +describe("CompatibilitySetting", () => { + describe("#constructor", () => { + it("creates an initially empty property object", () => { + const compatibilitySetting = new CompatibilitySetting(15); + + const tree = new Formatter().format(compatibilitySetting); + expect(tree).to.deep.equal({ + "w:compatSetting": { + _attr: { + "w:name": "compatibilityMode", + "w:uri": "http://schemas.microsoft.com/office/word", + "w:val": 15, + }, + }, + }); + }); + }); +}); diff --git a/src/file/settings/compatibility-setting/compatibility-setting.ts b/src/file/settings/compatibility-setting/compatibility-setting.ts new file mode 100644 index 0000000000..9f2a0b4982 --- /dev/null +++ b/src/file/settings/compatibility-setting/compatibility-setting.ts @@ -0,0 +1,27 @@ +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +export class CompatibilitySettingAttributes extends XmlAttributeComponent<{ + readonly version: number; + readonly name: string; + readonly uri: string; +}> { + protected readonly xmlKeys = { + version: "w:val", + name: "w:name", + uri: "w:uri", + }; +} + +export class CompatibilitySetting extends XmlComponent { + constructor(version: number) { + super("w:compatSetting"); + + this.root.push( + new CompatibilitySettingAttributes({ + version, + uri: "http://schemas.microsoft.com/office/word", + name: "compatibilityMode", + }), + ); + } +} diff --git a/src/file/settings/compatibility.spec.ts b/src/file/settings/compatibility.spec.ts index 6399dcfeea..fa9809672d 100644 --- a/src/file/settings/compatibility.spec.ts +++ b/src/file/settings/compatibility.spec.ts @@ -1,13 +1,14 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { Compatibility } from "file/settings/compatibility"; import { EMPTY_OBJECT } from "file/xml-components"; +import { Compatibility } from "./compatibility"; + describe("Compatibility", () => { describe("#constructor", () => { it("creates an initially empty property object", () => { - const compatibility = new Compatibility(); + const compatibility = new Compatibility({}); const tree = new Formatter().format(compatibility); expect(tree).to.deep.equal({ "w:compat": EMPTY_OBJECT }); @@ -16,8 +17,9 @@ describe("Compatibility", () => { describe("#doNotExpandShiftReturn", () => { it("should create a setting for not justifying lines ending in soft line break", () => { - const compatibility = new Compatibility(); - compatibility.doNotExpandShiftReturn(); + const compatibility = new Compatibility({ + doNotExpandShiftReturn: true, + }); const tree = new Formatter().format(compatibility); expect(tree).to.deep.equal({ "w:compat": [{ "w:doNotExpandShiftReturn": EMPTY_OBJECT }] }); diff --git a/src/file/settings/compatibility.ts b/src/file/settings/compatibility.ts index afd2dd0f37..fe63da92c5 100644 --- a/src/file/settings/compatibility.ts +++ b/src/file/settings/compatibility.ts @@ -1,4 +1,5 @@ import { XmlComponent } from "file/xml-components"; +import { CompatibilitySetting } from "./compatibility-setting/compatibility-setting"; class DoNotExpandShiftReturn extends XmlComponent { constructor() { @@ -6,14 +7,21 @@ class DoNotExpandShiftReturn extends XmlComponent { } } +export interface ICompatibilityOptions { + readonly doNotExpandShiftReturn?: boolean; + readonly version?: number; +} + export class Compatibility extends XmlComponent { - constructor() { + constructor(options: ICompatibilityOptions) { super("w:compat"); - } - public doNotExpandShiftReturn(): Compatibility { - this.root.push(new DoNotExpandShiftReturn()); + if (options.doNotExpandShiftReturn) { + this.root.push(new DoNotExpandShiftReturn()); + } - return this; + if (options.version) { + this.root.push(new CompatibilitySetting(options.version)); + } } } diff --git a/src/file/settings/display-background-shape.spec.ts b/src/file/settings/display-background-shape.spec.ts new file mode 100644 index 0000000000..34c23b65db --- /dev/null +++ b/src/file/settings/display-background-shape.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { DisplayBackgroundShape } from "./display-background-shape"; + +describe("DisplayBackgroundShape", () => { + describe("#constructor()", () => { + it("should create", () => { + const displayBackgroundShape = new DisplayBackgroundShape(); + const tree = new Formatter().format(displayBackgroundShape); + expect(tree).to.deep.equal({ + "w:displayBackgroundShape": {}, + }); + }); + }); +}); diff --git a/src/file/settings/display-background-shape.ts b/src/file/settings/display-background-shape.ts new file mode 100644 index 0000000000..bd0cd15675 --- /dev/null +++ b/src/file/settings/display-background-shape.ts @@ -0,0 +1,9 @@ +// http://officeopenxml.com/WPdocument.php +// http://www.datypic.com/sc/ooxml/e-w_background-1.html +import { XmlComponent } from "file/xml-components"; + +export class DisplayBackgroundShape extends XmlComponent { + constructor() { + super("w:displayBackgroundShape"); + } +} diff --git a/src/file/settings/settings.spec.ts b/src/file/settings/settings.spec.ts index 1e34c781c2..381b24d372 100644 --- a/src/file/settings/settings.spec.ts +++ b/src/file/settings/settings.spec.ts @@ -7,7 +7,7 @@ import { Settings } from "./settings"; describe("Settings", () => { describe("#constructor", () => { it("should create a empty Settings with correct rootKey", () => { - const settings = new Settings(); + const settings = new Settings({}); const tree = new Formatter().format(settings); let keys = Object.keys(tree); expect(keys).is.an.instanceof(Array); @@ -15,8 +15,7 @@ describe("Settings", () => { expect(keys[0]).to.be.equal("w:settings"); keys = Object.keys(tree["w:settings"]); expect(keys).is.an.instanceof(Array); - expect(keys).has.length(1); - expect(keys[0]).to.be.equal("_attr"); + expect(keys).has.length(3); }); }); describe("#addUpdateFields", () => { @@ -28,16 +27,16 @@ describe("Settings", () => { expect(keys[0]).to.be.equal("w:settings"); const rootArray = tree["w:settings"]; expect(rootArray).is.an.instanceof(Array); - expect(rootArray).has.length(2); + expect(rootArray).has.length(4); keys = Object.keys(rootArray[0]); expect(keys).is.an.instanceof(Array); expect(keys).has.length(1); expect(keys[0]).to.be.equal("_attr"); - keys = Object.keys(rootArray[1]); + keys = Object.keys(rootArray[3]); expect(keys).is.an.instanceof(Array); expect(keys).has.length(1); expect(keys[0]).to.be.equal("w:updateFields"); - const updateFields = rootArray[1]["w:updateFields"]; + const updateFields = rootArray[3]["w:updateFields"]; keys = Object.keys(updateFields); expect(keys).is.an.instanceof(Array); expect(keys).has.length(1); @@ -46,12 +45,12 @@ describe("Settings", () => { expect(updateFieldsAttr["w:val"]).to.be.equal(true); }; it("should add a UpdateFields with value true", () => { - const settings = new Settings(); + const settings = new Settings({}); settings.addUpdateFields(); assertSettingsWithUpdateFields(settings); }); it("should add a UpdateFields with value true only once", () => { - const settings = new Settings(); + const settings = new Settings({}); settings.addUpdateFields(); assertSettingsWithUpdateFields(settings); settings.addUpdateFields(); @@ -59,16 +58,15 @@ describe("Settings", () => { }); }); describe("#addCompatibility", () => { - it("should add an empty Compatibility", () => { - const settings = new Settings(); - settings.addCompatibility(); + it("should add an empty Compatibility by default", () => { + const settings = new Settings({}); const tree = new Formatter().format(settings); let keys: string[] = Object.keys(tree); expect(keys[0]).to.be.equal("w:settings"); const rootArray = tree["w:settings"]; expect(rootArray).is.an.instanceof(Array); - expect(rootArray).has.length(2); + expect(rootArray).has.length(3); keys = Object.keys(rootArray[0]); expect(keys).is.an.instanceof(Array); expect(keys).has.length(1); @@ -77,6 +75,58 @@ describe("Settings", () => { expect(keys).is.an.instanceof(Array); expect(keys).has.length(1); expect(keys[0]).to.be.equal("w:compat"); + expect(rootArray[1]["w:compat"][0]).to.deep.equal({ + "w:compatSetting": { + _attr: { + "w:val": 15, + "w:uri": "http://schemas.microsoft.com/office/word", + "w:name": "compatibilityMode", + }, + }, + }); + }); + }); + describe("#addTrackRevisions", () => { + it("should add an empty Track Revisions", () => { + const settings = new Settings({}); + settings.addTrackRevisions(); + + const tree = new Formatter().format(settings); + let keys: string[] = Object.keys(tree); + expect(keys[0]).to.be.equal("w:settings"); + const rootArray = tree["w:settings"]; + expect(rootArray).is.an.instanceof(Array); + expect(rootArray).has.length(4); + keys = Object.keys(rootArray[0]); + expect(keys).is.an.instanceof(Array); + expect(keys).has.length(1); + expect(keys[0]).to.be.equal("_attr"); + keys = Object.keys(rootArray[3]); + expect(keys).is.an.instanceof(Array); + expect(keys).has.length(1); + expect(keys[0]).to.be.equal("w:trackRevisions"); + }); + }); + describe("#addTrackRevisionsTwice", () => { + it("should add an empty Track Revisions if called twice", () => { + const settings = new Settings({}); + settings.addTrackRevisions(); + settings.addTrackRevisions(); + + const tree = new Formatter().format(settings); + let keys: string[] = Object.keys(tree); + expect(keys[0]).to.be.equal("w:settings"); + const rootArray = tree["w:settings"]; + expect(rootArray).is.an.instanceof(Array); + expect(rootArray).has.length(4); + keys = Object.keys(rootArray[0]); + expect(keys).is.an.instanceof(Array); + expect(keys).has.length(1); + expect(keys[0]).to.be.equal("_attr"); + keys = Object.keys(rootArray[3]); + expect(keys).is.an.instanceof(Array); + expect(keys).has.length(1); + expect(keys[0]).to.be.equal("w:trackRevisions"); }); }); }); diff --git a/src/file/settings/settings.ts b/src/file/settings/settings.ts index abae0e61d4..e63d539a39 100644 --- a/src/file/settings/settings.ts +++ b/src/file/settings/settings.ts @@ -1,5 +1,7 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { Compatibility } from "./compatibility"; +import { DisplayBackgroundShape } from "./display-background-shape"; +import { TrackRevisions } from "./track-revisions"; import { UpdateFields } from "./update-fields"; export interface ISettingsAttributesProperties { @@ -44,10 +46,15 @@ export class SettingsAttributes extends XmlAttributeComponent child instanceof Compatibility)) { - this.addChildElement(this.compatibility); + public addTrackRevisions(): TrackRevisions { + if (!this.root.find((child) => child instanceof TrackRevisions)) { + this.addChildElement(this.trackRevisions); } - return this.compatibility; + return this.trackRevisions; } } diff --git a/src/file/settings/track-revisions.spec.ts b/src/file/settings/track-revisions.spec.ts new file mode 100644 index 0000000000..3875d51f0a --- /dev/null +++ b/src/file/settings/track-revisions.spec.ts @@ -0,0 +1,16 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { TrackRevisions } from "file/settings/track-revisions"; + +import { EMPTY_OBJECT } from "file/xml-components"; + +describe("TrackRevisions", () => { + describe("#constructor", () => { + it("creates an initially empty property object", () => { + const trackRevisions = new TrackRevisions(); + + const tree = new Formatter().format(trackRevisions); + expect(tree).to.deep.equal({ "w:trackRevisions": EMPTY_OBJECT }); + }); + }); +}); diff --git a/src/file/settings/track-revisions.ts b/src/file/settings/track-revisions.ts new file mode 100644 index 0000000000..2da692827e --- /dev/null +++ b/src/file/settings/track-revisions.ts @@ -0,0 +1,7 @@ +import { XmlComponent } from "file/xml-components"; + +export class TrackRevisions extends XmlComponent { + constructor() { + super("w:trackRevisions"); + } +} diff --git a/src/file/styles/defaults/document-defaults.spec.ts b/src/file/styles/defaults/document-defaults.spec.ts new file mode 100644 index 0000000000..79ca9cccf7 --- /dev/null +++ b/src/file/styles/defaults/document-defaults.spec.ts @@ -0,0 +1,45 @@ +import { expect } from "chai"; + +import { DocumentDefaults } from "./document-defaults"; + +import { Formatter } from "export/formatter"; + +describe("DocumentDefaults", () => { + it("#constructor", () => { + const defaults = new DocumentDefaults({ + paragraph: { spacing: { line: 240 } }, + run: { color: "808080" }, + }); + const tree = new Formatter().format(defaults); + expect(tree).to.deep.equal({ + "w:docDefaults": [ + { + "w:rPrDefault": [ + { + "w:rPr": [ + { + "w:color": { _attr: { "w:val": "808080" } }, + }, + ], + }, + ], + }, + { + "w:pPrDefault": [ + { + "w:pPr": [ + { + "w:spacing": { + _attr: { + "w:line": 240, + }, + }, + }, + ], + }, + ], + }, + ], + }); + }); +}); diff --git a/src/file/styles/defaults/document-defaults.ts b/src/file/styles/defaults/document-defaults.ts new file mode 100644 index 0000000000..1f97bb2b07 --- /dev/null +++ b/src/file/styles/defaults/document-defaults.ts @@ -0,0 +1,25 @@ +import { IParagraphStylePropertiesOptions } from "file/paragraph/properties"; +import { IRunStylePropertiesOptions } from "file/paragraph/run/properties"; +import { XmlComponent } from "file/xml-components"; +import { ParagraphPropertiesDefaults } from "./paragraph-properties"; +import { RunPropertiesDefaults } from "./run-properties"; + +export interface IDocumentDefaultsOptions { + readonly paragraph?: IParagraphStylePropertiesOptions; + readonly run?: IRunStylePropertiesOptions; +} + +export class DocumentDefaults extends XmlComponent { + private readonly runPropertiesDefaults: RunPropertiesDefaults; + private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults; + + constructor(options?: IDocumentDefaultsOptions) { + super("w:docDefaults"); + + this.runPropertiesDefaults = new RunPropertiesDefaults(options && options.run); + this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults(options && options.paragraph); + + this.root.push(this.runPropertiesDefaults); + this.root.push(this.paragraphPropertiesDefaults); + } +} diff --git a/src/file/styles/defaults/index.ts b/src/file/styles/defaults/index.ts index 2b6c49e299..986aa6194d 100644 --- a/src/file/styles/defaults/index.ts +++ b/src/file/styles/defaults/index.ts @@ -1,16 +1,3 @@ -import { XmlComponent } from "file/xml-components"; -import { ParagraphPropertiesDefaults } from "./paragraph-properties"; -import { RunPropertiesDefaults } from "./run-properties"; - -export class DocumentDefaults extends XmlComponent { - private readonly runPropertiesDefaults: RunPropertiesDefaults; - private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults; - - constructor() { - super("w:docDefaults"); - this.runPropertiesDefaults = new RunPropertiesDefaults(); - this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults(); - this.root.push(this.runPropertiesDefaults); - this.root.push(this.paragraphPropertiesDefaults); - } -} +export * from "./paragraph-properties"; +export * from "./run-properties"; +export * from "./document-defaults"; diff --git a/src/file/styles/defaults/paragraph-properties.ts b/src/file/styles/defaults/paragraph-properties.ts index c5f2bee86c..cac92575a4 100644 --- a/src/file/styles/defaults/paragraph-properties.ts +++ b/src/file/styles/defaults/paragraph-properties.ts @@ -1,9 +1,9 @@ -import { ParagraphProperties } from "file/paragraph/properties"; +import { IParagraphStylePropertiesOptions, ParagraphProperties } from "file/paragraph/properties"; import { XmlComponent } from "file/xml-components"; export class ParagraphPropertiesDefaults extends XmlComponent { - constructor() { + constructor(options?: IParagraphStylePropertiesOptions) { super("w:pPrDefault"); - this.root.push(new ParagraphProperties({})); + this.root.push(new ParagraphProperties(options)); } } diff --git a/src/file/styles/defaults/run-properties.ts b/src/file/styles/defaults/run-properties.ts index 1ab8f5752c..f4e594ab99 100644 --- a/src/file/styles/defaults/run-properties.ts +++ b/src/file/styles/defaults/run-properties.ts @@ -1,25 +1,12 @@ -import { Size, SizeComplexScript } from "file/paragraph/run/formatting"; -import { RunProperties } from "file/paragraph/run/properties"; -import { RunFonts } from "file/paragraph/run/run-fonts"; +import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties"; import { XmlComponent } from "file/xml-components"; export class RunPropertiesDefaults extends XmlComponent { private readonly properties: RunProperties; - constructor() { + constructor(options?: IRunStylePropertiesOptions) { super("w:rPrDefault"); - this.properties = new RunProperties(); + this.properties = new RunProperties(options); this.root.push(this.properties); } - - public size(size: number): RunPropertiesDefaults { - this.properties.push(new Size(size)); - this.properties.push(new SizeComplexScript(size)); - return this; - } - - public font(fontName: string): RunPropertiesDefaults { - this.properties.push(new RunFonts(fontName)); - return this; - } } diff --git a/src/file/styles/factory.ts b/src/file/styles/factory.ts index f5bca8248d..097c812433 100644 --- a/src/file/styles/factory.ts +++ b/src/file/styles/factory.ts @@ -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 || {}), ], }; } diff --git a/src/file/styles/index.ts b/src/file/styles/index.ts index 144bbcb1fd..e18813fbb8 100644 --- a/src/file/styles/index.ts +++ b/src/file/styles/index.ts @@ -1,3 +1,4 @@ export * from "./styles"; export * from "./style/character-style"; export * from "./style/paragraph-style"; +export * from "./defaults"; diff --git a/src/file/styles/style-options.ts b/src/file/styles/style-options.ts deleted file mode 100644 index 744f4244fb..0000000000 --- a/src/file/styles/style-options.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { AlignmentType, IIndentAttributesProperties, ISpacingProperties, UnderlineType } from "../paragraph"; -import { ShadingType } from "../table"; - -export interface IRunStyleOptions { - readonly size?: number; - readonly bold?: boolean; - readonly italics?: boolean; - readonly smallCaps?: boolean; - readonly allCaps?: boolean; - readonly strike?: boolean; - readonly doubleStrike?: boolean; - readonly subScript?: boolean; - readonly superScript?: boolean; - readonly underline?: { - readonly type?: UnderlineType; - readonly color?: string; - }; - readonly color?: string; - readonly font?: string; - readonly characterSpacing?: number; - readonly highlight?: string; - readonly shadow?: { - readonly type: ShadingType; - readonly fill: string; - readonly color: string; - }; -} - -export interface IParagraphStyleOptions2 { - readonly alignment?: AlignmentType; - readonly thematicBreak?: boolean; - readonly contextualSpacing?: boolean; - readonly rightTabStop?: number; - readonly leftTabStop?: number; - readonly indent?: IIndentAttributesProperties; - readonly spacing?: ISpacingProperties; - readonly keepNext?: boolean; - readonly keepLines?: boolean; - readonly outlineLevel?: number; -} diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index fe269bfceb..c7adf4ff97 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -1,16 +1,17 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; +import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark"; import { UnderlineType } from "file/paragraph/run/underline"; import { ShadingType } from "file/table"; import { EMPTY_OBJECT } from "file/xml-components"; -import { CharacterStyle } from "./character-style"; +import { StyleForCharacter } from "./character-style"; describe("CharacterStyle", () => { describe("#constructor", () => { it("should set the style type to character and use the given style id", () => { - const style = new CharacterStyle({ id: "myStyleId" }); + const style = new StyleForCharacter({ id: "myStyleId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -30,7 +31,7 @@ describe("CharacterStyle", () => { }); it("should set the name of the style, if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", name: "Style Name", }); @@ -54,7 +55,7 @@ describe("CharacterStyle", () => { }); it("should add smallCaps", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { smallCaps: true, @@ -82,7 +83,7 @@ describe("CharacterStyle", () => { }); it("should add allCaps", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { allCaps: true, @@ -110,7 +111,7 @@ describe("CharacterStyle", () => { }); it("should add strike", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { strike: true, @@ -138,7 +139,7 @@ describe("CharacterStyle", () => { }); it("should add double strike", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { doubleStrike: true, @@ -166,7 +167,7 @@ describe("CharacterStyle", () => { }); it("should add sub script", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { subScript: true, @@ -201,8 +202,8 @@ describe("CharacterStyle", () => { }); }); - it("should add font", () => { - const style = new CharacterStyle({ + it("should add font by name", () => { + const style = new StyleForCharacter({ id: "myStyleId", run: { font: "test font", @@ -240,8 +241,48 @@ describe("CharacterStyle", () => { }); }); + it("should add font for ascii and eastAsia", () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { + font: { + ascii: "test font ascii", + eastAsia: "test font eastAsia", + }, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "test font ascii", + "w:eastAsia": "test font eastAsia", + }, + }, + }, + ], + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, + }, + }, + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); + }); + it("should add character spacing", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { characterSpacing: 100, @@ -271,7 +312,7 @@ describe("CharacterStyle", () => { describe("formatting methods: style attributes", () => { it("#basedOn", () => { - const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" }); + const style = new StyleForCharacter({ id: "myStyleId", basedOn: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -293,37 +334,58 @@ describe("CharacterStyle", () => { }); describe("formatting methods: run properties", () => { - it("#size", () => { - const style = new CharacterStyle({ - id: "myStyleId", - run: { - size: 24, - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], - }, - { - "w:uiPriority": { - _attr: { - "w:val": 99, + const sizeTests = [ + { + size: 24, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: true, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: false, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: 26, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }], + }, + ]; + sizeTests.forEach(({ size, sizeComplexScript, expected }) => { + it(`#size ${size} cs ${sizeComplexScript}`, () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { size, sizeComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": expected, + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, }, }, - }, - { - "w:unhideWhenUsed": EMPTY_OBJECT, - }, - ], + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); }); }); describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: {}, @@ -351,7 +413,7 @@ describe("CharacterStyle", () => { }); it("should set the style if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: { @@ -381,7 +443,7 @@ describe("CharacterStyle", () => { }); it("should set the style and color if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: { @@ -412,8 +474,68 @@ describe("CharacterStyle", () => { }); }); + describe("#emphasisMark", () => { + it("should set emphasisMark to 'dot' if no arguments are given", () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { + emphasisMark: {}, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, + }, + }, + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); + }); + + it("should set the style if given", () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { + emphasisMark: { + type: EmphasisMarkType.DOT, + }, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, + }, + }, + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); + }); + }); + it("#superScript", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { superScript: true, @@ -449,7 +571,7 @@ describe("CharacterStyle", () => { }); it("#color", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { color: "123456", @@ -476,64 +598,96 @@ describe("CharacterStyle", () => { }); }); - it("#bold", () => { - const style = new CharacterStyle({ - id: "myStyleId", - run: { - bold: true, - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], - }, - { - "w:uiPriority": { - _attr: { - "w:val": 99, + const boldTests = [ + { + bold: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: false, + expected: [{ "w:b": { _attr: { "w:val": true } } }], + }, + ]; + boldTests.forEach(({ bold, boldComplexScript, expected }) => { + it(`#bold ${bold} cs ${boldComplexScript}`, () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { bold, boldComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": expected, + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, }, }, - }, - { - "w:unhideWhenUsed": EMPTY_OBJECT, - }, - ], + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); }); }); - it("#italics", () => { - const style = new CharacterStyle({ - id: "myStyleId", - run: { - italics: true, - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], - }, - { - "w:uiPriority": { - _attr: { - "w:val": 99, + const italicsTests = [ + { + italics: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: false, + expected: [{ "w:i": { _attr: { "w:val": true } } }], + }, + ]; + italicsTests.forEach(({ italics, italicsComplexScript, expected }) => { + it(`#italics ${italics} cs ${italicsComplexScript}`, () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { italics, italicsComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": expected, + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, }, }, - }, - { - "w:unhideWhenUsed": EMPTY_OBJECT, - }, - ], + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); }); }); it("#link", () => { - const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" }); + const style = new StyleForCharacter({ id: "myStyleId", link: "MyLink" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -554,7 +708,7 @@ describe("CharacterStyle", () => { }); it("#semiHidden", () => { - const style = new CharacterStyle({ id: "myStyleId", semiHidden: true }); + const style = new StyleForCharacter({ id: "myStyleId", semiHidden: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -572,63 +726,141 @@ describe("CharacterStyle", () => { }); }); - it("#highlight", () => { - const style = new CharacterStyle({ - id: "myStyleId", - run: { - highlight: "005599", - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], - }, - { - "w:uiPriority": { - _attr: { - "w:val": 99, + const highlightTests = [ + { + highlight: "005599", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: true, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: false, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: "550099", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }], + }, + ]; + highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => { + it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { highlight, highlightComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": expected, + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, }, }, - }, - { - "w:unhideWhenUsed": EMPTY_OBJECT, - }, - ], + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); }); }); - it("#shadow", () => { - const style = new CharacterStyle({ - id: "myStyleId", - run: { - shadow: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", - }, + const shadingTests = [ + { + shadow: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], - }, - { - "w:uiPriority": { - _attr: { - "w:val": 99, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: true, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: false, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "00FF00", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } }, + ], + }, + ]; + shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => { + it("#shadow correctly", () => { + const style = new StyleForCharacter({ + id: "myStyleId", + run: { shadow, shading, shadingComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": expected, + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, }, }, - }, - { - "w:unhideWhenUsed": EMPTY_OBJECT, - }, - ], + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); }); }); }); diff --git a/src/file/styles/style/character-style.ts b/src/file/styles/style/character-style.ts index 32ff4b6b69..63252bddd5 100644 --- a/src/file/styles/style/character-style.ts +++ b/src/file/styles/style/character-style.ts @@ -1,6 +1,4 @@ -import * as formatting from "file/paragraph/run/formatting"; -import { RunProperties } from "file/paragraph/run/properties"; -import { UnderlineType } from "file/paragraph/run/underline"; +import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties"; import { BasedOn, Link, SemiHidden, UiPriority, UnhideWhenUsed } from "./components"; import { Style } from "./style"; @@ -9,30 +7,7 @@ export interface IBaseCharacterStyleOptions { readonly basedOn?: string; readonly link?: string; readonly semiHidden?: boolean; - readonly run?: { - readonly size?: number; - readonly bold?: boolean; - readonly italics?: boolean; - readonly smallCaps?: boolean; - readonly allCaps?: boolean; - readonly strike?: boolean; - readonly doubleStrike?: boolean; - readonly subScript?: boolean; - readonly superScript?: boolean; - readonly underline?: { - readonly type?: UnderlineType; - readonly color?: string; - }; - readonly color?: string; - readonly font?: string; - readonly characterSpacing?: number; - readonly highlight?: string; - readonly shadow?: { - readonly type: string; - readonly fill: string; - readonly color: string; - }; - }; + readonly run?: IRunStylePropertiesOptions; } export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions { @@ -40,12 +15,14 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions { readonly name?: string; } -export class CharacterStyle extends Style { +export class StyleForCharacter extends Style { private readonly runProperties: RunProperties; constructor(options: ICharacterStyleOptions) { super({ type: "character", styleId: options.id }, options.name); - this.runProperties = new RunProperties(); + + this.runProperties = new RunProperties(options.run); + this.root.push(this.runProperties); this.root.push(new UiPriority(99)); this.root.push(new UnhideWhenUsed()); @@ -61,68 +38,5 @@ export class CharacterStyle extends Style { if (options.semiHidden) { this.root.push(new SemiHidden()); } - - if (options.run) { - if (options.run.size) { - this.runProperties.push(new formatting.Size(options.run.size)); - this.runProperties.push(new formatting.SizeComplexScript(options.run.size)); - } - - if (options.run.bold) { - this.runProperties.push(new formatting.Bold()); - } - - if (options.run.italics) { - this.runProperties.push(new formatting.Italics()); - } - - if (options.run.smallCaps) { - this.runProperties.push(new formatting.SmallCaps()); - } - - if (options.run.allCaps) { - this.runProperties.push(new formatting.Caps()); - } - - if (options.run.strike) { - this.runProperties.push(new formatting.Strike()); - } - - if (options.run.doubleStrike) { - this.runProperties.push(new formatting.DoubleStrike()); - } - - if (options.run.subScript) { - this.runProperties.push(new formatting.SubScript()); - } - - if (options.run.superScript) { - this.runProperties.push(new formatting.SuperScript()); - } - - if (options.run.underline) { - this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color)); - } - - if (options.run.color) { - this.runProperties.push(new formatting.Color(options.run.color)); - } - - if (options.run.font) { - this.runProperties.push(new formatting.RunFonts(options.run.font)); - } - - if (options.run.characterSpacing) { - this.runProperties.push(new formatting.CharacterSpacing(options.run.characterSpacing)); - } - - if (options.run.highlight) { - this.runProperties.push(new formatting.Highlight(options.run.highlight)); - } - - if (options.run.shadow) { - this.runProperties.push(new formatting.Shading(options.run.shadow.type, options.run.shadow.fill, options.run.shadow.color)); - } - } } } diff --git a/src/file/styles/style/default-styles.spec.ts b/src/file/styles/style/default-styles.spec.ts index 1cf26ba482..962f47d9c0 100644 --- a/src/file/styles/style/default-styles.spec.ts +++ b/src/file/styles/style/default-styles.spec.ts @@ -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); diff --git a/src/file/styles/style/default-styles.ts b/src/file/styles/style/default-styles.ts index 8974435a95..f8be7572ee 100644 --- a/src/file/styles/style/default-styles.ts +++ b/src/file/styles/style/default-styles.ts @@ -1,9 +1,9 @@ import { UnderlineType } from "file/paragraph/run/underline"; -import { CharacterStyle, IBaseCharacterStyleOptions } from "./character-style"; -import { IBaseParagraphStyleOptions, IParagraphStyleOptions, ParagraphStyle } from "./paragraph-style"; +import { IBaseCharacterStyleOptions, StyleForCharacter } from "./character-style"; +import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph } from "./paragraph-style"; -export class HeadingStyle extends ParagraphStyle { +export class HeadingStyle extends StyleForParagraph { constructor(options: IParagraphStyleOptions) { super({ ...options, @@ -84,7 +84,17 @@ export class Heading6Style extends HeadingStyle { } } -export class ListParagraph extends ParagraphStyle { +export class StrongStyle extends HeadingStyle { + constructor(options: IBaseParagraphStyleOptions) { + super({ + ...options, + id: "Strong", + name: "Strong", + }); + } +} + +export class ListParagraph extends StyleForParagraph { constructor(options: IBaseParagraphStyleOptions) { super({ ...options, @@ -96,7 +106,7 @@ export class ListParagraph extends ParagraphStyle { } } -export class FootnoteText extends ParagraphStyle { +export class FootnoteText extends StyleForParagraph { constructor(options: IBaseParagraphStyleOptions) { super({ ...options, @@ -121,7 +131,7 @@ export class FootnoteText extends ParagraphStyle { } } -export class FootnoteReferenceStyle extends CharacterStyle { +export class FootnoteReferenceStyle extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, @@ -136,7 +146,7 @@ export class FootnoteReferenceStyle extends CharacterStyle { } } -export class FootnoteTextChar extends CharacterStyle { +export class FootnoteTextChar extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, @@ -152,7 +162,7 @@ export class FootnoteTextChar extends CharacterStyle { } } -export class HyperlinkStyle extends CharacterStyle { +export class HyperlinkStyle extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 8d9b4da15a..8683234793 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -1,17 +1,17 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { AlignmentType, TabStopPosition } from "file/paragraph"; +import { AlignmentType, EmphasisMarkType, TabStopPosition } from "file/paragraph"; import { UnderlineType } from "file/paragraph/run/underline"; import { ShadingType } from "file/table"; import { EMPTY_OBJECT } from "file/xml-components"; -import { ParagraphStyle } from "./paragraph-style"; +import { StyleForParagraph } from "./paragraph-style"; describe("ParagraphStyle", () => { describe("#constructor", () => { it("should set the style type to paragraph and use the given style id", () => { - const style = new ParagraphStyle({ id: "myStyleId" }); + const style = new StyleForParagraph({ id: "myStyleId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, @@ -19,7 +19,7 @@ describe("ParagraphStyle", () => { }); it("should set the name of the style, if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", name: "Style Name", }); @@ -35,7 +35,7 @@ describe("ParagraphStyle", () => { describe("formatting methods: style attributes", () => { it("#basedOn", () => { - const style = new ParagraphStyle({ id: "myStyleId", basedOn: "otherId" }); + const style = new StyleForParagraph({ id: "myStyleId", basedOn: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -46,15 +46,23 @@ describe("ParagraphStyle", () => { }); it("#quickFormat", () => { - const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true }); + const style = new StyleForParagraph({ id: "myStyleId", quickFormat: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": EMPTY_OBJECT }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:qFormat": EMPTY_OBJECT }, + ], }); }); it("#next", () => { - const style = new ParagraphStyle({ id: "myStyleId", next: "otherId" }); + const style = new StyleForParagraph({ id: "myStyleId", next: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -67,7 +75,7 @@ describe("ParagraphStyle", () => { describe("formatting methods: paragraph properties", () => { it("#indent", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { indent: { left: 720 }, @@ -85,7 +93,7 @@ describe("ParagraphStyle", () => { }); it("#spacing", () => { - const style = new ParagraphStyle({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } }); + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -98,7 +106,7 @@ describe("ParagraphStyle", () => { }); it("#center", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.CENTER, @@ -116,7 +124,7 @@ describe("ParagraphStyle", () => { }); it("#character spacing", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { characterSpacing: 24, @@ -134,7 +142,7 @@ describe("ParagraphStyle", () => { }); it("#left", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.LEFT, @@ -152,7 +160,7 @@ describe("ParagraphStyle", () => { }); it("#right", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.RIGHT, @@ -170,7 +178,7 @@ describe("ParagraphStyle", () => { }); it("#justified", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.JUSTIFIED, @@ -188,7 +196,7 @@ describe("ParagraphStyle", () => { }); it("#thematicBreak", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { thematicBreak: true, @@ -221,7 +229,7 @@ describe("ParagraphStyle", () => { }); it("#contextualSpacing", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { contextualSpacing: true, @@ -247,7 +255,7 @@ describe("ParagraphStyle", () => { }); it("#leftTabStop", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { leftTabStop: 1200, @@ -269,7 +277,7 @@ describe("ParagraphStyle", () => { }); it("#maxRightTabStop", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { rightTabStop: TabStopPosition.MAX, @@ -291,7 +299,7 @@ describe("ParagraphStyle", () => { }); it("#keepLines", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { keepLines: true, @@ -299,12 +307,20 @@ describe("ParagraphStyle", () => { }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }, + ], }); }); it("#keepNext", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { keepNext: true, @@ -312,12 +328,20 @@ describe("ParagraphStyle", () => { }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }, + ], }); }); it("#outlineLevel", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { outlineLevel: 1, @@ -334,26 +358,42 @@ describe("ParagraphStyle", () => { }); describe("formatting methods: run properties", () => { - it("#size", () => { - const style = new ParagraphStyle({ - id: "myStyleId", - run: { - size: 24, - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], - }, - ], + const sizeTests = [ + { + size: 24, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: true, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: false, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }], + }, + { + size: 24, + sizeComplexScript: 26, + expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }], + }, + ]; + sizeTests.forEach(({ size, sizeComplexScript, expected }) => { + it(`#size ${size} cs ${sizeComplexScript}`, () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { size, sizeComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }], + }); }); }); it("#smallCaps", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { smallCaps: true, @@ -371,7 +411,7 @@ describe("ParagraphStyle", () => { }); it("#allCaps", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { allCaps: true, @@ -389,7 +429,7 @@ describe("ParagraphStyle", () => { }); it("#strike", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { strike: true, @@ -407,7 +447,7 @@ describe("ParagraphStyle", () => { }); it("#doubleStrike", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { doubleStrike: true, @@ -425,7 +465,7 @@ describe("ParagraphStyle", () => { }); it("#subScript", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { subScript: true, @@ -443,7 +483,7 @@ describe("ParagraphStyle", () => { }); it("#superScript", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { superScript: true, @@ -460,8 +500,8 @@ describe("ParagraphStyle", () => { }); }); - it("#font", () => { - const style = new ParagraphStyle({ + it("#font by name", () => { + const style = new StyleForParagraph({ id: "myStyleId", run: { font: "Times", @@ -473,18 +513,30 @@ describe("ParagraphStyle", () => { { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": [ - { "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } }, + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:cs": "Times", + "w:eastAsia": "Times", + "w:hAnsi": "Times", + }, + }, + }, ], }, ], }); }); - it("#bold", () => { - const style = new ParagraphStyle({ + it("#font for ascii and eastAsia", () => { + const style = new StyleForParagraph({ id: "myStyleId", run: { - bold: true, + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, }, }); const tree = new Formatter().format(style); @@ -492,73 +544,190 @@ describe("ParagraphStyle", () => { "w:style": [ { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { - "w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, + ], }, ], }); }); - it("#italics", () => { - const style = new ParagraphStyle({ - id: "myStyleId", - run: { - italics: true, - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], - }, - ], + const boldTests = [ + { + bold: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: true, + expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }], + }, + { + bold: true, + boldComplexScript: false, + expected: [{ "w:b": { _attr: { "w:val": true } } }], + }, + ]; + boldTests.forEach(({ bold, boldComplexScript, expected }) => { + it(`#bold ${bold} cs ${boldComplexScript}`, () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { bold, boldComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }], + }); }); }); - it("#highlight", () => { - const style = new ParagraphStyle({ - id: "myStyleId", - run: { - highlight: "005599", - }, - }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], - }, - ], + const italicsTests = [ + { + italics: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: true, + expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }], + }, + { + italics: true, + italicsComplexScript: false, + expected: [{ "w:i": { _attr: { "w:val": true } } }], + }, + ]; + italicsTests.forEach(({ italics, italicsComplexScript, expected }) => { + it(`#italics ${italics} cs ${italicsComplexScript}`, () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { italics, italicsComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }], + }); }); }); - it("#shadow", () => { - const style = new ParagraphStyle({ - id: "myStyleId", - run: { - shadow: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", - }, - }, + const highlightTests = [ + { + highlight: "005599", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: true, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: false, + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }], + }, + { + highlight: "005599", + highlightComplexScript: "550099", + expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }], + }, + ]; + highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => { + it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { highlight, highlightComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }], + }); }); - const tree = new Formatter().format(style); - expect(tree).to.deep.equal({ - "w:style": [ - { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, - { - "w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], - }, + }); + + const shadingTests = [ + { + shadow: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: true, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + ], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: false, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + shadingComplexScript: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "00FF00", + }, + expected: [ + { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, + { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } }, + ], + }, + ]; + shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => { + it("#shadow correctly", () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { shadow, shading, shadingComplexScript }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }], + }); }); }); describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: {}, @@ -576,7 +745,7 @@ describe("ParagraphStyle", () => { }); it("should set the style if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: { @@ -596,7 +765,7 @@ describe("ParagraphStyle", () => { }); it("should set the style and color if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: { @@ -617,8 +786,48 @@ describe("ParagraphStyle", () => { }); }); + describe("#emphasisMark", () => { + it("should set emphasisMark to 'dot' if no arguments are given", () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { + emphasisMark: {}, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }, + ], + }); + }); + + it("should set the style if given", () => { + const style = new StyleForParagraph({ + id: "myStyleId", + run: { + emphasisMark: { + type: EmphasisMarkType.DOT, + }, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }], + }, + ], + }); + }); + }); + it("#color", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { color: "123456", @@ -636,23 +845,39 @@ describe("ParagraphStyle", () => { }); it("#link", () => { - const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" }); + const style = new StyleForParagraph({ id: "myStyleId", link: "MyLink" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:link": { _attr: { "w:val": "MyLink" } } }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:link": { _attr: { "w:val": "MyLink" } } }, + ], }); }); it("#semiHidden", () => { - const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true }); + const style = new StyleForParagraph({ id: "myStyleId", semiHidden: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": EMPTY_OBJECT }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:semiHidden": EMPTY_OBJECT }, + ], }); }); it("#uiPriority", () => { - const style = new ParagraphStyle({ id: "myStyleId", uiPriority: 99 }); + const style = new StyleForParagraph({ id: "myStyleId", uiPriority: 99 }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -669,10 +894,18 @@ describe("ParagraphStyle", () => { }); it("#unhideWhenUsed", () => { - const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true }); + const style = new StyleForParagraph({ id: "myStyleId", unhideWhenUsed: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ - "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": EMPTY_OBJECT }], + "w:style": [ + { + _attr: { + "w:type": "paragraph", + "w:styleId": "myStyleId", + }, + }, + { "w:unhideWhenUsed": EMPTY_OBJECT }, + ], }); }); }); diff --git a/src/file/styles/style/paragraph-style.ts b/src/file/styles/style/paragraph-style.ts index 3adb1edbbe..25c035e514 100644 --- a/src/file/styles/style/paragraph-style.ts +++ b/src/file/styles/style/paragraph-style.ts @@ -1,19 +1,6 @@ -import { - Alignment, - ContextualSpacing, - Indent, - KeepLines, - KeepNext, - OutlineLevel, - ParagraphProperties, - Spacing, - ThematicBreak, -} from "file/paragraph"; -import { TabStop, TabStopType } from "file/paragraph/formatting"; -import * as formatting from "file/paragraph/run/formatting"; +import { IParagraphStylePropertiesOptions, IRunStylePropertiesOptions, ParagraphProperties } from "file/paragraph"; import { RunProperties } from "file/paragraph/run/properties"; -import { IParagraphStyleOptions2, IRunStyleOptions } from "../style-options"; import { BasedOn, Link, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components"; import { Style } from "./style"; @@ -25,22 +12,25 @@ export interface IBaseParagraphStyleOptions { readonly semiHidden?: boolean; readonly uiPriority?: number; readonly unhideWhenUsed?: boolean; - readonly run?: IRunStyleOptions; - readonly paragraph?: IParagraphStyleOptions2; + readonly paragraph?: IParagraphStylePropertiesOptions; + readonly run?: IRunStylePropertiesOptions; } export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions { readonly id: string; readonly name?: string; } -export class ParagraphStyle extends Style { + +export class StyleForParagraph extends Style { private readonly paragraphProperties: ParagraphProperties; private readonly runProperties: RunProperties; constructor(options: IParagraphStyleOptions) { super({ type: "paragraph", styleId: options.id }, options.name); - this.paragraphProperties = new ParagraphProperties({}); - this.runProperties = new RunProperties(); + + this.paragraphProperties = new ParagraphProperties(options.paragraph); + this.runProperties = new RunProperties(options.run); + this.root.push(this.paragraphProperties); this.root.push(this.runProperties); @@ -71,110 +61,5 @@ export class ParagraphStyle extends Style { if (options.unhideWhenUsed) { this.root.push(new UnhideWhenUsed()); } - - if (options.run) { - if (options.run.size) { - this.runProperties.push(new formatting.Size(options.run.size)); - this.runProperties.push(new formatting.SizeComplexScript(options.run.size)); - } - - if (options.run.bold) { - this.runProperties.push(new formatting.Bold()); - } - - if (options.run.italics) { - this.runProperties.push(new formatting.Italics()); - } - - if (options.run.smallCaps) { - this.runProperties.push(new formatting.SmallCaps()); - } - - if (options.run.allCaps) { - this.runProperties.push(new formatting.Caps()); - } - - if (options.run.strike) { - this.runProperties.push(new formatting.Strike()); - } - - if (options.run.doubleStrike) { - this.runProperties.push(new formatting.DoubleStrike()); - } - - if (options.run.subScript) { - this.runProperties.push(new formatting.SubScript()); - } - - if (options.run.superScript) { - this.runProperties.push(new formatting.SuperScript()); - } - - if (options.run.underline) { - this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color)); - } - - if (options.run.color) { - this.runProperties.push(new formatting.Color(options.run.color)); - } - - if (options.run.font) { - this.runProperties.push(new formatting.RunFonts(options.run.font)); - } - - if (options.run.characterSpacing) { - this.runProperties.push(new formatting.CharacterSpacing(options.run.characterSpacing)); - } - - if (options.run.highlight) { - this.runProperties.push(new formatting.Highlight(options.run.highlight)); - } - - if (options.run.shadow) { - this.runProperties.push(new formatting.Shading(options.run.shadow.type, options.run.shadow.fill, options.run.shadow.color)); - } - } - - if (options.paragraph) { - if (options.paragraph.alignment) { - this.paragraphProperties.push(new Alignment(options.paragraph.alignment)); - } - - if (options.paragraph.thematicBreak) { - this.paragraphProperties.push(new ThematicBreak()); - } - - if (options.paragraph.contextualSpacing) { - this.paragraphProperties.push(new ContextualSpacing(options.paragraph.contextualSpacing)); - } - - if (options.paragraph.rightTabStop) { - this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, options.paragraph.rightTabStop)); - } - - if (options.paragraph.leftTabStop) { - this.paragraphProperties.push(new TabStop(TabStopType.LEFT, options.paragraph.leftTabStop)); - } - - if (options.paragraph.indent) { - this.paragraphProperties.push(new Indent(options.paragraph.indent)); - } - - if (options.paragraph.spacing) { - this.paragraphProperties.push(new Spacing(options.paragraph.spacing)); - } - - if (options.paragraph.keepNext) { - this.paragraphProperties.push(new KeepNext()); - } - - if (options.paragraph.keepLines) { - this.paragraphProperties.push(new KeepLines()); - } - - if (options.paragraph.outlineLevel) { - this.paragraphProperties.push(new OutlineLevel(options.paragraph.outlineLevel)); - } - } } } diff --git a/src/file/styles/styles.ts b/src/file/styles/styles.ts index 064411e419..1906b45ba0 100644 --- a/src/file/styles/styles.ts +++ b/src/file/styles/styles.ts @@ -1,15 +1,16 @@ +import { IDefaultStylesOptions } from "file/styles/factory"; import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components"; - -import { CharacterStyle, ParagraphStyle } from "./style"; +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[]; - readonly importedStyles?: Array; + readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[]; } export class Styles extends XmlComponent { @@ -28,13 +29,13 @@ export class Styles extends XmlComponent { if (options.paragraphStyles) { for (const style of options.paragraphStyles) { - this.root.push(new ParagraphStyle(style)); + this.root.push(new StyleForParagraph(style)); } } if (options.characterStyles) { for (const style of options.characterStyles) { - this.root.push(new CharacterStyle(style)); + this.root.push(new StyleForCharacter(style)); } } } diff --git a/src/file/table/table-cell/table-cell-components.ts b/src/file/table/table-cell/table-cell-components.ts index e16c2f6885..f3ebe570e9 100644 --- a/src/file/table/table-cell/table-cell-components.ts +++ b/src/file/table/table-cell/table-cell-components.ts @@ -158,6 +158,31 @@ export class VAlign extends XmlComponent { } } +export enum TextDirection { + BOTTOM_TO_TOP_LEFT_TO_RIGHT = "btLr", + LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb", + TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl", +} + +class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDirection }> { + protected readonly xmlKeys = { val: "w:val" }; +} + +/** + * Text Direction within a table cell + */ +export class TDirection extends XmlComponent { + constructor(value: TextDirection) { + super("w:textDirection"); + + this.root.push( + new TDirectionAttributes({ + val: value, + }), + ); + } +} + export enum WidthType { /** Auto. */ AUTO = "auto", diff --git a/src/file/table/table-cell/table-cell-properties.ts b/src/file/table/table-cell/table-cell-properties.ts index aed56aaeda..e248290294 100644 --- a/src/file/table/table-cell/table-cell-properties.ts +++ b/src/file/table/table-cell/table-cell-properties.ts @@ -6,6 +6,8 @@ import { GridSpan, TableCellBorders, TableCellWidth, + TDirection, + TextDirection, VAlign, VerticalAlign, VerticalMerge, @@ -61,4 +63,10 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent { return this; } + + public setTextDirection(type: TextDirection): TableCellProperties { + this.root.push(new TDirection(type)); + + return this; + } } diff --git a/src/file/table/table-cell/table-cell.spec.ts b/src/file/table/table-cell/table-cell.spec.ts index a4c316f7ba..2ba34bc9d4 100644 --- a/src/file/table/table-cell/table-cell.spec.ts +++ b/src/file/table/table-cell/table-cell.spec.ts @@ -5,7 +5,7 @@ import { BorderStyle } from "file/styles"; import { ShadingType } from "../shading"; import { TableCell } from "./table-cell"; -import { TableCellBorders, TableCellWidth, VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components"; +import { TableCellBorders, TableCellWidth, TextDirection, VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components"; describe("TableCellBorders", () => { describe("#prepForXml", () => { @@ -271,6 +271,34 @@ describe("TableCell", () => { }); }); + it("should create with text direction", () => { + const cell = new TableCell({ + children: [], + textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT, + }); + + const tree = new Formatter().format(cell); + + expect(tree).to.deep.equal({ + "w:tc": [ + { + "w:tcPr": [ + { + "w:textDirection": { + _attr: { + "w:val": "btLr", + }, + }, + }, + ], + }, + { + "w:p": {}, + }, + ], + }); + }); + it("should create with vertical merge", () => { const cell = new TableCell({ children: [], diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index fe8f8b5868..9c8e8efd58 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -1,19 +1,20 @@ // http://officeopenxml.com/WPtableGrid.php +import { IViewWrapper } from "file/document-wrapper"; import { Paragraph } from "file/paragraph"; import { BorderStyle } from "file/styles"; import { IXmlableObject, XmlComponent } from "file/xml-components"; -import { File } from "../../file"; import { ITableShadingAttributesProperties } from "../shading"; import { Table } from "../table"; import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins"; -import { VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components"; +import { TextDirection, VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components"; import { TableCellProperties } from "./table-cell-properties"; export interface ITableCellOptions { readonly shading?: ITableShadingAttributesProperties; readonly margins?: ITableCellMarginOptions; readonly verticalAlign?: VerticalAlign; + readonly textDirection?: TextDirection; readonly verticalMerge?: VerticalMergeType; readonly width?: { readonly size: number | string; @@ -43,75 +44,68 @@ export interface ITableCellOptions { readonly color: string; }; }; - readonly children: Array; + readonly children: (Paragraph | Table)[]; } export class TableCell extends XmlComponent { - private readonly properties: TableCellProperties; - constructor(readonly options: ITableCellOptions) { super("w:tc"); - this.properties = new TableCellProperties(); - this.root.push(this.properties); + const properties = new TableCellProperties(); + this.root.push(properties); for (const child of options.children) { this.root.push(child); } if (options.verticalAlign) { - this.properties.setVerticalAlign(options.verticalAlign); + properties.setVerticalAlign(options.verticalAlign); + } + + if (options.textDirection) { + properties.setTextDirection(options.textDirection); } if (options.verticalMerge) { - this.properties.addVerticalMerge(options.verticalMerge); + properties.addVerticalMerge(options.verticalMerge); + } else if (options.rowSpan && options.rowSpan > 1) { + // if cell already have a `verticalMerge`, don't handle `rowSpan` + properties.addVerticalMerge(VerticalMergeType.RESTART); } if (options.margins) { - this.properties.addMargins(options.margins); + properties.addMargins(options.margins); } if (options.shading) { - this.properties.setShading(options.shading); + properties.setShading(options.shading); } if (options.columnSpan) { - this.properties.addGridSpan(options.columnSpan); - } - - if (options.rowSpan && options.rowSpan > 1) { - this.properties.addVerticalMerge(VerticalMergeType.RESTART); + properties.addGridSpan(options.columnSpan); } if (options.width) { - this.properties.setWidth(options.width.size, options.width.type); + properties.setWidth(options.width.size, options.width.type); } if (options.borders) { if (options.borders.top) { - this.properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color); + properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color); } if (options.borders.bottom) { - this.properties.Borders.addBottomBorder( - options.borders.bottom.style, - options.borders.bottom.size, - options.borders.bottom.color, - ); + properties.Borders.addBottomBorder(options.borders.bottom.style, options.borders.bottom.size, options.borders.bottom.color); } if (options.borders.left) { - this.properties.Borders.addLeftBorder(options.borders.left.style, options.borders.left.size, options.borders.left.color); + properties.Borders.addLeftBorder(options.borders.left.style, options.borders.left.size, options.borders.left.color); } if (options.borders.right) { - this.properties.Borders.addRightBorder( - options.borders.right.style, - options.borders.right.size, - options.borders.right.color, - ); + properties.Borders.addRightBorder(options.borders.right.style, options.borders.right.size, options.borders.right.color); } } } - public prepForXml(file?: File): IXmlableObject | undefined { + public prepForXml(file?: IViewWrapper): IXmlableObject | undefined { // Cells must end with a paragraph if (!(this.root[this.root.length - 1] instanceof Paragraph)) { this.root.push(new Paragraph({})); diff --git a/src/file/table/table-properties/table-borders.spec.ts b/src/file/table/table-properties/table-borders.spec.ts index 679192f120..4a3212feb1 100644 --- a/src/file/table/table-properties/table-borders.spec.ts +++ b/src/file/table/table-properties/table-borders.spec.ts @@ -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", + }, + }, + }, + ], + }); + }); + }); }); }); diff --git a/src/file/table/table-properties/table-borders.ts b/src/file/table/table-properties/table-borders.ts index 7c7ac96ca9..8de354fc36 100644 --- a/src/file/table/table-properties/table-borders.ts +++ b/src/file/table/table-properties/table-borders.ts @@ -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"); diff --git a/src/file/table/table-properties/table-cell-margin.spec.ts b/src/file/table/table-properties/table-cell-margin.spec.ts index 2a89db7a4a..814888adc0 100644 --- a/src/file/table/table-properties/table-cell-margin.spec.ts +++ b/src/file/table/table-properties/table-cell-margin.spec.ts @@ -8,22 +8,31 @@ import { TableCellMargin } from "./table-cell-margin"; describe("TableCellMargin", () => { describe("#constructor", () => { it("should throw an error if theres no child elements", () => { - const cellMargin = new TableCellMargin(); + const cellMargin = new TableCellMargin({}); expect(() => new Formatter().format(cellMargin)).to.throw(); }); }); describe("#addTopMargin", () => { it("should add a table cell top margin", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addTopMargin(1234, WidthType.DXA); + const cellMargin = new TableCellMargin({ + top: { + value: 1234, + type: WidthType.DXA, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); it("should add a table cell top margin using default width type", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addTopMargin(1234); + const cellMargin = new TableCellMargin({ + top: { + value: 1234, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); @@ -31,15 +40,22 @@ describe("TableCellMargin", () => { describe("#addLeftMargin", () => { it("should add a table cell left margin", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addLeftMargin(1234, WidthType.DXA); + const cellMargin = new TableCellMargin({ + left: { + value: 1234, + type: WidthType.DXA, + }, + }); const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); it("should add a table cell left margin using default width type", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addLeftMargin(1234); + const cellMargin = new TableCellMargin({ + left: { + value: 1234, + }, + }); const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); @@ -47,15 +63,24 @@ describe("TableCellMargin", () => { describe("#addBottomMargin", () => { it("should add a table cell bottom margin", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addBottomMargin(1234, WidthType.DXA); + const cellMargin = new TableCellMargin({ + bottom: { + value: 1234, + type: WidthType.DXA, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); it("should add a table cell bottom margin using default width type", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addBottomMargin(1234); + const cellMargin = new TableCellMargin({ + bottom: { + value: 1234, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); @@ -63,15 +88,24 @@ describe("TableCellMargin", () => { describe("#addRightMargin", () => { it("should add a table cell right margin", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addRightMargin(1234, WidthType.DXA); + const cellMargin = new TableCellMargin({ + right: { + value: 1234, + type: WidthType.DXA, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); it("should add a table cell right margin using default width type", () => { - const cellMargin = new TableCellMargin(); - cellMargin.addRightMargin(1234); + const cellMargin = new TableCellMargin({ + right: { + value: 1234, + }, + }); + const tree = new Formatter().format(cellMargin); expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }); }); diff --git a/src/file/table/table-properties/table-cell-margin.ts b/src/file/table/table-properties/table-cell-margin.ts index ebebb87bc3..9d94e7c84a 100644 --- a/src/file/table/table-properties/table-cell-margin.ts +++ b/src/file/table/table-properties/table-cell-margin.ts @@ -6,47 +6,49 @@ class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: W protected readonly xmlKeys = { value: "w:w", type: "w:type" }; } +interface IBaseTableCellMarginOptions { + readonly value: number; + readonly type?: WidthType; +} + class BaseTableCellMargin extends XmlComponent { - public setProperties(value: number, type: WidthType = WidthType.DXA): void { + constructor(rootKey: string, options: IBaseTableCellMarginOptions) { + super(rootKey); + this.root.push( new TableCellMarginAttributes({ - type: type, - value: value, + type: options.type ?? WidthType.DXA, + value: options.value, }), ); } } +export interface ITableCellMarginOptions { + readonly top?: IBaseTableCellMarginOptions; + readonly bottom?: IBaseTableCellMarginOptions; + readonly left?: IBaseTableCellMarginOptions; + readonly right?: IBaseTableCellMarginOptions; +} + export class TableCellMargin extends IgnoreIfEmptyXmlComponent { - constructor() { + constructor(options: ITableCellMarginOptions) { super("w:tblCellMar"); - } - public addTopMargin(value: number, type: WidthType = WidthType.DXA): void { - const top = new BaseTableCellMargin("w:top"); + if (options.bottom) { + this.root.push(new BaseTableCellMargin("w:bottom", options.bottom)); + } - top.setProperties(value, type); - this.root.push(top); - } + if (options.top) { + this.root.push(new BaseTableCellMargin("w:top", options.top)); + } - public addLeftMargin(value: number, type: WidthType = WidthType.DXA): void { - const left = new BaseTableCellMargin("w:left"); + if (options.left) { + this.root.push(new BaseTableCellMargin("w:left", options.left)); + } - left.setProperties(value, type); - this.root.push(left); - } - - public addBottomMargin(value: number, type: WidthType = WidthType.DXA): void { - const bottom = new BaseTableCellMargin("w:bottom"); - - bottom.setProperties(value, type); - this.root.push(bottom); - } - - public addRightMargin(value: number, type: WidthType = WidthType.DXA): void { - const right = new BaseTableCellMargin("w:right"); - - right.setProperties(value, type); - this.root.push(right); + if (options.right) { + this.root.push(new BaseTableCellMargin("w:right", options.right)); + } } } diff --git a/src/file/table/table-properties/table-properties.spec.ts b/src/file/table/table-properties/table-properties.spec.ts index 1c10e09b6a..a6a9b5879f 100644 --- a/src/file/table/table-properties/table-properties.spec.ts +++ b/src/file/table/table-properties/table-properties.spec.ts @@ -11,7 +11,7 @@ import { TableProperties } from "./table-properties"; describe("TableProperties", () => { describe("#constructor", () => { it("creates an initially empty property object", () => { - const tp = new TableProperties(); + const tp = new TableProperties({}); // The TableProperties is ignorable if there are no attributes, // which results in prepForXml returning undefined, which causes // the formatter to throw an error if that is the only object it @@ -20,9 +20,26 @@ describe("TableProperties", () => { }); }); + describe("#setStyle", () => { + it("should add a table style property", () => { + const tp = new TableProperties({ + style: "TableNormal", + }); + const tree = new Formatter().format(tp); + expect(tree).to.deep.equal({ + "w:tblPr": [{ "w:tblStyle": { _attr: { "w:val": "TableNormal" } } }], + }); + }); + }); + describe("#setWidth", () => { it("should add a table width property", () => { - const tp = new TableProperties().setWidth(1234, WidthType.DXA); + const tp = new TableProperties({ + width: { + size: 1234, + type: WidthType.DXA, + }, + }); const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [{ "w:tblW": { _attr: { "w:type": "dxa", "w:w": 1234 } } }], @@ -30,7 +47,12 @@ describe("TableProperties", () => { }); it("should add a table width property with default of AUTO", () => { - const tp = new TableProperties().setWidth(1234); + const tp = new TableProperties({ + width: { + size: 1234, + }, + }); + const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [{ "w:tblW": { _attr: { "w:type": "auto", "w:w": 1234 } } }], @@ -40,8 +62,10 @@ describe("TableProperties", () => { describe("#setLayout", () => { it("sets the table to fixed width layout", () => { - const tp = new TableProperties(); - tp.setLayout(TableLayoutType.FIXED); + const tp = new TableProperties({ + layout: TableLayoutType.FIXED, + }); + const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [{ "w:tblLayout": { _attr: { "w:type": "fixed" } } }], @@ -51,8 +75,15 @@ describe("TableProperties", () => { describe("#cellMargin", () => { it("adds a table cell top margin", () => { - const tp = new TableProperties(); - tp.CellMargin.addTopMargin(1234, WidthType.DXA); + const tp = new TableProperties({ + cellMargin: { + top: { + value: 1234, + type: WidthType.DXA, + }, + }, + }); + const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [{ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }], @@ -60,8 +91,15 @@ describe("TableProperties", () => { }); it("adds a table cell left margin", () => { - const tp = new TableProperties(); - tp.CellMargin.addLeftMargin(1234, WidthType.DXA); + const tp = new TableProperties({ + cellMargin: { + left: { + value: 1234, + type: WidthType.DXA, + }, + }, + }); + const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [{ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] }], @@ -71,12 +109,14 @@ describe("TableProperties", () => { describe("#setShading", () => { it("sets the shading of the table", () => { - const tp = new TableProperties(); - tp.setShading({ - fill: "b79c2f", - val: ShadingType.REVERSE_DIAGONAL_STRIPE, - color: "auto", + const tp = new TableProperties({ + shading: { + fill: "b79c2f", + val: ShadingType.REVERSE_DIAGONAL_STRIPE, + color: "auto", + }, }); + const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [ @@ -95,9 +135,10 @@ describe("TableProperties", () => { }); describe("#setAlignment", () => { - it("sets the shading of the table", () => { - const tp = new TableProperties(); - tp.setAlignment(AlignmentType.CENTER); + it("sets the alignment of the table", () => { + const tp = new TableProperties({ + alignment: AlignmentType.CENTER, + }); const tree = new Formatter().format(tp); expect(tree).to.deep.equal({ "w:tblPr": [ @@ -112,4 +153,20 @@ describe("TableProperties", () => { }); }); }); + + describe("#Set Virtual Right to Left", () => { + it("sets the alignment of the table", () => { + const tp = new TableProperties({ + visuallyRightToLeft: true, + }); + const tree = new Formatter().format(tp); + expect(tree).to.deep.equal({ + "w:tblPr": [ + { + "w:bidiVisual": {}, + }, + ], + }); + }); + }); }); diff --git a/src/file/table/table-properties/table-properties.ts b/src/file/table/table-properties/table-properties.ts index 8a7d000d5b..67fa8e3f5f 100644 --- a/src/file/table/table-properties/table-properties.ts +++ b/src/file/table/table-properties/table-properties.ts @@ -5,51 +5,64 @@ import { Alignment, AlignmentType } from "../../paragraph"; import { ITableShadingAttributesProperties, TableShading } from "../shading"; import { WidthType } from "../table-cell"; import { ITableBordersOptions, TableBorders } from "./table-borders"; -import { TableCellMargin } from "./table-cell-margin"; +import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin"; import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties"; import { TableLayout, TableLayoutType } from "./table-layout"; +import { TableStyle } from "./table-style"; import { PreferredTableWidth } from "./table-width"; +import { VisuallyRightToLeft } from "./visually-right-to-left"; + +export interface ITablePropertiesOptions { + readonly width?: { + readonly size: number; + readonly type?: WidthType; + }; + readonly layout?: TableLayoutType; + readonly borders?: ITableBordersOptions; + readonly float?: ITableFloatOptions; + readonly shading?: ITableShadingAttributesProperties; + readonly style?: string; + readonly alignment?: AlignmentType; + readonly cellMargin?: ITableCellMarginOptions; + readonly visuallyRightToLeft?: boolean; +} export class TableProperties extends IgnoreIfEmptyXmlComponent { - private readonly cellMargin: TableCellMargin; - - constructor() { + constructor(options: ITablePropertiesOptions) { super("w:tblPr"); - this.cellMargin = new TableCellMargin(); - this.root.push(this.cellMargin); - } + this.root.push(new TableCellMargin(options.cellMargin || {})); - public setWidth(width: number, type: WidthType = WidthType.AUTO): TableProperties { - this.root.push(new PreferredTableWidth(type, width)); - return this; - } + if (options.borders) { + this.root.push(new TableBorders(options.borders)); + } - public setLayout(type: TableLayoutType): void { - this.root.push(new TableLayout(type)); - } + if (options.width) { + this.root.push(new PreferredTableWidth(options.width.type, options.width.size)); + } - public setBorder(borderOptions: ITableBordersOptions): TableProperties { - this.root.push(new TableBorders(borderOptions)); - return this; - } + if (options.float) { + this.root.push(new TableFloatProperties(options.float)); + } - public get CellMargin(): TableCellMargin { - return this.cellMargin; - } + if (options.layout) { + this.root.push(new TableLayout(options.layout)); + } - public setTableFloatProperties(tableFloatOptions: ITableFloatOptions): TableProperties { - this.root.push(new TableFloatProperties(tableFloatOptions)); - return this; - } + if (options.alignment) { + this.root.push(new Alignment(options.alignment)); + } - public setShading(attrs: ITableShadingAttributesProperties): TableProperties { - this.root.push(new TableShading(attrs)); + if (options.shading) { + this.root.push(new TableShading(options.shading)); + } - return this; - } + if (options.visuallyRightToLeft) { + this.root.push(new VisuallyRightToLeft()); + } - public setAlignment(type: AlignmentType): void { - this.root.push(new Alignment(type)); + if (options.style) { + this.root.push(new TableStyle(options.style)); + } } } diff --git a/src/file/table/table-properties/table-style.spec.ts b/src/file/table/table-properties/table-style.spec.ts new file mode 100644 index 0000000000..1b9b0e9748 --- /dev/null +++ b/src/file/table/table-properties/table-style.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { TableStyle } from "./table-style"; + +describe("TableStyle", () => { + describe("#constructor", () => { + it("should create", () => { + const tableStyle = new TableStyle("test-id"); + const tree = new Formatter().format(tableStyle); + + expect(tree).to.deep.equal({ + "w:tblStyle": { + _attr: { + "w:val": "test-id", + }, + }, + }); + }); + }); +}); diff --git a/src/file/table/table-properties/table-style.ts b/src/file/table/table-properties/table-style.ts new file mode 100644 index 0000000000..22b4dc5e89 --- /dev/null +++ b/src/file/table/table-properties/table-style.ts @@ -0,0 +1,13 @@ +import { Attributes, XmlComponent } from "file/xml-components"; + +export class TableStyle extends XmlComponent { + constructor(styleId: string) { + super("w:tblStyle"); + + this.root.push( + new Attributes({ + val: styleId, + }), + ); + } +} diff --git a/src/file/table/table-properties/table-width.ts b/src/file/table/table-properties/table-width.ts index a463e958df..44468c744d 100644 --- a/src/file/table/table-properties/table-width.ts +++ b/src/file/table/table-properties/table-width.ts @@ -13,7 +13,7 @@ class TableWidthAttributes extends XmlAttributeComponent { } export class PreferredTableWidth extends XmlComponent { - constructor(type: WidthType, w: number) { + constructor(type: WidthType = WidthType.AUTO, w: number) { super("w:tblW"); const width: number | string = type === WidthType.PERCENTAGE ? `${w}%` : w; this.root.push(new TableWidthAttributes({ type: type, w: width })); diff --git a/src/file/table/table-properties/visually-right-to-left.spec.ts b/src/file/table/table-properties/visually-right-to-left.spec.ts new file mode 100644 index 0000000000..792c90194b --- /dev/null +++ b/src/file/table/table-properties/visually-right-to-left.spec.ts @@ -0,0 +1,14 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { VisuallyRightToLeft } from "./visually-right-to-left"; + +describe("VisuallyRightToLeft", () => { + it("should create", () => { + const visuallyRightToLeft = new VisuallyRightToLeft(); + const tree = new Formatter().format(visuallyRightToLeft); + expect(tree).to.deep.equal({ + "w:bidiVisual": {}, + }); + }); +}); diff --git a/src/file/table/table-properties/visually-right-to-left.ts b/src/file/table/table-properties/visually-right-to-left.ts new file mode 100644 index 0000000000..c0598a5a26 --- /dev/null +++ b/src/file/table/table-properties/visually-right-to-left.ts @@ -0,0 +1,8 @@ +// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_bidiVisual_topic_ID0EOXIQ.html +import { XmlComponent } from "file/xml-components"; + +export class VisuallyRightToLeft extends XmlComponent { + constructor() { + super("w:bidiVisual"); + } +} diff --git a/src/file/table/table-row/table-row-height.ts b/src/file/table/table-row/table-row-height.ts index 71e2c36aa1..79e4266201 100644 --- a/src/file/table/table-row/table-row-height.ts +++ b/src/file/table/table-row/table-row-height.ts @@ -10,12 +10,12 @@ export enum HeightRule { } interface ITableRowHeight { - readonly height: number; + readonly value: number; readonly rule: HeightRule; } export class TableRowHeightAttributes extends XmlAttributeComponent { - protected readonly xmlKeys = { height: "w:val", rule: "w:hRule" }; + protected readonly xmlKeys = { value: "w:val", rule: "w:hRule" }; } export class TableRowHeight extends XmlComponent { @@ -24,7 +24,7 @@ export class TableRowHeight extends XmlComponent { this.root.push( new TableRowHeightAttributes({ - height: value, + value: value, rule: rule, }), ); diff --git a/src/file/table/table-row/table-row-properties.ts b/src/file/table/table-row/table-row-properties.ts index c9b60c13f4..1b4c9784cd 100644 --- a/src/file/table/table-row/table-row-properties.ts +++ b/src/file/table/table-row/table-row-properties.ts @@ -1,6 +1,8 @@ -import { HeightRule, TableRowHeight } from "file/table/table-row/table-row-height"; +// http://officeopenxml.com/WPtableRowProperties.php import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components"; +import { HeightRule, TableRowHeight } from "./table-row-height"; + export class TableRowProperties extends IgnoreIfEmptyXmlComponent { constructor() { super("w:trPr"); @@ -18,8 +20,8 @@ export class TableRowProperties extends IgnoreIfEmptyXmlComponent { return this; } - public setHeight(height: number, rule: HeightRule): TableRowProperties { - this.root.push(new TableRowHeight(height, rule)); + public setHeight(value: number, rule: HeightRule): TableRowProperties { + this.root.push(new TableRowHeight(value, rule)); return this; } diff --git a/src/file/table/table-row/table-row.spec.ts b/src/file/table/table-row/table-row.spec.ts index e013153cd8..16a08e10ae 100644 --- a/src/file/table/table-row/table-row.spec.ts +++ b/src/file/table/table-row/table-row.spec.ts @@ -92,7 +92,7 @@ describe("TableRow", () => { const tableRow = new TableRow({ children: [], height: { - height: 100, + value: 100, rule: HeightRule.EXACT, }, }); @@ -182,4 +182,97 @@ describe("TableRow", () => { }); }); }); + + describe("#rootIndexToColumnIndex", () => { + it("should get the correct virtual column index by root index", () => { + const tableRow = new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + ], + }); + + expect(tableRow.rootIndexToColumnIndex(1)).to.equal(0); + expect(tableRow.rootIndexToColumnIndex(2)).to.equal(3); + expect(tableRow.rootIndexToColumnIndex(3)).to.equal(4); + expect(tableRow.rootIndexToColumnIndex(4)).to.equal(5); + + expect(() => tableRow.rootIndexToColumnIndex(0)).to.throw(`cell 'rootIndex' should between 1 to 4`); + expect(() => tableRow.rootIndexToColumnIndex(5)).to.throw(`cell 'rootIndex' should between 1 to 4`); + }); + }); + + describe("#columnIndexToRootIndex", () => { + it("should get the correct root index by virtual column index", () => { + const tableRow = new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + ], + }); + + expect(tableRow.columnIndexToRootIndex(0)).to.equal(1); + expect(tableRow.columnIndexToRootIndex(1)).to.equal(1); + expect(tableRow.columnIndexToRootIndex(2)).to.equal(1); + + expect(tableRow.columnIndexToRootIndex(3)).to.equal(2); + expect(tableRow.columnIndexToRootIndex(4)).to.equal(3); + + expect(tableRow.columnIndexToRootIndex(5)).to.equal(4); + expect(tableRow.columnIndexToRootIndex(6)).to.equal(4); + expect(tableRow.columnIndexToRootIndex(7)).to.equal(4); + + expect(() => tableRow.columnIndexToRootIndex(-1)).to.throw(`cell 'columnIndex' should not less than zero`); + expect(() => tableRow.columnIndexToRootIndex(8)).to.throw(`cell 'columnIndex' should not great than 7`); + }); + + it("should allow end new cell index", () => { + const tableRow = new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + }), + new TableCell({ + children: [new Paragraph("test")], + columnSpan: 3, + }), + ], + }); + + expect(tableRow.columnIndexToRootIndex(8, true)).to.equal(5); + // for column 10, just place the new cell at the end of row + expect(tableRow.columnIndexToRootIndex(10, true)).to.equal(5); + }); + }); }); diff --git a/src/file/table/table-row/table-row.ts b/src/file/table/table-row/table-row.ts index 466b7eb320..92a8614511 100644 --- a/src/file/table/table-row/table-row.ts +++ b/src/file/table/table-row/table-row.ts @@ -7,7 +7,7 @@ export interface ITableRowOptions { readonly cantSplit?: boolean; readonly tableHeader?: boolean; readonly height?: { - readonly height: number; + readonly value: number; readonly rule: HeightRule; }; readonly children: TableCell[]; @@ -34,7 +34,7 @@ export class TableRow extends XmlComponent { } if (options.height) { - this.properties.setHeight(options.height.height, options.height.rule); + this.properties.setHeight(options.height.value, options.height.rule); } } @@ -42,12 +42,56 @@ export class TableRow extends XmlComponent { return this.options.children.length; } - public get Children(): TableCell[] { - return this.options.children; + public get cells(): TableCell[] { + return this.root.filter((xmlComponent) => xmlComponent instanceof TableCell); } public addCellToIndex(cell: TableCell, index: number): void { // Offset because properties is also in root. this.root.splice(index + 1, 0, cell); } + + public addCellToColumnIndex(cell: TableCell, columnIndex: number): void { + const rootIndex = this.columnIndexToRootIndex(columnIndex, true); + this.addCellToIndex(cell, rootIndex - 1); + } + + public rootIndexToColumnIndex(rootIndex: number): number { + // convert the root index to the virtual column index + if (rootIndex < 1 || rootIndex >= this.root.length) { + throw new Error(`cell 'rootIndex' should between 1 to ${this.root.length - 1}`); + } + let colIdx = 0; + // Offset because properties is also in root. + for (let rootIdx = 1; rootIdx < rootIndex; rootIdx++) { + const cell = this.root[rootIdx] as TableCell; + colIdx += cell.options.columnSpan || 1; + } + return colIdx; + } + + public columnIndexToRootIndex(columnIndex: number, allowEndNewCell: boolean = false): number { + // convert the virtual column index to the root index + // `allowEndNewCell` for get index to inert new cell + if (columnIndex < 0) { + throw new Error(`cell 'columnIndex' should not less than zero`); + } + let colIdx = 0; + // Offset because properties is also in root. + let rootIdx = 1; + while (colIdx <= columnIndex) { + if (rootIdx >= this.root.length) { + if (allowEndNewCell) { + // for inserting verticalMerge CONTINUE cell at end of row + return this.root.length; + } else { + throw new Error(`cell 'columnIndex' should not great than ${colIdx - 1}`); + } + } + const cell = this.root[rootIdx] as TableCell; + rootIdx += 1; + colIdx += (cell && cell.options.columnSpan) || 1; + } + return rootIdx - 1; + } } diff --git a/src/file/table/table.spec.ts b/src/file/table/table.spec.ts index d2098fb1e4..3165330047 100644 --- a/src/file/table/table.spec.ts +++ b/src/file/table/table.spec.ts @@ -188,6 +188,72 @@ describe("Table", () => { }); }); + it("creates a table with the correct columnSpan and rowSpan", () => { + const table = new Table({ + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("hello")], + columnSpan: 2, + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("hello")], + rowSpan: 2, + }), + new TableCell({ + children: [new Paragraph("hello")], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("hello")], + }), + ], + }), + ], + }); + const tree = new Formatter().format(table); + const cellP = { "w:p": [{ "w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "hello"] }] }] }; + expect(tree).to.deep.equal({ + "w:tbl": [ + { "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] }, + { + "w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }], + }, + { + "w:tr": [ + { + "w:tc": [{ "w:tcPr": [{ "w:gridSpan": { _attr: { "w:val": 2 } } }] }, cellP], + }, + ], + }, + { + "w:tr": [ + { + "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "restart" } } }] }, cellP], + }, + { "w:tc": [cellP] }, + ], + }, + { + "w:tr": [ + { + "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": {} }], + }, + { "w:tc": [cellP] }, + ], + }, + ], + }); + }); + it("sets the table to fixed width layout", () => { const table = new Table({ rows: [ @@ -202,10 +268,7 @@ describe("Table", () => { layout: TableLayoutType.FIXED, }); const tree = new Formatter().format(table); - expect(tree) - .to.have.property("w:tbl") - .which.is.an("array") - .with.has.length.at.least(1); + expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }], }); @@ -225,10 +288,7 @@ describe("Table", () => { alignment: AlignmentType.CENTER, }); const tree = new Formatter().format(table); - expect(tree) - .to.have.property("w:tbl") - .which.is.an("array") - .with.has.length.at.least(1); + expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:jc": { _attr: { "w:val": "center" } } }], }); @@ -252,10 +312,7 @@ describe("Table", () => { layout: TableLayoutType.FIXED, }); const tree = new Formatter().format(table); - expect(tree) - .to.have.property("w:tbl") - .which.is.an("array") - .with.has.length.at.least(1); + expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ "w:tblPr": [ DEFAULT_TABLE_PROPERTIES, @@ -289,14 +346,10 @@ describe("Table", () => { ], }); const tree = new Formatter().format(table); - expect(tree) - .to.have.property("w:tbl") - .which.is.an("array"); + expect(tree).to.have.property("w:tbl").which.is.an("array"); const row = tree["w:tbl"].find((x) => x["w:tr"]); expect(row).not.to.be.undefined; - expect(row["w:tr"]) - .to.be.an("array") - .which.has.length.at.least(1); + expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ "w:tc": [ { @@ -421,10 +474,7 @@ describe("Table", () => { }, }); const tree = new Formatter().format(table); - expect(tree) - .to.have.property("w:tbl") - .which.is.an("array") - .with.has.length.at.least(1); + expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree["w:tbl"][0]).to.deep.equal({ "w:tblPr": [ DEFAULT_TABLE_PROPERTIES, diff --git a/src/file/table/table.ts b/src/file/table/table.ts index a0e6dab88f..ea4acd93d5 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -34,13 +34,13 @@ export interface ITableOptions { }; readonly float?: ITableFloatOptions; readonly layout?: TableLayoutType; + readonly style?: string; readonly borders?: ITableBordersOptions; readonly alignment?: AlignmentType; + readonly visuallyRightToLeft?: boolean; } export class Table extends XmlComponent { - private readonly properties: TableProperties; - constructor({ rows, width, @@ -48,29 +48,42 @@ export class Table extends XmlComponent { margins: { marginUnitType, top, bottom, right, left } = { marginUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 }, float, layout, + style, borders, alignment, + visuallyRightToLeft, }: ITableOptions) { super("w:tbl"); - this.properties = new TableProperties(); - this.root.push(this.properties); - if (borders) { - this.properties.setBorder(borders); - } else { - this.properties.setBorder({}); - } - - if (width) { - this.properties.setWidth(width.size, width.type); - } else { - this.properties.setWidth(100); - } - - this.properties.CellMargin.addBottomMargin(bottom || 0, marginUnitType); - this.properties.CellMargin.addTopMargin(top || 0, marginUnitType); - this.properties.CellMargin.addLeftMargin(left || 0, marginUnitType); - this.properties.CellMargin.addRightMargin(right || 0, marginUnitType); + this.root.push( + new TableProperties({ + borders: borders ?? {}, + width: width ?? { size: 100 }, + float, + layout, + style, + alignment, + cellMargin: { + bottom: { + value: bottom || 0, + type: marginUnitType, + }, + top: { + value: top || 0, + type: marginUnitType, + }, + left: { + value: left || 0, + type: marginUnitType, + }, + right: { + value: right || 0, + type: marginUnitType, + }, + }, + visuallyRightToLeft, + }), + ); this.root.push(new TableGrid(columnWidths)); @@ -78,38 +91,28 @@ export class Table extends XmlComponent { this.root.push(row); } - for (const row of rows) { - row.Children.forEach((cell, cellIndex) => { - const column = rows.map((r) => r.Children[cellIndex]); + rows.forEach((row, rowIndex) => { + if (rowIndex === rows.length - 1) { + // don't process the end row + return; + } + let columnIndex = 0; + row.cells.forEach((cell) => { // Row Span has to be added in this method and not the constructor because it needs to know information about the column which happens after Table Cell construction // Row Span of 1 will crash word as it will add RESTART and not a corresponding CONTINUE if (cell.options.rowSpan && cell.options.rowSpan > 1) { - const thisCellsColumnIndex = column.indexOf(cell); - const endColumnIndex = thisCellsColumnIndex + (cell.options.rowSpan - 1); - - for (let i = thisCellsColumnIndex + 1; i <= endColumnIndex; i++) { - rows[i].addCellToIndex( - new TableCell({ - children: [], - verticalMerge: VerticalMergeType.CONTINUE, - }), - i, - ); - } + const continueCell = new TableCell({ + // the inserted CONTINUE cell has rowSpan, and will be handled when process the next row + rowSpan: cell.options.rowSpan - 1, + columnSpan: cell.options.columnSpan, + borders: cell.options.borders, + children: [], + verticalMerge: VerticalMergeType.CONTINUE, + }); + rows[rowIndex + 1].addCellToColumnIndex(continueCell, columnIndex); } + columnIndex += cell.options.columnSpan || 1; }); - } - - if (float) { - this.properties.setTableFloatProperties(float); - } - - if (layout) { - this.properties.setLayout(layout); - } - - if (alignment) { - this.properties.setAlignment(alignment); - } + }); } } diff --git a/src/file/track-revision/index.ts b/src/file/track-revision/index.ts new file mode 100644 index 0000000000..eb2465d8fe --- /dev/null +++ b/src/file/track-revision/index.ts @@ -0,0 +1,2 @@ +export * from "./track-revision-components/inserted-text-run"; +export * from "./track-revision-components/deleted-text-run"; diff --git a/src/file/track-revision/track-revision-components/deleted-page-number.spec.ts b/src/file/track-revision/track-revision-components/deleted-page-number.spec.ts new file mode 100644 index 0000000000..5e0238da96 --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-page-number.spec.ts @@ -0,0 +1,30 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number"; + +describe("Deleted Page", () => { + describe("#constructor()", () => { + it("uses the font name for both ascii and hAnsi", () => { + const tree = new Formatter().format(new DeletedPage()); + expect(tree).to.deep.equal({ "w:delInstrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] }); + }); + }); +}); + +describe("Delted NumberOfPages", () => { + describe("#constructor()", () => { + it("uses the font name for both ascii and hAnsi", () => { + const tree = new Formatter().format(new DeletedNumberOfPages()); + expect(tree).to.deep.equal({ "w:delInstrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] }); + }); + }); +}); + +describe("Deleted NumberOfPagesSection", () => { + describe("#constructor()", () => { + it("uses the font name for both ascii and hAnsi", () => { + const tree = new Formatter().format(new DeletedNumberOfPagesSection()); + expect(tree).to.deep.equal({ "w:delInstrText": [{ _attr: { "xml:space": "preserve" } }, "SECTIONPAGES"] }); + }); + }); +}); diff --git a/src/file/track-revision/track-revision-components/deleted-page-number.ts b/src/file/track-revision/track-revision-components/deleted-page-number.ts new file mode 100644 index 0000000000..6ce6266f13 --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-page-number.ts @@ -0,0 +1,30 @@ +import { SpaceType } from "file/space-type"; +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; +} + +export class DeletedPage extends XmlComponent { + constructor() { + super("w:delInstrText"); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); + this.root.push("PAGE"); + } +} + +export class DeletedNumberOfPages extends XmlComponent { + constructor() { + super("w:delInstrText"); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); + this.root.push("NUMPAGES"); + } +} + +export class DeletedNumberOfPagesSection extends XmlComponent { + constructor() { + super("w:delInstrText"); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); + this.root.push("SECTIONPAGES"); + } +} diff --git a/src/file/track-revision/track-revision-components/deleted-text-run.spec.ts b/src/file/track-revision/track-revision-components/deleted-text-run.spec.ts new file mode 100644 index 0000000000..6bd11c24d7 --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-text-run.spec.ts @@ -0,0 +1,372 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { FootnoteReferenceRun, PageNumber } from "../../index"; +import { DeletedTextRun } from "./deleted-text-run"; + +describe("DeletedTextRun", () => { + describe("#constructor", () => { + it("should create a deleted text run", () => { + const deletedTextRun = new DeletedTextRun({ text: "some text", id: 0, date: "123", author: "Author" }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "some text", + ], + }, + ], + }, + ], + }); + }); + }); + + describe("#constructor with formatting", () => { + it("should create a deleted text run", () => { + const deletedTextRun = new DeletedTextRun({ text: "some text", bold: true, id: 0, date: "123", author: "Author" }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:rPr": [ + { + "w:b": { + _attr: { + "w:val": true, + }, + }, + }, + { + "w:bCs": { + _attr: { + "w:val": true, + }, + }, + }, + ], + }, + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "some text", + ], + }, + ], + }, + ], + }); + }); + }); + + describe("#break()", () => { + it("should add a break", () => { + const deletedTextRun = new DeletedTextRun({ + break: 1, + children: ["some text"], + id: 0, + date: "123", + author: "Author", + }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:br": {}, + }, + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "some text", + ], + }, + ], + }, + ], + }); + }); + }); + + describe("page numbering", () => { + it("should be able to delete the total pages", () => { + const deletedTextRun = new DeletedTextRun({ + children: [" to ", PageNumber.TOTAL_PAGES], + id: 0, + date: "123", + author: "Author", + }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + " to ", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "begin", + }, + }, + }, + { + "w:delInstrText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "NUMPAGES", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "separate", + }, + }, + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "end", + }, + }, + }, + ], + }, + ], + }); + }); + + it("should be able to delete the total pages in section", () => { + const deletedTextRun = new DeletedTextRun({ + children: [" to ", PageNumber.TOTAL_PAGES_IN_SECTION], + id: 0, + date: "123", + author: "Author", + }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + " to ", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "begin", + }, + }, + }, + { + "w:delInstrText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "SECTIONPAGES", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "separate", + }, + }, + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "end", + }, + }, + }, + ], + }, + ], + }); + }); + + it("should be able to delete the current page", () => { + const deletedTextRun = new DeletedTextRun({ + children: [" to ", PageNumber.CURRENT], + id: 0, + date: "123", + author: "Author", + }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + " to ", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "begin", + }, + }, + }, + { + "w:delInstrText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "PAGE", + ], + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "separate", + }, + }, + }, + { + "w:fldChar": { + _attr: { + "w:fldCharType": "end", + }, + }, + }, + ], + }, + ], + }); + }); + }); + + describe("footnote references", () => { + it("should add a valid footnote reference", () => { + const deletedTextRun = new DeletedTextRun({ + children: ["some text", new FootnoteReferenceRun(1)], + id: 0, + date: "123", + author: "Author", + }); + const tree = new Formatter().format(deletedTextRun); + expect(tree).to.deep.equal({ + "w:del": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:delText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "some text", + ], + }, + { + "w:r": [ + { "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "FootnoteReference" } } }] }, + { "w:footnoteReference": { _attr: { "w:id": 1 } } }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/track-revision/track-revision-components/deleted-text-run.ts b/src/file/track-revision/track-revision-components/deleted-text-run.ts new file mode 100644 index 0000000000..7830d3d63c --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-text-run.ts @@ -0,0 +1,76 @@ +import { XmlComponent } from "file/xml-components"; + +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"; +import { ChangeAttributes, IChangedAttributesProperties } from "../track-revision"; +import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number"; +import { DeletedText } from "./deleted-text"; + +interface IDeletedRunOptions extends IRunOptions, IChangedAttributesProperties {} + +export class DeletedTextRun extends XmlComponent { + protected readonly deletedTextRunWrapper: DeletedTextRunWrapper; + + constructor(options: IDeletedRunOptions) { + super("w:del"); + this.root.push( + new ChangeAttributes({ + id: options.id, + author: options.author, + date: options.date, + }), + ); + this.deletedTextRunWrapper = new DeletedTextRunWrapper(options); + this.addChildElement(this.deletedTextRunWrapper); + } +} + +class DeletedTextRunWrapper extends XmlComponent { + constructor(options: IRunOptions) { + super("w:r"); + this.root.push(new RunProperties(options)); + + if (options.children) { + for (const child of options.children) { + if (typeof child === "string") { + switch (child) { + case PageNumber.CURRENT: + this.root.push(new Begin()); + this.root.push(new DeletedPage()); + this.root.push(new Separate()); + this.root.push(new End()); + break; + case PageNumber.TOTAL_PAGES: + this.root.push(new Begin()); + this.root.push(new DeletedNumberOfPages()); + this.root.push(new Separate()); + this.root.push(new End()); + break; + case PageNumber.TOTAL_PAGES_IN_SECTION: + this.root.push(new Begin()); + this.root.push(new DeletedNumberOfPagesSection()); + this.root.push(new Separate()); + this.root.push(new End()); + break; + default: + this.root.push(new DeletedText(child)); + break; + } + continue; + } + + this.root.push(child); + } + } else if (options.text) { + this.root.push(new DeletedText(options.text)); + } + + if (options.break) { + for (let i = 0; i < options.break; i++) { + this.root.splice(1, 0, new Break()); + } + } + } +} diff --git a/src/file/track-revision/track-revision-components/deleted-text.spec.ts b/src/file/track-revision/track-revision-components/deleted-text.spec.ts new file mode 100644 index 0000000000..d9c8de46bf --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-text.spec.ts @@ -0,0 +1,15 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { DeletedText } from "./deleted-text"; + +describe("Deleted Text", () => { + describe("#constructor", () => { + it("adds the passed in text to the component", () => { + const t = new DeletedText(" this is\n text"); + const f = new Formatter().format(t); + expect(f).to.deep.equal({ + "w:delText": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"], + }); + }); + }); +}); diff --git a/src/file/track-revision/track-revision-components/deleted-text.ts b/src/file/track-revision/track-revision-components/deleted-text.ts new file mode 100644 index 0000000000..408b47304d --- /dev/null +++ b/src/file/track-revision/track-revision-components/deleted-text.ts @@ -0,0 +1,15 @@ +import { SpaceType } from "file/space-type"; +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; +} + +export class DeletedText extends XmlComponent { + constructor(text: string) { + super("w:delText"); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); + + this.root.push(text); + } +} diff --git a/src/file/track-revision/track-revision-components/inserted-text-run.spec.ts b/src/file/track-revision/track-revision-components/inserted-text-run.spec.ts new file mode 100644 index 0000000000..c23069fbba --- /dev/null +++ b/src/file/track-revision/track-revision-components/inserted-text-run.spec.ts @@ -0,0 +1,37 @@ +import { expect } from "chai"; +import { Formatter } from "export/formatter"; +import { InsertedTextRun } from "./inserted-text-run"; + +describe("InsertedTextRun", () => { + describe("#constructor", () => { + it("should create a inserted text run", () => { + const insertedTextRun = new InsertedTextRun({ text: "some text", id: 0, date: "123", author: "Author" }); + const tree = new Formatter().format(insertedTextRun); + expect(tree).to.deep.equal({ + "w:ins": [ + { + _attr: { + "w:author": "Author", + "w:date": "123", + "w:id": 0, + }, + }, + { + "w:r": [ + { + "w:t": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + "some text", + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/track-revision/track-revision-components/inserted-text-run.ts b/src/file/track-revision/track-revision-components/inserted-text-run.ts new file mode 100644 index 0000000000..3d39e92c1c --- /dev/null +++ b/src/file/track-revision/track-revision-components/inserted-text-run.ts @@ -0,0 +1,20 @@ +import { XmlComponent } from "file/xml-components"; + +import { IRunOptions, TextRun } from "../../index"; +import { ChangeAttributes, IChangedAttributesProperties } from "../track-revision"; + +interface IInsertedRunOptions extends IChangedAttributesProperties, IRunOptions {} + +export class InsertedTextRun extends XmlComponent { + constructor(options: IInsertedRunOptions) { + super("w:ins"); + this.root.push( + new ChangeAttributes({ + id: options.id, + author: options.author, + date: options.date, + }), + ); + this.addChildElement(new TextRun(options as IRunOptions)); + } +} diff --git a/src/file/track-revision/track-revision.ts b/src/file/track-revision/track-revision.ts new file mode 100644 index 0000000000..4318e9a468 --- /dev/null +++ b/src/file/track-revision/track-revision.ts @@ -0,0 +1,15 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export interface IChangedAttributesProperties { + readonly id: number; + readonly author: string; + readonly date: string; +} + +export class ChangeAttributes extends XmlAttributeComponent { + protected readonly xmlKeys = { + id: "w:id", + author: "w:author", + date: "w:date", + }; +} diff --git a/src/file/xml-components/base.ts b/src/file/xml-components/base.ts index 782dfdba12..4bb37c8ad9 100644 --- a/src/file/xml-components/base.ts +++ b/src/file/xml-components/base.ts @@ -1,4 +1,4 @@ -import { File } from "../file"; +import { IViewWrapper } from "../document-wrapper"; import { IXmlableObject } from "./xmlable-object"; export abstract class BaseXmlComponent { @@ -10,7 +10,7 @@ export abstract class BaseXmlComponent { this.rootKey = rootKey; } - public abstract prepForXml(file?: File): IXmlableObject | undefined; + public abstract prepForXml(file?: IViewWrapper): IXmlableObject | undefined; public get IsDeleted(): boolean { return this.deleted; diff --git a/src/file/xml-components/xml-component.ts b/src/file/xml-components/xml-component.ts index dfe3800b96..84fd5f98e4 100644 --- a/src/file/xml-components/xml-component.ts +++ b/src/file/xml-components/xml-component.ts @@ -1,4 +1,4 @@ -import { File } from "../file"; +import { IViewWrapper } from "../document-wrapper"; import { BaseXmlComponent } from "./base"; import { IXmlableObject } from "./xmlable-object"; @@ -6,14 +6,14 @@ export const EMPTY_OBJECT = Object.seal({}); export abstract class XmlComponent extends BaseXmlComponent { // tslint:disable-next-line:readonly-keyword no-any - protected root: Array; + protected root: (BaseXmlComponent | string | any)[]; constructor(rootKey: string) { super(rootKey); this.root = new Array(); } - public prepForXml(file?: File): IXmlableObject | undefined { + public prepForXml(file?: IViewWrapper): IXmlableObject | undefined { const children = this.root .filter((c) => { if (c instanceof BaseXmlComponent) { diff --git a/src/import-dotx/import-dotx.ts b/src/import-dotx/import-dotx.ts index 2b1261efe7..4c77ea75be 100644 --- a/src/import-dotx/import-dotx.ts +++ b/src/import-dotx/import-dotx.ts @@ -17,8 +17,8 @@ const schemeToType = { }; interface IDocumentRefs { - readonly headers: Array<{ readonly id: number; readonly type: HeaderReferenceType }>; - readonly footers: Array<{ readonly id: number; readonly type: FooterReferenceType }>; + readonly headers: { readonly id: number; readonly type: HeaderReferenceType }[]; + readonly footers: { readonly id: number; readonly type: FooterReferenceType }[]; } enum RelationshipType { @@ -46,7 +46,9 @@ export interface IDocumentTemplate { } export class ImportDotx { - public async extract(data: Buffer): Promise { + public async extract( + data: Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream, + ): Promise { const zipContent = await JSZip.loadAsync(data); const documentContent = await zipContent.files["word/document.xml"].async("text"); @@ -99,7 +101,7 @@ export class ImportDotx { return { type: reference.type, footer: wrapper }; }) - .filter((x) => !!x) as Array>; + .filter((x) => !!x) as Promise[]; return Promise.all(result); } @@ -134,7 +136,7 @@ export class ImportDotx { return { type: reference.type, header: wrapper }; }) - .filter((x) => !!x) as Array>; + .filter((x) => !!x) as Promise[]; return Promise.all(result); } diff --git a/src/index.ts b/src/index.ts index 1e35c87d30..a319e4dcfe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,3 +4,4 @@ export { File as Document } from "./file"; export * from "./file"; export * from "./export"; export * from "./import-dotx"; +export * from "./convenience-functions"; diff --git a/tslint.json b/tslint.json index d6eb606eba..cb979f920a 100644 --- a/tslint.json +++ b/tslint.json @@ -21,6 +21,8 @@ "no-duplicate-imports": true, "unnecessary-constructor": true, "file-name-casing": [true, "kebab-case"], + "interface-name": [true, "always-prefix"], + "ordered-imports": true, // Functional Programming Rules "no-parameter-reassignment": true, "readonly-keyword": true,