diff --git a/demo/demo1.ts b/demo/1-basic.ts similarity index 100% rename from demo/demo1.ts rename to demo/1-basic.ts diff --git a/demo/demo10.ts b/demo/10-my-cv.ts similarity index 100% rename from demo/demo10.ts rename to demo/10-my-cv.ts diff --git a/demo/demo11.ts b/demo/11-declaritive-styles-2.ts similarity index 100% rename from demo/demo11.ts rename to demo/11-declaritive-styles-2.ts diff --git a/demo/demo12.ts b/demo/12-scaling-images.ts similarity index 100% rename from demo/demo12.ts rename to demo/12-scaling-images.ts diff --git a/demo/demo13.ts b/demo/13-xml-styles.ts similarity index 100% rename from demo/demo13.ts rename to demo/13-xml-styles.ts diff --git a/demo/demo14.ts b/demo/14-page-numbers.ts similarity index 100% rename from demo/demo14.ts rename to demo/14-page-numbers.ts diff --git a/demo/demo15.ts b/demo/15-page-break-before.ts similarity index 100% rename from demo/demo15.ts rename to demo/15-page-break-before.ts diff --git a/demo/demo16.ts b/demo/16-multiple-sections.ts similarity index 100% rename from demo/demo16.ts rename to demo/16-multiple-sections.ts diff --git a/demo/demo17.ts b/demo/17-footnotes.ts similarity index 100% rename from demo/demo17.ts rename to demo/17-footnotes.ts diff --git a/demo/demo18.ts b/demo/18-image-from-buffer.ts similarity index 100% rename from demo/demo18.ts rename to demo/18-image-from-buffer.ts diff --git a/demo/demo19.ts b/demo/19-export-to-base64.ts similarity index 100% rename from demo/demo19.ts rename to demo/19-export-to-base64.ts diff --git a/demo/demo2.ts b/demo/2-declaritive-styles.ts similarity index 100% rename from demo/demo2.ts rename to demo/2-declaritive-styles.ts diff --git a/demo/demo20.ts b/demo/20-table-cell-borders.ts similarity index 100% rename from demo/demo20.ts rename to demo/20-table-cell-borders.ts diff --git a/demo/demo21.ts b/demo/21-bookmarks.ts similarity index 100% rename from demo/demo21.ts rename to demo/21-bookmarks.ts diff --git a/demo/demo22.ts b/demo/22-right-to-left-text.ts similarity index 100% rename from demo/demo22.ts rename to demo/22-right-to-left-text.ts diff --git a/demo/demo23.ts b/demo/23-base64-images.ts similarity index 100% rename from demo/demo23.ts rename to demo/23-base64-images.ts diff --git a/demo/demo24.ts b/demo/24-images-to-table-cell.ts similarity index 100% rename from demo/demo24.ts rename to demo/24-images-to-table-cell.ts diff --git a/demo/demo26.ts b/demo/26-paragraph-borders.ts similarity index 100% rename from demo/demo26.ts rename to demo/26-paragraph-borders.ts diff --git a/demo/demo27.ts b/demo/27-declaritive-styles-3.ts similarity index 100% rename from demo/demo27.ts rename to demo/27-declaritive-styles-3.ts diff --git a/demo/demo28.ts b/demo/28-table-of-contents.ts similarity index 100% rename from demo/demo28.ts rename to demo/28-table-of-contents.ts diff --git a/demo/demo29.ts b/demo/29-numbered-lists.ts similarity index 100% rename from demo/demo29.ts rename to demo/29-numbered-lists.ts diff --git a/demo/demo3.ts b/demo/3-numbering-and-bullet-points.ts similarity index 100% rename from demo/demo3.ts rename to demo/3-numbering-and-bullet-points.ts diff --git a/demo/demo30.ts b/demo/30-template-document.ts similarity index 100% rename from demo/demo30.ts rename to demo/30-template-document.ts diff --git a/demo/demo31.ts b/demo/31-tables.ts similarity index 100% rename from demo/demo31.ts rename to demo/31-tables.ts diff --git a/demo/demo32.ts b/demo/32-merge-table-cells.ts similarity index 100% rename from demo/demo32.ts rename to demo/32-merge-table-cells.ts diff --git a/demo/demo33.ts b/demo/33-sequential-captions.ts similarity index 100% rename from demo/demo33.ts rename to demo/33-sequential-captions.ts diff --git a/demo/demo34.ts b/demo/34-floating-tables.ts similarity index 100% rename from demo/demo34.ts rename to demo/34-floating-tables.ts diff --git a/demo/demo35.ts b/demo/35-hyperlinks.ts similarity index 100% rename from demo/demo35.ts rename to demo/35-hyperlinks.ts diff --git a/demo/demo36.ts b/demo/36-image-to-table-cell.ts similarity index 100% rename from demo/demo36.ts rename to demo/36-image-to-table-cell.ts diff --git a/demo/demo37.ts b/demo/37-images-to-header-and-footer.ts similarity index 100% rename from demo/demo37.ts rename to demo/37-images-to-header-and-footer.ts diff --git a/demo/demo38.ts b/demo/38-text-wrapping.ts similarity index 100% rename from demo/demo38.ts rename to demo/38-text-wrapping.ts diff --git a/demo/demo39.ts b/demo/39-page-numbers.ts similarity index 100% rename from demo/demo39.ts rename to demo/39-page-numbers.ts diff --git a/demo/demo4.ts b/demo/4-basic-table.ts similarity index 100% rename from demo/demo4.ts rename to demo/4-basic-table.ts diff --git a/demo/demo40.ts b/demo/40-line-numbers.ts similarity index 100% rename from demo/demo40.ts rename to demo/40-line-numbers.ts diff --git a/demo/demo41.ts b/demo/41-merge-table-cells-2.ts similarity index 100% rename from demo/demo41.ts rename to demo/41-merge-table-cells-2.ts diff --git a/demo/demo43.ts b/demo/43-images-to-table-cell-2.ts similarity index 100% rename from demo/demo43.ts rename to demo/43-images-to-table-cell-2.ts diff --git a/demo/demo44.ts b/demo/44-multiple-columns.ts similarity index 100% rename from demo/demo44.ts rename to demo/44-multiple-columns.ts diff --git a/demo/demo45.ts b/demo/45-highlighting-text.ts similarity index 91% rename from demo/demo45.ts rename to demo/45-highlighting-text.ts index dc44693e4d..0e2b416f33 100644 --- a/demo/demo45.ts +++ b/demo/45-highlighting-text.ts @@ -1,3 +1,5 @@ +// Highlighting text +// Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build"; diff --git a/demo/demo46.ts b/demo/46-shading-text.ts similarity index 90% rename from demo/demo46.ts rename to demo/46-shading-text.ts index 2bb31abdf9..5e0b816a63 100644 --- a/demo/demo46.ts +++ b/demo/46-shading-text.ts @@ -1,3 +1,5 @@ +// Shading text +// Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build"; @@ -18,7 +20,7 @@ doc.addSection({ font: { name: "Garamond", }, - shadow: { + shading: { type: ShadingType.REVERSE_DIAGONAL_STRIPE, color: "00FFFF", fill: "FF0000", diff --git a/demo/demo5.ts b/demo/5-images.ts similarity index 100% rename from demo/demo5.ts rename to demo/5-images.ts diff --git a/demo/demo6.ts b/demo/6-page-borders.ts similarity index 100% rename from demo/demo6.ts rename to demo/6-page-borders.ts diff --git a/demo/demo7.ts b/demo/7-landscape.ts similarity index 100% rename from demo/demo7.ts rename to demo/7-landscape.ts diff --git a/demo/demo8.ts b/demo/8-header-footer.ts similarity index 100% rename from demo/demo8.ts rename to demo/8-header-footer.ts diff --git a/demo/demo9.ts b/demo/9-images-in-header-and-footer.ts similarity index 100% rename from demo/demo9.ts rename to demo/9-images-in-header-and-footer.ts diff --git a/demo/index.ts b/demo/index.ts index 50b65572f2..8764e25f31 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -19,13 +19,16 @@ prompt.start(); prompt.get(schema, (_, result) => { const demoNumber = result.number; - const filePath = `./demo/demo${demoNumber}.ts`; + const files = fs.readdirSync("./demo").filter((fn) => fn.startsWith(demoNumber)); - if (!fs.existsSync(filePath)) { - console.error(`demo${demoNumber} does not exist: ${filePath}`); + if (files.length === 0) { + console.error(`demo number ${demoNumber} does not exist`); return; } - console.log(`Running demo ${demoNumber}`); + + const filePath = `./demo/${files[0]}`; + + console.log(`Running demo ${demoNumber}: ${files[0]}`); if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) { console.log("Document created successfully"); } else { diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index bbfb27493f..8a266fa47f 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -205,7 +205,7 @@ export class LevelBase extends XmlComponent { } public shadow(value: string, fill: string, color: string): Level { - this.addRunProperty(new formatting.Shadow(value, fill, color)); + this.addRunProperty(new formatting.Shading(value, fill, color)); return this; } // --------------------- Paragraph formatting ------------------------ // diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index 87273b9459..549f2ae552 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -201,7 +201,7 @@ export class HighlightComplexScript extends XmlComponent { } } -export class Shadow extends XmlComponent { +export class Shading extends XmlComponent { constructor(value: string, fill: string, color: string) { super("w:shd"); this.root.push( diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index b8b30295d6..81033425e4 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -158,7 +158,7 @@ describe("Run", () => { describe("#shadow()", () => { it("it should add shadow to the properties", () => { const run = new Run({ - shadow: { + shading: { type: ShadingType.PERCENT_10, fill: "00FFFF", color: "FF0000", diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index 2e5cd63439..f6ac359852 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -15,7 +15,7 @@ import { Italics, ItalicsComplexScript, RightToLeft, - Shadow, + Shading, ShadowComplexScript, Size, SizeComplexScript, @@ -51,7 +51,7 @@ export interface IRunOptions { readonly hint?: string; }; readonly highlight?: string; - readonly shadow?: { + readonly shading?: { readonly type: ShadingType; readonly fill: string; readonly color: string; @@ -130,9 +130,9 @@ export class Run extends XmlComponent { this.properties.push(new HighlightComplexScript(options.highlight)); } - if (options.shadow) { - this.properties.push(new Shadow(options.shadow.type, options.shadow.fill, options.shadow.color)); - this.properties.push(new ShadowComplexScript(options.shadow.type, options.shadow.fill, options.shadow.color)); + 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)); } } diff --git a/src/file/styles/style/character-style.ts b/src/file/styles/style/character-style.ts index 4ac49ba950..c60cca9394 100644 --- a/src/file/styles/style/character-style.ts +++ b/src/file/styles/style/character-style.ts @@ -64,6 +64,6 @@ export class CharacterStyle extends Style { } public shadow(value: string, fill: string, color: string): CharacterStyle { - return this.addRunProperty(new formatting.Shadow(value, fill, color)); + return this.addRunProperty(new formatting.Shading(value, fill, color)); } } diff --git a/src/file/styles/style/paragraph-style.ts b/src/file/styles/style/paragraph-style.ts index a1d3d86775..e79c6abe17 100644 --- a/src/file/styles/style/paragraph-style.ts +++ b/src/file/styles/style/paragraph-style.ts @@ -119,7 +119,7 @@ export class ParagraphStyle extends Style { } public shadow(value: string, fill: string, color: string): ParagraphStyle { - return this.addRunProperty(new formatting.Shadow(value, fill, color)); + return this.addRunProperty(new formatting.Shading(value, fill, color)); } // --------------------- Paragraph formatting ------------------------ //