Compare commits

..

12 Commits

Author SHA1 Message Date
7570fc2bf5 Version bump (#2496) 2023-12-31 14:35:06 +00:00
6929dee846 Revery demo 14 (#2495) 2023-12-31 14:22:22 +00:00
d4ac2a08ee Make demos synchronous (#2494) 2023-12-31 14:14:41 +00:00
010ef05ce3 Feat/embedded fonts (#2174)
* #239 Embedded fonts

* Add boilerplate for font table

* Fix linting

* Fix linting

* Fix odttf naming

* Correct writing of fonts to relationships and font table

new uuid function

* Add font to run

* Add demo

Fix tests

* Add character set support

* Add tests

* Write tests
2023-12-30 02:23:54 +00:00
fa401297da Re-name variables (#2486) 2023-12-29 23:52:43 +00:00
ce0e9936c3 build(deps-dev): bump @typescript-eslint/eslint-plugin (#2488)
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 6.15.0 to 6.16.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.16.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-29 23:51:46 +00:00
c13e9938cf Set target to es2015 in vite config (#2492)
* Set target to es2015 in vite config

* Remove document
2023-12-29 23:51:31 +00:00
b8f97553b3 #933 Discriminated union for frame alignment (#2477) 2023-12-29 15:07:42 +00:00
2550da199d build(deps-dev): bump vite-tsconfig-paths from 4.2.2 to 4.2.3 (#2493)
Bumps [vite-tsconfig-paths](https://github.com/aleclarson/vite-tsconfig-paths) from 4.2.2 to 4.2.3.
- [Release notes](https://github.com/aleclarson/vite-tsconfig-paths/releases)
- [Commits](https://github.com/aleclarson/vite-tsconfig-paths/compare/v4.2.2...v4.2.3)

---
updated-dependencies:
- dependency-name: vite-tsconfig-paths
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-29 15:06:48 +00:00
682b679bdb build(deps-dev): bump @typescript-eslint/parser from 6.15.0 to 6.16.0 (#2489)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 6.15.0 to 6.16.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.16.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-28 22:06:50 +00:00
e0fd7e751c build(deps-dev): bump cspell from 8.2.3 to 8.2.4 (#2490)
Bumps [cspell](https://github.com/streetsidesoftware/cspell) from 8.2.3 to 8.2.4.
- [Release notes](https://github.com/streetsidesoftware/cspell/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell/compare/v8.2.3...v8.2.4)

---
updated-dependencies:
- dependency-name: cspell
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-28 22:06:24 +00:00
9b57db4716 build(deps-dev): bump vite-plugin-node-polyfills from 0.9.0 to 0.19.0 (#2491)
Bumps [vite-plugin-node-polyfills](https://github.com/davidmyersdev/vite-plugin-node-polyfills) from 0.9.0 to 0.19.0.
- [Release notes](https://github.com/davidmyersdev/vite-plugin-node-polyfills/releases)
- [Commits](https://github.com/davidmyersdev/vite-plugin-node-polyfills/compare/v0.9.0...v0.19.0)

---
updated-dependencies:
- dependency-name: vite-plugin-node-polyfills
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-28 22:05:59 +00:00
41 changed files with 1601 additions and 2000 deletions

View File

@ -21,6 +21,7 @@
"iife",
"Initializable",
"iroha",
"JOHAB",
"jsonify",
"jszip",
"NUMPAGES",

View File

@ -8,777 +8,189 @@ on:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Build
run: npm run build
- name: Archive Production Artifact
uses: actions/upload-artifact@master
with:
name: build
path: build
demo_1:
name: Run Demo 1 and validate
needs: [build]
demos:
name: Demos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/1-basic.ts
- name: Run Demos
run: npm run run-ts -- ./demo/1-basic.ts
- uses: "./.github/actions/validate-docx"
demo_2:
name: Run Demo 2 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/2-declaritive-styles.ts
- uses: "./.github/actions/validate-docx"
demo_3:
name: Run Demo 3 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/3-numbering-and-bullet-points.ts
- uses: "./.github/actions/validate-docx"
demo_4:
name: Run Demo 4 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/4-basic-table.ts
- uses: "./.github/actions/validate-docx"
demo_5:
name: Run Demo 5 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/5-images.ts
- uses: "./.github/actions/validate-docx"
demo_6:
name: Run Demo 6 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/6-page-borders.ts
- uses: "./.github/actions/validate-docx"
demo_7:
name: Run Demo 7 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/7-landscape.ts
- uses: "./.github/actions/validate-docx"
demo_8:
name: Run Demo 8 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/8-header-footer.ts
- uses: "./.github/actions/validate-docx"
demo_9:
name: Run Demo 9 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/9-images-in-header-and-footer.ts
- uses: "./.github/actions/validate-docx"
demo_10:
name: Run Demo 10 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/10-my-cv.ts
- uses: "./.github/actions/validate-docx"
demo_11:
name: Run Demo 11 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/11-declaritive-styles-2.ts
- uses: "./.github/actions/validate-docx"
demo_12:
name: Run Demo 12 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/12-scaling-images.ts
- uses: "./.github/actions/validate-docx"
demo_13:
name: Run Demo 13 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/13-xml-styles.ts
- uses: "./.github/actions/validate-docx"
demo_14:
name: Run Demo 14 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/14-page-numbers.ts
- uses: "./.github/actions/validate-docx"
demo_15:
name: Run Demo 15 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/15-page-break-before.ts
- uses: "./.github/actions/validate-docx"
demo_16:
name: Run Demo 16 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/16-multiple-sections.ts
- uses: "./.github/actions/validate-docx"
demo_17:
name: Run Demo 17 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/17-footnotes.ts
# element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected.
# - uses: "./.github/actions/validate-docx"
demo_18:
name: Run Demo 18 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/18-image-from-buffer.ts
- uses: "./.github/actions/validate-docx"
demo_19:
name: Run Demo 19 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/19-export-to-base64.ts
# Base 64 No longer works, abruptly. Node issue?
# - uses: "./.github/actions/validate-docx"
demo_20:
name: Run Demo 20 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/20-table-cell-borders.ts
- uses: "./.github/actions/validate-docx"
demo_21:
name: Run Demo 21 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/21-bookmarks.ts
# Bad ID - need numeric ID
# - uses: "./.github/actions/validate-docx"
demo_22:
name: Run Demo 22 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/22-right-to-left-text.ts
- uses: "./.github/actions/validate-docx"
demo_23:
name: Run Demo 23 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/23-base64-images.ts
- uses: "./.github/actions/validate-docx"
demo_24:
name: Run Demo 24 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/24-images-to-table-cell.ts
- uses: "./.github/actions/validate-docx"
demo_25:
name: Run Demo 25 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/25-table-xml-styles.ts
- uses: "./.github/actions/validate-docx"
demo_26:
name: Run Demo 26 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/26-paragraph-borders.ts
- uses: "./.github/actions/validate-docx"
demo_27:
name: Run Demo 27 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/27-declaritive-styles-3.ts
- uses: "./.github/actions/validate-docx"
demo_28:
name: Run Demo 28 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/28-table-of-contents.ts
- uses: "./.github/actions/validate-docx"
demo_29:
name: Run Demo 29 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/29-numbered-lists.ts
- uses: "./.github/actions/validate-docx"
demo_31:
name: Run Demo 31 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/31-tables.ts
- uses: "./.github/actions/validate-docx"
demo_32:
name: Run Demo 32 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/32-merge-and-shade-table-cells.ts
- uses: "./.github/actions/validate-docx"
demo_33:
name: Run Demo 33 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/33-sequential-captions.ts
- uses: "./.github/actions/validate-docx"
demo_34:
name: Run Demo 34 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/34-floating-tables.ts
# element tblpPr: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tblpPr', attribute 'overlap': The attribute 'overlap' is not allowed.
# element tblpPr: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tblpPr': Element content is not allowed, because the content type is empty.
# - uses: "./.github/actions/validate-docx"
demo_35:
name: Run Demo 35 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/35-hyperlinks.ts
- uses: "./.github/actions/validate-docx"
demo_36:
name: Run Demo 36 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/36-image-to-table-cell.ts
- uses: "./.github/actions/validate-docx"
demo_37:
name: Run Demo 37 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/37-images-to-header-and-footer.ts
- uses: "./.github/actions/validate-docx"
demo_38:
name: Run Demo 38 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/38-text-wrapping.ts
- uses: "./.github/actions/validate-docx"
demo_39:
name: Run Demo 39 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/39-page-numbers.ts
- uses: "./.github/actions/validate-docx"
demo_40:
name: Run Demo 40 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/40-line-numbers.ts
- uses: "./.github/actions/validate-docx"
demo_41:
name: Run Demo 41 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/41-merge-table-cells-2.ts
- uses: "./.github/actions/validate-docx"
demo_42:
name: Run Demo 42 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/42-restart-page-numbers.ts
- uses: "./.github/actions/validate-docx"
demo_43:
name: Run Demo 43 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/43-images-to-table-cell-2.ts
- uses: "./.github/actions/validate-docx"
demo_44:
name: Run Demo 44 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/44-multiple-columns.ts
- uses: "./.github/actions/validate-docx"
demo_45:
name: Run Demo 45 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/45-highlighting-text.ts
- uses: "./.github/actions/validate-docx"
demo_46:
name: Run Demo 46 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/46-shading-text.ts
- uses: "./.github/actions/validate-docx"
demo_47:
name: Run Demo 47 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/47-number-of-total-pages-section.ts
- uses: "./.github/actions/validate-docx"
demo_48:
name: Run Demo 48 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/48-vertical-align.ts
- uses: "./.github/actions/validate-docx"
demo_49:
name: Run Demo 49 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/49-table-borders.ts
- uses: "./.github/actions/validate-docx"
demo_50:
name: Run Demo 50 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/50-readme-demo.ts
- uses: "./.github/actions/validate-docx"
demo_51:
name: Run Demo 51 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/51-character-styles.ts
- uses: "./.github/actions/validate-docx"
demo_52:
name: Run Demo 52 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/52-japanese.ts
- uses: "./.github/actions/validate-docx"
demo_53:
name: Run Demo 53 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/53-chinese.ts
- uses: "./.github/actions/validate-docx"
demo_54:
name: Run Demo 54 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/54-custom-properties.ts
- uses: "./.github/actions/validate-docx"
demo_55:
name: Run Demo 55 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/55-math.ts
#: element subHide: Schemas validity error : Element '{http://schemas.openxmlformats.org/officeDocument/2006/math}subHide': This element is not expected. Expected is ( {http://schemas.openxmlformats.org/officeDocument/2006/math}ctrlPr ).
#: element e: Schemas validity error : Element '{http://schemas.openxmlformats.org/officeDocument/2006/math}e': This element is not expected. Expected is ( {http://schemas.openxmlformats.org/officeDocument/2006/math}sub ).
#: element e: Schemas validity error : Element '{http://schemas.openxmlformats.org/officeDocument/2006/math}e': This element is not expected. Expected is ( {http://schemas.openxmlformats.org/officeDocument/2006/math}sup ).
#: element e: Schemas validity error : Element '{http://schemas.openxmlformats.org/officeDocument/2006/math}e': This element is not expected. Expected is ( {http://schemas.openxmlformats.org/officeDocument/2006/math}sub ).
# - uses: "./.github/actions/validate-docx"
demo_56:
name: Run Demo 56 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/56-background-color.ts
- uses: "./.github/actions/validate-docx"
demo_57:
name: Run Demo 57 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/57-add-parent-numbered-lists.ts
- uses: "./.github/actions/validate-docx"
demo_58:
name: Run Demo 58 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/58-section-types.ts
- uses: "./.github/actions/validate-docx"
demo_59:
name: Run Demo 59 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/59-header-footer-margins.ts
- uses: "./.github/actions/validate-docx"
demo_60:
name: Run Demo 60 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/60-track-revisions.ts
# element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected.
# - uses: "./.github/actions/validate-docx"
demo_61:
name: Run Demo 61 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/61-text-frame.ts
# element left: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}left': This element is not expected. Expected is one of ( {http://schemas.openxmlformats.org/wordprocessingml/2006/main}right, {http://schemas.openxmlformats.org/wordprocessingml/2006/main}between, {http://schemas.openxmlformats.org/wordprocessingml/2006/main}bar ).
# - uses: "./.github/actions/validate-docx"
demo_62:
name: Run Demo 62 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/62-paragraph-spacing.ts
- uses: "./.github/actions/validate-docx"
demo_63:
name: Run Demo 63 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/63-odd-even-header-footer.ts
- uses: "./.github/actions/validate-docx"
demo_64:
name: Run Demo 64 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/64-complex-numbering-text.ts
- uses: "./.github/actions/validate-docx"
demo_65:
name: Run Demo 65 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/65-page-sizes.ts
- uses: "./.github/actions/validate-docx"
demo_66:
name: Run Demo 66 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/66-fields.ts
# element bookmarkStart: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart', attribute '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id': '-irrswq-ln94j4fdgdjxs' is not a valid value of the atomic type '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ST_DecimalNumber'.
# element bookmarkEnd: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd', attribute '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id': '-irrswq-ln94j4fdgdjxs' is not a valid value of the atomic type '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}ST_DecimalNumber'.
# - uses: "./.github/actions/validate-docx"
demo_67:
name: Run Demo 67 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/67-column-break.ts
- uses: "./.github/actions/validate-docx"
demo_68:
name: Run Demo 68 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/68-numbering-instances-and-starting-number.ts
- uses: "./.github/actions/validate-docx"
demo_69:
name: Run Demo 69 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/69-different-width-columns.ts
- uses: "./.github/actions/validate-docx"
demo_70:
name: Run Demo 70 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/70-line-numbers-suppression.ts
- uses: "./.github/actions/validate-docx"
demo_71:
name: Run Demo 71 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/71-page-borders-2.ts
- uses: "./.github/actions/validate-docx"
demo_72:
name: Run Demo 72 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/72-word-wrap.ts
- uses: "./.github/actions/validate-docx"
demo_73:
name: Run Demo 73 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/73-comments.ts
- uses: "./.github/actions/validate-docx"
demo_74:
name: Run Demo 74 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/74-nodejs-stream.ts
# - uses: "./.github/actions/validate-docx"
demo_75:
name: Run Demo 75 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
# run: npm run run-ts -- ./demo/75-tab-stops.ts
# - uses: "./.github/actions/validate-docx"
demo_76:
name: Run Demo 76 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/76-compatibility.ts
- uses: "./.github/actions/validate-docx"
demo_77:
name: Run Demo 77 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/77-side-by-side-tables.ts
- uses: "./.github/actions/validate-docx"
demo_78:
name: Run Demo 78 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/78-thai-distributed.ts
- uses: "./.github/actions/validate-docx"
demo_79:
name: Run Demo 79 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/79-table-from-data-source.ts
- uses: "./.github/actions/validate-docx"
demo_80:
name: Run Demo 80 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/80-thai-distributed.ts
- uses: "./.github/actions/validate-docx"
demo_81:
name: Run Demo 81 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/81-continuous-header.ts
- uses: "./.github/actions/validate-docx"
demo_82:
name: Run Demo 82 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/82-new-headers-new-section.ts
- uses: "./.github/actions/validate-docx"
demo_83:
name: Run Demo 83 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/83-setting-languages.ts
- uses: "./.github/actions/validate-docx"
demo_84:
name: Run Demo 84 and validate
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- run: npm run run-ts -- ./demo/84-positional-tabs.ts
- uses: "./.github/actions/validate-docx"

View File

@ -3,142 +3,6 @@
import * as fs from "fs";
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "docx";
// cspell: disable
const createLoremIpsumParagraphs = () => [
new Paragraph(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan condimentum elit ut placerat. Integer vitae justo est. Quisque tempus augue eu diam pulvinar aliquam. Pellentesque neque sem, posuere eget augue pretium, feugiat mattis diam. Mauris libero arcu, elementum sit amet nunc sed, vestibulum posuere sapien. Nullam",
),
new Paragraph(
"ultrices efficitur magna et commodo. Morbi vitae dolor vulputate, dapibus ipsum in, finibus enim. Aliquam dapibus tellus libero. Nullam nulla eros, ullamcorper eu risus at, luctus aliquet nunc. Nunc dictum turpis eu quam suscipit porta. In rutrum scelerisque nunc in consectetur. Pellentesque ut nibh eget neque congue auctor. Nunc dapibus massa elit, vel cursus metus condimentum et. Nunc venenatis dolor eu lobortis fringilla. Nulla sed risus id lectus scelerisque sollicitudin. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.",
),
new Paragraph(
"Nulla lobortis et purus convallis ullamcorper. Nunc scelerisque, urna eu vestibulum feugiat, orci turpis pulvinar odio, vitae faucibus elit tortor et urna. Curabitur eros mauris, mollis a vestibulum nec, vestibulum sed velit. Nam semper metus ut felis ultricies rutrum. Cras hendrerit eros vel placerat vulputate. Proin placerat ",
),
new Paragraph(
"mollis lacus a ultricies. Mauris vel turpis vitae purus suscipit dignissim. Donec egestas molestie libero in suscipit. Aenean auctor tellus convallis eros porttitor, id vehicula risus commodo. Sed accumsan turpis elit, eget molestie tortor efficitur eget. Aliquam ut lectus quis augue pellentesque tincidunt id id quam. Maecenas auctor, lorem eu ornare tempor, lacus metus ultrices turpis, nec feugiat nibh purus id justo.",
),
new Paragraph(
"Sed semper feugiat ante, sit amet accumsan lorem vulputate vel. Morbi interdum, mauris sit amet efficitur mattis, nunc sapien tempor ante, eget maximus ipsum arcu quis dolor. Suspendisse id consequat justo, quis sollicitudin nisi. Duis euismod, velit non faucibus placerat, eros sem fermentum lectus, ut egestas nisi ipsum eget mi. ",
),
new Paragraph(
"Donec vitae mollis libero. Etiam magna leo, auctor sit amet nibh sit amet, interdum finibus nunc. Quisque a pellentesque velit, a laoreet ante.",
),
new Paragraph(
"Quisque fringilla orci quis dui facilisis, quis auctor urna cursus. Mauris eget justo lacus. Integer placerat, leo vitae ullamcorper varius, nulla mauris gravida massa, ac dignissim odio erat eu ante. Duis non dui semper, eleifend neque nec, ultricies ligula. Sed nec sem nec dolor ultrices finibus. Praesent rutrum iaculis mollis. ",
),
new Paragraph(
"Fusce accumsan dui tortor, quis feugiat urna efficitur sed. Fusce viverra tristique lacinia. Sed nec faucibus ipsum, vel pulvinar ligula. Curabitur ut viverra nisl. Nulla nisi tortor, imperdiet et ipsum sit amet, egestas lacinia leo. Quisque interdum mauris non nunc egestas tempor a vehicula diam. Vestibulum convallis quam sit amet tincidunt posuere. Mauris velit sem, fermentum a diam sit amet, pulvinar iaculis lectus. In dolor turpis, cursus id libero sit amet, aliquet ullamcorper urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.",
),
new Paragraph(
"Etiam tincidunt euismod nisi, ut dignissim neque blandit sit amet. Etiam vel velit rhoncus, tincidunt diam quis, dignissim felis. Integer dolor urna, rutrum vitae ultricies ut, sagittis quis felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec pharetra aliquam augue. Donec ",
),
new Paragraph(
"imperdiet placerat augue, nec consequat leo placerat a. Mauris accumsan ornare massa vitae volutpat. Sed commodo purus ac fringilla ultricies. Donec quis urna hendrerit dolor efficitur sollicitudin. Pellentesque diam arcu, dapibus a nisl pretium, auctor lobortis augue.",
),
new Paragraph(
"Aliquam libero lorem, scelerisque a volutpat ac, venenatis eu nisl. Maecenas turpis diam, consequat eget elementum eget, venenatis at lacus. In maximus erat magna, ut hendrerit erat malesuada vel. Suspendisse iaculis, lacus posuere convallis gravida, nisi purus blandit nunc, imperdiet tempor nunc turpis et sapien. Duis euismod id ",
),
new Paragraph(
"ligula ac laoreet. Ut facilisis massa quis turpis imperdiet, eu ornare lorem placerat. Vestibulum pharetra feugiat eleifend. Quisque ornare pretium urna, lacinia aliquam eros placerat et. Integer sit amet auctor ipsum. Morbi imperdiet dictum ex sed lacinia. Curabitur interdum mattis nunc non vestibulum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque odio libero, viverra ac quam eleifend, dignissim euismod nibh. Etiam sit amet semper ante. Morbi in tellus lacinia, bibendum dolor quis, viverra nisi. Proin condimentum purus ipsum, et accumsan sapien finibus ac.",
),
new Paragraph(
"Maecenas congue in leo id faucibus. Etiam porta dapibus ultricies. Nunc ac volutpat magna. Nam pretium dolor ac ultrices tincidunt. Vestibulum pharetra elit vitae lacus pharetra euismod. Pellentesque fringilla lacus ac neque varius sagittis. Mauris tincidunt rutrum velit. Etiam pretium est vitae lacus ultricies, vitae viverra ",
),
new Paragraph(
"turpis auctor. Nulla at lectus pellentesque enim dapibus aliquet eleifend et quam. Suspendisse cursus sed velit et lobortis. Integer sed facilisis ligula, ultrices molestie neque. Nulla porta mauris vitae quam consequat, eget fringilla enim luctus. Integer vitae rhoncus nibh, ac ornare ligula. Sed sed placerat libero. Suspendisse laoreet erat lacus, et lacinia nibh maximus in. Maecenas vitae enim at urna gravida euismod.",
),
new Paragraph(
"Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam lacinia lobortis tortor mollis venenatis. Sed sodales iaculis justo in rhoncus. Proin orci sapien, fermentum nec eleifend in, tristique vel mi. Donec vitae ornare justo, sed rhoncus nibh. Quisque a interdum est, in scelerisque odio. Ut luctus eget ex non ",
),
new Paragraph(
"fringilla. Morbi nec iaculis nisi. Donec porta libero ac ex sollicitudin, vitae interdum erat faucibus. Donec ornare, arcu ullamcorper pretium euismod, nibh nisi consectetur justo, ac aliquet sem eros non nibh. Nulla vitae elementum arcu. Aenean ut consectetur dui. Donec posuere condimentum velit ac hendrerit. Sed aliquet aliquet mi, sed rutrum justo ultrices eget.",
),
new Paragraph(
"Donec volutpat libero dui, ac bibendum nunc eleifend a. Fusce ultricies ligula non sollicitudin lobortis. Integer sit amet elit sapien. Morbi rhoncus bibendum nibh et facilisis. Etiam consectetur elementum sem non elementum. Nunc rutrum sagittis ipsum non sodales. Orci varius natoque penatibus et magnis dis parturient montes, ",
),
new Paragraph(
"nascetur ridiculus mus. Quisque porttitor nulla ultrices mollis porta. Cras non metus sed quam rutrum ultricies. Curabitur aliquet in sem eget auctor. Ut sodales quis leo bibendum venenatis. Etiam pellentesque eros ut metus dignissim commodo. Aliquam vitae sem gravida, convallis ipsum at, imperdiet tellus. Pellentesque consectetur odio sit amet sapien vestibulum aliquam nec id libero. Proin a maximus felis. Aenean molestie vulputate massa, eu eleifend sem consequat id.",
),
new Paragraph(
"Etiam quis ante nec leo faucibus dignissim eu at mi. Nam nec ligula nec sapien rhoncus faucibus. Fusce vestibulum orci libero, vel commodo est congue iaculis. In hac habitasse platea dictumst. Sed lacinia magna eu arcu commodo pretium. Fusce id elementum enim. Mauris tristique tortor dolor, at pretium magna tempor nec. Vivamus non ",
),
new Paragraph(
"dui sit amet odio porttitor tincidunt. Nam pulvinar aliquet tortor tristique tempor. Duis finibus tincidunt elit, at viverra justo sagittis in. Morbi pellentesque gravida mi, in pulvinar metus molestie at. Fusce bibendum eleifend sapien a fermentum. Nam efficitur tellus dignissim, vehicula tortor ac, tristique enim. Aliquam pretium dui interdum varius elementum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec a finibus elit.",
),
new Paragraph(
"Phasellus cursus tortor at justo bibendum aliquam. Sed nec hendrerit nibh, eu finibus tortor. Aenean sit amet dui rutrum, sollicitudin justo eu, condimentum ipsum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas dictum neque lacus, vel posuere eros pretium nec. Morbi ac ante at ",
),
new Paragraph(
"ex semper ultricies ac quis augue. In hac habitasse platea dictumst. Mauris laoreet porta nisl. Sed augue lorem, aliquet in volutpat ut, rhoncus eget nibh. Sed rhoncus arcu diam, accumsan rhoncus sem iaculis ac. Duis dolor magna, semper et tellus non, condimentum volutpat nisi. Donec eget metus eget elit eleifend vestibulum et ut purus.",
),
new Paragraph(
"Nam a dui accumsan, efficitur ex at, commodo eros. Pellentesque sit amet nunc ac odio egestas suscipit id sodales ligula. Duis non mi vitae mi mollis fringilla at sit amet sem. Morbi laoreet mattis dolor sit amet tincidunt. Aliquam erat volutpat. Pellentesque porta sem odio, at lobortis quam commodo vitae. Curabitur ut urna dolor.",
),
new Paragraph(
"Nulla vitae pretium ex. Nulla facilisi. Vestibulum placerat odio eget enim ultrices, et imperdiet tellus consequat. Sed dignissim, erat ut dignissim interdum, dui mi rhoncus nunc, id rhoncus turpis nunc eu risus. Mauris leo orci, euismod sit amet velit ac, condimentum dictum dui. Cras cursus dolor augue, et vestibulum lorem ",
),
new Paragraph(
"fringilla in. Nulla fermentum odio vehicula justo placerat, et aliquet velit vulputate. Sed aliquam auctor dictum. Phasellus sit amet sollicitudin elit. Cras eget gravida ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis tortor erat, ornare id feugiat eget, pellentesque at lectus. Sed vitae nisi ullamcorper, tincidunt augue vitae, accumsan ligula. Curabitur ut lobortis lacus, imperdiet placerat arcu.",
),
new Paragraph(
"Sed vestibulum tempor nulla vel dignissim. Phasellus imperdiet, dolor nec mollis tempor, nulla nibh pretium nibh, nec elementum lacus neque in sapien. Nam et eleifend lorem. Nam pretium molestie enim quis porta. Proin eu pharetra enim. Etiam a velit eget augue congue tempor. Interdum et malesuada fames ac ante ipsum primis in ",
),
new Paragraph("faucibus. Sed urna tellus, euismod ac pharetra nec, ultrices vel nisi."),
new Paragraph(
"Phasellus at arcu eget tellus mattis ultricies non quis urna. Vestibulum non eros fringilla, porttitor massa id, ornare metus. Quisque lacinia, massa a ornare vulputate, ex lectus ullamcorper ligula, eget facilisis mi turpis at dolor. Curabitur posuere elementum enim, non placerat tortor tincidunt sit amet. Pellentesque habitant ",
),
new Paragraph(
"morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam fermentum ut felis et dapibus. Ut consectetur finibus bibendum. Phasellus semper sapien neque, nec consequat nibh convallis et. Nunc nec egestas enim. Nulla facilisi.",
),
new Paragraph(
"Quisque sed nibh sed lorem placerat ornare sed nec sapien. Morbi et risus vitae magna varius varius eget at leo. Curabitur a eleifend elit. Mauris augue nulla, convallis vel ante in, consequat feugiat orci. Donec sagittis risus nibh, eget porta purus faucibus non. Curabitur ultrices, ex et placerat rutrum, velit odio accumsan ",
),
new Paragraph(
"nulla, et elementum mi leo in velit. Pellentesque auctor egestas ultricies. In viverra est a mauris sollicitudin, a laoreet augue cursus. Vestibulum non sollicitudin massa. Curabitur ac tellus metus. Pellentesque hendrerit dolor sed mi vestibulum imperdiet. Nulla vitae odio ultrices, tempor enim sed, vestibulum eros. Cras libero ex, malesuada nec porttitor sit amet, efficitur sit amet ligula.",
),
new Paragraph(
"Morbi pellentesque tempus felis, id iaculis quam euismod non. Sed scelerisque id massa eu elementum. Vestibulum id malesuada arcu. Maecenas eget placerat sem, at consectetur orci. Nullam interdum erat urna, ac rhoncus odio feugiat sed. Morbi rutrum auctor sem eget pulvinar. Suspendisse egestas tempor volutpat.",
),
new Paragraph(
"Vivamus euismod, sem eget molestie rhoncus, metus dui laoreet lacus, et lobortis est metus ut felis. Aenean imperdiet lacus nunc, vitae molestie orci ultrices nec. Cras egestas maximus diam, vitae efficitur nisl luctus imperdiet. Nulla pellentesque sodales ante, nec facilisis turpis. Vivamus at hendrerit enim, ac dictum lorem. Cras ",
),
new Paragraph(
"congue accumsan dui, non pretium sem auctor quis. Nunc a mauris vehicula, elementum ex vitae, sollicitudin eros. Nunc non sapien vitae justo sodales condimentum. Praesent nisl felis, tristique ac odio at, rhoncus porttitor orci. Morbi egestas placerat iaculis.",
),
new Paragraph(
"Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In at lorem nec neque faucibus ultricies ut in ipsum.",
),
new Paragraph(
"Suspendisse fermentum feugiat augue eu convallis. Maecenas eros velit, efficitur sit amet posuere sed, tristique sit amet nisi. Donec vel convallis justo, id tempor neque. Nunc pulvinar maximus nulla, vitae congue lacus cursus ut. Morbi at mollis est, a vehicula nisi. Cras venenatis nibh vel massa interdum commodo. Nulla mattis ",
),
new Paragraph(
"neque sed sem bibendum, iaculis hendrerit neque fringilla. Sed a lobortis orci. Morbi in est sed libero vestibulum semper. Suspendisse potenti. Aliquam pretium erat tellus, in suscipit lorem aliquet iaculis. Aenean ac viverra ipsum. Sed at diam luctus, pharetra lorem vel, aliquam magna. Donec mollis orci eget enim efficitur ultricies. Proin neque diam, dignissim euismod ex vel, sollicitudin sodales sapien.",
),
new Paragraph(
"Sed a egestas nunc, a ullamcorper est. Aenean vulputate fringilla justo non vestibulum. Donec ac dolor in nisl finibus tristique. Donec sed turpis at felis congue porttitor sed sit amet metus. In in ex nulla. Donec sodales vel velit ut congue. Nullam vitae egestas purus. Vivamus non mi consequat, molestie enim nec, hendrerit mi.",
),
];
// cspell: enable
const doc = new Document({
sections: [
{
@ -185,19 +49,6 @@ const doc = new Document({
}),
],
}),
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun({
children: [
"Footer - Page in section ",
PageNumber.CURRENT_SECTION,
" of ",
PageNumber.TOTAL_PAGES_IN_SECTION,
],
}),
],
}),
],
}),
first: new Footer({
@ -219,96 +70,6 @@ const doc = new Document({
children: [new TextRun("First Page"), new PageBreak()],
}),
new Paragraph("Second Page"),
...createLoremIpsumParagraphs(),
new Paragraph({
children: [new TextRun("Next Page"), new PageBreak()],
}),
...createLoremIpsumParagraphs(),
],
},
{
properties: {
titlePage: true,
},
headers: {
default: new Header({
children: [
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun("My Title "),
new TextRun({
children: ["Page ", PageNumber.CURRENT],
}),
],
}),
],
}),
first: new Header({
children: [
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun("First Page Header "),
new TextRun({
children: ["Page ", PageNumber.CURRENT],
}),
],
}),
],
}),
},
footers: {
default: new Footer({
children: [
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun("My Title "),
new TextRun({
children: ["Footer - Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
}),
],
}),
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun({
children: [
"Footer - Page in section ",
PageNumber.CURRENT_SECTION,
" of ",
PageNumber.TOTAL_PAGES_IN_SECTION,
],
}),
],
}),
],
}),
first: new Footer({
children: [
new Paragraph({
alignment: AlignmentType.RIGHT,
children: [
new TextRun("First Page Footer "),
new TextRun({
children: ["Page ", PageNumber.CURRENT],
}),
],
}),
],
}),
},
children: [
new Paragraph({
children: [new TextRun("First Page"), new PageBreak()],
}),
new Paragraph("Second Page"),
...createLoremIpsumParagraphs(),
new Paragraph({
children: [new TextRun("Next Page"), new PageBreak()],
}),
...createLoremIpsumParagraphs(),
],
},
],

View File

@ -1,7 +1,7 @@
// Example of how you would create a table and add data to it
import * as fs from "fs";
import { BorderStyle, Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
const doc = new Document({
sections: [
@ -67,173 +67,6 @@ const doc = new Document({
}),
],
}),
new Paragraph("Table with borders"),
new Table({
rows: [
new TableRow({
children: [
new TableCell({
borders: {
top: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
bottom: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
left: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
right: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
},
children: [new Paragraph("Dash small gap border")],
}),
new TableCell({
borders: {
top: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
bottom: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
left: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
right: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "000000",
},
},
children: [new Paragraph("Dash small gap border")],
}),
],
}),
new TableRow({
children: [
new TableCell({
borders: {
top: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
bottom: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
left: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
right: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
},
children: [new Paragraph("Double border")],
}),
new TableCell({
borders: {
top: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
bottom: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
left: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
right: {
style: BorderStyle.DOUBLE,
size: 1,
color: "ff0000",
},
},
children: [new Paragraph("Double border")],
}),
],
}),
new TableRow({
children: [
new TableCell({
borders: {
top: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
bottom: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
left: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
right: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
},
children: [new Paragraph("Should have no border")],
}),
new TableCell({
borders: {
top: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
bottom: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
left: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
right: {
style: BorderStyle.NONE,
size: 0,
color: "ffffff",
},
},
children: [new Paragraph("Should have no border")],
}),
],
}),
],
}),
],
},
],

View File

@ -2,6 +2,7 @@
import * as fs from "fs";
import {
AlignmentType,
BorderStyle,
Document,
FrameAnchorType,
@ -20,6 +21,7 @@ const doc = new Document({
children: [
new Paragraph({
frame: {
type: "absolute",
position: {
x: 1000,
y: 3000,
@ -30,6 +32,54 @@ const doc = new Document({
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
},
border: {
top: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
bottom: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
left: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
right: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
},
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
new TextRun({
children: [new Tab(), "Github is the best"],
bold: true,
}),
],
}),
new Paragraph({
frame: {
type: "alignment",
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.TOP,
@ -73,6 +123,59 @@ const doc = new Document({
}),
],
}),
new Paragraph({
frame: {
type: "alignment",
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.BOTTOM,
},
},
border: {
top: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
bottom: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
left: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
right: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
},
alignment: AlignmentType.RIGHT,
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
}),
new TextRun({
children: [new Tab(), "Github is the best"],
bold: true,
}),
],
}),
],
},
],

40
demo/91-custom-fonts.ts Normal file
View File

@ -0,0 +1,40 @@
// Simple example to add text to a document
import * as fs from "fs";
import { CharacterSet, Document, Packer, Paragraph, Tab, TextRun } from "docx";
const font = fs.readFileSync("./demo/assets/Pacifico.ttf");
const doc = new Document({
sections: [
{
properties: {},
children: [
new Paragraph({
run: {
font: "Pacifico",
},
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
size: 40,
font: "Pacifico",
}),
new TextRun({
children: [new Tab(), "Github is the best"],
bold: true,
font: "Pacifico",
}),
],
}),
],
},
],
fonts: [{ name: "Pacifico", data: font, characterSet: CharacterSet.ANSI }],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

View File

@ -0,0 +1,44 @@
// Simple example to add text to a document
import * as fs from "fs";
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
const font = fs.readFileSync("./demo/assets/Pacifico.ttf");
const doc = new Document({
styles: {
default: {
document: {
run: {
font: "Pacifico",
},
},
},
},
sections: [
{
properties: {},
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: "Foo Bar",
bold: true,
size: 40,
}),
new TextRun({
children: [new Tab(), "Github is the best"],
bold: true,
}),
],
}),
],
},
],
fonts: [{ name: "Pacifico", data: font, characterSet: "00" }],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

BIN
demo/assets/Pacifico.ttf Normal file

Binary file not shown.

10
demo/tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./",
"paths": {
"docx": ["../build"]
}
},
"include": ["../demo"]
}

1240
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "docx",
"version": "8.4.0",
"version": "8.5.0",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"type": "module",
"main": "build/index.umd.js",
@ -97,7 +97,7 @@
"unzipper": "^0.10.11",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.3.1",
"vite-plugin-node-polyfills": "^0.9.0",
"vite-plugin-node-polyfills": "^0.19.0",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^1.1.0"
},

View File

@ -36,7 +36,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(17);
expect(fileNames).has.length(19);
expect(fileNames).to.include("word/document.xml");
expect(fileNames).to.include("word/styles.xml");
expect(fileNames).to.include("docProps/core.xml");
@ -47,7 +47,9 @@ describe("Compiler", () => {
expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
expect(fileNames).to.include("word/settings.xml");
expect(fileNames).to.include("word/comments.xml");
expect(fileNames).to.include("word/fontTable.xml");
expect(fileNames).to.include("word/_rels/document.xml.rels");
expect(fileNames).to.include("word/_rels/fontTable.xml.rels");
expect(fileNames).to.include("[Content_Types].xml");
expect(fileNames).to.include("_rels/.rels");
},
@ -94,7 +96,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(25);
expect(fileNames).has.length(27);
expect(fileNames).to.include("word/header1.xml");
expect(fileNames).to.include("word/_rels/header1.xml.rels");
@ -127,12 +129,10 @@ describe("Compiler", () => {
const spy = vi.spyOn(compiler["formatter"], "format");
compiler.compile(file);
expect(spy).toBeCalledTimes(13);
expect(spy).toBeCalledTimes(15);
});
it("should work with media datas", () => {
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
const file = new File({
sections: [
{
@ -182,5 +182,14 @@ describe("Compiler", () => {
compiler.compile(file);
});
it("should work with fonts", () => {
const file = new File({
sections: [],
fonts: [{ name: "Pacifico", data: Buffer.from("") }],
});
compiler.compile(file);
});
});
});

View File

@ -2,6 +2,7 @@ import JSZip from "jszip";
import xml from "xml";
import { File } from "@file/file";
import { obfuscate } from "@file/fonts/obfuscate-ttf-to-odttf";
import { Formatter } from "../formatter";
import { ImageReplacer } from "./image-replacer";
@ -31,6 +32,8 @@ interface IXmlifyedFileMapping {
readonly FootNotesRelationships: IXmlifyedFile;
readonly Settings: IXmlifyedFile;
readonly Comments?: IXmlifyedFile;
readonly FontTable?: IXmlifyedFile;
readonly FontTableRelationships?: IXmlifyedFile;
}
export class Compiler {
@ -63,6 +66,11 @@ export class Compiler {
zip.file(`word/media/${fileName}`, stream);
}
for (const { data: buffer, name, fontKey } of file.FontTable.fontOptionsWithKey) {
const [nameWithoutExtension] = name.split(".");
zip.file(`word/fonts/${nameWithoutExtension}.odttf`, obfuscate(buffer, fontKey));
}
return zip;
}
@ -439,6 +447,40 @@ export class Compiler {
),
path: "word/comments.xml",
},
FontTable: {
data: xml(
this.formatter.format(file.FontTable.View, {
viewWrapper: file.Document,
file,
stack: [],
}),
{
indent: prettify,
declaration: {
standalone: "yes",
encoding: "UTF-8",
},
},
),
path: "word/fontTable.xml",
},
FontTableRelationships: {
data: (() =>
xml(
this.formatter.format(file.FontTable.Relationships, {
viewWrapper: file.Document,
file,
stack: [],
}),
{
indent: prettify,
declaration: {
encoding: "UTF-8",
},
},
))(),
path: "word/_rels/fontTable.xml.rels",
},
};
}
}

View File

@ -29,7 +29,16 @@ describe("ContentTypes", () => {
Default: { _attr: { ContentType: "application/vnd.openxmlformats-package.relationships+xml", Extension: "rels" } },
});
expect(tree["Types"][7]).to.deep.equal({ Default: { _attr: { ContentType: "application/xml", Extension: "xml" } } });
expect(tree["Types"][8]).to.deep.equal({
Default: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.obfuscatedFont",
Extension: "odttf",
},
},
});
expect(tree["Types"][9]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
@ -37,7 +46,7 @@ describe("ContentTypes", () => {
},
},
});
expect(tree["Types"][9]).to.deep.equal({
expect(tree["Types"][10]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
@ -45,7 +54,7 @@ describe("ContentTypes", () => {
},
},
});
expect(tree["Types"][10]).to.deep.equal({
expect(tree["Types"][11]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-package.core-properties+xml",
@ -53,7 +62,7 @@ describe("ContentTypes", () => {
},
},
});
expect(tree["Types"][11]).to.deep.equal({
expect(tree["Types"][12]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.custom-properties+xml",
@ -61,7 +70,7 @@ describe("ContentTypes", () => {
},
},
});
expect(tree["Types"][12]).to.deep.equal({
expect(tree["Types"][13]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
@ -69,7 +78,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.numbering+xml",
@ -77,7 +86,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.footnotes+xml",
@ -85,7 +94,7 @@ describe("ContentTypes", () => {
},
},
});
expect(tree["Types"][15]).to.deep.equal({
expect(tree["Types"][16]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
@ -102,7 +111,7 @@ describe("ContentTypes", () => {
contentTypes.addFooter(102);
const tree = new Formatter().format(contentTypes);
expect(tree["Types"][17]).to.deep.equal({
expect(tree["Types"][19]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
@ -111,7 +120,7 @@ describe("ContentTypes", () => {
},
});
expect(tree["Types"][18]).to.deep.equal({
expect(tree["Types"][20]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
@ -128,7 +137,7 @@ describe("ContentTypes", () => {
contentTypes.addHeader(202);
const tree = new Formatter().format(contentTypes);
expect(tree["Types"][17]).to.deep.equal({
expect(tree["Types"][19]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
@ -137,7 +146,7 @@ describe("ContentTypes", () => {
},
});
expect(tree["Types"][18]).to.deep.equal({
expect(tree["Types"][20]).to.deep.equal({
Override: {
_attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",

View File

@ -20,6 +20,7 @@ export class ContentTypes extends XmlComponent {
this.root.push(new Default("image/gif", "gif"));
this.root.push(new Default("application/vnd.openxmlformats-package.relationships+xml", "rels"));
this.root.push(new Default("application/xml", "xml"));
this.root.push(new Default("application/vnd.openxmlformats-officedocument.obfuscatedFont", "odttf"));
this.root.push(
new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "/word/document.xml"),
@ -33,6 +34,7 @@ export class ContentTypes extends XmlComponent {
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", "/word/footnotes.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", "/word/settings.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml", "/word/comments.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml", "/word/fontTable.xml"));
}
public addFooter(index: number): void {

View File

@ -1,5 +1,6 @@
import { ICommentsOptions } from "@file/paragraph/run/comment-run";
import { ICompatibilityOptions } from "@file/settings/compatibility";
import { FontOptions } from "@file/fonts/font-table";
import { StringContainer, XmlComponent } from "@file/xml-components";
import { dateTimeValue } from "@util/values";
@ -40,6 +41,7 @@ export interface IPropertiesOptions {
readonly customProperties?: readonly ICustomPropertyOptions[];
readonly evenAndOddHeaderAndFooters?: boolean;
readonly defaultTabStop?: number;
readonly fonts?: readonly FontOptions[];
}
// <xs:element name="coreProperties" type="CT_CoreProperties"/>

View File

@ -1,3 +1,4 @@
import { XmlComponent } from "./xml-components";
import { Document, IDocumentOptions } from "./document";
import { Footer } from "./footer/footer";
import { FootNotes } from "./footnotes";
@ -5,7 +6,7 @@ import { Header } from "./header/header";
import { Relationships } from "./relationships";
export interface IViewWrapper {
readonly View: Document | Footer | Header | FootNotes;
readonly View: Document | Footer | Header | FootNotes | XmlComponent;
readonly Relationships: Relationships;
}

View File

@ -17,6 +17,7 @@ import { Styles } from "./styles";
import { ExternalStylesFactory } from "./styles/external-styles-factory";
import { DefaultStylesFactory } from "./styles/factory";
import { FileChild } from "./file-child";
import { FontWrapper } from "./fonts/font-wrapper";
export interface ISectionOptions {
readonly headers?: {
@ -53,6 +54,7 @@ export class File {
private readonly appProperties: AppProperties;
private readonly styles: Styles;
private readonly comments: Comments;
private readonly fontWrapper: FontWrapper;
public constructor(options: IPropertiesOptions) {
this.coreProperties = new CoreProperties({
@ -109,6 +111,8 @@ export class File {
this.footnotesWrapper.View.createFootNote(parseFloat(key), options.footnotes[key].children);
}
}
this.fontWrapper = new FontWrapper(options.fonts ?? []);
}
private addSection({ headers = {}, footers = {}, children, properties }: ISectionOptions): void {
@ -292,4 +296,8 @@ export class File {
public get Comments(): Comments {
return this.comments;
}
public get FontTable(): FontWrapper {
return this.fontWrapper;
}
}

View File

@ -0,0 +1,33 @@
import { XmlComponent } from "@file/xml-components";
import { CharacterSet, createFont } from "./font";
export const createRegularFont = ({
name,
index,
fontKey,
characterSet,
}: {
readonly name: string;
readonly index: number;
readonly fontKey: string;
readonly characterSet?: (typeof CharacterSet)[keyof typeof CharacterSet];
}): XmlComponent =>
createFont({
name,
sig: {
usb0: "E0002AFF",
usb1: "C000247B",
usb2: "00000009",
usb3: "00000000",
csb0: "000001FF",
csb1: "00000000",
},
charset: characterSet,
family: "auto",
pitch: "variable",
embedRegular: {
fontKey,
id: `rId${index}`,
},
});

View File

@ -0,0 +1,44 @@
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { createRegularFont } from "./create-regular-font";
import { FontOptionsWithKey } from "./font-wrapper";
import { CharacterSet } from "./font";
// <xsd:complexType name="CT_FontsList">
// <xsd:sequence>
// <xsd:element name="font" type="CT_Font" minOccurs="0" maxOccurs="unbounded"/>
// </xsd:sequence>
// </xsd:complexType>
export type FontOptions = {
readonly name: string;
readonly data: Buffer;
readonly characterSet?: (typeof CharacterSet)[keyof typeof CharacterSet];
};
export const createFontTable = (fonts: readonly FontOptionsWithKey[]): XmlComponent =>
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_Font_topic_ID0ERNCU.html
// http://www.datypic.com/sc/ooxml/e-w_fonts.html
new BuilderElement({
name: "w:fonts",
attributes: {
mc: { key: "xmlns:mc", value: "http://schemas.openxmlformats.org/markup-compatibility/2006" },
r: { key: "xmlns:r", value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships" },
w: { key: "xmlns:w", value: "http://schemas.openxmlformats.org/wordprocessingml/2006/main" },
w14: { key: "xmlns:w14", value: "http://schemas.microsoft.com/office/word/2010/wordml" },
w15: { key: "xmlns:w15", value: "http://schemas.microsoft.com/office/word/2012/wordml" },
w16cex: { key: "xmlns:w16cex", value: "http://schemas.microsoft.com/office/word/2018/wordml/cex" },
w16cid: { key: "xmlns:w16cid", value: "http://schemas.microsoft.com/office/word/2016/wordml/cid" },
w16: { key: "xmlns:w16", value: "http://schemas.microsoft.com/office/word/2018/wordml" },
w16sdtdh: { key: "xmlns:w16sdtdh", value: "http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" },
w16se: { key: "xmlns:w16se", value: "http://schemas.microsoft.com/office/word/2015/wordml/symex" },
Ignorable: { key: "mc:Ignorable", value: "w14 w15 w16se w16cid w16 w16cex w16sdtdh" },
},
children: fonts.map((font, i) =>
createRegularFont({
name: font.name,
index: i + 1,
fontKey: font.fontKey,
}),
),
});

View File

@ -0,0 +1,36 @@
import { IViewWrapper } from "@file/document-wrapper";
import { Relationships } from "@file/relationships";
import { XmlComponent } from "@file/xml-components";
import { uniqueUuid } from "@util/convenience-functions";
import { FontOptions, createFontTable } from "./font-table";
export type FontOptionsWithKey = FontOptions & { readonly fontKey: string };
export class FontWrapper implements IViewWrapper {
private readonly fontTable: XmlComponent;
private readonly relationships: Relationships;
public readonly fontOptionsWithKey: readonly FontOptionsWithKey[] = [];
public constructor(public readonly options: readonly FontOptions[]) {
this.fontOptionsWithKey = options.map((o) => ({ ...o, fontKey: uniqueUuid() }));
this.fontTable = createFontTable(this.fontOptionsWithKey);
this.relationships = new Relationships();
for (let i = 0; i < options.length; i++) {
this.relationships.createRelationship(
i + 1,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/font",
`fonts/${options[i].name}.odttf`,
);
}
}
public get View(): XmlComponent {
return this.fontTable;
}
public get Relationships(): Relationships {
return this.relationships;
}
}

223
src/file/fonts/font.spec.ts Normal file
View File

@ -0,0 +1,223 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { createFont } from "./font";
describe("font", () => {
it("should work", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
altName: "Times New Roman",
family: "roman",
charset: "00",
panose1: "02020603050405020304",
pitch: "variable",
embedRegular: {
id: "rId0",
fontKey: "00000000-0000-0000-0000-000000000000",
},
}),
);
expect(tree).to.deep.equal({
"w:font": [
{
_attr: {
"w:name": "Times New Roman",
},
},
{
"w:altName": {
_attr: {
"w:val": "Times New Roman",
},
},
},
{
"w:panose1": {
_attr: {
"w:val": "02020603050405020304",
},
},
},
{
"w:charset": {
_attr: {
"w:val": "00",
},
},
},
{
"w:family": {
_attr: {
"w:val": "roman",
},
},
},
{
"w:pitch": {
_attr: {
"w:val": "variable",
},
},
},
{
"w:embedRegular": {
_attr: {
"r:id": "rId0",
"w:fontKey": "{00000000-0000-0000-0000-000000000000}",
},
},
},
],
});
});
it("should work for embedBold", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
embedBold: {
id: "rId0",
fontKey: "00000000-0000-0000-0000-000000000000",
},
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:embedBold": {
_attr: {
"r:id": "rId0",
"w:fontKey": "{00000000-0000-0000-0000-000000000000}",
},
},
},
]),
});
});
it("should work for embedBoldItalic", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
embedBoldItalic: {
id: "rId0",
fontKey: "00000000-0000-0000-0000-000000000000",
},
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:embedBoldItalic": {
_attr: {
"r:id": "rId0",
"w:fontKey": "{00000000-0000-0000-0000-000000000000}",
},
},
},
]),
});
});
it("should work for embedItalic", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
embedItalic: {
id: "rId0",
fontKey: "00000000-0000-0000-0000-000000000000",
},
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:embedItalic": {
_attr: {
"r:id": "rId0",
"w:fontKey": "{00000000-0000-0000-0000-000000000000}",
},
},
},
]),
});
});
it("should work for notTrueType", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
embedRegular: {
id: "rId0",
fontKey: "00000000-0000-0000-0000-000000000000",
subsetted: true,
},
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:embedRegular": [
{
_attr: {
"r:id": "rId0",
"w:fontKey": "{00000000-0000-0000-0000-000000000000}",
},
},
{
"w:subsetted": {},
},
],
},
]),
});
});
it("should work for subsetted", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
notTrueType: true,
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:notTrueType": {},
},
]),
});
});
it("should work without fontKey", () => {
const tree = new Formatter().format(
createFont({
name: "Times New Roman",
embedItalic: {
id: "rId0",
},
}),
);
expect(tree).toStrictEqual({
"w:font": expect.arrayContaining([
{
"w:embedItalic": {
_attr: {
"r:id": "rId0",
},
},
},
]),
});
});
});

156
src/file/fonts/font.ts Normal file
View File

@ -0,0 +1,156 @@
import { BuilderElement, createStringElement, OnOffElement, XmlComponent } from "@file/xml-components";
// <xsd:complexType name="CT_Font">
// <xsd:sequence>
// <xsd:element name="altName" type="CT_String" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="panose1" type="CT_Panose" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="charset" type="CT_Charset" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="family" type="CT_FontFamily" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="notTrueType" type="CT_OnOff" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="pitch" type="CT_Pitch" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="sig" type="CT_FontSig" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="embedRegular" type="CT_FontRel" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="embedBold" type="CT_FontRel" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="embedItalic" type="CT_FontRel" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="embedBoldItalic" type="CT_FontRel" minOccurs="0" maxOccurs="1"/>
// </xsd:sequence>
// <xsd:attribute name="name" type="s:ST_String" use="required"/>
// </xsd:complexType>
// <xsd:complexType name="CT_FontRel">
// <xsd:complexContent>
// <xsd:extension base="CT_Rel">
// <xsd:attribute name="fontKey" type="s:ST_Guid" />
// <xsd:attribute name="subsetted" type="s:ST_OnOff" />
// </xsd:extension>
// </xsd:complexContent>
// </xsd:complexType>
// http://www.datypic.com/sc/ooxml/e-w_embedRegular-1.html
export interface IFontRelationshipOptions {
/**
* Relationship to Part
*/
readonly id: string;
/**
* Embedded Font Obfuscation Key
*/
readonly fontKey?: string;
/**
* Embedded Font Is Subsetted
*/
readonly subsetted?: boolean;
}
export const CharacterSet = {
ANSI: "00",
DEFAULT: "01",
SYMBOL: "02",
MAC: "4D",
JIS: "80",
HANGUL: "81",
JOHAB: "82",
GB_2312: "86",
CHINESEBIG5: "88",
GREEK: "A1",
TURKISH: "A2",
VIETNAMESE: "A3",
HEBREW: "B1",
ARABIC: "B2",
BALTIC: "BA",
RUSSIAN: "CC",
THAI: "DE",
EASTEUROPE: "EE",
OEM: "FF",
} as const;
export type FontOptions = {
readonly name: string;
readonly altName?: string;
readonly panose1?: string;
readonly charset?: (typeof CharacterSet)[keyof typeof CharacterSet];
readonly family?: string;
readonly notTrueType?: boolean;
readonly pitch?: string;
readonly sig?: {
readonly usb0: string;
readonly usb1: string;
readonly usb2: string;
readonly usb3: string;
readonly csb0: string;
readonly csb1: string;
};
readonly embedRegular?: IFontRelationshipOptions;
readonly embedBold?: IFontRelationshipOptions;
readonly embedItalic?: IFontRelationshipOptions;
readonly embedBoldItalic?: IFontRelationshipOptions;
};
const createFontRelationship = ({ id, fontKey, subsetted }: IFontRelationshipOptions, name: string): XmlComponent =>
new BuilderElement({
name,
attributes: {
id: { key: "r:id", value: id },
...(fontKey ? { fontKey: { key: "w:fontKey", value: `{${fontKey}}` } } : {}),
},
children: [...(subsetted ? [new OnOffElement("w:subsetted", subsetted)] : [])],
});
export const createFont = ({
name,
altName,
panose1,
charset,
family,
notTrueType,
pitch,
sig,
embedRegular,
embedBold,
embedItalic,
embedBoldItalic,
}: FontOptions): XmlComponent =>
// http://www.datypic.com/sc/ooxml/e-w_font-1.html
new BuilderElement({
name: "w:font",
attributes: {
name: { key: "w:name", value: name },
},
children: [
// http://www.datypic.com/sc/ooxml/e-w_altName-1.html
...(altName ? [createStringElement("w:altName", altName)] : []),
// http://www.datypic.com/sc/ooxml/e-w_panose1-1.html
...(panose1 ? [createStringElement("w:panose1", panose1)] : []),
// http://www.datypic.com/sc/ooxml/e-w_charset-1.html
...(charset ? [createStringElement("w:charset", charset)] : []),
// http://www.datypic.com/sc/ooxml/e-w_family-1.html
...(family ? [createStringElement("w:family", family)] : []),
// http://www.datypic.com/sc/ooxml/e-w_notTrueType-1.html
...(notTrueType ? [new OnOffElement("w:notTrueType", notTrueType)] : []),
...(pitch ? [createStringElement("w:pitch", pitch)] : []),
// http://www.datypic.com/sc/ooxml/e-w_sig-1.html
...(sig
? [
new BuilderElement({
name: "w:sig",
attributes: {
usb0: { key: "w:usb0", value: sig.usb0 },
usb1: { key: "w:usb1", value: sig.usb1 },
usb2: { key: "w:usb2", value: sig.usb2 },
usb3: { key: "w:usb3", value: sig.usb3 },
csb0: { key: "w:csb0", value: sig.csb0 },
csb1: { key: "w:csb1", value: sig.csb1 },
},
}),
]
: []),
// http://www.datypic.com/sc/ooxml/e-w_embedRegular-1.html
...(embedRegular ? [createFontRelationship(embedRegular, "w:embedRegular")] : []),
// http://www.datypic.com/sc/ooxml/e-w_embedBold-1.html
...(embedBold ? [createFontRelationship(embedBold, "w:embedBold")] : []),
// http://www.datypic.com/sc/ooxml/e-w_embedItalic-1.html
...(embedItalic ? [createFontRelationship(embedItalic, "w:embedItalic")] : []),
// http://www.datypic.com/sc/ooxml/e-w_embedBoldItalic-1.html
...(embedBoldItalic ? [createFontRelationship(embedBoldItalic, "w:embedBoldItalic")] : []),
],
});

1
src/file/fonts/index.ts Normal file
View File

@ -0,0 +1 @@
export { CharacterSet } from "./font";

View File

@ -0,0 +1,22 @@
const obfuscatedStartOffset = 0;
const obfuscatedEndOffset = 32;
const guidSize = 32;
export const obfuscate = (buf: Buffer, fontKey: string): Buffer => {
const guid = fontKey.replace(/-/g, "");
if (guid.length !== guidSize) {
throw new Error(`Error: Cannot extract GUID from font filename: ${fontKey}`);
}
const hexStrings = guid.replace(/(..)/g, "$1 ").trim().split(" ");
const hexNumbers = hexStrings.map((hexString) => parseInt(hexString, 16));
// eslint-disable-next-line functional/immutable-data
hexNumbers.reverse();
const bytesToObfuscate = buf.slice(obfuscatedStartOffset, obfuscatedEndOffset);
// eslint-disable-next-line no-bitwise
const obfuscatedBytes = bytesToObfuscate.map((byte, i) => byte ^ hexNumbers[i % hexNumbers.length]);
const out = Buffer.concat([buf.slice(0, obfuscatedStartOffset), obfuscatedBytes, buf.slice(obfuscatedEndOffset)]);
return out;
};

View File

@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { obfuscate } from "./obfuscate-ttf-to-odttf";
describe("obfuscate", () => {
it("should work", () => {
const buffer = obfuscate(Buffer.from(""), "00000000-0000-0000-0000-000000000000");
expect(buffer).toBeDefined();
});
it("should throw error if uuid is not correct", () => {
expect(() => obfuscate(Buffer.from(""), "bad-uuid")).toThrowError();
});
});

View File

@ -18,3 +18,4 @@ export * from "./shared";
export * from "./border";
export * from "./vertical-align";
export * from "./checkbox";
export * from "./fonts";

View File

@ -3,154 +3,144 @@ import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared";
import { FrameAnchorType, FrameProperties } from "./frame-properties";
import { FrameAnchorType, createFrameProperties } from "./frame-properties";
describe("FrameProperties", () => {
describe("#constructor()", () => {
it("should create", () => {
const currentFrameProperties = new FrameProperties({
position: {
x: 1000,
y: 3000,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.TOP,
},
});
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:xAlign": "center",
"w:y": 3000,
"w:yAlign": "top",
},
},
});
describe("createFrameProperties", () => {
it("should create", () => {
const currentFrameProperties = createFrameProperties({
type: "absolute",
position: {
x: 1000,
y: 3000,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
});
it("should create with the space attribute", () => {
const currentFrameProperties = new FrameProperties({
position: {
x: 1000,
y: 3000,
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:y": 3000,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.TOP,
},
space: {
horizontal: 100,
vertical: 200,
},
});
},
});
});
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:xAlign": "center",
"w:y": 3000,
"w:yAlign": "top",
"w:hSpace": 100,
"w:vSpace": 200,
},
},
});
it("should create with the space attribute", () => {
const currentFrameProperties = createFrameProperties({
type: "absolute",
position: {
x: 1000,
y: 3000,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
space: {
horizontal: 100,
vertical: 200,
},
});
it("should create without x and y", () => {
const currentFrameProperties = new FrameProperties({
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:y": 3000,
"w:hSpace": 100,
"w:vSpace": 200,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.TOP,
},
space: {
horizontal: 100,
vertical: 200,
},
});
},
});
});
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:xAlign": "center",
"w:yAlign": "top",
"w:hSpace": 100,
"w:vSpace": 200,
},
},
});
it("should create without x and y", () => {
const currentFrameProperties = createFrameProperties({
type: "alignment",
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
alignment: {
x: HorizontalPositionAlign.CENTER,
y: VerticalPositionAlign.TOP,
},
space: {
horizontal: 100,
vertical: 200,
},
});
it("should create without alignments", () => {
const currentFrameProperties = new FrameProperties({
position: {
x: 1000,
y: 3000,
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:xAlign": "center",
"w:yAlign": "top",
"w:hSpace": 100,
"w:vSpace": 200,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
space: {
horizontal: 100,
vertical: 200,
},
});
},
});
});
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:y": 3000,
"w:hSpace": 100,
"w:vSpace": 200,
},
it("should create without alignments", () => {
const currentFrameProperties = createFrameProperties({
type: "absolute",
position: {
x: 1000,
y: 3000,
},
width: 4000,
height: 1000,
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
space: {
horizontal: 100,
vertical: 200,
},
});
const tree = new Formatter().format(currentFrameProperties);
expect(tree).to.deep.equal({
"w:framePr": {
_attr: {
"w:h": 1000,
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:y": 3000,
"w:hSpace": 100,
"w:vSpace": 200,
},
});
},
});
});
});

View File

@ -1,7 +1,7 @@
// http://officeopenxml.com/WPparagraph-textFrames.php
import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/alignment";
import { HeightRule } from "@file/table";
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { BuilderElement, XmlComponent } from "@file/xml-components";
export const DropCapType = {
NONE: "none",
@ -44,6 +44,7 @@ interface IBaseFrameOptions {
}
export interface IXYFrameOptions extends IBaseFrameOptions {
readonly type: "absolute";
readonly position: {
readonly x: number;
readonly y: number;
@ -51,6 +52,7 @@ export interface IXYFrameOptions extends IBaseFrameOptions {
}
export interface IAlignmentFrameOptions extends IBaseFrameOptions {
readonly type: "alignment";
readonly alignment: {
readonly x: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly y: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
@ -61,7 +63,24 @@ export interface IAlignmentFrameOptions extends IBaseFrameOptions {
// https://stackoverflow.com/q/46370222/3481582
export type IFrameOptions = IXYFrameOptions | IAlignmentFrameOptions;
export class FramePropertiesAttributes extends XmlAttributeComponent<{
// <xsd:complexType name="CT_FramePr">
// <xsd:attribute name="dropCap" type="ST_DropCap" use="optional"/>
// <xsd:attribute name="lines" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="w" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="h" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="vSpace" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="hSpace" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="wrap" type="ST_Wrap" use="optional"/>
// <xsd:attribute name="hAnchor" type="ST_HAnchor" use="optional"/>
// <xsd:attribute name="vAnchor" type="ST_VAnchor" use="optional"/>
// <xsd:attribute name="x" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="xAlign" type="s:ST_XAlign" use="optional"/>
// <xsd:attribute name="y" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="yAlign" type="s:ST_YAlign" use="optional"/>
// <xsd:attribute name="hRule" type="ST_HeightRule" use="optional"/>
// <xsd:attribute name="anchorLock" type="s:ST_OnOff" use="optional"/>
// </xsd:complexType>
type FramePropertiesAttributes = {
readonly anchorLock?: boolean;
readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
readonly width: number;
@ -77,47 +96,71 @@ export class FramePropertiesAttributes extends XmlAttributeComponent<{
readonly rule?: (typeof HeightRule)[keyof typeof HeightRule];
readonly alignmentX?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly alignmentY?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
}> {
protected readonly xmlKeys = {
anchorLock: "w:anchorLock",
dropCap: "w:dropCap",
width: "w:w",
height: "w:h",
x: "w:x",
y: "w:y",
anchorHorizontal: "w:hAnchor",
anchorVertical: "w:vAnchor",
spaceHorizontal: "w:hSpace",
spaceVertical: "w:vSpace",
rule: "w:hRule",
alignmentX: "w:xAlign",
alignmentY: "w:yAlign",
lines: "w:lines",
wrap: "w:wrap",
};
}
};
export class FrameProperties extends XmlComponent {
public constructor(options: IFrameOptions) {
super("w:framePr");
this.root.push(
new FramePropertiesAttributes({
anchorLock: options.anchorLock,
dropCap: options.dropCap,
width: options.width,
height: options.height,
x: (options as IXYFrameOptions).position ? (options as IXYFrameOptions).position.x : undefined,
y: (options as IXYFrameOptions).position ? (options as IXYFrameOptions).position.y : undefined,
anchorHorizontal: options.anchor.horizontal,
anchorVertical: options.anchor.vertical,
spaceHorizontal: options.space?.horizontal,
spaceVertical: options.space?.vertical,
rule: options.rule,
alignmentX: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.x : undefined,
alignmentY: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.y : undefined,
lines: options.lines,
wrap: options.wrap,
}),
);
}
}
export const createFrameProperties = (options: IFrameOptions): XmlComponent =>
new BuilderElement<FramePropertiesAttributes>({
name: "w:framePr",
attributes: {
anchorLock: {
key: "w:anchorLock",
value: options.anchorLock,
},
dropCap: {
key: "w:dropCap",
value: options.dropCap,
},
width: {
key: "w:w",
value: options.width,
},
height: {
key: "w:h",
value: options.height,
},
x: {
key: "w:x",
value: (options as IXYFrameOptions).position ? (options as IXYFrameOptions).position.x : undefined,
},
y: {
key: "w:y",
value: (options as IXYFrameOptions).position ? (options as IXYFrameOptions).position.y : undefined,
},
anchorHorizontal: {
key: "w:hAnchor",
value: options.anchor.horizontal,
},
anchorVertical: {
key: "w:vAnchor",
value: options.anchor.vertical,
},
spaceHorizontal: {
key: "w:hSpace",
value: options.space?.horizontal,
},
spaceVertical: {
key: "w:vSpace",
value: options.space?.vertical,
},
rule: {
key: "w:hRule",
value: options.rule,
},
alignmentX: {
key: "w:xAlign",
value: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.x : undefined,
},
alignmentY: {
key: "w:yAlign",
value: (options as IAlignmentFrameOptions).alignment ? (options as IAlignmentFrameOptions).alignment.y : undefined,
},
lines: {
key: "w:lines",
value: options.lines,
},
wrap: {
key: "w:wrap",
value: options.wrap,
},
},
});

View File

@ -890,10 +890,7 @@ describe("Paragraph", () => {
it("should set frame attribute", () => {
const paragraph = new Paragraph({
frame: {
position: {
x: 1000,
y: 3000,
},
type: "alignment",
width: 4000,
height: 1000,
anchor: {
@ -918,9 +915,7 @@ describe("Paragraph", () => {
"w:hAnchor": "margin",
"w:vAnchor": "margin",
"w:w": 4000,
"w:x": 1000,
"w:xAlign": "center",
"w:y": 3000,
"w:yAlign": "top",
},
},

View File

@ -13,7 +13,7 @@ import { HeadingLevel, Style } from "./formatting/style";
import { TabStop, TabStopDefinition, TabStopType } from "./formatting/tab-stop";
import { NumberProperties } from "./formatting/unordered-list";
import { WordWrap } from "./formatting/word-wrap";
import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
import { createFrameProperties, IFrameOptions } from "./frame/frame-properties";
import { OutlineLevel } from "./links";
import { IRunOptions, RunProperties } from ".";
@ -117,7 +117,7 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
}
if (options.frame) {
this.push(new FrameProperties(options.frame));
this.push(createFrameProperties(options.frame));
}
if (options.widowControl !== undefined) {

View File

@ -70,8 +70,8 @@ export class ImageRun extends Run {
.split("")
.map((c) => c.charCodeAt(0)),
);
/* c8 ignore next 6 */
} else {
/* c8 ignore next 4 */
// Not possible to test this branch in NodeJS
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const b = require("buf" + "fer");

View File

@ -2,11 +2,11 @@ import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
import { CurrentSection, NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
describe("Page", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
it("should work", () => {
const tree = new Formatter().format(new Page());
expect(tree).to.deep.equal({ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] });
});
@ -15,7 +15,7 @@ describe("Page", () => {
describe("NumberOfPages", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
it("should work", () => {
const tree = new Formatter().format(new NumberOfPages());
expect(tree).to.deep.equal({ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] });
});
@ -24,9 +24,18 @@ describe("NumberOfPages", () => {
describe("NumberOfPagesSection", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
it("should work", () => {
const tree = new Formatter().format(new NumberOfPagesSection());
expect(tree).to.deep.equal({ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTIONPAGES"] });
});
});
});
describe("CurrentSection", () => {
describe("#constructor()", () => {
it("should work", () => {
const tree = new Formatter().format(new CurrentSection());
expect(tree).to.deep.equal({ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTION"] });
});
});
});

View File

@ -27,7 +27,7 @@ export class NumberOfPagesSection extends XmlComponent {
}
}
export class CurrentPageInSection extends XmlComponent {
export class CurrentSection extends XmlComponent {
public constructor() {
super("w:instrText");
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));

View File

@ -6,7 +6,7 @@ import { FieldInstruction } from "@file/table-of-contents/field-instruction";
import { Break } from "./break";
import { Begin, End, Separate } from "./field";
import { NumberOfPages, NumberOfPagesSection, Page, CurrentPageInSection } from "./page-number";
import { NumberOfPages, NumberOfPagesSection, Page, CurrentSection } from "./page-number";
import { IRunPropertiesOptions, RunProperties } from "./properties";
import { Text } from "./run-components/text";
import {
@ -146,7 +146,7 @@ export class Run extends XmlComponent {
break;
case PageNumber.CURRENT_SECTION:
this.root.push(new Begin());
this.root.push(new CurrentPageInSection());
this.root.push(new CurrentSection());
this.root.push(new Separate());
this.root.push(new End());
break;

View File

@ -17,7 +17,8 @@ export type RelationshipType =
| "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"
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font";
export const TargetModeType = {
EXTERNAL: "External",

View File

@ -30,6 +30,7 @@ export const convertToXmlComponent = (element: XmlElement): ImportedXmlComponent
return element.text as string;
default:
return undefined;
/* c8 ignore next 2 */
}
};

View File

@ -55,6 +55,14 @@ export class StringValueElement extends XmlComponent {
}
}
export const createStringElement = (name: string, value: string): XmlComponent =>
new BuilderElement({
name,
attributes: {
value: { key: "w:val", value },
},
});
// This represents various number element types.
export class NumberValueElement extends XmlComponent {
public constructor(name: string, val: number) {
@ -82,19 +90,23 @@ export class StringContainer extends XmlComponent {
}
export class BuilderElement<T extends AttributeData> extends XmlComponent {
public constructor(options: {
public constructor({
name,
attributes,
children,
}: {
readonly name: string;
readonly attributes?: AttributePayload<T>;
readonly children?: readonly XmlComponent[];
}) {
super(options.name);
super(name);
if (options.attributes) {
this.root.push(new NextAttributeComponent(options.attributes));
if (attributes) {
this.root.push(new NextAttributeComponent(attributes));
}
for (const child of options.children ?? []) {
this.root.push(child);
if (children) {
this.root.push(...children);
}
}
}

View File

@ -1,6 +1,16 @@
import { describe, expect, it } from "vitest";
import { convertInchesToTwip, convertMillimetersToTwip, uniqueId, uniqueNumericIdCreator } from "./convenience-functions";
import {
abstractNumUniqueNumericIdGen,
bookmarkUniqueNumericIdGen,
concreteNumUniqueNumericIdGen,
convertInchesToTwip,
convertMillimetersToTwip,
docPropertiesUniqueNumericIdGen,
uniqueId,
uniqueNumericIdCreator,
uniqueUuid,
} from "./convenience-functions";
describe("Utility", () => {
describe("#convertMillimetersToTwip", () => {
@ -24,9 +34,47 @@ describe("Utility", () => {
});
});
describe("#abstractNumUniqueNumericIdGen", () => {
it("should generate a unique incrementing ID", () => {
const uniqueNumericId = abstractNumUniqueNumericIdGen();
expect(uniqueNumericId()).to.equal(1);
expect(uniqueNumericId()).to.equal(2);
});
});
describe("#concreteNumUniqueNumericIdGen", () => {
it("should generate a unique incrementing ID", () => {
const uniqueNumericId = concreteNumUniqueNumericIdGen();
expect(uniqueNumericId()).to.equal(2);
expect(uniqueNumericId()).to.equal(3);
});
});
describe("#docPropertiesUniqueNumericIdGen", () => {
it("should generate a unique incrementing ID", () => {
const uniqueNumericId = docPropertiesUniqueNumericIdGen();
expect(uniqueNumericId()).to.equal(1);
expect(uniqueNumericId()).to.equal(2);
});
});
describe("#bookmarkUniqueNumericIdGen", () => {
it("should generate a unique incrementing ID", () => {
const uniqueNumericId = bookmarkUniqueNumericIdGen();
expect(uniqueNumericId()).to.equal(1);
expect(uniqueNumericId()).to.equal(2);
});
});
describe("#uniqueId", () => {
it("should generate a unique pseudorandom ID", () => {
expect(uniqueId()).to.not.be.empty;
});
});
describe("#uniqueUuid", () => {
it("should generate a unique pseudorandom ID", () => {
expect(uniqueUuid()).to.not.be.empty;
});
});
});

View File

@ -1,4 +1,4 @@
import { nanoid } from "nanoid/non-secure";
import { nanoid, customAlphabet } from "nanoid/non-secure";
// Twip - twentieths of a point
export const convertMillimetersToTwip = (millimeters: number): number => Math.floor((millimeters / 25.4) * 72 * 20);
@ -23,3 +23,7 @@ export const docPropertiesUniqueNumericIdGen = (): UniqueNumericIdCreator => uni
export const bookmarkUniqueNumericIdGen = (): UniqueNumericIdCreator => uniqueNumericIdCreator();
export const uniqueId = (): string => nanoid().toLowerCase();
const generateUuidPart = (count: number): string => customAlphabet("1234567890abcdef", count)();
export const uniqueUuid = (): string =>
`${generateUuidPart(8)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(12)}`;

View File

@ -26,6 +26,7 @@ export default defineConfig({
},
build: {
minify: false,
target: "es2015",
lib: {
entry: [resolve(__dirname, "src/index.ts")],
name: "docx",
@ -61,10 +62,10 @@ export default defineConfig({
provider: "v8",
reporter: ["text", "json", "html"],
thresholds: {
statements: 99.96,
branches: 98.98,
statements: 99.98,
branches: 99.15,
functions: 100,
lines: 99.96,
lines: 99.98,
},
exclude: [
...configDefaults.exclude,