Compare commits

...

70 Commits
8.2.2 ... 8.4.0

Author SHA1 Message Date
b7334a1ab5 Version bump 2023-12-25 01:52:12 +00:00
9229f45d59 Downgrade Build to ES2015 (#2473) 2023-12-25 01:50:26 +00:00
2bd4aacdd5 #2388 - Add default tab stop (#2470)
* #2388 - Check for undefined rather than falsey

* Add default tab stop

* Add back tab stop positions

* Add test for default tab stop
2023-12-24 03:37:36 +00:00
abbd695a8f Version bump 2023-12-22 01:32:44 +00:00
f7b98bcde8 build(deps-dev): bump eslint-plugin-functional from 5.0.8 to 6.0.0 (#2409)
* build(deps-dev): bump eslint-plugin-functional from 5.0.8 to 6.0.0

Bumps [eslint-plugin-functional](https://github.com/eslint-functional/eslint-plugin-functional) from 5.0.8 to 6.0.0.
- [Release notes](https://github.com/eslint-functional/eslint-plugin-functional/releases)
- [Changelog](https://github.com/eslint-functional/eslint-plugin-functional/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint-functional/eslint-plugin-functional/compare/v5.0.8...v6.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-functional
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Remove assumeTypes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
2023-12-22 01:31:34 +00:00
a756a7697c Change all project enums to objects with as const (#2445)
* feat: change all enums to as const objects

* Add word to dictionary

---------

Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
2023-12-22 01:25:00 +00:00
fd1ea5b4dc build(deps-dev): bump eslint-plugin-unicorn from 48.0.1 to 50.0.1 (#2458)
Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 48.0.1 to 50.0.1.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v48.0.1...v50.0.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-22 01:21:22 +00:00
d83e089cd3 add run options to ParagraphPropertiesOptions (#2457) 2023-12-22 01:21:12 +00:00
33715cc50c build(deps-dev): bump vite from 4.5.0 to 5.0.10 (#2455)
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.5.0 to 5.0.10.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v5.0.10/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-22 01:20:42 +00:00
f3f1f2d0b1 build(deps-dev): bump eslint from 8.45.0 to 8.56.0 (#2454)
Bumps [eslint](https://github.com/eslint/eslint) from 8.45.0 to 8.56.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.45.0...v8.56.0)

---
updated-dependencies:
- dependency-name: eslint
  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-22 01:20:33 +00:00
c35e706fa8 build(deps-dev): bump eslint-plugin-import from 2.27.5 to 2.29.1 (#2453)
Bumps [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) from 2.27.5 to 2.29.1.
- [Release notes](https://github.com/import-js/eslint-plugin-import/releases)
- [Changelog](https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md)
- [Commits](https://github.com/import-js/eslint-plugin-import/compare/v2.27.5...v2.29.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-import
  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-22 01:20:25 +00:00
35cebfe1a2 build(deps-dev): bump vite-tsconfig-paths from 4.2.0 to 4.2.2 (#2442)
Bumps [vite-tsconfig-paths](https://github.com/aleclarson/vite-tsconfig-paths) from 4.2.0 to 4.2.2.
- [Release notes](https://github.com/aleclarson/vite-tsconfig-paths/releases)
- [Commits](https://github.com/aleclarson/vite-tsconfig-paths/compare/v4.2.0...v4.2.2)

---
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-22 01:20:17 +00:00
d04c42cbe8 Use esm for ts-node (#2459)
* Use esm for ts-node

* Add esm flag

* Change tsconfig properties

* Use tsx rather than ts-node

* Use tsx

* Remove ts-node
2023-12-22 01:10:54 +00:00
8744e613ac Merge pull request #2438 from dolanmiu/dependabot/npm_and_yarn/vite-4.5.1
build(deps-dev): bump vite from 4.5.0 to 4.5.1
2023-12-21 23:52:36 +00:00
cbeecbf3e1 Merge pull request #2435 from dolanmiu/dependabot/npm_and_yarn/nanoid-5.0.4
build(deps): bump nanoid from 4.0.2 to 5.0.4
2023-12-21 23:52:28 +00:00
f8ab2d1701 Merge pull request #2433 from dolanmiu/dependabot/npm_and_yarn/vite-plugin-dts-3.6.4
build(deps-dev): bump vite-plugin-dts from 3.3.1 to 3.6.4
2023-12-21 23:52:20 +00:00
adc5c6f594 Merge pull request #2419 from dolanmiu/dependabot/npm_and_yarn/types/unzipper-0.10.9
build(deps-dev): bump @types/unzipper from 0.10.6 to 0.10.9
2023-12-21 23:52:14 +00:00
c9524cc497 Merge pull request #2418 from dolanmiu/dependabot/npm_and_yarn/inquirer-and-types/inquirer-9.2.12
build(deps-dev): bump inquirer and @types/inquirer
2023-12-21 23:52:06 +00:00
90de6ba7e1 Merge pull request #2407 from dolanmiu/dependabot/npm_and_yarn/vitest/coverage-v8-0.34.6
build(deps-dev): bump @vitest/coverage-v8 from 0.33.0 to 0.34.6
2023-12-21 23:51:57 +00:00
78d74ae60b Merge pull request #2439 from morlay/master
Run prop snapToGrid should be false
2023-12-06 12:09:40 +00:00
579593a467 Run prop snapToGrid should be false 2023-12-06 10:15:46 +08:00
b5393dadae build(deps-dev): bump vite from 4.5.0 to 4.5.1
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v4.5.1/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v4.5.1/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-06 00:01:15 +00:00
528ab1933e build(deps): bump nanoid from 4.0.2 to 5.0.4
Bumps [nanoid](https://github.com/ai/nanoid) from 4.0.2 to 5.0.4.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ai/nanoid/compare/4.0.2...5.0.4)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-04 11:15:37 +00:00
36181f8c91 build(deps-dev): bump vite-plugin-dts from 3.3.1 to 3.6.4
Bumps [vite-plugin-dts](https://github.com/qmhc/vite-plugin-dts) from 3.3.1 to 3.6.4.
- [Release notes](https://github.com/qmhc/vite-plugin-dts/releases)
- [Changelog](https://github.com/qmhc/vite-plugin-dts/blob/main/CHANGELOG.md)
- [Commits](https://github.com/qmhc/vite-plugin-dts/compare/v3.3.1...v3.6.4)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-30 11:36:50 +00:00
45af681db1 build(deps-dev): bump @types/unzipper from 0.10.6 to 0.10.9
Bumps [@types/unzipper](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/unzipper) from 0.10.6 to 0.10.9.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/unzipper)

---
updated-dependencies:
- dependency-name: "@types/unzipper"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-08 12:04:31 +00:00
ad6b482136 build(deps-dev): bump inquirer and @types/inquirer
Bumps [inquirer](https://github.com/SBoudrias/Inquirer.js) and [@types/inquirer](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/inquirer). These dependencies needed to be updated together.

Updates `inquirer` from 9.2.11 to 9.2.12
- [Release notes](https://github.com/SBoudrias/Inquirer.js/releases)
- [Commits](https://github.com/SBoudrias/Inquirer.js/compare/inquirer@9.2.11...inquirer@9.2.12)

Updates `@types/inquirer` from 9.0.3 to 9.0.7
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/inquirer)

---
updated-dependencies:
- dependency-name: inquirer
  dependency-type: direct:development
  update-type: version-update:semver-patch
- dependency-name: "@types/inquirer"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-08 11:59:29 +00:00
a6e1c2b019 build(deps-dev): bump @vitest/coverage-v8 from 0.33.0 to 0.34.6
Bumps [@vitest/coverage-v8](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-v8) from 0.33.0 to 0.34.6.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v0.34.6/packages/coverage-v8)

---
updated-dependencies:
- dependency-name: "@vitest/coverage-v8"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-02 11:15:26 +00:00
3eb98533ae Version bump 2023-11-02 03:02:21 +00:00
f5f021834e Merge pull request #2403 from dolanmiu/feature/bump-eslint-plugin
Upgrade @typescript-eslint/parser
2023-11-02 03:01:55 +00:00
35702c3f77 Upgrade @typescript-eslint/parser 2023-11-01 22:52:41 +00:00
8fbbd571ad Merge pull request #2402 from dolanmiu/dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.9.1
build(deps-dev): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.9.1
2023-11-01 22:27:36 +00:00
2dd228be69 build(deps-dev): bump @typescript-eslint/eslint-plugin
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.60.1 to 6.9.1.
- [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.9.1/packages/eslint-plugin)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 21:16:40 +00:00
562835cfe7 Merge pull request #2401 from dolanmiu/dependabot/npm_and_yarn/vite-4.5.0
build(deps-dev): bump vite from 4.3.9 to 4.5.0
2023-11-01 21:15:57 +00:00
6bac06e84d Merge pull request #2382 from dolanmiu/dependabot/npm_and_yarn/cspell-7.3.8
build(deps-dev): bump cspell from 6.31.1 to 7.3.8
2023-11-01 21:15:33 +00:00
88436168ee Merge pull request #2400 from dolanmiu/dependabot/npm_and_yarn/browserify-sign-4.2.2
build(deps-dev): bump browserify-sign from 4.2.1 to 4.2.2
2023-11-01 21:15:26 +00:00
0c3206d2e2 Merge pull request #2350 from dolanmiu/dependabot/npm_and_yarn/eslint-plugin-jsdoc-46.8.2
build(deps-dev): bump eslint-plugin-jsdoc from 46.4.4 to 46.8.2
2023-11-01 21:15:08 +00:00
033debd339 Merge pull request #2303 from dolanmiu/dependabot/npm_and_yarn/execa-8.0.1
build(deps-dev): bump execa from 7.1.1 to 8.0.1
2023-11-01 21:15:00 +00:00
d4f160732a Use Record instead of Object 2023-11-01 20:56:02 +00:00
4238fc9ab4 build(deps-dev): bump execa from 7.1.1 to 8.0.1
Bumps [execa](https://github.com/sindresorhus/execa) from 7.1.1 to 8.0.1.
- [Release notes](https://github.com/sindresorhus/execa/releases)
- [Commits](https://github.com/sindresorhus/execa/compare/v7.1.1...v8.0.1)

---
updated-dependencies:
- dependency-name: execa
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 20:55:59 +00:00
0d042b8dd1 build(deps-dev): bump vite from 4.3.9 to 4.5.0
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.3.9 to 4.5.0.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v4.5.0/packages/vite)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 20:55:35 +00:00
afdd5f2d8f Merge pull request #2383 from dolanmiu/dependabot/npm_and_yarn/types/node-20.8.6
build(deps): bump @types/node from 20.4.2 to 20.8.6
2023-11-01 20:55:29 +00:00
70c7b3d1b3 Merge pull request #2374 from dolanmiu/dependabot/npm_and_yarn/postcss-8.4.31
build(deps-dev): bump postcss from 8.4.23 to 8.4.31
2023-11-01 20:55:22 +00:00
7b1cd5fe86 build(deps-dev): bump browserify-sign from 4.2.1 to 4.2.2
Bumps [browserify-sign](https://github.com/crypto-browserify/browserify-sign) from 4.2.1 to 4.2.2.
- [Changelog](https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md)
- [Commits](https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2)

---
updated-dependencies:
- dependency-name: browserify-sign
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 20:55:02 +00:00
09ab169ffd Merge pull request #2359 from dolanmiu/dependabot/npm_and_yarn/glob-10.3.10
build(deps-dev): bump glob from 10.3.1 to 10.3.10
2023-11-01 20:55:01 +00:00
35a82cf12e Merge pull request #2333 from dolanmiu/dependabot/npm_and_yarn/inquirer-9.2.11
build(deps-dev): bump inquirer from 9.2.7 to 9.2.11
2023-11-01 20:54:54 +00:00
8d33cb01dd Merge pull request #2268 from dolanmiu/dependabot/npm_and_yarn/eslint-plugin-unicorn-48.0.1
build(deps-dev): bump eslint-plugin-unicorn from 47.0.0 to 48.0.1
2023-11-01 20:54:35 +00:00
438d11dd86 Merge pull request #2387 from wilkmaia/fix/patch-styling
Fix style being missed on patchDocument
2023-11-01 20:54:23 +00:00
d23b0d0789 Fix coverage 2023-11-01 20:40:30 +00:00
1fa8c7ac82 Merge pull request #2397 from hom/master
fix: #2082 Numbering instance restart number not work since v8.0.0 and work well in v7.8.2
2023-10-27 00:41:01 +01:00
3d6ead0359 Merge pull request #2 from hom/fix/#2082 2023-10-27 03:59:58 +08:00
379050dccd Merge pull request #1 from dolanmiu/master 2023-10-27 03:31:07 +08:00
f9d1c197cf Merge pull request #2379 from rahon6000/master
changed default section margin from inch to Twip
2023-10-20 22:10:03 +01:00
a89ee463e6 Fix style being missed on patchDocument
There were scenarios in which patching a document would result in loss
of style for the template runs and, possibly, their right-adjacent run
as well (post-splitting). That was due to the run style elements not
being added to the newly created runs.

This commit addresses this issue by introducing a new, optional, flag
for the `patchDocument` function: `keepOriginalStyles`. It defaults to
`false` (current behavior) and, when `true`, ensures that there is no
loss of styling.

This should address https://github.com/dolanmiu/docx/issues/2293.
2023-10-18 12:58:01 -03:00
036caaacc8 build(deps): bump @types/node from 20.4.2 to 20.8.6
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.4.2 to 20.8.6.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-16 11:53:19 +00:00
80c37afe2b build(deps-dev): bump cspell from 6.31.1 to 7.3.8
Bumps [cspell](https://github.com/streetsidesoftware/cspell) from 6.31.1 to 7.3.8.
- [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/v6.31.1...v7.3.8)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-16 11:52:24 +00:00
3a36d912fe changed default section margin from inch to Twip 2023-10-12 12:14:13 +09:00
c741d5d8ac build(deps-dev): bump postcss from 8.4.23 to 8.4.31
Bumps [postcss](https://github.com/postcss/postcss) from 8.4.23 to 8.4.31.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.4.23...8.4.31)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-07 19:43:49 +00:00
0fa7dd13ad build(deps-dev): bump glob from 10.3.1 to 10.3.10
Bumps [glob](https://github.com/isaacs/node-glob) from 10.3.1 to 10.3.10.
- [Changelog](https://github.com/isaacs/node-glob/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/node-glob/compare/v10.3.1...v10.3.10)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-27 11:43:28 +00:00
d5d80550e7 Version bump 2023-09-26 23:00:51 +01:00
23a0a59454 Use .mjs for ESM 2023-09-26 22:59:32 +01:00
066aa56f6a build(deps-dev): bump eslint-plugin-jsdoc from 46.4.4 to 46.8.2
Bumps [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) from 46.4.4 to 46.8.2.
- [Release notes](https://github.com/gajus/eslint-plugin-jsdoc/releases)
- [Changelog](https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.releaserc)
- [Commits](https://github.com/gajus/eslint-plugin-jsdoc/compare/v46.4.4...v46.8.2)

---
updated-dependencies:
- dependency-name: eslint-plugin-jsdoc
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-21 11:59:15 +00:00
3997b7a5d6 fix: #2082 Numbering instance restart number not work since v8.0.0 and work well in v7.8.2 2023-09-13 17:08:59 +08:00
ccc391607a Merge pull request #2331 from hshoja/doc/update-style-with-xml
Update styling with xml  docs
2023-09-11 21:04:32 +01:00
9577192d41 build(deps-dev): bump inquirer from 9.2.7 to 9.2.11
Bumps [inquirer](https://github.com/SBoudrias/Inquirer.js) from 9.2.7 to 9.2.11.
- [Release notes](https://github.com/SBoudrias/Inquirer.js/releases)
- [Commits](https://github.com/SBoudrias/Inquirer.js/compare/inquirer@9.2.7...inquirer@9.2.11)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 11:40:53 +00:00
968c3aed0f Update styling-with-xml doc 2023-09-10 15:57:48 +02:00
9c7a80729b Merge branch 'master' of github.com:dolanmiu/docx 2023-08-06 20:10:11 +01:00
5f26ca1c94 Update numbering docs 2023-08-06 20:10:03 +01:00
f2b1587bff build(deps-dev): bump eslint-plugin-unicorn from 47.0.0 to 48.0.1
Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 47.0.0 to 48.0.1.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v47.0.0...v48.0.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-26 11:15:05 +00:00
3b9f80fb1a Merge pull request #2259 from dolanmiu/feat/bump-prettier
Bump prettier
2023-07-21 22:13:17 +01:00
8da57bec51 Bump prettier
Fix new prettier issues
2023-07-21 20:11:52 +01:00
86 changed files with 6097 additions and 3364 deletions

View File

@ -17,6 +17,7 @@
"dolan", "dolan",
"execa", "execa",
"falsey", "falsey",
"horz",
"iife", "iife",
"Initializable", "Initializable",
"iroha", "iroha",

View File

@ -7,7 +7,6 @@ parser: "@typescript-eslint/parser"
parserOptions: parserOptions:
project: project:
- tsconfig.json - tsconfig.json
- demo/tsconfig.json
sourceType: module sourceType: module
plugins: plugins:
- eslint-plugin-import - eslint-plugin-import
@ -214,8 +213,7 @@ rules:
valid-typeof: "off" valid-typeof: "off"
functional/immutable-data: functional/immutable-data:
- error - error
- assumeTypes: true - ignoreImmediateMutation: true
ignoreImmediateMutation: true
ignoreAccessorPattern: ignoreAccessorPattern:
- "**.root*" - "**.root*"
- "**.numberingReferences*" - "**.numberingReferences*"

View File

@ -38,7 +38,7 @@ jobs:
name: build name: build
path: build path: build
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/1-basic.ts run: npm run run-ts -- ./demo/1-basic.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -47,7 +47,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/2-declaritive-styles.ts run: npm run run-ts -- ./demo/2-declaritive-styles.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -56,7 +56,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts run: npm run run-ts -- ./demo/3-numbering-and-bullet-points.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -65,7 +65,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/4-basic-table.ts run: npm run run-ts -- ./demo/4-basic-table.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -74,7 +74,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/5-images.ts run: npm run run-ts -- ./demo/5-images.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -83,7 +83,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/6-page-borders.ts run: npm run run-ts -- ./demo/6-page-borders.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -92,7 +92,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/7-landscape.ts run: npm run run-ts -- ./demo/7-landscape.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -101,7 +101,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/8-header-footer.ts run: npm run run-ts -- ./demo/8-header-footer.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -110,7 +110,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/9-images-in-header-and-footer.ts run: npm run run-ts -- ./demo/9-images-in-header-and-footer.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -119,7 +119,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/10-my-cv.ts run: npm run run-ts -- ./demo/10-my-cv.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -128,7 +128,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/11-declaritive-styles-2.ts run: npm run run-ts -- ./demo/11-declaritive-styles-2.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -137,7 +137,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/12-scaling-images.ts run: npm run run-ts -- ./demo/12-scaling-images.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -146,7 +146,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/13-xml-styles.ts run: npm run run-ts -- ./demo/13-xml-styles.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -155,7 +155,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/14-page-numbers.ts run: npm run run-ts -- ./demo/14-page-numbers.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -164,7 +164,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/15-page-break-before.ts run: npm run run-ts -- ./demo/15-page-break-before.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -173,7 +173,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/16-multiple-sections.ts run: npm run run-ts -- ./demo/16-multiple-sections.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -182,7 +182,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/17-footnotes.ts run: npm run run-ts -- ./demo/17-footnotes.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected. # element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected.
@ -192,7 +192,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/18-image-from-buffer.ts run: npm run run-ts -- ./demo/18-image-from-buffer.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -201,7 +201,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/19-export-to-base64.ts run: npm run run-ts -- ./demo/19-export-to-base64.ts
# Base 64 No longer works, abruptly. Node issue? # Base 64 No longer works, abruptly. Node issue?
# - name: Extract Word Document # - name: Extract Word Document
# run: npm run extract # run: npm run extract
@ -211,7 +211,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/20-table-cell-borders.ts run: npm run run-ts -- ./demo/20-table-cell-borders.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -220,7 +220,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/21-bookmarks.ts run: npm run run-ts -- ./demo/21-bookmarks.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# Bad ID - need numeric ID # Bad ID - need numeric ID
@ -230,7 +230,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/22-right-to-left-text.ts run: npm run run-ts -- ./demo/22-right-to-left-text.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -239,7 +239,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/23-base64-images.ts run: npm run run-ts -- ./demo/23-base64-images.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -248,7 +248,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/24-images-to-table-cell.ts run: npm run run-ts -- ./demo/24-images-to-table-cell.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -257,7 +257,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/25-table-xml-styles.ts run: npm run run-ts -- ./demo/25-table-xml-styles.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -266,7 +266,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/26-paragraph-borders.ts run: npm run run-ts -- ./demo/26-paragraph-borders.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -275,7 +275,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/27-declaritive-styles-3.ts run: npm run run-ts -- ./demo/27-declaritive-styles-3.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -284,7 +284,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/28-table-of-contents.ts run: npm run run-ts -- ./demo/28-table-of-contents.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -293,7 +293,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/29-numbered-lists.ts run: npm run run-ts -- ./demo/29-numbered-lists.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -302,7 +302,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/31-tables.ts run: npm run run-ts -- ./demo/31-tables.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -311,7 +311,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts run: npm run run-ts -- ./demo/32-merge-and-shade-table-cells.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -320,7 +320,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/33-sequential-captions.ts run: npm run run-ts -- ./demo/33-sequential-captions.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -329,7 +329,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/34-floating-tables.ts run: npm run run-ts -- ./demo/34-floating-tables.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# 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', attribute 'overlap': The attribute 'overlap' is not allowed.
@ -340,7 +340,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/35-hyperlinks.ts run: npm run run-ts -- ./demo/35-hyperlinks.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -349,7 +349,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/36-image-to-table-cell.ts run: npm run run-ts -- ./demo/36-image-to-table-cell.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -358,7 +358,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/37-images-to-header-and-footer.ts run: npm run run-ts -- ./demo/37-images-to-header-and-footer.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -367,7 +367,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/38-text-wrapping.ts run: npm run run-ts -- ./demo/38-text-wrapping.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -376,7 +376,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/39-page-numbers.ts run: npm run run-ts -- ./demo/39-page-numbers.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -385,7 +385,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/40-line-numbers.ts run: npm run run-ts -- ./demo/40-line-numbers.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -394,7 +394,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/41-merge-table-cells-2.ts run: npm run run-ts -- ./demo/41-merge-table-cells-2.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -403,7 +403,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/42-restart-page-numbers.ts run: npm run run-ts -- ./demo/42-restart-page-numbers.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -412,7 +412,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/43-images-to-table-cell-2.ts run: npm run run-ts -- ./demo/43-images-to-table-cell-2.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -421,7 +421,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/44-multiple-columns.ts run: npm run run-ts -- ./demo/44-multiple-columns.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -430,7 +430,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/45-highlighting-text.ts run: npm run run-ts -- ./demo/45-highlighting-text.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -439,7 +439,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/46-shading-text.ts run: npm run run-ts -- ./demo/46-shading-text.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -448,7 +448,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/47-number-of-total-pages-section.ts run: npm run run-ts -- ./demo/47-number-of-total-pages-section.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -457,7 +457,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/48-vertical-align.ts run: npm run run-ts -- ./demo/48-vertical-align.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -466,7 +466,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/49-table-borders.ts run: npm run run-ts -- ./demo/49-table-borders.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -475,7 +475,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/50-readme-demo.ts run: npm run run-ts -- ./demo/50-readme-demo.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -484,7 +484,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/51-character-styles.ts run: npm run run-ts -- ./demo/51-character-styles.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -493,7 +493,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/52-japanese.ts run: npm run run-ts -- ./demo/52-japanese.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -502,7 +502,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/53-chinese.ts run: npm run run-ts -- ./demo/53-chinese.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -511,7 +511,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/54-custom-properties.ts run: npm run run-ts -- ./demo/54-custom-properties.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -520,7 +520,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/55-math.ts run: npm run run-ts -- ./demo/55-math.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
#: 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 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 ).
@ -533,7 +533,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/56-background-color.ts run: npm run run-ts -- ./demo/56-background-color.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -542,7 +542,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/57-add-parent-numbered-lists.ts run: npm run run-ts -- ./demo/57-add-parent-numbered-lists.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -551,7 +551,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/58-section-types.ts run: npm run run-ts -- ./demo/58-section-types.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -560,7 +560,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/59-header-footer-margins.ts run: npm run run-ts -- ./demo/59-header-footer-margins.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -569,7 +569,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/60-track-revisions.ts run: npm run run-ts -- ./demo/60-track-revisions.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected. # element r: Schemas validity error : Element '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}r': This element is not expected.
@ -579,7 +579,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/61-text-frame.ts run: npm run run-ts -- ./demo/61-text-frame.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# 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 ). # 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 ).
@ -589,7 +589,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/62-paragraph-spacing.ts run: npm run run-ts -- ./demo/62-paragraph-spacing.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -598,7 +598,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/63-odd-even-header-footer.ts run: npm run run-ts -- ./demo/63-odd-even-header-footer.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -607,7 +607,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/64-complex-numbering-text.ts run: npm run run-ts -- ./demo/64-complex-numbering-text.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -616,7 +616,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/65-page-sizes.ts run: npm run run-ts -- ./demo/65-page-sizes.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -625,7 +625,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/66-fields.ts run: npm run run-ts -- ./demo/66-fields.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
# 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 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'.
@ -636,7 +636,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/67-column-break.ts run: npm run run-ts -- ./demo/67-column-break.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -645,7 +645,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/68-numbering-instances-and-starting-number.ts run: npm run run-ts -- ./demo/68-numbering-instances-and-starting-number.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -654,7 +654,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/69-different-width-columns.ts run: npm run run-ts -- ./demo/69-different-width-columns.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -663,7 +663,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/70-line-numbers-suppression.ts run: npm run run-ts -- ./demo/70-line-numbers-suppression.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -672,7 +672,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/71-page-borders-2.ts run: npm run run-ts -- ./demo/71-page-borders-2.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -681,7 +681,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/72-word-wrap.ts run: npm run run-ts -- ./demo/72-word-wrap.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -690,7 +690,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/73-comments.ts run: npm run run-ts -- ./demo/73-comments.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -699,7 +699,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/73-comments.ts run: npm run run-ts -- ./demo/73-comments.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -708,7 +708,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
# - name: Run Demo # - name: Run Demo
# run: npm run ts-node -- ./demo/75-tab-stops.ts # run: npm run run-ts -- ./demo/75-tab-stops.ts
# - name: Extract Word Document # - name: Extract Word Document
# run: npm run extract # run: npm run extract
# - name: Validate XML # - name: Validate XML
@ -717,7 +717,7 @@ jobs:
# xml-file: build/extracted-doc/word/document.xml # xml-file: build/extracted-doc/word/document.xml
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/76-compatibility.ts run: npm run run-ts -- ./demo/76-compatibility.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -726,7 +726,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/77-side-by-side-tables.ts run: npm run run-ts -- ./demo/77-side-by-side-tables.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -735,7 +735,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/78-thai-distributed.ts run: npm run run-ts -- ./demo/78-thai-distributed.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -744,7 +744,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/79-table-from-data-source.ts run: npm run run-ts -- ./demo/79-table-from-data-source.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -753,7 +753,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/80-thai-distributed.ts run: npm run run-ts -- ./demo/80-thai-distributed.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -762,7 +762,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/81-continuous-header.ts run: npm run run-ts -- ./demo/81-continuous-header.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -771,7 +771,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/82-new-headers-new-section.ts run: npm run run-ts -- ./demo/82-new-headers-new-section.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -780,7 +780,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/83-setting-languages.ts run: npm run run-ts -- ./demo/83-setting-languages.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML
@ -789,7 +789,7 @@ jobs:
xml-file: build/extracted-doc/word/document.xml xml-file: build/extracted-doc/word/document.xml
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
- name: Run Demo - name: Run Demo
run: npm run ts-node -- ./demo/84-positional-tabs.ts run: npm run run-ts -- ./demo/84-positional-tabs.ts
- name: Extract Word Document - name: Extract Word Document
run: npm run extract run: npm run extract
- name: Validate XML - name: Validate XML

16
.vscode/launch.json vendored
View File

@ -1,18 +1,4 @@
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": []
{
"name": "Run Demo",
"type": "node",
"request": "launch",
"runtimeArgs": [
"-r",
"${workspaceFolder}/node_modules/ts-node/register",
"-r",
"${workspaceFolder}/node_modules/tsconfig-paths/register"
],
"cwd": "${workspaceRoot}",
"program": "${workspaceFolder}/demo/85-template-document.ts"
}
]
} }

20
.vscode/tasks.json vendored
View File

@ -2,23 +2,5 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558 // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": []
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
]
},
{
"type": "npm",
"script": "ts-node",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
} }

View File

@ -18,6 +18,7 @@ const receiptTabStops = [
const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }]; const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
const doc = new Document({ const doc = new Document({
defaultTabStop: 0,
sections: [ sections: [
{ {
properties: {}, properties: {},

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head> <head>
<script src="../build/index.umd.js"></script> <script src="../build/index.umd.js"></script>

View File

@ -55,7 +55,7 @@ if (files.length === 0) {
const filePath = path.join(dir, files[0]); const filePath = path.join(dir, files[0]);
console.log(`Running demo ${demoNumber}: ${files[0]}`); console.log(`Running demo ${demoNumber}: ${files[0]}`);
const { stdout } = await $`ts-node --project demo/tsconfig.json ${filePath}`; const { stdout } = await $`tsx ${filePath}`;
console.log(stdout); console.log(stdout);
console.log("Successfully created document!"); console.log("Successfully created document!");
} }

View File

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

View File

@ -1,5 +1,7 @@
# Bullets and Numbering # Bullets and Numbering
!> Bullets and Numbering requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
`docx` is quite flexible in its bullets and numbering system, allowing `docx` is quite flexible in its bullets and numbering system, allowing
the user great freedom in how bullets and numbers are to be styled and the user great freedom in how bullets and numbers are to be styled and
displayed. E.g., numbers can be shown using Arabic numerals, roman displayed. E.g., numbers can be shown using Arabic numerals, roman
@ -8,112 +10,128 @@ format also supports re-using bullets/numbering styles throughout the
document, so that different lists using the same style need not document, so that different lists using the same style need not
redefine them. redefine them.
Because of this flexibility, bullets and numbering in DOCX involves a ## Configuration
couple of moving pieces:
1. Document-level bullets/numbering definitions (abstract) Numbering is configured by adding config into `Document`:
2. Document-level bullets/numbering definitions (concrete)
3. Paragraph-level bullets/numbering selection
## Document-level bullets/numbering definitions (abstract)
Every document contains a set of abstract bullets/numbering
definitions which define the formatting and layout of paragraphs using
those bullets/numbering. An abstract numbering system defines how
bullets/numbers are to be shown for lists, including any sublists that
may be used. Thus each abstract definition includes a series of
_levels_ which form a sequence starting at 0 indicating the top-level
list look and increasing from there to describe the sublists, then
sub-sublists, etc. Each level includes the following properties:
* **level**: This is its 0-based index in the definition stack
* **numberFormat**: This indicates how the bullet or number should be
generated. Options include `bullet` (meaning don't count), `decimal`
(arabic numerals), `upperRoman`, `lowerRoman`, `hex`, and many
more.
* **levelText**: This is a format string using the output of the
`numberFormat` function and generating a string to insert before
every item in the list. You may use `%1`, `%2`, ... to reference the
numbers from each numbering level before this one. Thus a level
text of `%d)` with a number format of `lowerLetter` would result in
the sequence "a)", "b)", ...
* and a few others, which you can see in the OOXML spec section 17.9.6
## Document-level bullets/numbering definitions (concrete)
Concrete definitions are sort of like concrete subclasses of the
abstract definitions. They indicate their parent and are allowed to
override certain level definitions. Thus two lists that differ only in
how sub-sub-lists are to be displayed can share the same abstract
numbering definition and have slightly different concrete definitions.
## Paragraph-level bullets/numbering selection
In order to use a bullets/numbering definition (which must be
concrete), paragraphs need to select it, similar to applying a CSS
class to an element, using both the concrete numbering definition ID
and the level number that the paragraph should be at. Additionally, MS
Word and LibreOffice typically apply a "ListParagraph" style to
paragraphs that are being numbered.
## Using bullets/numbering in `docx`
`docx` includes a pre-defined bullet style which you can add to your
paragraphs using `para.bullets()`. If you require different bullet
styles or numbering of any kind, you'll have to use the
`docx.Numbering` class.
First you need to create a new numbering container class and use it to
create your abstract numbering style, define your levels, and create
your concrete numbering style:
```ts ```ts
const numbering = new docx.Numbering(); new Document({
numbering: {
const abstractNum = numbering.createAbstractNumbering(); config: [...]
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent(720, 260)); }
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent(1440, 980)); })
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent(2160, 1700));
const concrete = numbering.createConcreteNumbering(abstractNum);
``` ```
You can then apply your concrete style to paragraphs using the Each `config` entry includes the following properties:
`setNumbering` method:
. Each level includes the following properties:
| Property | Type | Notes | Possible Values |
| --------- | ----------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| reference | `string` | Required | A unique `string` |
| levels | `ILevelOptions[]` | Required | a series of _levels_ which form a sequence starting at 0 indicating the top-level list look and increasing from there to describe the sublists, then sub-sublists, etc |
### Level Options
Levels define the numbering definition itself, what it looks like, the indention, the alignment and the style. The reason why it is an array is because it allows the ability to create sub-lists. A sub list will have a different configuration because you may want the sub-list to have a different indentation or different bullet.
| Property | Type | Notes | Possible Values |
| --------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| level | `number` | Required | The list level this definition is for. `0` is for the root level, `1` is for a sub list, `2` is for a sub-sub-list etc. |
| format | `LevelFormat` | Optional | `DECIMAL`, `UPPER_ROMAN`, `LOWER_ROMAN`, `UPPER_LETTER`, `LOWER_LETTER`, `ORDINAL`, `CARDINAL_TEXT`, `ORDINAL_TEXT`, `HEX`, `CHICAGO`, `IDEOGRAPH__DIGITAL`, `JAPANESE_COUNTING`, `AIUEO`, `IROHA`, `DECIMAL_FULL_WIDTH`, `DECIMAL_HALF_WIDTH`, `JAPANESE_LEGAL`, `JAPANESE_DIGITAL_TEN_THOUSAND`, `DECIMAL_ENCLOSED_CIRCLE`, `DECIMAL_FULL_WIDTH2`, `AIUEO_FULL_WIDTH`, `IROHA_FULL_WIDTH`, `DECIMAL_ZERO`, `BULLET`, `GANADA`, `CHOSUNG`, `DECIMAL_ENCLOSED_FULLSTOP`, `DECIMAL_ENCLOSED_PARENTHESES`, `DECIMAL_ENCLOSED_CIRCLE_CHINESE`, `IDEOGRAPH_ENCLOSED_CIRCLE`, `IDEOGRAPH_TRADITIONAL`, `IDEOGRAPH_ZODIAC`, `IDEOGRAPH_ZODIAC_TRADITIONAL`, `TAIWANESE_COUNTING`, `IDEOGRAPH_LEGAL_TRADITIONAL`, `TAIWANESE_COUNTING_THOUSAND`, `TAIWANESE_DIGITAL`, `CHINESE_COUNTING`, `CHINESE_LEGAL_SIMPLIFIED`, `CHINESE_COUNTING_THOUSAND`, `KOREAN_DIGITAL`, `KOREAN_COUNTING`, `KOREAN_LEGAL`, `KOREAN_DIGITAL2`, `VIETNAMESE_COUNTING`, `RUSSIAN_LOWER`, `RUSSIAN_UPPER`, `NONE`, `NUMBER_IN_DASH`, `HEBREW1`, `HEBREW2`, `ARABIC_ALPHA`, `ARABIC_ABJAD`, `HINDI_VOWELS`, `HINDI_CONSONANTS`, `HINDI_NUMBERS`, `HINDI_COUNTING`, `THAI_LETTERS`, `THAI_NUMBERS`, `THAI_COUNTING`, `BAHT_TEXT`, `DOLLAR_TEXT`, `CUSTOM` |
| text | `string` | Optional | A unique `string` to describe the shape of the bullet |
| alignment | `string` | Required | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
| style | `string` | Optional | [Sections](usage/styling-with-js.md) |
## Using ordered lists in `docx`
Add a `numbering` section to the `Document` to numbering style, define your levels. Use `LevelFormat.UPPER_ROMAN` for the `format` in `levels`:
```ts ```ts
topLevelP.setNumbering(concrete, 0); const doc = new Document({
subP.setNumbering(concrete, 1); ...
subSubP.setNumbering(concrete, 2); numbering: {
``` config: [
{
## Unindent numbering reference: "my-numbering",
levels: [
Default:1. test {
After:1.test
Use default numbering have indent,If you want unindent numbering
How to custom number see the demo:
https://runkit.com/dolanmiu/docx-demo3
```ts
enum LevelSuffix {
NOTHING = "nothing",
SPACE = "space",
TAB = "tab"
}
// custom numbering
const levels=[
{
level: 0, level: 0,
format: "decimal", format: LevelFormat.UPPER_ROMAN,
text: "%1.", text: "%1",
alignment: AlignmentType.START, alignment: AlignmentType.START,
suffix: LevelSuffix.NOTHING, // Cancel intent style: {
}] paragraph: {
indent: { left: 2880, hanging: 2420 },
},
},
},
...
],
},
],
},
...
});
``` ```
And then on a `Paragraph`, we can add use the numbering created:
```ts
new Paragraph({
text: "Hey you!",
numbering: {
reference: "my-numbering",
level: 0,
},
}),
```
## Un-ordered lists / Bullet points
Add a `numbering` section to the `Document` to numbering style, define your levels. Use `LevelFormat.BULLET` for the `format` in `levels`:
```ts
const doc = new Document({
...
numbering: {
config: [
{
reference: "my-bullet-points",
levels: [
{
level: 0,
format: LevelFormat.BULLET,
text: "\u1F60",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
},
},
},
],
},
],
},
...
});
```
And then on a `Paragraph`, we can add use the numbering created:
```ts
new Paragraph({
text: "Hey you!",
numbering: {
reference: "my-bullet-points",
level: 0,
},
}),
```
## Full Example
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include")
_Source: https://github.com/dolanmiu/docx/blob/master/demo/3-numbering-and-bullet-points.ts_

View File

@ -9,11 +9,16 @@
![image](https://user-images.githubusercontent.com/2917613/41195113-65edebfa-6c1f-11e8-97b4-77de2d60044a.png) ![image](https://user-images.githubusercontent.com/2917613/41195113-65edebfa-6c1f-11e8-97b4-77de2d60044a.png)
![image](https://user-images.githubusercontent.com/2917613/41195126-ca99c36c-6c1f-11e8-9e58-19e5f69b3b87.png) ![image](https://user-images.githubusercontent.com/2917613/41195126-ca99c36c-6c1f-11e8-9e58-19e5f69b3b87.png)
*Note*: Font and color selection from the theme are currently not supported.
3. You can even create a totally new `Style`: 3. You can even create a totally new `Style`:
![image](https://user-images.githubusercontent.com/2917613/41195135-f0f7862a-6c1f-11e8-8be4-dd6d8fe5be03.png) ![image](https://user-images.githubusercontent.com/2917613/41195135-f0f7862a-6c1f-11e8-8be4-dd6d8fe5be03.png)
![image](https://user-images.githubusercontent.com/2917613/41195139-0ec52130-6c20-11e8-8fae-f6b44b43fdf8.png) ![image](https://user-images.githubusercontent.com/2917613/41195139-0ec52130-6c20-11e8-8fae-f6b44b43fdf8.png)
*Note*: When selecting the style type, it is important to consider the component being used.
4. Save 4. Save
5. Re-name the saved `.docx` file to `.zip` and un-zip 5. Re-name the saved `.docx` file to `.zip` and un-zip
6. Find `styles.xml` 6. Find `styles.xml`

7269
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,17 @@
{ {
"name": "docx", "name": "docx",
"version": "8.2.2", "version": "8.4.0",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.", "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"type": "module", "type": "module",
"main": "build/index.umd.js", "main": "build/index.umd.js",
"module": "./build/index.js", "module": "./build/index.mjs",
"types": "./build/index.d.ts", "types": "./build/index.d.ts",
"exports": { "exports": {
".": { ".": {
"require": "./build/index.cjs", "require": "./build/index.cjs",
"types": "./build/index.d.ts", "types": "./build/index.d.ts",
"import": "./build/index.js", "import": "./build/index.mjs",
"default": "./build/index.js" "default": "./build/index.mjs"
} }
}, },
"files": [ "files": [
@ -24,14 +24,14 @@
"prepublishOnly": "npm run build --omit=dev", "prepublishOnly": "npm run build --omit=dev",
"lint": "eslint --ext .ts src", "lint": "eslint --ext .ts src",
"predemo": "npm run build", "predemo": "npm run build",
"demo": "ts-node --project demo/tsconfig.json ./demo/index.ts", "demo": "tsx ./demo/index.ts",
"typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json", "typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"", "style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
"style.fix": "npm run style -- --write", "style.fix": "npm run style -- --write",
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"", "cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
"serve.docs": "cd docs && docsify serve", "serve.docs": "cd docs && docsify serve",
"extract": "ts-node scripts/extract-document.ts", "extract": "tsx scripts/extract-document.ts",
"ts-node": "ts-node --project demo/tsconfig.json" "run-ts": "tsx"
}, },
"pre-commit": [ "pre-commit": [
"style", "style",
@ -56,7 +56,7 @@
"dependencies": { "dependencies": {
"@types/node": "^20.3.1", "@types/node": "^20.3.1",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"nanoid": "^4.0.2", "nanoid": "^5.0.4",
"xml": "^1.0.1", "xml": "^1.0.1",
"xml-js": "^1.6.8" "xml-js": "^1.6.8"
}, },
@ -67,36 +67,35 @@
}, },
"homepage": "https://docx.js.org", "homepage": "https://docx.js.org",
"devDependencies": { "devDependencies": {
"@esbuild/win32-x64": "^0.18.3",
"@types/inquirer": "^9.0.3", "@types/inquirer": "^9.0.3",
"@types/prompt": "^1.1.1", "@types/prompt": "^1.1.1",
"@types/unzipper": "^0.10.4", "@types/unzipper": "^0.10.4",
"@types/xml": "^1.0.8", "@types/xml": "^1.0.8",
"@typescript-eslint/eslint-plugin": "^5.36.1", "@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^5.36.1", "@typescript-eslint/parser": "^6.9.1",
"@vitest/coverage-v8": "^0.33.0", "@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.33.0", "@vitest/ui": "^0.33.0",
"cspell": "^6.2.2", "cspell": "^7.3.8",
"docsify-cli": "^4.3.0", "docsify-cli": "^4.3.0",
"eslint": "^8.23.0", "eslint": "^8.23.0",
"eslint-plugin-functional": "^5.0.8", "eslint-plugin-functional": "^6.0.0",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^46.2.6", "eslint-plugin-jsdoc": "^46.2.6",
"eslint-plugin-no-null": "^1.0.2", "eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-prefer-arrow": "^1.2.3", "eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-unicorn": "^47.0.0", "eslint-plugin-unicorn": "^50.0.1",
"execa": "^7.1.1", "execa": "^8.0.1",
"glob": "^10.2.7", "glob": "^10.2.7",
"inquirer": "^9.2.7", "inquirer": "^9.2.7",
"jsdom": "^22.1.0", "jsdom": "^22.1.0",
"pre-commit": "^1.2.2", "pre-commit": "^1.2.2",
"prettier": "^2.3.1", "prettier": "^3.0.0",
"ts-node": "^10.2.1",
"tsconfig-paths": "^4.0.0", "tsconfig-paths": "^4.0.0",
"tsx": "^4.7.0",
"typedoc": "^0.24.8", "typedoc": "^0.24.8",
"typescript": "5.1.6", "typescript": "5.1.6",
"unzipper": "^0.10.11", "unzipper": "^0.10.11",
"vite": "^4.3.2", "vite": "^5.0.10",
"vite-plugin-dts": "^3.3.1", "vite-plugin-dts": "^3.3.1",
"vite-plugin-node-polyfills": "^0.9.0", "vite-plugin-node-polyfills": "^0.9.0",
"vite-tsconfig-paths": "^4.2.0", "vite-tsconfig-paths": "^4.2.0",

View File

@ -44,7 +44,7 @@ export class Compiler {
this.numberingReplacer = new NumberingReplacer(); this.numberingReplacer = new NumberingReplacer();
} }
public compile(file: File, prettifyXml?: PrettifyType): JSZip { public compile(file: File, prettifyXml?: (typeof PrettifyType)[keyof typeof PrettifyType]): JSZip {
const zip = new JSZip(); const zip = new JSZip();
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml); const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping)); const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
@ -66,7 +66,7 @@ export class Compiler {
return zip; return zip;
} }
private xmlifyFile(file: File, prettify?: PrettifyType): IXmlifyedFileMapping { private xmlifyFile(file: File, prettify?: (typeof PrettifyType)[keyof typeof PrettifyType]): IXmlifyedFileMapping {
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1; const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
const documentXmlData = xml( const documentXmlData = xml(

View File

@ -6,18 +6,21 @@ import { Compiler } from "./next-compiler";
/** /**
* Use blanks to prettify * Use blanks to prettify
*/ */
export enum PrettifyType { export const PrettifyType = {
NONE = "", NONE: "",
WITH_2_BLANKS = " ", WITH_2_BLANKS: " ",
WITH_4_BLANKS = " ", WITH_4_BLANKS: " ",
WITH_TAB = "\t", // eslint-disable-next-line @typescript-eslint/naming-convention
} WITH_TAB: "\t",
} as const;
const convertPrettifyType = (prettify?: boolean | PrettifyType): PrettifyType | undefined => const convertPrettifyType = (
prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType],
): (typeof PrettifyType)[keyof typeof PrettifyType] | undefined =>
prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify; prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify;
export class Packer { export class Packer {
public static async toString(file: File, prettify?: boolean | PrettifyType): Promise<string> { public static async toString(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string> {
const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zip = this.compiler.compile(file, convertPrettifyType(prettify));
const zipData = await zip.generateAsync({ const zipData = await zip.generateAsync({
type: "string", type: "string",
@ -28,7 +31,7 @@ export class Packer {
return zipData; return zipData;
} }
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> { public static async toBuffer(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Buffer> {
const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zip = this.compiler.compile(file, convertPrettifyType(prettify));
const zipData = await zip.generateAsync({ const zipData = await zip.generateAsync({
type: "nodebuffer", type: "nodebuffer",
@ -39,7 +42,7 @@ export class Packer {
return zipData; return zipData;
} }
public static async toBase64String(file: File, prettify?: boolean | PrettifyType): Promise<string> { public static async toBase64String(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string> {
const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zip = this.compiler.compile(file, convertPrettifyType(prettify));
const zipData = await zip.generateAsync({ const zipData = await zip.generateAsync({
type: "base64", type: "base64",
@ -50,7 +53,7 @@ export class Packer {
return zipData; return zipData;
} }
public static async toBlob(file: File, prettify?: boolean | PrettifyType): Promise<Blob> { public static async toBlob(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Blob> {
const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zip = this.compiler.compile(file, convertPrettifyType(prettify));
const zipData = await zip.generateAsync({ const zipData = await zip.generateAsync({
type: "blob", type: "blob",
@ -61,7 +64,7 @@ export class Packer {
return zipData; return zipData;
} }
public static toStream(file: File, prettify?: boolean | PrettifyType): Stream { public static toStream(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Stream {
const stream = new Stream(); const stream = new Stream();
const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zip = this.compiler.compile(file, convertPrettifyType(prettify));

View File

@ -23,7 +23,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values"; import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values";
export interface IBorderOptions { export interface IBorderOptions {
readonly style: BorderStyle; readonly style: (typeof BorderStyle)[keyof typeof BorderStyle];
/** Border color, in hex (eg 'FF00AA') */ /** Border color, in hex (eg 'FF00AA') */
readonly color?: string; readonly color?: string;
/** Size of the border in 1/8 pt */ /** Size of the border in 1/8 pt */
@ -55,32 +55,34 @@ class BordersAttributes extends XmlAttributeComponent<IBorderOptions> {
}; };
} }
export enum BorderStyle { /* eslint-disable @typescript-eslint/naming-convention */
SINGLE = "single", export const BorderStyle = {
DASH_DOT_STROKED = "dashDotStroked", SINGLE: "single",
DASHED = "dashed", DASH_DOT_STROKED: "dashDotStroked",
DASH_SMALL_GAP = "dashSmallGap", DASHED: "dashed",
DOT_DASH = "dotDash", DASH_SMALL_GAP: "dashSmallGap",
DOT_DOT_DASH = "dotDotDash", DOT_DASH: "dotDash",
DOTTED = "dotted", DOT_DOT_DASH: "dotDotDash",
DOUBLE = "double", DOTTED: "dotted",
DOUBLE_WAVE = "doubleWave", DOUBLE: "double",
INSET = "inset", DOUBLE_WAVE: "doubleWave",
NIL = "nil", INSET: "inset",
NONE = "none", NIL: "nil",
OUTSET = "outset", NONE: "none",
THICK = "thick", OUTSET: "outset",
THICK_THIN_LARGE_GAP = "thickThinLargeGap", THICK: "thick",
THICK_THIN_MEDIUM_GAP = "thickThinMediumGap", THICK_THIN_LARGE_GAP: "thickThinLargeGap",
THICK_THIN_SMALL_GAP = "thickThinSmallGap", THICK_THIN_MEDIUM_GAP: "thickThinMediumGap",
THIN_THICK_LARGE_GAP = "thinThickLargeGap", THICK_THIN_SMALL_GAP: "thickThinSmallGap",
THIN_THICK_MEDIUM_GAP = "thinThickMediumGap", THIN_THICK_LARGE_GAP: "thinThickLargeGap",
THIN_THICK_SMALL_GAP = "thinThickSmallGap", THIN_THICK_MEDIUM_GAP: "thinThickMediumGap",
THIN_THICK_THIN_LARGE_GAP = "thinThickThinLargeGap", THIN_THICK_SMALL_GAP: "thinThickSmallGap",
THIN_THICK_THIN_MEDIUM_GAP = "thinThickThinMediumGap", THIN_THICK_THIN_LARGE_GAP: "thinThickThinLargeGap",
THIN_THICK_THIN_SMALL_GAP = "thinThickThinSmallGap", THIN_THICK_THIN_MEDIUM_GAP: "thinThickThinMediumGap",
THREE_D_EMBOSS = "threeDEmboss", THIN_THICK_THIN_SMALL_GAP: "thinThickThinSmallGap",
THREE_D_ENGRAVE = "threeDEngrave", THREE_D_EMBOSS: "threeDEmboss",
TRIPLE = "triple", THREE_D_ENGRAVE: "threeDEngrave",
WAVE = "wave", TRIPLE: "triple",
} WAVE: "wave",
} as const;
/* eslint-enable */

View File

@ -39,6 +39,7 @@ export interface IPropertiesOptions {
readonly compatibility?: ICompatibilityOptions; readonly compatibility?: ICompatibilityOptions;
readonly customProperties?: readonly ICustomPropertyOptions[]; readonly customProperties?: readonly ICustomPropertyOptions[];
readonly evenAndOddHeaderAndFooters?: boolean; readonly evenAndOddHeaderAndFooters?: boolean;
readonly defaultTabStop?: number;
} }
// <xs:element name="coreProperties" type="CT_CoreProperties"/> // <xs:element name="coreProperties" type="CT_CoreProperties"/>

View File

@ -17,14 +17,17 @@ import { decimalNumber } from "@util/values";
// <xsd:attribute name="charSpace" type="ST_DecimalNumber"/> // <xsd:attribute name="charSpace" type="ST_DecimalNumber"/>
// </xsd:complexType> // </xsd:complexType>
export enum DocumentGridType { /* eslint-disable @typescript-eslint/naming-convention */
DEFAULT = "default", export const DocumentGridType = {
LINES = "lines", DEFAULT: "default",
LINES_AND_CHARS = "linesAndChars", LINES: "lines",
SNAP_TO_CHARS = "snapToChars", LINES_AND_CHARS: "linesAndChars",
} SNAP_TO_CHARS: "snapToChars",
} as const;
/* eslint-enable */
export interface IDocGridAttributesProperties { export interface IDocGridAttributesProperties {
readonly type?: DocumentGridType; readonly type?: (typeof DocumentGridType)[keyof typeof DocumentGridType];
readonly linePitch?: number; readonly linePitch?: number;
readonly charSpace?: number; readonly charSpace?: number;
} }
@ -38,7 +41,7 @@ export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesP
} }
export class DocumentGrid extends XmlComponent { export class DocumentGrid extends XmlComponent {
public constructor(linePitch: number, charSpace?: number, type?: DocumentGridType) { public constructor(linePitch: number, charSpace?: number, type?: (typeof DocumentGridType)[keyof typeof DocumentGridType]) {
super("w:docGrid"); super("w:docGrid");
this.root.push( this.root.push(

View File

@ -7,11 +7,11 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="first"/> // <xsd:enumeration value="first"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum HeaderFooterReferenceType { export const HeaderFooterReferenceType = {
DEFAULT = "default", DEFAULT: "default",
FIRST = "first", FIRST: "first",
EVEN = "even", EVEN: "even",
} } as const;
// </xsd:complexType> // </xsd:complexType>
// <xsd:group name="EG_HdrFtrReferences"> // <xsd:group name="EG_HdrFtrReferences">
@ -33,12 +33,12 @@ export enum HeaderFooterReferenceType {
// </xsd:complexType> // </xsd:complexType>
export interface IHeaderFooterOptions { export interface IHeaderFooterOptions {
readonly type?: HeaderFooterReferenceType; readonly type?: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
readonly id?: number; readonly id?: number;
} }
class FooterReferenceAttributes extends XmlAttributeComponent<{ class FooterReferenceAttributes extends XmlAttributeComponent<{
readonly type: HeaderFooterReferenceType; readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
readonly id: string; readonly id: string;
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
@ -47,12 +47,13 @@ class FooterReferenceAttributes extends XmlAttributeComponent<{
}; };
} }
export enum HeaderFooterType { export const HeaderFooterType = {
HEADER = "w:headerReference", HEADER: "w:headerReference",
FOOTER = "w:footerReference", FOOTER: "w:footerReference",
} } as const;
export class HeaderFooterReference extends XmlComponent { export class HeaderFooterReference extends XmlComponent {
public constructor(type: HeaderFooterType, options: IHeaderFooterOptions) { public constructor(type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType], options: IHeaderFooterOptions) {
super(type); super(type);
this.root.push( this.root.push(

View File

@ -9,11 +9,14 @@ import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@uti
// <xsd:enumeration value="continuous"/> // <xsd:enumeration value="continuous"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum LineNumberRestartFormat {
NEW_PAGE = "newPage", /* eslint-disable @typescript-eslint/naming-convention */
NEW_SECTION = "newSection", export const LineNumberRestartFormat = {
CONTINUOUS = "continuous", NEW_PAGE: "newPage",
} NEW_SECTION: "newSection",
CONTINUOUS: "continuous",
} as const;
/* eslint-enable */
// <xsd:complexType name="CT_LineNumber"> // <xsd:complexType name="CT_LineNumber">
// <xsd:attribute name="countBy" type="ST_DecimalNumber" use="optional"/> // <xsd:attribute name="countBy" type="ST_DecimalNumber" use="optional"/>
@ -25,7 +28,7 @@ export enum LineNumberRestartFormat {
export interface ILineNumberAttributes { export interface ILineNumberAttributes {
readonly countBy?: number; readonly countBy?: number;
readonly start?: number; readonly start?: number;
readonly restart?: LineNumberRestartFormat; readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
readonly distance?: number | PositiveUniversalMeasure; readonly distance?: number | PositiveUniversalMeasure;
} }
@ -36,13 +39,16 @@ export class LineNumberType extends XmlComponent {
new NextAttributeComponent<{ new NextAttributeComponent<{
readonly countBy?: number; readonly countBy?: number;
readonly start?: number; readonly start?: number;
readonly restart?: LineNumberRestartFormat; readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
readonly distance?: number | PositiveUniversalMeasure; readonly distance?: number | PositiveUniversalMeasure;
}>({ }>({
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) }, countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) }, start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
restart: { key: "w:restart", value: restart }, restart: { key: "w:restart", value: restart },
distance: { key: "w:distance", value: distance === undefined ? undefined : twipsMeasureValue(distance) }, distance: {
key: "w:distance",
value: distance === undefined ? undefined : twipsMeasureValue(distance),
},
}), }),
); );
} }

View File

@ -9,11 +9,14 @@ import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-comp
// <xsd:enumeration value="notFirstPage"/> // <xsd:enumeration value="notFirstPage"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PageBorderDisplay {
ALL_PAGES = "allPages", /* eslint-disable @typescript-eslint/naming-convention */
FIRST_PAGE = "firstPage", export const PageBorderDisplay = {
NOT_FIRST_PAGE = "notFirstPage", ALL_PAGES: "allPages",
} FIRST_PAGE: "firstPage",
NOT_FIRST_PAGE: "notFirstPage",
} as const;
/* eslint-enable */
// <xsd:simpleType name="ST_PageBorderOffset"> // <xsd:simpleType name="ST_PageBorderOffset">
// <xsd:restriction base="xsd:string"> // <xsd:restriction base="xsd:string">
@ -21,10 +24,10 @@ export enum PageBorderDisplay {
// <xsd:enumeration value="text"/> // <xsd:enumeration value="text"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PageBorderOffsetFrom { export const PageBorderOffsetFrom = {
PAGE = "page", PAGE: "page",
TEXT = "text", TEXT: "text",
} } as const;
// <xsd:simpleType name="ST_PageBorderZOrder"> // <xsd:simpleType name="ST_PageBorderZOrder">
// <xsd:restriction base="xsd:string"> // <xsd:restriction base="xsd:string">
@ -32,15 +35,15 @@ export enum PageBorderOffsetFrom {
// <xsd:enumeration value="back"/> // <xsd:enumeration value="back"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PageBorderZOrder { export const PageBorderZOrder = {
BACK = "back", BACK: "back",
FRONT = "front", FRONT: "front",
} } as const;
export interface IPageBorderAttributes { export interface IPageBorderAttributes {
readonly display?: PageBorderDisplay; readonly display?: (typeof PageBorderDisplay)[keyof typeof PageBorderDisplay];
readonly offsetFrom?: PageBorderOffsetFrom; readonly offsetFrom?: (typeof PageBorderOffsetFrom)[keyof typeof PageBorderOffsetFrom];
readonly zOrder?: PageBorderZOrder; readonly zOrder?: (typeof PageBorderZOrder)[keyof typeof PageBorderZOrder];
} }
export interface IPageBordersOptions { export interface IPageBordersOptions {

View File

@ -12,18 +12,22 @@ import { decimalNumber } from "@util/values";
// <xsd:enumeration value="enDash"/> // <xsd:enumeration value="enDash"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PageNumberSeparator {
HYPHEN = "hyphen", /* eslint-disable @typescript-eslint/naming-convention */
PERIOD = "period", export const PageNumberSeparator = {
COLON = "colon", HYPHEN: "hyphen",
EM_DASH = "emDash", PERIOD: "period",
EN_DASH = "endash", COLON: "colon",
} EM_DASH: "emDash",
EN_DASH: "endash",
} as const;
/* eslint-enable */
export interface IPageNumberTypeAttributes { export interface IPageNumberTypeAttributes {
readonly start?: number; readonly start?: number;
readonly formatType?: NumberFormat; readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
readonly separator?: PageNumberSeparator; readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator];
} }
// <xsd:complexType name="CT_PageNumber"> // <xsd:complexType name="CT_PageNumber">
@ -40,6 +44,7 @@ export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberT
separator: "w:chapSep", separator: "w:chapSep",
}; };
} }
export class PageNumberType extends XmlComponent { export class PageNumberType extends XmlComponent {
public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) { public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
super("w:pgNumType"); super("w:pgNumType");

View File

@ -7,10 +7,10 @@ import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
// <xsd:enumeration value="landscape"/> // <xsd:enumeration value="landscape"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PageOrientation { export const PageOrientation = {
PORTRAIT = "portrait", PORTRAIT: "portrait",
LANDSCAPE = "landscape", LANDSCAPE: "landscape",
} } as const;
// <xsd:complexType name="CT_PageSz"> // <xsd:complexType name="CT_PageSz">
// <xsd:attribute name="w" type="s:ST_TwipsMeasure"/> // <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
@ -21,11 +21,15 @@ export enum PageOrientation {
export type IPageSizeAttributes = { export type IPageSizeAttributes = {
readonly width?: number | PositiveUniversalMeasure; readonly width?: number | PositiveUniversalMeasure;
readonly height?: number | PositiveUniversalMeasure; readonly height?: number | PositiveUniversalMeasure;
readonly orientation?: PageOrientation; readonly orientation?: (typeof PageOrientation)[keyof typeof PageOrientation];
}; };
export class PageSize extends XmlComponent { export class PageSize extends XmlComponent {
public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) { public constructor(
width: number | PositiveUniversalMeasure,
height: number | PositiveUniversalMeasure,
orientation: (typeof PageOrientation)[keyof typeof PageOrientation],
) {
super("w:pgSz"); super("w:pgSz");
const flip = orientation === PageOrientation.LANDSCAPE; const flip = orientation === PageOrientation.LANDSCAPE;

View File

@ -1,16 +1,21 @@
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
export enum PageTextDirectionType { /* eslint-disable @typescript-eslint/naming-convention */
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb", export const PageTextDirectionType = {
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl", LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
} TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl",
} as const;
class PageTextDirectionAttributes extends XmlAttributeComponent<{ readonly val: PageTextDirectionType }> { /* eslint-enable */
class PageTextDirectionAttributes extends XmlAttributeComponent<{
readonly val: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
}> {
protected readonly xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
export class PageTextDirection extends XmlComponent { export class PageTextDirection extends XmlComponent {
public constructor(value: PageTextDirectionType) { public constructor(value: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType]) {
super("w:textDirection"); super("w:textDirection");
this.root.push( this.root.push(

View File

@ -10,19 +10,22 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="oddPage"/> // <xsd:enumeration value="oddPage"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum SectionType {
NEXT_PAGE = "nextPage", /* eslint-disable @typescript-eslint/naming-convention */
NEXT_COLUMN = "nextColumn", export const SectionType = {
CONTINUOUS = "continuous", NEXT_PAGE: "nextPage",
EVEN_PAGE = "evenPage", NEXT_COLUMN: "nextColumn",
ODD_PAGE = "oddPage", CONTINUOUS: "continuous",
} EVEN_PAGE: "evenPage",
ODD_PAGE: "oddPage",
} as const;
/* eslint-enable */
// <xsd:complexType name="CT_SectType"> // <xsd:complexType name="CT_SectType">
// <xsd:attribute name="val" type="ST_SectionMark"/> // <xsd:attribute name="val" type="ST_SectionMark"/>
// </xsd:complexType> // </xsd:complexType>
export class SectionTypeAttributes extends XmlAttributeComponent<{ export class SectionTypeAttributes extends XmlAttributeComponent<{
readonly val: SectionType; readonly val: (typeof SectionType)[keyof typeof SectionType];
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
val: "w:val", val: "w:val",
@ -30,7 +33,7 @@ export class SectionTypeAttributes extends XmlAttributeComponent<{
} }
export class Type extends XmlComponent { export class Type extends XmlComponent {
public constructor(value: SectionType) { public constructor(value: (typeof SectionType)[keyof typeof SectionType]) {
super("w:type"); super("w:type");
this.root.push(new SectionTypeAttributes({ val: value })); this.root.push(new SectionTypeAttributes({ val: value }));
} }

View File

@ -5,7 +5,6 @@ import { FooterWrapper } from "@file/footer-wrapper";
import { HeaderWrapper } from "@file/header-wrapper"; import { HeaderWrapper } from "@file/header-wrapper";
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align"; import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
import { OnOffElement, XmlComponent } from "@file/xml-components"; import { OnOffElement, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, UniversalMeasure } from "@util/values";
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference"; import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
import { Columns, IColumnsAttributes } from "./properties/columns"; import { Columns, IColumnsAttributes } from "./properties/columns";
@ -30,16 +29,16 @@ export interface ISectionPropertiesOptions {
readonly margin?: IPageMarginAttributes; readonly margin?: IPageMarginAttributes;
readonly pageNumbers?: IPageNumberTypeAttributes; readonly pageNumbers?: IPageNumberTypeAttributes;
readonly borders?: IPageBordersOptions; readonly borders?: IPageBordersOptions;
readonly textDirection?: PageTextDirectionType; readonly textDirection?: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
}; };
readonly grid?: IDocGridAttributesProperties; readonly grid?: IDocGridAttributesProperties;
readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>; readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>; readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>;
readonly lineNumbers?: ILineNumberAttributes; readonly lineNumbers?: ILineNumberAttributes;
readonly titlePage?: boolean; readonly titlePage?: boolean;
readonly verticalAlign?: VerticalAlign; readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
readonly column?: IColumnsAttributes; readonly column?: IColumnsAttributes;
readonly type?: SectionType; readonly type?: (typeof SectionType)[keyof typeof SectionType];
} }
// <xsd:complexType name="CT_SectPr"> // <xsd:complexType name="CT_SectPr">
@ -76,10 +75,10 @@ export interface ISectionPropertiesOptions {
// </xsd:group> // </xsd:group>
export const sectionMarginDefaults = { export const sectionMarginDefaults = {
TOP: "1in" as UniversalMeasure, TOP: 1440,
RIGHT: "1in" as PositiveUniversalMeasure, RIGHT: 1440,
BOTTOM: "1in" as UniversalMeasure, BOTTOM: 1440,
LEFT: "1in" as PositiveUniversalMeasure, LEFT: 1440,
HEADER: 708, HEADER: 708,
FOOTER: 708, FOOTER: 708,
GUTTER: 0, GUTTER: 0,
@ -163,7 +162,7 @@ export class SectionProperties extends XmlComponent {
} }
private addHeaderFooterGroup( private addHeaderFooterGroup(
type: HeaderFooterType, type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType],
group: IHeaderFooterGroup<HeaderWrapper> | IHeaderFooterGroup<FooterWrapper>, group: IHeaderFooterGroup<HeaderWrapper> | IHeaderFooterGroup<FooterWrapper>,
): void { ): void {
if (group.default) { if (group.default) {

View File

@ -80,6 +80,7 @@ export class Document extends XmlComponent {
} }
public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document { public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document {
// eslint-disable-next-line functional/immutable-data
this.body.push(item); this.body.push(item);
return this; return this;
} }

View File

@ -3,7 +3,11 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
import { XmlComponent } from "@file/xml-components"; import { XmlComponent } from "@file/xml-components";
export class Align extends XmlComponent { export class Align extends XmlComponent {
public constructor(value: HorizontalPositionAlign | VerticalPositionAlign) { public constructor(
value:
| (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign]
| (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign],
) {
super("wp:align"); super("wp:align");
this.root.push(value); this.root.push(value);
} }

View File

@ -4,37 +4,39 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
import { ITextWrapping } from "../text-wrap"; import { ITextWrapping } from "../text-wrap";
export enum HorizontalPositionRelativeFrom { /* eslint-disable @typescript-eslint/naming-convention */
CHARACTER = "character", export const HorizontalPositionRelativeFrom = {
COLUMN = "column", CHARACTER: "character",
INSIDE_MARGIN = "insideMargin", COLUMN: "column",
LEFT_MARGIN = "leftMargin", INSIDE_MARGIN: "insideMargin",
MARGIN = "margin", LEFT_MARGIN: "leftMargin",
OUTSIDE_MARGIN = "outsideMargin", MARGIN: "margin",
PAGE = "page", OUTSIDE_MARGIN: "outsideMargin",
RIGHT_MARGIN = "rightMargin", PAGE: "page",
} RIGHT_MARGIN: "rightMargin",
} as const;
export enum VerticalPositionRelativeFrom { export const VerticalPositionRelativeFrom = {
BOTTOM_MARGIN = "bottomMargin", BOTTOM_MARGIN: "bottomMargin",
INSIDE_MARGIN = "insideMargin", INSIDE_MARGIN: "insideMargin",
LINE = "line", LINE: "line",
MARGIN = "margin", MARGIN: "margin",
OUTSIDE_MARGIN = "outsideMargin", OUTSIDE_MARGIN: "outsideMargin",
PAGE = "page", PAGE: "page",
PARAGRAPH = "paragraph", PARAGRAPH: "paragraph",
TOP_MARGIN = "topMargin", TOP_MARGIN: "topMargin",
} } as const;
/* eslint-enable */
export interface IHorizontalPositionOptions { export interface IHorizontalPositionOptions {
readonly relative?: HorizontalPositionRelativeFrom; readonly relative?: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom];
readonly align?: HorizontalPositionAlign; readonly align?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly offset?: number; readonly offset?: number;
} }
export interface IVerticalPositionOptions { export interface IVerticalPositionOptions {
readonly relative?: VerticalPositionRelativeFrom; readonly relative?: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
readonly align?: VerticalPositionAlign; readonly align?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
readonly offset?: number; readonly offset?: number;
} }

View File

@ -5,7 +5,7 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl
import { PositionOffset } from "./position-offset"; import { PositionOffset } from "./position-offset";
class HorizontalPositionAttributes extends XmlAttributeComponent<{ class HorizontalPositionAttributes extends XmlAttributeComponent<{
readonly relativeFrom: HorizontalPositionRelativeFrom; readonly relativeFrom: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom];
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
relativeFrom: "relativeFrom", relativeFrom: "relativeFrom",

View File

@ -5,7 +5,7 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati
import { PositionOffset } from "./position-offset"; import { PositionOffset } from "./position-offset";
class VerticalPositionAttributes extends XmlAttributeComponent<{ class VerticalPositionAttributes extends XmlAttributeComponent<{
readonly relativeFrom: VerticalPositionRelativeFrom; readonly relativeFrom: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
relativeFrom: "relativeFrom", relativeFrom: "relativeFrom",

View File

@ -1,22 +1,25 @@
// http://officeopenxml.com/drwPicFloating-textWrap.php // http://officeopenxml.com/drwPicFloating-textWrap.php
import { IDistance } from "../drawing"; import { IDistance } from "../drawing";
export enum TextWrappingType { /* eslint-disable @typescript-eslint/naming-convention */
NONE, export const TextWrappingType = {
SQUARE, NONE: 0,
TIGHT, SQUARE: 1,
TOP_AND_BOTTOM, TIGHT: 2,
} TOP_AND_BOTTOM: 3,
} as const;
export enum TextWrappingSide { export const TextWrappingSide = {
BOTH_SIDES = "bothSides", BOTH_SIDES: "bothSides",
LEFT = "left", LEFT: "left",
RIGHT = "right", RIGHT: "right",
LARGEST = "largest", LARGEST: "largest",
} } as const;
/* eslint-enable */
export interface ITextWrapping { export interface ITextWrapping {
readonly type: TextWrappingType; readonly type: (typeof TextWrappingType)[keyof typeof TextWrappingType];
readonly side?: TextWrappingSide; readonly side?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
readonly margins?: IDistance; readonly margins?: IDistance;
} }

View File

@ -6,7 +6,7 @@ import { IMargins } from "../floating";
import { ITextWrapping, TextWrappingSide } from "./text-wrapping"; import { ITextWrapping, TextWrappingSide } from "./text-wrapping";
interface IWrapSquareAttributes extends IDistance { interface IWrapSquareAttributes extends IDistance {
readonly wrapText?: TextWrappingSide; readonly wrapText?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
} }
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> { class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {

View File

@ -77,6 +77,7 @@ export class File {
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false, evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
trackRevisions: options.features?.trackRevisions, trackRevisions: options.features?.trackRevisions,
updateFields: options.features?.updateFields, updateFields: options.features?.updateFields,
defaultTabStop: options.defaultTabStop,
}); });
this.media = new Media(); this.media = new Media();
@ -154,7 +155,10 @@ export class File {
return wrapper; return wrapper;
} }
private addHeaderToDocument(header: HeaderWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void { private addHeaderToDocument(
header: HeaderWrapper,
type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT,
): void {
// eslint-disable-next-line functional/immutable-data // eslint-disable-next-line functional/immutable-data
this.headers.push({ header, type }); this.headers.push({ header, type });
this.documentWrapper.Relationships.createRelationship( this.documentWrapper.Relationships.createRelationship(
@ -165,7 +169,10 @@ export class File {
this.contentTypes.addHeader(this.headers.length); this.contentTypes.addHeader(this.headers.length);
} }
private addFooterToDocument(footer: FooterWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void { private addFooterToDocument(
footer: FooterWrapper,
type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT,
): void {
// eslint-disable-next-line functional/immutable-data // eslint-disable-next-line functional/immutable-data
this.footers.push({ footer, type }); this.footers.push({ footer, type });
this.documentWrapper.Relationships.createRelationship( this.documentWrapper.Relationships.createRelationship(

View File

@ -10,14 +10,18 @@ import { Table } from "./table";
export interface IDocumentFooter { export interface IDocumentFooter {
readonly footer: FooterWrapper; readonly footer: FooterWrapper;
readonly type: HeaderFooterReferenceType; readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
} }
export class FooterWrapper implements IViewWrapper { export class FooterWrapper implements IViewWrapper {
private readonly footer: Footer; private readonly footer: Footer;
private readonly relationships: Relationships; private readonly relationships: Relationships;
public constructor(private readonly media: Media, referenceId: number, initContent?: XmlComponent) { public constructor(
private readonly media: Media,
referenceId: number,
initContent?: XmlComponent,
) {
this.footer = new Footer(referenceId, initContent); this.footer = new Footer(referenceId, initContent);
this.relationships = new Relationships(); this.relationships = new Relationships();
} }

View File

@ -4,14 +4,15 @@ import { XmlComponent } from "@file/xml-components";
import { FootnoteAttributes } from "./footnote-attributes"; import { FootnoteAttributes } from "./footnote-attributes";
import { FootnoteRefRun } from "./run/footnote-ref-run"; import { FootnoteRefRun } from "./run/footnote-ref-run";
export enum FootnoteType { export const FootnoteType = {
SEPERATOR = "separator", SEPERATOR: "separator",
CONTINUATION_SEPERATOR = "continuationSeparator", // eslint-disable-next-line @typescript-eslint/naming-convention
} CONTINUATION_SEPERATOR: "continuationSeparator",
} as const;
export interface IFootnoteOptions { export interface IFootnoteOptions {
readonly id: number; readonly id: number;
readonly type?: FootnoteType; readonly type?: (typeof FootnoteType)[keyof typeof FootnoteType];
readonly children: readonly Paragraph[]; readonly children: readonly Paragraph[];
} }

View File

@ -10,14 +10,18 @@ import { Table } from "./table";
export interface IDocumentHeader { export interface IDocumentHeader {
readonly header: HeaderWrapper; readonly header: HeaderWrapper;
readonly type: HeaderFooterReferenceType; readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
} }
export class HeaderWrapper implements IViewWrapper { export class HeaderWrapper implements IViewWrapper {
private readonly header: Header; private readonly header: Header;
private readonly relationships: Relationships; private readonly relationships: Relationships;
public constructor(private readonly media: Media, referenceId: number, initContent?: XmlComponent) { public constructor(
private readonly media: Media,
referenceId: number,
initContent?: XmlComponent,
) {
this.header = new Header(referenceId, initContent); this.header = new Header(referenceId, initContent);
this.relationships = new Relationships(); this.relationships = new Relationships();
} }

View File

@ -75,71 +75,75 @@ import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/prop
// <xsd:enumeration value="custom"/> // <xsd:enumeration value="custom"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum LevelFormat {
DECIMAL = "decimal", /* eslint-disable @typescript-eslint/naming-convention */
UPPER_ROMAN = "upperRoman", export const LevelFormat = {
LOWER_ROMAN = "lowerRoman", DECIMAL: "decimal",
UPPER_LETTER = "upperLetter", UPPER_ROMAN: "upperRoman",
LOWER_LETTER = "lowerLetter", LOWER_ROMAN: "lowerRoman",
ORDINAL = "ordinal", UPPER_LETTER: "upperLetter",
CARDINAL_TEXT = "cardinalText", LOWER_LETTER: "lowerLetter",
ORDINAL_TEXT = "ordinalText", ORDINAL: "ordinal",
HEX = "hex", CARDINAL_TEXT: "cardinalText",
CHICAGO = "chicago", ORDINAL_TEXT: "ordinalText",
IDEOGRAPH__DIGITAL = "ideographDigital", HEX: "hex",
JAPANESE_COUNTING = "japaneseCounting", CHICAGO: "chicago",
AIUEO = "aiueo", IDEOGRAPH__DIGITAL: "ideographDigital",
IROHA = "iroha", JAPANESE_COUNTING: "japaneseCounting",
DECIMAL_FULL_WIDTH = "decimalFullWidth", AIUEO: "aiueo",
DECIMAL_HALF_WIDTH = "decimalHalfWidth", IROHA: "iroha",
JAPANESE_LEGAL = "japaneseLegal", DECIMAL_FULL_WIDTH: "decimalFullWidth",
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand", DECIMAL_HALF_WIDTH: "decimalHalfWidth",
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle", JAPANESE_LEGAL: "japaneseLegal",
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2", JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand",
AIUEO_FULL_WIDTH = "aiueoFullWidth", DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle",
IROHA_FULL_WIDTH = "irohaFullWidth", DECIMAL_FULL_WIDTH2: "decimalFullWidth2",
DECIMAL_ZERO = "decimalZero", AIUEO_FULL_WIDTH: "aiueoFullWidth",
BULLET = "bullet", IROHA_FULL_WIDTH: "irohaFullWidth",
GANADA = "ganada", DECIMAL_ZERO: "decimalZero",
CHOSUNG = "chosung", BULLET: "bullet",
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop", GANADA: "ganada",
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen", CHOSUNG: "chosung",
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese", DECIMAL_ENCLOSED_FULLSTOP: "decimalEnclosedFullstop",
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle", DECIMAL_ENCLOSED_PARENTHESES: "decimalEnclosedParen",
IDEOGRAPH_TRADITIONAL = "ideographTraditional", DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese",
IDEOGRAPH_ZODIAC = "ideographZodiac", IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle",
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional", IDEOGRAPH_TRADITIONAL: "ideographTraditional",
TAIWANESE_COUNTING = "taiwaneseCounting", IDEOGRAPH_ZODIAC: "ideographZodiac",
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional", IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional",
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand", TAIWANESE_COUNTING: "taiwaneseCounting",
TAIWANESE_DIGITAL = "taiwaneseDigital", IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional",
CHINESE_COUNTING = "chineseCounting", TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand",
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified", TAIWANESE_DIGITAL: "taiwaneseDigital",
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand", CHINESE_COUNTING: "chineseCounting",
KOREAN_DIGITAL = "koreanDigital", CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified",
KOREAN_COUNTING = "koreanCounting", CHINESE_COUNTING_THOUSAND: "chineseCountingThousand",
KOREAN_LEGAL = "koreanLegal", KOREAN_DIGITAL: "koreanDigital",
KOREAN_DIGITAL2 = "koreanDigital2", KOREAN_COUNTING: "koreanCounting",
VIETNAMESE_COUNTING = "vietnameseCounting", KOREAN_LEGAL: "koreanLegal",
RUSSIAN_LOWER = "russianLower", KOREAN_DIGITAL2: "koreanDigital2",
RUSSIAN_UPPER = "russianUpper", VIETNAMESE_COUNTING: "vietnameseCounting",
NONE = "none", RUSSIAN_LOWER: "russianLower",
NUMBER_IN_DASH = "numberInDash", RUSSIAN_UPPER: "russianUpper",
HEBREW1 = "hebrew1", NONE: "none",
HEBREW2 = "hebrew2", NUMBER_IN_DASH: "numberInDash",
ARABIC_ALPHA = "arabicAlpha", HEBREW1: "hebrew1",
ARABIC_ABJAD = "arabicAbjad", HEBREW2: "hebrew2",
HINDI_VOWELS = "hindiVowels", ARABIC_ALPHA: "arabicAlpha",
HINDI_CONSONANTS = "hindiConsonants", ARABIC_ABJAD: "arabicAbjad",
HINDI_NUMBERS = "hindiNumbers", HINDI_VOWELS: "hindiVowels",
HINDI_COUNTING = "hindiCounting", HINDI_CONSONANTS: "hindiConsonants",
THAI_LETTERS = "thaiLetters", HINDI_NUMBERS: "hindiNumbers",
THAI_NUMBERS = "thaiNumbers", HINDI_COUNTING: "hindiCounting",
THAI_COUNTING = "thaiCounting", THAI_LETTERS: "thaiLetters",
BAHT_TEXT = "bahtText", THAI_NUMBERS: "thaiNumbers",
DOLLAR_TEXT = "dollarText", THAI_COUNTING: "thaiCounting",
CUSTOM = "custom", BAHT_TEXT: "bahtText",
} DOLLAR_TEXT: "dollarText",
CUSTOM: "custom",
} as const;
/* eslint-enable */
class LevelAttributes extends XmlAttributeComponent<{ class LevelAttributes extends XmlAttributeComponent<{
readonly ilvl?: number; readonly ilvl?: number;
@ -182,7 +186,7 @@ class LevelText extends XmlComponent {
} }
class LevelJc extends XmlComponent { class LevelJc extends XmlComponent {
public constructor(value: AlignmentType) { public constructor(value: (typeof AlignmentType)[keyof typeof AlignmentType]) {
super("w:lvlJc"); super("w:lvlJc");
this.root.push( this.root.push(
new Attributes({ new Attributes({
@ -192,19 +196,19 @@ class LevelJc extends XmlComponent {
} }
} }
export enum LevelSuffix { export const LevelSuffix = {
NOTHING = "nothing", NOTHING: "nothing",
SPACE = "space", SPACE: "space",
TAB = "tab", TAB: "tab",
} } as const;
export interface ILevelsOptions { export interface ILevelsOptions {
readonly level: number; readonly level: number;
readonly format?: LevelFormat; readonly format?: (typeof LevelFormat)[keyof typeof LevelFormat];
readonly text?: string; readonly text?: string;
readonly alignment?: AlignmentType; readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
readonly start?: number; readonly start?: number;
readonly suffix?: LevelSuffix; readonly suffix?: (typeof LevelSuffix)[keyof typeof LevelSuffix];
readonly isLegalNumberingStyle?: boolean; readonly isLegalNumberingStyle?: boolean;
readonly style?: { readonly style?: {
readonly run?: IRunStylePropertiesOptions; readonly run?: IRunStylePropertiesOptions;
@ -223,7 +227,7 @@ export interface ILevelsOptions {
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
class Suffix extends XmlComponent { class Suffix extends XmlComponent {
public constructor(value: LevelSuffix) { public constructor(value: (typeof LevelSuffix)[keyof typeof LevelSuffix]) {
super("w:suff"); super("w:suff");
this.root.push( this.root.push(
new Attributes({ new Attributes({

View File

@ -216,7 +216,7 @@ export class Numbering extends XmlComponent {
abstractNumId: abstractNumbering.id, abstractNumId: abstractNumbering.id,
reference, reference,
instance, instance,
overrideLevel: overrideLevels: [
firstLevelStartNumber && Number.isInteger(firstLevelStartNumber) firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)
? { ? {
num: 0, num: 0,
@ -226,6 +226,7 @@ export class Numbering extends XmlComponent {
num: 0, num: 0,
start: 1, start: 1,
}, },
],
}; };
this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings)); this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings));

View File

@ -19,41 +19,47 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="right"/> // <xsd:enumeration value="right"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum AlignmentType {
/** Align Start */
START = "start",
/** Align Center */
CENTER = "center",
/** End */
END = "end",
/** Justified */
BOTH = "both",
/** Medium Kashida Length */
MEDIUM_KASHIDA = "mediumKashida",
/** Distribute All Characters Equally */
DISTRIBUTE = "distribute",
/** Align to List Tab */
NUM_TAB = "numTab",
/** Widest Kashida Length */
HIGH_KASHIDA = "highKashida",
/** Low Kashida Length */
LOW_KASHIDA = "lowKashida",
/** Thai Language Justification */
THAI_DISTRIBUTE = "thaiDistribute",
/** Align Left */
LEFT = "left",
/** Align Right */
RIGHT = "right",
/** Justified */
JUSTIFIED = "both",
}
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> { /* eslint-disable @typescript-eslint/naming-convention */
export const AlignmentType = {
/** Align Start */
START: "start",
/** Align Center */
CENTER: "center",
/** End */
END: "end",
/** Justified */
BOTH: "both",
/** Medium Kashida Length */
MEDIUM_KASHIDA: "mediumKashida",
/** Distribute All Characters Equally */
DISTRIBUTE: "distribute",
/** Align to List Tab */
NUM_TAB: "numTab",
/** Widest Kashida Length */
HIGH_KASHIDA: "highKashida",
/** Low Kashida Length */
LOW_KASHIDA: "lowKashida",
/** Thai Language Justification */
THAI_DISTRIBUTE: "thaiDistribute",
/** Align Left */
LEFT: "left",
/** Align Right */
RIGHT: "right",
/** Justified */
JUSTIFIED: "both",
} as const;
/* eslint-enable */
export class AlignmentAttributes extends XmlAttributeComponent<{
readonly val: (typeof AlignmentType)[keyof typeof AlignmentType];
}> {
protected readonly xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
export class Alignment extends XmlComponent { export class Alignment extends XmlComponent {
public constructor(type: AlignmentType) { public constructor(type: (typeof AlignmentType)[keyof typeof AlignmentType]) {
super("w:jc"); super("w:jc");
this.root.push(new AlignmentAttributes({ val: type })); this.root.push(new AlignmentAttributes({ val: type }));
} }

View File

@ -2,14 +2,14 @@
import { Attributes, XmlComponent } from "@file/xml-components"; import { Attributes, XmlComponent } from "@file/xml-components";
import { Run } from "../run"; import { Run } from "../run";
enum BreakType { const BreakType = {
COLUMN = "column", COLUMN: "column",
PAGE = "page", PAGE: "page",
// textWrapping breaks are the default and already exposed via the "Run" class // textWrapping breaks are the default and already exposed via the "Run" class
} } as const;
class Break extends XmlComponent { class Break extends XmlComponent {
public constructor(type: BreakType) { public constructor(type: (typeof BreakType)[keyof typeof BreakType]) {
super("w:br"); super("w:br");
this.root.push( this.root.push(
new Attributes({ new Attributes({

View File

@ -1,17 +1,19 @@
// http://officeopenxml.com/WPspacing.php // http://officeopenxml.com/WPspacing.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
export enum LineRuleType { export const LineRuleType = {
AT_LEAST = "atLeast", // eslint-disable-next-line @typescript-eslint/naming-convention
EXACTLY = "exactly", AT_LEAST: "atLeast",
EXACT = "exact", EXACTLY: "exactly",
AUTO = "auto", EXACT: "exact",
} AUTO: "auto",
} as const;
export interface ISpacingProperties { export interface ISpacingProperties {
readonly after?: number; readonly after?: number;
readonly before?: number; readonly before?: number;
readonly line?: number; readonly line?: number;
readonly lineRule?: LineRuleType; readonly lineRule?: (typeof LineRuleType)[keyof typeof LineRuleType];
readonly beforeAutoSpacing?: boolean; readonly beforeAutoSpacing?: boolean;
readonly afterAutoSpacing?: boolean; readonly afterAutoSpacing?: boolean;
} }

View File

@ -1,14 +1,14 @@
import { Attributes, XmlComponent } from "@file/xml-components"; import { Attributes, XmlComponent } from "@file/xml-components";
export enum HeadingLevel { export const HeadingLevel = {
HEADING_1 = "Heading1", HEADING_1: "Heading1",
HEADING_2 = "Heading2", HEADING_2: "Heading2",
HEADING_3 = "Heading3", HEADING_3: "Heading3",
HEADING_4 = "Heading4", HEADING_4: "Heading4",
HEADING_5 = "Heading5", HEADING_5: "Heading5",
HEADING_6 = "Heading6", HEADING_6: "Heading6",
TITLE = "Title", TITLE: "Title",
} } as const;
export class Style extends XmlComponent { export class Style extends XmlComponent {
public constructor(styleId: string) { public constructor(styleId: string) {

View File

@ -2,9 +2,9 @@
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
export interface TabStopDefinition { export interface TabStopDefinition {
readonly type: TabStopType; readonly type: (typeof TabStopType)[keyof typeof TabStopType];
readonly position: number | TabStopPosition; readonly position: number | (typeof TabStopPosition)[keyof typeof TabStopPosition];
readonly leader?: LeaderType; readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
} }
export class TabStop extends XmlComponent { export class TabStop extends XmlComponent {
@ -17,34 +17,35 @@ export class TabStop extends XmlComponent {
} }
} }
export enum TabStopType { export const TabStopType = {
LEFT = "left", LEFT: "left",
RIGHT = "right", RIGHT: "right",
CENTER = "center", CENTER: "center",
BAR = "bar", BAR: "bar",
CLEAR = "clear", CLEAR: "clear",
DECIMAL = "decimal", DECIMAL: "decimal",
END = "end", END: "end",
NUM = "num", NUM: "num",
START = "start", START: "start",
} } as const;
export enum LeaderType { export const LeaderType = {
DOT = "dot", DOT: "dot",
HYPHEN = "hyphen", HYPHEN: "hyphen",
MIDDLE_DOT = "middleDot", // eslint-disable-next-line @typescript-eslint/naming-convention
NONE = "none", MIDDLE_DOT: "middleDot",
UNDERSCORE = "underscore", NONE: "none",
} UNDERSCORE: "underscore",
} as const;
export enum TabStopPosition { export const TabStopPosition = {
MAX = 9026, MAX: 9026,
} } as const;
export class TabAttributes extends XmlAttributeComponent<{ export class TabAttributes extends XmlAttributeComponent<{
readonly val: TabStopType; readonly val: (typeof TabStopType)[keyof typeof TabStopType];
readonly pos: string | number; readonly pos: string | number;
readonly leader?: LeaderType; readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
}> { }> {
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" }; protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
} }

View File

@ -3,43 +3,44 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
import { HeightRule } from "@file/table"; import { HeightRule } from "@file/table";
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
export enum DropCapType { export const DropCapType = {
NONE = "none", NONE: "none",
DROP = "drop", DROP: "drop",
MARGIN = "margin", MARGIN: "margin",
} } as const;
export enum FrameAnchorType { export const FrameAnchorType = {
MARGIN = "margin", MARGIN: "margin",
PAGE = "page", PAGE: "page",
TEXT = "text", TEXT: "text",
} } as const;
export enum FrameWrap { export const FrameWrap = {
AROUND = "around", AROUND: "around",
AUTO = "auto", AUTO: "auto",
NONE = "none", NONE: "none",
NOT_BESIDE = "notBeside", // eslint-disable-next-line @typescript-eslint/naming-convention
THROUGH = "through", NOT_BESIDE: "notBeside",
TIGHT = "tight", THROUGH: "through",
} TIGHT: "tight",
} as const;
interface IBaseFrameOptions { interface IBaseFrameOptions {
readonly anchorLock?: boolean; readonly anchorLock?: boolean;
readonly dropCap?: DropCapType; readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
readonly width: number; readonly width: number;
readonly height: number; readonly height: number;
readonly wrap?: FrameWrap; readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap];
readonly lines?: number; readonly lines?: number;
readonly anchor: { readonly anchor: {
readonly horizontal: FrameAnchorType; readonly horizontal: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
readonly vertical: FrameAnchorType; readonly vertical: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
}; };
readonly space?: { readonly space?: {
readonly horizontal: number; readonly horizontal: number;
readonly vertical: number; readonly vertical: number;
}; };
readonly rule?: HeightRule; readonly rule?: (typeof HeightRule)[keyof typeof HeightRule];
} }
export interface IXYFrameOptions extends IBaseFrameOptions { export interface IXYFrameOptions extends IBaseFrameOptions {
@ -51,8 +52,8 @@ export interface IXYFrameOptions extends IBaseFrameOptions {
export interface IAlignmentFrameOptions extends IBaseFrameOptions { export interface IAlignmentFrameOptions extends IBaseFrameOptions {
readonly alignment: { readonly alignment: {
readonly x: HorizontalPositionAlign; readonly x: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly y: VerticalPositionAlign; readonly y: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
}; };
} }
@ -62,20 +63,20 @@ export type IFrameOptions = IXYFrameOptions | IAlignmentFrameOptions;
export class FramePropertiesAttributes extends XmlAttributeComponent<{ export class FramePropertiesAttributes extends XmlAttributeComponent<{
readonly anchorLock?: boolean; readonly anchorLock?: boolean;
readonly dropCap?: DropCapType; readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
readonly width: number; readonly width: number;
readonly height: number; readonly height: number;
readonly x?: number; readonly x?: number;
readonly y?: number; readonly y?: number;
readonly wrap?: FrameWrap; readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap];
readonly lines?: number; readonly lines?: number;
readonly anchorHorizontal?: FrameAnchorType; readonly anchorHorizontal?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
readonly anchorVertical?: FrameAnchorType; readonly anchorVertical?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
readonly spaceHorizontal?: number; readonly spaceHorizontal?: number;
readonly spaceVertical?: number; readonly spaceVertical?: number;
readonly rule?: HeightRule; readonly rule?: (typeof HeightRule)[keyof typeof HeightRule];
readonly alignmentX?: HorizontalPositionAlign; readonly alignmentX?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly alignmentY?: VerticalPositionAlign; readonly alignmentY?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
anchorLock: "w:anchorLock", anchorLock: "w:anchorLock",

View File

@ -5,10 +5,10 @@ import { uniqueId } from "@util/convenience-functions";
import { ParagraphChild } from "../paragraph"; import { ParagraphChild } from "../paragraph";
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes"; import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
export enum HyperlinkType { export const HyperlinkType = {
INTERNAL = "INTERNAL", INTERNAL: "INTERNAL",
EXTERNAL = "EXTERNAL", EXTERNAL: "EXTERNAL",
} } as const;
export class ConcreteHyperlink extends XmlComponent { export class ConcreteHyperlink extends XmlComponent {
public readonly linkId: string; public readonly linkId: string;
@ -39,7 +39,12 @@ export class InternalHyperlink extends ConcreteHyperlink {
} }
export class ExternalHyperlink extends XmlComponent { export class ExternalHyperlink extends XmlComponent {
public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) { public constructor(
public readonly options: {
readonly children: readonly ParagraphChild[];
readonly link: string;
},
) {
super("w:externalHyperlink"); super("w:externalHyperlink");
} }
} }

View File

@ -158,5 +158,37 @@ describe("ParagraphProperties", () => {
], ],
}); });
}); });
it("should create with the run property", () => {
const properties = new ParagraphProperties({
run: {
size: "10pt",
},
});
const tree = new Formatter().format(properties);
expect(tree).to.deep.equal({
"w:pPr": [
{
"w:rPr": [
{
"w:sz": {
_attr: {
"w:val": "10pt",
},
},
},
{
"w:szCs": {
_attr: {
"w:val": "10pt",
},
},
},
],
},
],
});
});
}); });
}); });

View File

@ -1,5 +1,6 @@
// http://officeopenxml.com/WPparagraphProperties.php // http://officeopenxml.com/WPparagraphProperties.php
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_suppressLineNumbers_topic_ID0ECJAO.html // https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_suppressLineNumbers_topic_ID0ECJAO.html
/* eslint-disable functional/immutable-data */
import { IContext, IgnoreIfEmptyXmlComponent, IXmlableObject, OnOffElement, XmlComponent } from "@file/xml-components"; import { IContext, IgnoreIfEmptyXmlComponent, IXmlableObject, OnOffElement, XmlComponent } from "@file/xml-components";
import { DocumentWrapper } from "../document-wrapper"; import { DocumentWrapper } from "../document-wrapper";
import { IShadingAttributesProperties, Shading } from "../shading"; import { IShadingAttributesProperties, Shading } from "../shading";
@ -14,9 +15,10 @@ import { NumberProperties } from "./formatting/unordered-list";
import { WordWrap } from "./formatting/word-wrap"; import { WordWrap } from "./formatting/word-wrap";
import { FrameProperties, IFrameOptions } from "./frame/frame-properties"; import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
import { OutlineLevel } from "./links"; import { OutlineLevel } from "./links";
import { IRunOptions, RunProperties } from ".";
export interface ILevelParagraphStylePropertiesOptions { export interface ILevelParagraphStylePropertiesOptions {
readonly alignment?: AlignmentType; readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
readonly thematicBreak?: boolean; readonly thematicBreak?: boolean;
readonly contextualSpacing?: boolean; readonly contextualSpacing?: boolean;
readonly rightTabStop?: number; readonly rightTabStop?: number;
@ -45,7 +47,7 @@ export interface IParagraphStylePropertiesOptions extends ILevelParagraphStylePr
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions { export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
readonly border?: IBordersOptions; readonly border?: IBordersOptions;
readonly heading?: HeadingLevel; readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
readonly bidirectional?: boolean; readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean; readonly pageBreakBefore?: boolean;
readonly tabStops?: readonly TabStopDefinition[]; readonly tabStops?: readonly TabStopDefinition[];
@ -64,6 +66,10 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
* This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard. * This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard.
*/ */
readonly autoSpaceEastAsianText?: boolean; readonly autoSpaceEastAsianText?: boolean;
/**
* Reference: ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference § 17.3.1.29.
*/
readonly run?: IRunOptions;
} }
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
@ -151,9 +157,9 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
* Ensure there is only one w:tabs tag with multiple w:tab * Ensure there is only one w:tabs tag with multiple w:tab
*/ */
const tabDefinitions: readonly TabStopDefinition[] = [ const tabDefinitions: readonly TabStopDefinition[] = [
...(options.rightTabStop ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []), ...(options.rightTabStop !== undefined ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
...(options.tabStops ? options.tabStops : []), ...(options.tabStops ? options.tabStops : []),
...(options.leftTabStop ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []), ...(options.leftTabStop !== undefined ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
]; ];
if (tabDefinitions.length > 0) { if (tabDefinitions.length > 0) {
@ -194,6 +200,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
if (options.autoSpaceEastAsianText !== undefined) { if (options.autoSpaceEastAsianText !== undefined) {
this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText)); this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText));
} }
if (options.run) {
this.push(new RunProperties(options.run));
}
} }
public push(item: XmlComponent): void { public push(item: XmlComponent): void {

View File

@ -1,11 +1,11 @@
import { Attributes, XmlComponent } from "@file/xml-components"; import { Attributes, XmlComponent } from "@file/xml-components";
export enum EmphasisMarkType { export const EmphasisMarkType = {
DOT = "dot", DOT: "dot",
} } as const;
export abstract class BaseEmphasisMark extends XmlComponent { export abstract class BaseEmphasisMark extends XmlComponent {
protected constructor(emphasisMarkType: EmphasisMarkType) { protected constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType]) {
super("w:em"); super("w:em");
this.root.push( this.root.push(
new Attributes({ new Attributes({
@ -16,7 +16,7 @@ export abstract class BaseEmphasisMark extends XmlComponent {
} }
export class EmphasisMark extends BaseEmphasisMark { export class EmphasisMark extends BaseEmphasisMark {
public constructor(emphasisMarkType: EmphasisMarkType = EmphasisMarkType.DOT) { public constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType] = EmphasisMarkType.DOT) {
super(emphasisMarkType); super(emphasisMarkType);
} }
} }

View File

@ -1,12 +1,15 @@
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
enum FieldCharacterType { const FieldCharacterType = {
BEGIN = "begin", BEGIN: "begin",
END = "end", END: "end",
SEPARATE = "separate", SEPARATE: "separate",
} } as const;
class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> { class FidCharAttrs extends XmlAttributeComponent<{
readonly type: (typeof FieldCharacterType)[keyof typeof FieldCharacterType];
readonly dirty?: boolean;
}> {
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" }; protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
} }

View File

@ -7,11 +7,11 @@ import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="right" /> // <xsd:enumeration value="right" />
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PositionalTabAlignment { export const PositionalTabAlignment = {
LEFT = "left", LEFT: "left",
CENTER = "center", CENTER: "center",
RIGHT = "right", RIGHT: "right",
} } as const;
// <xsd:simpleType name="ST_PTabRelativeTo"> // <xsd:simpleType name="ST_PTabRelativeTo">
// <xsd:restriction base="xsd:string"> // <xsd:restriction base="xsd:string">
@ -19,10 +19,10 @@ export enum PositionalTabAlignment {
// <xsd:enumeration value="indent" /> // <xsd:enumeration value="indent" />
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PositionalTabRelativeTo { export const PositionalTabRelativeTo = {
MARGIN = "margin", MARGIN: "margin",
INDENT = "indent", INDENT: "indent",
} } as const;
// <xsd:simpleType name="ST_PTabLeader"> // <xsd:simpleType name="ST_PTabLeader">
// <xsd:restriction base="xsd:string"> // <xsd:restriction base="xsd:string">
@ -33,18 +33,19 @@ export enum PositionalTabRelativeTo {
// <xsd:enumeration value="middleDot" /> // <xsd:enumeration value="middleDot" />
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum PositionalTabLeader { export const PositionalTabLeader = {
NONE = "none", NONE: "none",
DOT = "dot", DOT: "dot",
HYPHEN = "hyphen", HYPHEN: "hyphen",
UNDERSCORE = "underscore", UNDERSCORE: "underscore",
MIDDLE_DOT = "middleDot", // eslint-disable-next-line @typescript-eslint/naming-convention
} MIDDLE_DOT: "middleDot",
} as const;
export interface PositionalTabOptions { export interface PositionalTabOptions {
readonly alignment: PositionalTabAlignment; readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment];
readonly relativeTo: PositionalTabRelativeTo; readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo];
readonly leader: PositionalTabLeader; readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader];
} }
// <xsd:complexType name="CT_PTab"> // <xsd:complexType name="CT_PTab">
@ -58,9 +59,9 @@ export class PositionalTab extends XmlComponent {
this.root.push( this.root.push(
new NextAttributeComponent<{ new NextAttributeComponent<{
readonly alignment: PositionalTabAlignment; readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment];
readonly relativeTo: PositionalTabRelativeTo; readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo];
readonly leader: PositionalTabLeader; readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader];
}>({ }>({
alignment: { alignment: {
key: "w:alignment", key: "w:alignment",

View File

@ -1,4 +1,5 @@
// https://www.ecma-international.org/wp-content/uploads/ECMA-376-1_5th_edition_december_2016.zip page 297, section 17.3.2.21 // https://www.ecma-international.org/wp-content/uploads/ECMA-376-1_5th_edition_december_2016.zip page 297, section 17.3.2.21
/* eslint-disable functional/immutable-data */
import { BorderElement, IBorderOptions } from "@file/border"; import { BorderElement, IBorderOptions } from "@file/border";
import { IShadingAttributesProperties, Shading } from "@file/shading"; import { IShadingAttributesProperties, Shading } from "@file/shading";
import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision"; import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision";
@ -24,15 +25,18 @@ interface IFontOptions {
readonly hint?: string; readonly hint?: string;
} }
export enum TextEffect { /* eslint-disable @typescript-eslint/naming-convention */
BLINK_BACKGROUND = "blinkBackground", export const TextEffect = {
LIGHTS = "lights", BLINK_BACKGROUND: "blinkBackground",
ANTS_BLACK = "antsBlack", LIGHTS: "lights",
ANTS_RED = "antsRed", ANTS_BLACK: "antsBlack",
SHIMMER = "shimmer", ANTS_RED: "antsRed",
SPARKLE = "sparkle", SHIMMER: "shimmer",
NONE = "none", SPARKLE: "sparkle",
} NONE: "none",
} as const;
/* eslint-enable */
export interface IRunStylePropertiesOptions { export interface IRunStylePropertiesOptions {
readonly noProof?: boolean; readonly noProof?: boolean;
@ -42,11 +46,11 @@ export interface IRunStylePropertiesOptions {
readonly italicsComplexScript?: boolean; readonly italicsComplexScript?: boolean;
readonly underline?: { readonly underline?: {
readonly color?: string; readonly color?: string;
readonly type?: UnderlineType; readonly type?: (typeof UnderlineType)[keyof typeof UnderlineType];
}; };
readonly effect?: TextEffect; readonly effect?: (typeof TextEffect)[keyof typeof TextEffect];
readonly emphasisMark?: { readonly emphasisMark?: {
readonly type?: EmphasisMarkType; readonly type?: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType];
}; };
readonly color?: string; readonly color?: string;
readonly kern?: number | PositiveUniversalMeasure; readonly kern?: number | PositiveUniversalMeasure;
@ -126,6 +130,8 @@ export interface IRunPropertiesChangeOptions extends IRunPropertiesOptions, ICha
// <xsd:element name="oMath" type="CT_OnOff"/> // <xsd:element name="oMath" type="CT_OnOff"/>
// </xsd:choice> // </xsd:choice>
// </xsd:group> // </xsd:group>
/* eslint-disable functional/immutable-data */
export class RunProperties extends IgnoreIfEmptyXmlComponent { export class RunProperties extends IgnoreIfEmptyXmlComponent {
public constructor(options?: IRunPropertiesOptions) { public constructor(options?: IRunPropertiesOptions) {
super("w:rPr"); super("w:rPr");
@ -260,7 +266,7 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
this.push(new BorderElement("w:bdr", options.border)); this.push(new BorderElement("w:bdr", options.border));
} }
if (options.snapToGrid) { if (options.snapToGrid !== undefined) {
this.push(new OnOffElement("w:snapToGrid", options.snapToGrid)); this.push(new OnOffElement("w:snapToGrid", options.snapToGrid));
} }
@ -293,6 +299,8 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
} }
} }
/* eslint-enable */
export class RunPropertiesChange extends XmlComponent { export class RunPropertiesChange extends XmlComponent {
public constructor(options: IRunPropertiesChangeOptions) { public constructor(options: IRunPropertiesChangeOptions) {
super("w:rPrChange"); super("w:rPrChange");

View File

@ -12,7 +12,7 @@ import { TextAttributes } from "../text-attributes";
// </xsd:complexType> // </xsd:complexType>
interface ITextOptions { interface ITextOptions {
readonly space?: SpaceType; readonly space?: (typeof SpaceType)[keyof typeof SpaceType];
readonly text?: string; readonly text?: string;
} }

View File

@ -71,7 +71,7 @@ export interface IRunOptions extends IRunPropertiesOptions {
| FieldInstruction | FieldInstruction
| Separate | Separate
| End | End
| PageNumber | (typeof PageNumber)[keyof typeof PageNumber]
| FootnoteReferenceRun | FootnoteReferenceRun
| Break | Break
| AnnotationReference | AnnotationReference
@ -98,11 +98,14 @@ export interface IRunOptions extends IRunPropertiesOptions {
readonly text?: string; readonly text?: string;
} }
export enum PageNumber { /* eslint-disable @typescript-eslint/naming-convention */
CURRENT = "CURRENT", export const PageNumber = {
TOTAL_PAGES = "TOTAL_PAGES", CURRENT: "CURRENT",
TOTAL_PAGES_IN_SECTION = "TOTAL_PAGES_IN_SECTION", TOTAL_PAGES: "TOTAL_PAGES",
} TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION",
} as const;
/* eslint-enable */
export class Run extends XmlComponent { export class Run extends XmlComponent {
protected readonly properties: RunProperties; protected readonly properties: RunProperties;

View File

@ -1,6 +1,8 @@
import { SpaceType } from "@file/shared"; import { SpaceType } from "@file/shared";
import { XmlAttributeComponent } from "@file/xml-components"; import { XmlAttributeComponent } from "@file/xml-components";
export class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { export class TextAttributes extends XmlAttributeComponent<{
readonly space: (typeof SpaceType)[keyof typeof SpaceType];
}> {
protected readonly xmlKeys = { space: "xml:space" }; protected readonly xmlKeys = { space: "xml:space" };
} }

View File

@ -1,29 +1,29 @@
import { Attributes, XmlComponent } from "@file/xml-components"; import { Attributes, XmlComponent } from "@file/xml-components";
import { hexColorValue } from "@util/values"; import { hexColorValue } from "@util/values";
export enum UnderlineType { export const UnderlineType = {
SINGLE = "single", SINGLE: "single",
WORDS = "words", WORDS: "words",
DOUBLE = "double", DOUBLE: "double",
THICK = "thick", THICK: "thick",
DOTTED = "dotted", DOTTED: "dotted",
DOTTEDHEAVY = "dottedHeavy", DOTTEDHEAVY: "dottedHeavy",
DASH = "dash", DASH: "dash",
DASHEDHEAVY = "dashedHeavy", DASHEDHEAVY: "dashedHeavy",
DASHLONG = "dashLong", DASHLONG: "dashLong",
DASHLONGHEAVY = "dashLongHeavy", DASHLONGHEAVY: "dashLongHeavy",
DOTDASH = "dotDash", DOTDASH: "dotDash",
DASHDOTHEAVY = "dashDotHeavy", DASHDOTHEAVY: "dashDotHeavy",
DOTDOTDASH = "dotDotDash", DOTDOTDASH: "dotDotDash",
DASHDOTDOTHEAVY = "dashDotDotHeavy", DASHDOTDOTHEAVY: "dashDotDotHeavy",
WAVE = "wave", WAVE: "wave",
WAVYHEAVY = "wavyHeavy", WAVYHEAVY: "wavyHeavy",
WAVYDOUBLE = "wavyDouble", WAVYDOUBLE: "wavyDouble",
NONE = "none", NONE: "none",
} } as const;
export class Underline extends XmlComponent { export class Underline extends XmlComponent {
public constructor(underlineType: UnderlineType = UnderlineType.SINGLE, color?: string) { public constructor(underlineType: (typeof UnderlineType)[keyof typeof UnderlineType] = UnderlineType.SINGLE, color?: string) {
super("w:u"); super("w:u");
this.root.push( this.root.push(
new Attributes({ new Attributes({

View File

@ -19,12 +19,17 @@ export type RelationshipType =
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"; | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
export enum TargetModeType { export const TargetModeType = {
EXTERNAL = "External", EXTERNAL: "External",
} } as const;
export class Relationship extends XmlComponent { export class Relationship extends XmlComponent {
public constructor(id: string, type: RelationshipType, target: string, targetMode?: TargetModeType) { public constructor(
id: string,
type: RelationshipType,
target: string,
targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType],
) {
super("Relationship"); super("Relationship");
this.root.push( this.root.push(

View File

@ -12,7 +12,12 @@ export class Relationships extends XmlComponent {
); );
} }
public createRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: TargetModeType): Relationship { public createRelationship(
id: number | string,
type: RelationshipType,
target: string,
targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType],
): Relationship {
const relationship = new Relationship(`rId${id}`, type, target, targetMode); const relationship = new Relationship(`rId${id}`, type, target, targetMode);
this.root.push(relationship); this.root.push(relationship);

View File

@ -112,6 +112,23 @@ describe("Settings", () => {
}); });
}); });
it("should add defaultTabStop setting with version", () => {
const settings = new Settings({
defaultTabStop: 100,
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:defaultTabStop": {
_attr: {
"w:val": 100,
},
},
});
});
// TODO: Remove when deprecating compatibilityModeVersion // TODO: Remove when deprecating compatibilityModeVersion
it("should add compatibility setting with legacy version", () => { it("should add compatibility setting with legacy version", () => {
const settings = new Settings({ const settings = new Settings({

View File

@ -1,4 +1,4 @@
import { OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { NumberValueElement, OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { Compatibility, ICompatibilityOptions } from "./compatibility"; import { Compatibility, ICompatibilityOptions } from "./compatibility";
@ -152,6 +152,7 @@ export interface ISettingsOptions {
readonly trackRevisions?: boolean; readonly trackRevisions?: boolean;
readonly updateFields?: boolean; readonly updateFields?: boolean;
readonly compatibility?: ICompatibilityOptions; readonly compatibility?: ICompatibilityOptions;
readonly defaultTabStop?: number;
} }
export class Settings extends XmlComponent { export class Settings extends XmlComponent {
@ -198,6 +199,11 @@ export class Settings extends XmlComponent {
this.root.push(new OnOffElement("w:updateFields", options.updateFields)); this.root.push(new OnOffElement("w:updateFields", options.updateFields));
} }
// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_defaultTabStop_topic_ID0EIXSX.html
if (options.defaultTabStop !== undefined) {
this.root.push(new NumberValueElement("w:defaultTabStop", options.defaultTabStop));
}
this.root.push( this.root.push(
new Compatibility({ new Compatibility({
...(options.compatibility ?? {}), ...(options.compatibility ?? {}),

View File

@ -23,7 +23,7 @@ import { hexColorValue } from "@util/values";
export interface IShadingAttributesProperties { export interface IShadingAttributesProperties {
readonly fill?: string; readonly fill?: string;
readonly color?: string; readonly color?: string;
readonly type?: ShadingType; readonly type?: (typeof ShadingType)[keyof typeof ShadingType];
} }
class ShadingAttributes extends XmlAttributeComponent<IShadingAttributesProperties> { class ShadingAttributes extends XmlAttributeComponent<IShadingAttributesProperties> {
@ -47,42 +47,44 @@ export class Shading extends XmlComponent {
} }
} }
export enum ShadingType { /* eslint-disable @typescript-eslint/naming-convention */
CLEAR = "clear", export const ShadingType = {
DIAGONAL_CROSS = "diagCross", CLEAR: "clear",
DIAGONAL_STRIPE = "diagStripe", DIAGONAL_CROSS: "diagCross",
HORIZONTAL_CROSS = "horzCross", DIAGONAL_STRIPE: "diagStripe",
HORIZONTAL_STRIPE = "horzStripe", HORIZONTAL_CROSS: "horzCross",
NIL = "nil", HORIZONTAL_STRIPE: "horzStripe",
PERCENT_5 = "pct5", NIL: "nil",
PERCENT_10 = "pct10", PERCENT_5: "pct5",
PERCENT_12 = "pct12", PERCENT_10: "pct10",
PERCENT_15 = "pct15", PERCENT_12: "pct12",
PERCENT_20 = "pct20", PERCENT_15: "pct15",
PERCENT_25 = "pct25", PERCENT_20: "pct20",
PERCENT_30 = "pct30", PERCENT_25: "pct25",
PERCENT_35 = "pct35", PERCENT_30: "pct30",
PERCENT_37 = "pct37", PERCENT_35: "pct35",
PERCENT_40 = "pct40", PERCENT_37: "pct37",
PERCENT_45 = "pct45", PERCENT_40: "pct40",
PERCENT_50 = "pct50", PERCENT_45: "pct45",
PERCENT_55 = "pct55", PERCENT_50: "pct50",
PERCENT_60 = "pct60", PERCENT_55: "pct55",
PERCENT_62 = "pct62", PERCENT_60: "pct60",
PERCENT_65 = "pct65", PERCENT_62: "pct62",
PERCENT_70 = "pct70", PERCENT_65: "pct65",
PERCENT_75 = "pct75", PERCENT_70: "pct70",
PERCENT_80 = "pct80", PERCENT_75: "pct75",
PERCENT_85 = "pct85", PERCENT_80: "pct80",
PERCENT_87 = "pct87", PERCENT_85: "pct85",
PERCENT_90 = "pct90", PERCENT_87: "pct87",
PERCENT_95 = "pct95", PERCENT_90: "pct90",
REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe", PERCENT_95: "pct95",
SOLID = "solid", REVERSE_DIAGONAL_STRIPE: "reverseDiagStripe",
THIN_DIAGONAL_CROSS = "thinDiagCross", SOLID: "solid",
THIN_DIAGONAL_STRIPE = "thinDiagStripe", THIN_DIAGONAL_CROSS: "thinDiagCross",
THIN_HORIZONTAL_CROSS = "thinHorzCross", THIN_DIAGONAL_STRIPE: "thinDiagStripe",
THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe", THIN_HORIZONTAL_CROSS: "thinHorzCross",
THIN_VERTICAL_STRIPE = "thinVertStripe", THIN_REVERSE_DIAGONAL_STRIPE: "thinReverseDiagStripe",
VERTICAL_STRIPE = "vertStripe", THIN_VERTICAL_STRIPE: "thinVertStripe",
} VERTICAL_STRIPE: "vertStripe",
} as const;
/* eslint-enable */

View File

@ -1,15 +1,15 @@
export enum HorizontalPositionAlign { export const HorizontalPositionAlign = {
CENTER = "center", CENTER: "center",
INSIDE = "inside", INSIDE: "inside",
LEFT = "left", LEFT: "left",
OUTSIDE = "outside", OUTSIDE: "outside",
RIGHT = "right", RIGHT: "right",
} } as const;
export enum VerticalPositionAlign { export const VerticalPositionAlign = {
BOTTOM = "bottom", BOTTOM: "bottom",
CENTER = "center", CENTER: "center",
INSIDE = "inside", INSIDE: "inside",
OUTSIDE = "outside", OUTSIDE: "outside",
TOP = "top", TOP: "top",
} } as const;

View File

@ -66,68 +66,70 @@
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum NumberFormat { /* eslint-disable @typescript-eslint/naming-convention*/
DECIMAL = "decimal", export const NumberFormat = {
UPPER_ROMAN = "upperRoman", DECIMAL: "decimal",
LOWER_ROMAN = "lowerRoman", UPPER_ROMAN: "upperRoman",
UPPER_LETTER = "upperLetter", LOWER_ROMAN: "lowerRoman",
LOWER_LETTER = "lowerLetter", UPPER_LETTER: "upperLetter",
ORDINAL = "ordinal", LOWER_LETTER: "lowerLetter",
CARDINAL_TEXT = "cardinalText", ORDINAL: "ordinal",
ORDINAL_TEXT = "ordinalText", CARDINAL_TEXT: "cardinalText",
HEX = "hex", ORDINAL_TEXT: "ordinalText",
CHICAGO = "chicago", HEX: "hex",
IDEOGRAPH_DIGITAL = "ideographDigital", CHICAGO: "chicago",
JAPANESE_COUNTING = "japaneseCounting", IDEOGRAPH_DIGITAL: "ideographDigital",
AIUEO = "aiueo", JAPANESE_COUNTING: "japaneseCounting",
IROHA = "iroha", AIUEO: "aiueo",
DECIMAL_FULL_WIDTH = "decimalFullWidth", IROHA: "iroha",
DECIMAL_HALF_WIDTH = "decimalHalfWidth", DECIMAL_FULL_WIDTH: "decimalFullWidth",
JAPANESE_LEGAL = "japaneseLegal", DECIMAL_HALF_WIDTH: "decimalHalfWidth",
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand", JAPANESE_LEGAL: "japaneseLegal",
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle", JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand",
DECIMAL_FULL_WIDTH_2 = "decimalFullWidth2", DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle",
AIUEO_FULL_WIDTH = "aiueoFullWidth", DECIMAL_FULL_WIDTH_2: "decimalFullWidth2",
IROHA_FULL_WIDTH = "irohaFullWidth", AIUEO_FULL_WIDTH: "aiueoFullWidth",
DECIMAL_ZERO = "decimalZero", IROHA_FULL_WIDTH: "irohaFullWidth",
BULLET = "bullet", DECIMAL_ZERO: "decimalZero",
GANADA = "ganada", BULLET: "bullet",
CHOSUNG = "chosung", GANADA: "ganada",
DECIMAL_ENCLOSED_FULL_STOP = "decimalEnclosedFullstop", CHOSUNG: "chosung",
DECIMAL_ENCLOSED_PAREN = "decimalEnclosedParen", DECIMAL_ENCLOSED_FULL_STOP: "decimalEnclosedFullstop",
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese", DECIMAL_ENCLOSED_PAREN: "decimalEnclosedParen",
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle", DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese",
IDEOGRAPH_TRADITIONAL = "ideographTraditional", IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle",
IDEOGRAPH_ZODIAC = "ideographZodiac", IDEOGRAPH_TRADITIONAL: "ideographTraditional",
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional", IDEOGRAPH_ZODIAC: "ideographZodiac",
TAIWANESE_COUNTING = "taiwaneseCounting", IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional",
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional", TAIWANESE_COUNTING: "taiwaneseCounting",
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand", IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional",
TAIWANESE_DIGITAL = "taiwaneseDigital", TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand",
CHINESE_COUNTING = "chineseCounting", TAIWANESE_DIGITAL: "taiwaneseDigital",
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified", CHINESE_COUNTING: "chineseCounting",
CHINESE_COUNTING_TEN_THOUSAND = "chineseCountingThousand", CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified",
KOREAN_DIGITAL = "koreanDigital", CHINESE_COUNTING_TEN_THOUSAND: "chineseCountingThousand",
KOREAN_COUNTING = "koreanCounting", KOREAN_DIGITAL: "koreanDigital",
KOREAN_LEGAL = "koreanLegal", KOREAN_COUNTING: "koreanCounting",
KOREAN_DIGITAL_2 = "koreanDigital2", KOREAN_LEGAL: "koreanLegal",
VIETNAMESE_COUNTING = "vietnameseCounting", KOREAN_DIGITAL_2: "koreanDigital2",
RUSSIAN_LOWER = "russianLower", VIETNAMESE_COUNTING: "vietnameseCounting",
RUSSIAN_UPPER = "russianUpper", RUSSIAN_LOWER: "russianLower",
NONE = "none", RUSSIAN_UPPER: "russianUpper",
NUMBER_IN_DASH = "numberInDash", NONE: "none",
HEBREW_1 = "hebrew1", NUMBER_IN_DASH: "numberInDash",
HEBREW_2 = "hebrew2", HEBREW_1: "hebrew1",
ARABIC_ALPHA = "arabicAlpha", HEBREW_2: "hebrew2",
ARABIC_ABJAD = "arabicAbjad", ARABIC_ALPHA: "arabicAlpha",
HINDI_VOWELS = "hindiVowels", ARABIC_ABJAD: "arabicAbjad",
HINDI_CONSONANTS = "hindiConsonants", HINDI_VOWELS: "hindiVowels",
HINDI_NUMBERS = "hindiNumbers", HINDI_CONSONANTS: "hindiConsonants",
HINDI_COUNTING = "hindiCounting", HINDI_NUMBERS: "hindiNumbers",
THAI_LETTERS = "thaiLetters", HINDI_COUNTING: "hindiCounting",
THAI_NUMBERS = "thaiNumbers", THAI_LETTERS: "thaiLetters",
THAI_COUNTING = "thaiCounting", THAI_NUMBERS: "thaiNumbers",
BAHT_TEXT = "bahtText", THAI_COUNTING: "thaiCounting",
DOLLAR_TEXT = "dollarText", BAHT_TEXT: "bahtText",
DOLLAR_TEXT: "dollarText",
// <xsd:enumeration value="custom"/> // <xsd:enumeration value="custom"/>
} } as const;
/* eslint-enable */

View File

@ -1,4 +1,4 @@
export enum SpaceType { export const SpaceType = {
DEFAULT = "default", DEFAULT: "default",
PRESERVE = "preserve", PRESERVE: "preserve",
} } as const;

View File

@ -80,18 +80,20 @@ export class GridSpan extends XmlComponent {
/** /**
* Vertical merge types. * Vertical merge types.
*/ */
export enum VerticalMergeType { export const VerticalMergeType = {
/** /**
* Cell that is merged with upper one. * Cell that is merged with upper one.
*/ */
CONTINUE = "continue", CONTINUE: "continue",
/** /**
* Cell that is starting the vertical merge. * Cell that is starting the vertical merge.
*/ */
RESTART = "restart", RESTART: "restart",
} } as const;
class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: VerticalMergeType }> { class VerticalMergeAttributes extends XmlAttributeComponent<{
readonly val: (typeof VerticalMergeType)[keyof typeof VerticalMergeType];
}> {
protected readonly xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
@ -99,7 +101,7 @@ class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: Vert
* Vertical merge element. Should be used in a table cell. * Vertical merge element. Should be used in a table cell.
*/ */
export class VerticalMerge extends XmlComponent { export class VerticalMerge extends XmlComponent {
public constructor(value: VerticalMergeType) { public constructor(value: (typeof VerticalMergeType)[keyof typeof VerticalMergeType]) {
super("w:vMerge"); super("w:vMerge");
this.root.push( this.root.push(
@ -110,13 +112,18 @@ export class VerticalMerge extends XmlComponent {
} }
} }
export enum TextDirection { export const TextDirection = {
BOTTOM_TO_TOP_LEFT_TO_RIGHT = "btLr", // eslint-disable-next-line @typescript-eslint/naming-convention
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb", BOTTOM_TO_TOP_LEFT_TO_RIGHT: "btLr",
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl", // eslint-disable-next-line @typescript-eslint/naming-convention
} LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
// eslint-disable-next-line @typescript-eslint/naming-convention
TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl",
} as const;
class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDirection }> { class TDirectionAttributes extends XmlAttributeComponent<{
readonly val: (typeof TextDirection)[keyof typeof TextDirection];
}> {
protected readonly xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
@ -124,7 +131,7 @@ class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDir
* Text Direction within a table cell * Text Direction within a table cell
*/ */
export class TDirection extends XmlComponent { export class TDirection extends XmlComponent {
public constructor(value: TextDirection) { public constructor(value: (typeof TextDirection)[keyof typeof TextDirection]) {
super("w:textDirection"); super("w:textDirection");
this.root.push( this.root.push(

View File

@ -17,9 +17,9 @@ import {
export interface ITableCellPropertiesOptions { export interface ITableCellPropertiesOptions {
readonly shading?: IShadingAttributesProperties; readonly shading?: IShadingAttributesProperties;
readonly margins?: ITableCellMarginOptions; readonly margins?: ITableCellMarginOptions;
readonly verticalAlign?: VerticalAlign; readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
readonly textDirection?: TextDirection; readonly textDirection?: (typeof TextDirection)[keyof typeof TextDirection];
readonly verticalMerge?: VerticalMergeType; readonly verticalMerge?: (typeof VerticalMergeType)[keyof typeof VerticalMergeType];
readonly width?: ITableWidthProperties; readonly width?: ITableWidthProperties;
readonly columnSpan?: number; readonly columnSpan?: number;
readonly rowSpan?: number; readonly rowSpan?: number;

View File

@ -1,8 +1,8 @@
import { IgnoreIfEmptyXmlComponent } from "@file/xml-components"; import { IgnoreIfEmptyXmlComponent } from "@file/xml-components";
import { TableWidthElement, WidthType } from "../table-width"; import { TableWidthElement, WidthType } from "@file/table";
export interface ITableCellMarginOptions { export interface ITableCellMarginOptions {
readonly marginUnitType?: WidthType; readonly marginUnitType?: (typeof WidthType)[keyof typeof WidthType];
readonly top?: number; readonly top?: number;
readonly bottom?: number; readonly bottom?: number;
readonly left?: number; readonly left?: number;
@ -33,14 +33,15 @@ export interface ITableCellMarginOptions {
// </xsd:sequence> // </xsd:sequence>
// </xsd:complexType> // </xsd:complexType>
export enum TableCellMarginElementType { export const TableCellMarginElementType = {
TABLE = "w:tblCellMar", TABLE: "w:tblCellMar",
TABLE_CELL = "w:tcMar", // eslint-disable-next-line @typescript-eslint/naming-convention
} TABLE_CELL: "w:tcMar",
} as const;
export class TableCellMargin extends IgnoreIfEmptyXmlComponent { export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
public constructor( public constructor(
type: TableCellMarginElementType, type: (typeof TableCellMarginElementType)[keyof typeof TableCellMarginElementType],
{ marginUnitType = WidthType.DXA, top, left, bottom, right }: ITableCellMarginOptions, { marginUnitType = WidthType.DXA, top, left, bottom, right }: ITableCellMarginOptions,
) { ) {
super(type); super(type);

View File

@ -1,28 +1,28 @@
import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components"; import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values"; import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
export enum TableAnchorType { export const TableAnchorType = {
MARGIN = "margin", MARGIN: "margin",
PAGE = "page", PAGE: "page",
TEXT = "text", TEXT: "text",
} } as const;
export enum RelativeHorizontalPosition { export const RelativeHorizontalPosition = {
CENTER = "center", CENTER: "center",
INSIDE = "inside", INSIDE: "inside",
LEFT = "left", LEFT: "left",
OUTSIDE = "outside", OUTSIDE: "outside",
RIGHT = "right", RIGHT: "right",
} } as const;
export enum RelativeVerticalPosition { export const RelativeVerticalPosition = {
CENTER = "center", CENTER: "center",
INSIDE = "inside", INSIDE: "inside",
BOTTOM = "bottom", BOTTOM: "bottom",
OUTSIDE = "outside", OUTSIDE: "outside",
INLINE = "inline", INLINE: "inline",
TOP = "top", TOP: "top",
} } as const;
// <xsd:simpleType name="ST_TblOverlap"> // <xsd:simpleType name="ST_TblOverlap">
// <xsd:restriction base="xsd:string"> // <xsd:restriction base="xsd:string">
@ -30,10 +30,10 @@ export enum RelativeVerticalPosition {
// <xsd:enumeration value="overlap"/> // <xsd:enumeration value="overlap"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum OverlapType { export const OverlapType = {
NEVER = "never", NEVER: "never",
OVERLAP = "overlap", OVERLAP: "overlap",
} } as const;
export type ITableFloatOptions = { export type ITableFloatOptions = {
/* cSpell:disable */ /* cSpell:disable */
@ -46,7 +46,7 @@ export type ITableFloatOptions = {
* If omitted, the value is assumed to be page. * If omitted, the value is assumed to be page.
*/ */
/* cSpell:enable */ /* cSpell:enable */
readonly horizontalAnchor?: TableAnchorType; readonly horizontalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
/** /**
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor. * Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
@ -67,7 +67,7 @@ export type ITableFloatOptions = {
* outside - the table should be outside of the anchor * outside - the table should be outside of the anchor
* right - the table should be right aligned with respect to the anchor * right - the table should be right aligned with respect to the anchor
*/ */
readonly relativeHorizontalPosition?: RelativeHorizontalPosition; readonly relativeHorizontalPosition?: (typeof RelativeHorizontalPosition)[keyof typeof RelativeHorizontalPosition];
/** /**
* Specifies the vertical anchor or the base object from which the vertical positioning * Specifies the vertical anchor or the base object from which the vertical positioning
@ -77,7 +77,7 @@ export type ITableFloatOptions = {
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located * text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page. * If omitted, the value is assumed to be page.
*/ */
readonly verticalAnchor?: TableAnchorType; readonly verticalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
/** /**
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor. * Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
@ -98,7 +98,7 @@ export type ITableFloatOptions = {
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it) * inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
* top - the table should be vertically aligned to the top edge of the anchor * top - the table should be vertically aligned to the top edge of the anchor
*/ */
readonly relativeVerticalPosition?: RelativeVerticalPosition; readonly relativeVerticalPosition?: (typeof RelativeVerticalPosition)[keyof typeof RelativeVerticalPosition];
/** /**
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph * Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
@ -123,7 +123,7 @@ export type ITableFloatOptions = {
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. * to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/ */
readonly rightFromText?: number | PositiveUniversalMeasure; readonly rightFromText?: number | PositiveUniversalMeasure;
readonly overlap?: OverlapType; readonly overlap?: (typeof OverlapType)[keyof typeof OverlapType];
}; };
// <xsd:complexType name="CT_TblPPr"> // <xsd:complexType name="CT_TblPPr">
@ -156,12 +156,18 @@ export class TableFloatProperties extends XmlComponent {
super("w:tblpPr"); super("w:tblpPr");
this.root.push( this.root.push(
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({ new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
leftFromText: { key: "w:leftFromText", value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText) }, leftFromText: {
key: "w:leftFromText",
value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText),
},
rightFromText: { rightFromText: {
key: "w:rightFromText", key: "w:rightFromText",
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText), value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
}, },
topFromText: { key: "w:topFromText", value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText) }, topFromText: {
key: "w:topFromText",
value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText),
},
bottomFromText: { bottomFromText: {
key: "w:bottomFromText", key: "w:bottomFromText",
value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText), value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText),
@ -197,7 +203,7 @@ export class TableFloatProperties extends XmlComponent {
// <xsd:complexType name="CT_TblOverlap"> // <xsd:complexType name="CT_TblOverlap">
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/> // <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
// </xsd:complexType> // </xsd:complexType>
this.root.push(new StringEnumValueElement<OverlapType>("w:tblOverlap", overlap)); this.root.push(new StringEnumValueElement<(typeof OverlapType)[keyof typeof OverlapType]>("w:tblOverlap", overlap));
} }
} }
} }

View File

@ -6,12 +6,14 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="autofit"/> // <xsd:enumeration value="autofit"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum TableLayoutType { export const TableLayoutType = {
AUTOFIT = "autofit", AUTOFIT: "autofit",
FIXED = "fixed", FIXED: "fixed",
} } as const;
class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> { class TableLayoutAttributes extends XmlAttributeComponent<{
readonly type: (typeof TableLayoutType)[keyof typeof TableLayoutType];
}> {
protected readonly xmlKeys = { type: "w:type" }; protected readonly xmlKeys = { type: "w:type" };
} }
@ -19,7 +21,7 @@ class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: Table
// <xsd:attribute name="type" type="ST_TblLayoutType"/> // <xsd:attribute name="type" type="ST_TblLayoutType"/>
// </xsd:complexType> // </xsd:complexType>
export class TableLayout extends XmlComponent { export class TableLayout extends XmlComponent {
public constructor(type: TableLayoutType) { public constructor(type: (typeof TableLayoutType)[keyof typeof TableLayoutType]) {
super("w:tblLayout"); super("w:tblLayout");
this.root.push(new TableLayoutAttributes({ type })); this.root.push(new TableLayoutAttributes({ type }));
} }

View File

@ -34,12 +34,12 @@ import { TableLayout, TableLayoutType } from "./table-layout";
export interface ITablePropertiesOptions { export interface ITablePropertiesOptions {
readonly width?: ITableWidthProperties; readonly width?: ITableWidthProperties;
readonly indent?: ITableWidthProperties; readonly indent?: ITableWidthProperties;
readonly layout?: TableLayoutType; readonly layout?: (typeof TableLayoutType)[keyof typeof TableLayoutType];
readonly borders?: ITableBordersOptions; readonly borders?: ITableBordersOptions;
readonly float?: ITableFloatOptions; readonly float?: ITableFloatOptions;
readonly shading?: IShadingAttributesProperties; readonly shading?: IShadingAttributesProperties;
readonly style?: string; readonly style?: string;
readonly alignment?: AlignmentType; readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
readonly cellMargin?: ITableCellMarginOptions; readonly cellMargin?: ITableCellMarginOptions;
readonly visuallyRightToLeft?: boolean; readonly visuallyRightToLeft?: boolean;
} }

View File

@ -13,24 +13,24 @@ import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
// <xsd:enumeration value="atLeast"/> // <xsd:enumeration value="atLeast"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum HeightRule { export const HeightRule = {
/** Height is determined based on the content, so value is ignored. */ /** Height is determined based on the content, so value is ignored. */
AUTO = "auto", AUTO: "auto",
/** At least the value specified */ /** At least the value specified */
ATLEAST = "atLeast", ATLEAST: "atLeast",
/** Exactly the value specified */ /** Exactly the value specified */
EXACT = "exact", EXACT: "exact",
} } as const;
export class TableRowHeightAttributes extends XmlAttributeComponent<{ export class TableRowHeightAttributes extends XmlAttributeComponent<{
readonly value: number | string; readonly value: number | string;
readonly rule: HeightRule; readonly rule: (typeof HeightRule)[keyof typeof HeightRule];
}> { }> {
protected readonly xmlKeys = { value: "w:val", rule: "w:hRule" }; protected readonly xmlKeys = { value: "w:val", rule: "w:hRule" };
} }
export class TableRowHeight extends XmlComponent { export class TableRowHeight extends XmlComponent {
public constructor(value: number | PositiveUniversalMeasure, rule: HeightRule) { public constructor(value: number | PositiveUniversalMeasure, rule: (typeof HeightRule)[keyof typeof HeightRule]) {
super("w:trHeight"); super("w:trHeight");
this.root.push( this.root.push(

View File

@ -37,7 +37,7 @@ export interface ITableRowPropertiesOptions {
readonly tableHeader?: boolean; readonly tableHeader?: boolean;
readonly height?: { readonly height?: {
readonly value: number | PositiveUniversalMeasure; readonly value: number | PositiveUniversalMeasure;
readonly rule: HeightRule; readonly rule: (typeof HeightRule)[keyof typeof HeightRule];
}; };
} }

View File

@ -10,16 +10,17 @@ import { measurementOrPercentValue, Percentage, UniversalMeasure } from "@util/v
// <xsd:enumeration value="auto"/> // <xsd:enumeration value="auto"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum WidthType {
export const WidthType = {
/** Auto. */ /** Auto. */
AUTO = "auto", AUTO: "auto",
/** Value is in twentieths of a point */ /** Value is in twentieths of a point */
DXA = "dxa", DXA: "dxa",
/** No (empty) value. */ /** No (empty) value. */
NIL = "nil", NIL: "nil",
/** Value is in percentage. */ /** Value is in percentage. */
PERCENTAGE = "pct", PERCENTAGE: "pct",
} } as const;
// <xsd:complexType name="CT_TblWidth"> // <xsd:complexType name="CT_TblWidth">
// <xsd:attribute name="w" type="ST_MeasurementOrPercent"/> // <xsd:attribute name="w" type="ST_MeasurementOrPercent"/>
@ -27,7 +28,7 @@ export enum WidthType {
// </xsd:complexType> // </xsd:complexType>
export type ITableWidthProperties = { export type ITableWidthProperties = {
readonly size: number | Percentage | UniversalMeasure; readonly size: number | Percentage | UniversalMeasure;
readonly type?: WidthType; readonly type?: (typeof WidthType)[keyof typeof WidthType];
}; };
export class TableWidthElement extends XmlComponent { export class TableWidthElement extends XmlComponent {

View File

@ -27,10 +27,10 @@ export interface ITableOptions {
readonly margins?: ITableCellMarginOptions; readonly margins?: ITableCellMarginOptions;
readonly indent?: ITableWidthProperties; readonly indent?: ITableWidthProperties;
readonly float?: ITableFloatOptions; readonly float?: ITableFloatOptions;
readonly layout?: TableLayoutType; readonly layout?: (typeof TableLayoutType)[keyof typeof TableLayoutType];
readonly style?: string; readonly style?: string;
readonly borders?: ITableBordersOptions; readonly borders?: ITableBordersOptions;
readonly alignment?: AlignmentType; readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
readonly visuallyRightToLeft?: boolean; readonly visuallyRightToLeft?: boolean;
} }

View File

@ -11,13 +11,14 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="bottom"/> // <xsd:enumeration value="bottom"/>
// </xsd:restriction> // </xsd:restriction>
// </xsd:simpleType> // </xsd:simpleType>
export enum VerticalAlign { export const VerticalAlign = {
BOTTOM = "bottom", BOTTOM: "bottom",
CENTER = "center", CENTER: "center",
TOP = "top", TOP: "top",
} } as const;
export class VerticalAlignAttributes extends XmlAttributeComponent<{ export class VerticalAlignAttributes extends XmlAttributeComponent<{
readonly verticalAlign?: VerticalAlign; readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
}> { }> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
verticalAlign: "w:val", verticalAlign: "w:val",
@ -25,7 +26,7 @@ export class VerticalAlignAttributes extends XmlAttributeComponent<{
} }
export class VerticalAlignElement extends XmlComponent { export class VerticalAlignElement extends XmlComponent {
public constructor(value: VerticalAlign) { public constructor(value: (typeof VerticalAlign)[keyof typeof VerticalAlign]) {
super("w:vAlign"); super("w:vAlign");
this.root.push(new VerticalAlignAttributes({ verticalAlign: value })); this.root.push(new VerticalAlignAttributes({ verticalAlign: value }));
} }

View File

@ -55,6 +55,7 @@ describe("ImportedXmlComponent", () => {
otherAttr: "2", otherAttr: "2",
}; };
importedXmlComponent = new ImportedXmlComponent("w:test", attributes); importedXmlComponent = new ImportedXmlComponent("w:test", attributes);
// eslint-disable-next-line functional/immutable-data
importedXmlComponent.push(new ImportedXmlComponent("w:child")); importedXmlComponent.push(new ImportedXmlComponent("w:child"));
}); });

View File

@ -21,6 +21,7 @@ export const convertToXmlComponent = (element: XmlElement): ImportedXmlComponent
for (const childElm of childElements) { for (const childElm of childElements) {
const child = convertToXmlComponent(childElm); const child = convertToXmlComponent(childElm);
if (child !== undefined) { if (child !== undefined) {
// eslint-disable-next-line functional/immutable-data
xmlComponent.push(child); xmlComponent.push(child);
} }
} }
@ -60,6 +61,7 @@ export class ImportedXmlComponent extends XmlComponent {
public constructor(rootKey: string, _attr?: any) { public constructor(rootKey: string, _attr?: any) {
super(rootKey); super(rootKey);
if (_attr) { if (_attr) {
// eslint-disable-next-line functional/immutable-data
this.root.push(new ImportedXmlComponentAttributes(_attr)); this.root.push(new ImportedXmlComponentAttributes(_attr));
} }
} }

View File

@ -20,11 +20,13 @@ describe("XmlComponent", () => {
}); });
it("should handle children elements", () => { it("should handle children elements", () => {
const xmlComponent = new TestComponent("w:test"); const xmlComponent = new TestComponent("w:test");
// eslint-disable-next-line functional/immutable-data
xmlComponent.push( xmlComponent.push(
new Attributes({ new Attributes({
val: "test", val: "test",
}), }),
); );
// eslint-disable-next-line functional/immutable-data
xmlComponent.push(new TestComponent("innerTest")); xmlComponent.push(new TestComponent("innerTest"));
const tree = new Formatter().format(xmlComponent); const tree = new Formatter().format(xmlComponent);
@ -43,6 +45,7 @@ describe("XmlComponent", () => {
}); });
it("should hoist attrs if only attrs are present", () => { it("should hoist attrs if only attrs are present", () => {
const xmlComponent = new TestComponent("w:test"); const xmlComponent = new TestComponent("w:test");
// eslint-disable-next-line functional/immutable-data
xmlComponent.push( xmlComponent.push(
new Attributes({ new Attributes({
val: "test", val: "test",

View File

@ -1,7 +1,7 @@
export interface IXmlAttribute { export interface IXmlAttribute {
readonly [key: string]: string | number | boolean; readonly [key: string]: string | number | boolean;
} }
export interface IXmlableObject extends Object { export interface IXmlableObject extends Record<string, unknown> {
// readonly _attr?: IXmlAttribute; // readonly _attr?: IXmlAttribute;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly [key: string]: any; readonly [key: string]: any;

View File

@ -20,18 +20,18 @@ import { appendContentType } from "./content-types-manager";
// eslint-disable-next-line functional/prefer-readonly-type // eslint-disable-next-line functional/prefer-readonly-type
type InputDataType = Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream; type InputDataType = Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream;
export enum PatchType { export const PatchType = {
DOCUMENT = "file", DOCUMENT: "file",
PARAGRAPH = "paragraph", PARAGRAPH: "paragraph",
} } as const;
type ParagraphPatch = { type ParagraphPatch = {
readonly type: PatchType.PARAGRAPH; readonly type: typeof PatchType.PARAGRAPH;
readonly children: readonly ParagraphChild[]; readonly children: readonly ParagraphChild[];
}; };
type FilePatch = { type FilePatch = {
readonly type: PatchType.DOCUMENT; readonly type: typeof PatchType.DOCUMENT;
readonly children: readonly FileChild[]; readonly children: readonly FileChild[];
}; };
@ -49,6 +49,7 @@ export type IPatch = ParagraphPatch | FilePatch;
export interface PatchDocumentOptions { export interface PatchDocumentOptions {
readonly patches: { readonly [key: string]: IPatch }; readonly patches: { readonly [key: string]: IPatch };
readonly keepOriginalStyles?: boolean;
} }
const imageReplacer = new ImageReplacer(); const imageReplacer = new ImageReplacer();
@ -82,7 +83,12 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
file, file,
viewWrapper: { viewWrapper: {
Relationships: { Relationships: {
createRelationship: (linkId: string, _: string, target: string, __: TargetModeType) => { createRelationship: (
linkId: string,
_: string,
target: string,
__: (typeof TargetModeType)[keyof typeof TargetModeType],
) => {
// eslint-disable-next-line functional/immutable-data // eslint-disable-next-line functional/immutable-data
hyperlinkRelationshipAdditions.push({ hyperlinkRelationshipAdditions.push({
key, key,
@ -128,6 +134,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
patchText, patchText,
renderedParagraphs, renderedParagraphs,
context, context,
options.keepOriginalStyles,
); );
} }

View File

@ -3,11 +3,11 @@ import { Element } from "xml-js";
import { createTextElementContents, patchSpaceAttribute } from "./util"; import { createTextElementContents, patchSpaceAttribute } from "./util";
import { IRenderedParagraphNode } from "./run-renderer"; import { IRenderedParagraphNode } from "./run-renderer";
enum ReplaceMode { const ReplaceMode = {
START, START: 0,
MIDDLE, MIDDLE: 1,
END, END: 2,
} } as const;
export const replaceTokenInParagraphElement = ({ export const replaceTokenInParagraphElement = ({
paragraphElement, paragraphElement,
@ -23,7 +23,7 @@ export const replaceTokenInParagraphElement = ({
const startIndex = renderedParagraph.text.indexOf(originalText); const startIndex = renderedParagraph.text.indexOf(originalText);
const endIndex = startIndex + originalText.length - 1; const endIndex = startIndex + originalText.length - 1;
let replaceMode = ReplaceMode.START; let replaceMode: (typeof ReplaceMode)[keyof typeof ReplaceMode] = ReplaceMode.START;
for (const run of renderedParagraph.runs) { for (const run of renderedParagraph.runs) {
for (const { text, index, start, end } of run.parts) { for (const { text, index, start, end } of run.parts) {
@ -43,6 +43,7 @@ export const replaceTokenInParagraphElement = ({
patchTextElement(paragraphElement.elements![run.index].elements![index], firstPart); patchTextElement(paragraphElement.elements![run.index].elements![index], firstPart);
replaceMode = ReplaceMode.MIDDLE; replaceMode = ReplaceMode.MIDDLE;
continue; continue;
/* c8 ignore next 2 */
} }
break; break;
case ReplaceMode.MIDDLE: case ReplaceMode.MIDDLE:
@ -59,6 +60,7 @@ export const replaceTokenInParagraphElement = ({
patchTextElement(paragraphElement.elements![run.index].elements![index], ""); patchTextElement(paragraphElement.elements![run.index].elements![index], "");
} }
break; break;
/* c8 ignore next */
default: default:
} }
} }

View File

@ -23,7 +23,7 @@ export const appendRelationship = (
id: number | string, id: number | string,
type: RelationshipType, type: RelationshipType,
target: string, target: string,
targetMode?: TargetModeType, targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType],
): readonly Element[] => { ): readonly Element[] => {
const relationshipElements = getFirstLevelElements(relationships, "Relationships"); const relationshipElements = getFirstLevelElements(relationships, "Relationships");
// eslint-disable-next-line functional/immutable-data // eslint-disable-next-line functional/immutable-data

View File

@ -44,6 +44,28 @@ const MOCK_JSON = {
}, },
], ],
}, },
{
type: "element",
name: "w:p",
elements: [
{
type: "element",
name: "w:r",
elements: [
{
type: "element",
name: "w:rPr",
elements: [{ type: "element", name: "w:b", attributes: { "w:val": "1" } }],
},
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "What a {{bold}} text!" }],
},
],
},
],
},
], ],
}, },
], ],
@ -115,6 +137,93 @@ describe("replacer", () => {
expect(JSON.stringify(output)).to.contain("Delightful Header"); expect(JSON.stringify(output)).to.contain("Delightful Header");
}); });
it("should replace paragraph type keeping original styling if keepOriginalStyles is true", () => {
const output = replacer(
MOCK_JSON,
{
type: PatchType.PARAGRAPH,
children: [new TextRun("sweet")],
},
"{{bold}}",
[
{
text: "What a {{bold}} text!",
runs: [
{
text: "What a {{bold}} text!",
parts: [{ text: "What a {{bold}} text!", index: 1, start: 0, end: 21 }],
index: 0,
start: 0,
end: 21,
},
],
index: 0,
path: [0, 0, 1],
},
],
{
file: {} as unknown as File,
viewWrapper: {
Relationships: {},
} as unknown as IViewWrapper,
stack: [],
},
true,
);
expect(JSON.stringify(output)).to.contain("sweet");
expect(output.elements![0].elements![1].elements).toMatchObject([
{
type: "element",
name: "w:r",
elements: [
{
type: "element",
name: "w:rPr",
elements: [{ type: "element", name: "w:b", attributes: { "w:val": "1" } }],
},
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "What a " }],
},
],
},
{
type: "element",
name: "w:r",
elements: [
{
type: "element",
name: "w:rPr",
elements: [{ type: "element", name: "w:b", attributes: { "w:val": "1" } }],
},
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "sweet" }],
},
],
},
{
type: "element",
name: "w:r",
elements: [
{
type: "element",
name: "w:rPr",
elements: [{ type: "element", name: "w:b", attributes: { "w:val": "1" } }],
},
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: " text!" }],
},
],
},
]);
});
it("should replace document type", () => { it("should replace document type", () => {
const output = replacer( const output = replacer(
MOCK_JSON, MOCK_JSON,

View File

@ -20,6 +20,7 @@ export const replacer = (
patchText: string, patchText: string,
renderedParagraphs: readonly IRenderedParagraphNode[], renderedParagraphs: readonly IRenderedParagraphNode[],
context: IContext, context: IContext,
keepOriginalStyles: boolean = false,
): Element => { ): Element => {
for (const renderedParagraph of renderedParagraphs) { for (const renderedParagraph of renderedParagraphs) {
const textJson = patch.children const textJson = patch.children
@ -47,9 +48,30 @@ export const replacer = (
const index = findRunElementIndexWithToken(paragraphElement, SPLIT_TOKEN); const index = findRunElementIndexWithToken(paragraphElement, SPLIT_TOKEN);
const { left, right } = splitRunElement(paragraphElement.elements![index], SPLIT_TOKEN); const runElementToBeReplaced = paragraphElement.elements![index];
const { left, right } = splitRunElement(runElementToBeReplaced, SPLIT_TOKEN);
let newRunElements = textJson;
let patchedRightElement = right;
if (keepOriginalStyles) {
const runElementNonTextualElements = runElementToBeReplaced.elements!.filter(
(e) => e.type === "element" && e.name !== "w:t",
);
newRunElements = textJson.map((e) => ({
...e,
elements: [...runElementNonTextualElements, ...e.elements!],
}));
patchedRightElement = {
...right,
elements: [...runElementNonTextualElements, ...right.elements!],
};
}
// eslint-disable-next-line functional/immutable-data // eslint-disable-next-line functional/immutable-data
paragraphElement.elements!.splice(index, 1, left, ...textJson, right); paragraphElement.elements!.splice(index, 1, left, ...newRunElements, patchedRightElement);
break; break;
} }
} }

View File

@ -1,9 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ES2015",
"useDefineForClassFields": true, "useDefineForClassFields": true,
"module": "ESNext", "module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"], "lib": ["ES2015", "DOM", "DOM.Iterable"],
"skipLibCheck": true, "skipLibCheck": true,
/* Bundler mode */ /* Bundler mode */
@ -35,14 +35,5 @@
"@shared": ["./shared/index.ts"] "@shared": ["./shared/index.ts"]
} }
}, },
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
},
"include": ["src"] "include": ["src"]
} }

View File

@ -39,7 +39,7 @@ export default defineConfig({
} }
if (d === "es") { if (d === "es") {
return "index.js"; return "index.mjs";
} }
if (d === "iife") { if (d === "iife") {