diff --git a/src/file/footnotes/footnote/run/reference-run.ts b/src/file/footnotes/footnote/run/reference-run.ts index 3bfd772f50..c355bb17a3 100644 --- a/src/file/footnotes/footnote/run/reference-run.ts +++ b/src/file/footnotes/footnote/run/reference-run.ts @@ -1,5 +1,4 @@ import { Run } from "file/paragraph/run"; -import { Style } from "file/paragraph/run/style"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<{ @@ -24,9 +23,7 @@ export class FootnoteReference extends XmlComponent { export class FootnoteReferenceRun extends Run { constructor(id: number) { - super({}); - - this.properties.push(new Style("FootnoteReference")); + super({ style: "FootnoteReference" }); this.root.push(new FootnoteReference(id)); } diff --git a/src/file/paragraph/formatting/indent.ts b/src/file/paragraph/formatting/indent.ts index 3aad7d4e8a..aad272fa7c 100644 --- a/src/file/paragraph/formatting/indent.ts +++ b/src/file/paragraph/formatting/indent.ts @@ -1,29 +1,57 @@ // http://officeopenxml.com/WPindentation.php +import { signedTwipsMeasureValue, twipsMeasureValue } from "file/values"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface IIndentAttributesProperties { - readonly left?: number; - readonly hanging?: number; - readonly firstLine?: number; - readonly start?: number; - readonly end?: number; - readonly right?: number; + readonly start?: number | string; + readonly end?: number | string; + readonly left?: number | string; + readonly right?: number | string; + readonly hanging?: number | string; + readonly firstLine?: number | string; } +// +// +// +// +// +// +// +// +// +// +// +// +// +// class IndentAttributes extends XmlAttributeComponent { protected readonly xmlKeys = { - left: "w:left", - hanging: "w:hanging", - firstLine: "w:firstLine", start: "w:start", end: "w:end", - right: "w:end", // alias + left: "w:left", + right: "w:right", + hanging: "w:hanging", + firstLine: "w:firstLine", }; } +// +// +// ... +// export class Indent extends XmlComponent { - constructor(attrs: IIndentAttributesProperties) { + constructor({ start, end, left, right, hanging, firstLine }: IIndentAttributesProperties) { super("w:ind"); - this.root.push(new IndentAttributes(attrs)); + this.root.push( + new IndentAttributes({ + start: start === undefined ? undefined : signedTwipsMeasureValue(start), + end: end === undefined ? undefined : signedTwipsMeasureValue(end), + left: left === undefined ? undefined : signedTwipsMeasureValue(left), + right: right === undefined ? undefined : signedTwipsMeasureValue(right), + hanging: hanging === undefined ? undefined : twipsMeasureValue(hanging), + firstLine: firstLine === undefined ? undefined : twipsMeasureValue(firstLine), + }), + ); } } diff --git a/src/file/paragraph/run/break.ts b/src/file/paragraph/run/break.ts index 293071773b..0d0eac8c8c 100644 --- a/src/file/paragraph/run/break.ts +++ b/src/file/paragraph/run/break.ts @@ -1,6 +1,30 @@ // http://officeopenxml.com/WPtextSpecialContent-break.php import { XmlComponent } from "file/xml-components"; +// +// ... +// + +// +// +// +// + +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// export class Break extends XmlComponent { constructor() { super("w:br"); diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 89be41619e..3c47099b85 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -1,10 +1,9 @@ import { IShadingAttributesProperties, Shading } from "file/shading"; -import { HpsMeasureElement, IgnoreIfEmptyXmlComponent, OnOffElement, XmlComponent } from "file/xml-components"; +import { HpsMeasureElement, IgnoreIfEmptyXmlComponent, OnOffElement, StringValueElement, XmlComponent } from "file/xml-components"; import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark"; import { CharacterSpacing, Color, Highlight, HighlightComplexScript } from "./formatting"; import { IFontAttributesProperties, RunFonts } from "./run-fonts"; import { SubScript, SuperScript } from "./script"; -import { Style } from "./style"; import { Underline, UnderlineType } from "./underline"; interface IFontOptions { @@ -162,7 +161,7 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent { } if (options.style) { - this.push(new Style(options.style)); + this.push(new StringValueElement("w:rStyle", options.style)); } if (options.font) { diff --git a/src/file/paragraph/run/style.ts b/src/file/paragraph/run/style.ts deleted file mode 100644 index 2472c1d406..0000000000 --- a/src/file/paragraph/run/style.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; - -class StyleAttributes extends XmlAttributeComponent<{ readonly val: string }> { - protected readonly xmlKeys = { val: "w:val" }; -} - -export class Style extends XmlComponent { - constructor(styleId: string) { - super("w:rStyle"); - this.root.push(new StyleAttributes({ val: styleId })); - } -} diff --git a/src/file/paragraph/run/tab.ts b/src/file/paragraph/run/tab.ts index 55893862af..33f2b09427 100644 --- a/src/file/paragraph/run/tab.ts +++ b/src/file/paragraph/run/tab.ts @@ -1,5 +1,11 @@ import { XmlComponent } from "file/xml-components"; +// +// ... +// +// +// TODO: this is unused and undocumented currently. +// I think the intended use was for users to import, and insert as a child of `Run`. export class Tab extends XmlComponent { constructor() { super("w:tab"); diff --git a/src/file/paragraph/run/underline.spec.ts b/src/file/paragraph/run/underline.spec.ts index 77f7819e7b..bc406a1da4 100644 --- a/src/file/paragraph/run/underline.spec.ts +++ b/src/file/paragraph/run/underline.spec.ts @@ -2,12 +2,12 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import * as u from "./underline"; +import { Underline, UnderlineType } from "./underline"; describe("Underline", () => { describe("#constructor()", () => { it("should create a new Underline object with u:u as the rootKey", () => { - const underline = new u.Underline(); + const underline = new Underline(); const tree = new Formatter().format(underline); expect(tree).to.deep.equal({ "w:u": { @@ -19,7 +19,7 @@ describe("Underline", () => { }); it("should default to 'single' and no color", () => { - const underline = new u.Underline(); + const underline = new Underline(); const tree = new Formatter().format(underline); expect(tree).to.deep.equal({ "w:u": { _attr: { "w:val": "single" } }, @@ -27,7 +27,7 @@ describe("Underline", () => { }); it("should use the given style type and color", () => { - const underline = new u.Underline(u.UnderlineType.DOUBLE, "FF00CC"); + const underline = new Underline(UnderlineType.DOUBLE, "FF00CC"); const tree = new Formatter().format(underline); expect(tree).to.deep.equal({ "w:u": { _attr: { "w:val": "double", "w:color": "FF00CC" } }, @@ -35,259 +35,3 @@ describe("Underline", () => { }); }); }); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DashDotDotHeavyUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dashDotDotHeavy", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DashDotHeavyUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dashDotHeavy", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DashLongHeavyUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dashLongHeavy", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DashLongUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dashLong", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DashUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dash", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DotDashUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dotDash", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DotDotDashUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dotDotDash", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DottedHeavyUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dottedHeavy", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DottedUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "dotted", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.DoubleUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "double", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.SingleUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "single", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.ThickUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "thick", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.WaveUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "wave", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.WavyDoubleUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "wavyDouble", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.WavyHeavyUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "wavyHeavy", - }, - }, - }); - }); - }); -}); - -describe("DashDotDotHeavyUnderline", () => { - describe("#constructor()", () => { - it("should put value in attribute", () => { - const underline = new u.WordsUnderline(); - const tree = new Formatter().format(underline); - expect(tree).to.deep.equal({ - "w:u": { - _attr: { - "w:val": "words", - }, - }, - }); - }); - }); -}); diff --git a/src/file/paragraph/run/underline.ts b/src/file/paragraph/run/underline.ts index af1db4611d..a94c37e1f5 100644 --- a/src/file/paragraph/run/underline.ts +++ b/src/file/paragraph/run/underline.ts @@ -21,116 +21,14 @@ export enum UnderlineType { WAVYDOUBLE = "wavyDouble", } -export abstract class BaseUnderline extends XmlComponent { - constructor(underlineType: UnderlineType, color?: string) { +export class Underline extends XmlComponent { + constructor(underlineType: UnderlineType = UnderlineType.SINGLE, color?: string) { super("w:u"); this.root.push( new Attributes({ val: underlineType, - color: color === undefined ? color : hexColorValue(color), + color: color === undefined ? undefined : hexColorValue(color), }), ); } } - -export class Underline extends BaseUnderline { - constructor(underlineType: UnderlineType = UnderlineType.SINGLE, color?: string) { - super(underlineType, color); - } -} - -export class DashUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DASH); - } -} - -export class DashDotDotHeavyUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DASHDOTDOTHEAVY); - } -} - -export class DashDotHeavyUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DASHDOTHEAVY); - } -} - -export class DashLongUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DASHLONG); - } -} - -export class DashLongHeavyUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DASHLONGHEAVY); - } -} - -export class DotDashUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DOTDASH); - } -} - -export class DotDotDashUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DOTDOTDASH); - } -} - -export class DottedUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DOTTED); - } -} - -export class DottedHeavyUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DOTTEDHEAVY); - } -} - -export class DoubleUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.DOUBLE); - } -} - -export class SingleUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.SINGLE); - } -} - -export class ThickUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.THICK); - } -} - -export class WaveUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.WAVE); - } -} - -export class WavyDoubleUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.WAVYDOUBLE); - } -} - -export class WavyHeavyUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.WAVYHEAVY); - } -} - -export class WordsUnderline extends BaseUnderline { - constructor() { - super(UnderlineType.WORDS); - } -}