From 45130bed0b45390a4637764f4579bb3d222fa087 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 00:36:35 +0300 Subject: [PATCH 01/10] Fix conformance issues with imagerun - out of order properties (a:xfrm), invalid attr name (pic:cNvPr) desc -> descr --- src/file/drawing/drawing.spec.ts | 36 +++++----- .../non-visual-properties-attributes.ts | 2 +- .../pic/shape-properties/form.spec.ts | 32 ++++----- .../pic/shape-properties/form/form.ts | 2 +- src/file/paragraph/run/image-run.spec.ts | 72 +++++++++---------- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/file/drawing/drawing.spec.ts b/src/file/drawing/drawing.spec.ts index b97b6ea11e..52c76c791f 100644 --- a/src/file/drawing/drawing.spec.ts +++ b/src/file/drawing/drawing.spec.ts @@ -111,7 +111,7 @@ describe("Drawing", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -166,14 +166,6 @@ describe("Drawing", () => { { _attr: {}, }, - { - "a:ext": { - _attr: { - cx: 952500, - cy: 952500, - }, - }, - }, { "a:off": { _attr: { @@ -182,6 +174,14 @@ describe("Drawing", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 952500, + cy: 952500, + }, + }, + }, ], }, { @@ -341,7 +341,7 @@ describe("Drawing", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -396,14 +396,6 @@ describe("Drawing", () => { { _attr: {}, }, - { - "a:ext": { - _attr: { - cx: 952500, - cy: 952500, - }, - }, - }, { "a:off": { _attr: { @@ -412,6 +404,14 @@ describe("Drawing", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 952500, + cy: 952500, + }, + }, + }, ], }, { diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts index cac3312dde..8d8951c12c 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts @@ -8,6 +8,6 @@ export class NonVisualPropertiesAttributes extends XmlAttributeComponent<{ protected readonly xmlKeys = { id: "id", name: "name", - descr: "desc", + descr: "descr", }; } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form.spec.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form.spec.ts index 3d46b1875a..3cf724d656 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form.spec.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form.spec.ts @@ -24,14 +24,6 @@ describe("Form", () => { { _attr: {}, }, - { - "a:ext": { - _attr: { - cx: 100, - cy: 100, - }, - }, - }, { "a:off": { _attr: { @@ -40,6 +32,14 @@ describe("Form", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 100, + cy: 100, + }, + }, + }, ], }); }); @@ -70,14 +70,6 @@ describe("Form", () => { flipV: true, }, }, - { - "a:ext": { - _attr: { - cx: 100, - cy: 100, - }, - }, - }, { "a:off": { _attr: { @@ -86,6 +78,14 @@ describe("Form", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 100, + cy: 100, + }, + }, + }, ], }); }); diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts index 5311b83911..163af208d6 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/form.ts @@ -34,8 +34,8 @@ export class Form extends XmlComponent { this.extents = new Extents(options.emus.x, options.emus.y); - this.root.push(this.extents); this.root.push(new Offset()); + this.root.push(this.extents); } public setXY(x: number, y: number): void { diff --git a/src/file/paragraph/run/image-run.spec.ts b/src/file/paragraph/run/image-run.spec.ts index a5572f48a9..de36455840 100644 --- a/src/file/paragraph/run/image-run.spec.ts +++ b/src/file/paragraph/run/image-run.spec.ts @@ -168,7 +168,7 @@ describe("ImageRun", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -224,14 +224,6 @@ describe("ImageRun", () => { rot: 2700000, }, }, - { - "a:ext": { - _attr: { - cx: 1905000, - cy: 1905000, - }, - }, - }, { "a:off": { _attr: { @@ -240,6 +232,14 @@ describe("ImageRun", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 1905000, + cy: 1905000, + }, + }, + }, ], }, { @@ -418,7 +418,7 @@ describe("ImageRun", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -474,14 +474,6 @@ describe("ImageRun", () => { rot: 2700000, }, }, - { - "a:ext": { - _attr: { - cx: 1905000, - cy: 1905000, - }, - }, - }, { "a:off": { _attr: { @@ -490,6 +482,14 @@ describe("ImageRun", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 1905000, + cy: 1905000, + }, + }, + }, ], }, { @@ -671,7 +671,7 @@ describe("ImageRun", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -727,14 +727,6 @@ describe("ImageRun", () => { rot: 2700000, }, }, - { - "a:ext": { - _attr: { - cx: 1905000, - cy: 1905000, - }, - }, - }, { "a:off": { _attr: { @@ -743,6 +735,14 @@ describe("ImageRun", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 1905000, + cy: 1905000, + }, + }, + }, ], }, { @@ -927,7 +927,7 @@ describe("ImageRun", () => { { "pic:cNvPr": { _attr: { - desc: "", + descr: "", id: 0, name: "", }, @@ -983,14 +983,6 @@ describe("ImageRun", () => { rot: 2700000, }, }, - { - "a:ext": { - _attr: { - cx: 1905000, - cy: 1905000, - }, - }, - }, { "a:off": { _attr: { @@ -999,6 +991,14 @@ describe("ImageRun", () => { }, }, }, + { + "a:ext": { + _attr: { + cx: 1905000, + cy: 1905000, + }, + }, + }, ], }, { From d0a675fde62fb948b56c65af875b5364b7da3074 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 01:03:09 +0300 Subject: [PATCH 02/10] Fix ordering of elements in table, table-cell, table-properties, table-cell-properties, table-cell-margin --- .../cell-margin/table-cell-margins.spec.ts | 32 +++++++-------- .../cell-margin/table-cell-margins.ts | 2 +- .../table-cell/table-cell-properties.spec.ts | 16 ++++---- .../table/table-cell/table-cell-properties.ts | 7 +++- src/file/table/table-cell/table-cell.spec.ts | 16 ++++---- src/file/table/table-cell/table-cell.ts | 41 ++++++++++--------- .../table-properties/table-cell-margin.ts | 8 ++-- .../table-properties/table-properties.ts | 26 ++++++------ src/file/table/table.spec.ts | 34 +++++++-------- 9 files changed, 94 insertions(+), 88 deletions(-) diff --git a/src/file/table/table-cell/cell-margin/table-cell-margins.spec.ts b/src/file/table/table-cell/cell-margin/table-cell-margins.spec.ts index dc4a0a9ab9..8777ec5a9b 100644 --- a/src/file/table/table-cell/cell-margin/table-cell-margins.spec.ts +++ b/src/file/table/table-cell/cell-margin/table-cell-margins.spec.ts @@ -19,6 +19,14 @@ describe("TableCellMargin", () => { }, }, }, + { + "w:start": { + _attr: { + "w:type": "dxa", + "w:w": 0, + }, + }, + }, { "w:bottom": { _attr: { @@ -35,14 +43,6 @@ describe("TableCellMargin", () => { }, }, }, - { - "w:start": { - _attr: { - "w:type": "dxa", - "w:w": 0, - }, - }, - }, ], }); }); @@ -65,6 +65,14 @@ describe("TableCellMargin", () => { }, }, }, + { + "w:start": { + _attr: { + "w:type": "dxa", + "w:w": 5, + }, + }, + }, { "w:bottom": { _attr: { @@ -81,14 +89,6 @@ describe("TableCellMargin", () => { }, }, }, - { - "w:start": { - _attr: { - "w:type": "dxa", - "w:w": 5, - }, - }, - }, ], }); }); diff --git a/src/file/table/table-cell/cell-margin/table-cell-margins.ts b/src/file/table/table-cell/cell-margin/table-cell-margins.ts index b97c349c9c..efb2beb5bd 100644 --- a/src/file/table/table-cell/cell-margin/table-cell-margins.ts +++ b/src/file/table/table-cell/cell-margin/table-cell-margins.ts @@ -14,8 +14,8 @@ export class TableCellMargin extends XmlComponent { constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMarginOptions) { super("w:tcMar"); this.root.push(new TopCellMargin(top)); + this.root.push(new LeftCellMargin(left)); this.root.push(new BottomCellMargin(bottom)); this.root.push(new RightCellMargin(right)); - this.root.push(new LeftCellMargin(left)); } } diff --git a/src/file/table/table-cell/table-cell-properties.spec.ts b/src/file/table/table-cell/table-cell-properties.spec.ts index c3452e757c..24c17b674c 100644 --- a/src/file/table/table-cell/table-cell-properties.spec.ts +++ b/src/file/table/table-cell/table-cell-properties.spec.ts @@ -90,6 +90,14 @@ describe("TableCellProperties", () => { }, }, }, + { + "w:start": { + _attr: { + "w:type": "dxa", + "w:w": 0, + }, + }, + }, { "w:bottom": { _attr: { @@ -106,14 +114,6 @@ describe("TableCellProperties", () => { }, }, }, - { - "w:start": { - _attr: { - "w:type": "dxa", - "w:w": 0, - }, - }, - }, ], }, ], diff --git a/src/file/table/table-cell/table-cell-properties.ts b/src/file/table/table-cell/table-cell-properties.ts index e248290294..68f21e22dc 100644 --- a/src/file/table/table-cell/table-cell-properties.ts +++ b/src/file/table/table-cell/table-cell-properties.ts @@ -21,7 +21,6 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent { constructor() { super("w:tcPr"); this.cellBorder = new TableCellBorders(); - this.root.push(this.cellBorder); } public get Borders(): TableCellBorders { @@ -69,4 +68,10 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent { return this; } + + public addBorders(): TableCellProperties { + this.root.push(this.cellBorder); + + 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 2ba34bc9d4..f320cfed6e 100644 --- a/src/file/table/table-cell/table-cell.spec.ts +++ b/src/file/table/table-cell/table-cell.spec.ts @@ -354,6 +354,14 @@ describe("TableCell", () => { }, }, }, + { + "w:start": { + _attr: { + "w:type": "dxa", + "w:w": 1, + }, + }, + }, { "w:bottom": { _attr: { @@ -370,14 +378,6 @@ describe("TableCell", () => { }, }, }, - { - "w:start": { - _attr: { - "w:type": "dxa", - "w:w": 1, - }, - }, - }, ], }, ], diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index c79468e208..7a1bd8b458 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -57,12 +57,12 @@ export class TableCell extends XmlComponent { this.root.push(child); } - if (options.verticalAlign) { - properties.setVerticalAlign(options.verticalAlign); + if (options.width) { + properties.setWidth(options.width.size, options.width.type); } - if (options.textDirection) { - properties.setTextDirection(options.textDirection); + if (options.columnSpan) { + properties.addGridSpan(options.columnSpan); } if (options.verticalMerge) { @@ -72,23 +72,8 @@ export class TableCell extends XmlComponent { properties.addVerticalMerge(VerticalMergeType.RESTART); } - if (options.margins) { - properties.addMargins(options.margins); - } - - if (options.shading) { - properties.setShading(options.shading); - } - - if (options.columnSpan) { - properties.addGridSpan(options.columnSpan); - } - - if (options.width) { - properties.setWidth(options.width.size, options.width.type); - } - if (options.borders) { + properties.addBorders(); if (options.borders.top) { properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color); } @@ -102,6 +87,22 @@ export class TableCell extends XmlComponent { properties.Borders.addRightBorder(options.borders.right.style, options.borders.right.size, options.borders.right.color); } } + + if (options.shading) { + properties.setShading(options.shading); + } + + if (options.margins) { + properties.addMargins(options.margins); + } + + if (options.textDirection) { + properties.setTextDirection(options.textDirection); + } + + if (options.verticalAlign) { + properties.setVerticalAlign(options.verticalAlign); + } } public prepForXml(context: IContext): IXmlableObject | undefined { diff --git a/src/file/table/table-properties/table-cell-margin.ts b/src/file/table/table-properties/table-cell-margin.ts index 9d94e7c84a..ffa554a8de 100644 --- a/src/file/table/table-properties/table-cell-margin.ts +++ b/src/file/table/table-properties/table-cell-margin.ts @@ -35,10 +35,6 @@ export class TableCellMargin extends IgnoreIfEmptyXmlComponent { constructor(options: ITableCellMarginOptions) { super("w:tblCellMar"); - if (options.bottom) { - this.root.push(new BaseTableCellMargin("w:bottom", options.bottom)); - } - if (options.top) { this.root.push(new BaseTableCellMargin("w:top", options.top)); } @@ -47,6 +43,10 @@ export class TableCellMargin extends IgnoreIfEmptyXmlComponent { this.root.push(new BaseTableCellMargin("w:left", options.left)); } + if (options.bottom) { + this.root.push(new BaseTableCellMargin("w:bottom", options.bottom)); + } + if (options.right) { this.root.push(new BaseTableCellMargin("w:right", options.right)); } diff --git a/src/file/table/table-properties/table-properties.ts b/src/file/table/table-properties/table-properties.ts index cd0341a6ac..5d1aa048e1 100644 --- a/src/file/table/table-properties/table-properties.ts +++ b/src/file/table/table-properties/table-properties.ts @@ -35,34 +35,34 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent { this.root.push(new TableStyle(options.style)); } - this.root.push(new TableCellMargin(options.cellMargin || {})); + if (options.float) { + this.root.push(new TableFloatProperties(options.float)); + } - if (options.borders) { - this.root.push(new TableBorders(options.borders)); + if (options.visuallyRightToLeft) { + this.root.push(new VisuallyRightToLeft()); } if (options.width) { this.root.push(new PreferredTableWidth(options.width.type, options.width.size)); } - if (options.float) { - this.root.push(new TableFloatProperties(options.float)); - } - - if (options.layout) { - this.root.push(new TableLayout(options.layout)); - } - if (options.alignment) { this.root.push(new Alignment(options.alignment)); } + if (options.borders) { + this.root.push(new TableBorders(options.borders)); + } + if (options.shading) { this.root.push(new TableShading(options.shading)); } - if (options.visuallyRightToLeft) { - this.root.push(new VisuallyRightToLeft()); + if (options.layout) { + this.root.push(new TableLayout(options.layout)); } + + this.root.push(new TableCellMargin(options.cellMargin || {})); } } diff --git a/src/file/table/table.spec.ts b/src/file/table/table.spec.ts index 3165330047..623540985f 100644 --- a/src/file/table/table.spec.ts +++ b/src/file/table/table.spec.ts @@ -14,14 +14,6 @@ import { TableRow } from "./table-row"; const DEFAULT_TABLE_PROPERTIES = { "w:tblCellMar": [ - { - "w:bottom": { - _attr: { - "w:type": "auto", - "w:w": 0, - }, - }, - }, { "w:top": { _attr: { @@ -38,6 +30,14 @@ const DEFAULT_TABLE_PROPERTIES = { }, }, }, + { + "w:bottom": { + _attr: { + "w:type": "auto", + "w:w": 0, + }, + }, + }, { "w:right": { _attr: { @@ -177,7 +177,7 @@ describe("Table", () => { }; expect(tree).to.deep.equal({ "w:tbl": [ - { "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS] }, + { "w:tblPr": [WIDTHS, BORDERS, DEFAULT_TABLE_PROPERTIES] }, { "w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }], }, @@ -223,7 +223,7 @@ describe("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:tblPr": [WIDTHS, BORDERS, DEFAULT_TABLE_PROPERTIES] }, { "w:tblGrid": [{ "w:gridCol": { _attr: { "w:w": 100 } } }, { "w:gridCol": { _attr: { "w:w": 100 } } }], }, @@ -270,7 +270,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["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }], + "w:tblPr": [WIDTHS, BORDERS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }, DEFAULT_TABLE_PROPERTIES], }); }); @@ -290,7 +290,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["w:tbl"][0]).to.deep.equal({ - "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:jc": { _attr: { "w:val": "center" } } }], + "w:tblPr": [WIDTHS, { "w:jc": { _attr: { "w:val": "center" } } }, BORDERS, DEFAULT_TABLE_PROPERTIES], }); }); @@ -315,8 +315,6 @@ describe("Table", () => { 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, { "w:tblW": { _attr: { @@ -325,7 +323,9 @@ describe("Table", () => { }, }, }, + BORDERS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }, + DEFAULT_TABLE_PROPERTIES, ], }); }); @@ -477,9 +477,6 @@ describe("Table", () => { 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:tblpPr": { _attr: { @@ -496,6 +493,9 @@ describe("Table", () => { }, }, }, + WIDTHS, + BORDERS, + DEFAULT_TABLE_PROPERTIES, ], }); }); From 56b18d379336cc61a88496f7dd1fb6999a076fd1 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 01:06:07 +0300 Subject: [PATCH 03/10] Fix ordering of elements in paragraph-properties --- src/file/paragraph/paragraph.ts | 2 +- src/file/paragraph/properties.ts | 135 +++++++++++++++-------------- src/file/paragraph/run/text-run.ts | 2 +- 3 files changed, 73 insertions(+), 66 deletions(-) diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index a54698e837..aef1a0a4fc 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -43,7 +43,7 @@ export class Paragraph extends XmlComponent { this.properties = new ParagraphProperties({}); this.root.push(this.properties); this.root.push(new TextRun(options)); - return; + return this; } this.properties = new ParagraphProperties(options); diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 29bcc0613e..e32a747412 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -66,70 +66,15 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { 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)); + return this; } 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) { @@ -138,6 +83,37 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { this.push(new Style("ListParagraph")); } } + } + + if (options.style) { + this.push(new Style(options.style)); + } + + if (options.keepNext) { + this.push(new KeepNext()); + } + + if (options.keepLines) { + this.push(new KeepLines()); + } + + if (options.pageBreakBefore) { + this.push(new PageBreakBefore()); + } + + if (options.frame) { + this.push(new FrameProperties(options.frame)); + } + + if (options.widowControl) { + this.push(new WidowControl(options.widowControl)); + } + + if (options.bullet) { + this.push(new NumberProperties(1, options.bullet.level)); + } + + if (options.numbering) { this.numberingReferences.push({ reference: options.numbering.reference, instance: options.numbering.instance ?? 0, @@ -146,24 +122,55 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { this.push(new NumberProperties(`${options.numbering.reference}-${options.numbering.instance ?? 0}`, options.numbering.level)); } - if (options.rightTabStop) { - this.push(new TabStop(TabStopType.RIGHT, options.rightTabStop)); + if (options.border) { + this.push(new Border(options.border)); } - if (options.leftTabStop) { - this.push(new TabStop(TabStopType.LEFT, options.leftTabStop)); + if (options.thematicBreak) { + this.push(new ThematicBreak()); } if (options.shading) { this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color)); } - if (options.widowControl) { - this.push(new WidowControl(options.widowControl)); + if (options.rightTabStop) { + this.push(new TabStop(TabStopType.RIGHT, options.rightTabStop)); } - if (options.frame) { - this.push(new FrameProperties(options.frame)); + if (options.tabStops) { + for (const tabStop of options.tabStops) { + this.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader)); + } + } + + if (options.leftTabStop) { + this.push(new TabStop(TabStopType.LEFT, options.leftTabStop)); + } + + + if (options.bidirectional) { + this.push(new Bidirectional()); + } + + if (options.spacing) { + this.push(new Spacing(options.spacing)); + } + + if (options.indent) { + this.push(new Indent(options.indent)); + } + + if (options.contextualSpacing) { + this.push(new ContextualSpacing(options.contextualSpacing)); + } + + if (options.alignment) { + this.push(new Alignment(options.alignment)); + } + + if (options.outlineLevel !== undefined) { + this.push(new OutlineLevel(options.outlineLevel)); } } diff --git a/src/file/paragraph/run/text-run.ts b/src/file/paragraph/run/text-run.ts index 200651c9de..e262db72a4 100644 --- a/src/file/paragraph/run/text-run.ts +++ b/src/file/paragraph/run/text-run.ts @@ -6,7 +6,7 @@ export class TextRun extends Run { if (typeof options === "string") { super({}); this.root.push(new Text(options)); - return; + return this; } super(options); From 30912e7aaf86da1d95f1115795c63928b1df88c8 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 02:18:17 +0300 Subject: [PATCH 04/10] Fix ordering of elements in table-cell-borders and section-properties --- src/file/document/body/body.spec.ts | 4 +-- .../section-properties.spec.ts | 20 +++++++------ .../section-properties/section-properties.ts | 28 +++++++++-------- src/file/file.spec.ts | 30 +++++++++---------- src/file/table/table-cell/table-cell.spec.ts | 18 +++++------ src/file/table/table-cell/table-cell.ts | 6 ++-- 6 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/file/document/body/body.spec.ts b/src/file/document/body/body.spec.ts index 63f7cf03ba..b0b6836cef 100644 --- a/src/file/document/body/body.spec.ts +++ b/src/file/document/body/body.spec.ts @@ -43,13 +43,13 @@ describe("Body", () => { }, }, }, - { "w:cols": { _attr: { "w:space": 708, "w:sep": false, "w:num": 1 } } }, - { "w:docGrid": { _attr: { "w:linePitch": 360 } } }, { "w:pgNumType": { _attr: {}, }, }, + { "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/section-properties/section-properties.spec.ts b/src/file/document/body/section-properties/section-properties.spec.ts index 3472772411..38bdfe5a4e 100644 --- a/src/file/document/body/section-properties/section-properties.spec.ts +++ b/src/file/document/body/section-properties/section-properties.spec.ts @@ -61,8 +61,10 @@ describe("SectionProperties", () => { expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(tree["w:sectPr"]).to.be.an.instanceof(Array); - expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } }); - expect(tree["w:sectPr"][1]).to.deep.equal({ + expect(tree["w:sectPr"][0]).to.deep.equal({ "w:headerReference": { _attr: { "r:id": "rId100", "w:type": "default" } } }); + expect(tree["w:sectPr"][1]).to.deep.equal({ "w:footerReference": { _attr: { "r:id": "rId200", "w:type": "even" } } }); + expect(tree["w:sectPr"][2]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } }); + expect(tree["w:sectPr"][3]).to.deep.equal({ "w:pgMar": { _attr: { "w:bottom": 1440, @@ -77,11 +79,11 @@ describe("SectionProperties", () => { }, }); - 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" } } }); - expect(tree["w:sectPr"][6]).to.deep.equal({ "w:pgNumType": { _attr: { "w:fmt": "cardinalText", "w:start": 10 } } }); + expect(tree["w:sectPr"][4]).to.deep.equal({ "w:pgNumType": { _attr: { "w:fmt": "cardinalText", "w:start": 10 } } }); + expect(tree["w:sectPr"][5]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:sep": true, "w:num": 1 } } }); + expect(tree["w:sectPr"][6]).to.deep.equal({ "w:vAlign": { _attr: { "w:val": "top" } } }); + expect(tree["w:sectPr"][7]).to.deep.equal({ "w:titlePg": { _attr: { "w:val": "1" } } }); + expect(tree["w:sectPr"][8]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } }); }); it("should create section properties with no options", () => { @@ -104,8 +106,8 @@ describe("SectionProperties", () => { }, }, }); - 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 } } }); + expect(tree["w:sectPr"][3]).to.deep.equal({ "w:cols": { _attr: { "w:space": 708, "w:sep": false, "w:num": 1 } } }); + expect(tree["w:sectPr"][4]).to.deep.equal({ "w:docGrid": { _attr: { "w:linePitch": 360 } } }); }); it("should create section properties with changed options", () => { diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index fd5a061218..9000ef96c8 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -89,20 +89,16 @@ export class SectionProperties extends XmlComponent { }: ISectionPropertiesOptions = {}) { super("w:sectPr"); - 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(space, count, separate)); - this.root.push(new DocumentGrid(linePitch)); - this.addHeaders(headerWrapperGroup); this.addFooters(footerWrapperGroup); - this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType, pageNumberSeparator)); - - if (lineNumberCountBy || lineNumberStart || lineNumberRestart || lineNumberDistance) { - this.root.push(new LineNumberType(lineNumberCountBy, lineNumberStart, lineNumberRestart, lineNumberDistance)); + if (type) { + this.root.push(new Type(type)); } + this.root.push(new PageSize(width, height, orientation)); + this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror)); + if (pageBorders || pageBorderTop || pageBorderRight || pageBorderBottom || pageBorderLeft) { this.root.push( new PageBorders({ @@ -115,17 +111,23 @@ export class SectionProperties extends XmlComponent { ); } - if (titlePage) { - this.root.push(new TitlePage()); + if (lineNumberCountBy || lineNumberStart || lineNumberRestart || lineNumberDistance) { + this.root.push(new LineNumberType(lineNumberCountBy, lineNumberStart, lineNumberRestart, lineNumberDistance)); } + this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType, pageNumberSeparator)); + + this.root.push(new Columns(space, count, separate)); + if (verticalAlign) { this.root.push(new SectionVerticalAlign(verticalAlign)); } - if (type) { - this.root.push(new Type(type)); + if (titlePage) { + this.root.push(new TitlePage()); } + + this.root.push(new DocumentGrid(linePitch)); } private addHeaders(headers: IHeaderFooterGroup): void { diff --git a/src/file/file.spec.ts b/src/file/file.spec.ts index 808407c6d9..5636b83716 100644 --- a/src/file/file.spec.ts +++ b/src/file/file.spec.ts @@ -25,8 +25,8 @@ describe("File", () => { 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"); + expect(tree["w:body"][0]["w:sectPr"][0]["w:headerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][0]["w:sectPr"][1]["w:footerReference"]._attr["w:type"]).to.equal("default"); }); it("should create with first headers and footers", () => { @@ -45,8 +45,8 @@ describe("File", () => { }); const tree = new Formatter().format(doc.Document.View.Body); - expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("first"); - expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][0]["w:sectPr"][0]["w:headerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][0]["w:sectPr"][1]["w:footerReference"]._attr["w:type"]).to.equal("first"); }); it("should create with correct headers", () => { @@ -70,13 +70,13 @@ describe("File", () => { 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"); - expect(tree["w:body"][0]["w:sectPr"][6]["w:headerReference"]._attr["w:type"]).to.equal("even"); + expect(tree["w:body"][0]["w:sectPr"][0]["w:headerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][0]["w:sectPr"][1]["w:headerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][0]["w:sectPr"][2]["w:headerReference"]._attr["w:type"]).to.equal("even"); - expect(tree["w:body"][0]["w:sectPr"][7]["w:footerReference"]._attr["w:type"]).to.equal("default"); - expect(tree["w:body"][0]["w:sectPr"][8]["w:footerReference"]._attr["w:type"]).to.equal("first"); - expect(tree["w:body"][0]["w:sectPr"][9]["w:footerReference"]._attr["w:type"]).to.equal("even"); + expect(tree["w:body"][0]["w:sectPr"][3]["w:footerReference"]._attr["w:type"]).to.equal("default"); + expect(tree["w:body"][0]["w:sectPr"][4]["w:footerReference"]._attr["w:type"]).to.equal("first"); + expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("even"); }); it("should add child", () => { @@ -135,6 +135,11 @@ describe("File", () => { }, }, }, + { + "w:pgNumType": { + _attr: {}, + }, + }, { "w:cols": { _attr: { @@ -151,11 +156,6 @@ describe("File", () => { }, }, }, - { - "w:pgNumType": { - _attr: {}, - }, - }, ], }, ], diff --git a/src/file/table/table-cell/table-cell.spec.ts b/src/file/table/table-cell/table-cell.spec.ts index f320cfed6e..3ea123fb5b 100644 --- a/src/file/table/table-cell/table-cell.spec.ts +++ b/src/file/table/table-cell/table-cell.spec.ts @@ -568,15 +568,6 @@ describe("TableCell", () => { }, }, }, - { - "w:bottom": { - _attr: { - "w:color": "blue", - "w:sz": 3, - "w:val": "double", - }, - }, - }, { "w:left": { _attr: { @@ -586,6 +577,15 @@ describe("TableCell", () => { }, }, }, + { + "w:bottom": { + _attr: { + "w:color": "blue", + "w:sz": 3, + "w:val": "double", + }, + }, + }, { "w:right": { _attr: { diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index 7a1bd8b458..672b5d2f94 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -77,12 +77,12 @@ export class TableCell extends XmlComponent { if (options.borders.top) { properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color); } - if (options.borders.bottom) { - properties.Borders.addBottomBorder(options.borders.bottom.style, options.borders.bottom.size, options.borders.bottom.color); - } if (options.borders.left) { properties.Borders.addLeftBorder(options.borders.left.style, options.borders.left.size, options.borders.left.color); } + if (options.borders.bottom) { + properties.Borders.addBottomBorder(options.borders.bottom.style, options.borders.bottom.size, options.borders.bottom.color); + } if (options.borders.right) { properties.Borders.addRightBorder(options.borders.right.style, options.borders.right.size, options.borders.right.color); } From 06da596ffbc5a6ddf66c6b5fc6db21d1b0cb375e Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 03:02:48 +0300 Subject: [PATCH 05/10] Remove invalid 'w:shdCs' element --- src/file/numbering/abstract-numbering.spec.ts | 15 ++------------- src/file/paragraph/run/formatting.ts | 12 ------------ src/file/paragraph/run/properties.ts | 7 ------- src/file/paragraph/run/run.spec.ts | 9 --------- src/file/styles/style/character-style.spec.ts | 15 ++------------- src/file/styles/style/paragraph-style.spec.ts | 15 ++------------- 6 files changed, 6 insertions(+), 67 deletions(-) diff --git a/src/file/numbering/abstract-numbering.spec.ts b/src/file/numbering/abstract-numbering.spec.ts index df5416f453..8a9827aec2 100644 --- a/src/file/numbering/abstract-numbering.spec.ts +++ b/src/file/numbering/abstract-numbering.spec.ts @@ -625,7 +625,6 @@ describe("AbstractNumbering", () => { }, 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" } } }, ], }, { @@ -636,7 +635,6 @@ describe("AbstractNumbering", () => { }, 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" } } }, ], }, { @@ -645,10 +643,8 @@ describe("AbstractNumbering", () => { 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" } } }, ], }, { @@ -657,7 +653,6 @@ describe("AbstractNumbering", () => { fill: "00FFFF", color: "FF0000", }, - shadingComplexScript: false, expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { @@ -666,18 +661,12 @@ describe("AbstractNumbering", () => { 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 }) => { + shadingTests.forEach(({ shadow, shading, expected }) => { it("#shadow correctly", () => { const abstractNumbering = new AbstractNumbering(1, [ { @@ -685,7 +674,7 @@ describe("AbstractNumbering", () => { format: LevelFormat.LOWER_ROMAN, text: "%0.", style: { - run: { shadow, shading, shadingComplexScript }, + run: { shadow, shading }, }, }, ]); diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index 36c202b8d5..e10bda376a 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -200,15 +200,3 @@ export class Shading extends XmlComponent { } } -export class ShadowComplexScript extends XmlComponent { - constructor(value: string, fill: string, color: string) { - super("w:shdCs"); - this.root.push( - new Attributes({ - val: value, - fill: fill, - color: color, - }), - ); - } -} diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 7fb054d545..fa61e4d9d7 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -16,7 +16,6 @@ import { ItalicsComplexScript, RightToLeft, Shading, - ShadowComplexScript, Size, SizeComplexScript, SmallCaps, @@ -63,7 +62,6 @@ export interface IRunStylePropertiesOptions { readonly fill: string; readonly color: string; }; - readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"]; readonly shadow?: IRunStylePropertiesOptions["shading"]; readonly emboss?: boolean; readonly imprint?: boolean; @@ -185,11 +183,6 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent { 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.spec.ts b/src/file/paragraph/run/run.spec.ts index 5dc7c270d0..fb4284308c 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -245,15 +245,6 @@ describe("Run", () => { { "w:rPr": [ { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - { - "w:shdCs": { - _attr: { - "w:val": "pct10", - "w:fill": "00FFFF", - "w:color": "FF0000", - }, - }, - }, ], }, ], diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index c7adf4ff97..434376ebf8 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -784,7 +784,6 @@ describe("CharacterStyle", () => { }, 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" } } }, ], }, { @@ -795,7 +794,6 @@ describe("CharacterStyle", () => { }, 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" } } }, ], }, { @@ -804,10 +802,8 @@ describe("CharacterStyle", () => { 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" } } }, ], }, { @@ -816,7 +812,6 @@ describe("CharacterStyle", () => { fill: "00FFFF", color: "FF0000", }, - shadingComplexScript: false, expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { @@ -825,22 +820,16 @@ describe("CharacterStyle", () => { 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 }) => { + shadingTests.forEach(({ shadow, shading, expected }) => { it("#shadow correctly", () => { const style = new StyleForCharacter({ id: "myStyleId", - run: { shadow, shading, shadingComplexScript }, + run: { shadow, shading }, }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 8683234793..7fabb2024d 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -660,7 +660,6 @@ describe("ParagraphStyle", () => { }, 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" } } }, ], }, { @@ -671,7 +670,6 @@ describe("ParagraphStyle", () => { }, 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" } } }, ], }, { @@ -680,10 +678,8 @@ describe("ParagraphStyle", () => { 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" } } }, ], }, { @@ -692,7 +688,6 @@ describe("ParagraphStyle", () => { fill: "00FFFF", color: "FF0000", }, - shadingComplexScript: false, expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { @@ -701,22 +696,16 @@ describe("ParagraphStyle", () => { 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 }) => { + shadingTests.forEach(({ shadow, shading, expected }) => { it("#shadow correctly", () => { const style = new StyleForParagraph({ id: "myStyleId", - run: { shadow, shading, shadingComplexScript }, + run: { shadow, shading }, }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ From f5e35603ef21c6cfe52cece5abbfc93eee409d97 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 03:42:10 +0300 Subject: [PATCH 06/10] remove invalid w:mirrorMargins attribute from w:pgMar --- src/file/document/body/body.spec.ts | 1 - .../page-margin/page-margin-attributes.ts | 2 -- .../body/section-properties/page-margin/page-margin.ts | 3 +-- .../body/section-properties/section-properties.spec.ts | 6 ------ .../document/body/section-properties/section-properties.ts | 3 +-- src/file/file.spec.ts | 1 - 6 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/file/document/body/body.spec.ts b/src/file/document/body/body.spec.ts index b0b6836cef..bae759266c 100644 --- a/src/file/document/body/body.spec.ts +++ b/src/file/document/body/body.spec.ts @@ -39,7 +39,6 @@ describe("Body", () => { "w:header": 708, "w:footer": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }, diff --git a/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts b/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts index 73677ab4aa..7d7df6565c 100644 --- a/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts +++ b/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts @@ -8,7 +8,6 @@ export interface IPageMarginAttributes { readonly header?: number; readonly footer?: number; readonly gutter?: number; - readonly mirror?: boolean; } export class PageMarginAttributes extends XmlAttributeComponent { @@ -20,6 +19,5 @@ export class PageMarginAttributes extends XmlAttributeComponent { header: 708, footer: 708, gutter: 0, - mirror: false, }, pageNumbers: { start: 10, @@ -74,7 +73,6 @@ describe("SectionProperties", () => { "w:left": 1440, "w:header": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }); @@ -102,7 +100,6 @@ describe("SectionProperties", () => { "w:left": 1440, "w:header": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }); @@ -132,7 +129,6 @@ describe("SectionProperties", () => { "w:left": 1440, "w:header": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }); @@ -160,7 +156,6 @@ describe("SectionProperties", () => { "w:left": 1440, "w:header": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }); @@ -189,7 +184,6 @@ describe("SectionProperties", () => { "w:left": 1440, "w:header": 708, "w:gutter": 0, - "w:mirrorMargins": false, }, }, }); diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 9000ef96c8..095928d022 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -63,7 +63,6 @@ export class SectionProperties extends XmlComponent { header = 708, footer = 708, gutter = 0, - mirror = false, } = {}, pageNumbers: { start: pageNumberStart = undefined, @@ -97,7 +96,7 @@ export class SectionProperties extends XmlComponent { } 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 PageMargin(top, right, bottom, left, header, footer, gutter)); if (pageBorders || pageBorderTop || pageBorderRight || pageBorderBottom || pageBorderLeft) { this.root.push( diff --git a/src/file/file.spec.ts b/src/file/file.spec.ts index 5636b83716..a3cd9fbf65 100644 --- a/src/file/file.spec.ts +++ b/src/file/file.spec.ts @@ -129,7 +129,6 @@ describe("File", () => { "w:gutter": 0, "w:header": 708, "w:left": 1440, - "w:mirrorMargins": false, "w:right": 1440, "w:top": 1440, }, From 15f79abf5e1fa0f66dac403cb59c859a32b1dfcc Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 04:02:14 +0300 Subject: [PATCH 07/10] fix lint issues --- src/file/paragraph/properties.ts | 1 - src/file/paragraph/run/formatting.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index e32a747412..6a7fe283fd 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -148,7 +148,6 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { this.push(new TabStop(TabStopType.LEFT, options.leftTabStop)); } - if (options.bidirectional) { this.push(new Bidirectional()); } diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index e10bda376a..07e401a91e 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -199,4 +199,3 @@ export class Shading extends XmlComponent { ); } } - From 798cbb8628eac846467e409f821b02837fbbf985 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 04:08:00 +0300 Subject: [PATCH 08/10] fix prettier issues --- src/file/numbering/abstract-numbering.spec.ts | 44 ++++++++----------- src/file/paragraph/run/run.spec.ts | 4 +- src/file/styles/style/character-style.spec.ts | 44 ++++++++----------- src/file/styles/style/paragraph-style.spec.ts | 44 ++++++++----------- 4 files changed, 55 insertions(+), 81 deletions(-) diff --git a/src/file/numbering/abstract-numbering.spec.ts b/src/file/numbering/abstract-numbering.spec.ts index 8a9827aec2..b2d9f19bc1 100644 --- a/src/file/numbering/abstract-numbering.spec.ts +++ b/src/file/numbering/abstract-numbering.spec.ts @@ -623,29 +623,7 @@ describe("AbstractNumbering", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _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" } } }, - ], - }, - { - shading: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", - }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { shading: { @@ -661,9 +639,23 @@ describe("AbstractNumbering", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _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" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, ]; shadingTests.forEach(({ shadow, shading, expected }) => { diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index fb4284308c..a001699a7b 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -243,9 +243,7 @@ describe("Run", () => { expect(tree).to.deep.equal({ "w:r": [ { - "w:rPr": [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + "w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, ], }); diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index 434376ebf8..65dcdc26ee 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -782,29 +782,7 @@ describe("CharacterStyle", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _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" } } }, - ], - }, - { - shading: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", - }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { shading: { @@ -820,9 +798,23 @@ describe("CharacterStyle", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _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" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, ]; shadingTests.forEach(({ shadow, shading, expected }) => { diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 7fabb2024d..0885181c0c 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -658,29 +658,7 @@ describe("ParagraphStyle", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _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" } } }, - ], - }, - { - shading: { - type: ShadingType.PERCENT_10, - fill: "00FFFF", - color: "FF0000", - }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, { shading: { @@ -696,9 +674,23 @@ describe("ParagraphStyle", () => { fill: "00FFFF", color: "FF0000", }, - expected: [ - { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }, - ], + expected: [{ "w:shd": { _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" } } }], + }, + { + shading: { + type: ShadingType.PERCENT_10, + fill: "00FFFF", + color: "FF0000", + }, + expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }], }, ]; shadingTests.forEach(({ shadow, shading, expected }) => { From b627f0982a50b34f436dd2f0433924348534ab1f Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 04:20:14 +0300 Subject: [PATCH 09/10] fix ordering of elements in w:lvl --- src/file/numbering/level.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index 08f96c1610..d189e24e01 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -111,33 +111,35 @@ export class LevelBase extends XmlComponent { constructor({ level, format, text, alignment = AlignmentType.START, start = 1, style, suffix }: ILevelsOptions) { super("w:lvl"); - this.root.push( - new LevelAttributes({ - ilvl: level, - tentative: 1, - }), - ); this.root.push(new Start(start)); - this.root.push(new LevelJc(alignment)); if (format) { this.root.push(new NumberFormat(format)); } + if (suffix) { + this.root.push(new Suffix(suffix)); + } + if (text) { this.root.push(new LevelText(text)); } + this.root.push(new LevelJc(alignment)); + this.paragraphProperties = new ParagraphProperties(style && style.paragraph); this.runProperties = new RunProperties(style && style.run); this.root.push(this.paragraphProperties); this.root.push(this.runProperties); - if (suffix) { - this.root.push(new Suffix(suffix)); - } + this.root.push( + new LevelAttributes({ + ilvl: level, + tentative: 1, + }), + ); } } From 780682a8f7e2b382d211cfbfc19311859eb3a8da Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Thu, 20 May 2021 05:03:12 +0300 Subject: [PATCH 10/10] add test for ExternalStylesFactory when styles element is missing, to bump coverage --- src/file/styles/external-styles-factory.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/file/styles/external-styles-factory.spec.ts b/src/file/styles/external-styles-factory.spec.ts index 4db0f3199e..2ddc849ae8 100644 --- a/src/file/styles/external-styles-factory.spec.ts +++ b/src/file/styles/external-styles-factory.spec.ts @@ -153,6 +153,12 @@ describe("External styles factory", () => { }); }); + it("should throw when style element isn't found", () => { + expect(() => new ExternalStylesFactory().newInstance(``)).to.throw( + "can not find styles element", + ); + }); + it("should parse styles elements", () => { // tslint:disable-next-line:no-any const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;