Compare commits
247 Commits
7.7.0
...
feature/pa
Author | SHA1 | Date | |
---|---|---|---|
c5a2c1c0cb | |||
d505281a7e | |||
58575342e0 | |||
60ad6d6ab5 | |||
f9dec1cb3c | |||
c713e6f371 | |||
3c55f9fc1f | |||
c9a8a99278 | |||
b309d327f0 | |||
58bad10bfe | |||
26ea6c518f | |||
d4594a97a2 | |||
68f951ef79 | |||
12e29c6a75 | |||
05eedb2ac1 | |||
46ded68369 | |||
b3a53d341d | |||
afcd5e70a1 | |||
ae48999e38 | |||
4c38e45455 | |||
ec847dccf9 | |||
ca47a1dc3f | |||
cc53ff417b | |||
fcba817a4a | |||
bcd8249d17 | |||
bc0a197ba1 | |||
2e16279d7b | |||
87590aedbd | |||
0fef7763d5 | |||
e55698d221 | |||
d410b5e96f | |||
8587601411 | |||
5b67cb21c6 | |||
42fd9d06de | |||
1e0b74fd27 | |||
21934ec85b | |||
b4f01fb6ec | |||
fbf6329500 | |||
41549443c3 | |||
92630af4e1 | |||
4db633da16 | |||
dac02f13ae | |||
1a52dec1c2 | |||
be1ca51162 | |||
768e20bb79 | |||
26b9b15de8 | |||
42713095b6 | |||
3acafeca38 | |||
7ca75c8c5a | |||
c00ad454a9 | |||
16d04eb4d3 | |||
816845f271 | |||
12eeda8d33 | |||
3d622c2ef1 | |||
21a6767c6f | |||
7a7326ec09 | |||
9b3af4e217 | |||
cee0114f81 | |||
03399aedf0 | |||
2739b94bd8 | |||
c720441d62 | |||
00b5898fe0 | |||
0d0940b7a5 | |||
f28c949ac6 | |||
63317d6ac8 | |||
6406ba831f | |||
7a7575964a | |||
d75c833717 | |||
40344b57d9 | |||
6fc26d1da3 | |||
a012a0e418 | |||
bf1a2f3059 | |||
ca316b4e6d | |||
1fb5c581c9 | |||
efa64b451a | |||
38059ea6b9 | |||
c2110622ca | |||
0452959b85 | |||
0eca8389b6 | |||
66e043137b | |||
d684654625 | |||
7749f6b20f | |||
15c9c0ae3e | |||
74fddc2ada | |||
cff866ecdc | |||
e952c02c83 | |||
546983c6ba | |||
c7134564a3 | |||
984a3573eb | |||
defe94a2b2 | |||
e23c8c4b46 | |||
7941ff487a | |||
7b7df33a0f | |||
68b04f2511 | |||
db3e017a7d | |||
c21d45a79e | |||
6defb686bb | |||
f68796dae1 | |||
b1872bcb95 | |||
3006f4d2c1 | |||
7f88a38219 | |||
aeb2487c70 | |||
e42e50dd39 | |||
f4572b9720 | |||
7646f3a845 | |||
e4e5b1e4f6 | |||
a481518470 | |||
2435ebf16e | |||
414fa70e5d | |||
f255d4c141 | |||
4513bb529b | |||
5907132062 | |||
69bf313f18 | |||
fe8b0a6b2b | |||
abcfd79f2f | |||
41e3b078ec | |||
4eb2f92c1f | |||
9bfb5bf681 | |||
473ad2947c | |||
ee28f6ad84 | |||
11bebd42ac | |||
49b4ca67e0 | |||
3282f762df | |||
d335106b46 | |||
cefa01f7ec | |||
b7ba2b3306 | |||
03d5152e7c | |||
af3b7f2613 | |||
1405841565 | |||
211d2dc0d6 | |||
82f431465f | |||
247afe56ce | |||
91e874eee5 | |||
ff67c3660b | |||
58c580b9ca | |||
a9da151026 | |||
83c72d0dbb | |||
2c31367851 | |||
3b618f3a2c | |||
4c5bc6232d | |||
694835bdac | |||
c8b75c19da | |||
c0181aa83a | |||
c5b615ae2a | |||
54cbd56f42 | |||
c8914a109e | |||
62d0767ceb | |||
8509bccc4f | |||
4ce53a3d76 | |||
8024c01a82 | |||
1b380c3fdb | |||
06b67bd292 | |||
8a1087f601 | |||
ff09d6515c | |||
ebe85d8e14 | |||
5dc27ac46a | |||
1dcc8ee761 | |||
ec69f9ac07 | |||
f789f60e22 | |||
32e3f07d57 | |||
9ea41ab3ce | |||
4b8d062862 | |||
d9408029f3 | |||
9fe0406078 | |||
5a4fe5d5da | |||
e6af9b4b73 | |||
361f9231d8 | |||
4215932550 | |||
29da523579 | |||
fbb4d7cfde | |||
3ea453a07f | |||
984e762a53 | |||
1592aa7117 | |||
62b4522c94 | |||
8b86751c95 | |||
afa380e336 | |||
feebff9077 | |||
028b50ff99 | |||
559e81c3fe | |||
4da6b98437 | |||
5b2409c76f | |||
ff027d172e | |||
3f23290a46 | |||
f1a10d32e6 | |||
a71f40e873 | |||
7f449319cd | |||
ab5c8ea698 | |||
68cfa9360b | |||
f627e3d994 | |||
7c870548d9 | |||
57ccc41547 | |||
988ba45197 | |||
df6606041b | |||
3ae27b466f | |||
69f5e21435 | |||
6da73c612a | |||
e1b1c1492f | |||
6ca13c4fce | |||
b474567d20 | |||
c07170902e | |||
0f201d2f4b | |||
b875d6f183 | |||
831b92239d | |||
66b91c22dd | |||
1242c0689f | |||
4386d02526 | |||
3ba521f8cc | |||
85bb818ae6 | |||
be7e2aa8fe | |||
7f71f6e3f1 | |||
a94d23e2ae | |||
133c255ce2 | |||
863e27ff9b | |||
5c63e6ae12 | |||
10dd36569d | |||
be5985fb6a | |||
0d7f169613 | |||
eaddcb83ab | |||
9a6885f124 | |||
7284ee818b | |||
20964454c4 | |||
d7670929d1 | |||
58f0761423 | |||
3f28bc09bc | |||
323895f0ab | |||
6efa734e81 | |||
47d64af737 | |||
4a2b91ce07 | |||
080a77cc73 | |||
9b874b0061 | |||
ff8a2ed538 | |||
251eafe103 | |||
64b604c9ac | |||
72fc5f9874 | |||
71dcdf0ca2 | |||
e23fc987a7 | |||
36dba1a36f | |||
1b1547d4b6 | |||
32a5cca878 | |||
911c705b59 | |||
594c8d72b8 | |||
7ea5232b22 | |||
be12d61795 | |||
925340eb3d | |||
601a4038f4 | |||
e0576c889b | |||
4ff7f0a7bd |
@ -47,7 +47,9 @@
|
|||||||
"/xmlKeys = {[^}]+}/g",
|
"/xmlKeys = {[^}]+}/g",
|
||||||
"/\\.to\\.deep\\.equal\\({[^)]+}\\)/g",
|
"/\\.to\\.deep\\.equal\\({[^)]+}\\)/g",
|
||||||
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g"
|
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
||||||
|
"/<element name=\"[a-z]+\"/gi",
|
||||||
|
"/<attribute name=\"[a-z]+\"/gi"
|
||||||
],
|
],
|
||||||
"ignorePaths": ["package.json", "docs/api"],
|
"ignorePaths": ["package.json", "docs/api"],
|
||||||
"allowCompoundWords": true,
|
"allowCompoundWords": true,
|
||||||
|
14
.eslintrc.js
14
.eslintrc.js
@ -96,8 +96,8 @@ module.exports = {
|
|||||||
"@typescript-eslint/explicit-function-return-type": [
|
"@typescript-eslint/explicit-function-return-type": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
allowExpressions: false,
|
allowExpressions: true,
|
||||||
allowTypedFunctionExpressions: false,
|
allowTypedFunctionExpressions: true,
|
||||||
allowHigherOrderFunctions: false,
|
allowHigherOrderFunctions: false,
|
||||||
allowDirectConstAssertionInArrowFunctions: true,
|
allowDirectConstAssertionInArrowFunctions: true,
|
||||||
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
||||||
@ -214,7 +214,6 @@ module.exports = {
|
|||||||
"no-sequences": "error",
|
"no-sequences": "error",
|
||||||
"no-shadow": "off",
|
"no-shadow": "off",
|
||||||
"no-sparse-arrays": "error",
|
"no-sparse-arrays": "error",
|
||||||
"no-template-curly-in-string": "error",
|
|
||||||
"no-throw-literal": "error",
|
"no-throw-literal": "error",
|
||||||
"no-trailing-spaces": "error",
|
"no-trailing-spaces": "error",
|
||||||
"no-undef-init": "error",
|
"no-undef-init": "error",
|
||||||
@ -243,7 +242,6 @@ module.exports = {
|
|||||||
"unicorn/prefer-ternary": "error",
|
"unicorn/prefer-ternary": "error",
|
||||||
"use-isnan": "error",
|
"use-isnan": "error",
|
||||||
"valid-typeof": "off",
|
"valid-typeof": "off",
|
||||||
"@typescript-eslint/explicit-function-return-type": "off",
|
|
||||||
"functional/immutable-data": [
|
"functional/immutable-data": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
@ -252,9 +250,12 @@ module.exports = {
|
|||||||
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
|
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"functional/no-method-signature": "error",
|
"functional/prefer-property-signatures": "error",
|
||||||
"functional/no-mixed-type": "error",
|
"functional/no-mixed-types": "error",
|
||||||
|
// TODO: Deprecated. Use prefer-immutable-types and type-declaration-immutability instead
|
||||||
"functional/prefer-readonly-type": "error",
|
"functional/prefer-readonly-type": "error",
|
||||||
|
// "functional/prefer-immutable-types": "error",
|
||||||
|
// "functional/type-declaration-immutability": "error",
|
||||||
"no-unused-vars": ["error", { argsIgnorePattern: "^[_]+$" }],
|
"no-unused-vars": ["error", { argsIgnorePattern: "^[_]+$" }],
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
@ -264,6 +265,7 @@ module.exports = {
|
|||||||
"@typescript-eslint/no-unused-expressions": "off",
|
"@typescript-eslint/no-unused-expressions": "off",
|
||||||
"@typescript-eslint/dot-notation": "off",
|
"@typescript-eslint/dot-notation": "off",
|
||||||
"prefer-destructuring": "off",
|
"prefer-destructuring": "off",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": "off",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
2
.github/workflows/default.yml
vendored
2
.github/workflows/default.yml
vendored
@ -34,7 +34,7 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test.coverage
|
run: npm run test.coverage
|
||||||
- name: Codecov
|
- name: Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
verbose: true
|
verbose: true
|
||||||
|
90
.github/workflows/demos.yml
vendored
90
.github/workflows/demos.yml
vendored
@ -716,3 +716,93 @@ 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/75-tab-stops.ts
|
||||||
|
# - name: Extract Word Document
|
||||||
|
# run: npm run extract
|
||||||
|
# - name: Validate XML
|
||||||
|
# uses: ChristophWurst/xmllint-action@v1
|
||||||
|
# with:
|
||||||
|
# xml-file: build/extracted-doc/word/document.xml
|
||||||
|
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/76-compatibility.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/77-side-by-side-tables.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/78-thai-distributed.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/79-table-from-data-source.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/80-thai-distributed.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/81-continuous-header.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/82-new-headers-new-section.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/83-setting-languages.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/84-positional-tabs.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
@ -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)
|
||||||
|
@ -14,6 +14,7 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Foo Bar",
|
text: "Foo Bar",
|
||||||
bold: true,
|
bold: true,
|
||||||
|
size: 40,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: [new Tab(), "Github is the best"],
|
children: [new Tab(), "Github is the best"],
|
||||||
|
@ -222,6 +222,15 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Underline and Strike",
|
text: "Underline and Strike",
|
||||||
}),
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " Override Underline ",
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.NONE,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "Strike and Underline",
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Exporting the document as a stream
|
// Example of using tab stops
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import 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, TabStopPosition, TabStopType, TextRun } from "../build";
|
import { Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||||
|
27
demo/78-thai-distributed.ts
Normal file
27
demo/78-thai-distributed.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัท บิสกิด จำกัด (บริษัทฯ) ได้จดทะเบียนจัดตั้งขึ้นเป็นบริษัทจำกัดตามประมวลกฎหมายแพ่งและพาณิชย์ของประเทศไทย เมื่อวันที่ 30 พฤษภาคม 2561 ทะเบียนนิติบุคคลเลขที่ 0845561005665",
|
||||||
|
size: 36,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
193
demo/79-table-from-data-source.ts
Normal file
193
demo/79-table-from-data-source.ts
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
// Example of how you would create a table and add data to it from a data source
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
VerticalAlign,
|
||||||
|
TextDirection,
|
||||||
|
TextRun,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
interface StockPrice {
|
||||||
|
readonly date: Date;
|
||||||
|
readonly ticker: string;
|
||||||
|
readonly price: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DATA: StockPrice[] = [
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-28"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-29"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.15,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-30"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.46,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-31"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.78,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-04"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 20.59,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-05"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.54,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-06"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.29,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-07"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.82,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-10"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.53,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-11"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.36,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-12"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.55,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-13"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-14"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.83,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-17"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.77,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const generateRows = (prices: StockPrice[]): TableRow[] =>
|
||||||
|
prices.map(
|
||||||
|
({ date, ticker, price }) =>
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(date.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(ticker)],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(price.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
|
width: {
|
||||||
|
size: 9070,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Date",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Ticker",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Price",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
...generateRows(DATA),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
49
demo/80-thai-distributed.ts
Normal file
49
demo/80-thai-distributed.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "test",
|
||||||
|
name: "Test",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertMillimetersToTwip(6.4) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
|
top: 0,
|
||||||
|
right: convertMillimetersToTwip(24),
|
||||||
|
bottom: convertMillimetersToTwip(24),
|
||||||
|
left: convertMillimetersToTwip(24),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัทฯ มีเงินสด 41,985.00 บาท และ 25,855.66 บาทตามลำดับ เงินสดทั้งจำนวนอยู่ในความดูแลและรับผิดชอบของกรรมการ บริษัทฯบันทึกการรับชำระเงินและการจ่ายชำระเงินผ่านบัญชีเงินสดเพียงเท่านั้น ซึ่งอาจกระทบต่อความถูกต้องครบถ้วนของการบันทึกบัญชี ทั้งนี้ขึ้นอยู่กับระบบการควบคุมภายในของบริษัท",
|
||||||
|
size: 28,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
148
demo/81-continuous-header.ts
Normal file
148
demo/81-continuous-header.ts
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// Example of a continuous header
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Creator",
|
||||||
|
title: "Title",
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: { titlePage: true },
|
||||||
|
headers: {
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
first: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
after: 500,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The first section ends after this paragraph.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.CONTINUOUS,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
148
demo/82-new-headers-new-section.ts
Normal file
148
demo/82-new-headers-new-section.ts
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// Example of using headers and footers in a new section
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Creator",
|
||||||
|
title: "Title",
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
after: 500,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The first section ends after this paragraph.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
69
demo/83-setting-languages.ts
Normal file
69
demo/83-setting-languages.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
default: {
|
||||||
|
document: {
|
||||||
|
run: {
|
||||||
|
color: "ff0000",
|
||||||
|
language: {
|
||||||
|
value: "es-ES",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "frenchNormal",
|
||||||
|
name: "French Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "999999",
|
||||||
|
italics: true,
|
||||||
|
language: {
|
||||||
|
value: "fr-FR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "koreanNormal",
|
||||||
|
name: "Korean Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "0000ff",
|
||||||
|
bold: true,
|
||||||
|
language: {
|
||||||
|
value: "ko-KR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Yo vivo en Granada, una ciudad pequeña que tiene monumentos muy importantes como la Alhambra. Aquí la comida es deliciosa y son famosos el gazpacho, el rebujito y el salmorejo.",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Toute personne a droit à l'éducation. L'éducation doit être gratuite, au moins en ce qui concerne l'enseignement élémentaire et fondamental. L'enseignement élémentaire est obligatoire. L'enseignement technique et professionnel doit être généralisé; l'accès aux études supérieures doit être ouvert en pleine égalité à tous en fonction de leur mérite.",
|
||||||
|
style: "frenchNormal",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "대법관은 대법원장의 제청으로 국회의 동의를 얻어 대통령이 임명한다. 강화조약. 국가는 국민 모두의 생산 및 생활의 기반이 되는 국토의 효율적이고 균형있는 이용·개발과 보전을 위하여 법률이 정하는 바에 의하여 그에 관한 필요한 제한과 의무를 과할 수 있다, 국가는 청원에 대하여 심사할 의무를 진다.",
|
||||||
|
style: "koreanNormal",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
60
demo/84-positional-tabs.ts
Normal file
60
demo/84-positional-tabs.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Simple example apply positional tabs to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
PositionalTab,
|
||||||
|
Tab,
|
||||||
|
TextRun,
|
||||||
|
PositionalTabAlignment,
|
||||||
|
PositionalTabRelativeTo,
|
||||||
|
PositionalTabLeader,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Full name"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.RIGHT,
|
||||||
|
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||||
|
leader: PositionalTabLeader.DOT,
|
||||||
|
}),
|
||||||
|
"John Doe",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.CENTER,
|
||||||
|
relativeTo: PositionalTabRelativeTo.INDENT,
|
||||||
|
leader: PositionalTabLeader.HYPHEN,
|
||||||
|
}),
|
||||||
|
"Foo bar",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -11,22 +11,26 @@
|
|||||||
- [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)
|
||||||
- [Numbering](usage/numbering.md)
|
- [Numbering](usage/numbering.md)
|
||||||
- [Tables](usage/tables.md)
|
- [Tables](usage/tables.md)
|
||||||
- [Tab Stops](usage/tab-stops.md)
|
- [Tabs](usage/tabs.md)
|
||||||
- [Table of Contents](usage/table-of-contents.md)
|
- [Table of Contents](usage/table-of-contents.md)
|
||||||
- [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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -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:**
|
||||||
|
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
# Tab Stops
|
|
||||||
|
|
||||||
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
|
||||||
|
|
||||||
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
|
||||||
|
|
||||||

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

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

|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Full name"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.RIGHT,
|
||||||
|
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||||
|
leader: PositionalTabLeader.DOT,
|
||||||
|
}),
|
||||||
|
"John Doe",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Option | Type | Description | Possible Values |
|
||||||
|
| ---------- | ------------------------- | ------------------------------------- | ------------------------------------------------------------- |
|
||||||
|
| alignment | `PositionalTabAlignment` | The alignment of the tab stop | `LEFT`, `RIGHT`, `CENTER` |
|
||||||
|
| relativeTo | `PositionalTabRelativeTo` | The relative position of the tab stop | `MARGIN`, `INDENT` |
|
||||||
|
| leader | `PositionalTabLeader` | The leader of the tab stop | `NONE`, `DOT`, `HYPHEN`, `UNDERSCORE`, `MIDDLE_DOT`, `EQUALS` |
|
3683
package-lock.json
generated
3683
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "7.7.0",
|
"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": {
|
||||||
@ -52,7 +52,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^18.0.0",
|
"@types/node": "^18.0.0",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"nanoid": "^3.1.20",
|
"nanoid": "^3.3.4",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xml-js": "^1.6.8"
|
"xml-js": "^1.6.8"
|
||||||
},
|
},
|
||||||
@ -79,12 +79,12 @@
|
|||||||
"cspell": "^6.2.2",
|
"cspell": "^6.2.2",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
"eslint": "^8.23.0",
|
"eslint": "^8.23.0",
|
||||||
"eslint-plugin-functional": "^4.3.1",
|
"eslint-plugin-functional": "^5.0.1",
|
||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"eslint-plugin-jsdoc": "^39.3.6",
|
"eslint-plugin-jsdoc": "^39.3.6",
|
||||||
"eslint-plugin-no-null": "^1.0.2",
|
"eslint-plugin-no-null": "^1.0.2",
|
||||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||||
"eslint-plugin-unicorn": "^44.0.0",
|
"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",
|
||||||
@ -96,19 +96,19 @@
|
|||||||
"replace-in-file": "^6.2.0",
|
"replace-in-file": "^6.2.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^4.0.4",
|
||||||
"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": "^4.0.0",
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
||||||
"typedoc": "^0.23.2",
|
"typedoc": "^0.23.2",
|
||||||
"typescript": "4.8.4",
|
"typescript": "4.9.5",
|
||||||
"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"
|
||||||
|
@ -2,7 +2,7 @@ import { BaseXmlComponent, IContext, IXmlableObject } from "@file/xml-components
|
|||||||
|
|
||||||
export class Formatter {
|
export class Formatter {
|
||||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
public format(input: BaseXmlComponent, context: IContext = {} as IContext): IXmlableObject {
|
public format(input: BaseXmlComponent, context: IContext = { stack: [] } as unknown as IContext): IXmlableObject {
|
||||||
const output = input.prepForXml(context);
|
const output = input.prepForXml(context);
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
|
@ -74,6 +74,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Document.View, {
|
this.formatter.format(file.Document.View, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -100,6 +101,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Document.Relationships, {
|
this.formatter.format(file.Document.Relationships, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -125,6 +127,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Styles, {
|
this.formatter.format(file.Styles, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -144,6 +147,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.CoreProperties, {
|
this.formatter.format(file.CoreProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -160,6 +164,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Numbering, {
|
this.formatter.format(file.Numbering, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -176,6 +181,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.FileRelationships, {
|
this.formatter.format(file.FileRelationships, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -191,6 +197,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.View, {
|
this.formatter.format(headerWrapper.View, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -214,6 +221,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.Relationships, {
|
this.formatter.format(headerWrapper.Relationships, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -230,6 +238,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.View, {
|
this.formatter.format(footerWrapper.View, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -253,6 +262,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.Relationships, {
|
this.formatter.format(footerWrapper.Relationships, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -269,6 +279,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.View, {
|
this.formatter.format(headerWrapper.View, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -293,6 +304,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.View, {
|
this.formatter.format(footerWrapper.View, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -317,6 +329,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.ContentTypes, {
|
this.formatter.format(file.ContentTypes, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -332,6 +345,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.CustomProperties, {
|
this.formatter.format(file.CustomProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -348,6 +362,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.AppProperties, {
|
this.formatter.format(file.AppProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -363,7 +378,8 @@ export class Compiler {
|
|||||||
data: xml(
|
data: xml(
|
||||||
this.formatter.format(file.FootNotes.View, {
|
this.formatter.format(file.FootNotes.View, {
|
||||||
viewWrapper: file.FootNotes,
|
viewWrapper: file.FootNotes,
|
||||||
file: file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -378,7 +394,8 @@ export class Compiler {
|
|||||||
data: xml(
|
data: xml(
|
||||||
this.formatter.format(file.FootNotes.Relationships, {
|
this.formatter.format(file.FootNotes.Relationships, {
|
||||||
viewWrapper: file.FootNotes,
|
viewWrapper: file.FootNotes,
|
||||||
file: file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -394,6 +411,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Settings, {
|
this.formatter.format(file.Settings, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -410,6 +428,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Comments, {
|
this.formatter.format(file.Comments, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
export interface IColumnAttributes {
|
// <xsd:complexType name="CT_Column">
|
||||||
readonly width: number | string;
|
// <xsd:attribute name="w" type="s:ST_TwipsMeasure" use="optional" />
|
||||||
readonly space?: number | string;
|
// <xsd:attribute name="space" type="s:ST_TwipsMeasure" use="optional" default="0" />
|
||||||
}
|
// </xsd:complexType>
|
||||||
|
|
||||||
export class ColumnAttributes extends XmlAttributeComponent<IColumnAttributes> {
|
type IColumnAttributes = {
|
||||||
protected readonly xmlKeys = {
|
readonly width: number | PositiveUniversalMeasure;
|
||||||
width: "w:w",
|
readonly space?: number | PositiveUniversalMeasure;
|
||||||
space: "w:space",
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Column extends XmlComponent {
|
export class Column extends XmlComponent {
|
||||||
public constructor({ width, space }: IColumnAttributes) {
|
public constructor({ width, space }: IColumnAttributes) {
|
||||||
super("w:col");
|
super("w:col");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new ColumnAttributes({
|
new NextAttributeComponent<IColumnAttributes>({
|
||||||
width: twipsMeasureValue(width),
|
width: { key: "w:w", value: twipsMeasureValue(width) },
|
||||||
space: space === undefined ? undefined : twipsMeasureValue(space),
|
space: { key: "w:space", value: space === undefined ? undefined : twipsMeasureValue(space) },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber, twipsMeasureValue } from "@util/values";
|
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
import { Column } from "./column";
|
import { Column } from "./column";
|
||||||
|
|
||||||
@ -12,32 +12,23 @@ import { Column } from "./column";
|
|||||||
// <xsd:attribute name="num" type="ST_DecimalNumber" use="optional" default="1"/>
|
// <xsd:attribute name="num" type="ST_DecimalNumber" use="optional" default="1"/>
|
||||||
// <xsd:attribute name="sep" type="s:ST_OnOff" use="optional"/>
|
// <xsd:attribute name="sep" type="s:ST_OnOff" use="optional"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export interface IColumnsAttributes {
|
export type IColumnsAttributes = {
|
||||||
readonly space?: number | string;
|
readonly space?: number | PositiveUniversalMeasure;
|
||||||
readonly count?: number;
|
readonly count?: number;
|
||||||
readonly separate?: boolean;
|
readonly separate?: boolean;
|
||||||
readonly equalWidth?: boolean;
|
readonly equalWidth?: boolean;
|
||||||
readonly children?: readonly Column[];
|
readonly children?: readonly Column[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
space: "w:space",
|
|
||||||
count: "w:num",
|
|
||||||
separate: "w:sep",
|
|
||||||
equalWidth: "w:equalWidth",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Columns extends XmlComponent {
|
export class Columns extends XmlComponent {
|
||||||
public 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 NextAttributeComponent<Omit<IColumnsAttributes, "children">>({
|
||||||
space: space === undefined ? undefined : twipsMeasureValue(space),
|
space: { key: "w:space", value: space === undefined ? undefined : twipsMeasureValue(space) },
|
||||||
count: count === undefined ? undefined : decimalNumber(count),
|
count: { key: "w:num", value: count === undefined ? undefined : decimalNumber(count) },
|
||||||
separate,
|
separate: { key: "w:sep", value: separate },
|
||||||
equalWidth,
|
equalWidth: { key: "w:equalWidth", value: equalWidth },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// http://officeopenxml.com/WPsectionLineNumbering.php
|
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber, twipsMeasureValue } from "@util/values";
|
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_LineNumberRestart">
|
// <xsd:simpleType name="ST_LineNumberRestart">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -26,27 +26,23 @@ export interface ILineNumberAttributes {
|
|||||||
readonly countBy?: number;
|
readonly countBy?: number;
|
||||||
readonly start?: number;
|
readonly start?: number;
|
||||||
readonly restart?: LineNumberRestartFormat;
|
readonly restart?: LineNumberRestartFormat;
|
||||||
readonly distance?: number | string;
|
readonly distance?: number | PositiveUniversalMeasure;
|
||||||
}
|
|
||||||
|
|
||||||
export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttributes> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
countBy: "w:countBy",
|
|
||||||
start: "w:start",
|
|
||||||
restart: "w:restart",
|
|
||||||
distance: "w:distance",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LineNumberType extends XmlComponent {
|
export class LineNumberType extends XmlComponent {
|
||||||
public 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 NextAttributeComponent<{
|
||||||
countBy: countBy === undefined ? undefined : decimalNumber(countBy),
|
readonly countBy?: number;
|
||||||
start: start === undefined ? undefined : decimalNumber(start),
|
readonly start?: number;
|
||||||
restart,
|
readonly restart?: LineNumberRestartFormat;
|
||||||
distance: distance === undefined ? undefined : twipsMeasureValue(distance),
|
readonly distance?: number | PositiveUniversalMeasure;
|
||||||
|
}>({
|
||||||
|
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||||
|
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||||
|
restart: { key: "w:restart", value: restart },
|
||||||
|
distance: { key: "w:distance", value: distance === undefined ? undefined : twipsMeasureValue(distance) },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
|||||||
super("w:pgBorders");
|
super("w:pgBorders");
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.pageBorders) {
|
if (options.pageBorders) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
// <xsd:complexType name="CT_PageMar">
|
// <xsd:complexType name="CT_PageMar">
|
||||||
// <xsd:attribute name="top" type="ST_SignedTwipsMeasure" use="required"/>
|
// <xsd:attribute name="top" type="ST_SignedTwipsMeasure" use="required"/>
|
||||||
@ -10,48 +10,36 @@ import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
|||||||
// <xsd:attribute name="footer" type="s:ST_TwipsMeasure" use="required"/>
|
// <xsd:attribute name="footer" type="s:ST_TwipsMeasure" use="required"/>
|
||||||
// <xsd:attribute name="gutter" type="s:ST_TwipsMeasure" use="required"/>
|
// <xsd:attribute name="gutter" type="s:ST_TwipsMeasure" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export interface IPageMarginAttributes {
|
export type IPageMarginAttributes = {
|
||||||
readonly top?: number | string;
|
readonly top?: number | UniversalMeasure;
|
||||||
readonly right?: number | string;
|
readonly right?: number | PositiveUniversalMeasure;
|
||||||
readonly bottom?: number | string;
|
readonly bottom?: number | UniversalMeasure;
|
||||||
readonly left?: number | string;
|
readonly left?: number | PositiveUniversalMeasure;
|
||||||
readonly header?: number | string;
|
readonly header?: number | PositiveUniversalMeasure;
|
||||||
readonly footer?: number | string;
|
readonly footer?: number | PositiveUniversalMeasure;
|
||||||
readonly gutter?: number | string;
|
readonly gutter?: number | PositiveUniversalMeasure;
|
||||||
}
|
};
|
||||||
|
|
||||||
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
top: "w:top",
|
|
||||||
right: "w:right",
|
|
||||||
bottom: "w:bottom",
|
|
||||||
left: "w:left",
|
|
||||||
header: "w:header",
|
|
||||||
footer: "w:footer",
|
|
||||||
gutter: "w:gutter",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PageMargin extends XmlComponent {
|
export class PageMargin extends XmlComponent {
|
||||||
public constructor(
|
public constructor(
|
||||||
top: number | string,
|
top: number | UniversalMeasure,
|
||||||
right: number | string,
|
right: number | PositiveUniversalMeasure,
|
||||||
bottom: number | string,
|
bottom: number | UniversalMeasure,
|
||||||
left: number | string,
|
left: number | PositiveUniversalMeasure,
|
||||||
header: number | string,
|
header: number | PositiveUniversalMeasure,
|
||||||
footer: number | string,
|
footer: number | PositiveUniversalMeasure,
|
||||||
gutter: number | string,
|
gutter: number | PositiveUniversalMeasure,
|
||||||
) {
|
) {
|
||||||
super("w:pgMar");
|
super("w:pgMar");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageMarginAttributes({
|
new NextAttributeComponent<IPageMarginAttributes>({
|
||||||
top: signedTwipsMeasureValue(top),
|
top: { key: "w:top", value: signedTwipsMeasureValue(top) },
|
||||||
right: twipsMeasureValue(right),
|
right: { key: "w:right", value: twipsMeasureValue(right) },
|
||||||
bottom: signedTwipsMeasureValue(bottom),
|
bottom: { key: "w:bottom", value: signedTwipsMeasureValue(bottom) },
|
||||||
left: twipsMeasureValue(left),
|
left: { key: "w:left", value: twipsMeasureValue(left) },
|
||||||
header: twipsMeasureValue(header),
|
header: { key: "w:header", value: twipsMeasureValue(header) },
|
||||||
footer: twipsMeasureValue(footer),
|
footer: { key: "w:footer", value: twipsMeasureValue(footer) },
|
||||||
gutter: twipsMeasureValue(gutter),
|
gutter: { key: "w:gutter", value: twipsMeasureValue(gutter) },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PageOrientation">
|
// <xsd:simpleType name="ST_PageOrientation">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -18,22 +18,14 @@ export enum PageOrientation {
|
|||||||
// <xsd:attribute name="orient" type="ST_PageOrientation" use="optional"/>
|
// <xsd:attribute name="orient" type="ST_PageOrientation" use="optional"/>
|
||||||
// <xsd:attribute name="code" type="ST_DecimalNumber" use="optional"/>
|
// <xsd:attribute name="code" type="ST_DecimalNumber" use="optional"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export interface IPageSizeAttributes {
|
export type IPageSizeAttributes = {
|
||||||
readonly width?: number | string;
|
readonly width?: number | PositiveUniversalMeasure;
|
||||||
readonly height?: number | string;
|
readonly height?: number | PositiveUniversalMeasure;
|
||||||
readonly orientation?: PageOrientation;
|
readonly orientation?: PageOrientation;
|
||||||
}
|
};
|
||||||
|
|
||||||
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
width: "w:w",
|
|
||||||
height: "w:h",
|
|
||||||
orientation: "w:orient",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PageSize extends XmlComponent {
|
export class PageSize extends XmlComponent {
|
||||||
public constructor(width: number | string, height: number | string, orientation: PageOrientation) {
|
public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) {
|
||||||
super("w:pgSz");
|
super("w:pgSz");
|
||||||
|
|
||||||
const flip = orientation === PageOrientation.LANDSCAPE;
|
const flip = orientation === PageOrientation.LANDSCAPE;
|
||||||
@ -42,10 +34,10 @@ export class PageSize extends XmlComponent {
|
|||||||
const heightTwips = twipsMeasureValue(height);
|
const heightTwips = twipsMeasureValue(height);
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageSizeAttributes({
|
new NextAttributeComponent<IPageSizeAttributes>({
|
||||||
width: flip ? heightTwips : widthTwips,
|
width: { key: "w:w", value: flip ? heightTwips : widthTwips },
|
||||||
height: flip ? widthTwips : heightTwips,
|
height: { key: "w:h", value: flip ? widthTwips : heightTwips },
|
||||||
orientation: orientation,
|
orientation: { key: "w:orient", value: orientation },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import { FooterWrapper } from "@file/footer-wrapper";
|
|||||||
import { HeaderWrapper } from "@file/header-wrapper";
|
import { HeaderWrapper } from "@file/header-wrapper";
|
||||||
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
|
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
|
||||||
import { OnOffElement, XmlComponent } from "@file/xml-components";
|
import { OnOffElement, XmlComponent } from "@file/xml-components";
|
||||||
|
import { PositiveUniversalMeasure, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
||||||
|
|
||||||
import { Columns, IColumnsAttributes } from "./properties/columns";
|
import { Columns, IColumnsAttributes } from "./properties/columns";
|
||||||
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
||||||
import { ILineNumberAttributes, LineNumberType } from "./properties/line-number";
|
import { ILineNumberAttributes, LineNumberType } from "./properties/line-number";
|
||||||
@ -76,10 +76,10 @@ export interface ISectionPropertiesOptions {
|
|||||||
// </xsd:group>
|
// </xsd:group>
|
||||||
|
|
||||||
export const sectionMarginDefaults = {
|
export const sectionMarginDefaults = {
|
||||||
TOP: "1in",
|
TOP: "1in" as UniversalMeasure,
|
||||||
RIGHT: "1in",
|
RIGHT: "1in" as PositiveUniversalMeasure,
|
||||||
BOTTOM: "1in",
|
BOTTOM: "1in" as UniversalMeasure,
|
||||||
LEFT: "1in",
|
LEFT: "1in" as PositiveUniversalMeasure,
|
||||||
HEADER: 708,
|
HEADER: 708,
|
||||||
FOOTER: 708,
|
FOOTER: 708,
|
||||||
GUTTER: 0,
|
GUTTER: 0,
|
||||||
|
@ -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"/>
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { createHyperlinkClick, createHyperlinkHover } from "./doc-properties-children";
|
||||||
|
|
||||||
|
describe("Document Properties Children", () => {
|
||||||
|
describe("#createHyperlinkClick", () => {
|
||||||
|
it("should create a Hyperlink Click component", () => {
|
||||||
|
const tree = new Formatter().format(createHyperlinkClick("1", false));
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:hlinkClick": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create a Hyperlink Click component with xmlns:a", () => {
|
||||||
|
const tree = new Formatter().format(createHyperlinkClick("1", true));
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:hlinkClick": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#createHyperlinkHover", () => {
|
||||||
|
it("should create a Hyperlink Hover component", () => {
|
||||||
|
const tree = new Formatter().format(createHyperlinkHover("1", false));
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:hlinkHover": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create a Hyperlink Hover component with xmlns:a", () => {
|
||||||
|
const tree = new Formatter().format(createHyperlinkHover("1", true));
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:hlinkHover": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
57
src/file/drawing/doc-properties/doc-properties-children.ts
Normal file
57
src/file/drawing/doc-properties/doc-properties-children.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// <sequence>
|
||||||
|
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||||
|
// </sequence>
|
||||||
|
|
||||||
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_Hyperlink">
|
||||||
|
// <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded" />
|
||||||
|
// <xsd:attribute name="tgtFrame" type="s:ST_String" use="optional" />
|
||||||
|
// <xsd:attribute name="tooltip" type="s:ST_String" use="optional" />
|
||||||
|
// <xsd:attribute name="docLocation" type="s:ST_String" use="optional" />
|
||||||
|
// <xsd:attribute name="history" type="s:ST_OnOff" use="optional" />
|
||||||
|
// <xsd:attribute name="anchor" type="s:ST_String" use="optional" />
|
||||||
|
// <xsd:attribute ref="r:id" />
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
|
// TODO: Implement the rest of the attributes
|
||||||
|
|
||||||
|
export const createHyperlinkClick = (linkId: string, hasXmlNs: boolean): XmlComponent =>
|
||||||
|
new BuilderElement({
|
||||||
|
name: "a:hlinkClick",
|
||||||
|
attributes: {
|
||||||
|
...(hasXmlNs
|
||||||
|
? {
|
||||||
|
xmlns: {
|
||||||
|
key: "xmlns:a",
|
||||||
|
value: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
id: {
|
||||||
|
key: "r:id",
|
||||||
|
value: `rId${linkId}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const createHyperlinkHover = (linkId: string, hasXmlNs: boolean): XmlComponent =>
|
||||||
|
new BuilderElement({
|
||||||
|
name: "a:hlinkHover",
|
||||||
|
attributes: {
|
||||||
|
...(hasXmlNs
|
||||||
|
? {
|
||||||
|
xmlns: {
|
||||||
|
key: "xmlns:a",
|
||||||
|
value: "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
id: {
|
||||||
|
key: "r:id",
|
||||||
|
value: `rId${linkId}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
@ -1,19 +1,22 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_docPr_topic_ID0ES32OB.html
|
||||||
|
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
import { ConcreteHyperlink } from "@file/paragraph";
|
||||||
|
|
||||||
import { uniqueNumericId } from "@util/convenience-functions";
|
import { uniqueNumericId } from "@util/convenience-functions";
|
||||||
|
|
||||||
class DocPropertiesAttributes extends XmlAttributeComponent<{
|
import { createHyperlinkClick } from "./doc-properties-children";
|
||||||
readonly id?: number;
|
|
||||||
readonly name?: string;
|
// <complexType name="CT_NonVisualDrawingProps">
|
||||||
readonly description?: string;
|
// <sequence>
|
||||||
readonly title?: string;
|
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
}> {
|
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
protected readonly xmlKeys = {
|
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||||
id: "id",
|
// </sequence>
|
||||||
name: "name",
|
// <attribute name="id" type="ST_DrawingElementId" use="required" />
|
||||||
description: "descr",
|
// <attribute name="name" type="xsd:string" use="required" />
|
||||||
title: "title",
|
// <attribute name="descr" type="xsd:string" use="optional" default="" />
|
||||||
};
|
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
|
||||||
}
|
// </complexType>
|
||||||
|
|
||||||
export interface DocPropertiesOptions {
|
export interface DocPropertiesOptions {
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
@ -26,12 +29,39 @@ export class DocProperties extends XmlComponent {
|
|||||||
super("wp:docPr");
|
super("wp:docPr");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new DocPropertiesAttributes({
|
new NextAttributeComponent({
|
||||||
id: uniqueNumericId(),
|
id: {
|
||||||
name,
|
key: "id",
|
||||||
description,
|
value: uniqueNumericId(),
|
||||||
title,
|
},
|
||||||
|
name: {
|
||||||
|
key: "name",
|
||||||
|
value: name,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
key: "descr",
|
||||||
|
value: description,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
key: "title",
|
||||||
|
value: title,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||||
|
for (let i = context.stack.length - 1; i >= 0; i--) {
|
||||||
|
const element = context.stack[i];
|
||||||
|
if (!(element instanceof ConcreteHyperlink)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root.push(createHyperlinkClick(element.linkId, true));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.prepForXml(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { SinonStub, stub } from "sinon";
|
import { SinonStub, stub } from "sinon";
|
||||||
|
|
||||||
|
import { IContext } from "@file/xml-components";
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
import * as convenienceFunctions from "@util/convenience-functions";
|
import * as convenienceFunctions from "@util/convenience-functions";
|
||||||
|
|
||||||
|
import { ConcreteHyperlink, TextRun } from "../";
|
||||||
import { Drawing, IDrawingOptions } from "./drawing";
|
import { Drawing, IDrawingOptions } from "./drawing";
|
||||||
|
|
||||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4jHR4hHh4hHx8hHyAiHyAjHyAjHSAjHR4jHR4hHh4hHx8hHyAjHyAjHyAjHSAjHR4hHR4hHR4hHx8iHyAjHyAjHyAjHSAhHR4hHR4hHR4hHx8jHyAjHyAjHyAjHyC9S2xeAAAA7nRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFxgZGhscHR4fICEiIyQlJicoKSorLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZISUpLTE1OUFFSU1RVVllaW1xdXmBhYmNkZWZnaGprbG1ub3Byc3R1dnd4eXp8fn+AgYKDhIWGiImKi4yNj5CRkpOUlZaXmJmam5ydnp+goaKjpKaoqqusra6vsLGys7S1tri5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+fkZpVQAABcBJREFUGBntwftjlQMcBvDnnLNL22qzJjWlKLHFVogyty3SiFq6EZliqZGyhnSxsLlMRahYoZKRFcul5dKFCatYqWZaNKvWtrPz/A2+7/b27qRzec/lPfvl/XxgMplMJpPJZDKZAtA9HJ3ppnIez0KnSdtC0RCNznHdJrbrh85wdSlVVRaEXuoGamYi5K5430HNiTiEWHKJg05eRWgNfKeV7RxbqUhGKPV/207VupQ8is0IoX5vtFC18SqEHaK4GyHTZ2kzVR8PBTCO4oANIZL4ShNVZcOhKKeYg9DoWdhI1ec3os2VFI0JCIUez5+i6st0qJZRrEAIJCw+QdW223BG/EmKwTBc/IJ/qfp2FDrkUnwFo8U9dZyqnaPhxLqfYjyM1S3vb6p+GGOBszsojoTDSDFz6qj66R4LzvYJxVMwUNRjf1H1ywQr/megg2RzLximy8waqvbda8M5iijegVEiHjlM1W/3h+FcXesphsMY4dMOUnUgOxyuPEzxPQwRNvV3qg5Nj4BreyimwADWe/dRVTMjEm6MoGLzGwtystL6RyOY3qSqdlYU3FpLZw1VW0sK5943MvUCKwJ1noNtjs6Ohge76Zq9ZkfpigU5WWkDYuCfbs1U5HWFR8/Qq4a9W0uK5k4ZmdrTCl8spGIePLPlbqqsc1Afe83O0hULc8alDYiBd7ZyitYMeBfR55rR2fOKP6ioPk2dGvZ+UVI0d8rtqT2tcCexlqK2F3wRn5Q+YVbBqrLKOupkr9lZujAOrmS0UpTb4JeIPkNHZ+cXr6uoPk2vyuBSPhWLEKj45PQJuQWryyqP0Z14uGLdROHIRNBEXDR09EP5r62rOHCazhrD4VKPwxTH+sIA3ZPTJ+YuWV22n+IruHFDC8X2CBjnPoolcGc2FYUwzmsUWXDHsoGKLBhmN0VvuBVfTVE/AAbpaid5CB4MbaLY1QXGuIViLTyZQcVyGGMuxWPwaA0Vk2GI9RRp8Ci2iuLkIBjhT5LNUfAspZFiTwyC72KK7+DNg1SsRvCNp3gZXq2k4iEEXSHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4jHR4hHh4hHx8hHyAiHyAjHyAjHSAjHR4jHR4hHh4hHx8hHyAjHyAjHyAjHSAjHR4hHR4hHR4hHx8iHyAjHyAjHyAjHSAhHR4hHR4hHR4hHx8jHyAjHyAjHyAjHyC9S2xeAAAA7nRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFxgZGhscHR4fICEiIyQlJicoKSorLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZISUpLTE1OUFFSU1RVVllaW1xdXmBhYmNkZWZnaGprbG1ub3Byc3R1dnd4eXp8fn+AgYKDhIWGiImKi4yNj5CRkpOUlZaXmJmam5ydnp+goaKjpKaoqqusra6vsLGys7S1tri5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+fkZpVQAABcBJREFUGBntwftjlQMcBvDnnLNL22qzJjWlKLHFVogyty3SiFq6EZliqZGyhnSxsLlMRahYoZKRFcul5dKFCatYqWZaNKvWtrPz/A2+7/b27qRzec/lPfvl/XxgMplMJpPJZDKZAtA9HJ3ppnIez0KnSdtC0RCNznHdJrbrh85wdSlVVRaEXuoGamYi5K5430HNiTiEWHKJg05eRWgNfKeV7RxbqUhGKPV/207VupQ8is0IoX5vtFC18SqEHaK4GyHTZ2kzVR8PBTCO4oANIZL4ShNVZcOhKKeYg9DoWdhI1ec3os2VFI0JCIUez5+i6st0qJZRrEAIJCw+QdW223BG/EmKwTBc/IJ/qfp2FDrkUnwFo8U9dZyqnaPhxLqfYjyM1S3vb6p+GGOBszsojoTDSDFz6qj66R4LzvYJxVMwUNRjf1H1ywQr/megg2RzLximy8waqvbda8M5iijegVEiHjlM1W/3h+FcXesphsMY4dMOUnUgOxyuPEzxPQwRNvV3qg5Nj4BreyimwADWe/dRVTMjEm6MoGLzGwtystL6RyOY3qSqdlYU3FpLZw1VW0sK5943MvUCKwJ1noNtjs6Ohge76Zq9ZkfpigU5WWkDYuCfbs1U5HWFR8/Qq4a9W0uK5k4ZmdrTCl8spGIePLPlbqqsc1Afe83O0hULc8alDYiBd7ZyitYMeBfR55rR2fOKP6ioPk2dGvZ+UVI0d8rtqT2tcCexlqK2F3wRn5Q+YVbBqrLKOupkr9lZujAOrmS0UpTb4JeIPkNHZ+cXr6uoPk2vyuBSPhWLEKj45PQJuQWryyqP0Z14uGLdROHIRNBEXDR09EP5r62rOHCazhrD4VKPwxTH+sIA3ZPTJ+YuWV22n+IruHFDC8X2CBjnPoolcGc2FYUwzmsUWXDHsoGKLBhmN0VvuBVfTVE/AAbpaid5CB4MbaLY1QXGuIViLTyZQcVyGGMuxWPwaA0Vk2GI9RRp8Ci2iuLkIBjhT5LNUfAspZFiTwyC72KK7+DNg1SsRvCNp3gZXq2k4iEEXSHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||||
@ -450,5 +452,257 @@ describe("Drawing", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should create a drawing with a hyperlink", () => {
|
||||||
|
currentBreak = createDrawing({
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 0,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(currentBreak, {
|
||||||
|
stack: [new ConcreteHyperlink([new TextRun("Test")], "1")],
|
||||||
|
} as unknown as IContext);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:drawing": [
|
||||||
|
{
|
||||||
|
"wp:anchor": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
allowOverlap: "1",
|
||||||
|
behindDoc: "0",
|
||||||
|
distB: 0,
|
||||||
|
distL: 0,
|
||||||
|
distR: 0,
|
||||||
|
distT: 0,
|
||||||
|
layoutInCell: "1",
|
||||||
|
locked: "0",
|
||||||
|
relativeHeight: 952500,
|
||||||
|
simplePos: "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:simplePos": {
|
||||||
|
_attr: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:positionH": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "page",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:positionV": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
relativeFrom: "page",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:posOffset": ["0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:extent": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:effectExtent": {
|
||||||
|
_attr: {
|
||||||
|
b: 0,
|
||||||
|
l: 0,
|
||||||
|
r: 0,
|
||||||
|
t: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:wrapNone": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:docPr": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
descr: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
title: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:hlinkClick": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wp:cNvGraphicFramePr": [
|
||||||
|
{
|
||||||
|
"a:graphicFrameLocks": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
noChangeAspect: 1,
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:graphicData": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:pic": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"xmlns:pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:nvPicPr": [
|
||||||
|
{
|
||||||
|
"pic:cNvPr": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
descr: "",
|
||||||
|
id: 0,
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:hlinkClick": {
|
||||||
|
_attr: {
|
||||||
|
"r:id": "rId1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:cNvPicPr": [
|
||||||
|
{
|
||||||
|
"a:picLocks": {
|
||||||
|
_attr: {
|
||||||
|
noChangeArrowheads: 1,
|
||||||
|
noChangeAspect: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:blipFill": [
|
||||||
|
{
|
||||||
|
"a:blip": {
|
||||||
|
_attr: {
|
||||||
|
// tslint:disable-next-line:object-literal-key-quotes
|
||||||
|
cstate: "none",
|
||||||
|
"r:embed": "rId{test.jpg}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:srcRect": {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:stretch": [
|
||||||
|
{
|
||||||
|
"a:fillRect": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pic:spPr": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
bwMode: "auto",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:xfrm": [
|
||||||
|
{
|
||||||
|
_attr: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:off": {
|
||||||
|
_attr: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:ext": {
|
||||||
|
_attr: {
|
||||||
|
cx: 952500,
|
||||||
|
cy: 952500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:prstGeom": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
prst: "rect",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:avLst": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
||||||
|
import { createHyperlinkClick } from "@file/drawing/doc-properties/doc-properties-children";
|
||||||
|
import { ConcreteHyperlink } from "@file/paragraph";
|
||||||
|
|
||||||
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
|
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
|
||||||
|
|
||||||
|
// <complexType name="CT_NonVisualDrawingProps">
|
||||||
|
// <sequence>
|
||||||
|
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
||||||
|
// </sequence>
|
||||||
|
// <attribute name="id" type="ST_DrawingElementId" use="required" />
|
||||||
|
// <attribute name="name" type="xsd:string" use="required" />
|
||||||
|
// <attribute name="descr" type="xsd:string" use="optional" default="" />
|
||||||
|
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
|
||||||
|
// </complexType>
|
||||||
|
|
||||||
export class NonVisualProperties extends XmlComponent {
|
export class NonVisualProperties extends XmlComponent {
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super("pic:cNvPr");
|
super("pic:cNvPr");
|
||||||
@ -13,4 +28,19 @@ export class NonVisualProperties extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||||
|
for (let i = context.stack.length - 1; i >= 0; i--) {
|
||||||
|
const element = context.stack[i];
|
||||||
|
if (!(element instanceof ConcreteHyperlink)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root.push(createHyperlinkClick(element.linkId, false));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.prepForXml(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
src/file/file-child.ts
Normal file
5
src/file/file-child.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
export class FileChild extends XmlComponent {
|
||||||
|
public readonly fileChild = Symbol();
|
||||||
|
}
|
@ -11,15 +11,13 @@ import { Footer, Header } from "./header";
|
|||||||
import { HeaderWrapper, IDocumentHeader } from "./header-wrapper";
|
import { HeaderWrapper, IDocumentHeader } from "./header-wrapper";
|
||||||
import { Media } from "./media";
|
import { Media } from "./media";
|
||||||
import { Numbering } from "./numbering";
|
import { Numbering } from "./numbering";
|
||||||
import { Paragraph } from "./paragraph";
|
|
||||||
import { Comments } from "./paragraph/run/comment-run";
|
import { Comments } from "./paragraph/run/comment-run";
|
||||||
import { Relationships } from "./relationships";
|
import { Relationships } from "./relationships";
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
import { Styles } from "./styles";
|
import { Styles } from "./styles";
|
||||||
import { ExternalStylesFactory } from "./styles/external-styles-factory";
|
import { ExternalStylesFactory } from "./styles/external-styles-factory";
|
||||||
import { DefaultStylesFactory } from "./styles/factory";
|
import { DefaultStylesFactory } from "./styles/factory";
|
||||||
import { Table } from "./table";
|
import { FileChild } from "./file-child";
|
||||||
import { TableOfContents } from "./table-of-contents";
|
|
||||||
|
|
||||||
export interface ISectionOptions {
|
export interface ISectionOptions {
|
||||||
readonly headers?: {
|
readonly headers?: {
|
||||||
@ -33,7 +31,7 @@ export interface ISectionOptions {
|
|||||||
readonly even?: Footer;
|
readonly even?: Footer;
|
||||||
};
|
};
|
||||||
readonly properties?: ISectionPropertiesOptions;
|
readonly properties?: ISectionPropertiesOptions;
|
||||||
readonly children: readonly (Paragraph | Table | TableOfContents)[];
|
readonly children: readonly FileChild[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class File {
|
export class File {
|
||||||
@ -73,7 +71,7 @@ export class File {
|
|||||||
this.appProperties = new AppProperties();
|
this.appProperties = new AppProperties();
|
||||||
this.footnotesWrapper = new FootnotesWrapper();
|
this.footnotesWrapper = new FootnotesWrapper();
|
||||||
this.contentTypes = new ContentTypes();
|
this.contentTypes = new ContentTypes();
|
||||||
this.documentWrapper = new DocumentWrapper({ background: options.background || {} });
|
this.documentWrapper = new DocumentWrapper({ background: options.background });
|
||||||
this.settings = new Settings({
|
this.settings = new Settings({
|
||||||
compatibilityModeVersion: options.compatabilityModeVersion,
|
compatibilityModeVersion: options.compatabilityModeVersion,
|
||||||
compatibility: options.compatibility,
|
compatibility: options.compatibility,
|
||||||
|
@ -12,9 +12,11 @@ describe("ConcreteNumbering", () => {
|
|||||||
abstractNumId: 1,
|
abstractNumId: 1,
|
||||||
reference: "1",
|
reference: "1",
|
||||||
instance: 0,
|
instance: 0,
|
||||||
overrideLevel: {
|
overrideLevels: [
|
||||||
num: 3,
|
{
|
||||||
},
|
num: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const tree = new Formatter().format(concreteNumbering);
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
@ -44,16 +46,61 @@ describe("ConcreteNumbering", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("sets a new override level for two different level numbers", () => {
|
||||||
|
const concreteNumbering = new ConcreteNumbering({
|
||||||
|
numId: 0,
|
||||||
|
abstractNumId: 1,
|
||||||
|
reference: "1",
|
||||||
|
instance: 0,
|
||||||
|
overrideLevels: [{ num: 3 }, { num: 5 }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:num": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:numId": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:abstractNumId": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("sets the startOverride element if start is given", () => {
|
it("sets the startOverride element if start is given", () => {
|
||||||
const concreteNumbering = new ConcreteNumbering({
|
const concreteNumbering = new ConcreteNumbering({
|
||||||
numId: 0,
|
numId: 0,
|
||||||
abstractNumId: 1,
|
abstractNumId: 1,
|
||||||
reference: "1",
|
reference: "1",
|
||||||
instance: 0,
|
instance: 0,
|
||||||
overrideLevel: {
|
overrideLevels: [
|
||||||
num: 1,
|
{
|
||||||
start: 9,
|
num: 1,
|
||||||
},
|
start: 9,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(concreteNumbering);
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
@ -90,15 +137,143 @@ describe("ConcreteNumbering", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("sets the startOverride element for several levels if start is given", () => {
|
||||||
|
const concreteNumbering = new ConcreteNumbering({
|
||||||
|
numId: 0,
|
||||||
|
abstractNumId: 1,
|
||||||
|
reference: "1",
|
||||||
|
instance: 0,
|
||||||
|
overrideLevels: [
|
||||||
|
{
|
||||||
|
num: 1,
|
||||||
|
start: 9,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
num: 3,
|
||||||
|
start: 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:num": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:numId": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:abstractNumId": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:startOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 9,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:startOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Mix of overrideLevels with start and without", () => {
|
||||||
|
const concreteNumbering = new ConcreteNumbering({
|
||||||
|
numId: 0,
|
||||||
|
abstractNumId: 1,
|
||||||
|
reference: "1",
|
||||||
|
instance: 0,
|
||||||
|
overrideLevels: [
|
||||||
|
{
|
||||||
|
num: 1,
|
||||||
|
start: 9,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
num: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:num": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:numId": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:abstractNumId": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": [
|
||||||
|
{
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:startOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 9,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:lvlOverride": {
|
||||||
|
_attr: {
|
||||||
|
"w:ilvl": 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("sets the lvl element if overrideLevel.Level is accessed", () => {
|
it("sets the lvl element if overrideLevel.Level is accessed", () => {
|
||||||
const concreteNumbering = new ConcreteNumbering({
|
const concreteNumbering = new ConcreteNumbering({
|
||||||
numId: 0,
|
numId: 0,
|
||||||
abstractNumId: 1,
|
abstractNumId: 1,
|
||||||
reference: "1",
|
reference: "1",
|
||||||
instance: 0,
|
instance: 0,
|
||||||
overrideLevel: {
|
overrideLevels: [
|
||||||
num: 1,
|
{
|
||||||
},
|
num: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(concreteNumbering);
|
const tree = new Formatter().format(concreteNumbering);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPnumbering-numFmt.php
|
// http://officeopenxml.com/WPnumbering-numFmt.php
|
||||||
|
// http://www.datypic.com/sc/ooxml/a-w_val-57.html
|
||||||
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber } from "@util/values";
|
import { decimalNumber } from "@util/values";
|
||||||
|
|
||||||
@ -6,21 +7,138 @@ import { AlignmentType } from "../paragraph/formatting";
|
|||||||
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
||||||
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
||||||
|
|
||||||
|
// TODO: Breaking change - consolidate with number-format
|
||||||
|
// <xsd:simpleType name="ST_NumberFormat">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="decimal"/>
|
||||||
|
// <xsd:enumeration value="upperRoman"/>
|
||||||
|
// <xsd:enumeration value="lowerRoman"/>
|
||||||
|
// <xsd:enumeration value="upperLetter"/>
|
||||||
|
// <xsd:enumeration value="lowerLetter"/>
|
||||||
|
// <xsd:enumeration value="ordinal"/>
|
||||||
|
// <xsd:enumeration value="cardinalText"/>
|
||||||
|
// <xsd:enumeration value="ordinalText"/>
|
||||||
|
// <xsd:enumeration value="hex"/>
|
||||||
|
// <xsd:enumeration value="chicago"/>
|
||||||
|
// <xsd:enumeration value="ideographDigital"/>
|
||||||
|
// <xsd:enumeration value="japaneseCounting"/>
|
||||||
|
// <xsd:enumeration value="aiueo"/>
|
||||||
|
// <xsd:enumeration value="iroha"/>
|
||||||
|
// <xsd:enumeration value="decimalFullWidth"/>
|
||||||
|
// <xsd:enumeration value="decimalHalfWidth"/>
|
||||||
|
// <xsd:enumeration value="japaneseLegal"/>
|
||||||
|
// <xsd:enumeration value="japaneseDigitalTenThousand"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedCircle"/>
|
||||||
|
// <xsd:enumeration value="decimalFullWidth2"/>
|
||||||
|
// <xsd:enumeration value="aiueoFullWidth"/>
|
||||||
|
// <xsd:enumeration value="irohaFullWidth"/>
|
||||||
|
// <xsd:enumeration value="decimalZero"/>
|
||||||
|
// <xsd:enumeration value="bullet"/>
|
||||||
|
// <xsd:enumeration value="ganada"/>
|
||||||
|
// <xsd:enumeration value="chosung"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedFullstop"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedParen"/>
|
||||||
|
// <xsd:enumeration value="decimalEnclosedCircleChinese"/>
|
||||||
|
// <xsd:enumeration value="ideographEnclosedCircle"/>
|
||||||
|
// <xsd:enumeration value="ideographTraditional"/>
|
||||||
|
// <xsd:enumeration value="ideographZodiac"/>
|
||||||
|
// <xsd:enumeration value="ideographZodiacTraditional"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseCounting"/>
|
||||||
|
// <xsd:enumeration value="ideographLegalTraditional"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseCountingThousand"/>
|
||||||
|
// <xsd:enumeration value="taiwaneseDigital"/>
|
||||||
|
// <xsd:enumeration value="chineseCounting"/>
|
||||||
|
// <xsd:enumeration value="chineseLegalSimplified"/>
|
||||||
|
// <xsd:enumeration value="chineseCountingThousand"/>
|
||||||
|
// <xsd:enumeration value="koreanDigital"/>
|
||||||
|
// <xsd:enumeration value="koreanCounting"/>
|
||||||
|
// <xsd:enumeration value="koreanLegal"/>
|
||||||
|
// <xsd:enumeration value="koreanDigital2"/>
|
||||||
|
// <xsd:enumeration value="vietnameseCounting"/>
|
||||||
|
// <xsd:enumeration value="russianLower"/>
|
||||||
|
// <xsd:enumeration value="russianUpper"/>
|
||||||
|
// <xsd:enumeration value="none"/>
|
||||||
|
// <xsd:enumeration value="numberInDash"/>
|
||||||
|
// <xsd:enumeration value="hebrew1"/>
|
||||||
|
// <xsd:enumeration value="hebrew2"/>
|
||||||
|
// <xsd:enumeration value="arabicAlpha"/>
|
||||||
|
// <xsd:enumeration value="arabicAbjad"/>
|
||||||
|
// <xsd:enumeration value="hindiVowels"/>
|
||||||
|
// <xsd:enumeration value="hindiConsonants"/>
|
||||||
|
// <xsd:enumeration value="hindiNumbers"/>
|
||||||
|
// <xsd:enumeration value="hindiCounting"/>
|
||||||
|
// <xsd:enumeration value="thaiLetters"/>
|
||||||
|
// <xsd:enumeration value="thaiNumbers"/>
|
||||||
|
// <xsd:enumeration value="thaiCounting"/>
|
||||||
|
// <xsd:enumeration value="bahtText"/>
|
||||||
|
// <xsd:enumeration value="dollarText"/>
|
||||||
|
// <xsd:enumeration value="custom"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum LevelFormat {
|
export enum LevelFormat {
|
||||||
BULLET = "bullet",
|
|
||||||
CARDINAL_TEXT = "cardinalText",
|
|
||||||
CHICAGO = "chicago",
|
|
||||||
DECIMAL = "decimal",
|
DECIMAL = "decimal",
|
||||||
|
UPPER_ROMAN = "upperRoman",
|
||||||
|
LOWER_ROMAN = "lowerRoman",
|
||||||
|
UPPER_LETTER = "upperLetter",
|
||||||
|
LOWER_LETTER = "lowerLetter",
|
||||||
|
ORDINAL = "ordinal",
|
||||||
|
CARDINAL_TEXT = "cardinalText",
|
||||||
|
ORDINAL_TEXT = "ordinalText",
|
||||||
|
HEX = "hex",
|
||||||
|
CHICAGO = "chicago",
|
||||||
|
IDEOGRAPH__DIGITAL = "ideographDigital",
|
||||||
|
JAPANESE_COUNTING = "japaneseCounting",
|
||||||
|
AIUEO = "aiueo",
|
||||||
|
IROHA = "iroha",
|
||||||
|
DECIMAL_FULL_WIDTH = "decimalFullWidth",
|
||||||
|
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
|
||||||
|
JAPANESE_LEGAL = "japaneseLegal",
|
||||||
|
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
|
||||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
||||||
|
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2",
|
||||||
|
AIUEO_FULL_WIDTH = "aiueoFullWidth",
|
||||||
|
IROHA_FULL_WIDTH = "irohaFullWidth",
|
||||||
|
DECIMAL_ZERO = "decimalZero",
|
||||||
|
BULLET = "bullet",
|
||||||
|
GANADA = "ganada",
|
||||||
|
CHOSUNG = "chosung",
|
||||||
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
||||||
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
||||||
DECIMAL_ZERO = "decimalZero",
|
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
|
||||||
LOWER_LETTER = "lowerLetter",
|
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
|
||||||
LOWER_ROMAN = "lowerRoman",
|
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
|
||||||
|
IDEOGRAPH_ZODIAC = "ideographZodiac",
|
||||||
|
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
|
||||||
|
TAIWANESE_COUNTING = "taiwaneseCounting",
|
||||||
|
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
|
||||||
|
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
|
||||||
|
TAIWANESE_DIGITAL = "taiwaneseDigital",
|
||||||
|
CHINESE_COUNTING = "chineseCounting",
|
||||||
|
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
|
||||||
|
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand",
|
||||||
|
KOREAN_DIGITAL = "koreanDigital",
|
||||||
|
KOREAN_COUNTING = "koreanCounting",
|
||||||
|
KOREAN_LEGAL = "koreanLegal",
|
||||||
|
KOREAN_DIGITAL2 = "koreanDigital2",
|
||||||
|
VIETNAMESE_COUNTING = "vietnameseCounting",
|
||||||
|
RUSSIAN_LOWER = "russianLower",
|
||||||
|
RUSSIAN_UPPER = "russianUpper",
|
||||||
NONE = "none",
|
NONE = "none",
|
||||||
ORDINAL_TEXT = "ordinalText",
|
NUMBER_IN_DASH = "numberInDash",
|
||||||
UPPER_LETTER = "upperLetter",
|
HEBREW1 = "hebrew1",
|
||||||
UPPER_ROMAN = "upperRoman",
|
HEBREW2 = "hebrew2",
|
||||||
|
ARABIC_ALPHA = "arabicAlpha",
|
||||||
|
ARABIC_ABJAD = "arabicAbjad",
|
||||||
|
HINDI_VOWELS = "hindiVowels",
|
||||||
|
HINDI_CONSONANTS = "hindiConsonants",
|
||||||
|
HINDI_NUMBERS = "hindiNumbers",
|
||||||
|
HINDI_COUNTING = "hindiCounting",
|
||||||
|
THAI_LETTERS = "thaiLetters",
|
||||||
|
THAI_NUMBERS = "thaiNumbers",
|
||||||
|
THAI_COUNTING = "thaiCounting",
|
||||||
|
BAHT_TEXT = "bahtText",
|
||||||
|
DOLLAR_TEXT = "dollarText",
|
||||||
|
CUSTOM = "custom",
|
||||||
}
|
}
|
||||||
|
|
||||||
class LevelAttributes extends XmlAttributeComponent<{
|
class LevelAttributes extends XmlAttributeComponent<{
|
||||||
|
@ -18,15 +18,17 @@ class NumAttributes extends XmlAttributeComponent<{
|
|||||||
protected readonly xmlKeys = { numId: "w:numId" };
|
protected readonly xmlKeys = { numId: "w:numId" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IOverrideLevel {
|
||||||
|
readonly num: number;
|
||||||
|
readonly start?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IConcreteNumberingOptions {
|
export interface IConcreteNumberingOptions {
|
||||||
readonly numId: number;
|
readonly numId: number;
|
||||||
readonly abstractNumId: number;
|
readonly abstractNumId: number;
|
||||||
readonly reference: string;
|
readonly reference: string;
|
||||||
readonly instance: number;
|
readonly instance: number;
|
||||||
readonly overrideLevel?: {
|
readonly overrideLevels?: readonly IOverrideLevel[];
|
||||||
readonly num: number;
|
|
||||||
readonly start?: number;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Numbering">
|
// <xsd:complexType name="CT_Numbering">
|
||||||
@ -60,8 +62,10 @@ export class ConcreteNumbering extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(new AbstractNumId(decimalNumber(options.abstractNumId)));
|
this.root.push(new AbstractNumId(decimalNumber(options.abstractNumId)));
|
||||||
|
|
||||||
if (options.overrideLevel) {
|
if (options.overrideLevels && options.overrideLevels.length) {
|
||||||
this.root.push(new LevelOverride(options.overrideLevel.num, options.overrideLevel.start));
|
for (const level of options.overrideLevels) {
|
||||||
|
this.root.push(new LevelOverride(level.num, level.start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,10 +164,12 @@ export class Numbering extends XmlComponent {
|
|||||||
abstractNumId: abstractNumbering.id,
|
abstractNumId: abstractNumbering.id,
|
||||||
reference: "default-bullet-numbering",
|
reference: "default-bullet-numbering",
|
||||||
instance: 0,
|
instance: 0,
|
||||||
overrideLevel: {
|
overrideLevels: [
|
||||||
num: 0,
|
{
|
||||||
start: 1,
|
num: 0,
|
||||||
},
|
start: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,16 +1,51 @@
|
|||||||
// http://officeopenxml.com/WPalignment.php
|
// http://officeopenxml.com/WPalignment.php
|
||||||
// http://officeopenxml.com/WPtableAlignment.php
|
// http://officeopenxml.com/WPtableAlignment.php
|
||||||
|
// http://www.datypic.com/sc/ooxml/t-w_ST_Jc.html
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_Jc">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="start"/>
|
||||||
|
// <xsd:enumeration value="center"/>
|
||||||
|
// <xsd:enumeration value="end"/>
|
||||||
|
// <xsd:enumeration value="both"/>
|
||||||
|
// <xsd:enumeration value="mediumKashida"/>
|
||||||
|
// <xsd:enumeration value="distribute"/>
|
||||||
|
// <xsd:enumeration value="numTab"/>
|
||||||
|
// <xsd:enumeration value="highKashida"/>
|
||||||
|
// <xsd:enumeration value="lowKashida"/>
|
||||||
|
// <xsd:enumeration value="thaiDistribute"/>
|
||||||
|
// <xsd:enumeration value="left"/>
|
||||||
|
// <xsd:enumeration value="right"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
export enum AlignmentType {
|
export enum AlignmentType {
|
||||||
|
/** Align Start */
|
||||||
START = "start",
|
START = "start",
|
||||||
END = "end",
|
/** Align Center */
|
||||||
CENTER = "center",
|
CENTER = "center",
|
||||||
|
/** End */
|
||||||
|
END = "end",
|
||||||
|
/** Justified */
|
||||||
BOTH = "both",
|
BOTH = "both",
|
||||||
JUSTIFIED = "both",
|
/** Medium Kashida Length */
|
||||||
|
MEDIUM_KASHIDA = "mediumKashida",
|
||||||
|
/** Distribute All Characters Equally */
|
||||||
DISTRIBUTE = "distribute",
|
DISTRIBUTE = "distribute",
|
||||||
|
/** Align to List Tab */
|
||||||
|
NUM_TAB = "numTab",
|
||||||
|
/** Widest Kashida Length */
|
||||||
|
HIGH_KASHIDA = "highKashida",
|
||||||
|
/** Low Kashida Length */
|
||||||
|
LOW_KASHIDA = "lowKashida",
|
||||||
|
/** Thai Language Justification */
|
||||||
|
THAI_DISTRIBUTE = "thaiDistribute",
|
||||||
|
/** Align Left */
|
||||||
LEFT = "left",
|
LEFT = "left",
|
||||||
|
/** Align Right */
|
||||||
RIGHT = "right",
|
RIGHT = "right",
|
||||||
|
/** Justified */
|
||||||
|
JUSTIFIED = "both",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
||||||
|
@ -1,39 +1,14 @@
|
|||||||
// http://officeopenxml.com/WPindentation.php
|
// http://officeopenxml.com/WPindentation.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
export interface IIndentAttributesProperties {
|
export interface IIndentAttributesProperties {
|
||||||
readonly start?: number | string;
|
readonly start?: number | UniversalMeasure;
|
||||||
readonly end?: number | string;
|
readonly end?: number | UniversalMeasure;
|
||||||
readonly left?: number | string;
|
readonly left?: number | UniversalMeasure;
|
||||||
readonly right?: number | string;
|
readonly right?: number | UniversalMeasure;
|
||||||
readonly hanging?: number | string;
|
readonly hanging?: number | PositiveUniversalMeasure;
|
||||||
readonly firstLine?: number | string;
|
readonly firstLine?: number | PositiveUniversalMeasure;
|
||||||
}
|
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Ind">
|
|
||||||
// <xsd:attribute name="start" type="ST_SignedTwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="startChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// <xsd:attribute name="end" type="ST_SignedTwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="endChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// <xsd:attribute name="left" type="ST_SignedTwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="leftChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// <xsd:attribute name="right" type="ST_SignedTwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="rightChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// <xsd:attribute name="hanging" type="s:ST_TwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="hangingChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// <xsd:attribute name="firstLine" type="s:ST_TwipsMeasure" use="optional"/>
|
|
||||||
// <xsd:attribute name="firstLineChars" type="ST_DecimalNumber" use="optional"/>
|
|
||||||
// </xsd:complexType>
|
|
||||||
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
start: "w:start",
|
|
||||||
end: "w:end",
|
|
||||||
left: "w:left",
|
|
||||||
right: "w:right",
|
|
||||||
hanging: "w:hanging",
|
|
||||||
firstLine: "w:firstLine",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_PPrBase">
|
// <xsd:complexType name="CT_PPrBase">
|
||||||
@ -43,14 +18,53 @@ class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties
|
|||||||
export class Indent extends XmlComponent {
|
export class Indent extends XmlComponent {
|
||||||
public constructor({ start, end, left, right, hanging, firstLine }: IIndentAttributesProperties) {
|
public constructor({ start, end, left, right, hanging, firstLine }: IIndentAttributesProperties) {
|
||||||
super("w:ind");
|
super("w:ind");
|
||||||
|
// <xsd:complexType name="CT_Ind">
|
||||||
|
// <xsd:attribute name="start" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="startChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// <xsd:attribute name="end" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="endChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// <xsd:attribute name="left" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="leftChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// <xsd:attribute name="right" type="ST_SignedTwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="rightChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// <xsd:attribute name="hanging" type="s:ST_TwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="hangingChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// <xsd:attribute name="firstLine" type="s:ST_TwipsMeasure" use="optional"/>
|
||||||
|
// <xsd:attribute name="firstLineChars" type="ST_DecimalNumber" use="optional"/>
|
||||||
|
// </xsd:complexType>
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new IndentAttributes({
|
new NextAttributeComponent<{
|
||||||
start: start === undefined ? undefined : signedTwipsMeasureValue(start),
|
readonly start?: number | UniversalMeasure;
|
||||||
end: end === undefined ? undefined : signedTwipsMeasureValue(end),
|
readonly end?: number | UniversalMeasure;
|
||||||
left: left === undefined ? undefined : signedTwipsMeasureValue(left),
|
readonly left?: number | UniversalMeasure;
|
||||||
right: right === undefined ? undefined : signedTwipsMeasureValue(right),
|
readonly right?: number | UniversalMeasure;
|
||||||
hanging: hanging === undefined ? undefined : twipsMeasureValue(hanging),
|
readonly hanging?: number | PositiveUniversalMeasure;
|
||||||
firstLine: firstLine === undefined ? undefined : twipsMeasureValue(firstLine),
|
readonly firstLine?: number | PositiveUniversalMeasure;
|
||||||
|
}>({
|
||||||
|
start: {
|
||||||
|
key: "w:start",
|
||||||
|
value: start === undefined ? undefined : signedTwipsMeasureValue(start),
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
key: "w:end",
|
||||||
|
value: end === undefined ? undefined : signedTwipsMeasureValue(end),
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
key: "w:left",
|
||||||
|
value: left === undefined ? undefined : signedTwipsMeasureValue(left),
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
key: "w:right",
|
||||||
|
value: right === undefined ? undefined : signedTwipsMeasureValue(right),
|
||||||
|
},
|
||||||
|
hanging: {
|
||||||
|
key: "w:hanging",
|
||||||
|
value: hanging === undefined ? undefined : twipsMeasureValue(hanging),
|
||||||
|
},
|
||||||
|
firstLine: {
|
||||||
|
key: "w:firstLine",
|
||||||
|
value: firstLine === undefined ? undefined : twipsMeasureValue(firstLine),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
export enum LineRuleType {
|
export enum LineRuleType {
|
||||||
AT_LEAST = "atLeast",
|
AT_LEAST = "atLeast",
|
||||||
EXACTLY = "exactly",
|
EXACTLY = "exactly",
|
||||||
|
EXACT = "exact",
|
||||||
AUTO = "auto",
|
AUTO = "auto",
|
||||||
}
|
}
|
||||||
export interface ISpacingProperties {
|
export interface ISpacingProperties {
|
||||||
|
@ -954,6 +954,7 @@ describe("Paragraph", () => {
|
|||||||
paragraph.prepForXml({
|
paragraph.prepForXml({
|
||||||
viewWrapper: viewWrapperMock,
|
viewWrapper: viewWrapperMock,
|
||||||
file: file,
|
file: file,
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// http://officeopenxml.com/WPparagraph.php
|
// http://officeopenxml.com/WPparagraph.php
|
||||||
import { FootnoteReferenceRun } from "@file/footnotes";
|
import { FootnoteReferenceRun } from "@file/footnotes";
|
||||||
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
import { IContext, IXmlableObject } from "@file/xml-components";
|
||||||
import { uniqueId } from "@util/convenience-functions";
|
import { uniqueId } from "@util/convenience-functions";
|
||||||
|
import { FileChild } from "@file/file-child";
|
||||||
|
|
||||||
import { TargetModeType } from "../relationships/relationship/relationship";
|
import { TargetModeType } from "../relationships/relationship/relationship";
|
||||||
import { DeletedTextRun, InsertedTextRun } from "../track-revision";
|
import { DeletedTextRun, InsertedTextRun } from "../track-revision";
|
||||||
@ -9,8 +10,10 @@ import { ColumnBreak, PageBreak } from "./formatting/break";
|
|||||||
import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./links";
|
import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } from "./links";
|
||||||
import { Math } from "./math";
|
import { Math } from "./math";
|
||||||
import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties";
|
import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties";
|
||||||
import { ImageRun, Run, SequentialIdentifier, SimpleField, SimpleMailMergeField, SymbolRun, TextRun } from "./run";
|
import { ImageRun, PageNumber, Run, SequentialIdentifier, SimpleField, SimpleMailMergeField, SymbolRun, TextRun } from "./run";
|
||||||
import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./run/comment-run";
|
import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./run/comment-run";
|
||||||
|
import { Begin, End, Separate } from "./run/field";
|
||||||
|
import { NumberOfPages, NumberOfPagesSection, Page } from "./run/page-number";
|
||||||
|
|
||||||
export type ParagraphChild =
|
export type ParagraphChild =
|
||||||
| TextRun
|
| TextRun
|
||||||
@ -32,14 +35,15 @@ export type ParagraphChild =
|
|||||||
| Comment
|
| Comment
|
||||||
| CommentRangeStart
|
| CommentRangeStart
|
||||||
| CommentRangeEnd
|
| CommentRangeEnd
|
||||||
| CommentReference;
|
| CommentReference
|
||||||
|
| PageNumber;
|
||||||
|
|
||||||
export interface IParagraphOptions extends IParagraphPropertiesOptions {
|
export interface IParagraphOptions extends IParagraphPropertiesOptions {
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
readonly children?: readonly ParagraphChild[];
|
readonly children?: readonly ParagraphChild[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Paragraph extends XmlComponent {
|
export class Paragraph extends FileChild {
|
||||||
private readonly properties: ParagraphProperties;
|
private readonly properties: ParagraphProperties;
|
||||||
|
|
||||||
public constructor(options: string | IParagraphOptions) {
|
public constructor(options: string | IParagraphOptions) {
|
||||||
@ -62,6 +66,34 @@ export class Paragraph extends XmlComponent {
|
|||||||
|
|
||||||
if (options.children) {
|
if (options.children) {
|
||||||
for (const child of options.children) {
|
for (const child of options.children) {
|
||||||
|
if (typeof child === "string") {
|
||||||
|
switch (child) {
|
||||||
|
case PageNumber.CURRENT:
|
||||||
|
this.root.push(new TextRun({ children: [new Begin()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new Page()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new Separate()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new End()] }));
|
||||||
|
break;
|
||||||
|
case PageNumber.TOTAL_PAGES:
|
||||||
|
this.root.push(new TextRun({ children: [new Begin()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new NumberOfPages()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new Separate()] }));
|
||||||
|
this.root.push(new TextRun("0"));
|
||||||
|
this.root.push(new TextRun({ children: [new End()] }));
|
||||||
|
break;
|
||||||
|
case PageNumber.TOTAL_PAGES_IN_SECTION:
|
||||||
|
this.root.push(new TextRun({ children: [new Begin()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new NumberOfPagesSection()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new Separate()] }));
|
||||||
|
this.root.push(new TextRun({ children: [new End()] }));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.root.push(new TextRun(child));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (child instanceof Bookmark) {
|
if (child instanceof Bookmark) {
|
||||||
this.root.push(child.start);
|
this.root.push(child.start);
|
||||||
for (const textRun of child.children) {
|
for (const textRun of child.children) {
|
||||||
|
@ -31,6 +31,7 @@ describe("ParagraphProperties", () => {
|
|||||||
} as File,
|
} as File,
|
||||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
viewWrapper: new DocumentWrapper({ background: {} }),
|
viewWrapper: new DocumentWrapper({ background: {} }),
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
|
@ -44,7 +44,7 @@ describe("Comment", () => {
|
|||||||
let clock: sinon.SinonFakeTimers;
|
let clock: sinon.SinonFakeTimers;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const now = new Date(1999, 0, 1);
|
const now = new Date("1999-01-01T00:00:00.000Z");
|
||||||
clock = sinon.useFakeTimers(now.getTime());
|
clock = sinon.useFakeTimers(now.getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ describe("Comment", () => {
|
|||||||
const component = new Comment({
|
const component = new Comment({
|
||||||
id: 0,
|
id: 0,
|
||||||
text: "test-comment",
|
text: "test-comment",
|
||||||
date: new Date(1999, 0, 1),
|
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(component);
|
const tree = new Formatter().format(component);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
@ -126,12 +126,12 @@ describe("Comments", () => {
|
|||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
text: "test-comment",
|
text: "test-comment",
|
||||||
date: new Date(1999, 0, 1),
|
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
text: "test-comment-2",
|
text: "test-comment-2",
|
||||||
date: new Date(1999, 0, 1),
|
date: new Date("1999-01-01T00:00:00.000Z"),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
229
src/file/paragraph/run/empty-children.spec.ts
Normal file
229
src/file/paragraph/run/empty-children.spec.ts
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
import {
|
||||||
|
AnnotationReference,
|
||||||
|
CarriageReturn,
|
||||||
|
ContinuationSeparator,
|
||||||
|
DayLong,
|
||||||
|
DayShort,
|
||||||
|
EndnoteReference,
|
||||||
|
FootnoteReferenceElement,
|
||||||
|
LastRenderedPageBreak,
|
||||||
|
MonthLong,
|
||||||
|
MonthShort,
|
||||||
|
NoBreakHyphen,
|
||||||
|
PageNumberElement,
|
||||||
|
Separator,
|
||||||
|
SoftHyphen,
|
||||||
|
Tab,
|
||||||
|
YearLong,
|
||||||
|
YearShort,
|
||||||
|
} from "./empty-children";
|
||||||
|
|
||||||
|
// <xsd:element name="noBreakHyphen" type="CT_Empty"/>
|
||||||
|
// <xsd:element name="softHyphen" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="annotationRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="footnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="endnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="separator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="continuationSeparator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="pgNum" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="cr" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="tab" type="CT_Empty" minOccurs="0" />
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="lastRenderedPageBreak" type="CT_Empty" minOccurs="0" maxOccurs="1" />
|
||||||
|
|
||||||
|
describe("NoBreakHyphen", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a NoBreakHyphen with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new NoBreakHyphen());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:noBreakHyphen": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("SoftHyphen", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a SoftHyphen with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new SoftHyphen());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:softHyphen": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DayShort", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a DayShort with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new DayShort());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:dayShort": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("MonthShort", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MonthShort with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new MonthShort());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:monthShort": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("YearShort", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a YearShort with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new YearShort());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:yearShort": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DayLong", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a DayLong with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new DayLong());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:dayLong": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("MonthLong", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MonthLong with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new MonthLong());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:monthLong": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("YearLong", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a YearLong with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new YearLong());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:yearLong": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AnnotationReference", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a AnnotationReference with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new AnnotationReference());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:annotationRef": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FootnoteReferenceElement", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a FootnoteReferenceElement with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new FootnoteReferenceElement());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:footnoteRef": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("EndnoteReference", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a EndnoteReference with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new EndnoteReference());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:endnoteRef": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Separator", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a Separator with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new Separator());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:separator": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ContinuationSeparator", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a ContinuationSeparator with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new ContinuationSeparator());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:continuationSeparator": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("PageNumberElement", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a PageNumberElement with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new PageNumberElement());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pgNum": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("CarriageReturn", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a CarriageReturn with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new CarriageReturn());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:cr": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Tab", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a Tab with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new Tab());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tab": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("LastRenderedPageBreak", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a LastRenderedPageBreak with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(new LastRenderedPageBreak());
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:lastRenderedPageBreak": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
127
src/file/paragraph/run/empty-children.ts
Normal file
127
src/file/paragraph/run/empty-children.ts
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
import { EmptyElement } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:group name="EG_RunInnerContent">
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="noBreakHyphen" type="CT_Empty"/>
|
||||||
|
// <xsd:element name="softHyphen" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="annotationRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="footnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="endnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="separator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="continuationSeparator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="pgNum" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="cr" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="tab" type="CT_Empty" minOccurs="0" />
|
||||||
|
// ...
|
||||||
|
// <xsd:element name="lastRenderedPageBreak" type="CT_Empty" minOccurs="0" maxOccurs="1" />
|
||||||
|
// </xsd:choice>
|
||||||
|
// </xsd:group>
|
||||||
|
|
||||||
|
export class NoBreakHyphen extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:noBreakHyphen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SoftHyphen extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:softHyphen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DayShort extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:dayShort");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MonthShort extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:monthShort");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class YearShort extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:yearShort");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DayLong extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:dayLong");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MonthLong extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:monthLong");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class YearLong extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:yearLong");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AnnotationReference extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:annotationRef");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FootnoteReferenceElement extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:footnoteRef");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EndnoteReference extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:endnoteRef");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Separator extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:separator");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ContinuationSeparator extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:continuationSeparator");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PageNumberElement extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:pgNum");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CarriageReturn extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:cr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Tab extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:tab");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LastRenderedPageBreak extends EmptyElement {
|
||||||
|
public constructor() {
|
||||||
|
super("w:lastRenderedPageBreak");
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,29 @@
|
|||||||
|
// http://www.datypic.com/sc/ooxml/e-w_fldChar-1.html
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_FldChar">
|
||||||
|
// <xsd:choice>
|
||||||
|
// <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1" />
|
||||||
|
// <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0" />
|
||||||
|
// </xsd:choice>
|
||||||
|
// <xsd:attribute name="fldCharType" type="ST_FldCharType" use="required" />
|
||||||
|
// <xsd:attribute name="fldLock" type="s:ST_OnOff" />
|
||||||
|
// <xsd:attribute name="dirty" type="s:ST_OnOff" />
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
enum FieldCharacterType {
|
enum FieldCharacterType {
|
||||||
BEGIN = "begin",
|
BEGIN = "begin",
|
||||||
END = "end",
|
END = "end",
|
||||||
SEPARATE = "separate",
|
SEPARATE = "separate",
|
||||||
}
|
}
|
||||||
|
|
||||||
class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> {
|
class FidCharAttrs extends XmlAttributeComponent<{
|
||||||
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
readonly type: FieldCharacterType;
|
||||||
|
readonly dirty?: boolean;
|
||||||
|
readonly fieldLock?: boolean;
|
||||||
|
}> {
|
||||||
|
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty", fieldLock: "w:fldLock" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Begin extends XmlComponent {
|
export class Begin extends XmlComponent {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||||
import { hexColorValue, signedTwipsMeasureValue } from "@util/values";
|
import { hexColorValue, signedTwipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
export class CharacterSpacing extends XmlComponent {
|
export class CharacterSpacing extends XmlComponent {
|
||||||
public constructor(value: number | string) {
|
public constructor(value: number | UniversalMeasure) {
|
||||||
super("w:spacing");
|
super("w:spacing");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
|
@ -47,6 +47,7 @@ describe("ImageRun", () => {
|
|||||||
},
|
},
|
||||||
} as unknown as File,
|
} as unknown as File,
|
||||||
viewWrapper: {} as unknown as IViewWrapper,
|
viewWrapper: {} as unknown as IViewWrapper,
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
@ -298,6 +299,7 @@ describe("ImageRun", () => {
|
|||||||
},
|
},
|
||||||
} as unknown as File,
|
} as unknown as File,
|
||||||
viewWrapper: {} as unknown as IViewWrapper,
|
viewWrapper: {} as unknown as IViewWrapper,
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:r": [
|
"w:r": [
|
||||||
@ -552,6 +554,7 @@ describe("ImageRun", () => {
|
|||||||
},
|
},
|
||||||
} as unknown as File,
|
} as unknown as File,
|
||||||
viewWrapper: {} as unknown as IViewWrapper,
|
viewWrapper: {} as unknown as IViewWrapper,
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
@ -810,6 +813,7 @@ describe("ImageRun", () => {
|
|||||||
},
|
},
|
||||||
} as unknown as File,
|
} as unknown as File,
|
||||||
viewWrapper: {} as unknown as IViewWrapper,
|
viewWrapper: {} as unknown as IViewWrapper,
|
||||||
|
stack: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
|
@ -7,6 +7,7 @@ export * from "./run-fonts";
|
|||||||
export * from "./sequential-identifier";
|
export * from "./sequential-identifier";
|
||||||
export * from "./underline";
|
export * from "./underline";
|
||||||
export * from "./emphasis-mark";
|
export * from "./emphasis-mark";
|
||||||
export * from "./tab";
|
|
||||||
export * from "./simple-field";
|
export * from "./simple-field";
|
||||||
export * from "./comment-run";
|
export * from "./comment-run";
|
||||||
|
export * from "./empty-children";
|
||||||
|
export * from "./positional-tab";
|
||||||
|
29
src/file/paragraph/run/language.spec.ts
Normal file
29
src/file/paragraph/run/language.spec.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { createLanguageComponent } from "./language";
|
||||||
|
|
||||||
|
describe("Language", () => {
|
||||||
|
describe("#createLanguageComponent", () => {
|
||||||
|
it("should create a language component", () => {
|
||||||
|
const tree = new Formatter().format(
|
||||||
|
createLanguageComponent({
|
||||||
|
value: "en-US",
|
||||||
|
eastAsia: "zh-CN",
|
||||||
|
bidirectional: "ar-SA",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:lang": {
|
||||||
|
_attr: {
|
||||||
|
"w:bidi": "ar-SA",
|
||||||
|
"w:eastAsia": "zh-CN",
|
||||||
|
"w:val": "en-US",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
35
src/file/paragraph/run/language.ts
Normal file
35
src/file/paragraph/run/language.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_Language">
|
||||||
|
// <xsd:attribute name="val" type="s:ST_Lang" use="optional"/>
|
||||||
|
// <xsd:attribute name="eastAsia" type="s:ST_Lang" use="optional"/>
|
||||||
|
// <xsd:attribute name="bidi" type="s:ST_Lang" use="optional"/>
|
||||||
|
// </xsd:complexType>
|
||||||
|
export interface ILanguageOptions {
|
||||||
|
readonly value?: string;
|
||||||
|
readonly eastAsia?: string;
|
||||||
|
readonly bidirectional?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createLanguageComponent = (options: ILanguageOptions): XmlComponent =>
|
||||||
|
new BuilderElement<{
|
||||||
|
readonly value?: string;
|
||||||
|
readonly eastAsia?: string;
|
||||||
|
readonly bidirectional?: string;
|
||||||
|
}>({
|
||||||
|
name: "w:lang",
|
||||||
|
attributes: {
|
||||||
|
value: {
|
||||||
|
key: "w:val",
|
||||||
|
value: options.value,
|
||||||
|
},
|
||||||
|
eastAsia: {
|
||||||
|
key: "w:eastAsia",
|
||||||
|
value: options.eastAsia,
|
||||||
|
},
|
||||||
|
bidirectional: {
|
||||||
|
key: "w:bidi",
|
||||||
|
value: options.bidirectional,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
27
src/file/paragraph/run/positional-tab.spec.ts
Normal file
27
src/file/paragraph/run/positional-tab.spec.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { PositionalTab, PositionalTabAlignment, PositionalTabLeader, PositionalTabRelativeTo } from "./positional-tab";
|
||||||
|
|
||||||
|
describe("PositionalTab", () => {
|
||||||
|
it("should create a PositionalTab with correct root key", () => {
|
||||||
|
const tree = new Formatter().format(
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.CENTER,
|
||||||
|
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||||
|
leader: PositionalTabLeader.DOT,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:ptab": {
|
||||||
|
_attr: {
|
||||||
|
"w:alignment": "center",
|
||||||
|
"w:relativeTo": "margin",
|
||||||
|
"w:leader": "dot",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
80
src/file/paragraph/run/positional-tab.ts
Normal file
80
src/file/paragraph/run/positional-tab.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PTabAlignment">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="left" />
|
||||||
|
// <xsd:enumeration value="center" />
|
||||||
|
// <xsd:enumeration value="right" />
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export enum PositionalTabAlignment {
|
||||||
|
LEFT = "left",
|
||||||
|
CENTER = "center",
|
||||||
|
RIGHT = "right",
|
||||||
|
}
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PTabRelativeTo">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="margin" />
|
||||||
|
// <xsd:enumeration value="indent" />
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export enum PositionalTabRelativeTo {
|
||||||
|
MARGIN = "margin",
|
||||||
|
INDENT = "indent",
|
||||||
|
}
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PTabLeader">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="none" />
|
||||||
|
// <xsd:enumeration value="dot" />
|
||||||
|
// <xsd:enumeration value="hyphen" />
|
||||||
|
// <xsd:enumeration value="underscore" />
|
||||||
|
// <xsd:enumeration value="middleDot" />
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export enum PositionalTabLeader {
|
||||||
|
NONE = "none",
|
||||||
|
DOT = "dot",
|
||||||
|
HYPHEN = "hyphen",
|
||||||
|
UNDERSCORE = "underscore",
|
||||||
|
MIDDLE_DOT = "middleDot",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PositionalTabOptions {
|
||||||
|
readonly alignment: PositionalTabAlignment;
|
||||||
|
readonly relativeTo: PositionalTabRelativeTo;
|
||||||
|
readonly leader: PositionalTabLeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_PTab">
|
||||||
|
// <xsd:attribute name="alignment" type="ST_PTabAlignment" use="required" />
|
||||||
|
// <xsd:attribute name="relativeTo" type="ST_PTabRelativeTo" use="required" />
|
||||||
|
// <xsd:attribute name="leader" type="ST_PTabLeader" use="required" />
|
||||||
|
// </xsd:complexType>
|
||||||
|
export class PositionalTab extends XmlComponent {
|
||||||
|
public constructor(options: PositionalTabOptions) {
|
||||||
|
super("w:ptab");
|
||||||
|
|
||||||
|
this.root.push(
|
||||||
|
new NextAttributeComponent<{
|
||||||
|
readonly alignment: PositionalTabAlignment;
|
||||||
|
readonly relativeTo: PositionalTabRelativeTo;
|
||||||
|
readonly leader: PositionalTabLeader;
|
||||||
|
}>({
|
||||||
|
alignment: {
|
||||||
|
key: "w:alignment",
|
||||||
|
value: options.alignment,
|
||||||
|
},
|
||||||
|
relativeTo: {
|
||||||
|
key: "w:relativeTo",
|
||||||
|
value: options.relativeTo,
|
||||||
|
},
|
||||||
|
leader: {
|
||||||
|
key: "w:leader",
|
||||||
|
value: options.leader,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -9,9 +9,11 @@ import {
|
|||||||
StringValueElement,
|
StringValueElement,
|
||||||
XmlComponent,
|
XmlComponent,
|
||||||
} from "@file/xml-components";
|
} from "@file/xml-components";
|
||||||
|
import { PositiveUniversalMeasure, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
||||||
import { CharacterSpacing, Color, Highlight, HighlightComplexScript } from "./formatting";
|
import { CharacterSpacing, Color, Highlight, HighlightComplexScript } from "./formatting";
|
||||||
|
import { createLanguageComponent, ILanguageOptions } from "./language";
|
||||||
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
|
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
|
||||||
import { SubScript, SuperScript } from "./script";
|
import { SubScript, SuperScript } from "./script";
|
||||||
import { Underline, UnderlineType } from "./underline";
|
import { Underline, UnderlineType } from "./underline";
|
||||||
@ -21,6 +23,16 @@ interface IFontOptions {
|
|||||||
readonly hint?: string;
|
readonly hint?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum TextEffect {
|
||||||
|
BLINK_BACKGROUND = "blinkBackground",
|
||||||
|
LIGHTS = "lights",
|
||||||
|
ANTS_BLACK = "antsBlack",
|
||||||
|
ANTS_RED = "antsRed",
|
||||||
|
SHIMMER = "shimmer",
|
||||||
|
SPARKLE = "sparkle",
|
||||||
|
NONE = "none",
|
||||||
|
}
|
||||||
|
|
||||||
export interface IRunStylePropertiesOptions {
|
export interface IRunStylePropertiesOptions {
|
||||||
readonly bold?: boolean;
|
readonly bold?: boolean;
|
||||||
readonly boldComplexScript?: boolean;
|
readonly boldComplexScript?: boolean;
|
||||||
@ -30,12 +42,15 @@ export interface IRunStylePropertiesOptions {
|
|||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly type?: UnderlineType;
|
readonly type?: UnderlineType;
|
||||||
};
|
};
|
||||||
|
readonly effect?: TextEffect;
|
||||||
readonly emphasisMark?: {
|
readonly emphasisMark?: {
|
||||||
readonly type?: EmphasisMarkType;
|
readonly type?: EmphasisMarkType;
|
||||||
};
|
};
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly size?: number | string;
|
readonly kern?: number | PositiveUniversalMeasure;
|
||||||
readonly sizeComplexScript?: boolean | number | string;
|
readonly position?: UniversalMeasure;
|
||||||
|
readonly size?: number | PositiveUniversalMeasure;
|
||||||
|
readonly sizeComplexScript?: boolean | number | PositiveUniversalMeasure;
|
||||||
readonly rightToLeft?: boolean;
|
readonly rightToLeft?: boolean;
|
||||||
readonly smallCaps?: boolean;
|
readonly smallCaps?: boolean;
|
||||||
readonly allCaps?: boolean;
|
readonly allCaps?: boolean;
|
||||||
@ -51,10 +66,13 @@ export interface IRunStylePropertiesOptions {
|
|||||||
readonly emboss?: boolean;
|
readonly emboss?: boolean;
|
||||||
readonly imprint?: boolean;
|
readonly imprint?: boolean;
|
||||||
readonly revision?: IRunPropertiesChangeOptions;
|
readonly revision?: IRunPropertiesChangeOptions;
|
||||||
|
readonly language?: ILanguageOptions;
|
||||||
readonly border?: IBorderOptions;
|
readonly border?: IBorderOptions;
|
||||||
|
readonly snapToGrid?: boolean;
|
||||||
readonly vanish?: boolean;
|
readonly vanish?: boolean;
|
||||||
readonly specVanish?: boolean;
|
readonly specVanish?: boolean;
|
||||||
readonly scale?: number;
|
readonly scale?: number;
|
||||||
|
readonly math?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
|
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
|
||||||
@ -133,6 +151,10 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
this.push(new Underline(options.underline.type, options.underline.color));
|
this.push(new Underline(options.underline.type, options.underline.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.effect) {
|
||||||
|
this.push(new StringValueElement("w:effect", options.effect));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.emphasisMark) {
|
if (options.emphasisMark) {
|
||||||
this.push(new EmphasisMark(options.emphasisMark.type));
|
this.push(new EmphasisMark(options.emphasisMark.type));
|
||||||
}
|
}
|
||||||
@ -141,6 +163,14 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
this.push(new Color(options.color));
|
this.push(new Color(options.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.kern) {
|
||||||
|
this.push(new HpsMeasureElement("w:kern", options.kern));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.position) {
|
||||||
|
this.push(new StringValueElement("w:position", options.position));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.size !== undefined) {
|
if (options.size !== undefined) {
|
||||||
this.push(new HpsMeasureElement("w:sz", options.size));
|
this.push(new HpsMeasureElement("w:sz", options.size));
|
||||||
}
|
}
|
||||||
@ -226,6 +256,10 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
this.push(new BorderElement("w:bdr", options.border));
|
this.push(new BorderElement("w:bdr", options.border));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.snapToGrid) {
|
||||||
|
this.push(new OnOffElement("w:snapToGrid", options.snapToGrid));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.vanish) {
|
if (options.vanish) {
|
||||||
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_vanish_topic_ID0E6W3O.html
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_vanish_topic_ID0E6W3O.html
|
||||||
// http://www.datypic.com/sc/ooxml/e-w_vanish-1.html
|
// http://www.datypic.com/sc/ooxml/e-w_vanish-1.html
|
||||||
@ -240,6 +274,14 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
if (options.scale !== undefined) {
|
if (options.scale !== undefined) {
|
||||||
this.push(new NumberValueElement("w:w", options.scale));
|
this.push(new NumberValueElement("w:w", options.scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.language) {
|
||||||
|
this.push(createLanguageComponent(options.language));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.math) {
|
||||||
|
this.push(new OnOffElement("w:oMath", options.math));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(item: XmlComponent): void {
|
public push(item: XmlComponent): void {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
|
import { SpaceType } from "@file/shared";
|
||||||
|
|
||||||
import { Text } from "./text";
|
import { Text } from "./text";
|
||||||
|
|
||||||
@ -13,5 +14,26 @@ describe("Text", () => {
|
|||||||
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
space: SpaceType.PRESERVE,
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds the passed in text to the component with options and sets default space type", () => {
|
||||||
|
const t = new Text({
|
||||||
|
text: " this is\n text",
|
||||||
|
});
|
||||||
|
const f = new Formatter().format(t);
|
||||||
|
expect(f).to.deep.equal({
|
||||||
|
"w:t": [{ _attr: { "xml:space": "default" } }, " this is\n text"],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,31 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
|
|
||||||
import { TextAttributes } from "../text-attributes";
|
import { TextAttributes } from "../text-attributes";
|
||||||
|
|
||||||
export class Text extends XmlComponent {
|
// <xsd:complexType name="CT_Text">
|
||||||
public constructor(text: string) {
|
// <xsd:simpleContent>
|
||||||
super("w:t");
|
// <xsd:extension base="s:ST_String">
|
||||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
// <xsd:attribute ref="xml:space" use="optional" />
|
||||||
|
// </xsd:extension>
|
||||||
|
// </xsd:simpleContent>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
this.root.push(text);
|
interface ITextOptions {
|
||||||
|
readonly space?: SpaceType;
|
||||||
|
readonly text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Text extends XmlComponent {
|
||||||
|
public constructor(options: string | ITextOptions) {
|
||||||
|
super("w:t");
|
||||||
|
|
||||||
|
if (typeof options === "string") {
|
||||||
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
|
this.root.push(options);
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
this.root.push(new TextAttributes({ space: options.space ?? SpaceType.DEFAULT }));
|
||||||
|
this.root.push(options.text);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import { ShadingType } from "@file/shading";
|
|||||||
import { EmphasisMarkType } from "./emphasis-mark";
|
import { EmphasisMarkType } from "./emphasis-mark";
|
||||||
import { PageNumber, Run } from "./run";
|
import { PageNumber, Run } from "./run";
|
||||||
import { UnderlineType } from "./underline";
|
import { UnderlineType } from "./underline";
|
||||||
|
import { TextEffect } from "./properties";
|
||||||
|
|
||||||
describe("Run", () => {
|
describe("Run", () => {
|
||||||
describe("#bold()", () => {
|
describe("#bold()", () => {
|
||||||
@ -580,5 +581,147 @@ describe("Run", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#language", () => {
|
||||||
|
it("should correctly set the language", () => {
|
||||||
|
const run = new Run({
|
||||||
|
language: {
|
||||||
|
value: "en-US",
|
||||||
|
eastAsia: "zh-CN",
|
||||||
|
bidirectional: "ar-SA",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:lang": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "en-US",
|
||||||
|
"w:eastAsia": "zh-CN",
|
||||||
|
"w:bidi": "ar-SA",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#position", () => {
|
||||||
|
it("should correctly set the position", () => {
|
||||||
|
const run = new Run({
|
||||||
|
position: "2mm",
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:position": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "2mm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#effect", () => {
|
||||||
|
it("should correctly set the effect", () => {
|
||||||
|
const run = new Run({
|
||||||
|
effect: TextEffect.ANTS_BLACK,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:effect": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "antsBlack",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#math", () => {
|
||||||
|
it("should correctly set the math", () => {
|
||||||
|
const run = new Run({
|
||||||
|
math: true,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:oMath": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#kern", () => {
|
||||||
|
it("should correctly set the kern", () => {
|
||||||
|
const run = new Run({
|
||||||
|
kern: "2mm",
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:kern": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "2mm",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#snapToGrid", () => {
|
||||||
|
it("should correctly set the snapToGrid", () => {
|
||||||
|
const run = new Run({
|
||||||
|
snapToGrid: true,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:snapToGrid": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,10 +9,91 @@ import { Begin, End, Separate } from "./field";
|
|||||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
||||||
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
||||||
import { Text } from "./run-components/text";
|
import { Text } from "./run-components/text";
|
||||||
import { Tab } from "./tab";
|
import {
|
||||||
|
AnnotationReference,
|
||||||
|
CarriageReturn,
|
||||||
|
ContinuationSeparator,
|
||||||
|
DayLong,
|
||||||
|
DayShort,
|
||||||
|
EndnoteReference,
|
||||||
|
FootnoteReferenceElement,
|
||||||
|
LastRenderedPageBreak,
|
||||||
|
MonthLong,
|
||||||
|
MonthShort,
|
||||||
|
NoBreakHyphen,
|
||||||
|
PageNumberElement,
|
||||||
|
Separator,
|
||||||
|
SoftHyphen,
|
||||||
|
Tab,
|
||||||
|
YearLong,
|
||||||
|
YearShort,
|
||||||
|
} from "./empty-children";
|
||||||
|
import { PositionalTab } from "./positional-tab";
|
||||||
|
|
||||||
export interface IRunOptions extends IRunPropertiesOptions {
|
export interface IRunOptions extends IRunPropertiesOptions {
|
||||||
readonly children?: readonly (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | Tab | string)[];
|
// <xsd:choice>
|
||||||
|
// <xsd:element name="br" type="CT_Br" />
|
||||||
|
// <xsd:element name="t" type="CT_Text" />
|
||||||
|
// <xsd:element name="contentPart" type="CT_Rel" />
|
||||||
|
// <xsd:element name="delText" type="CT_Text" />
|
||||||
|
// <xsd:element name="instrText" type="CT_Text" />
|
||||||
|
// <xsd:element name="delInstrText" type="CT_Text" />
|
||||||
|
// <xsd:element name="noBreakHyphen" type="CT_Empty" />
|
||||||
|
// <xsd:element name="softHyphen" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearShort" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="dayLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="monthLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="yearLong" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="annotationRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="footnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="endnoteRef" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="separator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="continuationSeparator" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="sym" type="CT_Sym" minOccurs="0" />
|
||||||
|
// <xsd:element name="pgNum" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="cr" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="tab" type="CT_Empty" minOccurs="0" />
|
||||||
|
// <xsd:element name="object" type="CT_Object" />
|
||||||
|
// <xsd:element name="pict" type="CT_Picture" />
|
||||||
|
// <xsd:element name="fldChar" type="CT_FldChar" />
|
||||||
|
// <xsd:element name="ruby" type="CT_Ruby" />
|
||||||
|
// <xsd:element name="footnoteReference" type="CT_FtnEdnRef" />
|
||||||
|
// <xsd:element name="endnoteReference" type="CT_FtnEdnRef" />
|
||||||
|
// <xsd:element name="commentReference" type="CT_Markup" />
|
||||||
|
// <xsd:element name="drawing" type="CT_Drawing" />
|
||||||
|
// <xsd:element name="ptab" type="CT_PTab" minOccurs="0" />
|
||||||
|
// <xsd:element name="lastRenderedPageBreak" type="CT_Empty" minOccurs="0" maxOccurs="1" />
|
||||||
|
// </xsd:choice>
|
||||||
|
readonly children?: readonly (
|
||||||
|
| Begin
|
||||||
|
| FieldInstruction
|
||||||
|
| Separate
|
||||||
|
| End
|
||||||
|
| PageNumber
|
||||||
|
| FootnoteReferenceRun
|
||||||
|
| Break
|
||||||
|
| AnnotationReference
|
||||||
|
| CarriageReturn
|
||||||
|
| ContinuationSeparator
|
||||||
|
| DayLong
|
||||||
|
| DayShort
|
||||||
|
| EndnoteReference
|
||||||
|
| FootnoteReferenceElement
|
||||||
|
| LastRenderedPageBreak
|
||||||
|
| MonthLong
|
||||||
|
| MonthShort
|
||||||
|
| NoBreakHyphen
|
||||||
|
| PageNumberElement
|
||||||
|
| Separator
|
||||||
|
| SoftHyphen
|
||||||
|
| Tab
|
||||||
|
| YearLong
|
||||||
|
| YearShort
|
||||||
|
| PositionalTab
|
||||||
|
| string
|
||||||
|
)[];
|
||||||
readonly break?: number;
|
readonly break?: number;
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export class SymbolRun extends Run {
|
|||||||
if (typeof options === "string") {
|
if (typeof options === "string") {
|
||||||
super({});
|
super({});
|
||||||
this.root.push(new Symbol(options));
|
this.root.push(new Symbol(options));
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
super(options);
|
super(options);
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
import { expect } from "chai";
|
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
|
||||||
|
|
||||||
import { Tab } from "./tab";
|
|
||||||
|
|
||||||
describe("Tab", () => {
|
|
||||||
let tab: Tab;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
tab = new Tab();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("#constructor()", () => {
|
|
||||||
it("should create a Tab with correct root key", () => {
|
|
||||||
const tree = new Formatter().format(tab);
|
|
||||||
expect(tree).to.deep.equal({
|
|
||||||
"w:tab": {},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,14 +0,0 @@
|
|||||||
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_tab_topic_ID0EM6AO.html
|
|
||||||
import { XmlComponent } from "@file/xml-components";
|
|
||||||
|
|
||||||
// <xsd:group name="EG_RunInnerContent">
|
|
||||||
// ...
|
|
||||||
// <xsd:element name="tab" type="CT_Empty" minOccurs="0"/>
|
|
||||||
//
|
|
||||||
// TODO: this is unused and undocumented currently.
|
|
||||||
// I think the intended use was for users to import, and insert as a child of `Run`.
|
|
||||||
export class Tab extends XmlComponent {
|
|
||||||
public constructor() {
|
|
||||||
super("w:tab");
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,6 +19,7 @@ export enum UnderlineType {
|
|||||||
WAVE = "wave",
|
WAVE = "wave",
|
||||||
WAVYHEAVY = "wavyHeavy",
|
WAVYHEAVY = "wavyHeavy",
|
||||||
WAVYDOUBLE = "wavyDouble",
|
WAVYDOUBLE = "wavyDouble",
|
||||||
|
NONE = "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Underline extends XmlComponent {
|
export class Underline extends XmlComponent {
|
||||||
|
@ -12,13 +12,9 @@ export class Relationships extends XmlComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addRelationship(relationship: Relationship): void {
|
|
||||||
this.root.push(relationship);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: TargetModeType): Relationship {
|
public createRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: TargetModeType): Relationship {
|
||||||
const relationship = new Relationship(`rId${id}`, type, target, targetMode);
|
const relationship = new Relationship(`rId${id}`, type, target, targetMode);
|
||||||
this.addRelationship(relationship);
|
this.root.push(relationship);
|
||||||
|
|
||||||
return relationship;
|
return relationship;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
const createLsdException = (name: string, uiPriority?: number, qFormat?: number, semiHidden?: number, unhideWhenUsed?: number) => {
|
const createLsdException = (
|
||||||
|
name: string,
|
||||||
|
uiPriority?: number,
|
||||||
|
qFormat?: number,
|
||||||
|
semiHidden?: number,
|
||||||
|
unhideWhenUsed?: number,
|
||||||
|
): readonly object[] => {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
import { Paragraph } from "@file/paragraph";
|
import { Paragraph } from "@file/paragraph";
|
||||||
import { Run } from "@file/paragraph/run";
|
import { Run } from "@file/paragraph/run";
|
||||||
import { Begin, End, Separate } from "@file/paragraph/run/field";
|
import { Begin, End, Separate } from "@file/paragraph/run/field";
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { FileChild } from "@file/file-child";
|
||||||
import { FieldInstruction } from "./field-instruction";
|
import { FieldInstruction } from "./field-instruction";
|
||||||
import { StructuredDocumentTagContent } from "./sdt-content";
|
import { StructuredDocumentTagContent } from "./sdt-content";
|
||||||
import { StructuredDocumentTagProperties } from "./sdt-properties";
|
import { StructuredDocumentTagProperties } from "./sdt-properties";
|
||||||
import { ITableOfContentsOptions } from "./table-of-contents-properties";
|
import { ITableOfContentsOptions } from "./table-of-contents-properties";
|
||||||
|
|
||||||
export class TableOfContents extends XmlComponent {
|
export class TableOfContents extends FileChild {
|
||||||
public constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) {
|
public constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) {
|
||||||
super("w:sdt");
|
super("w:sdt");
|
||||||
this.root.push(new StructuredDocumentTagProperties(alias));
|
this.root.push(new StructuredDocumentTagProperties(alias));
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
// </xsd:sequence>
|
// </xsd:sequence>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
export class TableGrid extends XmlComponent {
|
export class TableGrid extends XmlComponent {
|
||||||
public constructor(widths: readonly number[] | readonly string[]) {
|
public constructor(widths: readonly number[] | readonly PositiveUniversalMeasure[]) {
|
||||||
super("w:tblGrid");
|
super("w:tblGrid");
|
||||||
for (const width of widths) {
|
for (const width of widths) {
|
||||||
this.root.push(new GridCol(width));
|
this.root.push(new GridCol(width));
|
||||||
@ -21,15 +21,15 @@ export class TableGrid extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridColAttributes extends XmlAttributeComponent<{ readonly w: number | string }> {
|
|
||||||
protected readonly xmlKeys = { w: "w:w" };
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GridCol extends XmlComponent {
|
export class GridCol extends XmlComponent {
|
||||||
public constructor(width?: number | string) {
|
public constructor(width?: number | PositiveUniversalMeasure) {
|
||||||
super("w:gridCol");
|
super("w:gridCol");
|
||||||
if (width !== undefined) {
|
if (width !== undefined) {
|
||||||
this.root.push(new GridColAttributes({ w: twipsMeasureValue(width) }));
|
this.root.push(
|
||||||
|
new NextAttributeComponent<{ readonly width: number | PositiveUniversalMeasure }>({
|
||||||
|
width: { key: "w:w", value: twipsMeasureValue(width) },
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { StringEnumValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { StringEnumValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
export enum TableAnchorType {
|
export enum TableAnchorType {
|
||||||
MARGIN = "margin",
|
MARGIN = "margin",
|
||||||
@ -55,7 +55,7 @@ export interface ITableFloatOptions {
|
|||||||
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
|
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
|
||||||
* If the attribute is omitted, the value is assumed to be zero.
|
* If the attribute is omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly absoluteHorizontalPosition?: number | string;
|
readonly absoluteHorizontalPosition?: number | UniversalMeasure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
|
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
|
||||||
@ -86,7 +86,7 @@ export interface ITableFloatOptions {
|
|||||||
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
|
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
|
||||||
* If the attribute is omitted, the value is assumed to be zero.
|
* If the attribute is omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly absoluteVerticalPosition?: number | string;
|
readonly absoluteVerticalPosition?: number | UniversalMeasure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
|
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
|
||||||
@ -104,25 +104,25 @@ export interface ITableFloatOptions {
|
|||||||
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
|
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
|
||||||
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly bottomFromText?: number | string;
|
readonly bottomFromText?: number | PositiveUniversalMeasure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimum distance to be maintained between the table and the bottom edge of text in the paragraph
|
* Specifies the minimum distance to be maintained between the table and the bottom edge of text in the paragraph
|
||||||
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly topFromText?: number | string;
|
readonly topFromText?: number | PositiveUniversalMeasure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
||||||
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly leftFromText?: number | string;
|
readonly leftFromText?: number | PositiveUniversalMeasure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
|
||||||
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly rightFromText?: number | string;
|
readonly rightFromText?: number | PositiveUniversalMeasure;
|
||||||
readonly overlap?: OverlapType;
|
readonly overlap?: OverlapType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { twipsMeasureValue } from "@util/values";
|
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Height">
|
// <xsd:complexType name="CT_Height">
|
||||||
// <xsd:attribute name="val" type="s:ST_TwipsMeasure"/>
|
// <xsd:attribute name="val" type="s:ST_TwipsMeasure"/>
|
||||||
@ -30,7 +30,7 @@ export class TableRowHeightAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TableRowHeight extends XmlComponent {
|
export class TableRowHeight extends XmlComponent {
|
||||||
public constructor(value: number | string, rule: HeightRule) {
|
public constructor(value: number | PositiveUniversalMeasure, rule: HeightRule) {
|
||||||
super("w:trHeight");
|
super("w:trHeight");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
// </xsd:complexContent>
|
// </xsd:complexContent>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
import { IgnoreIfEmptyXmlComponent, OnOffElement } from "@file/xml-components";
|
import { IgnoreIfEmptyXmlComponent, OnOffElement } from "@file/xml-components";
|
||||||
|
import { PositiveUniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
import { HeightRule, TableRowHeight } from "./table-row-height";
|
import { HeightRule, TableRowHeight } from "./table-row-height";
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ export interface ITableRowPropertiesOptions {
|
|||||||
readonly cantSplit?: boolean;
|
readonly cantSplit?: boolean;
|
||||||
readonly tableHeader?: boolean;
|
readonly tableHeader?: boolean;
|
||||||
readonly height?: {
|
readonly height?: {
|
||||||
readonly value: number | string;
|
readonly value: number | PositiveUniversalMeasure;
|
||||||
readonly rule: HeightRule;
|
readonly rule: HeightRule;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// http://officeopenxml.com/WPtableWidth.php
|
// http://officeopenxml.com/WPtableWidth.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { measurementOrPercentValue } from "@util/values";
|
import { measurementOrPercentValue, Percentage, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_TblWidth">
|
// <xsd:simpleType name="ST_TblWidth">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -25,14 +25,10 @@ export enum WidthType {
|
|||||||
// <xsd:attribute name="w" type="ST_MeasurementOrPercent"/>
|
// <xsd:attribute name="w" type="ST_MeasurementOrPercent"/>
|
||||||
// <xsd:attribute name="type" type="ST_TblWidth"/>
|
// <xsd:attribute name="type" type="ST_TblWidth"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export interface ITableWidthProperties {
|
export type ITableWidthProperties = {
|
||||||
readonly size: string | number;
|
readonly size: number | Percentage | UniversalMeasure;
|
||||||
readonly type?: WidthType;
|
readonly type?: WidthType;
|
||||||
}
|
};
|
||||||
|
|
||||||
class TableWidthAttributes extends XmlAttributeComponent<ITableWidthProperties> {
|
|
||||||
protected readonly xmlKeys = { type: "w:type", size: "w:w" };
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableWidthElement extends XmlComponent {
|
export class TableWidthElement extends XmlComponent {
|
||||||
public constructor(name: string, { type = WidthType.AUTO, size }: ITableWidthProperties) {
|
public constructor(name: string, { type = WidthType.AUTO, size }: ITableWidthProperties) {
|
||||||
@ -42,6 +38,12 @@ export class TableWidthElement extends XmlComponent {
|
|||||||
if (type === WidthType.PERCENTAGE && typeof size === "number") {
|
if (type === WidthType.PERCENTAGE && typeof size === "number") {
|
||||||
tableWidthValue = `${size}%`;
|
tableWidthValue = `${size}%`;
|
||||||
}
|
}
|
||||||
this.root.push(new TableWidthAttributes({ type: type, size: measurementOrPercentValue(tableWidthValue) }));
|
|
||||||
|
this.root.push(
|
||||||
|
new NextAttributeComponent<ITableWidthProperties>({
|
||||||
|
type: { key: "w:type", value: type },
|
||||||
|
size: { key: "w:w", value: measurementOrPercentValue(tableWidthValue) },
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPtableGrid.php
|
// http://officeopenxml.com/WPtableGrid.php
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { FileChild } from "@file/file-child";
|
||||||
|
|
||||||
import { AlignmentType } from "../paragraph";
|
import { AlignmentType } from "../paragraph";
|
||||||
import { TableGrid } from "./grid";
|
import { TableGrid } from "./grid";
|
||||||
@ -34,7 +34,7 @@ export interface ITableOptions {
|
|||||||
readonly visuallyRightToLeft?: boolean;
|
readonly visuallyRightToLeft?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Table extends XmlComponent {
|
export class Table extends FileChild {
|
||||||
public constructor({
|
public constructor({
|
||||||
rows,
|
rows,
|
||||||
width,
|
width,
|
||||||
|
@ -5,6 +5,8 @@ import { IXmlableObject } from "./xmlable-object";
|
|||||||
export interface IContext {
|
export interface IContext {
|
||||||
readonly file: File;
|
readonly file: File;
|
||||||
readonly viewWrapper: IViewWrapper;
|
readonly viewWrapper: IViewWrapper;
|
||||||
|
// eslint-disable-next-line functional/prefer-readonly-type
|
||||||
|
readonly stack: IXmlableObject[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class BaseXmlComponent {
|
export abstract class BaseXmlComponent {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import { BaseXmlComponent, IContext } from "./base";
|
import { BaseXmlComponent, IContext } from "./base";
|
||||||
import { IXmlableObject } from "./xmlable-object";
|
import { IXmlableObject, IXmlAttribute } from "./xmlable-object";
|
||||||
|
|
||||||
export type AttributeMap<T> = { readonly [P in keyof T]: string };
|
export type AttributeMap<T> = { readonly [P in keyof T]: string };
|
||||||
|
|
||||||
|
export type AttributeData = { readonly [key: string]: boolean | number | string };
|
||||||
|
export type AttributePayload<T> = { readonly [P in keyof T]: { readonly key: string; readonly value: T[P] } };
|
||||||
|
|
||||||
export abstract class XmlAttributeComponent<T extends object> extends BaseXmlComponent {
|
export abstract class XmlAttributeComponent<T extends object> extends BaseXmlComponent {
|
||||||
// tslint:disable-next-line:readonly-keyword
|
|
||||||
protected readonly root: T;
|
|
||||||
protected readonly xmlKeys?: AttributeMap<T>;
|
protected readonly xmlKeys?: AttributeMap<T>;
|
||||||
|
|
||||||
public constructor(properties: T) {
|
public constructor(private readonly root: T) {
|
||||||
super("_attr");
|
super("_attr");
|
||||||
this.root = properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepForXml(_: IContext): IXmlableObject {
|
public prepForXml(_: IContext): IXmlableObject {
|
||||||
@ -26,3 +26,16 @@ export abstract class XmlAttributeComponent<T extends object> extends BaseXmlCom
|
|||||||
return { _attr: attrs };
|
return { _attr: attrs };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class NextAttributeComponent<T extends AttributeData> extends BaseXmlComponent {
|
||||||
|
public constructor(private readonly root: AttributePayload<T>) {
|
||||||
|
super("_attr");
|
||||||
|
}
|
||||||
|
|
||||||
|
public prepForXml(_: IContext): IXmlableObject {
|
||||||
|
const attrs = Object.values<{ readonly key: string; readonly value: string | boolean | number }>(this.root)
|
||||||
|
.filter(({ value }) => value !== undefined)
|
||||||
|
.reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {} as IXmlAttribute);
|
||||||
|
return { _attr: attrs };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -62,7 +62,7 @@ describe("ImportedXmlComponent", () => {
|
|||||||
describe("#prepForXml()", () => {
|
describe("#prepForXml()", () => {
|
||||||
it("should transform for xml", () => {
|
it("should transform for xml", () => {
|
||||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
const converted = importedXmlComponent.prepForXml({} as IContext);
|
const converted = importedXmlComponent.prepForXml({ stack: [] } as unknown as IContext);
|
||||||
expect(converted).to.deep.equal({
|
expect(converted).to.deep.equal({
|
||||||
"w:test": [
|
"w:test": [
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { AttributeData, AttributePayload, Attributes, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { hpsMeasureValue } from "@util/values";
|
import { hpsMeasureValue, PositiveUniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
// This represents element type CT_OnOff, which indicate a boolean value.
|
// This represents element type CT_OnOff, which indicate a boolean value.
|
||||||
//
|
//
|
||||||
@ -26,8 +26,13 @@ export class OnOffElement extends XmlComponent {
|
|||||||
// <xsd:complexType name="CT_HpsMeasure">
|
// <xsd:complexType name="CT_HpsMeasure">
|
||||||
// <xsd:attribute name="val" type="ST_HpsMeasure" use="required"/>
|
// <xsd:attribute name="val" type="ST_HpsMeasure" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_HpsMeasure">
|
||||||
|
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure" />
|
||||||
|
// </xsd:simpleType>
|
||||||
|
|
||||||
export class HpsMeasureElement extends XmlComponent {
|
export class HpsMeasureElement extends XmlComponent {
|
||||||
public constructor(name: string, val: number | string) {
|
public constructor(name: string, val: number | PositiveUniversalMeasure) {
|
||||||
super(name);
|
super(name);
|
||||||
this.root.push(new Attributes({ val: hpsMeasureValue(val) }));
|
this.root.push(new Attributes({ val: hpsMeasureValue(val) }));
|
||||||
}
|
}
|
||||||
@ -35,6 +40,11 @@ export class HpsMeasureElement extends XmlComponent {
|
|||||||
|
|
||||||
// This represents element type CT_String, which indicate a string value.
|
// This represents element type CT_String, which indicate a string value.
|
||||||
//
|
//
|
||||||
|
// <xsd:complexType name="CT_Empty"/>
|
||||||
|
export class EmptyElement extends XmlComponent {}
|
||||||
|
|
||||||
|
// This represents element type CT_Empty, which indicate aan empty element.
|
||||||
|
//
|
||||||
// <xsd:complexType name="CT_String">
|
// <xsd:complexType name="CT_String">
|
||||||
// <xsd:attribute name="val" type="s:ST_String" use="required"/>
|
// <xsd:attribute name="val" type="s:ST_String" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
@ -70,3 +80,17 @@ export class StringContainer extends XmlComponent {
|
|||||||
this.root.push(val);
|
this.root.push(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class BuilderElement<T extends AttributeData> extends XmlComponent {
|
||||||
|
public constructor(options: {
|
||||||
|
readonly name: string;
|
||||||
|
readonly attributes?: AttributePayload<T>;
|
||||||
|
readonly children?: readonly XmlComponent[];
|
||||||
|
}) {
|
||||||
|
super(options.name);
|
||||||
|
|
||||||
|
if (options.attributes) {
|
||||||
|
this.root.push(new NextAttributeComponent(options.attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,7 +12,15 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
|||||||
this.root = new Array<BaseXmlComponent | string>();
|
this.root = new Array<BaseXmlComponent | string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is called by the formatter to get the XML representation of this component.
|
||||||
|
// It is called recursively for all child components.
|
||||||
|
// It is a serializer to be used in the xml library.
|
||||||
|
// https://www.npmjs.com/package/xml
|
||||||
|
// Child components can override this method to customize the XML representation, or execute side effects.
|
||||||
public prepForXml(context: IContext): IXmlableObject | undefined {
|
public prepForXml(context: IContext): IXmlableObject | undefined {
|
||||||
|
// Mutating the stack is required for performance reasons
|
||||||
|
// eslint-disable-next-line functional/immutable-data
|
||||||
|
context.stack.push(this);
|
||||||
const children = this.root
|
const children = this.root
|
||||||
.map((comp) => {
|
.map((comp) => {
|
||||||
if (comp instanceof BaseXmlComponent) {
|
if (comp instanceof BaseXmlComponent) {
|
||||||
@ -21,6 +29,9 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
|||||||
return comp;
|
return comp;
|
||||||
})
|
})
|
||||||
.filter((comp) => comp !== undefined); // Exclude undefined
|
.filter((comp) => comp !== undefined); // Exclude undefined
|
||||||
|
|
||||||
|
// eslint-disable-next-line functional/immutable-data
|
||||||
|
context.stack.pop();
|
||||||
// If we only have a single IXmlableObject in our children array and it
|
// If we only have a single IXmlableObject in our children array and it
|
||||||
// represents our attributes, use the object itself as our children to
|
// represents our attributes, use the object itself as our children to
|
||||||
// avoid an unneeded XML close element.
|
// avoid an unneeded XML close element.
|
||||||
|
@ -25,13 +25,6 @@ describe("values", () => {
|
|||||||
expect(universalMeasureValue("5.22pc")).to.eq("5.22pc");
|
expect(universalMeasureValue("5.22pc")).to.eq("5.22pc");
|
||||||
expect(universalMeasureValue("100 pi")).to.eq("100pi");
|
expect(universalMeasureValue("100 pi")).to.eq("100pi");
|
||||||
});
|
});
|
||||||
it("should throw on invalid values", () => {
|
|
||||||
expect(() => universalMeasureValue("100pp")).to.throw();
|
|
||||||
expect(() => universalMeasureValue("foo")).to.throw();
|
|
||||||
expect(() => universalMeasureValue("--in")).to.throw();
|
|
||||||
expect(() => universalMeasureValue("NaNpc")).to.throw();
|
|
||||||
expect(() => universalMeasureValue("50")).to.throw();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("positiveUniversalMeasureValue", () => {
|
describe("positiveUniversalMeasureValue", () => {
|
||||||
@ -46,11 +39,6 @@ describe("values", () => {
|
|||||||
it("should throw on invalid values", () => {
|
it("should throw on invalid values", () => {
|
||||||
expect(() => positiveUniversalMeasureValue("-9mm")).to.throw();
|
expect(() => positiveUniversalMeasureValue("-9mm")).to.throw();
|
||||||
expect(() => positiveUniversalMeasureValue("-0.5in")).to.throw();
|
expect(() => positiveUniversalMeasureValue("-0.5in")).to.throw();
|
||||||
expect(() => positiveUniversalMeasureValue("100pp")).to.throw();
|
|
||||||
expect(() => positiveUniversalMeasureValue("foo")).to.throw();
|
|
||||||
expect(() => positiveUniversalMeasureValue("--in")).to.throw();
|
|
||||||
expect(() => positiveUniversalMeasureValue("NaNpc")).to.throw();
|
|
||||||
expect(() => positiveUniversalMeasureValue("50")).to.throw();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -116,7 +104,6 @@ describe("values", () => {
|
|||||||
});
|
});
|
||||||
it("should throw on invalid values", () => {
|
it("should throw on invalid values", () => {
|
||||||
expect(() => signedTwipsMeasureValue(NaN)).to.throw();
|
expect(() => signedTwipsMeasureValue(NaN)).to.throw();
|
||||||
expect(() => signedTwipsMeasureValue("foo")).to.throw();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,7 +116,6 @@ describe("values", () => {
|
|||||||
it("should throw on invalid values", () => {
|
it("should throw on invalid values", () => {
|
||||||
expect(() => twipsMeasureValue(-12)).to.throw();
|
expect(() => twipsMeasureValue(-12)).to.throw();
|
||||||
expect(() => twipsMeasureValue(NaN)).to.throw();
|
expect(() => twipsMeasureValue(NaN)).to.throw();
|
||||||
expect(() => twipsMeasureValue("foo")).to.throw();
|
|
||||||
expect(() => twipsMeasureValue("-5mm")).to.throw();
|
expect(() => twipsMeasureValue("-5mm")).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -154,7 +140,6 @@ describe("values", () => {
|
|||||||
});
|
});
|
||||||
it("should throw on invalid values", () => {
|
it("should throw on invalid values", () => {
|
||||||
expect(() => hpsMeasureValue(NaN)).to.throw();
|
expect(() => hpsMeasureValue(NaN)).to.throw();
|
||||||
expect(() => hpsMeasureValue("5FF")).to.throw();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -165,11 +150,6 @@ describe("values", () => {
|
|||||||
expect(percentageValue("100%")).to.eq("100%");
|
expect(percentageValue("100%")).to.eq("100%");
|
||||||
expect(percentageValue("1000%")).to.eq("1000%");
|
expect(percentageValue("1000%")).to.eq("1000%");
|
||||||
});
|
});
|
||||||
it("should throw on invalid values", () => {
|
|
||||||
expect(() => percentageValue("0%%")).to.throw();
|
|
||||||
expect(() => percentageValue("20")).to.throw();
|
|
||||||
expect(() => percentageValue("FF%")).to.throw();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("measurementOrPercentValue", () => {
|
describe("measurementOrPercentValue", () => {
|
||||||
@ -181,8 +161,6 @@ describe("values", () => {
|
|||||||
});
|
});
|
||||||
it("should throw on invalid values", () => {
|
it("should throw on invalid values", () => {
|
||||||
expect(() => measurementOrPercentValue(NaN)).to.throw();
|
expect(() => measurementOrPercentValue(NaN)).to.throw();
|
||||||
expect(() => measurementOrPercentValue("10%%")).to.throw();
|
|
||||||
expect(() => measurementOrPercentValue("10F")).to.throw();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,6 +4,23 @@
|
|||||||
// Most of the rest of the types not defined here are either aliases of existing types or enumerations.
|
// Most of the rest of the types not defined here are either aliases of existing types or enumerations.
|
||||||
// Enumerations should probably just be implemented as enums, with instructions to end-users, without a runtime check.
|
// Enumerations should probably just be implemented as enums, with instructions to end-users, without a runtime check.
|
||||||
|
|
||||||
|
// -?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)
|
||||||
|
export type UniversalMeasure = `${"-" | ""}${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PositiveUniversalMeasure">
|
||||||
|
// <xsd:restriction base="ST_UniversalMeasure">
|
||||||
|
// <xsd:pattern value="[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)" />
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export type PositiveUniversalMeasure = `${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_Percentage">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export type Percentage = `${"-" | ""}${number}%`;
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_DecimalNumber">
|
// <xsd:simpleType name="ST_DecimalNumber">
|
||||||
// <xsd:restriction base="xsd:integer"/>
|
// <xsd:restriction base="xsd:integer"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
@ -70,30 +87,23 @@ export const uCharHexNumber = (val: string): string => hexBinary(val, 1);
|
|||||||
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const universalMeasureValue = (val: string): string => {
|
export const universalMeasureValue = (val: UniversalMeasure): UniversalMeasure => {
|
||||||
const unit = val.slice(-2);
|
const unit = val.slice(-2);
|
||||||
if (!universalMeasureUnits.includes(unit)) {
|
|
||||||
throw new Error(`Invalid unit '${unit}' specified. Valid units are ${universalMeasureUnits.join(", ")}`);
|
|
||||||
}
|
|
||||||
const amount = val.substring(0, val.length - 2);
|
const amount = val.substring(0, val.length - 2);
|
||||||
if (isNaN(Number(amount))) {
|
return `${Number(amount)}${unit}` as UniversalMeasure;
|
||||||
throw new Error(`Invalid value '${amount}' specified. Expected a valid number.`);
|
|
||||||
}
|
|
||||||
return `${Number(amount)}${unit}`;
|
|
||||||
};
|
};
|
||||||
const universalMeasureUnits = ["mm", "cm", "in", "pt", "pc", "pi"];
|
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PositiveUniversalMeasure">
|
// <xsd:simpleType name="ST_PositiveUniversalMeasure">
|
||||||
// <xsd:restriction base="ST_UniversalMeasure">
|
// <xsd:restriction base="ST_UniversalMeasure">
|
||||||
// <xsd:pattern value="[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
// <xsd:pattern value="[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const positiveUniversalMeasureValue = (val: string): string => {
|
export const positiveUniversalMeasureValue = (val: PositiveUniversalMeasure): PositiveUniversalMeasure => {
|
||||||
const value = universalMeasureValue(val);
|
const value = universalMeasureValue(val);
|
||||||
if (parseFloat(value) < 0) {
|
if (parseFloat(value) < 0) {
|
||||||
throw new Error(`Invalid value '${value}' specified. Expected a positive number.`);
|
throw new Error(`Invalid value '${value}' specified. Expected a positive number.`);
|
||||||
}
|
}
|
||||||
return value;
|
return value as PositiveUniversalMeasure;
|
||||||
};
|
};
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_HexColor">
|
// <xsd:simpleType name="ST_HexColor">
|
||||||
@ -123,25 +133,25 @@ export const hexColorValue = (val: string): string => {
|
|||||||
// <xsd:simpleType name="ST_SignedTwipsMeasure">
|
// <xsd:simpleType name="ST_SignedTwipsMeasure">
|
||||||
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const signedTwipsMeasureValue = (val: string | number): string | number =>
|
export const signedTwipsMeasureValue = (val: UniversalMeasure | number): UniversalMeasure | number =>
|
||||||
typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_HpsMeasure">
|
// <xsd:simpleType name="ST_HpsMeasure">
|
||||||
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure"/>
|
// <xsd:union memberTypes="s:ST_UnsignedDecimalNumber s:ST_PositiveUniversalMeasure"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const hpsMeasureValue = (val: string | number): string | number =>
|
export const hpsMeasureValue = (val: PositiveUniversalMeasure | number): string | number =>
|
||||||
typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_SignedHpsMeasure">
|
// <xsd:simpleType name="ST_SignedHpsMeasure">
|
||||||
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
// <xsd:union memberTypes="xsd:integer s:ST_UniversalMeasure"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const signedHpsMeasureValue = (val: string | number): string | number =>
|
export const signedHpsMeasureValue = (val: UniversalMeasure | number): string | number =>
|
||||||
typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_TwipsMeasure">
|
// <xsd:simpleType name="ST_TwipsMeasure">
|
||||||
// <xsd:union memberTypes="ST_UnsignedDecimalNumber ST_PositiveUniversalMeasure"/>
|
// <xsd:union memberTypes="ST_UnsignedDecimalNumber ST_PositiveUniversalMeasure"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const twipsMeasureValue = (val: string | number): string | number =>
|
export const twipsMeasureValue = (val: PositiveUniversalMeasure | number): PositiveUniversalMeasure | number =>
|
||||||
typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_Percentage">
|
// <xsd:simpleType name="ST_Percentage">
|
||||||
@ -149,14 +159,8 @@ export const twipsMeasureValue = (val: string | number): string | number =>
|
|||||||
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/>
|
// <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export const percentageValue = (val: string): string => {
|
export const percentageValue = (val: Percentage): Percentage => {
|
||||||
if (val.slice(-1) !== "%") {
|
|
||||||
throw new Error(`Invalid value '${val}'. Expected percentage value (eg '55%')`);
|
|
||||||
}
|
|
||||||
const percent = val.substring(0, val.length - 1);
|
const percent = val.substring(0, val.length - 1);
|
||||||
if (isNaN(Number(percent))) {
|
|
||||||
throw new Error(`Invalid value '${percent}' specified. Expected a valid number.`);
|
|
||||||
}
|
|
||||||
return `${Number(percent)}%`;
|
return `${Number(percent)}%`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,14 +176,14 @@ export const percentageValue = (val: string): string => {
|
|||||||
// <xsd:restriction base="xsd:integer"/>
|
// <xsd:restriction base="xsd:integer"/>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
|
|
||||||
export const measurementOrPercentValue = (val: number | string): number | string => {
|
export const measurementOrPercentValue = (val: number | Percentage | UniversalMeasure): number | UniversalMeasure | Percentage => {
|
||||||
if (typeof val === "number") {
|
if (typeof val === "number") {
|
||||||
return decimalNumber(val);
|
return decimalNumber(val);
|
||||||
}
|
}
|
||||||
if (val.slice(-1) === "%") {
|
if (val.slice(-1) === "%") {
|
||||||
return percentageValue(val);
|
return percentageValue(val as Percentage);
|
||||||
}
|
}
|
||||||
return universalMeasureValue(val);
|
return universalMeasureValue(val as UniversalMeasure);
|
||||||
};
|
};
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_EighthPointMeasure">
|
// <xsd:simpleType name="ST_EighthPointMeasure">
|
||||||
|
Reference in New Issue
Block a user