Compare commits
343 Commits
Author | SHA1 | Date | |
---|---|---|---|
3006f4d2c1 | |||
7f88a38219 | |||
a481518470 | |||
2435ebf16e | |||
62d0767ceb | |||
8024c01a82 | |||
1b380c3fdb | |||
06b67bd292 | |||
8a1087f601 | |||
ff09d6515c | |||
ebe85d8e14 | |||
5dc27ac46a | |||
1dcc8ee761 | |||
f789f60e22 | |||
32e3f07d57 | |||
9ea41ab3ce | |||
4b8d062862 | |||
d9408029f3 | |||
9fe0406078 | |||
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 | |||
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 | |||
7e5e2baf92 | |||
53c70e6cd1 | |||
4bfb87ea74 | |||
86e12c7d40 | |||
eb5449adf8 | |||
19eeec9fc8 | |||
449f5f5be3 | |||
bc5a1b52b7 | |||
fc7f37767f | |||
38dbdd02ae | |||
7bb3fa74ce | |||
a33660d32c | |||
ef842d1f3f | |||
e5c2a0a87b | |||
817ffe8fd0 | |||
5b582d45ba | |||
6a303532f4 | |||
c75abb7cb9 | |||
8282d76b87 | |||
79f3866c4c | |||
6dcf3f25e9 | |||
e80acea63f | |||
640639264d | |||
3ccdd2585c | |||
2c4b55c692 | |||
70a3b25d54 | |||
d053baef03 | |||
629c586014 | |||
e4b03b3f71 | |||
9ab6df99b1 | |||
51519a55ef | |||
059455929b | |||
8a1df4438e | |||
cbf6e46e35 | |||
727b1bd63b | |||
363b8d74ae | |||
b31ecd6583 | |||
563914a0ef | |||
1e8adbb240 | |||
4b1f89a561 | |||
1a4a0ea5b8 | |||
f781028b08 | |||
56e8ad4f17 | |||
62c34ae612 | |||
26123b0a93 | |||
4023464a13 | |||
0c92f354c5 | |||
676723c8bd | |||
2f4d5afaea | |||
d0abceb08d | |||
8b165e93e1 | |||
321969eb85 | |||
85ec90849e | |||
96451bc5b7 | |||
311cbf55ef | |||
0258b256f2 | |||
c615de97c4 | |||
e29a7bf146 | |||
b665c243f0 | |||
bea1c9ed61 | |||
0e6bdaa9c9 | |||
7925689618 | |||
0e818c8d73 | |||
791441ec86 | |||
401de9147c | |||
563e10fa92 | |||
a22c34d8c2 | |||
e549f8ae61 | |||
0ac23d0646 | |||
814d3892f2 | |||
07d1306a35 | |||
5950055cca | |||
d6dd468e84 | |||
9a221a01ab | |||
2a78a29b08 | |||
e90d97b813 | |||
d020d59b11 | |||
5d6d52a465 | |||
ebb3f8137e | |||
af7d275c27 | |||
2b01a6006c | |||
9f3940746a | |||
9f729b3bb3 | |||
2376fb5834 | |||
0a1507599b | |||
42bb01c416 | |||
cfb0ae7428 | |||
6b30f44da0 | |||
a7f89ac58f | |||
38711f04bc | |||
78fd99c26e | |||
cae10d4611 | |||
40233dbf87 | |||
35865e46f0 | |||
ea565d8f71 | |||
859a3f4015 | |||
ebcb37cbed | |||
1bdf9a4987 | |||
d7a9cb2168 | |||
8890e13ccb | |||
87e1844f04 | |||
388030c6ec | |||
d5bd407802 | |||
ba4dc2ed54 | |||
c982e64996 | |||
0425939668 | |||
48b804b765 | |||
246ae6e6bc | |||
efa5b65e45 | |||
f4f6ee5055 | |||
1a630bcb4d | |||
600fef21f6 | |||
b779ee79a5 | |||
08537944ae | |||
004b3641eb | |||
b6be05a931 | |||
191cc071c2 | |||
9e52c46ad3 | |||
21f7662a77 | |||
d4d7f92df8 | |||
a3180fd70d | |||
3dc4f8e87a | |||
64393d92a5 | |||
1fbd405e41 | |||
f711aa1b58 | |||
e2e527ce44 | |||
bb7f48c021 | |||
ad9b64e7ae | |||
ef2ee6d00d | |||
2d259c4edc | |||
b286e3ae09 | |||
ec3e193672 | |||
40a2fcd81e | |||
7e876bad7e | |||
aefa3b102c | |||
4d1f295a26 | |||
56a31faf7e | |||
f3afef01b0 | |||
ea38655c48 | |||
972d06b492 | |||
8538489136 | |||
4f28464b99 | |||
049e111797 | |||
96199c4b12 | |||
cf23789edf | |||
48724e5b08 | |||
40c778d244 | |||
ff0c44ecfc | |||
828cc15ea3 | |||
bbbe55b706 | |||
cd98bdec9b | |||
59767bddfe | |||
035ae40b97 | |||
f7603bfdfc | |||
754201a9a2 | |||
d0af7e4781 | |||
ecf0bf8cdd | |||
85bafb3eef | |||
efe378e94f | |||
614cb74d47 | |||
df4190321e | |||
56c3574a2b | |||
51b11c7035 | |||
564693cf22 | |||
50a6bed92f | |||
ef54b3cf2e | |||
ebf06250b1 | |||
56f9c22ac6 | |||
384242974b | |||
7717d95cab | |||
5b69a32c11 | |||
24abf51c8c | |||
80c5092dc1 | |||
15ffa4d98b |
270
.eslintrc.js
Normal file
270
.eslintrc.js
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
/*
|
||||||
|
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
|
||||||
|
https://github.com/typescript-eslint/tslint-to-eslint-config
|
||||||
|
|
||||||
|
It represents the closest reasonable ESLint configuration to this
|
||||||
|
project's original TSLint configuration.
|
||||||
|
|
||||||
|
We recommend eventually switching this configuration to extend from
|
||||||
|
the recommended rulesets in typescript-eslint.
|
||||||
|
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
|
||||||
|
|
||||||
|
Happy linting! 💖
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
es6: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
project: "tsconfig.json",
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
"eslint-plugin-import",
|
||||||
|
"eslint-plugin-no-null",
|
||||||
|
"eslint-plugin-unicorn",
|
||||||
|
"eslint-plugin-jsdoc",
|
||||||
|
"eslint-plugin-prefer-arrow",
|
||||||
|
"@typescript-eslint",
|
||||||
|
"functional",
|
||||||
|
],
|
||||||
|
root: true,
|
||||||
|
rules: {
|
||||||
|
"no-undef": "off",
|
||||||
|
"no-extra-boolean-cast": "off",
|
||||||
|
"no-alert": "error",
|
||||||
|
"no-self-compare": "error",
|
||||||
|
"no-unreachable-loop": "error",
|
||||||
|
"no-template-curly-in-string": "error",
|
||||||
|
"no-unused-private-class-members": "error",
|
||||||
|
"no-extend-native": "error",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-implied-eval": "error",
|
||||||
|
"no-iterator": "error",
|
||||||
|
"no-lone-blocks": "error",
|
||||||
|
"no-loop-func": "error",
|
||||||
|
"no-new-object": "error",
|
||||||
|
"no-proto": "error",
|
||||||
|
"no-useless-catch": "error",
|
||||||
|
"one-var-declaration-per-line": "error",
|
||||||
|
"prefer-arrow-callback": "error",
|
||||||
|
"prefer-destructuring": "error",
|
||||||
|
"prefer-exponentiation-operator": "error",
|
||||||
|
"prefer-promise-reject-errors": "error",
|
||||||
|
"prefer-regex-literals": "error",
|
||||||
|
"prefer-spread": "error",
|
||||||
|
"prefer-template": "error",
|
||||||
|
"require-await": "error",
|
||||||
|
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||||
|
"@typescript-eslint/array-type": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
default: "array",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/ban-types": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
types: {
|
||||||
|
Object: {
|
||||||
|
message: "Avoid using the `Object` type. Did you mean `object`?",
|
||||||
|
},
|
||||||
|
Function: {
|
||||||
|
message: "Avoid using the `Function` type. Prefer a specific function type, like `() => void`.",
|
||||||
|
},
|
||||||
|
Boolean: {
|
||||||
|
message: "Avoid using the `Boolean` type. Did you mean `boolean`?",
|
||||||
|
},
|
||||||
|
Number: {
|
||||||
|
message: "Avoid using the `Number` type. Did you mean `number`?",
|
||||||
|
},
|
||||||
|
String: {
|
||||||
|
message: "Avoid using the `String` type. Did you mean `string`?",
|
||||||
|
},
|
||||||
|
Symbol: {
|
||||||
|
message: "Avoid using the `Symbol` type. Did you mean `symbol`?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/consistent-type-assertions": "error",
|
||||||
|
"@typescript-eslint/dot-notation": "error",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
allowExpressions: false,
|
||||||
|
allowTypedFunctionExpressions: false,
|
||||||
|
allowHigherOrderFunctions: false,
|
||||||
|
allowDirectConstAssertionInArrowFunctions: true,
|
||||||
|
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
accessibility: "explicit",
|
||||||
|
overrides: {
|
||||||
|
accessors: "explicit",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/explicit-module-boundary-types": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
allowArgumentsExplicitlyTypedAsAny: true,
|
||||||
|
allowDirectConstAssertionInArrowFunctions: true,
|
||||||
|
allowHigherOrderFunctions: false,
|
||||||
|
allowTypedFunctionExpressions: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/naming-convention": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
selector: ["objectLiteralProperty"],
|
||||||
|
leadingUnderscore: "allow",
|
||||||
|
format: ["camelCase", "PascalCase"],
|
||||||
|
filter: {
|
||||||
|
regex: "(^[a-z]+:.+)|_attr|[0-9]",
|
||||||
|
match: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-empty-function": "error",
|
||||||
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
|
"@typescript-eslint/no-namespace": "error",
|
||||||
|
"@typescript-eslint/no-parameter-properties": "off",
|
||||||
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
|
"@typescript-eslint/no-shadow": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
hoist: "all",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-this-alias": "error",
|
||||||
|
"@typescript-eslint/no-unused-expressions": "error",
|
||||||
|
"@typescript-eslint/no-use-before-define": "off",
|
||||||
|
"@typescript-eslint/no-var-requires": "error",
|
||||||
|
"@typescript-eslint/prefer-for-of": "error",
|
||||||
|
"@typescript-eslint/prefer-function-type": "error",
|
||||||
|
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||||
|
"@typescript-eslint/prefer-readonly": "error",
|
||||||
|
"@typescript-eslint/triple-slash-reference": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
path: "always",
|
||||||
|
types: "prefer-import",
|
||||||
|
lib: "always",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/typedef": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
parameter: true,
|
||||||
|
propertyDeclaration: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/unified-signatures": "error",
|
||||||
|
"arrow-body-style": "error",
|
||||||
|
complexity: "off",
|
||||||
|
"consistent-return": "error",
|
||||||
|
"constructor-super": "error",
|
||||||
|
curly: "error",
|
||||||
|
"dot-notation": "off",
|
||||||
|
eqeqeq: ["error", "smart"],
|
||||||
|
"guard-for-in": "error",
|
||||||
|
"id-denylist": ["error", "any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"],
|
||||||
|
"id-match": "error",
|
||||||
|
"import/no-default-export": "error",
|
||||||
|
"import/no-extraneous-dependencies": "off",
|
||||||
|
"import/no-internal-modules": "off",
|
||||||
|
"import/order": "error",
|
||||||
|
indent: "off",
|
||||||
|
"jsdoc/check-alignment": "error",
|
||||||
|
"jsdoc/check-indentation": "off",
|
||||||
|
"jsdoc/newline-after-description": "error",
|
||||||
|
"max-classes-per-file": "off",
|
||||||
|
"max-len": "off",
|
||||||
|
"new-parens": "error",
|
||||||
|
"no-bitwise": "error",
|
||||||
|
"no-caller": "error",
|
||||||
|
"no-cond-assign": "error",
|
||||||
|
"no-console": "error",
|
||||||
|
"no-debugger": "error",
|
||||||
|
"no-duplicate-case": "error",
|
||||||
|
"no-duplicate-imports": "error",
|
||||||
|
"no-empty": "error",
|
||||||
|
"no-empty-function": "off",
|
||||||
|
"no-eval": "error",
|
||||||
|
"no-extra-bind": "error",
|
||||||
|
"no-fallthrough": "off",
|
||||||
|
"no-invalid-this": "off",
|
||||||
|
"no-multiple-empty-lines": "error",
|
||||||
|
"no-new-func": "error",
|
||||||
|
"no-new-wrappers": "error",
|
||||||
|
"no-null/no-null": "error",
|
||||||
|
"no-param-reassign": "error",
|
||||||
|
"no-redeclare": "error",
|
||||||
|
"no-return-await": "error",
|
||||||
|
"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",
|
||||||
|
"no-underscore-dangle": ["error", { allow: ["_attr"] }],
|
||||||
|
"no-unsafe-finally": "error",
|
||||||
|
"no-unused-expressions": "off",
|
||||||
|
"no-unused-labels": "error",
|
||||||
|
"no-use-before-define": "off",
|
||||||
|
"no-useless-constructor": "error",
|
||||||
|
"no-var": "error",
|
||||||
|
"object-shorthand": "off",
|
||||||
|
"one-var": ["error", "never"],
|
||||||
|
"prefer-arrow/prefer-arrow-functions": "error",
|
||||||
|
"prefer-const": "error",
|
||||||
|
"prefer-object-spread": "error",
|
||||||
|
radix: "error",
|
||||||
|
"space-in-parens": ["error", "never"],
|
||||||
|
"spaced-comment": [
|
||||||
|
"error",
|
||||||
|
"always",
|
||||||
|
{
|
||||||
|
markers: ["/"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"unicorn/filename-case": "error",
|
||||||
|
"unicorn/prefer-ternary": "error",
|
||||||
|
"use-isnan": "error",
|
||||||
|
"valid-typeof": "off",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": "off",
|
||||||
|
"functional/immutable-data": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
assumeTypes: true,
|
||||||
|
ignoreImmediateMutation: true,
|
||||||
|
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"functional/no-method-signature": "error",
|
||||||
|
"functional/no-mixed-type": "error",
|
||||||
|
"functional/prefer-readonly-type": "error",
|
||||||
|
"no-unused-vars": ["error", { argsIgnorePattern: "^[_]+$" }],
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ["*.spec.ts"],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-unused-expressions": "off",
|
||||||
|
"@typescript-eslint/dot-notation": "off",
|
||||||
|
"prefer-destructuring": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
27
.github/workflows/demos.yml
vendored
27
.github/workflows/demos.yml
vendored
@ -689,3 +689,30 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
xml-file: build/extracted-doc/word/document.xml
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
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
|
||||||
|
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"check-coverage": true,
|
"check-coverage": true,
|
||||||
"statements": 99.62,
|
"statements": 99.79,
|
||||||
"branches": 96.81,
|
"branches": 98.41,
|
||||||
"functions": 99.82,
|
"functions": 100,
|
||||||
"lines": 99.62,
|
"lines": 99.73,
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
],
|
],
|
||||||
|
4
.vscode/extensions.json
vendored
4
.vscode/extensions.json
vendored
@ -1,5 +1,3 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": ["streetsidesoftware.code-spell-checker", "dbaeumer.vscode-eslint"]
|
||||||
"streetsidesoftware.code-spell-checker"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
@ -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://codepen.io/dolanmiu/pen/RwNeObg
|
||||||
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
- 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-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
|
||||||
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Simple example to add text to a document
|
// Simple example to add text to a document
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -14,9 +14,10 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Foo Bar",
|
text: "Foo Bar",
|
||||||
bold: true,
|
bold: true,
|
||||||
|
size: 40,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Generate a CV
|
// Generate a CV
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
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
|
// tslint:disable:no-shadowed-variable
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ class DocumentCreator {
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: `\t${dateText}`,
|
children: [new Tab(), dateText],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Export to base64 string - Useful in a browser environment.
|
// Export to base64 string - Useful in a browser environment.
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -15,7 +15,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tBar",
|
children: [new Tab(), "Bar"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -82,6 +82,32 @@ const doc = new Document({
|
|||||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
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: {
|
numbering: {
|
||||||
@ -169,6 +195,14 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "and back to normal.",
|
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({
|
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",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Example of making content of section vertically aligned
|
// Example of making content of section vertically aligned
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
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({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -18,7 +18,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -25,6 +25,11 @@ const doc = new Document({
|
|||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
},
|
},
|
||||||
|
altText: {
|
||||||
|
title: "This is an ultimate title",
|
||||||
|
description: "This is an ultimate image",
|
||||||
|
name: "My Ultimate Image",
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
MathSubScript,
|
MathSubScript,
|
||||||
MathSubSuperScript,
|
MathSubSuperScript,
|
||||||
MathSum,
|
MathSum,
|
||||||
|
MathIntegral,
|
||||||
MathSuperScript,
|
MathSuperScript,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
@ -90,6 +91,35 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathIntegral({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new Math({
|
new Math({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Change background colour of whole document
|
// Change background colour of whole document
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
background: {
|
background: {
|
||||||
@ -19,7 +19,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Example of how to change page borders
|
// Example of how to change page borders
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
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({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -25,7 +25,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
PageNumber,
|
PageNumber,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
ShadingType,
|
ShadingType,
|
||||||
|
Tab,
|
||||||
TextRun,
|
TextRun,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
bold: true,
|
bold: true,
|
||||||
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
children: [new Tab(), "use Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
bold: true,
|
bold: true,
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
HorizontalPositionAlign,
|
HorizontalPositionAlign,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
|
Tab,
|
||||||
TextRun,
|
TextRun,
|
||||||
VerticalPositionAlign,
|
VerticalPositionAlign,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
@ -67,7 +68,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -7,12 +7,31 @@ const doc = new Document({
|
|||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
children: [
|
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({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new TextRun("我今天遛狗去公园"),
|
new TextRun("我今天遛狗去公园"),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
space: SpaceType.PRESERVE,
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -23,7 +42,6 @@ const doc = new Document({
|
|||||||
),
|
),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
space: SpaceType.PRESERVE,
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
30
demo/74-nodejs-stream.ts
Normal file
30
demo/74-nodejs-stream.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [new Tab(), "Github is the best"],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stream = Packer.toStream(doc);
|
||||||
|
stream.pipe(fs.createWriteStream("My Document.docx"));
|
80
demo/75-tab-stops.ts
Normal file
80
demo/75-tab-stops.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Exporting the document as a stream
|
||||||
|
// 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";
|
||||||
|
|
||||||
|
const columnWidth = TabStopPosition.MAX / 4;
|
||||||
|
const receiptTabStops = [
|
||||||
|
// no need to define first left tab column
|
||||||
|
// the right aligned tab column position should point to the end of column
|
||||||
|
// i.e. in this case
|
||||||
|
// (end position of 1st) + (end position of current)
|
||||||
|
// columnWidth + columnWidth = columnWidth * 2
|
||||||
|
|
||||||
|
{ type: TabStopType.RIGHT, position: columnWidth * 2 },
|
||||||
|
{ type: TabStopType.RIGHT, position: columnWidth * 3 },
|
||||||
|
{ type: TabStopType.RIGHT, position: TabStopPosition.MAX },
|
||||||
|
],
|
||||||
|
twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
children: [new TextRun("Receipt 001")],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: twoTabStops,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "To Bob.\tBy Alice.",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: twoTabStops,
|
||||||
|
children: [new TextRun("Foo Inc\tBar Inc")],
|
||||||
|
}),
|
||||||
|
new Paragraph({ text: "" }),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Item\tPrice\tQuantity\tSub-total",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "\t\t\tTotal: 200",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stream = Packer.toStream(doc);
|
||||||
|
stream.pipe(fs.createWriteStream("My Document.docx"));
|
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/79-thai-distributed.ts
Normal file
49
demo/79-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);
|
||||||
|
});
|
@ -24,7 +24,7 @@
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new docx.TextRun({
|
new docx.TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new docx.Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
- [Document](usage/document.md)
|
- [Document](usage/document.md)
|
||||||
- [Sections](usage/sections.md)
|
- [Sections](usage/sections.md)
|
||||||
- [Paragraph](usage/paragraph.md)
|
- [Paragraph](usage/paragraph.md)
|
||||||
|
- [Text Frames](usage/text-frames.md)
|
||||||
|
- [Symbols](usage/symbols.md)
|
||||||
- [Text](usage/text.md)
|
- [Text](usage/text.md)
|
||||||
- [Image](usage/images.md)
|
- [Images](usage/images.md)
|
||||||
- [Headers & Footers](usage/headers-and-footers.md)
|
- [Headers & Footers](usage/headers-and-footers.md)
|
||||||
- [Bullet Points](usage/bullet-points.md)
|
- [Bullet Points](usage/bullet-points.md)
|
||||||
- [Hyperlinks](usage/hyperlinks.md)
|
- [Hyperlinks](usage/hyperlinks.md)
|
||||||
@ -23,10 +25,12 @@
|
|||||||
- [Page Numbers](usage/page-numbers.md)
|
- [Page Numbers](usage/page-numbers.md)
|
||||||
- [Change Tracking](usage/change-tracking.md)
|
- [Change Tracking](usage/change-tracking.md)
|
||||||
- [Math](usage/math.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
|
||||||
_ [Styling with JS](usage/styling-with-js.md)
|
- [Styling with JS](usage/styling-with-js.md)
|
||||||
_ [Styling with XML](usage/styling-with-xml.md)
|
- [Styling with XML](usage/styling-with-xml.md)
|
||||||
|
|
||||||
- Exporting
|
- Exporting
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
||||||
|
|
||||||
- Follow the `TSLint` rules
|
- Follow the `ESLint` rules
|
||||||
|
|
||||||
## Always think about the user
|
## Always think about the user
|
||||||
|
|
||||||
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
Put yourself in their position, and imagine how they would feel about the feature you wrote.
|
||||||
|
|
||||||
1. Is it easy to use?
|
1. Is it easy to use?
|
||||||
2. Has it been documented well?
|
2. Has it been documented well?
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1/index.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
name: "docx",
|
name: "docx",
|
||||||
@ -24,6 +25,12 @@
|
|||||||
subMaxLevel: 2,
|
subMaxLevel: 2,
|
||||||
search: "auto",
|
search: "auto",
|
||||||
coverpage: true,
|
coverpage: true,
|
||||||
|
plugins: [
|
||||||
|
// Change to your Carbon property ID
|
||||||
|
// cSpell:disable
|
||||||
|
DocsifyCarbon.create("CEAIP237", "docx"),
|
||||||
|
// cSpell:enable
|
||||||
|
],
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||||
|
@ -22,20 +22,19 @@ const doc = new docx.Document({
|
|||||||
|
|
||||||
### Full list of options:
|
### Full list of options:
|
||||||
|
|
||||||
|
- creator
|
||||||
* creator
|
- description
|
||||||
* description
|
- title
|
||||||
* title
|
- subject
|
||||||
* subject
|
- keywords
|
||||||
* keywords
|
- lastModifiedBy
|
||||||
* lastModifiedBy
|
- revision
|
||||||
* revision
|
- externalStyles
|
||||||
* externalStyles
|
- styles
|
||||||
* styles
|
- numbering
|
||||||
* numbering
|
- footnotes
|
||||||
* footnotes
|
- hyperlinks
|
||||||
* hyperlinks
|
- background
|
||||||
* background
|
|
||||||
|
|
||||||
### Change background color of Document
|
### 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.
|
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.
|
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` |
|
||||||
|
@ -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
|
## Examples
|
||||||
|
|
||||||
### Add image to the document
|
### Add image to the document
|
||||||
|
|
||||||
Importing Images from file system path
|
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_
|
_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 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_
|
_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 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_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_
|
||||||
|
@ -86,3 +86,34 @@ topLevelP.setNumbering(concrete, 0);
|
|||||||
subP.setNumbering(concrete, 1);
|
subP.setNumbering(concrete, 1);
|
||||||
subSubP.setNumbering(concrete, 2);
|
subSubP.setNumbering(concrete, 2);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Unindent numbering
|
||||||
|
|
||||||
|
Default:1. test
|
||||||
|
|
||||||
|
After:1.test
|
||||||
|
|
||||||
|
Use default numbering have indent,If you want unindent numbering
|
||||||
|
|
||||||
|
How to custom number see the demo:
|
||||||
|
https://runkit.com/dolanmiu/docx-demo3
|
||||||
|
|
||||||
|
```ts
|
||||||
|
|
||||||
|
enum LevelSuffix {
|
||||||
|
NOTHING = "nothing",
|
||||||
|
SPACE = "space",
|
||||||
|
TAB = "tab"
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom numbering
|
||||||
|
const levels=[
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "decimal",
|
||||||
|
text: "%1.",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
suffix: LevelSuffix.NOTHING, // Cancel intent
|
||||||
|
}]
|
||||||
|
|
||||||
|
```
|
||||||
|
@ -60,29 +60,29 @@ const doc = new Document({
|
|||||||
|
|
||||||
This is the list of options for a paragraph. A detailed explanation is below:
|
This is the list of options for a paragraph. A detailed explanation is below:
|
||||||
|
|
||||||
| Property | Type | Mandatory? | Possible Values |
|
| Property | Type | Mandatory? | Possible Values |
|
||||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- |
|
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [text](#text) | `string` | Optional | |
|
| [text](#text) | `string` | Optional | |
|
||||||
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
| [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 |
|
| [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 |
|
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||||
| [outlineLevel](#outline-level) | `number` | Optional | |
|
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||||
| alignment | `AlignmentType` | 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 | |
|
| heading | `HeadingLevel` | Optional | |
|
||||||
| bidirectional | `boolean` | Optional | |
|
| bidirectional | `boolean` | Optional | |
|
||||||
| thematicBreak | `boolean` | Optional | |
|
| thematicBreak | `boolean` | Optional | |
|
||||||
| pageBreakBefore | `boolean` | Optional | |
|
| pageBreakBefore | `boolean` | Optional | |
|
||||||
| contextualSpacing | `boolean` | Optional | |
|
| contextualSpacing | `boolean` | Optional | |
|
||||||
| indent | `IIndentAttributesProperties` | Optional | |
|
| indent | `IIndentAttributesProperties` | Optional | |
|
||||||
| keepLines | `boolean` | Optional | |
|
| keepLines | `boolean` | Optional | |
|
||||||
| keepNext | `boolean` | Optional | |
|
| keepNext | `boolean` | Optional | |
|
||||||
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
||||||
| style | `string` | Optional | |
|
| style | `string` | Optional | |
|
||||||
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||||
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
||||||
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||||
| [widowControl](#widow-control) | `boolean` | Optional | |
|
| [widowControl](#widow-control) | `boolean` | Optional | |
|
||||||
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
||||||
|
|
||||||
## Text
|
## Text
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ const paragraph = new Paragraph({
|
|||||||
|
|
||||||
## Border
|
## Border
|
||||||
|
|
||||||
Add borders to a `Paragraph`. Good for making the `Paragraph` stand out
|
Add borders to a `Paragraph`. Good for making the `Paragraph` stand out. Border top and border bottom can be used as a horizontal rule (also known as horizontal line).
|
||||||
|
|
||||||
#### IBorderPropertyOptions
|
#### IBorderPropertyOptions
|
||||||
|
|
||||||
@ -180,12 +180,14 @@ Adding spacing between paragraphs
|
|||||||
|
|
||||||
### ISpacingProperties
|
### ISpacingProperties
|
||||||
|
|
||||||
| Property | Type | Notes | Possible Values |
|
| Property | Type | Notes | Possible Values |
|
||||||
| -------- | -------------- | -------- | ----------------------------- |
|
| -------- | -------------- | -------- | -------------------------------------- |
|
||||||
| after | `number` | Optional | |
|
| after | `number` | Optional | |
|
||||||
| before | `number` | Optional | |
|
| before | `number` | Optional | |
|
||||||
| line | `number` | Optional | |
|
| line | `number` | Optional | |
|
||||||
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `AUTO` |
|
| 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:**
|
**Example:**
|
||||||
|
|
||||||
|
@ -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
|
## Break
|
||||||
|
|
||||||
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
||||||
|
8096
package-lock.json
generated
8096
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "7.4.1",
|
"version": "7.8.2",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -9,7 +9,7 @@
|
|||||||
"test.coverage": "nyc npm test",
|
"test.coverage": "nyc npm test",
|
||||||
"test.watch": "npm test -- --watch",
|
"test.watch": "npm test -- --watch",
|
||||||
"prepublishOnly": "npm run build --production",
|
"prepublishOnly": "npm run build --production",
|
||||||
"lint": "tslint --project .",
|
"lint": "eslint -c .eslintrc.js --ext .ts src",
|
||||||
"build": "npm run webpack && npm run fix-types",
|
"build": "npm run webpack && npm run fix-types",
|
||||||
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
|
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
|
||||||
"demo": "npm run build && npm run ts-node --skip-project ./demo",
|
"demo": "npm run build && npm run ts-node --skip-project ./demo",
|
||||||
@ -64,18 +64,27 @@
|
|||||||
"homepage": "https://github.com/dolanmiu/docx#readme",
|
"homepage": "https://github.com/dolanmiu/docx#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.15",
|
"@types/chai": "^4.2.15",
|
||||||
"@types/glob": "^7.1.4",
|
"@types/glob": "^8.0.0",
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^10.0.0",
|
||||||
"@types/prompt": "^1.1.1",
|
"@types/prompt": "^1.1.1",
|
||||||
"@types/request-promise": "^4.1.42",
|
"@types/request-promise": "^4.1.42",
|
||||||
"@types/shelljs": "^0.8.9",
|
"@types/shelljs": "^0.8.9",
|
||||||
"@types/sinon": "^10.0.0",
|
"@types/sinon": "^10.0.0",
|
||||||
"@types/unzipper": "^0.10.4",
|
"@types/unzipper": "^0.10.4",
|
||||||
"@types/webpack": "^5.0.0",
|
"@types/webpack": "^5.0.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||||
|
"@typescript-eslint/parser": "^5.36.1",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"chai": "^3.5.0",
|
"chai": "^4.3.6",
|
||||||
"cspell": "^6.2.2",
|
"cspell": "^6.2.2",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
|
"eslint": "^8.23.0",
|
||||||
|
"eslint-plugin-functional": "^4.3.1",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-jsdoc": "^39.3.6",
|
||||||
|
"eslint-plugin-no-null": "^1.0.2",
|
||||||
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||||
|
"eslint-plugin-unicorn": "^45.0.0",
|
||||||
"glob": "^8.0.1",
|
"glob": "^8.0.1",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"mocha": "^10.0.0",
|
"mocha": "^10.0.0",
|
||||||
@ -89,19 +98,17 @@
|
|||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"shelljs": "^0.8.4",
|
"shelljs": "^0.8.4",
|
||||||
"sinon": "^14.0.0",
|
"sinon": "^15.0.0",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"ts-loader": "^9.0.0",
|
"ts-loader": "^9.0.0",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"tsconfig-paths": "^4.0.0",
|
"tsconfig-paths": "^4.0.0",
|
||||||
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-immutable": "^6.0.1",
|
|
||||||
"typedoc": "^0.23.2",
|
"typedoc": "^0.23.2",
|
||||||
"typescript": "4.7.4",
|
"typescript": "4.9.4",
|
||||||
"unzipper": "^0.10.11",
|
"unzipper": "^0.10.11",
|
||||||
"webpack": "^5.28.0",
|
"webpack": "^5.28.0",
|
||||||
"webpack-cli": "^4.6.0"
|
"webpack-cli": "^5.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { IMediaData, Media } from "@file/media";
|
import { IMediaData, Media } from "@file/media";
|
||||||
|
|
||||||
export class ImageReplacer {
|
export class ImageReplacer {
|
||||||
public replace(xmlData: string, mediaData: IMediaData[], offset: number): string {
|
public replace(xmlData: string, mediaData: readonly IMediaData[], offset: number): string {
|
||||||
let currentXmlData = xmlData;
|
let currentXmlData = xmlData;
|
||||||
|
|
||||||
mediaData.forEach((image, i) => {
|
mediaData.forEach((image, i) => {
|
||||||
@ -11,7 +11,7 @@ export class ImageReplacer {
|
|||||||
return currentXmlData;
|
return currentXmlData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMediaData(xmlData: string, media: Media): IMediaData[] {
|
public getMediaData(xmlData: string, media: Media): readonly IMediaData[] {
|
||||||
return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0);
|
return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ describe("Compiler", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#compile()", () => {
|
describe("#compile()", () => {
|
||||||
it("should pack all the content", async function () {
|
it("should pack all the content", function () {
|
||||||
this.timeout(99999999);
|
this.timeout(99999999);
|
||||||
const file = new File({
|
const file = new File({
|
||||||
sections: [],
|
sections: [],
|
||||||
@ -53,7 +53,7 @@ describe("Compiler", () => {
|
|||||||
expect(fileNames).to.include("_rels/.rels");
|
expect(fileNames).to.include("_rels/.rels");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should pack all additional headers and footers", async function () {
|
it("should pack all additional headers and footers", function () {
|
||||||
const file = new File({
|
const file = new File({
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
|
@ -20,10 +20,10 @@ interface IXmlifyedFileMapping {
|
|||||||
readonly Numbering: IXmlifyedFile;
|
readonly Numbering: IXmlifyedFile;
|
||||||
readonly Relationships: IXmlifyedFile;
|
readonly Relationships: IXmlifyedFile;
|
||||||
readonly FileRelationships: IXmlifyedFile;
|
readonly FileRelationships: IXmlifyedFile;
|
||||||
readonly Headers: IXmlifyedFile[];
|
readonly Headers: readonly IXmlifyedFile[];
|
||||||
readonly Footers: IXmlifyedFile[];
|
readonly Footers: readonly IXmlifyedFile[];
|
||||||
readonly HeaderRelationships: IXmlifyedFile[];
|
readonly HeaderRelationships: readonly IXmlifyedFile[];
|
||||||
readonly FooterRelationships: IXmlifyedFile[];
|
readonly FooterRelationships: readonly IXmlifyedFile[];
|
||||||
readonly ContentTypes: IXmlifyedFile;
|
readonly ContentTypes: IXmlifyedFile;
|
||||||
readonly CustomProperties: IXmlifyedFile;
|
readonly CustomProperties: IXmlifyedFile;
|
||||||
readonly AppProperties: IXmlifyedFile;
|
readonly AppProperties: IXmlifyedFile;
|
||||||
@ -38,7 +38,7 @@ export class Compiler {
|
|||||||
private readonly imageReplacer: ImageReplacer;
|
private readonly imageReplacer: ImageReplacer;
|
||||||
private readonly numberingReplacer: NumberingReplacer;
|
private readonly numberingReplacer: NumberingReplacer;
|
||||||
|
|
||||||
constructor() {
|
public constructor() {
|
||||||
this.formatter = new Formatter();
|
this.formatter = new Formatter();
|
||||||
this.imageReplacer = new ImageReplacer();
|
this.imageReplacer = new ImageReplacer();
|
||||||
this.numberingReplacer = new NumberingReplacer();
|
this.numberingReplacer = new NumberingReplacer();
|
||||||
@ -47,15 +47,15 @@ export class Compiler {
|
|||||||
public compile(file: File, prettifyXml?: boolean | PrettifyType): JSZip {
|
public compile(file: File, prettifyXml?: boolean | PrettifyType): JSZip {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
||||||
const map = new Map<string, IXmlifyedFile | IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
||||||
|
|
||||||
for (const [, obj] of map) {
|
for (const [, obj] of map) {
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
for (const subFile of obj) {
|
for (const subFile of obj as readonly IXmlifyedFile[]) {
|
||||||
zip.file(subFile.path, subFile.data);
|
zip.file(subFile.path, subFile.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zip.file(obj.path, obj.data);
|
zip.file((obj as IXmlifyedFile).path, (obj as IXmlifyedFile).data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ConcreteNumbering } from "@file/numbering";
|
import { ConcreteNumbering } from "@file/numbering";
|
||||||
|
|
||||||
export class NumberingReplacer {
|
export class NumberingReplacer {
|
||||||
public replace(xmlData: string, concreteNumberings: ConcreteNumbering[]): string {
|
public replace(xmlData: string, concreteNumberings: readonly ConcreteNumbering[]): string {
|
||||||
let currentXmlData = xmlData;
|
let currentXmlData = xmlData;
|
||||||
|
|
||||||
for (const concreteNumbering of concreteNumberings) {
|
for (const concreteNumbering of concreteNumberings) {
|
||||||
|
@ -37,6 +37,14 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#toString()", () => {
|
||||||
|
it("should return a non-empty string", async () => {
|
||||||
|
const result = await Packer.toString(file);
|
||||||
|
|
||||||
|
assert.isAbove(result.length, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#toBuffer()", () => {
|
describe("#toBuffer()", () => {
|
||||||
it("should create a standard docx file", async function () {
|
it("should create a standard docx file", async function () {
|
||||||
this.timeout(99999999);
|
this.timeout(99999999);
|
||||||
@ -47,7 +55,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -57,7 +65,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -72,7 +80,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -82,14 +90,14 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#toBlob()", () => {
|
describe("#toBlob()", () => {
|
||||||
it("should create a standard docx file", async () => {
|
it("should create a standard docx file", async () => {
|
||||||
// tslint:disable-next-line: no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
// tslint:disable-next-line: no-empty
|
// tslint:disable-next-line: no-empty
|
||||||
generateAsync: () => mock({}),
|
generateAsync: () => mock({}),
|
||||||
@ -100,7 +108,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -110,7 +118,57 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
(Packer as any).compiler.compile.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#toStream()", () => {
|
||||||
|
it("should create a standard docx file", async () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
|
// tslint:disable-next-line: no-empty
|
||||||
|
generateNodeStream: () => ({
|
||||||
|
on: (event: string, cb: () => void) => {
|
||||||
|
if (event === "end") {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
const stream = await Packer.toStream(file);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
stream.on("error", () => {
|
||||||
|
reject(new Error());
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on("end", () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle exception if it throws any", () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const compiler = stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
|
// tslint:disable-next-line: no-empty
|
||||||
|
on: (event: string, cb: () => void) => {
|
||||||
|
if (event === "error") {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
compiler.throwsException();
|
||||||
|
try {
|
||||||
|
Packer.toStream(file);
|
||||||
|
} catch (error) {
|
||||||
|
assert.isDefined(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Stream } from "stream";
|
||||||
import { File } from "@file/file";
|
import { File } from "@file/file";
|
||||||
|
|
||||||
import { Compiler } from "./next-compiler";
|
import { Compiler } from "./next-compiler";
|
||||||
@ -13,6 +14,17 @@ export enum PrettifyType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Packer {
|
export class Packer {
|
||||||
|
public static async toString(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
||||||
|
const zip = this.compiler.compile(file, prettify);
|
||||||
|
const zipData = await zip.generateAsync({
|
||||||
|
type: "string",
|
||||||
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
compression: "DEFLATE",
|
||||||
|
});
|
||||||
|
|
||||||
|
return zipData;
|
||||||
|
}
|
||||||
|
|
||||||
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> {
|
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> {
|
||||||
const zip = this.compiler.compile(file, prettify);
|
const zip = this.compiler.compile(file, prettify);
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
@ -46,5 +58,17 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static toStream(file: File, prettify?: boolean | PrettifyType): Stream {
|
||||||
|
const zip = this.compiler.compile(file, prettify);
|
||||||
|
const zipData = zip.generateNodeStream({
|
||||||
|
type: "nodebuffer",
|
||||||
|
streamFiles: true,
|
||||||
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
compression: "DEFLATE",
|
||||||
|
});
|
||||||
|
|
||||||
|
return zipData;
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly compiler = new Compiler();
|
private static readonly compiler = new Compiler();
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { AppPropertiesAttributes } from "./app-properties-attributes";
|
import { AppPropertiesAttributes } from "./app-properties-attributes";
|
||||||
|
|
||||||
export class AppProperties extends XmlComponent {
|
export class AppProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("Properties");
|
super("Properties");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -33,7 +33,7 @@ export interface IBorderOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BorderElement extends XmlComponent {
|
export class BorderElement extends XmlComponent {
|
||||||
constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
|
public constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
|
||||||
super(elementName);
|
super(elementName);
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new BordersAttributes({
|
new BordersAttributes({
|
||||||
|
@ -4,7 +4,7 @@ import { Default } from "./default/default";
|
|||||||
import { Override } from "./override/override";
|
import { Override } from "./override/override";
|
||||||
|
|
||||||
export class ContentTypes extends XmlComponent {
|
export class ContentTypes extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("Types");
|
super("Types");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { DefaultAttributes } from "./default-attributes";
|
import { DefaultAttributes } from "./default-attributes";
|
||||||
|
|
||||||
export class Default extends XmlComponent {
|
export class Default extends XmlComponent {
|
||||||
constructor(contentType: string, extension?: string) {
|
public constructor(contentType: string, extension?: string) {
|
||||||
super("Default");
|
super("Default");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { OverrideAttributes } from "./override-attributes";
|
import { OverrideAttributes } from "./override-attributes";
|
||||||
|
|
||||||
export class Override extends XmlComponent {
|
export class Override extends XmlComponent {
|
||||||
constructor(contentType: string, partName?: string) {
|
public constructor(contentType: string, partName?: string) {
|
||||||
super("Override");
|
super("Override");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { ICommentsOptions } from "@file/paragraph/run/comment-run";
|
import { ICommentsOptions } from "@file/paragraph/run/comment-run";
|
||||||
|
import { ICompatibilityOptions } from "@file/settings/compatibility";
|
||||||
import { StringContainer, XmlComponent } from "@file/xml-components";
|
import { StringContainer, XmlComponent } from "@file/xml-components";
|
||||||
import { dateTimeValue } from "@util/values";
|
import { dateTimeValue } from "@util/values";
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ import { Paragraph } from "../paragraph";
|
|||||||
import { IStylesOptions } from "../styles";
|
import { IStylesOptions } from "../styles";
|
||||||
|
|
||||||
export interface IPropertiesOptions {
|
export interface IPropertiesOptions {
|
||||||
readonly sections: ISectionOptions[];
|
readonly sections: readonly ISectionOptions[];
|
||||||
readonly title?: string;
|
readonly title?: string;
|
||||||
readonly subject?: string;
|
readonly subject?: string;
|
||||||
readonly creator?: string;
|
readonly creator?: string;
|
||||||
@ -26,7 +27,7 @@ export interface IPropertiesOptions {
|
|||||||
readonly comments?: ICommentsOptions;
|
readonly comments?: ICommentsOptions;
|
||||||
readonly footnotes?: {
|
readonly footnotes?: {
|
||||||
readonly [key: string]: {
|
readonly [key: string]: {
|
||||||
readonly children: Paragraph[];
|
readonly children: readonly Paragraph[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
readonly background?: IDocumentBackgroundOptions;
|
readonly background?: IDocumentBackgroundOptions;
|
||||||
@ -35,7 +36,8 @@ export interface IPropertiesOptions {
|
|||||||
readonly updateFields?: boolean;
|
readonly updateFields?: boolean;
|
||||||
};
|
};
|
||||||
readonly compatabilityModeVersion?: number;
|
readonly compatabilityModeVersion?: number;
|
||||||
readonly customProperties?: ICustomPropertyOptions[];
|
readonly compatibility?: ICompatibilityOptions;
|
||||||
|
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ export interface IPropertiesOptions {
|
|||||||
/* cSpell:enable */
|
/* cSpell:enable */
|
||||||
|
|
||||||
export class CoreProperties extends XmlComponent {
|
export class CoreProperties extends XmlComponent {
|
||||||
constructor(options: Omit<IPropertiesOptions, "sections">) {
|
public constructor(options: Omit<IPropertiesOptions, "sections">) {
|
||||||
super("cp:coreProperties");
|
super("cp:coreProperties");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new DocumentAttributes({
|
new DocumentAttributes({
|
||||||
@ -102,7 +104,7 @@ export class CoreProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TimestampElement extends XmlComponent {
|
class TimestampElement extends XmlComponent {
|
||||||
constructor(name: string) {
|
public constructor(name: string) {
|
||||||
super(name);
|
super(name);
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new DocumentAttributes({
|
new DocumentAttributes({
|
||||||
|
@ -3,11 +3,12 @@ import { CustomPropertiesAttributes } from "./custom-properties-attributes";
|
|||||||
import { CustomProperty, ICustomPropertyOptions } from "./custom-property";
|
import { CustomProperty, ICustomPropertyOptions } from "./custom-property";
|
||||||
|
|
||||||
export class CustomProperties extends XmlComponent {
|
export class CustomProperties extends XmlComponent {
|
||||||
// tslint:disable-next-line:readonly-keyword
|
// eslint-disable-next-line functional/prefer-readonly-type
|
||||||
private nextId: number;
|
private nextId: number;
|
||||||
|
// eslint-disable-next-line functional/prefer-readonly-type
|
||||||
private readonly properties: CustomProperty[] = [];
|
private readonly properties: CustomProperty[] = [];
|
||||||
|
|
||||||
constructor(properties: ICustomPropertyOptions[]) {
|
public constructor(properties: readonly ICustomPropertyOptions[]) {
|
||||||
super("Properties");
|
super("Properties");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
@ -32,6 +33,7 @@ export class CustomProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public addCustomProperty(property: ICustomPropertyOptions): void {
|
public addCustomProperty(property: ICustomPropertyOptions): void {
|
||||||
|
// eslint-disable-next-line functional/immutable-data
|
||||||
this.properties.push(new CustomProperty(this.nextId++, property));
|
this.properties.push(new CustomProperty(this.nextId++, property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ export interface ICustomPropertyOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CustomProperty extends XmlComponent {
|
export class CustomProperty extends XmlComponent {
|
||||||
constructor(id: number, properties: ICustomPropertyOptions) {
|
public constructor(id: number, properties: ICustomPropertyOptions) {
|
||||||
super("property");
|
super("property");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CustomPropertyAttributes({
|
new CustomPropertyAttributes({
|
||||||
@ -21,7 +21,7 @@ export class CustomProperty extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CustomPropertyValue extends XmlComponent {
|
export class CustomPropertyValue extends XmlComponent {
|
||||||
constructor(value: string) {
|
public constructor(value: string) {
|
||||||
super("vt:lpwstr");
|
super("vt:lpwstr");
|
||||||
this.root.push(value);
|
this.root.push(value);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,7 @@ describe("DocumentWrapper", () => {
|
|||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const file = new DocumentWrapper({ background: {} });
|
const file = new DocumentWrapper({ background: {} });
|
||||||
|
|
||||||
// tslint:disable-next-line: no-unused-expression
|
|
||||||
expect(file.View).to.be.ok;
|
expect(file.View).to.be.ok;
|
||||||
// tslint:disable-next-line: no-unused-expression
|
|
||||||
expect(file.Relationships).to.be.ok;
|
expect(file.Relationships).to.be.ok;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,7 @@ export class DocumentWrapper implements IViewWrapper {
|
|||||||
private readonly document: Document;
|
private readonly document: Document;
|
||||||
private readonly relationships: Relationships;
|
private readonly relationships: Relationships;
|
||||||
|
|
||||||
constructor(options: IDocumentOptions) {
|
public constructor(options: IDocumentOptions) {
|
||||||
this.document = new Document(options);
|
this.document = new Document(options);
|
||||||
this.relationships = new Relationships();
|
this.relationships = new Relationships();
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
|||||||
import { ISectionPropertiesOptions, SectionProperties } from "./section-properties/section-properties";
|
import { ISectionPropertiesOptions, SectionProperties } from "./section-properties/section-properties";
|
||||||
|
|
||||||
export class Body extends XmlComponent {
|
export class Body extends XmlComponent {
|
||||||
|
// eslint-disable-next-line functional/prefer-readonly-type
|
||||||
private readonly sections: SectionProperties[] = [];
|
private readonly sections: SectionProperties[] = [];
|
||||||
|
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("w:body");
|
super("w:body");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ export class Body extends XmlComponent {
|
|||||||
* The spec says:
|
* The spec says:
|
||||||
* - section element should be in the last paragraph of the section
|
* - section element should be in the last paragraph of the section
|
||||||
* - last section should be direct child of body
|
* - last section should be direct child of body
|
||||||
|
*
|
||||||
* @param options new section options
|
* @param options new section options
|
||||||
*/
|
*/
|
||||||
public addSection(options: ISectionPropertiesOptions): void {
|
public addSection(options: ISectionPropertiesOptions): void {
|
||||||
|
@ -14,7 +14,7 @@ export class ColumnAttributes extends XmlAttributeComponent<IColumnAttributes> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Column extends XmlComponent {
|
export class Column extends XmlComponent {
|
||||||
constructor({ width, space }: IColumnAttributes) {
|
public constructor({ width, space }: IColumnAttributes) {
|
||||||
super("w:col");
|
super("w:col");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new ColumnAttributes({
|
new ColumnAttributes({
|
||||||
|
@ -13,6 +13,13 @@ describe("Columns", () => {
|
|||||||
expect(tree["w:cols"]).to.deep.equal({ _attr: { "w:num": 3, "w:space": 720 } });
|
expect(tree["w:cols"]).to.deep.equal({ _attr: { "w:num": 3, "w:space": 720 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should create set space and count to undefined if they are undefined", () => {
|
||||||
|
const columns = new Columns({});
|
||||||
|
const tree = new Formatter().format(columns);
|
||||||
|
|
||||||
|
expect(tree["w:cols"]).to.deep.equal({ _attr: {} });
|
||||||
|
});
|
||||||
|
|
||||||
it("should ignore individual column attributes if equalWidth is true", () => {
|
it("should ignore individual column attributes if equalWidth is true", () => {
|
||||||
const unequalColumns = [new Column({ width: 1000, space: 400 }), new Column({ width: 2000 })];
|
const unequalColumns = [new Column({ width: 1000, space: 400 }), new Column({ width: 2000 })];
|
||||||
const columns = new Columns({ count: 3, space: 720, equalWidth: true, children: unequalColumns });
|
const columns = new Columns({ count: 3, space: 720, equalWidth: true, children: unequalColumns });
|
||||||
|
@ -17,7 +17,7 @@ export interface IColumnsAttributes {
|
|||||||
readonly count?: number;
|
readonly count?: number;
|
||||||
readonly separate?: boolean;
|
readonly separate?: boolean;
|
||||||
readonly equalWidth?: boolean;
|
readonly equalWidth?: boolean;
|
||||||
readonly children?: Column[];
|
readonly children?: readonly Column[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||||
@ -30,7 +30,7 @@ export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Columns extends XmlComponent {
|
export class Columns extends XmlComponent {
|
||||||
constructor({ space, count, separate, equalWidth, children }: IColumnsAttributes) {
|
public constructor({ space, count, separate, equalWidth, children }: IColumnsAttributes) {
|
||||||
super("w:cols");
|
super("w:cols");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new ColumnsAttributes({
|
new ColumnsAttributes({
|
||||||
|
@ -38,7 +38,7 @@ export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesP
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DocumentGrid extends XmlComponent {
|
export class DocumentGrid extends XmlComponent {
|
||||||
constructor(linePitch: number, charSpace?: number, type?: DocumentGridType) {
|
public constructor(linePitch: number, charSpace?: number, type?: DocumentGridType) {
|
||||||
super("w:docGrid");
|
super("w:docGrid");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -52,7 +52,7 @@ export enum HeaderFooterType {
|
|||||||
FOOTER = "w:footerReference",
|
FOOTER = "w:footerReference",
|
||||||
}
|
}
|
||||||
export class HeaderFooterReference extends XmlComponent {
|
export class HeaderFooterReference extends XmlComponent {
|
||||||
constructor(type: HeaderFooterType, options: IHeaderFooterOptions) {
|
public constructor(type: HeaderFooterType, options: IHeaderFooterOptions) {
|
||||||
super(type);
|
super(type);
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -39,7 +39,7 @@ export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttri
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class LineNumberType extends XmlComponent {
|
export class LineNumberType extends XmlComponent {
|
||||||
constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
public constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
||||||
super("w:lnNumType");
|
super("w:lnNumType");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new LineNumberAttributes({
|
new LineNumberAttributes({
|
||||||
|
@ -71,11 +71,11 @@ class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes>
|
|||||||
// <xsd:attribute name="offsetFrom" type="ST_PageBorderOffset" use="optional" default="text"/>
|
// <xsd:attribute name="offsetFrom" type="ST_PageBorderOffset" use="optional" default="text"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
||||||
constructor(options?: IPageBordersOptions) {
|
public constructor(options?: IPageBordersOptions) {
|
||||||
super("w:pgBorders");
|
super("w:pgBorders");
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.pageBorders) {
|
if (options.pageBorders) {
|
||||||
|
@ -33,7 +33,7 @@ export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttri
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PageMargin extends XmlComponent {
|
export class PageMargin extends XmlComponent {
|
||||||
constructor(
|
public constructor(
|
||||||
top: number | string,
|
top: number | string,
|
||||||
right: number | string,
|
right: number | string,
|
||||||
bottom: number | string,
|
bottom: number | string,
|
||||||
|
@ -41,7 +41,7 @@ export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberT
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
export class PageNumberType extends XmlComponent {
|
export class PageNumberType extends XmlComponent {
|
||||||
constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
|
public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
|
||||||
super("w:pgNumType");
|
super("w:pgNumType");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageNumberTypeAttributes({
|
new PageNumberTypeAttributes({
|
||||||
|
@ -33,7 +33,7 @@ export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttribute
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PageSize extends XmlComponent {
|
export class PageSize extends XmlComponent {
|
||||||
constructor(width: number | string, height: number | string, orientation: PageOrientation) {
|
public constructor(width: number | string, height: number | string, orientation: PageOrientation) {
|
||||||
super("w:pgSz");
|
super("w:pgSz");
|
||||||
|
|
||||||
const flip = orientation === PageOrientation.LANDSCAPE;
|
const flip = orientation === PageOrientation.LANDSCAPE;
|
||||||
|
@ -10,7 +10,7 @@ class PageTextDirectionAttributes extends XmlAttributeComponent<{ readonly val:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PageTextDirection extends XmlComponent {
|
export class PageTextDirection extends XmlComponent {
|
||||||
constructor(value: PageTextDirectionType) {
|
public constructor(value: PageTextDirectionType) {
|
||||||
super("w:textDirection");
|
super("w:textDirection");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -30,7 +30,7 @@ export class SectionTypeAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Type extends XmlComponent {
|
export class Type extends XmlComponent {
|
||||||
constructor(value: SectionType) {
|
public constructor(value: SectionType) {
|
||||||
super("w:type");
|
super("w:type");
|
||||||
this.root.push(new SectionTypeAttributes({ val: value }));
|
this.root.push(new SectionTypeAttributes({ val: value }));
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ export const sectionPageSizeDefaults = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class SectionProperties extends XmlComponent {
|
export class SectionProperties extends XmlComponent {
|
||||||
constructor({
|
public constructor({
|
||||||
page: {
|
page: {
|
||||||
size: {
|
size: {
|
||||||
width = sectionPageSizeDefaults.WIDTH,
|
width = sectionPageSizeDefaults.WIDTH,
|
||||||
|
@ -63,7 +63,7 @@ export interface IDocumentBackgroundOptions {
|
|||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export class DocumentBackground extends XmlComponent {
|
export class DocumentBackground extends XmlComponent {
|
||||||
constructor(options: IDocumentBackgroundOptions) {
|
public constructor(options: IDocumentBackgroundOptions) {
|
||||||
super("w:background");
|
super("w:background");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -8,7 +8,7 @@ import { DocumentAttributes } from "./document-attributes";
|
|||||||
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
|
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
|
||||||
|
|
||||||
export interface IDocumentOptions {
|
export interface IDocumentOptions {
|
||||||
readonly background: IDocumentBackgroundOptions;
|
readonly background?: IDocumentBackgroundOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:element name="document" type="CT_Document"/>
|
// <xsd:element name="document" type="CT_Document"/>
|
||||||
@ -33,7 +33,7 @@ export interface IDocumentOptions {
|
|||||||
export class Document extends XmlComponent {
|
export class Document extends XmlComponent {
|
||||||
private readonly body: Body;
|
private readonly body: Body;
|
||||||
|
|
||||||
constructor(options: IDocumentOptions) {
|
public constructor(options: IDocumentOptions) {
|
||||||
super("w:document");
|
super("w:document");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new DocumentAttributes({
|
new DocumentAttributes({
|
||||||
@ -73,7 +73,9 @@ export class Document extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.body = new Body();
|
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);
|
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";
|
import { Utility } from "tests/utility";
|
||||||
|
|
||||||
@ -6,8 +10,8 @@ import { IDrawingOptions } from "../drawing";
|
|||||||
import { TextWrappingType } from "../text-wrap";
|
import { TextWrappingType } from "../text-wrap";
|
||||||
import { Anchor } from "./anchor";
|
import { Anchor } from "./anchor";
|
||||||
|
|
||||||
function createAnchor(drawingOptions: IDrawingOptions): Anchor {
|
const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||||
return new Anchor(
|
new Anchor(
|
||||||
{
|
{
|
||||||
fileName: "test.png",
|
fileName: "test.png",
|
||||||
stream: new Buffer(""),
|
stream: new Buffer(""),
|
||||||
@ -34,9 +38,16 @@ function createAnchor(drawingOptions: IDrawingOptions): Anchor {
|
|||||||
},
|
},
|
||||||
drawingOptions,
|
drawingOptions,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
describe("Anchor", () => {
|
describe("Anchor", () => {
|
||||||
|
before(() => {
|
||||||
|
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
|
||||||
|
});
|
||||||
|
|
||||||
let anchor: Anchor;
|
let anchor: Anchor;
|
||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
@ -363,5 +374,236 @@ describe("Anchor", () => {
|
|||||||
relativeHeight: 120,
|
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": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -37,7 +37,7 @@ import { AnchorAttributes } from "./anchor-attributes";
|
|||||||
// <xsd:attribute name="allowOverlap" type="xsd:boolean" use="required"/>
|
// <xsd:attribute name="allowOverlap" type="xsd:boolean" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class Anchor extends XmlComponent {
|
export class Anchor extends XmlComponent {
|
||||||
constructor(mediaData: IMediaData, transform: IMediaDataTransformation, drawingOptions: IDrawingOptions) {
|
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation, drawingOptions: IDrawingOptions) {
|
||||||
super("wp:anchor");
|
super("wp:anchor");
|
||||||
|
|
||||||
const floating: IFloating = {
|
const floating: IFloating = {
|
||||||
@ -90,7 +90,7 @@ export class Anchor extends XmlComponent {
|
|||||||
this.root.push(new WrapNone());
|
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 GraphicFrameProperties());
|
||||||
this.root.push(new Graphic(mediaData, transform));
|
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",
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,15 +1,36 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { DocPropertiesAttributes } from "./doc-properties-attributes";
|
import { uniqueNumericId } from "@util/convenience-functions";
|
||||||
|
|
||||||
|
class DocPropertiesAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly id?: number;
|
||||||
|
readonly name?: string;
|
||||||
|
readonly description?: string;
|
||||||
|
readonly title?: string;
|
||||||
|
}> {
|
||||||
|
protected readonly xmlKeys = {
|
||||||
|
id: "id",
|
||||||
|
name: "name",
|
||||||
|
description: "descr",
|
||||||
|
title: "title",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DocPropertiesOptions {
|
||||||
|
readonly name: string;
|
||||||
|
readonly description: string;
|
||||||
|
readonly title: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class DocProperties extends XmlComponent {
|
export class DocProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) {
|
||||||
super("wp:docPr");
|
super("wp:docPr");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new DocPropertiesAttributes({
|
new DocPropertiesAttributes({
|
||||||
id: 0,
|
id: uniqueNumericId(),
|
||||||
name: "",
|
name,
|
||||||
descr: "",
|
description,
|
||||||
|
title,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
import { SinonStub, stub } from "sinon";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
|
import * as convenienceFunctions from "@util/convenience-functions";
|
||||||
|
|
||||||
import { Drawing, IDrawingOptions } from "./drawing";
|
import { Drawing, IDrawingOptions } from "./drawing";
|
||||||
|
|
||||||
const imageBase64Data = `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`;
|
const imageBase64Data = `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`;
|
||||||
|
|
||||||
function createDrawing(drawingOptions?: IDrawingOptions): Drawing {
|
const createDrawing = (drawingOptions?: IDrawingOptions): Drawing =>
|
||||||
return new Drawing(
|
new Drawing(
|
||||||
{
|
{
|
||||||
fileName: "test.jpg",
|
fileName: "test.jpg",
|
||||||
stream: Buffer.from(imageBase64Data, "base64"),
|
stream: Buffer.from(imageBase64Data, "base64"),
|
||||||
@ -24,9 +26,16 @@ function createDrawing(drawingOptions?: IDrawingOptions): Drawing {
|
|||||||
},
|
},
|
||||||
drawingOptions,
|
drawingOptions,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
describe("Drawing", () => {
|
describe("Drawing", () => {
|
||||||
|
before(() => {
|
||||||
|
stub(convenienceFunctions, "uniqueNumericId").callsFake(() => 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
(convenienceFunctions.uniqueNumericId as SinonStub).restore();
|
||||||
|
});
|
||||||
|
|
||||||
let currentBreak: Drawing;
|
let currentBreak: Drawing;
|
||||||
|
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
@ -69,6 +78,7 @@ describe("Drawing", () => {
|
|||||||
descr: "",
|
descr: "",
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "",
|
name: "",
|
||||||
|
title: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -299,6 +309,7 @@ describe("Drawing", () => {
|
|||||||
descr: "",
|
descr: "",
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "",
|
name: "",
|
||||||
|
title: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { IMediaData } from "@file/media";
|
import { IMediaData } from "@file/media";
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { Anchor } from "./anchor";
|
import { Anchor } from "./anchor";
|
||||||
|
import { DocPropertiesOptions } from "./doc-properties/doc-properties";
|
||||||
import { IFloating } from "./floating";
|
import { IFloating } from "./floating";
|
||||||
import { Inline } from "./inline";
|
import { Inline } from "./inline";
|
||||||
|
|
||||||
@ -13,6 +15,7 @@ export interface IDistance {
|
|||||||
|
|
||||||
export interface IDrawingOptions {
|
export interface IDrawingOptions {
|
||||||
readonly floating?: IFloating;
|
readonly floating?: IFloating;
|
||||||
|
readonly docProperties?: DocPropertiesOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Drawing">
|
// <xsd:complexType name="CT_Drawing">
|
||||||
@ -25,11 +28,15 @@ export interface IDrawingOptions {
|
|||||||
export class Drawing extends XmlComponent {
|
export class Drawing extends XmlComponent {
|
||||||
private readonly inline: Inline;
|
private readonly inline: Inline;
|
||||||
|
|
||||||
constructor(imageData: IMediaData, drawingOptions: IDrawingOptions = {}) {
|
public constructor(imageData: IMediaData, drawingOptions: IDrawingOptions = {}) {
|
||||||
super("w:drawing");
|
super("w:drawing");
|
||||||
|
|
||||||
if (!drawingOptions.floating) {
|
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);
|
this.root.push(this.inline);
|
||||||
} else {
|
} else {
|
||||||
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
|
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { EffectExtentAttributes } from "./effect-extent-attributes";
|
import { EffectExtentAttributes } from "./effect-extent-attributes";
|
||||||
|
|
||||||
export class EffectExtent extends XmlComponent {
|
export class EffectExtent extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("wp:effectExtent");
|
super("wp:effectExtent");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -5,7 +5,7 @@ import { ExtentAttributes } from "./extent-attributes";
|
|||||||
export class Extent extends XmlComponent {
|
export class Extent extends XmlComponent {
|
||||||
private readonly attributes: ExtentAttributes;
|
private readonly attributes: ExtentAttributes;
|
||||||
|
|
||||||
constructor(x: number, y: number) {
|
public constructor(x: number, y: number) {
|
||||||
super("wp:extent");
|
super("wp:extent");
|
||||||
|
|
||||||
this.attributes = new ExtentAttributes({
|
this.attributes = new ExtentAttributes({
|
||||||
|
@ -3,7 +3,7 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class Align extends XmlComponent {
|
export class Align extends XmlComponent {
|
||||||
constructor(value: HorizontalPositionAlign | VerticalPositionAlign) {
|
public constructor(value: HorizontalPositionAlign | VerticalPositionAlign) {
|
||||||
super("wp:align");
|
super("wp:align");
|
||||||
this.root.push(value);
|
this.root.push(value);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class HorizontalPositionAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class HorizontalPosition extends XmlComponent {
|
export class HorizontalPosition extends XmlComponent {
|
||||||
constructor(horizontalPosition: IHorizontalPositionOptions) {
|
public constructor(horizontalPosition: IHorizontalPositionOptions) {
|
||||||
super("wp:positionH");
|
super("wp:positionH");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class PositionOffset extends XmlComponent {
|
export class PositionOffset extends XmlComponent {
|
||||||
constructor(offsetValue: number) {
|
public constructor(offsetValue: number) {
|
||||||
super("wp:posOffset");
|
super("wp:posOffset");
|
||||||
this.root.push(offsetValue.toString());
|
this.root.push(offsetValue.toString());
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class SimplePosAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SimplePos extends XmlComponent {
|
export class SimplePos extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("wp:simplePos");
|
super("wp:simplePos");
|
||||||
|
|
||||||
// NOTE: It's not fully supported in Microsoft Word, but this element is needed anyway
|
// NOTE: It's not fully supported in Microsoft Word, but this element is needed anyway
|
||||||
|
@ -13,7 +13,7 @@ class VerticalPositionAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class VerticalPosition extends XmlComponent {
|
export class VerticalPosition extends XmlComponent {
|
||||||
constructor(verticalPosition: IVerticalPositionOptions) {
|
public constructor(verticalPosition: IVerticalPositionOptions) {
|
||||||
super("wp:positionV");
|
super("wp:positionV");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes";
|
import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes";
|
||||||
|
|
||||||
export class GraphicFrameLocks extends XmlComponent {
|
export class GraphicFrameLocks extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:graphicFrameLocks");
|
super("a:graphicFrameLocks");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks";
|
import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks";
|
||||||
|
|
||||||
export class GraphicFrameProperties extends XmlComponent {
|
export class GraphicFrameProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("wp:cNvGraphicFramePr");
|
super("wp:cNvGraphicFramePr");
|
||||||
|
|
||||||
this.root.push(new GraphicFrameLocks());
|
this.root.push(new GraphicFrameLocks());
|
||||||
|
@ -7,7 +7,7 @@ import { Pic } from "./pic";
|
|||||||
export class GraphicData extends XmlComponent {
|
export class GraphicData extends XmlComponent {
|
||||||
private readonly pic: Pic;
|
private readonly pic: Pic;
|
||||||
|
|
||||||
constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||||
super("a:graphicData");
|
super("a:graphicData");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -6,7 +6,7 @@ import { SourceRectangle } from "./source-rectangle";
|
|||||||
import { Stretch } from "./stretch";
|
import { Stretch } from "./stretch";
|
||||||
|
|
||||||
export class BlipFill extends XmlComponent {
|
export class BlipFill extends XmlComponent {
|
||||||
constructor(mediaData: IMediaData) {
|
public constructor(mediaData: IMediaData) {
|
||||||
super("pic:blipFill");
|
super("pic:blipFill");
|
||||||
|
|
||||||
this.root.push(new Blip(mediaData));
|
this.root.push(new Blip(mediaData));
|
||||||
|
@ -12,7 +12,7 @@ class BlipAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Blip extends XmlComponent {
|
export class Blip extends XmlComponent {
|
||||||
constructor(mediaData: IMediaData) {
|
public constructor(mediaData: IMediaData) {
|
||||||
super("a:blip");
|
super("a:blip");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new BlipAttributes({
|
new BlipAttributes({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class SourceRectangle extends XmlComponent {
|
export class SourceRectangle extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:srcRect");
|
super("a:srcRect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
class FillRectangle extends XmlComponent {
|
class FillRectangle extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:fillRect");
|
super("a:fillRect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Stretch extends XmlComponent {
|
export class Stretch extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:stretch");
|
super("a:stretch");
|
||||||
this.root.push(new FillRectangle());
|
this.root.push(new FillRectangle());
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { PicLocks } from "./pic-locks/pic-locks";
|
import { PicLocks } from "./pic-locks/pic-locks";
|
||||||
|
|
||||||
export class ChildNonVisualProperties extends XmlComponent {
|
export class ChildNonVisualProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("pic:cNvPicPr");
|
super("pic:cNvPicPr");
|
||||||
|
|
||||||
this.root.push(new PicLocks());
|
this.root.push(new PicLocks());
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { PicLocksAttributes } from "./pic-locks-attributes";
|
import { PicLocksAttributes } from "./pic-locks-attributes";
|
||||||
|
|
||||||
export class PicLocks extends XmlComponent {
|
export class PicLocks extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:picLocks");
|
super("a:picLocks");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PicLocksAttributes({
|
new PicLocksAttributes({
|
||||||
|
@ -3,7 +3,7 @@ import { ChildNonVisualProperties } from "./child-non-visual-pic-properties/chil
|
|||||||
import { NonVisualProperties } from "./non-visual-properties/non-visual-properties";
|
import { NonVisualProperties } from "./non-visual-properties/non-visual-properties";
|
||||||
|
|
||||||
export class NonVisualPicProperties extends XmlComponent {
|
export class NonVisualPicProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("pic:nvPicPr");
|
super("pic:nvPicPr");
|
||||||
|
|
||||||
this.root.push(new NonVisualProperties());
|
this.root.push(new NonVisualProperties());
|
||||||
|
@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
|
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
|
||||||
|
|
||||||
export class NonVisualProperties extends XmlComponent {
|
export class NonVisualProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("pic:cNvPr");
|
super("pic:cNvPr");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -8,7 +8,7 @@ import { PicAttributes } from "./pic-attributes";
|
|||||||
import { ShapeProperties } from "./shape-properties/shape-properties";
|
import { ShapeProperties } from "./shape-properties/shape-properties";
|
||||||
|
|
||||||
export class Pic extends XmlComponent {
|
export class Pic extends XmlComponent {
|
||||||
constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||||
super("pic:pic");
|
super("pic:pic");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -5,7 +5,7 @@ import { ExtentsAttributes } from "./extents-attributes";
|
|||||||
export class Extents extends XmlComponent {
|
export class Extents extends XmlComponent {
|
||||||
private readonly attributes: ExtentsAttributes;
|
private readonly attributes: ExtentsAttributes;
|
||||||
|
|
||||||
constructor(x: number, y: number) {
|
public constructor(x: number, y: number) {
|
||||||
super("a:ext");
|
super("a:ext");
|
||||||
|
|
||||||
this.attributes = new ExtentsAttributes({
|
this.attributes = new ExtentsAttributes({
|
||||||
|
@ -21,7 +21,7 @@ export class FormAttributes extends XmlAttributeComponent<{
|
|||||||
export class Form extends XmlComponent {
|
export class Form extends XmlComponent {
|
||||||
private readonly extents: Extents;
|
private readonly extents: Extents;
|
||||||
|
|
||||||
constructor(options: IMediaDataTransformation) {
|
public constructor(options: IMediaDataTransformation) {
|
||||||
super("a:xfrm");
|
super("a:xfrm");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { OffsetAttributes } from "./off-attributes";
|
import { OffsetAttributes } from "./off-attributes";
|
||||||
|
|
||||||
export class Offset extends XmlComponent {
|
export class Offset extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:off");
|
super("a:off");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class NoFill extends XmlComponent {
|
export class NoFill extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:noFill");
|
super("a:noFill");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { NoFill } from "./no-fill";
|
import { NoFill } from "./no-fill";
|
||||||
|
|
||||||
export class Outline extends XmlComponent {
|
export class Outline extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:ln");
|
super("a:ln");
|
||||||
|
|
||||||
this.root.push(new NoFill());
|
this.root.push(new NoFill());
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class AdjustmentValues extends XmlComponent {
|
export class AdjustmentValues extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:avLst");
|
super("a:avLst");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { AdjustmentValues } from "./adjustment-values/adjustment-values";
|
|||||||
import { PresetGeometryAttributes } from "./preset-geometry-attributes";
|
import { PresetGeometryAttributes } from "./preset-geometry-attributes";
|
||||||
|
|
||||||
export class PresetGeometry extends XmlComponent {
|
export class PresetGeometry extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("a:prstGeom");
|
super("a:prstGeom");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user