Compare commits
485 Commits
Author | SHA1 | Date | |
---|---|---|---|
168e5e6e11 | |||
ce71f19826 | |||
4fd3f3a6b8 | |||
39763d3869 | |||
36f90edc67 | |||
b0cbd6f609 | |||
d23d4a4557 | |||
07c58ee43c | |||
1037e8f1b9 | |||
f0ae8396f7 | |||
1ae5995f9c | |||
751ad9d304 | |||
0bd1514826 | |||
16bfc78d8d | |||
528008406a | |||
9e3010ac6a | |||
7c1fa6f4bf | |||
f58d31cc3d | |||
286c742ece | |||
3edc51d5a0 | |||
05d4c9688e | |||
d4401d1597 | |||
90358e73f6 | |||
a77ca02ea9 | |||
7785f0df02 | |||
0e6ed6e5ea | |||
70e84c8d38 | |||
11c3886659 | |||
6104e5bc35 | |||
c748b9a7fc | |||
714dbc0179 | |||
7f16cfc359 | |||
78757753c8 | |||
8343edcdf1 | |||
1ab9e08eb9 | |||
e1bc7f34c9 | |||
d5b495df5b | |||
d6256d2acb | |||
f1c7e448ae | |||
b600fd9324 | |||
3bf40ecb33 | |||
ffb650daa9 | |||
d2122e7806 | |||
6b6eb1d7a2 | |||
c80d881105 | |||
3c223c69e9 | |||
2420321008 | |||
29d5421cea | |||
71953cf45a | |||
325866d9c3 | |||
457e9c12e3 | |||
ff4a66466a | |||
cc142cc052 | |||
6e0dc69217 | |||
33332bcf66 | |||
b94f9ac25b | |||
0a7be48dcb | |||
3f3397620e | |||
154bc1df95 | |||
715e436c4c | |||
f5a9bcf839 | |||
31d2da86ff | |||
9dad3ca356 | |||
355e01edc6 | |||
c19bf1c404 | |||
970450074d | |||
91e8295648 | |||
3e40ae862b | |||
236cce604f | |||
0388a564b5 | |||
cd77ceba69 | |||
5ae8731abe | |||
7bb90c55d1 | |||
a07d6378e8 | |||
4fb8d277b4 | |||
73186ce920 | |||
d02f98956f | |||
d186d42bb6 | |||
338f7be967 | |||
b63a6e6e16 | |||
7e9884081e | |||
262f6323d0 | |||
811dd61562 | |||
9801879063 | |||
e30836c935 | |||
352511bb55 | |||
8ce057e25c | |||
0775ecb08b | |||
e909ab9886 | |||
e03bb155b9 | |||
91620d61d8 | |||
0fba450c9a | |||
ca604fb004 | |||
9e998d233c | |||
6c0fd3adec | |||
6ad18420e5 | |||
ef95a16f39 | |||
53861ec18d | |||
81b1569ad2 | |||
66a1992da0 | |||
100356c344 | |||
31905a27b1 | |||
08916176a2 | |||
ffb3d63c92 | |||
22005428ba | |||
a70acd6d63 | |||
af9e0b0d3f | |||
a0c2be8af2 | |||
df9d4b4219 | |||
cdf5015920 | |||
fe9b438a51 | |||
59cbf8c9cb | |||
7af8175034 | |||
bf0393b485 | |||
83a8822cf7 | |||
eada41b8a1 | |||
2c03377c47 | |||
484fc4aa2d | |||
2846014db0 | |||
c9d86619de | |||
ce485dbc29 | |||
4e875b4744 | |||
3f6c006716 | |||
f8f5d43b0c | |||
8c0fe00c6f | |||
c37d9ca5b3 | |||
f3dc1f0712 | |||
a4d96bbf6e | |||
90c40178aa | |||
2ee96b419a | |||
773900b620 | |||
ece440340f | |||
5233b4b5e6 | |||
86de252a52 | |||
c206d23480 | |||
5a53a138d9 | |||
5b5deb198e | |||
88a30e5af7 | |||
0b9ffa9a7b | |||
5052bcde4f | |||
d5409678ee | |||
72c39a9eb2 | |||
2ed7a28d1e | |||
7b2ff00c83 | |||
d5b0083d77 | |||
406183d104 | |||
c6d3e60314 | |||
be71037a13 | |||
c8c64b320b | |||
8514e8ad31 | |||
d505281a7e | |||
58575342e0 | |||
60ad6d6ab5 | |||
f9dec1cb3c | |||
ffd998cbf5 | |||
c713e6f371 | |||
3c55f9fc1f | |||
c9a8a99278 | |||
b309d327f0 | |||
58bad10bfe | |||
26ea6c518f | |||
d4594a97a2 | |||
68f951ef79 | |||
12e29c6a75 | |||
05eedb2ac1 | |||
8cbc6c15fe | |||
2c21f64b9f | |||
7ec9cff433 | |||
3f979b9981 | |||
3077ca96a7 | |||
46ded68369 | |||
b3a53d341d | |||
afcd5e70a1 | |||
ae48999e38 | |||
4c38e45455 | |||
ec847dccf9 | |||
ca47a1dc3f | |||
cc53ff417b | |||
fcba817a4a | |||
bcd8249d17 | |||
bc0a197ba1 | |||
2e16279d7b | |||
87590aedbd | |||
0fef7763d5 | |||
e55698d221 | |||
d410b5e96f | |||
8587601411 | |||
5b67cb21c6 | |||
42fd9d06de | |||
1e0b74fd27 | |||
21934ec85b | |||
b4f01fb6ec | |||
fbf6329500 | |||
41549443c3 | |||
92630af4e1 | |||
4db633da16 | |||
dac02f13ae | |||
1a52dec1c2 | |||
be1ca51162 | |||
768e20bb79 | |||
26b9b15de8 | |||
42713095b6 | |||
3acafeca38 | |||
7ca75c8c5a | |||
c00ad454a9 | |||
16d04eb4d3 | |||
816845f271 | |||
12eeda8d33 | |||
3d622c2ef1 | |||
21a6767c6f | |||
7a7326ec09 | |||
9b3af4e217 | |||
cee0114f81 | |||
03399aedf0 | |||
2739b94bd8 | |||
c720441d62 | |||
00b5898fe0 | |||
0d0940b7a5 | |||
f28c949ac6 | |||
63317d6ac8 | |||
6406ba831f | |||
7a7575964a | |||
d75c833717 | |||
40344b57d9 | |||
6fc26d1da3 | |||
a012a0e418 | |||
bf1a2f3059 | |||
ca316b4e6d | |||
1fb5c581c9 | |||
efa64b451a | |||
38059ea6b9 | |||
c2110622ca | |||
0452959b85 | |||
0eca8389b6 | |||
66e043137b | |||
d684654625 | |||
7749f6b20f | |||
15c9c0ae3e | |||
74fddc2ada | |||
cff866ecdc | |||
e952c02c83 | |||
546983c6ba | |||
c7134564a3 | |||
984a3573eb | |||
defe94a2b2 | |||
e23c8c4b46 | |||
7941ff487a | |||
7b7df33a0f | |||
68b04f2511 | |||
db3e017a7d | |||
c21d45a79e | |||
6defb686bb | |||
f68796dae1 | |||
b1872bcb95 | |||
3006f4d2c1 | |||
7f88a38219 | |||
aeb2487c70 | |||
e42e50dd39 | |||
f4572b9720 | |||
7646f3a845 | |||
e4e5b1e4f6 | |||
a481518470 | |||
2435ebf16e | |||
414fa70e5d | |||
f255d4c141 | |||
4513bb529b | |||
5907132062 | |||
69bf313f18 | |||
fe8b0a6b2b | |||
abcfd79f2f | |||
41e3b078ec | |||
4eb2f92c1f | |||
9bfb5bf681 | |||
473ad2947c | |||
ee28f6ad84 | |||
11bebd42ac | |||
49b4ca67e0 | |||
3282f762df | |||
d335106b46 | |||
cefa01f7ec | |||
b7ba2b3306 | |||
03d5152e7c | |||
af3b7f2613 | |||
1405841565 | |||
211d2dc0d6 | |||
82f431465f | |||
247afe56ce | |||
91e874eee5 | |||
ff67c3660b | |||
58c580b9ca | |||
a9da151026 | |||
83c72d0dbb | |||
2c31367851 | |||
3b618f3a2c | |||
4c5bc6232d | |||
694835bdac | |||
c8b75c19da | |||
c0181aa83a | |||
c5b615ae2a | |||
54cbd56f42 | |||
c8914a109e | |||
62d0767ceb | |||
8509bccc4f | |||
4ce53a3d76 | |||
8024c01a82 | |||
1b380c3fdb | |||
06b67bd292 | |||
8a1087f601 | |||
ff09d6515c | |||
ebe85d8e14 | |||
5dc27ac46a | |||
1dcc8ee761 | |||
ec69f9ac07 | |||
f789f60e22 | |||
32e3f07d57 | |||
9ea41ab3ce | |||
4b8d062862 | |||
d9408029f3 | |||
9fe0406078 | |||
5a4fe5d5da | |||
e6af9b4b73 | |||
361f9231d8 | |||
4215932550 | |||
29da523579 | |||
fbb4d7cfde | |||
3ea453a07f | |||
984e762a53 | |||
1592aa7117 | |||
62b4522c94 | |||
8b86751c95 | |||
afa380e336 | |||
feebff9077 | |||
028b50ff99 | |||
559e81c3fe | |||
4da6b98437 | |||
5b2409c76f | |||
ff027d172e | |||
3f23290a46 | |||
f1a10d32e6 | |||
a71f40e873 | |||
7f449319cd | |||
ab5c8ea698 | |||
68cfa9360b | |||
f627e3d994 | |||
7c870548d9 | |||
57ccc41547 | |||
988ba45197 | |||
df6606041b | |||
3ae27b466f | |||
69f5e21435 | |||
6da73c612a | |||
e1b1c1492f | |||
6ca13c4fce | |||
b474567d20 | |||
c07170902e | |||
0f201d2f4b | |||
b875d6f183 | |||
831b92239d | |||
66b91c22dd | |||
1242c0689f | |||
4386d02526 | |||
3ba521f8cc | |||
85bb818ae6 | |||
be7e2aa8fe | |||
7f71f6e3f1 | |||
a94d23e2ae | |||
133c255ce2 | |||
863e27ff9b | |||
5c63e6ae12 | |||
10dd36569d | |||
be5985fb6a | |||
0d7f169613 | |||
eaddcb83ab | |||
9a6885f124 | |||
7284ee818b | |||
20964454c4 | |||
d7670929d1 | |||
58f0761423 | |||
3f28bc09bc | |||
323895f0ab | |||
6efa734e81 | |||
47d64af737 | |||
4a2b91ce07 | |||
080a77cc73 | |||
9b874b0061 | |||
ff8a2ed538 | |||
251eafe103 | |||
64b604c9ac | |||
72fc5f9874 | |||
71dcdf0ca2 | |||
e23fc987a7 | |||
36dba1a36f | |||
1b1547d4b6 | |||
8008482592 | |||
6d1a7fe438 | |||
90c58b0498 | |||
c91bb71700 | |||
3d09c45205 | |||
f1e41d883c | |||
4f783ec8e4 | |||
3d35e84953 | |||
e80bc8b584 | |||
2848b39479 | |||
7ee9be200c | |||
94cdd740ad | |||
9130687164 | |||
2f52f47463 | |||
01866f4802 | |||
fa8ac0f2e4 | |||
e9a909ed20 | |||
8808447963 | |||
056b496189 | |||
11b374ea75 | |||
f8f9744786 | |||
6f6888d638 | |||
995430b76f | |||
d4a5ec4e14 | |||
c7dce059f8 | |||
2f4e3f2153 | |||
a37c5646b6 | |||
ddc9c8f62f | |||
1b06fc71cf | |||
e65a3bfeab | |||
b9ceabcc07 | |||
35be3bfb9b | |||
572c8efbc7 | |||
b1b3e2369b | |||
dc72bb629e | |||
a724706817 | |||
84989116ef | |||
6c4efe4a1c | |||
8596d70b79 | |||
db6c9b2700 | |||
a33602ccf6 | |||
988987ddbe | |||
309e66a6de | |||
7d8cfc0382 | |||
5cbae5d3f7 | |||
9b630c4ef7 | |||
befcbabe27 | |||
4cfb0ade88 | |||
a6f528537b | |||
dfc82a517d | |||
29f421686f | |||
c11299076f | |||
1cb2ef565e | |||
2de07d04a8 | |||
75e064dd1d | |||
5f0091ee25 | |||
d2c0e656d0 | |||
522b21862b | |||
ccf66dbd50 | |||
6e30ab0355 | |||
568c764e3c | |||
d508e8ae31 | |||
ded346e34a | |||
edb8eddce1 | |||
abd3641da4 | |||
7e1165d012 | |||
461754e591 | |||
e649330dbc | |||
baec324811 | |||
91c430d9e2 | |||
efd853d519 | |||
f717b0eae4 | |||
d76d21a1f2 | |||
712450d717 | |||
b9d93c9d33 | |||
c7ca51cd65 | |||
20b793620a | |||
9bed303d34 | |||
f4ed171f85 | |||
8a3ccdb196 | |||
41765d133f | |||
482ea1b186 | |||
3bba7f9d23 | |||
32a5cca878 | |||
911c705b59 | |||
594c8d72b8 | |||
7ea5232b22 | |||
be12d61795 | |||
925340eb3d | |||
601a4038f4 | |||
e0576c889b | |||
4ff7f0a7bd |
@ -47,7 +47,9 @@
|
||||
"/xmlKeys = {[^}]+}/g",
|
||||
"/\\.to\\.deep\\.equal\\({[^)]+}\\)/g",
|
||||
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g"
|
||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
||||
"/<element name=\"[a-z]+\"/gi",
|
||||
"/<attribute name=\"[a-z]+\"/gi"
|
||||
],
|
||||
"ignorePaths": ["package.json", "docs/api"],
|
||||
"allowCompoundWords": true,
|
||||
|
14
.eslintrc.js
14
.eslintrc.js
@ -96,8 +96,8 @@ module.exports = {
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error",
|
||||
{
|
||||
allowExpressions: false,
|
||||
allowTypedFunctionExpressions: false,
|
||||
allowExpressions: true,
|
||||
allowTypedFunctionExpressions: true,
|
||||
allowHigherOrderFunctions: false,
|
||||
allowDirectConstAssertionInArrowFunctions: true,
|
||||
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
||||
@ -214,7 +214,6 @@ module.exports = {
|
||||
"no-sequences": "error",
|
||||
"no-shadow": "off",
|
||||
"no-sparse-arrays": "error",
|
||||
"no-template-curly-in-string": "error",
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef-init": "error",
|
||||
@ -243,7 +242,6 @@ module.exports = {
|
||||
"unicorn/prefer-ternary": "error",
|
||||
"use-isnan": "error",
|
||||
"valid-typeof": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"functional/immutable-data": [
|
||||
"error",
|
||||
{
|
||||
@ -252,9 +250,12 @@ module.exports = {
|
||||
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
|
||||
},
|
||||
],
|
||||
"functional/no-method-signature": "error",
|
||||
"functional/no-mixed-type": "error",
|
||||
"functional/prefer-property-signatures": "error",
|
||||
"functional/no-mixed-types": "error",
|
||||
// TODO: Deprecated. Use prefer-immutable-types and type-declaration-immutability instead
|
||||
"functional/prefer-readonly-type": "error",
|
||||
// "functional/prefer-immutable-types": "error",
|
||||
// "functional/type-declaration-immutability": "error",
|
||||
"no-unused-vars": ["error", { argsIgnorePattern: "^[_]+$" }],
|
||||
},
|
||||
overrides: [
|
||||
@ -264,6 +265,7 @@ module.exports = {
|
||||
"@typescript-eslint/no-unused-expressions": "off",
|
||||
"@typescript-eslint/dot-notation": "off",
|
||||
"prefer-destructuring": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
|
2
.github/workflows/default.yml
vendored
2
.github/workflows/default.yml
vendored
@ -34,7 +34,7 @@ jobs:
|
||||
- name: Test
|
||||
run: npm run test.coverage
|
||||
- name: Codecov
|
||||
uses: codecov/codecov-action@v1
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
fail_ci_if_error: true
|
||||
verbose: true
|
||||
|
128
.github/workflows/demos.yml
vendored
128
.github/workflows/demos.yml
vendored
@ -301,15 +301,6 @@ jobs:
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/30-template-document.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/31-tables.ts
|
||||
- name: Extract Word Document
|
||||
@ -688,4 +679,121 @@ jobs:
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
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
|
||||
run: npm run ts-node -- ./demo/72-word-wrap.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/73-comments.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/73-comments.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
# - name: Run Demo
|
||||
# run: npm run ts-node -- ./demo/75-tab-stops.ts
|
||||
# - name: Extract Word Document
|
||||
# run: npm run extract
|
||||
# - name: Validate XML
|
||||
# uses: ChristophWurst/xmllint-action@v1
|
||||
# with:
|
||||
# xml-file: build/extracted-doc/word/document.xml
|
||||
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/76-compatibility.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/77-side-by-side-tables.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/78-thai-distributed.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/79-table-from-data-source.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/80-thai-distributed.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/81-continuous-header.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/82-new-headers-new-section.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/83-setting-languages.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
- name: Run Demo
|
||||
run: npm run ts-node -- ./demo/84-positional-tabs.ts
|
||||
- name: Extract Word Document
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||
|
@ -40,4 +40,7 @@ build-tests
|
||||
.vscode
|
||||
|
||||
# docs
|
||||
docs
|
||||
docs
|
||||
|
||||
# src
|
||||
src
|
||||
|
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
||||
{
|
||||
"check-coverage": true,
|
||||
"statements": 99.72,
|
||||
"branches": 97.95,
|
||||
"functions": 99.82,
|
||||
"lines": 99.71,
|
||||
"statements": 99.87,
|
||||
"branches": 98.21,
|
||||
"functions": 100,
|
||||
"lines": 99.86,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
|
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
Easily generate .docx files with JS/TS. Works for Node and on the Browser.
|
||||
Easily generate and modify .docx files with JS/TS. Works for Node and on the Browser.
|
||||
</p>
|
||||
|
||||
---
|
||||
@ -29,11 +29,12 @@ Here are examples of `docx` being used with basic `HTML/JS` in a browser environ
|
||||
- https://codepen.io/dolanmiu/pen/RwNeObg
|
||||
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||
|
||||
Here is an example of `docx` working in `Angular`:
|
||||
Here are examples of `docx` working in `Angular`:
|
||||
|
||||
- https://stackblitz.com/edit/angular-docx
|
||||
- https://stackblitz.com/edit/angular-wmd6k3
|
||||
|
||||
Here is an example of `docx` working in `React`:
|
||||
Here are examples of `docx` working in `React`:
|
||||
|
||||
- https://stackblitz.com/edit/react-docx
|
||||
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||
@ -87,6 +88,7 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
||||
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing"/>](https://www.arity.co/)
|
||||
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
|
||||
[<img src="https://i.imgur.com/AKGhtlh.png" alt="drawing"/>](https://lexense.com/)
|
||||
[<img src="https://i.imgur.com/9tqJaHw.png" alt="drawing" height="50"/>](https://novelpad.co/)
|
||||
|
||||
...and many more!
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -14,9 +14,10 @@ const doc = new Document({
|
||||
new TextRun({
|
||||
text: "Foo Bar",
|
||||
bold: true,
|
||||
size: 40,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Generate a CV
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, Tab, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||
|
||||
// tslint:disable:no-shadowed-variable
|
||||
|
||||
@ -284,7 +284,7 @@ class DocumentCreator {
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: `\t${dateText}`,
|
||||
children: [new Tab(), dateText],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Export to base64 string - Useful in a browser environment.
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -15,7 +15,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tBar",
|
||||
children: [new Tab(), "Bar"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -82,6 +82,32 @@ const doc = new Document({
|
||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "strikeUnderline",
|
||||
name: "Strike Underline",
|
||||
basedOn: "Normal",
|
||||
quickFormat: true,
|
||||
run: {
|
||||
strike: true,
|
||||
underline: {
|
||||
type: UnderlineType.SINGLE,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
characterStyles: [
|
||||
{
|
||||
id: "strikeUnderlineCharacter",
|
||||
name: "Strike Underline",
|
||||
basedOn: "Normal",
|
||||
quickFormat: true,
|
||||
run: {
|
||||
strike: true,
|
||||
underline: {
|
||||
type: UnderlineType.SINGLE,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
numbering: {
|
||||
@ -169,6 +195,14 @@ const doc = new Document({
|
||||
new TextRun({
|
||||
text: "and back to normal.",
|
||||
}),
|
||||
new TextRun({
|
||||
text: "This text will be invisible!",
|
||||
vanish: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "This text will be VERY invisible! Word processors cannot override this!",
|
||||
specVanish: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
@ -182,6 +216,49 @@ const doc = new Document({
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
style: "strikeUnderline",
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Underline and Strike",
|
||||
}),
|
||||
new TextRun({
|
||||
text: " Override Underline ",
|
||||
underline: {
|
||||
type: UnderlineType.NONE,
|
||||
},
|
||||
}),
|
||||
new TextRun({
|
||||
text: "Strike and Underline",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Hello World ",
|
||||
}),
|
||||
new TextRun({
|
||||
style: "strikeUnderlineCharacter",
|
||||
text: "Underline and Strike",
|
||||
}),
|
||||
new TextRun({
|
||||
text: " Another Hello World",
|
||||
}),
|
||||
new TextRun({
|
||||
scale: 50,
|
||||
text: " Scaled text",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
scale: 200,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Scaled paragraph",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -25,6 +25,17 @@ const doc = new Document({
|
||||
},
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "",
|
||||
border: {
|
||||
top: {
|
||||
color: "auto",
|
||||
space: 1,
|
||||
style: BorderStyle.SINGLE,
|
||||
size: 6,
|
||||
},
|
||||
},
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
|
@ -1,35 +0,0 @@
|
||||
// Example on how to use a template document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, ImportDotx, Packer, Paragraph } from "../build";
|
||||
|
||||
const importDotx = new ImportDotx();
|
||||
const filePath = "./demo/dotx/template.dotx";
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
throw new Error(`Failed to read file ${filePath}.`);
|
||||
}
|
||||
|
||||
importDotx.extract(data).then((templateDocument) => {
|
||||
const doc = new Document(
|
||||
{
|
||||
sections: [
|
||||
{
|
||||
properties: {
|
||||
titlePage: templateDocument.titlePageIsDefined,
|
||||
},
|
||||
children: [new Paragraph("Hello World")],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
template: templateDocument,
|
||||
},
|
||||
);
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,7 +1,7 @@
|
||||
// Example of making content of section vertically aligned
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun, Tab } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -18,7 +18,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -25,6 +25,11 @@ const doc = new Document({
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
altText: {
|
||||
title: "This is an ultimate title",
|
||||
description: "This is an ultimate image",
|
||||
name: "My Ultimate Image",
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Change background colour of whole document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
background: {
|
||||
@ -19,7 +19,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how to change page borders
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -25,7 +25,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -12,6 +12,7 @@ import {
|
||||
PageNumber,
|
||||
Paragraph,
|
||||
ShadingType,
|
||||
Tab,
|
||||
TextRun,
|
||||
} from "../build";
|
||||
|
||||
@ -111,7 +112,7 @@ const doc = new Document({
|
||||
}),
|
||||
new TextRun({
|
||||
bold: true,
|
||||
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||
children: [new Tab(), "use Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||
}),
|
||||
new TextRun({
|
||||
bold: true,
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
HorizontalPositionAlign,
|
||||
Packer,
|
||||
Paragraph,
|
||||
Tab,
|
||||
TextRun,
|
||||
VerticalPositionAlign,
|
||||
} from "../build";
|
||||
@ -67,7 +68,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -7,12 +7,31 @@ const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
wordWrap: true,
|
||||
children: [
|
||||
new TextRun("我今天遛狗去公园"),
|
||||
new TextRun({
|
||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
wordWrap: true,
|
||||
children: [
|
||||
new TextRun(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
||||
),
|
||||
new TextRun({
|
||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("我今天遛狗去公园"),
|
||||
new TextRun({
|
||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||
space: SpaceType.PRESERVE,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -23,7 +42,6 @@ const doc = new Document({
|
||||
),
|
||||
new TextRun({
|
||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||
space: SpaceType.PRESERVE,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -5,7 +5,34 @@ import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEn
|
||||
|
||||
const doc = new Document({
|
||||
comments: {
|
||||
children: [{ id: 0, author: "Ray Chen", date: new Date(), text: "comment text content" }],
|
||||
children: [
|
||||
{
|
||||
id: 0,
|
||||
author: "Ray Chen",
|
||||
date: new Date(),
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "some initial text content",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "comment text content",
|
||||
}),
|
||||
new TextRun({ text: "", break: 1 }),
|
||||
new TextRun({
|
||||
text: "More text here",
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Exporting the document as a stream
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -16,7 +16,7 @@ const doc = new Document({
|
||||
bold: true,
|
||||
}),
|
||||
new TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Exporting the document as a stream
|
||||
// Example of using tab stops
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||
|
87
demo/76-compatibility.ts
Normal file
87
demo/76-compatibility.ts
Normal file
@ -0,0 +1,87 @@
|
||||
// Add compatibility options
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
compatibility: {
|
||||
useSingleBorderforContiguousCells: true,
|
||||
wordPerfectJustification: true,
|
||||
noTabStopForHangingIndent: true,
|
||||
noLeading: true,
|
||||
spaceForUnderline: true,
|
||||
noColumnBalance: true,
|
||||
balanceSingleByteDoubleByteWidth: true,
|
||||
noExtraLineSpacing: true,
|
||||
doNotLeaveBackslashAlone: true,
|
||||
underlineTrailingSpaces: true,
|
||||
doNotExpandShiftReturn: true,
|
||||
spacingInWholePoints: true,
|
||||
lineWrapLikeWord6: true,
|
||||
printBodyTextBeforeHeader: true,
|
||||
printColorsBlack: true,
|
||||
spaceWidth: true,
|
||||
showBreaksInFrames: true,
|
||||
subFontBySize: true,
|
||||
suppressBottomSpacing: true,
|
||||
suppressTopSpacing: true,
|
||||
suppressSpacingAtTopOfPage: true,
|
||||
suppressTopSpacingWP: true,
|
||||
suppressSpBfAfterPgBrk: true,
|
||||
swapBordersFacingPages: true,
|
||||
convertMailMergeEsc: true,
|
||||
truncateFontHeightsLikeWP6: true,
|
||||
macWordSmallCaps: true,
|
||||
usePrinterMetrics: true,
|
||||
doNotSuppressParagraphBorders: true,
|
||||
wrapTrailSpaces: true,
|
||||
footnoteLayoutLikeWW8: true,
|
||||
shapeLayoutLikeWW8: true,
|
||||
alignTablesRowByRow: true,
|
||||
forgetLastTabAlignment: true,
|
||||
adjustLineHeightInTable: true,
|
||||
autoSpaceLikeWord95: true,
|
||||
noSpaceRaiseLower: true,
|
||||
doNotUseHTMLParagraphAutoSpacing: true,
|
||||
layoutRawTableWidth: true,
|
||||
layoutTableRowsApart: true,
|
||||
useWord97LineBreakRules: true,
|
||||
doNotBreakWrappedTables: true,
|
||||
doNotSnapToGridInCell: true,
|
||||
selectFieldWithFirstOrLastCharacter: true,
|
||||
applyBreakingRules: true,
|
||||
doNotWrapTextWithPunctuation: true,
|
||||
doNotUseEastAsianBreakRules: true,
|
||||
useWord2002TableStyleRules: true,
|
||||
growAutofit: true,
|
||||
useFELayout: true,
|
||||
useNormalStyleForList: true,
|
||||
doNotUseIndentAsNumberingTabStop: true,
|
||||
useAlternateEastAsianLineBreakRules: true,
|
||||
allowSpaceOfSameStyleInTable: true,
|
||||
doNotSuppressIndentation: true,
|
||||
doNotAutofitConstrainedTables: true,
|
||||
autofitToFirstFixedWidthCell: true,
|
||||
underlineTabInNumberingList: true,
|
||||
displayHangulFixedWidth: true,
|
||||
splitPgBreakAndParaMark: true,
|
||||
doNotVerticallyAlignCellWithSp: true,
|
||||
doNotBreakConstrainedForcedTable: true,
|
||||
ignoreVerticalAlignmentInTextboxes: true,
|
||||
useAnsiKerningPairs: true,
|
||||
cachedColumnBalance: true,
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
116
demo/77-side-by-side-tables.ts
Normal file
116
demo/77-side-by-side-tables.ts
Normal file
@ -0,0 +1,116 @@
|
||||
// Exporting the document as a stream
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, WidthType } from "../build";
|
||||
|
||||
const table1 = new Table({
|
||||
columnWidths: [3505, 5505],
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 3505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [new Paragraph("Hello")],
|
||||
}),
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 5505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 3505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [],
|
||||
}),
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 5505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [new Paragraph("World")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const table2 = new Table({
|
||||
columnWidths: [3505, 5505],
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 3505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [new Paragraph("Foo")],
|
||||
}),
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 5505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 3505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [],
|
||||
}),
|
||||
new TableCell({
|
||||
width: {
|
||||
size: 5505,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
children: [new Paragraph("Bar")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const noBorderTable = new Table({
|
||||
borders: TableBorders.NONE,
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [table1],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [table2],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [noBorderTable],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const stream = Packer.toStream(doc);
|
||||
stream.pipe(fs.createWriteStream("My Document.docx"));
|
27
demo/78-thai-distributed.ts
Normal file
27
demo/78-thai-distributed.ts
Normal file
@ -0,0 +1,27 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "บริษัท บิสกิด จำกัด (บริษัทฯ) ได้จดทะเบียนจัดตั้งขึ้นเป็นบริษัทจำกัดตามประมวลกฎหมายแพ่งและพาณิชย์ของประเทศไทย เมื่อวันที่ 30 พฤษภาคม 2561 ทะเบียนนิติบุคคลเลขที่ 0845561005665",
|
||||
size: 36,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
193
demo/79-table-from-data-source.ts
Normal file
193
demo/79-table-from-data-source.ts
Normal file
@ -0,0 +1,193 @@
|
||||
// Example of how you would create a table and add data to it from a data source
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
HeadingLevel,
|
||||
Packer,
|
||||
Paragraph,
|
||||
Table,
|
||||
TableCell,
|
||||
TableRow,
|
||||
VerticalAlign,
|
||||
TextDirection,
|
||||
TextRun,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
|
||||
interface StockPrice {
|
||||
readonly date: Date;
|
||||
readonly ticker: string;
|
||||
readonly price: number;
|
||||
}
|
||||
|
||||
const DATA: StockPrice[] = [
|
||||
{
|
||||
date: new Date("2007-08-28"),
|
||||
ticker: "Apple",
|
||||
price: 18.12,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-08-29"),
|
||||
ticker: "Apple",
|
||||
price: 19.15,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-08-30"),
|
||||
ticker: "Apple",
|
||||
price: 19.46,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-08-31"),
|
||||
ticker: "Apple",
|
||||
price: 19.78,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-04"),
|
||||
ticker: "Apple",
|
||||
price: 20.59,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-05"),
|
||||
ticker: "Apple",
|
||||
price: 19.54,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-06"),
|
||||
ticker: "Apple",
|
||||
price: 19.29,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-07"),
|
||||
ticker: "Apple",
|
||||
price: 18.82,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-10"),
|
||||
ticker: "Apple",
|
||||
price: 19.53,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-11"),
|
||||
ticker: "Apple",
|
||||
price: 19.36,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-12"),
|
||||
ticker: "Apple",
|
||||
price: 19.55,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-13"),
|
||||
ticker: "Apple",
|
||||
price: 19.6,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-14"),
|
||||
ticker: "Apple",
|
||||
price: 19.83,
|
||||
},
|
||||
{
|
||||
date: new Date("2007-09-17"),
|
||||
ticker: "Apple",
|
||||
price: 19.77,
|
||||
},
|
||||
];
|
||||
|
||||
const generateRows = (prices: StockPrice[]): TableRow[] =>
|
||||
prices.map(
|
||||
({ date, ticker, price }) =>
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph(date.toString())],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph(ticker)],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph(price.toString())],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Table({
|
||||
width: {
|
||||
size: 9070,
|
||||
type: WidthType.DXA,
|
||||
},
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Date",
|
||||
bold: true,
|
||||
size: 40,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Ticker",
|
||||
bold: true,
|
||||
size: 40,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
heading: HeadingLevel.HEADING_2,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Price",
|
||||
bold: true,
|
||||
size: 40,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
...generateRows(DATA),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
49
demo/80-thai-distributed.ts
Normal file
49
demo/80-thai-distributed.ts
Normal file
@ -0,0 +1,49 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "test",
|
||||
name: "Test",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
paragraph: {
|
||||
indent: { left: convertMillimetersToTwip(6.4) },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
properties: {
|
||||
page: {
|
||||
margin: {
|
||||
top: 0,
|
||||
right: convertMillimetersToTwip(24),
|
||||
bottom: convertMillimetersToTwip(24),
|
||||
left: convertMillimetersToTwip(24),
|
||||
},
|
||||
},
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "บริษัทฯ มีเงินสด 41,985.00 บาท และ 25,855.66 บาทตามลำดับ เงินสดทั้งจำนวนอยู่ในความดูแลและรับผิดชอบของกรรมการ บริษัทฯบันทึกการรับชำระเงินและการจ่ายชำระเงินผ่านบัญชีเงินสดเพียงเท่านั้น ซึ่งอาจกระทบต่อความถูกต้องครบถ้วนของการบันทึกบัญชี ทั้งนี้ขึ้นอยู่กับระบบการควบคุมภายในของบริษัท",
|
||||
size: 28,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
148
demo/81-continuous-header.ts
Normal file
148
demo/81-continuous-header.ts
Normal file
@ -0,0 +1,148 @@
|
||||
// Example of a continuous header
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Creator",
|
||||
title: "Title",
|
||||
sections: [
|
||||
{
|
||||
properties: { titlePage: true },
|
||||
headers: {
|
||||
first: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "HEADER PAGE ONE",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
default: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
first: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "FOOTER PAGE ONE",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
default: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
spacing: {
|
||||
after: 500,
|
||||
},
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "The first section ends after this paragraph.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
type: SectionType.CONTINUOUS,
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
148
demo/82-new-headers-new-section.ts
Normal file
148
demo/82-new-headers-new-section.ts
Normal file
@ -0,0 +1,148 @@
|
||||
// Example of using headers and footers in a new section
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Creator",
|
||||
title: "Title",
|
||||
sections: [
|
||||
{
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "HEADER PAGE ONE",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "FOOTER PAGE ONE",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
spacing: {
|
||||
after: 500,
|
||||
},
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "The first section ends after this paragraph.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
69
demo/83-setting-languages.ts
Normal file
69
demo/83-setting-languages.ts
Normal file
@ -0,0 +1,69 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
default: {
|
||||
document: {
|
||||
run: {
|
||||
color: "ff0000",
|
||||
language: {
|
||||
value: "es-ES",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
paragraphStyles: [
|
||||
{
|
||||
id: "frenchNormal",
|
||||
name: "French Normal",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
run: {
|
||||
color: "999999",
|
||||
italics: true,
|
||||
language: {
|
||||
value: "fr-FR",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "koreanNormal",
|
||||
name: "Korean Normal",
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
run: {
|
||||
color: "0000ff",
|
||||
bold: true,
|
||||
language: {
|
||||
value: "ko-KR",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Yo vivo en Granada, una ciudad pequeña que tiene monumentos muy importantes como la Alhambra. Aquí la comida es deliciosa y son famosos el gazpacho, el rebujito y el salmorejo.",
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Toute personne a droit à l'éducation. L'éducation doit être gratuite, au moins en ce qui concerne l'enseignement élémentaire et fondamental. L'enseignement élémentaire est obligatoire. L'enseignement technique et professionnel doit être généralisé; l'accès aux études supérieures doit être ouvert en pleine égalité à tous en fonction de leur mérite.",
|
||||
style: "frenchNormal",
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "대법관은 대법원장의 제청으로 국회의 동의를 얻어 대통령이 임명한다. 강화조약. 국가는 국민 모두의 생산 및 생활의 기반이 되는 국토의 효율적이고 균형있는 이용·개발과 보전을 위하여 법률이 정하는 바에 의하여 그에 관한 필요한 제한과 의무를 과할 수 있다, 국가는 청원에 대하여 심사할 의무를 진다.",
|
||||
style: "koreanNormal",
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
60
demo/84-positional-tabs.ts
Normal file
60
demo/84-positional-tabs.ts
Normal file
@ -0,0 +1,60 @@
|
||||
// Simple example apply positional tabs to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
Packer,
|
||||
Paragraph,
|
||||
PositionalTab,
|
||||
Tab,
|
||||
TextRun,
|
||||
PositionalTabAlignment,
|
||||
PositionalTabRelativeTo,
|
||||
PositionalTabLeader,
|
||||
} from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("Full name"),
|
||||
new TextRun({
|
||||
children: [
|
||||
new PositionalTab({
|
||||
alignment: PositionalTabAlignment.RIGHT,
|
||||
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||
leader: PositionalTabLeader.DOT,
|
||||
}),
|
||||
"John Doe",
|
||||
],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("Hello World"),
|
||||
new TextRun({
|
||||
children: [
|
||||
new PositionalTab({
|
||||
alignment: PositionalTabAlignment.CENTER,
|
||||
relativeTo: PositionalTabRelativeTo.INDENT,
|
||||
leader: PositionalTabLeader.HYPHEN,
|
||||
}),
|
||||
"Foo bar",
|
||||
],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
155
demo/85-template-document.ts
Normal file
155
demo/85-template-document.ts
Normal file
@ -0,0 +1,155 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
ExternalHyperlink,
|
||||
HeadingLevel,
|
||||
ImageRun,
|
||||
Paragraph,
|
||||
patchDocument,
|
||||
PatchType,
|
||||
Table,
|
||||
TableCell,
|
||||
TableRow,
|
||||
TextDirection,
|
||||
TextRun,
|
||||
VerticalAlign,
|
||||
} from "../build";
|
||||
|
||||
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
|
||||
patches: {
|
||||
name: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new TextRun("Sir. "), new TextRun("John Doe"), new TextRun("(The Conqueror)")],
|
||||
},
|
||||
table_heading_1: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new TextRun("Heading wow!")],
|
||||
},
|
||||
item_1: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [
|
||||
new TextRun("#657"),
|
||||
new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "BBC News Link",
|
||||
}),
|
||||
],
|
||||
link: "https://www.bbc.co.uk/news",
|
||||
}),
|
||||
],
|
||||
},
|
||||
paragraph_replace: {
|
||||
type: PatchType.DOCUMENT,
|
||||
children: [
|
||||
new Paragraph("Lorem ipsum paragraph"),
|
||||
new Paragraph("Another paragraph"),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("This is a "),
|
||||
new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Google Link",
|
||||
}),
|
||||
],
|
||||
link: "https://www.google.co.uk",
|
||||
}),
|
||||
new ImageRun({ data: fs.readFileSync("./demo/images/dog.png"), transformation: { width: 100, height: 100 } }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
header_adjective: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new TextRun("Delightful Header")],
|
||||
},
|
||||
footer_text: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [
|
||||
new TextRun("replaced just as"),
|
||||
new TextRun(" well"),
|
||||
new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "BBC News Link",
|
||||
}),
|
||||
],
|
||||
link: "https://www.bbc.co.uk/news",
|
||||
}),
|
||||
],
|
||||
},
|
||||
image_test: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new ImageRun({ data: fs.readFileSync("./demo/images/image1.jpeg"), transformation: { width: 100, height: 100 } })],
|
||||
},
|
||||
table: {
|
||||
type: PatchType.DOCUMENT,
|
||||
children: [
|
||||
new Table({
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({}), new Paragraph({})],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
|
||||
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||
heading: HeadingLevel.HEADING_1,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "This text should be in the middle of the cell",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Text above should be vertical from bottom to top",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
new TableCell({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Text above should be vertical from top to bottom",
|
||||
}),
|
||||
],
|
||||
verticalAlign: VerticalAlign.CENTER,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
}).then((doc) => {
|
||||
fs.writeFileSync("My Document.docx", doc);
|
||||
});
|
20
demo/86-generate-template.ts
Normal file
20
demo/86-generate-template.ts
Normal file
@ -0,0 +1,20 @@
|
||||
// Generate a template document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("{{template}}")],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
15
demo/87-template-document.ts
Normal file
15
demo/87-template-document.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { patchDocument, PatchType, TextRun } from "../build";
|
||||
|
||||
patchDocument(fs.readFileSync("demo/assets/simple-template-2.docx"), {
|
||||
patches: {
|
||||
name: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new TextRun("Max")],
|
||||
},
|
||||
},
|
||||
}).then((doc) => {
|
||||
fs.writeFileSync("My Document.docx", doc);
|
||||
});
|
BIN
demo/assets/generated-template.docx
Normal file
BIN
demo/assets/generated-template.docx
Normal file
Binary file not shown.
BIN
demo/assets/simple-template-2.docx
Normal file
BIN
demo/assets/simple-template-2.docx
Normal file
Binary file not shown.
BIN
demo/assets/simple-template.docx
Normal file
BIN
demo/assets/simple-template.docx
Normal file
Binary file not shown.
@ -24,7 +24,7 @@
|
||||
bold: true,
|
||||
}),
|
||||
new docx.TextRun({
|
||||
text: "\tGithub is the best",
|
||||
children: [new docx.Tab(), "Github is the best"],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
|
@ -1,10 +1,10 @@
|
||||
<img src="https://i.imgur.com/37uBGhO.gif" alt="drawing" style="width:200px;"/>
|
||||
|
||||
> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
|
||||
> Easily generate and modify .docx files with JS/TS. Works for Node and on the Browser. :100:
|
||||
|
||||
- Simple, declarative API
|
||||
- 60+ usage examples
|
||||
- Battle tested, mature, 99%+ coverage
|
||||
- 80+ usage examples
|
||||
- Battle tested, mature, 99.9%+ coverage
|
||||
|
||||
[GitHub](https://github.com/dolanmiu/docx)
|
||||
[Get Started](#Welcome)
|
||||
|
@ -1,6 +1,8 @@
|
||||
- [Getting Started](/)
|
||||
|
||||
- [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||
- Examples
|
||||
|
||||
- [Demos](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||
|
||||
- API
|
||||
|
||||
@ -11,27 +13,35 @@
|
||||
- [Document](usage/document.md)
|
||||
- [Sections](usage/sections.md)
|
||||
- [Paragraph](usage/paragraph.md)
|
||||
- [Text Frames](usage/text-frames.md)
|
||||
- [Symbols](usage/symbols.md)
|
||||
- [Text](usage/text.md)
|
||||
- [Image](usage/images.md)
|
||||
- [Images](usage/images.md)
|
||||
- [Headers & Footers](usage/headers-and-footers.md)
|
||||
- [Bullet Points](usage/bullet-points.md)
|
||||
- [Hyperlinks](usage/hyperlinks.md)
|
||||
- [Numbering](usage/numbering.md)
|
||||
- [Tables](usage/tables.md)
|
||||
- [Tab Stops](usage/tab-stops.md)
|
||||
- [Tabs](usage/tabs.md)
|
||||
- [Table of Contents](usage/table-of-contents.md)
|
||||
- [Page Numbers](usage/page-numbers.md)
|
||||
- [Change Tracking](usage/change-tracking.md)
|
||||
- [Math](usage/math.md)
|
||||
- [Text Frames](usage/text-frames.md)
|
||||
- [Comments](usage/comments.md)
|
||||
- [Footnotes](usage/footnotes.md)
|
||||
- [Fields](usage/fields.md)
|
||||
- Styling
|
||||
_ [Styling with JS](usage/styling-with-js.md)
|
||||
_ [Styling with XML](usage/styling-with-xml.md)
|
||||
- [Styling with JS](usage/styling-with-js.md)
|
||||
- [Styling with XML](usage/styling-with-xml.md)
|
||||
|
||||
- Exporting
|
||||
|
||||
- [Packers](usage/packers.md)
|
||||
|
||||
- Modifying Existing Documents
|
||||
|
||||
- [Patcher](usage/patcher.md)
|
||||
|
||||
- Utility
|
||||
|
||||
- [Convenience functions](usage/convenience-functions.md)
|
||||
|
@ -1,11 +1,21 @@
|
||||
# Contribution Guidelines
|
||||
|
||||
- Include documentation reference(s) at the top of each file:
|
||||
- Include documentation reference(s) at the top of each file as a comment. For example:
|
||||
|
||||
```ts
|
||||
// http://officeopenxml.com/WPdocument.php
|
||||
```
|
||||
|
||||
<!-- cSpell:ignore datypic -->
|
||||
It can be a link to `officeopenxml.com` or `datypic.com` etc.
|
||||
It could also be a reference to the official ECMA-376 standard: https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
|
||||
|
||||
- Include a portion of the schema as a comment for cross reference. For example:
|
||||
|
||||
```ts
|
||||
// <xsd:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="1"/>
|
||||
```
|
||||
|
||||
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
||||
|
||||
- Follow the `ESLint` rules
|
||||
|
@ -22,20 +22,19 @@ const doc = new docx.Document({
|
||||
|
||||
### Full list of options:
|
||||
|
||||
|
||||
* creator
|
||||
* description
|
||||
* title
|
||||
* subject
|
||||
* keywords
|
||||
* lastModifiedBy
|
||||
* revision
|
||||
* externalStyles
|
||||
* styles
|
||||
* numbering
|
||||
* footnotes
|
||||
* hyperlinks
|
||||
* background
|
||||
- creator
|
||||
- description
|
||||
- title
|
||||
- subject
|
||||
- keywords
|
||||
- lastModifiedBy
|
||||
- revision
|
||||
- externalStyles
|
||||
- styles
|
||||
- numbering
|
||||
- footnotes
|
||||
- hyperlinks
|
||||
- background
|
||||
|
||||
### Change background color of Document
|
||||
|
||||
@ -55,3 +54,87 @@ You can mix and match whatever properties you want, or provide no properties.
|
||||
|
||||
Various parts of the API require positioning arguments. The units are "20ths of a point" from the [OOXML](http://officeopenxml.com/index.php) specification.
|
||||
See [Lars Corneliussen's blog post](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/) for more information and how to convert units.
|
||||
|
||||
## Compatibility
|
||||
|
||||
Compatibility Settings are optional settings used to preserve visual fidelity of documents created in earlier word processing applications. Some of these settings provide ability for specific behaviors, described in detail below; and others simply instruct applications to mimic the behavior of an existing word processing application.
|
||||
|
||||
```ts
|
||||
const doc = new docx.Document({
|
||||
compatibility: {
|
||||
version: 15,
|
||||
doNotExpandShiftReturn: true,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Compatibility Options
|
||||
|
||||
| Property | Type | Notes | Possible Values |
|
||||
| ----------------------------------- | --------- | -------- | ---------------------------- |
|
||||
| version | `number` | Optional | `15`, `16`, `17` |
|
||||
| useSingleBorderforContiguousCells | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| wordPerfectJustification | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| noTabStopForHangingIndent | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| noLeading | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| spaceForUnderline | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| noColumnBalance | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| balanceSingleByteDoubleByteWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| noExtraLineSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotLeaveBackslashAlone | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| underlineTrailingSpaces | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotExpandShiftReturn | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| spacingInWholePoints | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| lineWrapLikeWord6 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| printBodyTextBeforeHeader | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| printColorsBlack | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| spaceWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| showBreaksInFrames | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| subFontBySize | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| suppressBottomSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| suppressTopSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| suppressSpacingAtTopOfPage | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| suppressTopSpacingWP | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| suppressSpBfAfterPgBrk | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| swapBordersFacingPages | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| convertMailMergeEsc | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| truncateFontHeightsLikeWP6 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| macWordSmallCaps | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| usePrinterMetrics | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotSuppressParagraphBorders | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| wrapTrailSpaces | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| footnoteLayoutLikeWW8 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| shapeLayoutLikeWW8 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| alignTablesRowByRow | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| forgetLastTabAlignment | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| adjustLineHeightInTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| autoSpaceLikeWord95 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| noSpaceRaiseLower | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotUseHTMLParagraphAutoSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| layoutRawTableWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| layoutTableRowsApart | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useWord97LineBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotBreakWrappedTables | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotSnapToGridInCell | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| selectFieldWithFirstOrLastCharacter | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| applyBreakingRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotWrapTextWithPunctuation | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotUseEastAsianBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useWord2002TableStyleRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| growAutofit | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useFELayout | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useNormalStyleForList | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotUseIndentAsNumberingTabStop | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useAlternateEastAsianLineBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| allowSpaceOfSameStyleInTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotSuppressIndentation | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotAutofitConstrainedTables | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| autofitToFirstFixedWidthCell | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| underlineTabInNumberingList | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| displayHangulFixedWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| splitPgBreakAndParaMark | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotVerticallyAlignCellWithSp | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| doNotBreakConstrainedForcedTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| ignoreVerticalAlignmentInTextboxes | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| useAnsiKerningPairs | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
| cachedColumnBalance | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||
|
42
docs/usage/footnotes.md
Normal file
42
docs/usage/footnotes.md
Normal file
@ -0,0 +1,42 @@
|
||||
# Footnotes
|
||||
|
||||
!> Footnotes requires an understanding of [Sections](usage/sections.md).
|
||||
|
||||
Use footnotes and endnotes to explain, comment on, or provide references to something in a document. Usually, footnotes appear at the bottom of the page.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const doc = new Document({
|
||||
footnotes: {
|
||||
1: { children: [new Paragraph("Foo"), new Paragraph("Bar")] },
|
||||
2: { children: [new Paragraph("Test")] },
|
||||
},
|
||||
sections: [
|
||||
{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
children: ["Hello"],
|
||||
}),
|
||||
new FootnoteReferenceRun(1),
|
||||
new TextRun({
|
||||
children: [" World!"],
|
||||
}),
|
||||
new FootnoteReferenceRun(2),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Footnotes requires an entry into the `footnotes` array in the `Document` constructor, and a `FootnoteReferenceRun` in the `Paragraph` constructor.
|
||||
|
||||
`footnotes` is an object of number to `Footnote` objects. The number is the reference number, and the `Footnote` object is the content of the footnote. The `Footnote` object has a `children` property, which is an array of `Paragraph` objects.
|
||||
|
||||
`FootnoteReferenceRun` is a `Run` object, which are added to `Paragraph`s. It takes a number as a parameter, which is the reference number of the footnote.
|
@ -252,13 +252,36 @@ const image = new ImageRun({
|
||||
});
|
||||
```
|
||||
|
||||
## Alternative Text
|
||||
|
||||
Specifies common non-visual DrawingML properties. A name, title and description for a picture can be specified.
|
||||
|
||||
```ts
|
||||
const image = new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||
altText: {
|
||||
title: "This is an ultimate title",
|
||||
description: "This is an ultimate image",
|
||||
name: "My Ultimate Image",
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Property | Type | Notes | Possible Values |
|
||||
| ----------- | -------- | -------- | ------------------------------------ |
|
||||
| name | `string` | Required | `Specimen A` |
|
||||
| title | `string` | Required | `My awesome title of my image` |
|
||||
| description | `string` | Required | `My awesome description of my image` |
|
||||
|
||||
## Examples
|
||||
|
||||
### Add image to the document
|
||||
|
||||
Importing Images from file system path
|
||||
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/5-images.ts ':include')
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/5-images.ts ":include")
|
||||
|
||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_
|
||||
|
||||
@ -266,7 +289,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_
|
||||
|
||||
Example showing how to add image to headers and footers
|
||||
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ':include')
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ":include")
|
||||
|
||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_
|
||||
|
||||
@ -274,6 +297,6 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-an
|
||||
|
||||
Example showing how to float images on top of text and optimally give a `margin`
|
||||
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/38-text-wrapping.ts ':include')
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/38-text-wrapping.ts ":include")
|
||||
|
||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_
|
||||
|
@ -60,29 +60,29 @@ const doc = new Document({
|
||||
|
||||
This is the list of options for a paragraph. A detailed explanation is below:
|
||||
|
||||
| Property | Type | Mandatory? | Possible Values |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- |
|
||||
| [text](#text) | `string` | Optional | |
|
||||
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
||||
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
||||
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||
| alignment | `AlignmentType` | Optional | |
|
||||
| heading | `HeadingLevel` | Optional | |
|
||||
| bidirectional | `boolean` | Optional | |
|
||||
| thematicBreak | `boolean` | Optional | |
|
||||
| pageBreakBefore | `boolean` | Optional | |
|
||||
| contextualSpacing | `boolean` | Optional | |
|
||||
| indent | `IIndentAttributesProperties` | Optional | |
|
||||
| keepLines | `boolean` | Optional | |
|
||||
| keepNext | `boolean` | Optional | |
|
||||
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
||||
| style | `string` | Optional | |
|
||||
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
||||
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||
| [widowControl](#widow-control) | `boolean` | Optional | |
|
||||
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
||||
| Property | Type | Mandatory? | Possible Values |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [text](#text) | `string` | Optional | |
|
||||
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
||||
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
||||
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||
| alignment | `AlignmentType` | Optional | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
|
||||
| heading | `HeadingLevel` | Optional | |
|
||||
| bidirectional | `boolean` | Optional | |
|
||||
| thematicBreak | `boolean` | Optional | |
|
||||
| pageBreakBefore | `boolean` | Optional | |
|
||||
| contextualSpacing | `boolean` | Optional | |
|
||||
| indent | `IIndentAttributesProperties` | Optional | |
|
||||
| keepLines | `boolean` | Optional | |
|
||||
| keepNext | `boolean` | Optional | |
|
||||
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
||||
| style | `string` | Optional | |
|
||||
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
||||
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||
| [widowControl](#widow-control) | `boolean` | Optional | |
|
||||
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
||||
|
||||
## Text
|
||||
|
||||
@ -180,12 +180,14 @@ Adding spacing between paragraphs
|
||||
|
||||
### ISpacingProperties
|
||||
|
||||
| Property | Type | Notes | Possible Values |
|
||||
| -------- | -------------- | -------- | ----------------------------- |
|
||||
| after | `number` | Optional | |
|
||||
| before | `number` | Optional | |
|
||||
| line | `number` | Optional | |
|
||||
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `AUTO` |
|
||||
| Property | Type | Notes | Possible Values |
|
||||
| -------- | -------------- | -------- | -------------------------------------- |
|
||||
| after | `number` | Optional | |
|
||||
| before | `number` | Optional | |
|
||||
| line | `number` | Optional | |
|
||||
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `EXACT`, `AUTO` |
|
||||
|
||||
Note: The `lineRule` property has different values depending on the version of Word you are using. The `EXACTLY` value is only available in Word 2016 and above. Use `EXACT` for greater support, including LibreOffice etc. Read this issue for more information: https://github.com/dolanmiu/docx/issues/1773.
|
||||
|
||||
**Example:**
|
||||
|
||||
|
94
docs/usage/patcher.md
Normal file
94
docs/usage/patcher.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Patcher
|
||||
|
||||
The patcher allows you to modify existing documents, and add new content to them.
|
||||
|
||||
!> The Patcher requires an understanding of [Paragraphs](usage/paragraph.md).
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import * as fs from "fs";
|
||||
import { patchDocument } from "docx";
|
||||
|
||||
patchDocument(fs.readFileSync("My Document.docx"), {
|
||||
patches: {
|
||||
// Patches here
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Patches
|
||||
|
||||
The patcher takes in a `patches` object, which is a map of `string` to `Patch`:
|
||||
|
||||
```ts
|
||||
interface Patch {
|
||||
type: PatchType;
|
||||
children: FileChild[] | ParagraphChild[];
|
||||
}
|
||||
```
|
||||
|
||||
| Property | Type | Notes | Possible Values |
|
||||
| -------- | --------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| type | `PatchType` | Required | `DOCUMENT`, `PARAGRAPH` |
|
||||
| children | `FileChild[] or ParagraphChild[]` | Required | The contents to replace with. A `FileChild` is a `Paragraph` or `Table`, whereas a `ParagraphChild` is typical `Paragraph` children. |
|
||||
|
||||
### How to patch existing document
|
||||
|
||||
1. Open your existing word document in your favorite Word Processor
|
||||
2. Write tags in the document where you want to patch in a mustache style notation. For example, `{{my_patch}}` and `{{my_second_patch}}`.
|
||||
3. Run the patcher with the patches as a key value pair.
|
||||
|
||||
## Example
|
||||
|
||||
### Word Document
|
||||
|
||||

|
||||
|
||||
### Patcher
|
||||
|
||||
?> Notice how there is no handlebar notation in the key.
|
||||
|
||||
The patch can be as simple as a string, or as complex as a table. Images, hyperlinks, and other complex elements within the `docx` library are also supported.
|
||||
|
||||
```ts
|
||||
patchDocument(fs.readFileSync("My Document.docx"), {
|
||||
patches: {
|
||||
my_patch: {
|
||||
type: PatchType.PARAGRAPH,
|
||||
children: [new TextRun("Sir. "), new TextRun("John Doe"), new TextRun("(The Conqueror)")],
|
||||
},
|
||||
my_second_patch: {
|
||||
type: PatchType.DOCUMENT,
|
||||
children: [
|
||||
new Paragraph("Lorem ipsum paragraph"),
|
||||
new Paragraph("Another paragraph"),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("This is a "),
|
||||
new ExternalHyperlink({
|
||||
children: [
|
||||
new TextRun({
|
||||
text: "Google Link",
|
||||
}),
|
||||
],
|
||||
link: "https://www.google.co.uk",
|
||||
}),
|
||||
new ImageRun({ data: fs.readFileSync("./demo/images/dog.png"), transformation: { width: 100, height: 100 } }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Demo
|
||||
|
||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/85-template-document.ts_
|
||||
|
||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/85-template-document.ts ":include :type=code typescript")
|
@ -1,121 +0,0 @@
|
||||
# Tab Stops
|
||||
|
||||
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
||||
|
||||
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
||||
|
||||

|
||||
|
||||
Simply declare the tab stops on the paragraph, as shown below. Use the tab character `\t` to indicate the tab position within the `text` property of a `TextRun`. Adding multiple `tabStops` will mean you can add additional `\t` characters until the desired `tabStop` is selected. Example is shown below.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun({ text: "Hey everyone", bold: true}), new TextRun("\t11th November 1999")],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun("\t\tSecond tab stop here I come!")],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
{
|
||||
type: TabStopType.LEFT,
|
||||
position: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
The above shows the use of two tab stops, and how to select/use it.
|
||||
|
||||
You can add multiple tab stops of the same `type` too.
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun("Multiple \ttab \tstops!")],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## Left Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.LEFT,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the left side.
|
||||
|
||||
## Center Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.CENTER,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the center.
|
||||
|
||||
## Right Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the left side.
|
||||
|
||||
## Max Right Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
184
docs/usage/tabs.md
Normal file
184
docs/usage/tabs.md
Normal file
@ -0,0 +1,184 @@
|
||||
# Tabs and Tab Stops
|
||||
|
||||
## Tab Stops
|
||||
|
||||
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
||||
|
||||
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
||||
|
||||

|
||||
|
||||
Simply declare the tab stops on the paragraph, as shown below. Use the tab character `\t` or add the `new Tab()` child to indicate the tab position within the `text` property of a `TextRun`. Adding multiple `tabStops` will mean you can add additional `\t` characters until the desired `tabStop` is selected. Example is shown below.
|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [
|
||||
new TextRun({ text: "Hey everyone", bold: true }),
|
||||
new TextRun("\t11th November 1999"),
|
||||
new TextRun({
|
||||
children: [new Tab(), "11th November 1999"],
|
||||
}),
|
||||
],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun("\t\tSecond tab stop here I come!")],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
{
|
||||
type: TabStopType.LEFT,
|
||||
position: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
The above shows the use of two tab stops, and how to select/use it.
|
||||
|
||||
You can add multiple tab stops of the same `type` too.
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
children: [new TextRun("Multiple \ttab \tstops!")],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const paragraph = new Paragraph({
|
||||
children: [
|
||||
new TextRun({
|
||||
children: ["Multiple ", new Tab(), "tab ", new Tab(), "stops!"],
|
||||
}),
|
||||
],
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
### Left Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.LEFT,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the left side.
|
||||
|
||||
### Center Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.CENTER,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the center.
|
||||
|
||||
### Right Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: 2268,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
2268 is the distance from the left side.
|
||||
|
||||
### Max Right Tab Stop
|
||||
|
||||
```ts
|
||||
const paragraph = new Paragraph({
|
||||
tabStops: [
|
||||
{
|
||||
type: TabStopType.RIGHT,
|
||||
position: TabStopPosition.MAX,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
||||
|
||||
## Positional Tabs
|
||||
|
||||
> Positional tab allow you to create a tab stop that is relative to the margin, or the page. This is useful if you want to create a table of contents, or a table of figures.
|
||||
|
||||
They are easier to use than the normal tab stops, as you can use the `PositionalTab` class to create a tab stop, and then add the text to the `TextRun` children. Useful for most cases.
|
||||
|
||||

|
||||
|
||||
### Example
|
||||
|
||||
```ts
|
||||
new Paragraph({
|
||||
children: [
|
||||
new TextRun("Full name"),
|
||||
new TextRun({
|
||||
children: [
|
||||
new PositionalTab({
|
||||
alignment: PositionalTabAlignment.RIGHT,
|
||||
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||
leader: PositionalTabLeader.DOT,
|
||||
}),
|
||||
"John Doe",
|
||||
],
|
||||
bold: true,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Type | Description | Possible Values |
|
||||
| ---------- | ------------------------- | ------------------------------------- | ------------------------------------------------------------- |
|
||||
| alignment | `PositionalTabAlignment` | The alignment of the tab stop | `LEFT`, `RIGHT`, `CENTER` |
|
||||
| relativeTo | `PositionalTabRelativeTo` | The relative position of the tab stop | `MARGIN`, `INDENT` |
|
||||
| leader | `PositionalTabLeader` | The leader of the tab stop | `NONE`, `DOT`, `HYPHEN`, `UNDERSCORE`, `MIDDLE_DOT`, `EQUALS` |
|
@ -151,6 +151,28 @@ const text = new TextRun({
|
||||
});
|
||||
```
|
||||
|
||||
### Vanish and SpecVanish
|
||||
|
||||
You may want to hide your text in your document.
|
||||
|
||||
`Vanish` should affect the normal display of text, but an application may have settings to force hidden text to be displayed.
|
||||
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "This text will be hidden",
|
||||
vanish: true,
|
||||
});
|
||||
```
|
||||
|
||||
`SpecVanish` was typically used to ensure that a paragraph style can be applied to a part of a paragraph, and still appear as in the Table of Contents (which in previous word processors would ignore the use of the style if it were being used as a character style).
|
||||
|
||||
```ts
|
||||
const text = new TextRun({
|
||||
text: "This text will be hidden forever.",
|
||||
specVanish: true,
|
||||
});
|
||||
```
|
||||
|
||||
## Break
|
||||
|
||||
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
||||
|
5184
package-lock.json
generated
5184
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "7.6.0",
|
||||
"version": "8.0.1",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
@ -28,9 +28,7 @@
|
||||
"lint"
|
||||
],
|
||||
"files": [
|
||||
"src",
|
||||
"build",
|
||||
"template"
|
||||
"build"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -52,7 +50,7 @@
|
||||
"dependencies": {
|
||||
"@types/node": "^18.0.0",
|
||||
"jszip": "^3.1.5",
|
||||
"nanoid": "^3.1.20",
|
||||
"nanoid": "^3.3.4",
|
||||
"xml": "^1.0.1",
|
||||
"xml-js": "^1.6.8"
|
||||
},
|
||||
@ -61,31 +59,32 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/dolanmiu/docx/issues"
|
||||
},
|
||||
"homepage": "https://github.com/dolanmiu/docx#readme",
|
||||
"homepage": "https://docx.js.org",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.15",
|
||||
"@types/glob": "^8.0.0",
|
||||
"@types/chai-as-promised": "^7.1.5",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/prompt": "^1.1.1",
|
||||
"@types/request-promise": "^4.1.42",
|
||||
"@types/shelljs": "^0.8.9",
|
||||
"@types/shelljs": "^0.8.11",
|
||||
"@types/sinon": "^10.0.0",
|
||||
"@types/unzipper": "^0.10.4",
|
||||
"@types/webpack": "^5.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||
"@typescript-eslint/parser": "^5.36.1",
|
||||
"buffer": "^6.0.3",
|
||||
"chai": "^3.5.0",
|
||||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"cspell": "^6.2.2",
|
||||
"docsify-cli": "^4.3.0",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-plugin-functional": "^4.3.1",
|
||||
"eslint-plugin-functional": "^5.0.1",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-jsdoc": "^39.3.6",
|
||||
"eslint-plugin-jsdoc": "^40.0.0",
|
||||
"eslint-plugin-no-null": "^1.0.2",
|
||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||
"eslint-plugin-unicorn": "^44.0.0",
|
||||
"glob": "^8.0.1",
|
||||
"eslint-plugin-unicorn": "^46.0.0",
|
||||
"glob": "^9.3.0",
|
||||
"jszip": "^3.1.5",
|
||||
"mocha": "^10.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
@ -96,19 +95,19 @@
|
||||
"replace-in-file": "^6.2.0",
|
||||
"request": "^2.88.0",
|
||||
"request-promise": "^4.2.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"rimraf": "^4.0.4",
|
||||
"shelljs": "^0.8.4",
|
||||
"sinon": "^14.0.0",
|
||||
"sinon": "^15.0.0",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"ts-loader": "^9.0.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"tsconfig-paths": "^4.0.0",
|
||||
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
||||
"typedoc": "^0.23.2",
|
||||
"typescript": "4.8.4",
|
||||
"typescript": "5.0.2",
|
||||
"unzipper": "^0.10.11",
|
||||
"webpack": "^5.28.0",
|
||||
"webpack-cli": "^4.6.0"
|
||||
"webpack-cli": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
|
@ -9,7 +9,7 @@ for (const file of files) {
|
||||
from: /"@[a-z/-]*"/gi,
|
||||
to: (match) => {
|
||||
const matchSlug = match.replace(/['"]+/g, "").replace(/[@]+/g, "").trim();
|
||||
const levelCount = file.split("/").length - 2;
|
||||
const levelCount = file.split(/[\/\\]/).length - 2;
|
||||
const backLevels = Array(levelCount).fill("../").join("");
|
||||
|
||||
return `"${backLevels}${matchSlug}"`;
|
||||
|
@ -2,7 +2,7 @@ import { BaseXmlComponent, IContext, IXmlableObject } from "@file/xml-components
|
||||
|
||||
export class Formatter {
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
public format(input: BaseXmlComponent, context: IContext = {} as IContext): IXmlableObject {
|
||||
public format(input: BaseXmlComponent, context: IContext = { stack: [] } as unknown as IContext): IXmlableObject {
|
||||
const output = input.prepForXml(context);
|
||||
|
||||
if (output) {
|
||||
|
@ -59,9 +59,8 @@ export class Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
for (const data of file.Media.Array) {
|
||||
const mediaData = data.stream;
|
||||
zip.file(`word/media/${data.fileName}`, mediaData);
|
||||
for (const { stream, fileName } of file.Media.Array) {
|
||||
zip.file(`word/media/${fileName}`, stream);
|
||||
}
|
||||
|
||||
return zip;
|
||||
@ -74,6 +73,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Document.View, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -100,6 +100,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Document.Relationships, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -125,6 +126,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Styles, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -144,6 +146,7 @@ export class Compiler {
|
||||
this.formatter.format(file.CoreProperties, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -160,6 +163,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Numbering, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -176,6 +180,7 @@ export class Compiler {
|
||||
this.formatter.format(file.FileRelationships, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -191,6 +196,7 @@ export class Compiler {
|
||||
this.formatter.format(headerWrapper.View, {
|
||||
viewWrapper: headerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -214,6 +220,7 @@ export class Compiler {
|
||||
this.formatter.format(headerWrapper.Relationships, {
|
||||
viewWrapper: headerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -230,6 +237,7 @@ export class Compiler {
|
||||
this.formatter.format(footerWrapper.View, {
|
||||
viewWrapper: footerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -253,6 +261,7 @@ export class Compiler {
|
||||
this.formatter.format(footerWrapper.Relationships, {
|
||||
viewWrapper: footerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -269,6 +278,7 @@ export class Compiler {
|
||||
this.formatter.format(headerWrapper.View, {
|
||||
viewWrapper: headerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -293,6 +303,7 @@ export class Compiler {
|
||||
this.formatter.format(footerWrapper.View, {
|
||||
viewWrapper: footerWrapper,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -317,6 +328,7 @@ export class Compiler {
|
||||
this.formatter.format(file.ContentTypes, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -332,6 +344,7 @@ export class Compiler {
|
||||
this.formatter.format(file.CustomProperties, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -348,6 +361,7 @@ export class Compiler {
|
||||
this.formatter.format(file.AppProperties, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -363,7 +377,8 @@ export class Compiler {
|
||||
data: xml(
|
||||
this.formatter.format(file.FootNotes.View, {
|
||||
viewWrapper: file.FootNotes,
|
||||
file: file,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -378,7 +393,8 @@ export class Compiler {
|
||||
data: xml(
|
||||
this.formatter.format(file.FootNotes.Relationships, {
|
||||
viewWrapper: file.FootNotes,
|
||||
file: file,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -394,6 +410,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Settings, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
@ -410,6 +427,7 @@ export class Compiler {
|
||||
this.formatter.format(file.Comments, {
|
||||
viewWrapper: file.Document,
|
||||
file,
|
||||
stack: [],
|
||||
}),
|
||||
{
|
||||
indent: prettify,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { ICommentsOptions } from "@file/paragraph/run/comment-run";
|
||||
import { ICompatibilityOptions } from "@file/settings/compatibility";
|
||||
import { StringContainer, XmlComponent } from "@file/xml-components";
|
||||
import { dateTimeValue } from "@util/values";
|
||||
|
||||
@ -35,6 +36,7 @@ export interface IPropertiesOptions {
|
||||
readonly updateFields?: boolean;
|
||||
};
|
||||
readonly compatabilityModeVersion?: number;
|
||||
readonly compatibility?: ICompatibilityOptions;
|
||||
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||
}
|
||||
|
@ -1,25 +1,23 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
export interface IColumnAttributes {
|
||||
readonly width: number | string;
|
||||
readonly space?: number | string;
|
||||
}
|
||||
// <xsd:complexType name="CT_Column">
|
||||
// <xsd:attribute name="w" type="s:ST_TwipsMeasure" use="optional" />
|
||||
// <xsd:attribute name="space" type="s:ST_TwipsMeasure" use="optional" default="0" />
|
||||
// </xsd:complexType>
|
||||
|
||||
export class ColumnAttributes extends XmlAttributeComponent<IColumnAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
width: "w:w",
|
||||
space: "w:space",
|
||||
};
|
||||
}
|
||||
type IColumnAttributes = {
|
||||
readonly width: number | PositiveUniversalMeasure;
|
||||
readonly space?: number | PositiveUniversalMeasure;
|
||||
};
|
||||
|
||||
export class Column extends XmlComponent {
|
||||
public constructor({ width, space }: IColumnAttributes) {
|
||||
super("w:col");
|
||||
this.root.push(
|
||||
new ColumnAttributes({
|
||||
width: twipsMeasureValue(width),
|
||||
space: space === undefined ? undefined : twipsMeasureValue(space),
|
||||
new NextAttributeComponent<IColumnAttributes>({
|
||||
width: { key: "w:w", value: twipsMeasureValue(width) },
|
||||
space: { key: "w:space", value: space === undefined ? undefined : twipsMeasureValue(space) },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber, twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
import { Column } from "./column";
|
||||
|
||||
@ -12,32 +12,23 @@ import { Column } from "./column";
|
||||
// <xsd:attribute name="num" type="ST_DecimalNumber" use="optional" default="1"/>
|
||||
// <xsd:attribute name="sep" type="s:ST_OnOff" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
export interface IColumnsAttributes {
|
||||
readonly space?: number | string;
|
||||
export type IColumnsAttributes = {
|
||||
readonly space?: number | PositiveUniversalMeasure;
|
||||
readonly count?: number;
|
||||
readonly separate?: boolean;
|
||||
readonly equalWidth?: boolean;
|
||||
readonly children?: readonly Column[];
|
||||
}
|
||||
|
||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
space: "w:space",
|
||||
count: "w:num",
|
||||
separate: "w:sep",
|
||||
equalWidth: "w:equalWidth",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export class Columns extends XmlComponent {
|
||||
public constructor({ space, count, separate, equalWidth, children }: IColumnsAttributes) {
|
||||
super("w:cols");
|
||||
this.root.push(
|
||||
new ColumnsAttributes({
|
||||
space: space === undefined ? undefined : twipsMeasureValue(space),
|
||||
count: count === undefined ? undefined : decimalNumber(count),
|
||||
separate,
|
||||
equalWidth,
|
||||
new NextAttributeComponent<Omit<IColumnsAttributes, "children">>({
|
||||
space: { key: "w:space", value: space === undefined ? undefined : twipsMeasureValue(space) },
|
||||
count: { key: "w:num", value: count === undefined ? undefined : decimalNumber(count) },
|
||||
separate: { key: "w:sep", value: separate },
|
||||
equalWidth: { key: "w:equalWidth", value: equalWidth },
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber, twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
// <xsd:simpleType name="ST_LineNumberRestart">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
@ -26,27 +26,23 @@ export interface ILineNumberAttributes {
|
||||
readonly countBy?: number;
|
||||
readonly start?: number;
|
||||
readonly restart?: LineNumberRestartFormat;
|
||||
readonly distance?: number | string;
|
||||
}
|
||||
|
||||
export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
countBy: "w:countBy",
|
||||
start: "w:start",
|
||||
restart: "w:restart",
|
||||
distance: "w:distance",
|
||||
};
|
||||
readonly distance?: number | PositiveUniversalMeasure;
|
||||
}
|
||||
|
||||
export class LineNumberType extends XmlComponent {
|
||||
public constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
||||
super("w:lnNumType");
|
||||
this.root.push(
|
||||
new LineNumberAttributes({
|
||||
countBy: countBy === undefined ? undefined : decimalNumber(countBy),
|
||||
start: start === undefined ? undefined : decimalNumber(start),
|
||||
restart,
|
||||
distance: distance === undefined ? undefined : twipsMeasureValue(distance),
|
||||
new NextAttributeComponent<{
|
||||
readonly countBy?: number;
|
||||
readonly start?: number;
|
||||
readonly restart?: LineNumberRestartFormat;
|
||||
readonly distance?: number | PositiveUniversalMeasure;
|
||||
}>({
|
||||
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||
restart: { key: "w:restart", value: restart },
|
||||
distance: { key: "w:distance", value: distance === undefined ? undefined : twipsMeasureValue(distance) },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
||||
super("w:pgBorders");
|
||||
|
||||
if (!options) {
|
||||
return;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (options.pageBorders) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||
|
||||
// <xsd:complexType name="CT_PageMar">
|
||||
// <xsd:attribute name="top" type="ST_SignedTwipsMeasure" use="required"/>
|
||||
@ -10,48 +10,36 @@ import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
||||
// <xsd:attribute name="footer" type="s:ST_TwipsMeasure" use="required"/>
|
||||
// <xsd:attribute name="gutter" type="s:ST_TwipsMeasure" use="required"/>
|
||||
// </xsd:complexType>
|
||||
export interface IPageMarginAttributes {
|
||||
readonly top?: number | string;
|
||||
readonly right?: number | string;
|
||||
readonly bottom?: number | string;
|
||||
readonly left?: number | string;
|
||||
readonly header?: number | string;
|
||||
readonly footer?: number | string;
|
||||
readonly gutter?: number | string;
|
||||
}
|
||||
|
||||
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
top: "w:top",
|
||||
right: "w:right",
|
||||
bottom: "w:bottom",
|
||||
left: "w:left",
|
||||
header: "w:header",
|
||||
footer: "w:footer",
|
||||
gutter: "w:gutter",
|
||||
};
|
||||
}
|
||||
export type IPageMarginAttributes = {
|
||||
readonly top?: number | UniversalMeasure;
|
||||
readonly right?: number | PositiveUniversalMeasure;
|
||||
readonly bottom?: number | UniversalMeasure;
|
||||
readonly left?: number | PositiveUniversalMeasure;
|
||||
readonly header?: number | PositiveUniversalMeasure;
|
||||
readonly footer?: number | PositiveUniversalMeasure;
|
||||
readonly gutter?: number | PositiveUniversalMeasure;
|
||||
};
|
||||
|
||||
export class PageMargin extends XmlComponent {
|
||||
public constructor(
|
||||
top: number | string,
|
||||
right: number | string,
|
||||
bottom: number | string,
|
||||
left: number | string,
|
||||
header: number | string,
|
||||
footer: number | string,
|
||||
gutter: number | string,
|
||||
top: number | UniversalMeasure,
|
||||
right: number | PositiveUniversalMeasure,
|
||||
bottom: number | UniversalMeasure,
|
||||
left: number | PositiveUniversalMeasure,
|
||||
header: number | PositiveUniversalMeasure,
|
||||
footer: number | PositiveUniversalMeasure,
|
||||
gutter: number | PositiveUniversalMeasure,
|
||||
) {
|
||||
super("w:pgMar");
|
||||
this.root.push(
|
||||
new PageMarginAttributes({
|
||||
top: signedTwipsMeasureValue(top),
|
||||
right: twipsMeasureValue(right),
|
||||
bottom: signedTwipsMeasureValue(bottom),
|
||||
left: twipsMeasureValue(left),
|
||||
header: twipsMeasureValue(header),
|
||||
footer: twipsMeasureValue(footer),
|
||||
gutter: twipsMeasureValue(gutter),
|
||||
new NextAttributeComponent<IPageMarginAttributes>({
|
||||
top: { key: "w:top", value: signedTwipsMeasureValue(top) },
|
||||
right: { key: "w:right", value: twipsMeasureValue(right) },
|
||||
bottom: { key: "w:bottom", value: signedTwipsMeasureValue(bottom) },
|
||||
left: { key: "w:left", value: twipsMeasureValue(left) },
|
||||
header: { key: "w:header", value: twipsMeasureValue(header) },
|
||||
footer: { key: "w:footer", value: twipsMeasureValue(footer) },
|
||||
gutter: { key: "w:gutter", value: twipsMeasureValue(gutter) },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
// <xsd:simpleType name="ST_PageOrientation">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
@ -18,22 +18,14 @@ export enum PageOrientation {
|
||||
// <xsd:attribute name="orient" type="ST_PageOrientation" use="optional"/>
|
||||
// <xsd:attribute name="code" type="ST_DecimalNumber" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
export interface IPageSizeAttributes {
|
||||
readonly width?: number | string;
|
||||
readonly height?: number | string;
|
||||
export type IPageSizeAttributes = {
|
||||
readonly width?: number | PositiveUniversalMeasure;
|
||||
readonly height?: number | PositiveUniversalMeasure;
|
||||
readonly orientation?: PageOrientation;
|
||||
}
|
||||
|
||||
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
width: "w:w",
|
||||
height: "w:h",
|
||||
orientation: "w:orient",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export class PageSize extends XmlComponent {
|
||||
public constructor(width: number | string, height: number | string, orientation: PageOrientation) {
|
||||
public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) {
|
||||
super("w:pgSz");
|
||||
|
||||
const flip = orientation === PageOrientation.LANDSCAPE;
|
||||
@ -42,10 +34,10 @@ export class PageSize extends XmlComponent {
|
||||
const heightTwips = twipsMeasureValue(height);
|
||||
|
||||
this.root.push(
|
||||
new PageSizeAttributes({
|
||||
width: flip ? heightTwips : widthTwips,
|
||||
height: flip ? widthTwips : heightTwips,
|
||||
orientation: orientation,
|
||||
new NextAttributeComponent<IPageSizeAttributes>({
|
||||
width: { key: "w:w", value: flip ? heightTwips : widthTwips },
|
||||
height: { key: "w:h", value: flip ? widthTwips : heightTwips },
|
||||
orientation: { key: "w:orient", value: orientation },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import { FooterWrapper } from "@file/footer-wrapper";
|
||||
import { HeaderWrapper } from "@file/header-wrapper";
|
||||
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
|
||||
import { OnOffElement, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, UniversalMeasure } from "@util/values";
|
||||
|
||||
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
||||
|
||||
import { Columns, IColumnsAttributes } from "./properties/columns";
|
||||
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
||||
import { ILineNumberAttributes, LineNumberType } from "./properties/line-number";
|
||||
@ -76,10 +76,10 @@ export interface ISectionPropertiesOptions {
|
||||
// </xsd:group>
|
||||
|
||||
export const sectionMarginDefaults = {
|
||||
TOP: "1in",
|
||||
RIGHT: "1in",
|
||||
BOTTOM: "1in",
|
||||
LEFT: "1in",
|
||||
TOP: "1in" as UniversalMeasure,
|
||||
RIGHT: "1in" as PositiveUniversalMeasure,
|
||||
BOTTOM: "1in" as UniversalMeasure,
|
||||
LEFT: "1in" as PositiveUniversalMeasure,
|
||||
HEADER: 708,
|
||||
FOOTER: 708,
|
||||
GUTTER: 0,
|
||||
|
@ -8,7 +8,7 @@ import { DocumentAttributes } from "./document-attributes";
|
||||
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
|
||||
|
||||
export interface IDocumentOptions {
|
||||
readonly background: IDocumentBackgroundOptions;
|
||||
readonly background?: IDocumentBackgroundOptions;
|
||||
}
|
||||
|
||||
// <xsd:element name="document" type="CT_Document"/>
|
||||
@ -73,7 +73,9 @@ export class Document extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
this.body = new Body();
|
||||
this.root.push(new DocumentBackground(options.background));
|
||||
if (options.background) {
|
||||
this.root.push(new DocumentBackground(options.background));
|
||||
}
|
||||
this.root.push(this.body);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { assert } from "chai";
|
||||
import { assert, expect } from "chai";
|
||||
import { SinonStub, stub } from "sinon";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
import { Utility } from "tests/utility";
|
||||
|
||||
@ -36,6 +40,14 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||
);
|
||||
|
||||
describe("Anchor", () => {
|
||||
before(() => {
|
||||
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
|
||||
});
|
||||
|
||||
let anchor: Anchor;
|
||||
|
||||
describe("#constructor()", () => {
|
||||
@ -362,5 +374,236 @@ describe("Anchor", () => {
|
||||
relativeHeight: 120,
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Drawing with doc properties", () => {
|
||||
anchor = createAnchor({
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
zIndex: 120,
|
||||
},
|
||||
docProperties: {
|
||||
name: "test",
|
||||
description: "test",
|
||||
title: "test",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(anchor);
|
||||
expect(tree).to.deep.equal({
|
||||
"wp:anchor": [
|
||||
{
|
||||
_attr: {
|
||||
allowOverlap: "1",
|
||||
behindDoc: "0",
|
||||
distB: 0,
|
||||
distL: 0,
|
||||
distR: 0,
|
||||
distT: 0,
|
||||
layoutInCell: "1",
|
||||
locked: "0",
|
||||
relativeHeight: 120,
|
||||
simplePos: "0",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:simplePos": {
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:positionH": [
|
||||
{
|
||||
_attr: {
|
||||
relativeFrom: "page",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:posOffset": ["0"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"wp:positionV": [
|
||||
{
|
||||
_attr: {
|
||||
relativeFrom: "page",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:posOffset": ["0"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"wp:extent": {
|
||||
_attr: {
|
||||
cx: 952500,
|
||||
cy: 952500,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:effectExtent": {
|
||||
_attr: {
|
||||
b: 0,
|
||||
l: 0,
|
||||
r: 0,
|
||||
t: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:wrapNone": {},
|
||||
},
|
||||
{
|
||||
"wp:docPr": {
|
||||
_attr: {
|
||||
descr: "test",
|
||||
id: 0,
|
||||
name: "test",
|
||||
title: "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:cNvGraphicFramePr": [
|
||||
{
|
||||
"a:graphicFrameLocks": {
|
||||
_attr: {
|
||||
noChangeAspect: 1,
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"a:graphic": [
|
||||
{
|
||||
_attr: {
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:graphicData": [
|
||||
{
|
||||
_attr: {
|
||||
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:pic": [
|
||||
{
|
||||
_attr: {
|
||||
"xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:nvPicPr": [
|
||||
{
|
||||
"pic:cNvPr": {
|
||||
_attr: {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:cNvPicPr": [
|
||||
{
|
||||
"a:picLocks": {
|
||||
_attr: {
|
||||
noChangeArrowheads: 1,
|
||||
noChangeAspect: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"pic:blipFill": [
|
||||
{
|
||||
"a:blip": {
|
||||
_attr: {
|
||||
cstate: "none",
|
||||
"r:embed": "rId{test.png}",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:srcRect": {},
|
||||
},
|
||||
{
|
||||
"a:stretch": [
|
||||
{
|
||||
"a:fillRect": {},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"pic:spPr": [
|
||||
{
|
||||
_attr: {
|
||||
bwMode: "auto",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:xfrm": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
{
|
||||
"a:off": {
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:ext": {
|
||||
_attr: {
|
||||
cx: 952500,
|
||||
cy: 952500,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"a:prstGeom": [
|
||||
{
|
||||
_attr: {
|
||||
prst: "rect",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:avLst": {},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -90,7 +90,7 @@ export class Anchor extends XmlComponent {
|
||||
this.root.push(new WrapNone());
|
||||
}
|
||||
|
||||
this.root.push(new DocProperties());
|
||||
this.root.push(new DocProperties(drawingOptions.docProperties));
|
||||
this.root.push(new GraphicFrameProperties());
|
||||
this.root.push(new Graphic(mediaData, transform));
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
import { XmlAttributeComponent } from "@file/xml-components";
|
||||
|
||||
export class DocPropertiesAttributes extends XmlAttributeComponent<{
|
||||
readonly id?: number;
|
||||
readonly name?: string;
|
||||
readonly descr?: string;
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
id: "id",
|
||||
name: "name",
|
||||
descr: "descr",
|
||||
};
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { createHyperlinkClick, createHyperlinkHover } from "./doc-properties-children";
|
||||
|
||||
describe("Document Properties Children", () => {
|
||||
describe("#createHyperlinkClick", () => {
|
||||
it("should create a Hyperlink Click component", () => {
|
||||
const tree = new Formatter().format(createHyperlinkClick("1", false));
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"a:hlinkClick": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Hyperlink Click component with xmlns:a", () => {
|
||||
const tree = new Formatter().format(createHyperlinkClick("1", true));
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"a:hlinkClick": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createHyperlinkHover", () => {
|
||||
it("should create a Hyperlink Hover component", () => {
|
||||
const tree = new Formatter().format(createHyperlinkHover("1", false));
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"a:hlinkHover": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a Hyperlink Hover component with xmlns:a", () => {
|
||||
const tree = new Formatter().format(createHyperlinkHover("1", true));
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"a:hlinkHover": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
57
src/file/drawing/doc-properties/doc-properties-children.ts
Normal file
57
src/file/drawing/doc-properties/doc-properties-children.ts
Normal file
@ -0,0 +1,57 @@
|
||||
// <sequence>
|
||||
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||
// </sequence>
|
||||
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
// <xsd:complexType name="CT_Hyperlink">
|
||||
// <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded" />
|
||||
// <xsd:attribute name="tgtFrame" type="s:ST_String" use="optional" />
|
||||
// <xsd:attribute name="tooltip" type="s:ST_String" use="optional" />
|
||||
// <xsd:attribute name="docLocation" type="s:ST_String" use="optional" />
|
||||
// <xsd:attribute name="history" type="s:ST_OnOff" use="optional" />
|
||||
// <xsd:attribute name="anchor" type="s:ST_String" use="optional" />
|
||||
// <xsd:attribute ref="r:id" />
|
||||
// </xsd:complexType>
|
||||
|
||||
// TODO: Implement the rest of the attributes
|
||||
|
||||
export const createHyperlinkClick = (linkId: string, hasXmlNs: boolean): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "a:hlinkClick",
|
||||
attributes: {
|
||||
...(hasXmlNs
|
||||
? {
|
||||
xmlns: {
|
||||
key: "xmlns:a",
|
||||
value: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
id: {
|
||||
key: "r:id",
|
||||
value: `rId${linkId}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const createHyperlinkHover = (linkId: string, hasXmlNs: boolean): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "a:hlinkHover",
|
||||
attributes: {
|
||||
...(hasXmlNs
|
||||
? {
|
||||
xmlns: {
|
||||
key: "xmlns:a",
|
||||
value: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
id: {
|
||||
key: "r:id",
|
||||
value: `rId${linkId}`,
|
||||
},
|
||||
},
|
||||
});
|
@ -1,16 +1,67 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { DocPropertiesAttributes } from "./doc-properties-attributes";
|
||||
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_docPr_topic_ID0ES32OB.html
|
||||
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { ConcreteHyperlink } from "@file/paragraph";
|
||||
|
||||
import { uniqueNumericId } from "@util/convenience-functions";
|
||||
|
||||
import { createHyperlinkClick } from "./doc-properties-children";
|
||||
|
||||
// <complexType name="CT_NonVisualDrawingProps">
|
||||
// <sequence>
|
||||
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||
// </sequence>
|
||||
// <attribute name="id" type="ST_DrawingElementId" use="required" />
|
||||
// <attribute name="name" type="xsd:string" use="required" />
|
||||
// <attribute name="descr" type="xsd:string" use="optional" default="" />
|
||||
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
|
||||
// </complexType>
|
||||
|
||||
export interface DocPropertiesOptions {
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
readonly title: string;
|
||||
}
|
||||
|
||||
export class DocProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) {
|
||||
super("wp:docPr");
|
||||
|
||||
this.root.push(
|
||||
new DocPropertiesAttributes({
|
||||
id: 0,
|
||||
name: "",
|
||||
descr: "",
|
||||
new NextAttributeComponent({
|
||||
id: {
|
||||
key: "id",
|
||||
value: uniqueNumericId(),
|
||||
},
|
||||
name: {
|
||||
key: "name",
|
||||
value: name,
|
||||
},
|
||||
description: {
|
||||
key: "descr",
|
||||
value: description,
|
||||
},
|
||||
title: {
|
||||
key: "title",
|
||||
value: title,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||
for (let i = context.stack.length - 1; i >= 0; i--) {
|
||||
const element = context.stack[i];
|
||||
if (!(element instanceof ConcreteHyperlink)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.root.push(createHyperlinkClick(element.linkId, true));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return super.prepForXml(context);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { expect } from "chai";
|
||||
import { SinonStub, stub } from "sinon";
|
||||
|
||||
import { IContext } from "@file/xml-components";
|
||||
import { Formatter } from "@export/formatter";
|
||||
import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
import { ConcreteHyperlink, TextRun } from "../";
|
||||
import { Drawing, IDrawingOptions } from "./drawing";
|
||||
|
||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4jHR4hHh4hHx8hHyAiHyAjHyAjHSAjHR4jHR4hHh4hHx8hHyAjHyAjHyAjHSAjHR4hHR4hHR4hHx8iHyAjHyAjHyAjHSAhHR4hHR4hHR4hHx8jHyAjHyAjHyAjHyC9S2xeAAAA7nRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFxgZGhscHR4fICEiIyQlJicoKSorLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZISUpLTE1OUFFSU1RVVllaW1xdXmBhYmNkZWZnaGprbG1ub3Byc3R1dnd4eXp8fn+AgYKDhIWGiImKi4yNj5CRkpOUlZaXmJmam5ydnp+goaKjpKaoqqusra6vsLGys7S1tri5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+fkZpVQAABcBJREFUGBntwftjlQMcBvDnnLNL22qzJjWlKLHFVogyty3SiFq6EZliqZGyhnSxsLlMRahYoZKRFcul5dKFCatYqWZaNKvWtrPz/A2+7/b27qRzec/lPfvl/XxgMplMJpPJZDKZAtA9HJ3ppnIez0KnSdtC0RCNznHdJrbrh85wdSlVVRaEXuoGamYi5K5430HNiTiEWHKJg05eRWgNfKeV7RxbqUhGKPV/207VupQ8is0IoX5vtFC18SqEHaK4GyHTZ2kzVR8PBTCO4oANIZL4ShNVZcOhKKeYg9DoWdhI1ec3os2VFI0JCIUez5+i6st0qJZRrEAIJCw+QdW223BG/EmKwTBc/IJ/qfp2FDrkUnwFo8U9dZyqnaPhxLqfYjyM1S3vb6p+GGOBszsojoTDSDFz6qj66R4LzvYJxVMwUNRjf1H1ywQr/megg2RzLximy8waqvbda8M5iijegVEiHjlM1W/3h+FcXesphsMY4dMOUnUgOxyuPEzxPQwRNvV3qg5Nj4BreyimwADWe/dRVTMjEm6MoGLzGwtystL6RyOY3qSqdlYU3FpLZw1VW0sK5943MvUCKwJ1noNtjs6Ohge76Zq9ZkfpigU5WWkDYuCfbs1U5HWFR8/Qq4a9W0uK5k4ZmdrTCl8spGIePLPlbqqsc1Afe83O0hULc8alDYiBd7ZyitYMeBfR55rR2fOKP6ioPk2dGvZ+UVI0d8rtqT2tcCexlqK2F3wRn5Q+YVbBqrLKOupkr9lZujAOrmS0UpTb4JeIPkNHZ+cXr6uoPk2vyuBSPhWLEKj45PQJuQWryyqP0Z14uGLdROHIRNBEXDR09EP5r62rOHCazhrD4VKPwxTH+sIA3ZPTJ+YuWV22n+IruHFDC8X2CBjnPoolcGc2FYUwzmsUWXDHsoGKLBhmN0VvuBVfTVE/AAbpaid5CB4MbaLY1QXGuIViLTyZQcVyGGMuxWPwaA0Vk2GI9RRp8Ci2iuLkIBjhT5LNUfAspZFiTwyC72KK7+DNg1SsRvCNp3gZXq2k4iEEXSHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||
@ -26,6 +30,14 @@ const createDrawing = (drawingOptions?: IDrawingOptions): Drawing =>
|
||||
);
|
||||
|
||||
describe("Drawing", () => {
|
||||
before(() => {
|
||||
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
|
||||
});
|
||||
|
||||
let currentBreak: Drawing;
|
||||
|
||||
describe("#constructor()", () => {
|
||||
@ -68,6 +80,7 @@ describe("Drawing", () => {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
title: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -298,6 +311,7 @@ describe("Drawing", () => {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
title: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -438,5 +452,257 @@ describe("Drawing", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a drawing with a hyperlink", () => {
|
||||
currentBreak = createDrawing({
|
||||
floating: {
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(currentBreak, {
|
||||
stack: [new ConcreteHyperlink([new TextRun("Test")], "1")],
|
||||
} as unknown as IContext);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:drawing": [
|
||||
{
|
||||
"wp:anchor": [
|
||||
{
|
||||
_attr: {
|
||||
allowOverlap: "1",
|
||||
behindDoc: "0",
|
||||
distB: 0,
|
||||
distL: 0,
|
||||
distR: 0,
|
||||
distT: 0,
|
||||
layoutInCell: "1",
|
||||
locked: "0",
|
||||
relativeHeight: 952500,
|
||||
simplePos: "0",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:simplePos": {
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:positionH": [
|
||||
{
|
||||
_attr: {
|
||||
relativeFrom: "page",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:posOffset": ["0"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"wp:positionV": [
|
||||
{
|
||||
_attr: {
|
||||
relativeFrom: "page",
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:posOffset": ["0"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"wp:extent": {
|
||||
_attr: {
|
||||
cx: 952500,
|
||||
cy: 952500,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:effectExtent": {
|
||||
_attr: {
|
||||
b: 0,
|
||||
l: 0,
|
||||
r: 0,
|
||||
t: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:wrapNone": {},
|
||||
},
|
||||
{
|
||||
"wp:docPr": [
|
||||
{
|
||||
_attr: {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
title: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:hlinkClick": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"wp:cNvGraphicFramePr": [
|
||||
{
|
||||
"a:graphicFrameLocks": {
|
||||
_attr: {
|
||||
// tslint:disable-next-line:object-literal-key-quotes
|
||||
noChangeAspect: 1,
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"a:graphic": [
|
||||
{
|
||||
_attr: {
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:graphicData": [
|
||||
{
|
||||
_attr: {
|
||||
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:pic": [
|
||||
{
|
||||
_attr: {
|
||||
"xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:nvPicPr": [
|
||||
{
|
||||
"pic:cNvPr": [
|
||||
{
|
||||
_attr: {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:hlinkClick": {
|
||||
_attr: {
|
||||
"r:id": "rId1",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"pic:cNvPicPr": [
|
||||
{
|
||||
"a:picLocks": {
|
||||
_attr: {
|
||||
noChangeArrowheads: 1,
|
||||
noChangeAspect: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"pic:blipFill": [
|
||||
{
|
||||
"a:blip": {
|
||||
_attr: {
|
||||
// tslint:disable-next-line:object-literal-key-quotes
|
||||
cstate: "none",
|
||||
"r:embed": "rId{test.jpg}",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:srcRect": {},
|
||||
},
|
||||
{
|
||||
"a:stretch": [
|
||||
{
|
||||
"a:fillRect": {},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"pic:spPr": [
|
||||
{
|
||||
_attr: {
|
||||
bwMode: "auto",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:xfrm": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
{
|
||||
"a:off": {
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:ext": {
|
||||
_attr: {
|
||||
cx: 952500,
|
||||
cy: 952500,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"a:prstGeom": [
|
||||
{
|
||||
_attr: {
|
||||
prst: "rect",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:avLst": {},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { IMediaData } from "@file/media";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { Anchor } from "./anchor";
|
||||
import { DocPropertiesOptions } from "./doc-properties/doc-properties";
|
||||
import { IFloating } from "./floating";
|
||||
import { Inline } from "./inline";
|
||||
|
||||
@ -13,6 +15,7 @@ export interface IDistance {
|
||||
|
||||
export interface IDrawingOptions {
|
||||
readonly floating?: IFloating;
|
||||
readonly docProperties?: DocPropertiesOptions;
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Drawing">
|
||||
@ -29,7 +32,11 @@ export class Drawing extends XmlComponent {
|
||||
super("w:drawing");
|
||||
|
||||
if (!drawingOptions.floating) {
|
||||
this.inline = new Inline(imageData, imageData.transformation);
|
||||
this.inline = new Inline({
|
||||
mediaData: imageData,
|
||||
transform: imageData.transformation,
|
||||
docProperties: drawingOptions.docProperties,
|
||||
});
|
||||
this.root.push(this.inline);
|
||||
} else {
|
||||
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
|
||||
|
@ -1,6 +1,21 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
||||
import { createHyperlinkClick } from "@file/drawing/doc-properties/doc-properties-children";
|
||||
import { ConcreteHyperlink } from "@file/paragraph";
|
||||
|
||||
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
|
||||
|
||||
// <complexType name="CT_NonVisualDrawingProps">
|
||||
// <sequence>
|
||||
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||
// </sequence>
|
||||
// <attribute name="id" type="ST_DrawingElementId" use="required" />
|
||||
// <attribute name="name" type="xsd:string" use="required" />
|
||||
// <attribute name="descr" type="xsd:string" use="optional" default="" />
|
||||
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
|
||||
// </complexType>
|
||||
|
||||
export class NonVisualProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
super("pic:cNvPr");
|
||||
@ -13,4 +28,19 @@ export class NonVisualProperties extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||
for (let i = context.stack.length - 1; i >= 0; i--) {
|
||||
const element = context.stack[i];
|
||||
if (!(element instanceof ConcreteHyperlink)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.root.push(createHyperlinkClick(element.linkId, false));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return super.prepForXml(context);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
// http://officeopenxml.com/drwPicInline.php
|
||||
import { IMediaData, IMediaDataTransformation } from "@file/media";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { DocProperties } from "./../doc-properties/doc-properties";
|
||||
import { DocProperties, DocPropertiesOptions } from "./../doc-properties/doc-properties";
|
||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
||||
import { Extent } from "./../extent/extent";
|
||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||
import { Graphic } from "./../inline/graphic";
|
||||
import { InlineAttributes } from "./inline-attributes";
|
||||
|
||||
interface InlineOptions {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly docProperties?: DocPropertiesOptions;
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Inline">
|
||||
// <xsd:sequence>
|
||||
// <xsd:element name="extent" type="a:CT_PositiveSize2D"/>
|
||||
@ -26,7 +32,7 @@ export class Inline extends XmlComponent {
|
||||
private readonly extent: Extent;
|
||||
private readonly graphic: Graphic;
|
||||
|
||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||
public constructor({ mediaData, transform, docProperties }: InlineOptions) {
|
||||
super("wp:inline");
|
||||
|
||||
this.root.push(
|
||||
@ -43,7 +49,7 @@ export class Inline extends XmlComponent {
|
||||
|
||||
this.root.push(this.extent);
|
||||
this.root.push(new EffectExtent());
|
||||
this.root.push(new DocProperties());
|
||||
this.root.push(new DocProperties(docProperties));
|
||||
this.root.push(new GraphicFrameProperties());
|
||||
this.root.push(this.graphic);
|
||||
}
|
||||
|
5
src/file/file-child.ts
Normal file
5
src/file/file-child.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class FileChild extends XmlComponent {
|
||||
public readonly fileChild = Symbol();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import { IDocumentTemplate } from "../import-dotx";
|
||||
|
||||
export interface IFileProperties {
|
||||
readonly template?: IDocumentTemplate;
|
||||
}
|
||||
|
||||
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export const WORKAROUND = "";
|
@ -1,12 +1,11 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
import { sectionMarginDefaults, sectionPageSizeDefaults } from "./document";
|
||||
|
||||
import { sectionMarginDefaults, sectionPageSizeDefaults } from "./document";
|
||||
import { File } from "./file";
|
||||
import { Footer, Header } from "./header";
|
||||
import { Paragraph } from "./paragraph";
|
||||
import { Media } from "./media";
|
||||
|
||||
const PAGE_SIZE_DEFAULTS = {
|
||||
"w:h": sectionPageSizeDefaults.HEIGHT,
|
||||
@ -433,29 +432,6 @@ describe("File", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#templates", () => {
|
||||
// Test will be deprecated when import-dotx and templates are deprecated
|
||||
it("should work with template", () => {
|
||||
const doc = new File(
|
||||
{
|
||||
sections: [],
|
||||
},
|
||||
{
|
||||
template: {
|
||||
currentRelationshipId: 1,
|
||||
headers: [],
|
||||
footers: [],
|
||||
styles: "",
|
||||
titlePageIsDefined: true,
|
||||
media: new Media(),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(doc).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#externalStyles", () => {
|
||||
it("should work with external styles", () => {
|
||||
const doc = new File({
|
||||
|
@ -4,22 +4,19 @@ import { CoreProperties, IPropertiesOptions } from "./core-properties";
|
||||
import { CustomProperties } from "./custom-properties";
|
||||
import { DocumentWrapper } from "./document-wrapper";
|
||||
import { HeaderFooterReferenceType, ISectionPropertiesOptions } from "./document/body/section-properties";
|
||||
import { IFileProperties } from "./file-properties";
|
||||
import { FooterWrapper, IDocumentFooter } from "./footer-wrapper";
|
||||
import { FootnotesWrapper } from "./footnotes-wrapper";
|
||||
import { Footer, Header } from "./header";
|
||||
import { HeaderWrapper, IDocumentHeader } from "./header-wrapper";
|
||||
import { Media } from "./media";
|
||||
import { Numbering } from "./numbering";
|
||||
import { Paragraph } from "./paragraph";
|
||||
import { Comments } from "./paragraph/run/comment-run";
|
||||
import { Relationships } from "./relationships";
|
||||
import { Settings } from "./settings";
|
||||
import { Styles } from "./styles";
|
||||
import { ExternalStylesFactory } from "./styles/external-styles-factory";
|
||||
import { DefaultStylesFactory } from "./styles/factory";
|
||||
import { Table } from "./table";
|
||||
import { TableOfContents } from "./table-of-contents";
|
||||
import { FileChild } from "./file-child";
|
||||
|
||||
export interface ISectionOptions {
|
||||
readonly headers?: {
|
||||
@ -33,7 +30,7 @@ export interface ISectionOptions {
|
||||
readonly even?: Footer;
|
||||
};
|
||||
readonly properties?: ISectionPropertiesOptions;
|
||||
readonly children: readonly (Paragraph | Table | TableOfContents)[];
|
||||
readonly children: readonly FileChild[];
|
||||
}
|
||||
|
||||
export class File {
|
||||
@ -57,7 +54,7 @@ export class File {
|
||||
private readonly styles: Styles;
|
||||
private readonly comments: Comments;
|
||||
|
||||
public constructor(options: IPropertiesOptions, fileProperties: IFileProperties = {}) {
|
||||
public constructor(options: IPropertiesOptions) {
|
||||
this.coreProperties = new CoreProperties({
|
||||
...options,
|
||||
creator: options.creator ?? "Un-named",
|
||||
@ -73,28 +70,18 @@ export class File {
|
||||
this.appProperties = new AppProperties();
|
||||
this.footnotesWrapper = new FootnotesWrapper();
|
||||
this.contentTypes = new ContentTypes();
|
||||
this.documentWrapper = new DocumentWrapper({ background: options.background || {} });
|
||||
this.documentWrapper = new DocumentWrapper({ background: options.background });
|
||||
this.settings = new Settings({
|
||||
compatabilityModeVersion: options.compatabilityModeVersion,
|
||||
compatibilityModeVersion: options.compatabilityModeVersion,
|
||||
compatibility: options.compatibility,
|
||||
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
||||
trackRevisions: options.features?.trackRevisions,
|
||||
updateFields: options.features?.updateFields,
|
||||
});
|
||||
|
||||
this.media = fileProperties.template && fileProperties.template.media ? fileProperties.template.media : new Media();
|
||||
this.media = new Media();
|
||||
|
||||
if (fileProperties.template) {
|
||||
this.currentRelationshipId = fileProperties.template.currentRelationshipId + 1;
|
||||
}
|
||||
|
||||
// set up styles
|
||||
if (fileProperties.template && options.externalStyles) {
|
||||
throw Error("can not use both template and external styles");
|
||||
}
|
||||
if (fileProperties.template && fileProperties.template.styles) {
|
||||
const stylesFactory = new ExternalStylesFactory();
|
||||
this.styles = stylesFactory.newInstance(fileProperties.template.styles);
|
||||
} else if (options.externalStyles) {
|
||||
if (options.externalStyles) {
|
||||
const stylesFactory = new ExternalStylesFactory();
|
||||
this.styles = stylesFactory.newInstance(options.externalStyles);
|
||||
} else if (options.styles) {
|
||||
@ -111,18 +98,6 @@ export class File {
|
||||
|
||||
this.addDefaultRelationships();
|
||||
|
||||
if (fileProperties.template && fileProperties.template.headers) {
|
||||
for (const templateHeader of fileProperties.template.headers) {
|
||||
this.addHeaderToDocument(templateHeader.header, templateHeader.type);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileProperties.template && fileProperties.template.footers) {
|
||||
for (const templateFooter of fileProperties.template.footers) {
|
||||
this.addFooterToDocument(templateFooter.footer, templateFooter.type);
|
||||
}
|
||||
}
|
||||
|
||||
for (const section of options.sections) {
|
||||
this.addSection(section);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
export * from "./paragraph";
|
||||
export * from "./table";
|
||||
export * from "./file";
|
||||
export * from "./file-properties";
|
||||
export * from "./numbering";
|
||||
export * from "./media";
|
||||
export * from "./drawing";
|
||||
@ -18,4 +17,3 @@ export * from "./track-revision";
|
||||
export * from "./shared";
|
||||
export * from "./border";
|
||||
export * from "./vertical-align";
|
||||
export * from "./space-type";
|
||||
|
@ -15,96 +15,30 @@ describe("Media", () => {
|
||||
(convenienceFunctions.uniqueId as SinonStub).restore();
|
||||
});
|
||||
|
||||
describe("#addMedia", () => {
|
||||
it("should add media", () => {
|
||||
const image = new Media().addMedia("", {
|
||||
width: 100,
|
||||
height: 100,
|
||||
});
|
||||
expect(image.fileName).to.equal("test.png");
|
||||
expect(image.transformation).to.deep.equal({
|
||||
pixels: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
flip: undefined,
|
||||
emus: {
|
||||
x: 952500,
|
||||
y: 952500,
|
||||
},
|
||||
rotation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("should return UInt8Array if atob is present", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const image = new Media().addMedia("", {
|
||||
width: 100,
|
||||
height: 100,
|
||||
});
|
||||
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
|
||||
it("should use data as is if its not a string", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const image = new Media().addMedia(Buffer.from(""), {
|
||||
width: 100,
|
||||
height: 100,
|
||||
});
|
||||
expect(image.stream).to.be.an.instanceof(Uint8Array);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/immutable-data
|
||||
(global as any).atob = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addImage", () => {
|
||||
it("should add media", () => {
|
||||
describe("#Array", () => {
|
||||
it("Get images as array", () => {
|
||||
const media = new Media();
|
||||
media.addMedia("", {
|
||||
width: 100,
|
||||
height: 100,
|
||||
});
|
||||
|
||||
media.addImage("test2.png", {
|
||||
stream: Buffer.from(""),
|
||||
fileName: "",
|
||||
fileName: "test.png",
|
||||
transformation: {
|
||||
pixels: {
|
||||
x: Math.round(1),
|
||||
y: Math.round(1),
|
||||
x: Math.round(100),
|
||||
y: Math.round(100),
|
||||
},
|
||||
flip: {
|
||||
vertical: true,
|
||||
horizontal: true,
|
||||
},
|
||||
emus: {
|
||||
x: Math.round(1 * 9525),
|
||||
y: Math.round(1 * 9525),
|
||||
},
|
||||
rotation: 90,
|
||||
},
|
||||
});
|
||||
|
||||
expect(media.Array).to.be.lengthOf(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#Array", () => {
|
||||
it("Get images as array", () => {
|
||||
const media = new Media();
|
||||
media.addMedia("", {
|
||||
width: 100,
|
||||
height: 100,
|
||||
flip: {
|
||||
vertical: true,
|
||||
horizontal: true,
|
||||
},
|
||||
rotation: 90,
|
||||
});
|
||||
|
||||
const array = media.Array;
|
||||
expect(array).to.be.an.instanceof(Array);
|
||||
expect(array.length).to.equal(1);
|
||||
@ -121,10 +55,10 @@ describe("Media", () => {
|
||||
horizontal: true,
|
||||
},
|
||||
emus: {
|
||||
x: 952500,
|
||||
y: 952500,
|
||||
x: 9525,
|
||||
y: 9525,
|
||||
},
|
||||
rotation: 5400000,
|
||||
rotation: 90,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { uniqueId } from "@util/convenience-functions";
|
||||
|
||||
import { IMediaData } from "./data";
|
||||
|
||||
export interface IMediaTransformation {
|
||||
@ -20,33 +18,6 @@ export class Media {
|
||||
this.map = new Map<string, IMediaData>();
|
||||
}
|
||||
|
||||
public addMedia(data: Buffer | string | Uint8Array | ArrayBuffer, transformation: IMediaTransformation): IMediaData {
|
||||
const key = `${uniqueId()}.png`;
|
||||
|
||||
const newData = typeof data === "string" ? this.convertDataURIToBinary(data) : data;
|
||||
|
||||
const imageData: IMediaData = {
|
||||
stream: newData,
|
||||
fileName: key,
|
||||
transformation: {
|
||||
pixels: {
|
||||
x: Math.round(transformation.width),
|
||||
y: Math.round(transformation.height),
|
||||
},
|
||||
emus: {
|
||||
x: Math.round(transformation.width * 9525),
|
||||
y: Math.round(transformation.height * 9525),
|
||||
},
|
||||
flip: transformation.flip,
|
||||
rotation: transformation.rotation ? transformation.rotation * 60000 : undefined,
|
||||
},
|
||||
};
|
||||
|
||||
this.map.set(key, imageData);
|
||||
|
||||
return imageData;
|
||||
}
|
||||
|
||||
public addImage(key: string, mediaData: IMediaData): void {
|
||||
this.map.set(key, mediaData);
|
||||
}
|
||||
@ -54,24 +25,4 @@ export class Media {
|
||||
public get Array(): readonly IMediaData[] {
|
||||
return Array.from(this.map.values());
|
||||
}
|
||||
|
||||
private convertDataURIToBinary(dataURI: string): Uint8Array {
|
||||
// https://gist.github.com/borismus/1032746
|
||||
// https://github.com/mafintosh/base64-to-uint8array
|
||||
const BASE64_MARKER = ";base64,";
|
||||
|
||||
const base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
|
||||
|
||||
if (typeof atob === "function") {
|
||||
return new Uint8Array(
|
||||
atob(dataURI.substring(base64Index))
|
||||
.split("")
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const b = require("buf" + "fer");
|
||||
return new b.Buffer(dataURI, "base64");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,9 +12,11 @@ describe("ConcreteNumbering", () => {
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevel: {
|
||||
num: 3,
|
||||
},
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 3,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
@ -44,29 +46,216 @@ describe("ConcreteNumbering", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("sets a new override level for two different level numbers", () => {
|
||||
const concreteNumbering = new ConcreteNumbering({
|
||||
numId: 0,
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevels: [{ num: 3 }, { num: 5 }],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:num": [
|
||||
{
|
||||
_attr: {
|
||||
"w:numId": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:abstractNumId": {
|
||||
_attr: {
|
||||
"w:val": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": {
|
||||
_attr: {
|
||||
"w:ilvl": 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": {
|
||||
_attr: {
|
||||
"w:ilvl": 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("sets the startOverride element if start is given", () => {
|
||||
const concreteNumbering = new ConcreteNumbering({
|
||||
numId: 0,
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevel: {
|
||||
num: 1,
|
||||
start: 9,
|
||||
},
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 1,
|
||||
start: 9,
|
||||
},
|
||||
],
|
||||
});
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
expect(tree["w:num"]).to.include({
|
||||
"w:lvlOverride": [
|
||||
expect(tree).to.deep.equal({
|
||||
"w:num": [
|
||||
{
|
||||
_attr: {
|
||||
"w:ilvl": 1,
|
||||
"w:numId": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:startOverride": {
|
||||
"w:abstractNumId": {
|
||||
_attr: {
|
||||
"w:val": 9,
|
||||
"w:val": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": [
|
||||
{
|
||||
_attr: {
|
||||
"w:ilvl": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:startOverride": {
|
||||
_attr: {
|
||||
"w:val": 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("sets the startOverride element for several levels if start is given", () => {
|
||||
const concreteNumbering = new ConcreteNumbering({
|
||||
numId: 0,
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 1,
|
||||
start: 9,
|
||||
},
|
||||
{
|
||||
num: 3,
|
||||
start: 10,
|
||||
},
|
||||
],
|
||||
});
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:num": [
|
||||
{
|
||||
_attr: {
|
||||
"w:numId": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:abstractNumId": {
|
||||
_attr: {
|
||||
"w:val": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": [
|
||||
{
|
||||
_attr: {
|
||||
"w:ilvl": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:startOverride": {
|
||||
_attr: {
|
||||
"w:val": 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": [
|
||||
{
|
||||
_attr: {
|
||||
"w:ilvl": 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:startOverride": {
|
||||
_attr: {
|
||||
"w:val": 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("Mix of overrideLevels with start and without", () => {
|
||||
const concreteNumbering = new ConcreteNumbering({
|
||||
numId: 0,
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 1,
|
||||
start: 9,
|
||||
},
|
||||
{
|
||||
num: 3,
|
||||
},
|
||||
],
|
||||
});
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:num": [
|
||||
{
|
||||
_attr: {
|
||||
"w:numId": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:abstractNumId": {
|
||||
_attr: {
|
||||
"w:val": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": [
|
||||
{
|
||||
_attr: {
|
||||
"w:ilvl": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:startOverride": {
|
||||
_attr: {
|
||||
"w:val": 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:lvlOverride": {
|
||||
_attr: {
|
||||
"w:ilvl": 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -80,9 +269,11 @@ describe("ConcreteNumbering", () => {
|
||||
abstractNumId: 1,
|
||||
reference: "1",
|
||||
instance: 0,
|
||||
overrideLevel: {
|
||||
num: 1,
|
||||
},
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||
// http://www.datypic.com/sc/ooxml/a-w_val-57.html
|
||||
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber } from "@util/values";
|
||||
|
||||
@ -6,21 +7,138 @@ import { AlignmentType } from "../paragraph/formatting";
|
||||
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
||||
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
||||
|
||||
// TODO: Breaking change - consolidate with number-format
|
||||
// <xsd:simpleType name="ST_NumberFormat">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="decimal"/>
|
||||
// <xsd:enumeration value="upperRoman"/>
|
||||
// <xsd:enumeration value="lowerRoman"/>
|
||||
// <xsd:enumeration value="upperLetter"/>
|
||||
// <xsd:enumeration value="lowerLetter"/>
|
||||
// <xsd:enumeration value="ordinal"/>
|
||||
// <xsd:enumeration value="cardinalText"/>
|
||||
// <xsd:enumeration value="ordinalText"/>
|
||||
// <xsd:enumeration value="hex"/>
|
||||
// <xsd:enumeration value="chicago"/>
|
||||
// <xsd:enumeration value="ideographDigital"/>
|
||||
// <xsd:enumeration value="japaneseCounting"/>
|
||||
// <xsd:enumeration value="aiueo"/>
|
||||
// <xsd:enumeration value="iroha"/>
|
||||
// <xsd:enumeration value="decimalFullWidth"/>
|
||||
// <xsd:enumeration value="decimalHalfWidth"/>
|
||||
// <xsd:enumeration value="japaneseLegal"/>
|
||||
// <xsd:enumeration value="japaneseDigitalTenThousand"/>
|
||||
// <xsd:enumeration value="decimalEnclosedCircle"/>
|
||||
// <xsd:enumeration value="decimalFullWidth2"/>
|
||||
// <xsd:enumeration value="aiueoFullWidth"/>
|
||||
// <xsd:enumeration value="irohaFullWidth"/>
|
||||
// <xsd:enumeration value="decimalZero"/>
|
||||
// <xsd:enumeration value="bullet"/>
|
||||
// <xsd:enumeration value="ganada"/>
|
||||
// <xsd:enumeration value="chosung"/>
|
||||
// <xsd:enumeration value="decimalEnclosedFullstop"/>
|
||||
// <xsd:enumeration value="decimalEnclosedParen"/>
|
||||
// <xsd:enumeration value="decimalEnclosedCircleChinese"/>
|
||||
// <xsd:enumeration value="ideographEnclosedCircle"/>
|
||||
// <xsd:enumeration value="ideographTraditional"/>
|
||||
// <xsd:enumeration value="ideographZodiac"/>
|
||||
// <xsd:enumeration value="ideographZodiacTraditional"/>
|
||||
// <xsd:enumeration value="taiwaneseCounting"/>
|
||||
// <xsd:enumeration value="ideographLegalTraditional"/>
|
||||
// <xsd:enumeration value="taiwaneseCountingThousand"/>
|
||||
// <xsd:enumeration value="taiwaneseDigital"/>
|
||||
// <xsd:enumeration value="chineseCounting"/>
|
||||
// <xsd:enumeration value="chineseLegalSimplified"/>
|
||||
// <xsd:enumeration value="chineseCountingThousand"/>
|
||||
// <xsd:enumeration value="koreanDigital"/>
|
||||
// <xsd:enumeration value="koreanCounting"/>
|
||||
// <xsd:enumeration value="koreanLegal"/>
|
||||
// <xsd:enumeration value="koreanDigital2"/>
|
||||
// <xsd:enumeration value="vietnameseCounting"/>
|
||||
// <xsd:enumeration value="russianLower"/>
|
||||
// <xsd:enumeration value="russianUpper"/>
|
||||
// <xsd:enumeration value="none"/>
|
||||
// <xsd:enumeration value="numberInDash"/>
|
||||
// <xsd:enumeration value="hebrew1"/>
|
||||
// <xsd:enumeration value="hebrew2"/>
|
||||
// <xsd:enumeration value="arabicAlpha"/>
|
||||
// <xsd:enumeration value="arabicAbjad"/>
|
||||
// <xsd:enumeration value="hindiVowels"/>
|
||||
// <xsd:enumeration value="hindiConsonants"/>
|
||||
// <xsd:enumeration value="hindiNumbers"/>
|
||||
// <xsd:enumeration value="hindiCounting"/>
|
||||
// <xsd:enumeration value="thaiLetters"/>
|
||||
// <xsd:enumeration value="thaiNumbers"/>
|
||||
// <xsd:enumeration value="thaiCounting"/>
|
||||
// <xsd:enumeration value="bahtText"/>
|
||||
// <xsd:enumeration value="dollarText"/>
|
||||
// <xsd:enumeration value="custom"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export enum LevelFormat {
|
||||
BULLET = "bullet",
|
||||
CARDINAL_TEXT = "cardinalText",
|
||||
CHICAGO = "chicago",
|
||||
DECIMAL = "decimal",
|
||||
UPPER_ROMAN = "upperRoman",
|
||||
LOWER_ROMAN = "lowerRoman",
|
||||
UPPER_LETTER = "upperLetter",
|
||||
LOWER_LETTER = "lowerLetter",
|
||||
ORDINAL = "ordinal",
|
||||
CARDINAL_TEXT = "cardinalText",
|
||||
ORDINAL_TEXT = "ordinalText",
|
||||
HEX = "hex",
|
||||
CHICAGO = "chicago",
|
||||
IDEOGRAPH__DIGITAL = "ideographDigital",
|
||||
JAPANESE_COUNTING = "japaneseCounting",
|
||||
AIUEO = "aiueo",
|
||||
IROHA = "iroha",
|
||||
DECIMAL_FULL_WIDTH = "decimalFullWidth",
|
||||
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
|
||||
JAPANESE_LEGAL = "japaneseLegal",
|
||||
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
|
||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
||||
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2",
|
||||
AIUEO_FULL_WIDTH = "aiueoFullWidth",
|
||||
IROHA_FULL_WIDTH = "irohaFullWidth",
|
||||
DECIMAL_ZERO = "decimalZero",
|
||||
BULLET = "bullet",
|
||||
GANADA = "ganada",
|
||||
CHOSUNG = "chosung",
|
||||
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
||||
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
||||
DECIMAL_ZERO = "decimalZero",
|
||||
LOWER_LETTER = "lowerLetter",
|
||||
LOWER_ROMAN = "lowerRoman",
|
||||
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
|
||||
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
|
||||
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
|
||||
IDEOGRAPH_ZODIAC = "ideographZodiac",
|
||||
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
|
||||
TAIWANESE_COUNTING = "taiwaneseCounting",
|
||||
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
|
||||
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
|
||||
TAIWANESE_DIGITAL = "taiwaneseDigital",
|
||||
CHINESE_COUNTING = "chineseCounting",
|
||||
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
|
||||
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand",
|
||||
KOREAN_DIGITAL = "koreanDigital",
|
||||
KOREAN_COUNTING = "koreanCounting",
|
||||
KOREAN_LEGAL = "koreanLegal",
|
||||
KOREAN_DIGITAL2 = "koreanDigital2",
|
||||
VIETNAMESE_COUNTING = "vietnameseCounting",
|
||||
RUSSIAN_LOWER = "russianLower",
|
||||
RUSSIAN_UPPER = "russianUpper",
|
||||
NONE = "none",
|
||||
ORDINAL_TEXT = "ordinalText",
|
||||
UPPER_LETTER = "upperLetter",
|
||||
UPPER_ROMAN = "upperRoman",
|
||||
NUMBER_IN_DASH = "numberInDash",
|
||||
HEBREW1 = "hebrew1",
|
||||
HEBREW2 = "hebrew2",
|
||||
ARABIC_ALPHA = "arabicAlpha",
|
||||
ARABIC_ABJAD = "arabicAbjad",
|
||||
HINDI_VOWELS = "hindiVowels",
|
||||
HINDI_CONSONANTS = "hindiConsonants",
|
||||
HINDI_NUMBERS = "hindiNumbers",
|
||||
HINDI_COUNTING = "hindiCounting",
|
||||
THAI_LETTERS = "thaiLetters",
|
||||
THAI_NUMBERS = "thaiNumbers",
|
||||
THAI_COUNTING = "thaiCounting",
|
||||
BAHT_TEXT = "bahtText",
|
||||
DOLLAR_TEXT = "dollarText",
|
||||
CUSTOM = "custom",
|
||||
}
|
||||
|
||||
class LevelAttributes extends XmlAttributeComponent<{
|
||||
|
@ -18,15 +18,17 @@ class NumAttributes extends XmlAttributeComponent<{
|
||||
protected readonly xmlKeys = { numId: "w:numId" };
|
||||
}
|
||||
|
||||
interface IOverrideLevel {
|
||||
readonly num: number;
|
||||
readonly start?: number;
|
||||
}
|
||||
|
||||
export interface IConcreteNumberingOptions {
|
||||
readonly numId: number;
|
||||
readonly abstractNumId: number;
|
||||
readonly reference: string;
|
||||
readonly instance: number;
|
||||
readonly overrideLevel?: {
|
||||
readonly num: number;
|
||||
readonly start?: number;
|
||||
};
|
||||
readonly overrideLevels?: readonly IOverrideLevel[];
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Numbering">
|
||||
@ -60,8 +62,10 @@ export class ConcreteNumbering extends XmlComponent {
|
||||
|
||||
this.root.push(new AbstractNumId(decimalNumber(options.abstractNumId)));
|
||||
|
||||
if (options.overrideLevel) {
|
||||
this.root.push(new LevelOverride(options.overrideLevel.num, options.overrideLevel.start));
|
||||
if (options.overrideLevels && options.overrideLevels.length) {
|
||||
for (const level of options.overrideLevels) {
|
||||
this.root.push(new LevelOverride(level.num, level.start));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,10 +164,12 @@ export class Numbering extends XmlComponent {
|
||||
abstractNumId: abstractNumbering.id,
|
||||
reference: "default-bullet-numbering",
|
||||
instance: 0,
|
||||
overrideLevel: {
|
||||
num: 0,
|
||||
start: 1,
|
||||
},
|
||||
overrideLevels: [
|
||||
{
|
||||
num: 0,
|
||||
start: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -1,16 +1,51 @@
|
||||
// http://officeopenxml.com/WPalignment.php
|
||||
// http://officeopenxml.com/WPtableAlignment.php
|
||||
// http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
|
||||
// <xsd:simpleType name="ST_Jc">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="start"/>
|
||||
// <xsd:enumeration value="center"/>
|
||||
// <xsd:enumeration value="end"/>
|
||||
// <xsd:enumeration value="both"/>
|
||||
// <xsd:enumeration value="mediumKashida"/>
|
||||
// <xsd:enumeration value="distribute"/>
|
||||
// <xsd:enumeration value="numTab"/>
|
||||
// <xsd:enumeration value="highKashida"/>
|
||||
// <xsd:enumeration value="lowKashida"/>
|
||||
// <xsd:enumeration value="thaiDistribute"/>
|
||||
// <xsd:enumeration value="left"/>
|
||||
// <xsd:enumeration value="right"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export enum AlignmentType {
|
||||
/** Align Start */
|
||||
START = "start",
|
||||
END = "end",
|
||||
/** Align Center */
|
||||
CENTER = "center",
|
||||
/** End */
|
||||
END = "end",
|
||||
/** Justified */
|
||||
BOTH = "both",
|
||||
JUSTIFIED = "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 }> {
|
||||
|
@ -1,39 +1,14 @@
|
||||
// http://officeopenxml.com/WPindentation.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||
|
||||
export interface IIndentAttributesProperties {
|
||||
readonly start?: number | string;
|
||||
readonly end?: number | string;
|
||||
readonly left?: number | string;
|
||||
readonly right?: number | string;
|
||||
readonly hanging?: number | string;
|
||||
readonly firstLine?: number | string;
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Ind">
|
||||
// <xsd:attribute name="start" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="startChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="end" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="endChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="left" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="leftChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="right" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="rightChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="hanging" type="s:ST_TwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="hangingChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="firstLine" type="s:ST_TwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="firstLineChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
start: "w:start",
|
||||
end: "w:end",
|
||||
left: "w:left",
|
||||
right: "w:right",
|
||||
hanging: "w:hanging",
|
||||
firstLine: "w:firstLine",
|
||||
};
|
||||
readonly start?: number | UniversalMeasure;
|
||||
readonly end?: number | UniversalMeasure;
|
||||
readonly left?: number | UniversalMeasure;
|
||||
readonly right?: number | UniversalMeasure;
|
||||
readonly hanging?: number | PositiveUniversalMeasure;
|
||||
readonly firstLine?: number | PositiveUniversalMeasure;
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_PPrBase">
|
||||
@ -43,14 +18,53 @@ class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties
|
||||
export class Indent extends XmlComponent {
|
||||
public constructor({ start, end, left, right, hanging, firstLine }: IIndentAttributesProperties) {
|
||||
super("w:ind");
|
||||
// <xsd:complexType name="CT_Ind">
|
||||
// <xsd:attribute name="start" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="startChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="end" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="endChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="left" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="leftChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="right" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="rightChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="hanging" type="s:ST_TwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="hangingChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// <xsd:attribute name="firstLine" type="s:ST_TwipsMeasure" use="optional"/>
|
||||
// <xsd:attribute name="firstLineChars" type="ST_DecimalNumber" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
this.root.push(
|
||||
new IndentAttributes({
|
||||
start: start === undefined ? undefined : signedTwipsMeasureValue(start),
|
||||
end: end === undefined ? undefined : signedTwipsMeasureValue(end),
|
||||
left: left === undefined ? undefined : signedTwipsMeasureValue(left),
|
||||
right: right === undefined ? undefined : signedTwipsMeasureValue(right),
|
||||
hanging: hanging === undefined ? undefined : twipsMeasureValue(hanging),
|
||||
firstLine: firstLine === undefined ? undefined : twipsMeasureValue(firstLine),
|
||||
new NextAttributeComponent<{
|
||||
readonly start?: number | UniversalMeasure;
|
||||
readonly end?: number | UniversalMeasure;
|
||||
readonly left?: number | UniversalMeasure;
|
||||
readonly right?: number | UniversalMeasure;
|
||||
readonly hanging?: number | PositiveUniversalMeasure;
|
||||
readonly firstLine?: number | PositiveUniversalMeasure;
|
||||
}>({
|
||||
start: {
|
||||
key: "w:start",
|
||||
value: start === undefined ? undefined : signedTwipsMeasureValue(start),
|
||||
},
|
||||
end: {
|
||||
key: "w:end",
|
||||
value: end === undefined ? undefined : signedTwipsMeasureValue(end),
|
||||
},
|
||||
left: {
|
||||
key: "w:left",
|
||||
value: left === undefined ? undefined : signedTwipsMeasureValue(left),
|
||||
},
|
||||
right: {
|
||||
key: "w:right",
|
||||
value: right === undefined ? undefined : signedTwipsMeasureValue(right),
|
||||
},
|
||||
hanging: {
|
||||
key: "w:hanging",
|
||||
value: hanging === undefined ? undefined : twipsMeasureValue(hanging),
|
||||
},
|
||||
firstLine: {
|
||||
key: "w:firstLine",
|
||||
value: firstLine === undefined ? undefined : twipsMeasureValue(firstLine),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
export enum LineRuleType {
|
||||
AT_LEAST = "atLeast",
|
||||
EXACTLY = "exactly",
|
||||
EXACT = "exact",
|
||||
AUTO = "auto",
|
||||
}
|
||||
export interface ISpacingProperties {
|
||||
|
0
src/file/paragraph/formatting/width.ts
Normal file
0
src/file/paragraph/formatting/width.ts
Normal file
20
src/file/paragraph/formatting/word-wrap.spec.ts
Normal file
20
src/file/paragraph/formatting/word-wrap.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { WordWrap } from "./word-wrap";
|
||||
|
||||
describe("WordWrap", () => {
|
||||
it("should create", () => {
|
||||
const wordWrap = new WordWrap();
|
||||
const tree = new Formatter().format(wordWrap);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:wordWrap": {
|
||||
_attr: {
|
||||
"w:val": 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
14
src/file/paragraph/formatting/word-wrap.ts
Normal file
14
src/file/paragraph/formatting/word-wrap.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// http://officeopenxml.com/WPalignment.php
|
||||
// http://officeopenxml.com/WPtableAlignment.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class WordWrapAttributes extends XmlAttributeComponent<{ readonly val: 0 }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class WordWrap extends XmlComponent {
|
||||
public constructor() {
|
||||
super("w:wordWrap");
|
||||
this.root.push(new WordWrapAttributes({ val: 0 }));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { SpaceType } from "@file/space-type";
|
||||
import { SpaceType } from "@file/shared";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { TextAttributes } from "../run/text-attributes";
|
||||
|
@ -3,6 +3,7 @@ import { SinonStub, stub } from "sinon";
|
||||
|
||||
import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared";
|
||||
import { Formatter } from "@export/formatter";
|
||||
import { BorderStyle } from "@file/border";
|
||||
import { EMPTY_OBJECT } from "@file/xml-components";
|
||||
@ -10,7 +11,6 @@ import { EMPTY_OBJECT } from "@file/xml-components";
|
||||
import { IViewWrapper } from "../document-wrapper";
|
||||
import { File } from "../file";
|
||||
import { ShadingType } from "../shading";
|
||||
import { HorizontalPositionAlign, VerticalPositionAlign } from "../shared";
|
||||
import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting";
|
||||
import { FrameAnchorType } from "./frame";
|
||||
import { Bookmark, ExternalHyperlink } from "./links";
|
||||
@ -25,6 +25,7 @@ describe("Paragraph", () => {
|
||||
|
||||
after(() => {
|
||||
(convenienceFunctions.uniqueId as SinonStub).restore();
|
||||
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
@ -953,6 +954,7 @@ describe("Paragraph", () => {
|
||||
paragraph.prepForXml({
|
||||
viewWrapper: viewWrapperMock,
|
||||
file: file,
|
||||
stack: [],
|
||||
});
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,7 +1,8 @@
|
||||
// http://officeopenxml.com/WPparagraph.php
|
||||
import { FootnoteReferenceRun } from "@file/footnotes";
|
||||
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
||||
import { IContext, IXmlableObject } from "@file/xml-components";
|
||||
import { uniqueId } from "@util/convenience-functions";
|
||||
import { FileChild } from "@file/file-child";
|
||||
|
||||
import { TargetModeType } from "../relationships/relationship/relationship";
|
||||
import { DeletedTextRun, InsertedTextRun } from "../track-revision";
|
||||
@ -39,7 +40,7 @@ export interface IParagraphOptions extends IParagraphPropertiesOptions {
|
||||
readonly children?: readonly ParagraphChild[];
|
||||
}
|
||||
|
||||
export class Paragraph extends XmlComponent {
|
||||
export class Paragraph extends FileChild {
|
||||
private readonly properties: ParagraphProperties;
|
||||
|
||||
public constructor(options: string | IParagraphOptions) {
|
||||
|
@ -31,6 +31,7 @@ describe("ParagraphProperties", () => {
|
||||
} as File,
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
viewWrapper: new DocumentWrapper({ background: {} }),
|
||||
stack: [],
|
||||
});
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
@ -123,5 +124,39 @@ describe("ParagraphProperties", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with the autoSpaceEastAsianText property", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
autoSpaceEastAsianText: true,
|
||||
});
|
||||
const tree = new Formatter().format(properties);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:autoSpaceDN": {},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with the wordWrap property", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
wordWrap: true,
|
||||
});
|
||||
const tree = new Formatter().format(properties);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:wordWrap": {
|
||||
_attr: {
|
||||
"w:val": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -11,6 +11,7 @@ import { ISpacingProperties, Spacing } from "./formatting/spacing";
|
||||
import { HeadingLevel, Style } from "./formatting/style";
|
||||
import { TabStop, TabStopDefinition, TabStopType } from "./formatting/tab-stop";
|
||||
import { NumberProperties } from "./formatting/unordered-list";
|
||||
import { WordWrap } from "./formatting/word-wrap";
|
||||
import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
|
||||
import { OutlineLevel } from "./links";
|
||||
|
||||
@ -50,6 +51,13 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
readonly widowControl?: boolean;
|
||||
readonly frame?: IFrameOptions;
|
||||
readonly suppressLineNumbers?: boolean;
|
||||
readonly wordWrap?: boolean;
|
||||
readonly scale?: number;
|
||||
/**
|
||||
* This element specifies whether inter-character spacing shall automatically be adjusted between regions of numbers and regions of East Asian text in the current paragraph. These regions shall be determined by the Unicode character values of the text content within the paragraph.
|
||||
* This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard.
|
||||
*/
|
||||
readonly autoSpaceEastAsianText?: boolean;
|
||||
}
|
||||
|
||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
@ -128,6 +136,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
this.push(new Shading(options.shading));
|
||||
}
|
||||
|
||||
if (options.wordWrap) {
|
||||
this.push(new WordWrap());
|
||||
}
|
||||
|
||||
/**
|
||||
* FIX: Multitab support for Libre Writer
|
||||
* Ensure there is only one w:tabs tag with multiple w:tab
|
||||
@ -172,6 +184,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
if (options.suppressLineNumbers !== undefined) {
|
||||
this.push(new OnOffElement("w:suppressLineNumbers", options.suppressLineNumbers));
|
||||
}
|
||||
|
||||
if (options.autoSpaceEastAsianText !== undefined) {
|
||||
this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText));
|
||||
}
|
||||
}
|
||||
|
||||
public push(item: XmlComponent): void {
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { expect } from "chai";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { Paragraph } from "../paragraph";
|
||||
import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./comment-run";
|
||||
|
||||
describe("CommentRangeStart", () => {
|
||||
@ -40,12 +43,54 @@ describe("CommentReference", () => {
|
||||
});
|
||||
|
||||
describe("Comment", () => {
|
||||
let clock: sinon.SinonFakeTimers;
|
||||
|
||||
beforeEach(() => {
|
||||
const now = new Date("1999-01-01T00:00:00.000Z");
|
||||
clock = sinon.useFakeTimers(now.getTime());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create", () => {
|
||||
const component = new Comment({
|
||||
id: 0,
|
||||
text: "test-comment",
|
||||
date: new Date(1999, 0, 1),
|
||||
children: [new Paragraph("test-comment")],
|
||||
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||
});
|
||||
const tree = new Formatter().format(component);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:comment": [
|
||||
{ _attr: { "w:id": 0, "w:date": "1999-01-01T00:00:00.000Z" } },
|
||||
{
|
||||
"w:p": [
|
||||
{
|
||||
"w:r": [
|
||||
{
|
||||
"w:t": [
|
||||
{
|
||||
_attr: {
|
||||
"xml:space": "preserve",
|
||||
},
|
||||
},
|
||||
"test-comment",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create by using default date", () => {
|
||||
const component = new Comment({
|
||||
id: 0,
|
||||
children: [new Paragraph("test-comment")],
|
||||
});
|
||||
const tree = new Formatter().format(component);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -82,13 +127,13 @@ describe("Comments", () => {
|
||||
children: [
|
||||
{
|
||||
id: 0,
|
||||
text: "test-comment",
|
||||
date: new Date(1999, 0, 1),
|
||||
children: [new Paragraph("test-comment")],
|
||||
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
text: "test-comment-2",
|
||||
date: new Date(1999, 0, 1),
|
||||
children: [new Paragraph("test-comment-2")],
|
||||
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user