Compare commits
83 Commits
8.2.3
...
feature/im
Author | SHA1 | Date | |
---|---|---|---|
7d53e5d5f2 | |||
d23f453d28 | |||
6c28f8bab0 | |||
10b87b5a70 | |||
6b6f9d7ed4 | |||
0434d00ff7 | |||
7e3acc25b9 | |||
62ad8f12b7 | |||
a6a656f1a0 | |||
1bf36009e8 | |||
86bdf3e199 | |||
a3c796aae3 | |||
dbe0586f70 | |||
7e2538dffc | |||
c3080ff9d9 | |||
772fc8462a | |||
e194780cd1 | |||
5b80ea32d7 | |||
31b7e07ab3 | |||
939d418af1 | |||
4258dd2a2e | |||
b7334a1ab5 | |||
9229f45d59 | |||
2bd4aacdd5 | |||
abbd695a8f | |||
f7b98bcde8 | |||
a756a7697c | |||
fd1ea5b4dc | |||
d83e089cd3 | |||
33715cc50c | |||
f3f1f2d0b1 | |||
c35e706fa8 | |||
35cebfe1a2 | |||
d04c42cbe8 | |||
8744e613ac | |||
cbeecbf3e1 | |||
f8ab2d1701 | |||
adc5c6f594 | |||
c9524cc497 | |||
90de6ba7e1 | |||
78d74ae60b | |||
579593a467 | |||
b5393dadae | |||
528ab1933e | |||
36181f8c91 | |||
45af681db1 | |||
ad6b482136 | |||
a6e1c2b019 | |||
3eb98533ae | |||
f5f021834e | |||
35702c3f77 | |||
8fbbd571ad | |||
2dd228be69 | |||
562835cfe7 | |||
6bac06e84d | |||
88436168ee | |||
0c3206d2e2 | |||
033debd339 | |||
d4f160732a | |||
4238fc9ab4 | |||
0d042b8dd1 | |||
afdd5f2d8f | |||
70c7b3d1b3 | |||
7b1cd5fe86 | |||
09ab169ffd | |||
35a82cf12e | |||
8d33cb01dd | |||
438d11dd86 | |||
d23b0d0789 | |||
1fa8c7ac82 | |||
3d6ead0359 | |||
379050dccd | |||
f9d1c197cf | |||
a89ee463e6 | |||
036caaacc8 | |||
80c37afe2b | |||
3a36d912fe | |||
c741d5d8ac | |||
0fa7dd13ad | |||
066aa56f6a | |||
3997b7a5d6 | |||
9577192d41 | |||
f2b1587bff |
@ -17,6 +17,7 @@
|
|||||||
"dolan",
|
"dolan",
|
||||||
"execa",
|
"execa",
|
||||||
"falsey",
|
"falsey",
|
||||||
|
"horz",
|
||||||
"iife",
|
"iife",
|
||||||
"Initializable",
|
"Initializable",
|
||||||
"iroha",
|
"iroha",
|
||||||
@ -53,7 +54,8 @@
|
|||||||
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
||||||
"/<element name=\"[a-z]+\"/gi",
|
"/<element name=\"[a-z]+\"/gi",
|
||||||
"/<attribute name=\"[a-z]+\"/gi"
|
"/<attribute name=\"[a-z]+\"/gi",
|
||||||
|
"/key: \".+\"/"
|
||||||
],
|
],
|
||||||
"ignorePaths": ["package.json", "docs/api", "*.docx", "build"],
|
"ignorePaths": ["package.json", "docs/api", "*.docx", "build"],
|
||||||
"allowCompoundWords": true,
|
"allowCompoundWords": true,
|
||||||
|
@ -7,7 +7,6 @@ parser: "@typescript-eslint/parser"
|
|||||||
parserOptions:
|
parserOptions:
|
||||||
project:
|
project:
|
||||||
- tsconfig.json
|
- tsconfig.json
|
||||||
- demo/tsconfig.json
|
|
||||||
sourceType: module
|
sourceType: module
|
||||||
plugins:
|
plugins:
|
||||||
- eslint-plugin-import
|
- eslint-plugin-import
|
||||||
@ -93,6 +92,7 @@ rules:
|
|||||||
format:
|
format:
|
||||||
- camelCase
|
- camelCase
|
||||||
- PascalCase
|
- PascalCase
|
||||||
|
- UPPER_CASE # for constants
|
||||||
filter:
|
filter:
|
||||||
regex: (^[a-z]+:.+)|_attr|[0-9]
|
regex: (^[a-z]+:.+)|_attr|[0-9]
|
||||||
match: false
|
match: false
|
||||||
@ -214,8 +214,7 @@ rules:
|
|||||||
valid-typeof: "off"
|
valid-typeof: "off"
|
||||||
functional/immutable-data:
|
functional/immutable-data:
|
||||||
- error
|
- error
|
||||||
- assumeTypes: true
|
- ignoreImmediateMutation: true
|
||||||
ignoreImmediateMutation: true
|
|
||||||
ignoreAccessorPattern:
|
ignoreAccessorPattern:
|
||||||
- "**.root*"
|
- "**.root*"
|
||||||
- "**.numberingReferences*"
|
- "**.numberingReferences*"
|
||||||
|
12
.github/actions/install-and-build/action.yml
vendored
Normal file
12
.github/actions/install-and-build/action.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
name: Install dependencies and build ⚙️
|
||||||
|
description: Install dependencies and build
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Install Dependencies
|
||||||
|
shell: bash
|
||||||
|
run: npm ci --force
|
||||||
|
- name: Build
|
||||||
|
shell: bash
|
||||||
|
run: npm run build
|
14
.github/actions/validate-docx/action.yml
vendored
Normal file
14
.github/actions/validate-docx/action.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
name: Extract and Validate Document ⚙️
|
||||||
|
description: Extract the document and validate the XML against the schema.
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Extract Word Document
|
||||||
|
shell: bash
|
||||||
|
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
|
9
.github/workflows/default.yml
vendored
9
.github/workflows/default.yml
vendored
@ -14,10 +14,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- uses: "./.github/actions/install-and-build"
|
||||||
run: npm ci --force
|
|
||||||
- name: Build
|
|
||||||
run: npm run build
|
|
||||||
- name: Archive Production Artifact
|
- name: Archive Production Artifact
|
||||||
uses: actions/upload-artifact@master
|
uses: actions/upload-artifact@master
|
||||||
with:
|
with:
|
||||||
@ -32,7 +29,7 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci --force
|
run: npm ci --force
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test.ci
|
run: npm run test:ci
|
||||||
- name: Codecov
|
- name: Codecov
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
@ -57,7 +54,7 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci --force
|
run: npm ci --force
|
||||||
- name: Prettier
|
- name: Prettier
|
||||||
run: npm run style
|
run: npm run prettier
|
||||||
cspell:
|
cspell:
|
||||||
name: CSpell
|
name: CSpell
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
1505
.github/workflows/demos.yml
vendored
1505
.github/workflows/demos.yml
vendored
File diff suppressed because it is too large
Load Diff
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
@ -1,18 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": []
|
||||||
{
|
|
||||||
"name": "Run Demo",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-r",
|
|
||||||
"${workspaceFolder}/node_modules/ts-node/register",
|
|
||||||
"-r",
|
|
||||||
"${workspaceFolder}/node_modules/tsconfig-paths/register"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"program": "${workspaceFolder}/demo/85-template-document.ts"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
20
.vscode/tasks.json
vendored
20
.vscode/tasks.json
vendored
@ -2,23 +2,5 @@
|
|||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
// for the documentation about the tasks.json format
|
// for the documentation about the tasks.json format
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": []
|
||||||
{
|
|
||||||
"type": "typescript",
|
|
||||||
"tsconfig": "tsconfig.json",
|
|
||||||
"option": "watch",
|
|
||||||
"problemMatcher": [
|
|
||||||
"$tsc-watch"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "npm",
|
|
||||||
"script": "ts-node",
|
|
||||||
"problemMatcher": [],
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
@ -3,6 +3,142 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "docx";
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "docx";
|
||||||
|
|
||||||
|
// cspell: disable
|
||||||
|
const createLoremIpsumParagraphs = () => [
|
||||||
|
new Paragraph(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan condimentum elit ut placerat. Integer vitae justo est. Quisque tempus augue eu diam pulvinar aliquam. Pellentesque neque sem, posuere eget augue pretium, feugiat mattis diam. Mauris libero arcu, elementum sit amet nunc sed, vestibulum posuere sapien. Nullam",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"ultrices efficitur magna et commodo. Morbi vitae dolor vulputate, dapibus ipsum in, finibus enim. Aliquam dapibus tellus libero. Nullam nulla eros, ullamcorper eu risus at, luctus aliquet nunc. Nunc dictum turpis eu quam suscipit porta. In rutrum scelerisque nunc in consectetur. Pellentesque ut nibh eget neque congue auctor. Nunc dapibus massa elit, vel cursus metus condimentum et. Nunc venenatis dolor eu lobortis fringilla. Nulla sed risus id lectus scelerisque sollicitudin. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Nulla lobortis et purus convallis ullamcorper. Nunc scelerisque, urna eu vestibulum feugiat, orci turpis pulvinar odio, vitae faucibus elit tortor et urna. Curabitur eros mauris, mollis a vestibulum nec, vestibulum sed velit. Nam semper metus ut felis ultricies rutrum. Cras hendrerit eros vel placerat vulputate. Proin placerat ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"mollis lacus a ultricies. Mauris vel turpis vitae purus suscipit dignissim. Donec egestas molestie libero in suscipit. Aenean auctor tellus convallis eros porttitor, id vehicula risus commodo. Sed accumsan turpis elit, eget molestie tortor efficitur eget. Aliquam ut lectus quis augue pellentesque tincidunt id id quam. Maecenas auctor, lorem eu ornare tempor, lacus metus ultrices turpis, nec feugiat nibh purus id justo.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Sed semper feugiat ante, sit amet accumsan lorem vulputate vel. Morbi interdum, mauris sit amet efficitur mattis, nunc sapien tempor ante, eget maximus ipsum arcu quis dolor. Suspendisse id consequat justo, quis sollicitudin nisi. Duis euismod, velit non faucibus placerat, eros sem fermentum lectus, ut egestas nisi ipsum eget mi. ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Donec vitae mollis libero. Etiam magna leo, auctor sit amet nibh sit amet, interdum finibus nunc. Quisque a pellentesque velit, a laoreet ante.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Quisque fringilla orci quis dui facilisis, quis auctor urna cursus. Mauris eget justo lacus. Integer placerat, leo vitae ullamcorper varius, nulla mauris gravida massa, ac dignissim odio erat eu ante. Duis non dui semper, eleifend neque nec, ultricies ligula. Sed nec sem nec dolor ultrices finibus. Praesent rutrum iaculis mollis. ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Fusce accumsan dui tortor, quis feugiat urna efficitur sed. Fusce viverra tristique lacinia. Sed nec faucibus ipsum, vel pulvinar ligula. Curabitur ut viverra nisl. Nulla nisi tortor, imperdiet et ipsum sit amet, egestas lacinia leo. Quisque interdum mauris non nunc egestas tempor a vehicula diam. Vestibulum convallis quam sit amet tincidunt posuere. Mauris velit sem, fermentum a diam sit amet, pulvinar iaculis lectus. In dolor turpis, cursus id libero sit amet, aliquet ullamcorper urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Etiam tincidunt euismod nisi, ut dignissim neque blandit sit amet. Etiam vel velit rhoncus, tincidunt diam quis, dignissim felis. Integer dolor urna, rutrum vitae ultricies ut, sagittis quis felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec pharetra aliquam augue. Donec ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"imperdiet placerat augue, nec consequat leo placerat a. Mauris accumsan ornare massa vitae volutpat. Sed commodo purus ac fringilla ultricies. Donec quis urna hendrerit dolor efficitur sollicitudin. Pellentesque diam arcu, dapibus a nisl pretium, auctor lobortis augue.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Aliquam libero lorem, scelerisque a volutpat ac, venenatis eu nisl. Maecenas turpis diam, consequat eget elementum eget, venenatis at lacus. In maximus erat magna, ut hendrerit erat malesuada vel. Suspendisse iaculis, lacus posuere convallis gravida, nisi purus blandit nunc, imperdiet tempor nunc turpis et sapien. Duis euismod id ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"ligula ac laoreet. Ut facilisis massa quis turpis imperdiet, eu ornare lorem placerat. Vestibulum pharetra feugiat eleifend. Quisque ornare pretium urna, lacinia aliquam eros placerat et. Integer sit amet auctor ipsum. Morbi imperdiet dictum ex sed lacinia. Curabitur interdum mattis nunc non vestibulum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque odio libero, viverra ac quam eleifend, dignissim euismod nibh. Etiam sit amet semper ante. Morbi in tellus lacinia, bibendum dolor quis, viverra nisi. Proin condimentum purus ipsum, et accumsan sapien finibus ac.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Maecenas congue in leo id faucibus. Etiam porta dapibus ultricies. Nunc ac volutpat magna. Nam pretium dolor ac ultrices tincidunt. Vestibulum pharetra elit vitae lacus pharetra euismod. Pellentesque fringilla lacus ac neque varius sagittis. Mauris tincidunt rutrum velit. Etiam pretium est vitae lacus ultricies, vitae viverra ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"turpis auctor. Nulla at lectus pellentesque enim dapibus aliquet eleifend et quam. Suspendisse cursus sed velit et lobortis. Integer sed facilisis ligula, ultrices molestie neque. Nulla porta mauris vitae quam consequat, eget fringilla enim luctus. Integer vitae rhoncus nibh, ac ornare ligula. Sed sed placerat libero. Suspendisse laoreet erat lacus, et lacinia nibh maximus in. Maecenas vitae enim at urna gravida euismod.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam lacinia lobortis tortor mollis venenatis. Sed sodales iaculis justo in rhoncus. Proin orci sapien, fermentum nec eleifend in, tristique vel mi. Donec vitae ornare justo, sed rhoncus nibh. Quisque a interdum est, in scelerisque odio. Ut luctus eget ex non ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"fringilla. Morbi nec iaculis nisi. Donec porta libero ac ex sollicitudin, vitae interdum erat faucibus. Donec ornare, arcu ullamcorper pretium euismod, nibh nisi consectetur justo, ac aliquet sem eros non nibh. Nulla vitae elementum arcu. Aenean ut consectetur dui. Donec posuere condimentum velit ac hendrerit. Sed aliquet aliquet mi, sed rutrum justo ultrices eget.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Donec volutpat libero dui, ac bibendum nunc eleifend a. Fusce ultricies ligula non sollicitudin lobortis. Integer sit amet elit sapien. Morbi rhoncus bibendum nibh et facilisis. Etiam consectetur elementum sem non elementum. Nunc rutrum sagittis ipsum non sodales. Orci varius natoque penatibus et magnis dis parturient montes, ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"nascetur ridiculus mus. Quisque porttitor nulla ultrices mollis porta. Cras non metus sed quam rutrum ultricies. Curabitur aliquet in sem eget auctor. Ut sodales quis leo bibendum venenatis. Etiam pellentesque eros ut metus dignissim commodo. Aliquam vitae sem gravida, convallis ipsum at, imperdiet tellus. Pellentesque consectetur odio sit amet sapien vestibulum aliquam nec id libero. Proin a maximus felis. Aenean molestie vulputate massa, eu eleifend sem consequat id.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Etiam quis ante nec leo faucibus dignissim eu at mi. Nam nec ligula nec sapien rhoncus faucibus. Fusce vestibulum orci libero, vel commodo est congue iaculis. In hac habitasse platea dictumst. Sed lacinia magna eu arcu commodo pretium. Fusce id elementum enim. Mauris tristique tortor dolor, at pretium magna tempor nec. Vivamus non ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"dui sit amet odio porttitor tincidunt. Nam pulvinar aliquet tortor tristique tempor. Duis finibus tincidunt elit, at viverra justo sagittis in. Morbi pellentesque gravida mi, in pulvinar metus molestie at. Fusce bibendum eleifend sapien a fermentum. Nam efficitur tellus dignissim, vehicula tortor ac, tristique enim. Aliquam pretium dui interdum varius elementum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec a finibus elit.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Phasellus cursus tortor at justo bibendum aliquam. Sed nec hendrerit nibh, eu finibus tortor. Aenean sit amet dui rutrum, sollicitudin justo eu, condimentum ipsum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas dictum neque lacus, vel posuere eros pretium nec. Morbi ac ante at ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"ex semper ultricies ac quis augue. In hac habitasse platea dictumst. Mauris laoreet porta nisl. Sed augue lorem, aliquet in volutpat ut, rhoncus eget nibh. Sed rhoncus arcu diam, accumsan rhoncus sem iaculis ac. Duis dolor magna, semper et tellus non, condimentum volutpat nisi. Donec eget metus eget elit eleifend vestibulum et ut purus.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Nam a dui accumsan, efficitur ex at, commodo eros. Pellentesque sit amet nunc ac odio egestas suscipit id sodales ligula. Duis non mi vitae mi mollis fringilla at sit amet sem. Morbi laoreet mattis dolor sit amet tincidunt. Aliquam erat volutpat. Pellentesque porta sem odio, at lobortis quam commodo vitae. Curabitur ut urna dolor.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Nulla vitae pretium ex. Nulla facilisi. Vestibulum placerat odio eget enim ultrices, et imperdiet tellus consequat. Sed dignissim, erat ut dignissim interdum, dui mi rhoncus nunc, id rhoncus turpis nunc eu risus. Mauris leo orci, euismod sit amet velit ac, condimentum dictum dui. Cras cursus dolor augue, et vestibulum lorem ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"fringilla in. Nulla fermentum odio vehicula justo placerat, et aliquet velit vulputate. Sed aliquam auctor dictum. Phasellus sit amet sollicitudin elit. Cras eget gravida ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis tortor erat, ornare id feugiat eget, pellentesque at lectus. Sed vitae nisi ullamcorper, tincidunt augue vitae, accumsan ligula. Curabitur ut lobortis lacus, imperdiet placerat arcu.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Sed vestibulum tempor nulla vel dignissim. Phasellus imperdiet, dolor nec mollis tempor, nulla nibh pretium nibh, nec elementum lacus neque in sapien. Nam et eleifend lorem. Nam pretium molestie enim quis porta. Proin eu pharetra enim. Etiam a velit eget augue congue tempor. Interdum et malesuada fames ac ante ipsum primis in ",
|
||||||
|
),
|
||||||
|
new Paragraph("faucibus. Sed urna tellus, euismod ac pharetra nec, ultrices vel nisi."),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Phasellus at arcu eget tellus mattis ultricies non quis urna. Vestibulum non eros fringilla, porttitor massa id, ornare metus. Quisque lacinia, massa a ornare vulputate, ex lectus ullamcorper ligula, eget facilisis mi turpis at dolor. Curabitur posuere elementum enim, non placerat tortor tincidunt sit amet. Pellentesque habitant ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam fermentum ut felis et dapibus. Ut consectetur finibus bibendum. Phasellus semper sapien neque, nec consequat nibh convallis et. Nunc nec egestas enim. Nulla facilisi.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Quisque sed nibh sed lorem placerat ornare sed nec sapien. Morbi et risus vitae magna varius varius eget at leo. Curabitur a eleifend elit. Mauris augue nulla, convallis vel ante in, consequat feugiat orci. Donec sagittis risus nibh, eget porta purus faucibus non. Curabitur ultrices, ex et placerat rutrum, velit odio accumsan ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"nulla, et elementum mi leo in velit. Pellentesque auctor egestas ultricies. In viverra est a mauris sollicitudin, a laoreet augue cursus. Vestibulum non sollicitudin massa. Curabitur ac tellus metus. Pellentesque hendrerit dolor sed mi vestibulum imperdiet. Nulla vitae odio ultrices, tempor enim sed, vestibulum eros. Cras libero ex, malesuada nec porttitor sit amet, efficitur sit amet ligula.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Morbi pellentesque tempus felis, id iaculis quam euismod non. Sed scelerisque id massa eu elementum. Vestibulum id malesuada arcu. Maecenas eget placerat sem, at consectetur orci. Nullam interdum erat urna, ac rhoncus odio feugiat sed. Morbi rutrum auctor sem eget pulvinar. Suspendisse egestas tempor volutpat.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Vivamus euismod, sem eget molestie rhoncus, metus dui laoreet lacus, et lobortis est metus ut felis. Aenean imperdiet lacus nunc, vitae molestie orci ultrices nec. Cras egestas maximus diam, vitae efficitur nisl luctus imperdiet. Nulla pellentesque sodales ante, nec facilisis turpis. Vivamus at hendrerit enim, ac dictum lorem. Cras ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"congue accumsan dui, non pretium sem auctor quis. Nunc a mauris vehicula, elementum ex vitae, sollicitudin eros. Nunc non sapien vitae justo sodales condimentum. Praesent nisl felis, tristique ac odio at, rhoncus porttitor orci. Morbi egestas placerat iaculis.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In at lorem nec neque faucibus ultricies ut in ipsum.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Suspendisse fermentum feugiat augue eu convallis. Maecenas eros velit, efficitur sit amet posuere sed, tristique sit amet nisi. Donec vel convallis justo, id tempor neque. Nunc pulvinar maximus nulla, vitae congue lacus cursus ut. Morbi at mollis est, a vehicula nisi. Cras venenatis nibh vel massa interdum commodo. Nulla mattis ",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"neque sed sem bibendum, iaculis hendrerit neque fringilla. Sed a lobortis orci. Morbi in est sed libero vestibulum semper. Suspendisse potenti. Aliquam pretium erat tellus, in suscipit lorem aliquet iaculis. Aenean ac viverra ipsum. Sed at diam luctus, pharetra lorem vel, aliquam magna. Donec mollis orci eget enim efficitur ultricies. Proin neque diam, dignissim euismod ex vel, sollicitudin sodales sapien.",
|
||||||
|
),
|
||||||
|
|
||||||
|
new Paragraph(
|
||||||
|
"Sed a egestas nunc, a ullamcorper est. Aenean vulputate fringilla justo non vestibulum. Donec ac dolor in nisl finibus tristique. Donec sed turpis at felis congue porttitor sed sit amet metus. In in ex nulla. Donec sodales vel velit ut congue. Nullam vitae egestas purus. Vivamus non mi consequat, molestie enim nec, hendrerit mi.",
|
||||||
|
),
|
||||||
|
];
|
||||||
|
// cspell: enable
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
@ -45,7 +181,20 @@ const doc = new Document({
|
|||||||
children: [
|
children: [
|
||||||
new TextRun("My Title "),
|
new TextRun("My Title "),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: ["Footer - Page ", PageNumber.CURRENT],
|
children: ["Footer - Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
"Footer - Page in section ",
|
||||||
|
PageNumber.CURRENT_SECTION,
|
||||||
|
" of ",
|
||||||
|
PageNumber.TOTAL_PAGES_IN_SECTION,
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -70,6 +219,96 @@ const doc = new Document({
|
|||||||
children: [new TextRun("First Page"), new PageBreak()],
|
children: [new TextRun("First Page"), new PageBreak()],
|
||||||
}),
|
}),
|
||||||
new Paragraph("Second Page"),
|
new Paragraph("Second Page"),
|
||||||
|
...createLoremIpsumParagraphs(),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Next Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
...createLoremIpsumParagraphs(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
titlePage: true,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Header "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Footer - Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
"Footer - Page in section ",
|
||||||
|
PageNumber.CURRENT_SECTION,
|
||||||
|
" of ",
|
||||||
|
PageNumber.TOTAL_PAGES_IN_SECTION,
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Footer "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("First Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph("Second Page"),
|
||||||
|
...createLoremIpsumParagraphs(),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Next Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
...createLoremIpsumParagraphs(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Example of how you would create a table and add data to it
|
// Example of how you would create a table and add data to it
|
||||||
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
import { BorderStyle, Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -67,6 +67,173 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph("Table with borders"),
|
||||||
|
new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Dash small gap border")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Dash small gap border")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Double border")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 1,
|
||||||
|
color: "ff0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Double border")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Should have no border")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.NONE,
|
||||||
|
size: 0,
|
||||||
|
color: "ffffff",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Should have no border")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {
|
import {
|
||||||
|
convertMillimetersToTwip,
|
||||||
Document,
|
Document,
|
||||||
HorizontalPositionAlign,
|
HorizontalPositionAlign,
|
||||||
HorizontalPositionRelativeFrom,
|
HorizontalPositionRelativeFrom,
|
||||||
@ -41,6 +42,11 @@ const doc = new Document({
|
|||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
},
|
},
|
||||||
|
outline: {
|
||||||
|
type: "solidFill",
|
||||||
|
solidFillType: "rgb",
|
||||||
|
value: "FF0000",
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -55,6 +61,12 @@ const doc = new Document({
|
|||||||
vertical: true,
|
vertical: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
outline: {
|
||||||
|
type: "solidFill",
|
||||||
|
solidFillType: "rgb",
|
||||||
|
value: "0000FF",
|
||||||
|
width: convertMillimetersToTwip(600),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -107,5 +107,5 @@ const doc = new Document({
|
|||||||
|
|
||||||
// Used to export the file into a .docx file
|
// Used to export the file into a .docx file
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("6-numbering.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,7 @@ const receiptTabStops = [
|
|||||||
const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
|
defaultTabStop: 0,
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
properties: {},
|
properties: {},
|
||||||
|
@ -55,7 +55,7 @@ if (files.length === 0) {
|
|||||||
const filePath = path.join(dir, files[0]);
|
const filePath = path.join(dir, files[0]);
|
||||||
|
|
||||||
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
||||||
const { stdout } = await $`ts-node --project demo/tsconfig.json ${filePath}`;
|
const { stdout } = await $`tsx ${filePath}`;
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
console.log("Successfully created document!");
|
console.log("Successfully created document!");
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"rootDir": "./",
|
|
||||||
"paths": {
|
|
||||||
"docx": ["../build"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"include": ["../demo"]
|
|
||||||
}
|
|
7863
package-lock.json
generated
7863
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "8.2.3",
|
"version": "8.4.0",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "build/index.umd.js",
|
"main": "build/index.umd.js",
|
||||||
@ -20,21 +20,21 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"test": "vitest --ui --coverage",
|
"test": "vitest --ui --coverage",
|
||||||
"test.ci": "vitest run --coverage",
|
"test:ci": "vitest run --coverage",
|
||||||
"prepublishOnly": "npm run build --omit=dev",
|
"prepublishOnly": "npm run build --omit=dev",
|
||||||
"lint": "eslint --ext .ts src",
|
"lint": "eslint --ext .ts src",
|
||||||
"predemo": "npm run build",
|
"predemo": "npm run build",
|
||||||
"demo": "ts-node --project demo/tsconfig.json ./demo/index.ts",
|
"demo": "tsx ./demo/index.ts",
|
||||||
"typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
"typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
||||||
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
"prettier": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||||
"style.fix": "npm run style -- --write",
|
"prettier:fix": "npm run prettier -- --write",
|
||||||
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
||||||
"serve.docs": "cd docs && docsify serve",
|
"serve.docs": "cd docs && docsify serve",
|
||||||
"extract": "ts-node scripts/extract-document.ts",
|
"extract": "tsx scripts/extract-document.ts",
|
||||||
"ts-node": "ts-node --project demo/tsconfig.json"
|
"run-ts": "tsx"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"style",
|
"prettier",
|
||||||
"lint"
|
"lint"
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -56,7 +56,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^20.3.1",
|
"@types/node": "^20.3.1",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"nanoid": "^4.0.2",
|
"nanoid": "^5.0.4",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xml-js": "^1.6.8"
|
"xml-js": "^1.6.8"
|
||||||
},
|
},
|
||||||
@ -67,40 +67,39 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://docx.js.org",
|
"homepage": "https://docx.js.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@esbuild/win32-x64": "^0.18.3",
|
|
||||||
"@types/inquirer": "^9.0.3",
|
"@types/inquirer": "^9.0.3",
|
||||||
"@types/prompt": "^1.1.1",
|
"@types/prompt": "^1.1.1",
|
||||||
"@types/unzipper": "^0.10.4",
|
"@types/unzipper": "^0.10.4",
|
||||||
"@types/xml": "^1.0.8",
|
"@types/xml": "^1.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
||||||
"@typescript-eslint/parser": "^5.36.1",
|
"@typescript-eslint/parser": "^6.9.1",
|
||||||
"@vitest/coverage-v8": "^0.33.0",
|
"@vitest/coverage-v8": "^1.1.0",
|
||||||
"@vitest/ui": "^0.33.0",
|
"@vitest/ui": "^1.1.0",
|
||||||
"cspell": "^6.2.2",
|
"cspell": "^8.2.3",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
"eslint": "^8.23.0",
|
"eslint": "^8.23.0",
|
||||||
"eslint-plugin-functional": "^5.0.8",
|
"eslint-plugin-functional": "^6.0.0",
|
||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"eslint-plugin-jsdoc": "^46.2.6",
|
"eslint-plugin-jsdoc": "^46.2.6",
|
||||||
"eslint-plugin-no-null": "^1.0.2",
|
"eslint-plugin-no-null": "^1.0.2",
|
||||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||||
"eslint-plugin-unicorn": "^47.0.0",
|
"eslint-plugin-unicorn": "^50.0.1",
|
||||||
"execa": "^7.1.1",
|
"execa": "^8.0.1",
|
||||||
"glob": "^10.2.7",
|
"glob": "^10.2.7",
|
||||||
"inquirer": "^9.2.7",
|
"inquirer": "^9.2.7",
|
||||||
"jsdom": "^22.1.0",
|
"jsdom": "^23.0.1",
|
||||||
"pre-commit": "^1.2.2",
|
"pre-commit": "^1.2.2",
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.1.1",
|
||||||
"ts-node": "^10.2.1",
|
|
||||||
"tsconfig-paths": "^4.0.0",
|
"tsconfig-paths": "^4.0.0",
|
||||||
"typedoc": "^0.24.8",
|
"tsx": "^4.7.0",
|
||||||
"typescript": "5.1.6",
|
"typedoc": "^0.25.4",
|
||||||
|
"typescript": "5.3.3",
|
||||||
"unzipper": "^0.10.11",
|
"unzipper": "^0.10.11",
|
||||||
"vite": "^4.3.2",
|
"vite": "^5.0.10",
|
||||||
"vite-plugin-dts": "^3.3.1",
|
"vite-plugin-dts": "^3.3.1",
|
||||||
"vite-plugin-node-polyfills": "^0.9.0",
|
"vite-plugin-node-polyfills": "^0.9.0",
|
||||||
"vite-tsconfig-paths": "^4.2.0",
|
"vite-tsconfig-paths": "^4.2.0",
|
||||||
"vitest": "^0.33.0"
|
"vitest": "^1.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -44,7 +44,7 @@ export class Compiler {
|
|||||||
this.numberingReplacer = new NumberingReplacer();
|
this.numberingReplacer = new NumberingReplacer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public compile(file: File, prettifyXml?: PrettifyType): JSZip {
|
public compile(file: File, prettifyXml?: (typeof PrettifyType)[keyof typeof PrettifyType]): JSZip {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
||||||
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
||||||
@ -66,7 +66,7 @@ export class Compiler {
|
|||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
private xmlifyFile(file: File, prettify?: PrettifyType): IXmlifyedFileMapping {
|
private xmlifyFile(file: File, prettify?: (typeof PrettifyType)[keyof typeof PrettifyType]): IXmlifyedFileMapping {
|
||||||
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
|
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
|
||||||
|
|
||||||
const documentXmlData = xml(
|
const documentXmlData = xml(
|
||||||
|
@ -6,18 +6,21 @@ import { Compiler } from "./next-compiler";
|
|||||||
/**
|
/**
|
||||||
* Use blanks to prettify
|
* Use blanks to prettify
|
||||||
*/
|
*/
|
||||||
export enum PrettifyType {
|
export const PrettifyType = {
|
||||||
NONE = "",
|
NONE: "",
|
||||||
WITH_2_BLANKS = " ",
|
WITH_2_BLANKS: " ",
|
||||||
WITH_4_BLANKS = " ",
|
WITH_4_BLANKS: " ",
|
||||||
WITH_TAB = "\t",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
}
|
WITH_TAB: "\t",
|
||||||
|
} as const;
|
||||||
|
|
||||||
const convertPrettifyType = (prettify?: boolean | PrettifyType): PrettifyType | undefined =>
|
const convertPrettifyType = (
|
||||||
|
prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType],
|
||||||
|
): (typeof PrettifyType)[keyof typeof PrettifyType] | undefined =>
|
||||||
prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify;
|
prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify;
|
||||||
|
|
||||||
export class Packer {
|
export class Packer {
|
||||||
public static async toString(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
public static async toString(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string> {
|
||||||
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "string",
|
type: "string",
|
||||||
@ -28,7 +31,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> {
|
public static async toBuffer(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Buffer> {
|
||||||
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "nodebuffer",
|
type: "nodebuffer",
|
||||||
@ -39,7 +42,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async toBase64String(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
public static async toBase64String(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<string> {
|
||||||
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "base64",
|
type: "base64",
|
||||||
@ -50,7 +53,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async toBlob(file: File, prettify?: boolean | PrettifyType): Promise<Blob> {
|
public static async toBlob(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise<Blob> {
|
||||||
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "blob",
|
type: "blob",
|
||||||
@ -61,7 +64,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static toStream(file: File, prettify?: boolean | PrettifyType): Stream {
|
public static toStream(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Stream {
|
||||||
const stream = new Stream();
|
const stream = new Stream();
|
||||||
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
const zip = this.compiler.compile(file, convertPrettifyType(prettify));
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values";
|
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values";
|
||||||
|
|
||||||
export interface IBorderOptions {
|
export interface IBorderOptions {
|
||||||
readonly style: BorderStyle;
|
readonly style: (typeof BorderStyle)[keyof typeof BorderStyle];
|
||||||
/** Border color, in hex (eg 'FF00AA') */
|
/** Border color, in hex (eg 'FF00AA') */
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
/** Size of the border in 1/8 pt */
|
/** Size of the border in 1/8 pt */
|
||||||
@ -55,32 +55,34 @@ class BordersAttributes extends XmlAttributeComponent<IBorderOptions> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BorderStyle {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
SINGLE = "single",
|
export const BorderStyle = {
|
||||||
DASH_DOT_STROKED = "dashDotStroked",
|
SINGLE: "single",
|
||||||
DASHED = "dashed",
|
DASH_DOT_STROKED: "dashDotStroked",
|
||||||
DASH_SMALL_GAP = "dashSmallGap",
|
DASHED: "dashed",
|
||||||
DOT_DASH = "dotDash",
|
DASH_SMALL_GAP: "dashSmallGap",
|
||||||
DOT_DOT_DASH = "dotDotDash",
|
DOT_DASH: "dotDash",
|
||||||
DOTTED = "dotted",
|
DOT_DOT_DASH: "dotDotDash",
|
||||||
DOUBLE = "double",
|
DOTTED: "dotted",
|
||||||
DOUBLE_WAVE = "doubleWave",
|
DOUBLE: "double",
|
||||||
INSET = "inset",
|
DOUBLE_WAVE: "doubleWave",
|
||||||
NIL = "nil",
|
INSET: "inset",
|
||||||
NONE = "none",
|
NIL: "nil",
|
||||||
OUTSET = "outset",
|
NONE: "none",
|
||||||
THICK = "thick",
|
OUTSET: "outset",
|
||||||
THICK_THIN_LARGE_GAP = "thickThinLargeGap",
|
THICK: "thick",
|
||||||
THICK_THIN_MEDIUM_GAP = "thickThinMediumGap",
|
THICK_THIN_LARGE_GAP: "thickThinLargeGap",
|
||||||
THICK_THIN_SMALL_GAP = "thickThinSmallGap",
|
THICK_THIN_MEDIUM_GAP: "thickThinMediumGap",
|
||||||
THIN_THICK_LARGE_GAP = "thinThickLargeGap",
|
THICK_THIN_SMALL_GAP: "thickThinSmallGap",
|
||||||
THIN_THICK_MEDIUM_GAP = "thinThickMediumGap",
|
THIN_THICK_LARGE_GAP: "thinThickLargeGap",
|
||||||
THIN_THICK_SMALL_GAP = "thinThickSmallGap",
|
THIN_THICK_MEDIUM_GAP: "thinThickMediumGap",
|
||||||
THIN_THICK_THIN_LARGE_GAP = "thinThickThinLargeGap",
|
THIN_THICK_SMALL_GAP: "thinThickSmallGap",
|
||||||
THIN_THICK_THIN_MEDIUM_GAP = "thinThickThinMediumGap",
|
THIN_THICK_THIN_LARGE_GAP: "thinThickThinLargeGap",
|
||||||
THIN_THICK_THIN_SMALL_GAP = "thinThickThinSmallGap",
|
THIN_THICK_THIN_MEDIUM_GAP: "thinThickThinMediumGap",
|
||||||
THREE_D_EMBOSS = "threeDEmboss",
|
THIN_THICK_THIN_SMALL_GAP: "thinThickThinSmallGap",
|
||||||
THREE_D_ENGRAVE = "threeDEngrave",
|
THREE_D_EMBOSS: "threeDEmboss",
|
||||||
TRIPLE = "triple",
|
THREE_D_ENGRAVE: "threeDEngrave",
|
||||||
WAVE = "wave",
|
TRIPLE: "triple",
|
||||||
}
|
WAVE: "wave",
|
||||||
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
@ -39,6 +39,7 @@ export interface IPropertiesOptions {
|
|||||||
readonly compatibility?: ICompatibilityOptions;
|
readonly compatibility?: ICompatibilityOptions;
|
||||||
readonly customProperties?: readonly ICustomPropertyOptions[];
|
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||||
|
readonly defaultTabStop?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
|
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
|
||||||
|
@ -17,14 +17,17 @@ import { decimalNumber } from "@util/values";
|
|||||||
// <xsd:attribute name="charSpace" type="ST_DecimalNumber"/>
|
// <xsd:attribute name="charSpace" type="ST_DecimalNumber"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export enum DocumentGridType {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
DEFAULT = "default",
|
export const DocumentGridType = {
|
||||||
LINES = "lines",
|
DEFAULT: "default",
|
||||||
LINES_AND_CHARS = "linesAndChars",
|
LINES: "lines",
|
||||||
SNAP_TO_CHARS = "snapToChars",
|
LINES_AND_CHARS: "linesAndChars",
|
||||||
}
|
SNAP_TO_CHARS: "snapToChars",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
export interface IDocGridAttributesProperties {
|
export interface IDocGridAttributesProperties {
|
||||||
readonly type?: DocumentGridType;
|
readonly type?: (typeof DocumentGridType)[keyof typeof DocumentGridType];
|
||||||
readonly linePitch?: number;
|
readonly linePitch?: number;
|
||||||
readonly charSpace?: number;
|
readonly charSpace?: number;
|
||||||
}
|
}
|
||||||
@ -38,7 +41,7 @@ export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesP
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DocumentGrid extends XmlComponent {
|
export class DocumentGrid extends XmlComponent {
|
||||||
public constructor(linePitch: number, charSpace?: number, type?: DocumentGridType) {
|
public constructor(linePitch: number, charSpace?: number, type?: (typeof DocumentGridType)[keyof typeof DocumentGridType]) {
|
||||||
super("w:docGrid");
|
super("w:docGrid");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -7,11 +7,11 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
// <xsd:enumeration value="first"/>
|
// <xsd:enumeration value="first"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum HeaderFooterReferenceType {
|
export const HeaderFooterReferenceType = {
|
||||||
DEFAULT = "default",
|
DEFAULT: "default",
|
||||||
FIRST = "first",
|
FIRST: "first",
|
||||||
EVEN = "even",
|
EVEN: "even",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
// <xsd:group name="EG_HdrFtrReferences">
|
// <xsd:group name="EG_HdrFtrReferences">
|
||||||
@ -33,12 +33,12 @@ export enum HeaderFooterReferenceType {
|
|||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export interface IHeaderFooterOptions {
|
export interface IHeaderFooterOptions {
|
||||||
readonly type?: HeaderFooterReferenceType;
|
readonly type?: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
||||||
readonly id?: number;
|
readonly id?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FooterReferenceAttributes extends XmlAttributeComponent<{
|
class FooterReferenceAttributes extends XmlAttributeComponent<{
|
||||||
readonly type: HeaderFooterReferenceType;
|
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
@ -47,12 +47,13 @@ class FooterReferenceAttributes extends XmlAttributeComponent<{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum HeaderFooterType {
|
export const HeaderFooterType = {
|
||||||
HEADER = "w:headerReference",
|
HEADER: "w:headerReference",
|
||||||
FOOTER = "w:footerReference",
|
FOOTER: "w:footerReference",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class HeaderFooterReference extends XmlComponent {
|
export class HeaderFooterReference extends XmlComponent {
|
||||||
public constructor(type: HeaderFooterType, options: IHeaderFooterOptions) {
|
public constructor(type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType], options: IHeaderFooterOptions) {
|
||||||
super(type);
|
super(type);
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPsectionLineNumbering.php
|
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_LineNumberRestart">
|
// <xsd:simpleType name="ST_LineNumberRestart">
|
||||||
@ -9,11 +9,14 @@ import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@uti
|
|||||||
// <xsd:enumeration value="continuous"/>
|
// <xsd:enumeration value="continuous"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum LineNumberRestartFormat {
|
|
||||||
NEW_PAGE = "newPage",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
NEW_SECTION = "newSection",
|
export const LineNumberRestartFormat = {
|
||||||
CONTINUOUS = "continuous",
|
NEW_PAGE: "newPage",
|
||||||
}
|
NEW_SECTION: "newSection",
|
||||||
|
CONTINUOUS: "continuous",
|
||||||
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
// <xsd:complexType name="CT_LineNumber">
|
// <xsd:complexType name="CT_LineNumber">
|
||||||
// <xsd:attribute name="countBy" type="ST_DecimalNumber" use="optional"/>
|
// <xsd:attribute name="countBy" type="ST_DecimalNumber" use="optional"/>
|
||||||
@ -22,28 +25,23 @@ export enum LineNumberRestartFormat {
|
|||||||
// <xsd:attribute name="restart" type="ST_LineNumberRestart" use="optional" default="newPage"/>
|
// <xsd:attribute name="restart" type="ST_LineNumberRestart" use="optional" default="newPage"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export interface ILineNumberAttributes {
|
export type ILineNumberAttributes = {
|
||||||
readonly countBy?: number;
|
readonly countBy?: number;
|
||||||
readonly start?: number;
|
readonly start?: number;
|
||||||
readonly restart?: LineNumberRestartFormat;
|
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
||||||
readonly distance?: number | PositiveUniversalMeasure;
|
readonly distance?: number | PositiveUniversalMeasure;
|
||||||
}
|
};
|
||||||
|
|
||||||
export class LineNumberType extends XmlComponent {
|
export const createLineNumberType = ({ countBy, start, restart, distance }: ILineNumberAttributes): XmlComponent =>
|
||||||
public constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
new BuilderElement<ILineNumberAttributes>({
|
||||||
super("w:lnNumType");
|
name: "w:lnNumType",
|
||||||
this.root.push(
|
attributes: {
|
||||||
new NextAttributeComponent<{
|
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||||
readonly countBy?: number;
|
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||||
readonly start?: number;
|
restart: { key: "w:restart", value: restart },
|
||||||
readonly restart?: LineNumberRestartFormat;
|
distance: {
|
||||||
readonly distance?: number | PositiveUniversalMeasure;
|
key: "w:distance",
|
||||||
}>({
|
value: distance === undefined ? undefined : twipsMeasureValue(distance),
|
||||||
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) },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -9,11 +9,14 @@ import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-comp
|
|||||||
// <xsd:enumeration value="notFirstPage"/>
|
// <xsd:enumeration value="notFirstPage"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PageBorderDisplay {
|
|
||||||
ALL_PAGES = "allPages",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
FIRST_PAGE = "firstPage",
|
export const PageBorderDisplay = {
|
||||||
NOT_FIRST_PAGE = "notFirstPage",
|
ALL_PAGES: "allPages",
|
||||||
}
|
FIRST_PAGE: "firstPage",
|
||||||
|
NOT_FIRST_PAGE: "notFirstPage",
|
||||||
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PageBorderOffset">
|
// <xsd:simpleType name="ST_PageBorderOffset">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -21,10 +24,10 @@ export enum PageBorderDisplay {
|
|||||||
// <xsd:enumeration value="text"/>
|
// <xsd:enumeration value="text"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PageBorderOffsetFrom {
|
export const PageBorderOffsetFrom = {
|
||||||
PAGE = "page",
|
PAGE: "page",
|
||||||
TEXT = "text",
|
TEXT: "text",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PageBorderZOrder">
|
// <xsd:simpleType name="ST_PageBorderZOrder">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -32,15 +35,15 @@ export enum PageBorderOffsetFrom {
|
|||||||
// <xsd:enumeration value="back"/>
|
// <xsd:enumeration value="back"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PageBorderZOrder {
|
export const PageBorderZOrder = {
|
||||||
BACK = "back",
|
BACK: "back",
|
||||||
FRONT = "front",
|
FRONT: "front",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export interface IPageBorderAttributes {
|
export interface IPageBorderAttributes {
|
||||||
readonly display?: PageBorderDisplay;
|
readonly display?: (typeof PageBorderDisplay)[keyof typeof PageBorderDisplay];
|
||||||
readonly offsetFrom?: PageBorderOffsetFrom;
|
readonly offsetFrom?: (typeof PageBorderOffsetFrom)[keyof typeof PageBorderOffsetFrom];
|
||||||
readonly zOrder?: PageBorderZOrder;
|
readonly zOrder?: (typeof PageBorderZOrder)[keyof typeof PageBorderZOrder];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPageBordersOptions {
|
export interface IPageBordersOptions {
|
||||||
|
@ -12,18 +12,22 @@ import { decimalNumber } from "@util/values";
|
|||||||
// <xsd:enumeration value="enDash"/>
|
// <xsd:enumeration value="enDash"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PageNumberSeparator {
|
|
||||||
HYPHEN = "hyphen",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
PERIOD = "period",
|
export const PageNumberSeparator = {
|
||||||
COLON = "colon",
|
HYPHEN: "hyphen",
|
||||||
EM_DASH = "emDash",
|
PERIOD: "period",
|
||||||
EN_DASH = "endash",
|
COLON: "colon",
|
||||||
}
|
EM_DASH: "emDash",
|
||||||
|
EN_DASH: "endash",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
export interface IPageNumberTypeAttributes {
|
export interface IPageNumberTypeAttributes {
|
||||||
readonly start?: number;
|
readonly start?: number;
|
||||||
readonly formatType?: NumberFormat;
|
readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
|
||||||
readonly separator?: PageNumberSeparator;
|
readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator];
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_PageNumber">
|
// <xsd:complexType name="CT_PageNumber">
|
||||||
@ -40,6 +44,7 @@ export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberT
|
|||||||
separator: "w:chapSep",
|
separator: "w:chapSep",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageNumberType extends XmlComponent {
|
export class PageNumberType extends XmlComponent {
|
||||||
public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
|
public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
|
||||||
super("w:pgNumType");
|
super("w:pgNumType");
|
||||||
|
@ -7,10 +7,10 @@ import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
|||||||
// <xsd:enumeration value="landscape"/>
|
// <xsd:enumeration value="landscape"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PageOrientation {
|
export const PageOrientation = {
|
||||||
PORTRAIT = "portrait",
|
PORTRAIT: "portrait",
|
||||||
LANDSCAPE = "landscape",
|
LANDSCAPE: "landscape",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// <xsd:complexType name="CT_PageSz">
|
// <xsd:complexType name="CT_PageSz">
|
||||||
// <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
|
// <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
|
||||||
@ -21,11 +21,15 @@ export enum PageOrientation {
|
|||||||
export type IPageSizeAttributes = {
|
export type IPageSizeAttributes = {
|
||||||
readonly width?: number | PositiveUniversalMeasure;
|
readonly width?: number | PositiveUniversalMeasure;
|
||||||
readonly height?: number | PositiveUniversalMeasure;
|
readonly height?: number | PositiveUniversalMeasure;
|
||||||
readonly orientation?: PageOrientation;
|
readonly orientation?: (typeof PageOrientation)[keyof typeof PageOrientation];
|
||||||
};
|
};
|
||||||
|
|
||||||
export class PageSize extends XmlComponent {
|
export class PageSize extends XmlComponent {
|
||||||
public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) {
|
public constructor(
|
||||||
|
width: number | PositiveUniversalMeasure,
|
||||||
|
height: number | PositiveUniversalMeasure,
|
||||||
|
orientation: (typeof PageOrientation)[keyof typeof PageOrientation],
|
||||||
|
) {
|
||||||
super("w:pgSz");
|
super("w:pgSz");
|
||||||
|
|
||||||
const flip = orientation === PageOrientation.LANDSCAPE;
|
const flip = orientation === PageOrientation.LANDSCAPE;
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export enum PageTextDirectionType {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb",
|
export const PageTextDirectionType = {
|
||||||
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl",
|
LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
|
||||||
}
|
TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl",
|
||||||
|
} as const;
|
||||||
|
|
||||||
class PageTextDirectionAttributes extends XmlAttributeComponent<{ readonly val: PageTextDirectionType }> {
|
/* eslint-enable */
|
||||||
|
|
||||||
|
class PageTextDirectionAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly val: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageTextDirection extends XmlComponent {
|
export class PageTextDirection extends XmlComponent {
|
||||||
public constructor(value: PageTextDirectionType) {
|
public constructor(value: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType]) {
|
||||||
super("w:textDirection");
|
super("w:textDirection");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -10,19 +10,22 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
// <xsd:enumeration value="oddPage"/>
|
// <xsd:enumeration value="oddPage"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum SectionType {
|
|
||||||
NEXT_PAGE = "nextPage",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
NEXT_COLUMN = "nextColumn",
|
export const SectionType = {
|
||||||
CONTINUOUS = "continuous",
|
NEXT_PAGE: "nextPage",
|
||||||
EVEN_PAGE = "evenPage",
|
NEXT_COLUMN: "nextColumn",
|
||||||
ODD_PAGE = "oddPage",
|
CONTINUOUS: "continuous",
|
||||||
}
|
EVEN_PAGE: "evenPage",
|
||||||
|
ODD_PAGE: "oddPage",
|
||||||
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
// <xsd:complexType name="CT_SectType">
|
// <xsd:complexType name="CT_SectType">
|
||||||
// <xsd:attribute name="val" type="ST_SectionMark"/>
|
// <xsd:attribute name="val" type="ST_SectionMark"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class SectionTypeAttributes extends XmlAttributeComponent<{
|
export class SectionTypeAttributes extends XmlAttributeComponent<{
|
||||||
readonly val: SectionType;
|
readonly val: (typeof SectionType)[keyof typeof SectionType];
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
val: "w:val",
|
val: "w:val",
|
||||||
@ -30,7 +33,7 @@ export class SectionTypeAttributes extends XmlAttributeComponent<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Type extends XmlComponent {
|
export class Type extends XmlComponent {
|
||||||
public constructor(value: SectionType) {
|
public constructor(value: (typeof SectionType)[keyof typeof SectionType]) {
|
||||||
super("w:type");
|
super("w:type");
|
||||||
this.root.push(new SectionTypeAttributes({ val: value }));
|
this.root.push(new SectionTypeAttributes({ val: value }));
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,11 @@ 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, createLineNumberType } from "./properties/line-number";
|
||||||
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
||||||
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
||||||
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
||||||
@ -30,16 +29,16 @@ export interface ISectionPropertiesOptions {
|
|||||||
readonly margin?: IPageMarginAttributes;
|
readonly margin?: IPageMarginAttributes;
|
||||||
readonly pageNumbers?: IPageNumberTypeAttributes;
|
readonly pageNumbers?: IPageNumberTypeAttributes;
|
||||||
readonly borders?: IPageBordersOptions;
|
readonly borders?: IPageBordersOptions;
|
||||||
readonly textDirection?: PageTextDirectionType;
|
readonly textDirection?: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
|
||||||
};
|
};
|
||||||
readonly grid?: IDocGridAttributesProperties;
|
readonly grid?: IDocGridAttributesProperties;
|
||||||
readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
|
readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
|
||||||
readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>;
|
readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>;
|
||||||
readonly lineNumbers?: ILineNumberAttributes;
|
readonly lineNumbers?: ILineNumberAttributes;
|
||||||
readonly titlePage?: boolean;
|
readonly titlePage?: boolean;
|
||||||
readonly verticalAlign?: VerticalAlign;
|
readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
|
||||||
readonly column?: IColumnsAttributes;
|
readonly column?: IColumnsAttributes;
|
||||||
readonly type?: SectionType;
|
readonly type?: (typeof SectionType)[keyof typeof SectionType];
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_SectPr">
|
// <xsd:complexType name="CT_SectPr">
|
||||||
@ -76,10 +75,10 @@ export interface ISectionPropertiesOptions {
|
|||||||
// </xsd:group>
|
// </xsd:group>
|
||||||
|
|
||||||
export const sectionMarginDefaults = {
|
export const sectionMarginDefaults = {
|
||||||
TOP: "1in" as UniversalMeasure,
|
TOP: 1440,
|
||||||
RIGHT: "1in" as PositiveUniversalMeasure,
|
RIGHT: 1440,
|
||||||
BOTTOM: "1in" as UniversalMeasure,
|
BOTTOM: 1440,
|
||||||
LEFT: "1in" as PositiveUniversalMeasure,
|
LEFT: 1440,
|
||||||
HEADER: 708,
|
HEADER: 708,
|
||||||
FOOTER: 708,
|
FOOTER: 708,
|
||||||
GUTTER: 0,
|
GUTTER: 0,
|
||||||
@ -138,7 +137,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lineNumbers) {
|
if (lineNumbers) {
|
||||||
this.root.push(new LineNumberType(lineNumbers));
|
this.root.push(createLineNumberType(lineNumbers));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.push(new PageNumberType(pageNumbers));
|
this.root.push(new PageNumberType(pageNumbers));
|
||||||
@ -163,7 +162,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private addHeaderFooterGroup(
|
private addHeaderFooterGroup(
|
||||||
type: HeaderFooterType,
|
type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType],
|
||||||
group: IHeaderFooterGroup<HeaderWrapper> | IHeaderFooterGroup<FooterWrapper>,
|
group: IHeaderFooterGroup<HeaderWrapper> | IHeaderFooterGroup<FooterWrapper>,
|
||||||
): void {
|
): void {
|
||||||
if (group.default) {
|
if (group.default) {
|
||||||
|
@ -80,6 +80,7 @@ export class Document extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document {
|
public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document {
|
||||||
|
// eslint-disable-next-line functional/immutable-data
|
||||||
this.body.push(item);
|
this.body.push(item);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,10 @@ import { TextWrappingType } from "../text-wrap";
|
|||||||
import { Anchor } from "./anchor";
|
import { Anchor } from "./anchor";
|
||||||
|
|
||||||
const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||||
new Anchor(
|
new Anchor({
|
||||||
{
|
mediaData: {
|
||||||
fileName: "test.png",
|
fileName: "test.png",
|
||||||
stream: new Buffer(""),
|
stream: Buffer.from(""),
|
||||||
transformation: {
|
transformation: {
|
||||||
pixels: {
|
pixels: {
|
||||||
x: 0,
|
x: 0,
|
||||||
@ -24,7 +24,7 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
transform: {
|
||||||
pixels: {
|
pixels: {
|
||||||
x: 100,
|
x: 100,
|
||||||
y: 100,
|
y: 100,
|
||||||
@ -35,7 +35,7 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
drawingOptions,
|
drawingOptions,
|
||||||
);
|
});
|
||||||
|
|
||||||
describe("Anchor", () => {
|
describe("Anchor", () => {
|
||||||
let anchor: Anchor;
|
let anchor: Anchor;
|
||||||
|
@ -6,7 +6,7 @@ import { HorizontalPosition, IFloating, SimplePos, VerticalPosition } from "../f
|
|||||||
import { Graphic } from "../inline/graphic";
|
import { Graphic } from "../inline/graphic";
|
||||||
import { TextWrappingType, WrapNone, WrapSquare, WrapTight, WrapTopAndBottom } from "../text-wrap";
|
import { TextWrappingType, WrapNone, WrapSquare, WrapTight, WrapTopAndBottom } from "../text-wrap";
|
||||||
import { DocProperties } from "./../doc-properties/doc-properties";
|
import { DocProperties } from "./../doc-properties/doc-properties";
|
||||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
import { createEffectExtent } from "./../effect-extent/effect-extent";
|
||||||
import { Extent } from "./../extent/extent";
|
import { Extent } from "./../extent/extent";
|
||||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||||
import { AnchorAttributes } from "./anchor-attributes";
|
import { AnchorAttributes } from "./anchor-attributes";
|
||||||
@ -37,7 +37,15 @@ import { AnchorAttributes } from "./anchor-attributes";
|
|||||||
// <xsd:attribute name="allowOverlap" type="xsd:boolean" use="required"/>
|
// <xsd:attribute name="allowOverlap" type="xsd:boolean" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class Anchor extends XmlComponent {
|
export class Anchor extends XmlComponent {
|
||||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation, drawingOptions: IDrawingOptions) {
|
public constructor({
|
||||||
|
mediaData,
|
||||||
|
transform,
|
||||||
|
drawingOptions,
|
||||||
|
}: {
|
||||||
|
readonly mediaData: IMediaData;
|
||||||
|
readonly transform: IMediaDataTransformation;
|
||||||
|
readonly drawingOptions: IDrawingOptions;
|
||||||
|
}) {
|
||||||
super("wp:anchor");
|
super("wp:anchor");
|
||||||
|
|
||||||
const floating: IFloating = {
|
const floating: IFloating = {
|
||||||
@ -69,7 +77,7 @@ export class Anchor extends XmlComponent {
|
|||||||
this.root.push(new HorizontalPosition(floating.horizontalPosition));
|
this.root.push(new HorizontalPosition(floating.horizontalPosition));
|
||||||
this.root.push(new VerticalPosition(floating.verticalPosition));
|
this.root.push(new VerticalPosition(floating.verticalPosition));
|
||||||
this.root.push(new Extent(transform.emus.x, transform.emus.y));
|
this.root.push(new Extent(transform.emus.x, transform.emus.y));
|
||||||
this.root.push(new EffectExtent());
|
this.root.push(createEffectExtent({ top: 0, right: 0, bottom: 0, left: 0 }));
|
||||||
|
|
||||||
if (drawingOptions.floating !== undefined && drawingOptions.floating.wrap !== undefined) {
|
if (drawingOptions.floating !== undefined && drawingOptions.floating.wrap !== undefined) {
|
||||||
switch (drawingOptions.floating.wrap.type) {
|
switch (drawingOptions.floating.wrap.type) {
|
||||||
@ -92,6 +100,6 @@ export class Anchor extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(new DocProperties(drawingOptions.docProperties));
|
this.root.push(new DocProperties(drawingOptions.docProperties));
|
||||||
this.root.push(new GraphicFrameProperties());
|
this.root.push(new GraphicFrameProperties());
|
||||||
this.root.push(new Graphic(mediaData, transform));
|
this.root.push(new Graphic({ mediaData, transform, outline: drawingOptions.outline }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,20 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { Anchor } from "./anchor";
|
import { Anchor } from "./anchor";
|
||||||
import { DocPropertiesOptions } from "./doc-properties/doc-properties";
|
import { DocPropertiesOptions } from "./doc-properties/doc-properties";
|
||||||
import { IFloating } from "./floating";
|
import { IFloating } from "./floating";
|
||||||
import { Inline } from "./inline";
|
import { createInline } from "./inline";
|
||||||
|
import { OutlineOptions } from "./inline/graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||||
|
|
||||||
export interface IDistance {
|
export type IDistance = {
|
||||||
readonly distT?: number;
|
readonly distT?: number;
|
||||||
readonly distB?: number;
|
readonly distB?: number;
|
||||||
readonly distL?: number;
|
readonly distL?: number;
|
||||||
readonly distR?: number;
|
readonly distR?: number;
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface IDrawingOptions {
|
export interface IDrawingOptions {
|
||||||
readonly floating?: IFloating;
|
readonly floating?: IFloating;
|
||||||
readonly docProperties?: DocPropertiesOptions;
|
readonly docProperties?: DocPropertiesOptions;
|
||||||
|
readonly outline?: OutlineOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Drawing">
|
// <xsd:complexType name="CT_Drawing">
|
||||||
@ -30,14 +32,16 @@ export class Drawing extends XmlComponent {
|
|||||||
super("w:drawing");
|
super("w:drawing");
|
||||||
|
|
||||||
if (!drawingOptions.floating) {
|
if (!drawingOptions.floating) {
|
||||||
const inline = new Inline({
|
this.root.push(
|
||||||
mediaData: imageData,
|
createInline({
|
||||||
transform: imageData.transformation,
|
mediaData: imageData,
|
||||||
docProperties: drawingOptions.docProperties,
|
transform: imageData.transformation,
|
||||||
});
|
docProperties: drawingOptions.docProperties,
|
||||||
this.root.push(inline);
|
outline: drawingOptions.outline,
|
||||||
|
}),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
|
this.root.push(new Anchor({ mediaData: imageData, transform: imageData.transformation, drawingOptions }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import { XmlAttributeComponent } from "@file/xml-components";
|
|
||||||
|
|
||||||
export class EffectExtentAttributes extends XmlAttributeComponent<{
|
|
||||||
readonly b?: number;
|
|
||||||
readonly l?: number;
|
|
||||||
readonly r?: number;
|
|
||||||
readonly t?: number;
|
|
||||||
}> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
b: "b",
|
|
||||||
l: "l",
|
|
||||||
r: "r",
|
|
||||||
t: "t",
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,17 +1,31 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
import { EffectExtentAttributes } from "./effect-extent-attributes";
|
|
||||||
|
|
||||||
export class EffectExtent extends XmlComponent {
|
export type EffectExtentAttributes = {
|
||||||
public constructor() {
|
readonly top: number;
|
||||||
super("wp:effectExtent");
|
readonly right: number;
|
||||||
|
readonly bottom: number;
|
||||||
|
readonly left: number;
|
||||||
|
};
|
||||||
|
|
||||||
this.root.push(
|
export const createEffectExtent = ({ top, right, bottom, left }: EffectExtentAttributes): XmlComponent =>
|
||||||
new EffectExtentAttributes({
|
new BuilderElement<EffectExtentAttributes>({
|
||||||
b: 0,
|
name: "wp:effectExtent",
|
||||||
l: 0,
|
attributes: {
|
||||||
r: 0,
|
top: {
|
||||||
t: 0,
|
key: "t",
|
||||||
}),
|
value: top,
|
||||||
);
|
},
|
||||||
}
|
right: {
|
||||||
}
|
key: "r",
|
||||||
|
value: right,
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
key: "b",
|
||||||
|
value: bottom,
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
key: "l",
|
||||||
|
value: left,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
@ -3,7 +3,11 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class Align extends XmlComponent {
|
export class Align extends XmlComponent {
|
||||||
public constructor(value: HorizontalPositionAlign | VerticalPositionAlign) {
|
public constructor(
|
||||||
|
value:
|
||||||
|
| (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign]
|
||||||
|
| (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign],
|
||||||
|
) {
|
||||||
super("wp:align");
|
super("wp:align");
|
||||||
this.root.push(value);
|
this.root.push(value);
|
||||||
}
|
}
|
||||||
|
@ -4,37 +4,39 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
|
|||||||
|
|
||||||
import { ITextWrapping } from "../text-wrap";
|
import { ITextWrapping } from "../text-wrap";
|
||||||
|
|
||||||
export enum HorizontalPositionRelativeFrom {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
CHARACTER = "character",
|
export const HorizontalPositionRelativeFrom = {
|
||||||
COLUMN = "column",
|
CHARACTER: "character",
|
||||||
INSIDE_MARGIN = "insideMargin",
|
COLUMN: "column",
|
||||||
LEFT_MARGIN = "leftMargin",
|
INSIDE_MARGIN: "insideMargin",
|
||||||
MARGIN = "margin",
|
LEFT_MARGIN: "leftMargin",
|
||||||
OUTSIDE_MARGIN = "outsideMargin",
|
MARGIN: "margin",
|
||||||
PAGE = "page",
|
OUTSIDE_MARGIN: "outsideMargin",
|
||||||
RIGHT_MARGIN = "rightMargin",
|
PAGE: "page",
|
||||||
}
|
RIGHT_MARGIN: "rightMargin",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export enum VerticalPositionRelativeFrom {
|
export const VerticalPositionRelativeFrom = {
|
||||||
BOTTOM_MARGIN = "bottomMargin",
|
BOTTOM_MARGIN: "bottomMargin",
|
||||||
INSIDE_MARGIN = "insideMargin",
|
INSIDE_MARGIN: "insideMargin",
|
||||||
LINE = "line",
|
LINE: "line",
|
||||||
MARGIN = "margin",
|
MARGIN: "margin",
|
||||||
OUTSIDE_MARGIN = "outsideMargin",
|
OUTSIDE_MARGIN: "outsideMargin",
|
||||||
PAGE = "page",
|
PAGE: "page",
|
||||||
PARAGRAPH = "paragraph",
|
PARAGRAPH: "paragraph",
|
||||||
TOP_MARGIN = "topMargin",
|
TOP_MARGIN: "topMargin",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
export interface IHorizontalPositionOptions {
|
export interface IHorizontalPositionOptions {
|
||||||
readonly relative?: HorizontalPositionRelativeFrom;
|
readonly relative?: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom];
|
||||||
readonly align?: HorizontalPositionAlign;
|
readonly align?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
|
||||||
readonly offset?: number;
|
readonly offset?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IVerticalPositionOptions {
|
export interface IVerticalPositionOptions {
|
||||||
readonly relative?: VerticalPositionRelativeFrom;
|
readonly relative?: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
|
||||||
readonly align?: VerticalPositionAlign;
|
readonly align?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
|
||||||
readonly offset?: number;
|
readonly offset?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl
|
|||||||
import { PositionOffset } from "./position-offset";
|
import { PositionOffset } from "./position-offset";
|
||||||
|
|
||||||
class HorizontalPositionAttributes extends XmlAttributeComponent<{
|
class HorizontalPositionAttributes extends XmlAttributeComponent<{
|
||||||
readonly relativeFrom: HorizontalPositionRelativeFrom;
|
readonly relativeFrom: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom];
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
relativeFrom: "relativeFrom",
|
relativeFrom: "relativeFrom",
|
||||||
|
@ -5,7 +5,7 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati
|
|||||||
import { PositionOffset } from "./position-offset";
|
import { PositionOffset } from "./position-offset";
|
||||||
|
|
||||||
class VerticalPositionAttributes extends XmlAttributeComponent<{
|
class VerticalPositionAttributes extends XmlAttributeComponent<{
|
||||||
readonly relativeFrom: VerticalPositionRelativeFrom;
|
readonly relativeFrom: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
relativeFrom: "relativeFrom",
|
relativeFrom: "relativeFrom",
|
||||||
|
@ -3,11 +3,20 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
|
|
||||||
import { GraphicDataAttributes } from "./graphic-data-attribute";
|
import { GraphicDataAttributes } from "./graphic-data-attribute";
|
||||||
import { Pic } from "./pic";
|
import { Pic } from "./pic";
|
||||||
|
import { OutlineOptions } from "./pic/shape-properties/outline/outline";
|
||||||
|
|
||||||
export class GraphicData extends XmlComponent {
|
export class GraphicData extends XmlComponent {
|
||||||
private readonly pic: Pic;
|
private readonly pic: Pic;
|
||||||
|
|
||||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
public constructor({
|
||||||
|
mediaData,
|
||||||
|
transform,
|
||||||
|
outline,
|
||||||
|
}: {
|
||||||
|
readonly mediaData: IMediaData;
|
||||||
|
readonly transform: IMediaDataTransformation;
|
||||||
|
readonly outline?: OutlineOptions;
|
||||||
|
}) {
|
||||||
super("a:graphicData");
|
super("a:graphicData");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
@ -16,7 +25,7 @@ export class GraphicData extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.pic = new Pic(mediaData, transform);
|
this.pic = new Pic({ mediaData, transform, outline });
|
||||||
|
|
||||||
this.root.push(this.pic);
|
this.root.push(this.pic);
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,18 @@ import { BlipFill } from "./blip/blip-fill";
|
|||||||
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
|
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
|
||||||
import { PicAttributes } from "./pic-attributes";
|
import { PicAttributes } from "./pic-attributes";
|
||||||
import { ShapeProperties } from "./shape-properties/shape-properties";
|
import { ShapeProperties } from "./shape-properties/shape-properties";
|
||||||
|
import { OutlineOptions } from "./shape-properties/outline/outline";
|
||||||
|
|
||||||
export class Pic extends XmlComponent {
|
export class Pic extends XmlComponent {
|
||||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
public constructor({
|
||||||
|
mediaData,
|
||||||
|
transform,
|
||||||
|
outline,
|
||||||
|
}: {
|
||||||
|
readonly mediaData: IMediaData;
|
||||||
|
readonly transform: IMediaDataTransformation;
|
||||||
|
readonly outline?: OutlineOptions;
|
||||||
|
}) {
|
||||||
super("pic:pic");
|
super("pic:pic");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
@ -19,6 +28,6 @@ export class Pic extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(new NonVisualPicProperties());
|
this.root.push(new NonVisualPicProperties());
|
||||||
this.root.push(new BlipFill(mediaData));
|
this.root.push(new BlipFill(mediaData));
|
||||||
this.root.push(new ShapeProperties(transform));
|
this.root.push(new ShapeProperties({ transform, outline }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
import { NoFill } from "./no-fill";
|
import { createNoFill } from "./no-fill";
|
||||||
|
|
||||||
describe("NoFill", () => {
|
describe("NoFill", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const tree = new Formatter().format(new NoFill());
|
const tree = new Formatter().format(createNoFill());
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"a:noFill": {},
|
"a:noFill": {},
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class NoFill extends XmlComponent {
|
export const createNoFill = (): XmlComponent => new BuilderElement({ name: "a:noFill" });
|
||||||
public constructor() {
|
|
||||||
super("a:noFill");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,19 +1,66 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
import { Outline } from "./outline";
|
|
||||||
|
|
||||||
describe("Outline", () => {
|
import { createOutline } from "./outline";
|
||||||
describe("#constructor()", () => {
|
import { SchemeColor } from "./scheme-color";
|
||||||
it("should create", () => {
|
|
||||||
const tree = new Formatter().format(new Outline());
|
describe("createOutline", () => {
|
||||||
expect(tree).to.deep.equal({
|
it("should create no fill", () => {
|
||||||
"a:ln": [
|
const tree = new Formatter().format(createOutline({ type: "noFill" }));
|
||||||
{
|
expect(tree).to.deep.equal({
|
||||||
"a:noFill": {},
|
"a:ln": [
|
||||||
},
|
{
|
||||||
],
|
_attr: {},
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
"a:noFill": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create solid rgb fill", () => {
|
||||||
|
const tree = new Formatter().format(createOutline({ type: "solidFill", solidFillType: "rgb", value: "FFFFFF" }));
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:ln": [
|
||||||
|
{
|
||||||
|
_attr: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:solidFill": [
|
||||||
|
{
|
||||||
|
"a:srgbClr": {
|
||||||
|
_attr: {
|
||||||
|
val: "FFFFFF",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create solid scheme fill", () => {
|
||||||
|
const tree = new Formatter().format(createOutline({ type: "solidFill", solidFillType: "scheme", value: SchemeColor.ACCENT1 }));
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:ln": [
|
||||||
|
{
|
||||||
|
_attr: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"a:solidFill": [
|
||||||
|
{
|
||||||
|
"a:schemeClr": {
|
||||||
|
_attr: {
|
||||||
|
val: "accent1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,130 @@
|
|||||||
// http://officeopenxml.com/drwSp-outline.php
|
// http://officeopenxml.com/drwSp-outline.php
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
import { NoFill } from "./no-fill";
|
import { createNoFill } from "./no-fill";
|
||||||
|
import { createSolidFill } from "./solid-fill";
|
||||||
|
import { SchemeColor } from "./scheme-color";
|
||||||
|
|
||||||
export class Outline extends XmlComponent {
|
// <xsd:complexType name="CT_TextOutlineEffect">
|
||||||
public constructor() {
|
// <xsd:sequence>
|
||||||
super("a:ln");
|
// <xsd:group ref="EG_FillProperties" minOccurs="0"/>
|
||||||
|
// <xsd:group ref="EG_LineDashProperties" minOccurs="0"/>
|
||||||
|
// <xsd:group ref="EG_LineJoinProperties" minOccurs="0"/>
|
||||||
|
// </xsd:sequence>
|
||||||
|
// <xsd:attribute name="w" use="optional" type="a:ST_LineWidth"/>
|
||||||
|
// <xsd:attribute name="cap" use="optional" type="ST_LineCap"/>
|
||||||
|
// <xsd:attribute name="cmpd" use="optional" type="ST_CompoundLine"/>
|
||||||
|
// <xsd:attribute name="algn" use="optional" type="ST_PenAlignment"/>
|
||||||
|
// </xsd:complexType>
|
||||||
|
|
||||||
this.root.push(new NoFill());
|
// <xsd:simpleType name="ST_LineCap">
|
||||||
}
|
// <xsd:restriction base="xsd:string">
|
||||||
}
|
// <xsd:enumeration value="rnd"/>
|
||||||
|
// <xsd:enumeration value="sq"/>
|
||||||
|
// <xsd:enumeration value="flat"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export const LineCap = {
|
||||||
|
ROUND: "rnd",
|
||||||
|
SQUARE: "sq",
|
||||||
|
FLAT: "flat",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_CompoundLine">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="sng"/>
|
||||||
|
// <xsd:enumeration value="dbl"/>
|
||||||
|
// <xsd:enumeration value="thickThin"/>
|
||||||
|
// <xsd:enumeration value="thinThick"/>
|
||||||
|
// <xsd:enumeration value="tri"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export const CompoundLine = {
|
||||||
|
SINGLE: "sng",
|
||||||
|
DOUBLE: "dbl",
|
||||||
|
THICK_THIN: "thickThin",
|
||||||
|
THIN_THICK: "thinThick",
|
||||||
|
TRI: "tri",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_PenAlignment">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="ctr"/>
|
||||||
|
// <xsd:enumeration value="in"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
export const PenAlignment = {
|
||||||
|
CENTER: "ctr",
|
||||||
|
INSET: "in",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type OutlineAttributes = {
|
||||||
|
readonly width?: number;
|
||||||
|
readonly cap?: keyof typeof LineCap;
|
||||||
|
readonly compoundLine?: keyof typeof CompoundLine;
|
||||||
|
readonly align?: keyof typeof PenAlignment;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OutlineNoFill = {
|
||||||
|
readonly type: "noFill";
|
||||||
|
};
|
||||||
|
|
||||||
|
type OutlineRgbSolidFill = {
|
||||||
|
readonly type: "solidFill";
|
||||||
|
readonly solidFillType: "rgb";
|
||||||
|
readonly value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OutlineSchemeSolidFill = {
|
||||||
|
readonly type: "solidFill";
|
||||||
|
readonly solidFillType: "scheme";
|
||||||
|
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||||
|
};
|
||||||
|
|
||||||
|
type OutlineSolidFill = OutlineRgbSolidFill | OutlineSchemeSolidFill;
|
||||||
|
|
||||||
|
// <xsd:group name="EG_FillProperties">
|
||||||
|
// <xsd:choice>
|
||||||
|
// <xsd:element name="noFill" type="w:CT_Empty"/>
|
||||||
|
// <xsd:element name="solidFill" type="CT_SolidColorFillProperties"/>
|
||||||
|
// <xsd:element name="gradFill" type="CT_GradientFillProperties"/>
|
||||||
|
// </xsd:choice>
|
||||||
|
// </xsd:group>
|
||||||
|
type OutlineFillProperties = OutlineNoFill | OutlineSolidFill;
|
||||||
|
|
||||||
|
export type OutlineOptions = OutlineAttributes & OutlineFillProperties;
|
||||||
|
|
||||||
|
export const createOutline = (options: OutlineOptions): XmlComponent =>
|
||||||
|
new BuilderElement<OutlineAttributes>({
|
||||||
|
name: "a:ln",
|
||||||
|
attributes: {
|
||||||
|
width: {
|
||||||
|
key: "w",
|
||||||
|
value: options.width,
|
||||||
|
},
|
||||||
|
cap: {
|
||||||
|
key: "cap",
|
||||||
|
value: options.cap,
|
||||||
|
},
|
||||||
|
compoundLine: {
|
||||||
|
key: "cmpd",
|
||||||
|
value: options.compoundLine,
|
||||||
|
},
|
||||||
|
align: {
|
||||||
|
key: "algn",
|
||||||
|
value: options.align,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
options.type === "noFill"
|
||||||
|
? createNoFill()
|
||||||
|
: options.solidFillType === "rgb"
|
||||||
|
? createSolidFill({
|
||||||
|
type: "rgb",
|
||||||
|
value: options.value,
|
||||||
|
})
|
||||||
|
: createSolidFill({
|
||||||
|
type: "scheme",
|
||||||
|
value: options.value,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
type SolidRgbColorOptions = {
|
||||||
|
readonly value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_SRgbColor">
|
||||||
|
// <xsd:sequence>
|
||||||
|
// <xsd:group ref="EG_ColorTransform" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
// </xsd:sequence>
|
||||||
|
// <xsd:attribute name="val" type="s:ST_HexColorRGB" use="required"/>
|
||||||
|
// </xsd:complexType>
|
||||||
|
export const createSolidRgbColor = (options: SolidRgbColorOptions): XmlComponent =>
|
||||||
|
new BuilderElement<SolidRgbColorOptions>({
|
||||||
|
name: "a:srgbClr",
|
||||||
|
attributes: {
|
||||||
|
value: {
|
||||||
|
key: "val",
|
||||||
|
value: options.value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
@ -0,0 +1,65 @@
|
|||||||
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
type SchemeColorOptions = {
|
||||||
|
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||||
|
};
|
||||||
|
|
||||||
|
// <xsd:simpleType name="ST_SchemeColorVal">
|
||||||
|
// <xsd:restriction base="xsd:string">
|
||||||
|
// <xsd:enumeration value="bg1"/>
|
||||||
|
// <xsd:enumeration value="tx1"/>
|
||||||
|
// <xsd:enumeration value="bg2"/>
|
||||||
|
// <xsd:enumeration value="tx2"/>
|
||||||
|
// <xsd:enumeration value="accent1"/>
|
||||||
|
// <xsd:enumeration value="accent2"/>
|
||||||
|
// <xsd:enumeration value="accent3"/>
|
||||||
|
// <xsd:enumeration value="accent4"/>
|
||||||
|
// <xsd:enumeration value="accent5"/>
|
||||||
|
// <xsd:enumeration value="accent6"/>
|
||||||
|
// <xsd:enumeration value="hlink"/>
|
||||||
|
// <xsd:enumeration value="folHlink"/>
|
||||||
|
// <xsd:enumeration value="dk1"/>
|
||||||
|
// <xsd:enumeration value="lt1"/>
|
||||||
|
// <xsd:enumeration value="dk2"/>
|
||||||
|
// <xsd:enumeration value="lt2"/>
|
||||||
|
// <xsd:enumeration value="phClr"/>
|
||||||
|
// </xsd:restriction>
|
||||||
|
// </xsd:simpleType>
|
||||||
|
|
||||||
|
// cspell:ignore folHlink, phClr, hlink
|
||||||
|
export const SchemeColor = {
|
||||||
|
BG1: "bg1",
|
||||||
|
TX1: "tx1",
|
||||||
|
BG2: "bg2",
|
||||||
|
TX2: "tx2",
|
||||||
|
ACCENT1: "accent1",
|
||||||
|
ACCENT2: "accent2",
|
||||||
|
ACCENT3: "accent3",
|
||||||
|
ACCENT4: "accent4",
|
||||||
|
ACCENT5: "accent5",
|
||||||
|
ACCENT6: "accent6",
|
||||||
|
HLINK: "hlink",
|
||||||
|
FOLHLINK: "folHlink",
|
||||||
|
DK1: "dk1",
|
||||||
|
LT1: "lt1",
|
||||||
|
DK2: "dk2",
|
||||||
|
LT2: "lt2",
|
||||||
|
PHCLR: "phClr",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// <xsd:complexType name="CT_SchemeColor">
|
||||||
|
// <xsd:sequence>
|
||||||
|
// <xsd:group ref="EG_ColorTransform" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
// </xsd:sequence>
|
||||||
|
// <xsd:attribute name="val" type="ST_SchemeColorVal" use="required"/>
|
||||||
|
// </xsd:complexType>
|
||||||
|
export const createSchemeColor = (options: SchemeColorOptions): XmlComponent =>
|
||||||
|
new BuilderElement<SchemeColorOptions>({
|
||||||
|
name: "a:schemeClr",
|
||||||
|
attributes: {
|
||||||
|
value: {
|
||||||
|
key: "val",
|
||||||
|
value: options.value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
@ -0,0 +1,38 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { createSolidFill } from "./solid-fill";
|
||||||
|
import { SchemeColor } from "./scheme-color";
|
||||||
|
|
||||||
|
describe("createSolidFill", () => {
|
||||||
|
it("should create of rgb", () => {
|
||||||
|
const tree = new Formatter().format(createSolidFill({ type: "rgb", value: "FFFFFF" }));
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:solidFill": [
|
||||||
|
{
|
||||||
|
"a:srgbClr": {
|
||||||
|
_attr: {
|
||||||
|
val: "FFFFFF",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create of scheme", () => {
|
||||||
|
const tree = new Formatter().format(createSolidFill({ type: "scheme", value: SchemeColor.TX1 }));
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"a:solidFill": [
|
||||||
|
{
|
||||||
|
"a:schemeClr": {
|
||||||
|
_attr: {
|
||||||
|
val: "tx1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,22 @@
|
|||||||
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
|
import { createSchemeColor, SchemeColor } from "./scheme-color";
|
||||||
|
import { createSolidRgbColor } from "./rgb-color";
|
||||||
|
|
||||||
|
export type RgbColorOptions = {
|
||||||
|
readonly type: "rgb";
|
||||||
|
readonly value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SchemeColorOptions = {
|
||||||
|
readonly type: "scheme";
|
||||||
|
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SolidFillOptions = RgbColorOptions | SchemeColorOptions;
|
||||||
|
|
||||||
|
export const createSolidFill = (options: SolidFillOptions): XmlComponent =>
|
||||||
|
new BuilderElement({
|
||||||
|
name: "a:solidFill",
|
||||||
|
children: [options.type === "rgb" ? createSolidRgbColor(options) : createSchemeColor(options)],
|
||||||
|
});
|
@ -2,15 +2,15 @@
|
|||||||
import { IMediaDataTransformation } from "@file/media";
|
import { IMediaDataTransformation } from "@file/media";
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
import { Form } from "./form";
|
import { Form } from "./form";
|
||||||
// import { NoFill } from "./no-fill";
|
import { OutlineOptions, createOutline } from "./outline/outline";
|
||||||
// import { Outline } from "./outline/outline";
|
|
||||||
import { PresetGeometry } from "./preset-geometry/preset-geometry";
|
import { PresetGeometry } from "./preset-geometry/preset-geometry";
|
||||||
import { ShapePropertiesAttributes } from "./shape-properties-attributes";
|
import { ShapePropertiesAttributes } from "./shape-properties-attributes";
|
||||||
|
import { createNoFill } from "./outline/no-fill";
|
||||||
|
|
||||||
export class ShapeProperties extends XmlComponent {
|
export class ShapeProperties extends XmlComponent {
|
||||||
private readonly form: Form;
|
private readonly form: Form;
|
||||||
|
|
||||||
public constructor(transform: IMediaDataTransformation) {
|
public constructor({ outline, transform }: { readonly outline?: OutlineOptions; readonly transform: IMediaDataTransformation }) {
|
||||||
super("pic:spPr");
|
super("pic:spPr");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
@ -23,7 +23,10 @@ export class ShapeProperties extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(this.form);
|
this.root.push(this.form);
|
||||||
this.root.push(new PresetGeometry());
|
this.root.push(new PresetGeometry());
|
||||||
// this.root.push(new NoFill());
|
|
||||||
// this.root.push(new Outline());
|
if (outline) {
|
||||||
|
this.root.push(createNoFill());
|
||||||
|
this.root.push(createOutline(outline));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { IMediaData, IMediaDataTransformation } from "@file/media";
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { GraphicData } from "./graphic-data";
|
import { GraphicData } from "./graphic-data";
|
||||||
|
import { OutlineOptions } from "./graphic-data/pic/shape-properties/outline/outline";
|
||||||
|
|
||||||
class GraphicAttributes extends XmlAttributeComponent<{
|
class GraphicAttributes extends XmlAttributeComponent<{
|
||||||
readonly a: string;
|
readonly a: string;
|
||||||
@ -14,7 +15,15 @@ class GraphicAttributes extends XmlAttributeComponent<{
|
|||||||
export class Graphic extends XmlComponent {
|
export class Graphic extends XmlComponent {
|
||||||
private readonly data: GraphicData;
|
private readonly data: GraphicData;
|
||||||
|
|
||||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
public constructor({
|
||||||
|
mediaData,
|
||||||
|
transform,
|
||||||
|
outline,
|
||||||
|
}: {
|
||||||
|
readonly mediaData: IMediaData;
|
||||||
|
readonly transform: IMediaDataTransformation;
|
||||||
|
readonly outline?: OutlineOptions;
|
||||||
|
}) {
|
||||||
super("a:graphic");
|
super("a:graphic");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new GraphicAttributes({
|
new GraphicAttributes({
|
||||||
@ -22,7 +31,7 @@ export class Graphic extends XmlComponent {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.data = new GraphicData(mediaData, transform);
|
this.data = new GraphicData({ mediaData, transform, outline });
|
||||||
|
|
||||||
this.root.push(this.data);
|
this.root.push(this.data);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { XmlAttributeComponent } from "@file/xml-components";
|
|
||||||
import { IDistance } from "../drawing";
|
|
||||||
|
|
||||||
// distT, distB etc have no effect on inline images, only floating
|
|
||||||
export class InlineAttributes extends XmlAttributeComponent<IDistance> {
|
|
||||||
protected readonly xmlKeys = {
|
|
||||||
distT: "distT",
|
|
||||||
distB: "distB",
|
|
||||||
distL: "distL",
|
|
||||||
distR: "distR",
|
|
||||||
};
|
|
||||||
}
|
|
58
src/file/drawing/inline/inline.spec.ts
Normal file
58
src/file/drawing/inline/inline.spec.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
import { createInline } from "./inline";
|
||||||
|
|
||||||
|
describe("Inline", () => {
|
||||||
|
it("should create with default effect extent", () => {
|
||||||
|
const tree = new Formatter().format(
|
||||||
|
createInline({
|
||||||
|
mediaData: {
|
||||||
|
fileName: "test.png",
|
||||||
|
stream: Buffer.from(""),
|
||||||
|
transformation: {
|
||||||
|
pixels: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
emus: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
pixels: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
emus: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
docProperties: {
|
||||||
|
name: "test",
|
||||||
|
description: "test",
|
||||||
|
title: "test",
|
||||||
|
},
|
||||||
|
outline: { type: "solidFill", solidFillType: "rgb", value: "FFFFFF" },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tree).toStrictEqual({
|
||||||
|
"wp:inline": expect.arrayContaining([
|
||||||
|
{
|
||||||
|
"wp:effectExtent": {
|
||||||
|
_attr: {
|
||||||
|
b: 19050,
|
||||||
|
l: 19050,
|
||||||
|
r: 19050,
|
||||||
|
t: 19050,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,18 +1,19 @@
|
|||||||
// http://officeopenxml.com/drwPicInline.php
|
// http://officeopenxml.com/drwPicInline.php
|
||||||
import { IMediaData, IMediaDataTransformation } from "@file/media";
|
import { IMediaData, IMediaDataTransformation } from "@file/media";
|
||||||
import { XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
import { DocProperties, DocPropertiesOptions } from "./../doc-properties/doc-properties";
|
import { DocProperties, DocPropertiesOptions } from "./../doc-properties/doc-properties";
|
||||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
import { createEffectExtent } from "./../effect-extent/effect-extent";
|
||||||
import { Extent } from "./../extent/extent";
|
import { Extent } from "./../extent/extent";
|
||||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||||
import { Graphic } from "./../inline/graphic";
|
import { Graphic } from "./../inline/graphic";
|
||||||
import { InlineAttributes } from "./inline-attributes";
|
import { OutlineOptions } from "./graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||||
|
|
||||||
interface InlineOptions {
|
type InlineOptions = {
|
||||||
readonly mediaData: IMediaData;
|
readonly mediaData: IMediaData;
|
||||||
readonly transform: IMediaDataTransformation;
|
readonly transform: IMediaDataTransformation;
|
||||||
readonly docProperties?: DocPropertiesOptions;
|
readonly docProperties?: DocPropertiesOptions;
|
||||||
}
|
readonly outline?: OutlineOptions;
|
||||||
|
};
|
||||||
|
|
||||||
// <xsd:complexType name="CT_Inline">
|
// <xsd:complexType name="CT_Inline">
|
||||||
// <xsd:sequence>
|
// <xsd:sequence>
|
||||||
@ -28,29 +29,41 @@ interface InlineOptions {
|
|||||||
// <xsd:attribute name="distL" type="ST_WrapDistance" use="optional"/>
|
// <xsd:attribute name="distL" type="ST_WrapDistance" use="optional"/>
|
||||||
// <xsd:attribute name="distR" type="ST_WrapDistance" use="optional"/>
|
// <xsd:attribute name="distR" type="ST_WrapDistance" use="optional"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class Inline extends XmlComponent {
|
export const createInline = ({ mediaData, transform, docProperties, outline }: InlineOptions): XmlComponent =>
|
||||||
private readonly extent: Extent;
|
new BuilderElement({
|
||||||
private readonly graphic: Graphic;
|
name: "wp:inline",
|
||||||
|
attributes: {
|
||||||
public constructor({ mediaData, transform, docProperties }: InlineOptions) {
|
distanceTop: {
|
||||||
super("wp:inline");
|
key: "distT",
|
||||||
|
value: 0,
|
||||||
this.root.push(
|
},
|
||||||
new InlineAttributes({
|
distanceBottom: {
|
||||||
distT: 0,
|
key: "distB",
|
||||||
distB: 0,
|
value: 0,
|
||||||
distL: 0,
|
},
|
||||||
distR: 0,
|
distanceLeft: {
|
||||||
}),
|
key: "distL",
|
||||||
);
|
value: 0,
|
||||||
|
},
|
||||||
this.extent = new Extent(transform.emus.x, transform.emus.y);
|
distanceRight: {
|
||||||
this.graphic = new Graphic(mediaData, transform);
|
key: "distR",
|
||||||
|
value: 0,
|
||||||
this.root.push(this.extent);
|
},
|
||||||
this.root.push(new EffectExtent());
|
},
|
||||||
this.root.push(new DocProperties(docProperties));
|
children: [
|
||||||
this.root.push(new GraphicFrameProperties());
|
new Extent(transform.emus.x, transform.emus.y),
|
||||||
this.root.push(this.graphic);
|
createEffectExtent(
|
||||||
}
|
outline
|
||||||
}
|
? {
|
||||||
|
top: (outline.width ?? 9525) * 2,
|
||||||
|
right: (outline.width ?? 9525) * 2,
|
||||||
|
bottom: (outline.width ?? 9525) * 2,
|
||||||
|
left: (outline.width ?? 9525) * 2,
|
||||||
|
}
|
||||||
|
: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||||
|
),
|
||||||
|
new DocProperties(docProperties),
|
||||||
|
new GraphicFrameProperties(),
|
||||||
|
new Graphic({ mediaData, transform, outline }),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
||||||
import { IDistance } from "../drawing";
|
import { IDistance } from "../drawing";
|
||||||
|
|
||||||
export enum TextWrappingType {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
NONE,
|
export const TextWrappingType = {
|
||||||
SQUARE,
|
NONE: 0,
|
||||||
TIGHT,
|
SQUARE: 1,
|
||||||
TOP_AND_BOTTOM,
|
TIGHT: 2,
|
||||||
}
|
TOP_AND_BOTTOM: 3,
|
||||||
|
} as const;
|
||||||
|
|
||||||
export enum TextWrappingSide {
|
export const TextWrappingSide = {
|
||||||
BOTH_SIDES = "bothSides",
|
BOTH_SIDES: "bothSides",
|
||||||
LEFT = "left",
|
LEFT: "left",
|
||||||
RIGHT = "right",
|
RIGHT: "right",
|
||||||
LARGEST = "largest",
|
LARGEST: "largest",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
export interface ITextWrapping {
|
export interface ITextWrapping {
|
||||||
readonly type: TextWrappingType;
|
readonly type: (typeof TextWrappingType)[keyof typeof TextWrappingType];
|
||||||
readonly side?: TextWrappingSide;
|
readonly side?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
|
||||||
readonly margins?: IDistance;
|
readonly margins?: IDistance;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import { IMargins } from "../floating";
|
|||||||
import { ITextWrapping, TextWrappingSide } from "./text-wrapping";
|
import { ITextWrapping, TextWrappingSide } from "./text-wrapping";
|
||||||
|
|
||||||
interface IWrapSquareAttributes extends IDistance {
|
interface IWrapSquareAttributes extends IDistance {
|
||||||
readonly wrapText?: TextWrappingSide;
|
readonly wrapText?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
|
||||||
}
|
}
|
||||||
|
|
||||||
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
|
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
|
||||||
|
@ -77,6 +77,7 @@ export class File {
|
|||||||
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
||||||
trackRevisions: options.features?.trackRevisions,
|
trackRevisions: options.features?.trackRevisions,
|
||||||
updateFields: options.features?.updateFields,
|
updateFields: options.features?.updateFields,
|
||||||
|
defaultTabStop: options.defaultTabStop,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.media = new Media();
|
this.media = new Media();
|
||||||
@ -154,7 +155,10 @@ export class File {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private addHeaderToDocument(header: HeaderWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void {
|
private addHeaderToDocument(
|
||||||
|
header: HeaderWrapper,
|
||||||
|
type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT,
|
||||||
|
): void {
|
||||||
// eslint-disable-next-line functional/immutable-data
|
// eslint-disable-next-line functional/immutable-data
|
||||||
this.headers.push({ header, type });
|
this.headers.push({ header, type });
|
||||||
this.documentWrapper.Relationships.createRelationship(
|
this.documentWrapper.Relationships.createRelationship(
|
||||||
@ -165,7 +169,10 @@ export class File {
|
|||||||
this.contentTypes.addHeader(this.headers.length);
|
this.contentTypes.addHeader(this.headers.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFooterToDocument(footer: FooterWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void {
|
private addFooterToDocument(
|
||||||
|
footer: FooterWrapper,
|
||||||
|
type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT,
|
||||||
|
): void {
|
||||||
// eslint-disable-next-line functional/immutable-data
|
// eslint-disable-next-line functional/immutable-data
|
||||||
this.footers.push({ footer, type });
|
this.footers.push({ footer, type });
|
||||||
this.documentWrapper.Relationships.createRelationship(
|
this.documentWrapper.Relationships.createRelationship(
|
||||||
|
@ -10,7 +10,7 @@ import { Table } from "./table";
|
|||||||
|
|
||||||
export interface IDocumentFooter {
|
export interface IDocumentFooter {
|
||||||
readonly footer: FooterWrapper;
|
readonly footer: FooterWrapper;
|
||||||
readonly type: HeaderFooterReferenceType;
|
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FooterWrapper implements IViewWrapper {
|
export class FooterWrapper implements IViewWrapper {
|
||||||
|
@ -4,14 +4,15 @@ import { XmlComponent } from "@file/xml-components";
|
|||||||
import { FootnoteAttributes } from "./footnote-attributes";
|
import { FootnoteAttributes } from "./footnote-attributes";
|
||||||
import { FootnoteRefRun } from "./run/footnote-ref-run";
|
import { FootnoteRefRun } from "./run/footnote-ref-run";
|
||||||
|
|
||||||
export enum FootnoteType {
|
export const FootnoteType = {
|
||||||
SEPERATOR = "separator",
|
SEPERATOR: "separator",
|
||||||
CONTINUATION_SEPERATOR = "continuationSeparator",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
}
|
CONTINUATION_SEPERATOR: "continuationSeparator",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export interface IFootnoteOptions {
|
export interface IFootnoteOptions {
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
readonly type?: FootnoteType;
|
readonly type?: (typeof FootnoteType)[keyof typeof FootnoteType];
|
||||||
readonly children: readonly Paragraph[];
|
readonly children: readonly Paragraph[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import { Table } from "./table";
|
|||||||
|
|
||||||
export interface IDocumentHeader {
|
export interface IDocumentHeader {
|
||||||
readonly header: HeaderWrapper;
|
readonly header: HeaderWrapper;
|
||||||
readonly type: HeaderFooterReferenceType;
|
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HeaderWrapper implements IViewWrapper {
|
export class HeaderWrapper implements IViewWrapper {
|
||||||
|
@ -75,71 +75,75 @@ import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/prop
|
|||||||
// <xsd:enumeration value="custom"/>
|
// <xsd:enumeration value="custom"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum LevelFormat {
|
|
||||||
DECIMAL = "decimal",
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
UPPER_ROMAN = "upperRoman",
|
export const LevelFormat = {
|
||||||
LOWER_ROMAN = "lowerRoman",
|
DECIMAL: "decimal",
|
||||||
UPPER_LETTER = "upperLetter",
|
UPPER_ROMAN: "upperRoman",
|
||||||
LOWER_LETTER = "lowerLetter",
|
LOWER_ROMAN: "lowerRoman",
|
||||||
ORDINAL = "ordinal",
|
UPPER_LETTER: "upperLetter",
|
||||||
CARDINAL_TEXT = "cardinalText",
|
LOWER_LETTER: "lowerLetter",
|
||||||
ORDINAL_TEXT = "ordinalText",
|
ORDINAL: "ordinal",
|
||||||
HEX = "hex",
|
CARDINAL_TEXT: "cardinalText",
|
||||||
CHICAGO = "chicago",
|
ORDINAL_TEXT: "ordinalText",
|
||||||
IDEOGRAPH__DIGITAL = "ideographDigital",
|
HEX: "hex",
|
||||||
JAPANESE_COUNTING = "japaneseCounting",
|
CHICAGO: "chicago",
|
||||||
AIUEO = "aiueo",
|
IDEOGRAPH__DIGITAL: "ideographDigital",
|
||||||
IROHA = "iroha",
|
JAPANESE_COUNTING: "japaneseCounting",
|
||||||
DECIMAL_FULL_WIDTH = "decimalFullWidth",
|
AIUEO: "aiueo",
|
||||||
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
|
IROHA: "iroha",
|
||||||
JAPANESE_LEGAL = "japaneseLegal",
|
DECIMAL_FULL_WIDTH: "decimalFullWidth",
|
||||||
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
|
DECIMAL_HALF_WIDTH: "decimalHalfWidth",
|
||||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
JAPANESE_LEGAL: "japaneseLegal",
|
||||||
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2",
|
JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand",
|
||||||
AIUEO_FULL_WIDTH = "aiueoFullWidth",
|
DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle",
|
||||||
IROHA_FULL_WIDTH = "irohaFullWidth",
|
DECIMAL_FULL_WIDTH2: "decimalFullWidth2",
|
||||||
DECIMAL_ZERO = "decimalZero",
|
AIUEO_FULL_WIDTH: "aiueoFullWidth",
|
||||||
BULLET = "bullet",
|
IROHA_FULL_WIDTH: "irohaFullWidth",
|
||||||
GANADA = "ganada",
|
DECIMAL_ZERO: "decimalZero",
|
||||||
CHOSUNG = "chosung",
|
BULLET: "bullet",
|
||||||
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
GANADA: "ganada",
|
||||||
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
CHOSUNG: "chosung",
|
||||||
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
|
DECIMAL_ENCLOSED_FULLSTOP: "decimalEnclosedFullstop",
|
||||||
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
|
DECIMAL_ENCLOSED_PARENTHESES: "decimalEnclosedParen",
|
||||||
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
|
DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese",
|
||||||
IDEOGRAPH_ZODIAC = "ideographZodiac",
|
IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle",
|
||||||
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
|
IDEOGRAPH_TRADITIONAL: "ideographTraditional",
|
||||||
TAIWANESE_COUNTING = "taiwaneseCounting",
|
IDEOGRAPH_ZODIAC: "ideographZodiac",
|
||||||
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
|
IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional",
|
||||||
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
|
TAIWANESE_COUNTING: "taiwaneseCounting",
|
||||||
TAIWANESE_DIGITAL = "taiwaneseDigital",
|
IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional",
|
||||||
CHINESE_COUNTING = "chineseCounting",
|
TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand",
|
||||||
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
|
TAIWANESE_DIGITAL: "taiwaneseDigital",
|
||||||
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand",
|
CHINESE_COUNTING: "chineseCounting",
|
||||||
KOREAN_DIGITAL = "koreanDigital",
|
CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified",
|
||||||
KOREAN_COUNTING = "koreanCounting",
|
CHINESE_COUNTING_THOUSAND: "chineseCountingThousand",
|
||||||
KOREAN_LEGAL = "koreanLegal",
|
KOREAN_DIGITAL: "koreanDigital",
|
||||||
KOREAN_DIGITAL2 = "koreanDigital2",
|
KOREAN_COUNTING: "koreanCounting",
|
||||||
VIETNAMESE_COUNTING = "vietnameseCounting",
|
KOREAN_LEGAL: "koreanLegal",
|
||||||
RUSSIAN_LOWER = "russianLower",
|
KOREAN_DIGITAL2: "koreanDigital2",
|
||||||
RUSSIAN_UPPER = "russianUpper",
|
VIETNAMESE_COUNTING: "vietnameseCounting",
|
||||||
NONE = "none",
|
RUSSIAN_LOWER: "russianLower",
|
||||||
NUMBER_IN_DASH = "numberInDash",
|
RUSSIAN_UPPER: "russianUpper",
|
||||||
HEBREW1 = "hebrew1",
|
NONE: "none",
|
||||||
HEBREW2 = "hebrew2",
|
NUMBER_IN_DASH: "numberInDash",
|
||||||
ARABIC_ALPHA = "arabicAlpha",
|
HEBREW1: "hebrew1",
|
||||||
ARABIC_ABJAD = "arabicAbjad",
|
HEBREW2: "hebrew2",
|
||||||
HINDI_VOWELS = "hindiVowels",
|
ARABIC_ALPHA: "arabicAlpha",
|
||||||
HINDI_CONSONANTS = "hindiConsonants",
|
ARABIC_ABJAD: "arabicAbjad",
|
||||||
HINDI_NUMBERS = "hindiNumbers",
|
HINDI_VOWELS: "hindiVowels",
|
||||||
HINDI_COUNTING = "hindiCounting",
|
HINDI_CONSONANTS: "hindiConsonants",
|
||||||
THAI_LETTERS = "thaiLetters",
|
HINDI_NUMBERS: "hindiNumbers",
|
||||||
THAI_NUMBERS = "thaiNumbers",
|
HINDI_COUNTING: "hindiCounting",
|
||||||
THAI_COUNTING = "thaiCounting",
|
THAI_LETTERS: "thaiLetters",
|
||||||
BAHT_TEXT = "bahtText",
|
THAI_NUMBERS: "thaiNumbers",
|
||||||
DOLLAR_TEXT = "dollarText",
|
THAI_COUNTING: "thaiCounting",
|
||||||
CUSTOM = "custom",
|
BAHT_TEXT: "bahtText",
|
||||||
}
|
DOLLAR_TEXT: "dollarText",
|
||||||
|
CUSTOM: "custom",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
class LevelAttributes extends XmlAttributeComponent<{
|
class LevelAttributes extends XmlAttributeComponent<{
|
||||||
readonly ilvl?: number;
|
readonly ilvl?: number;
|
||||||
@ -182,7 +186,7 @@ class LevelText extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LevelJc extends XmlComponent {
|
class LevelJc extends XmlComponent {
|
||||||
public constructor(value: AlignmentType) {
|
public constructor(value: (typeof AlignmentType)[keyof typeof AlignmentType]) {
|
||||||
super("w:lvlJc");
|
super("w:lvlJc");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
@ -192,19 +196,19 @@ class LevelJc extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum LevelSuffix {
|
export const LevelSuffix = {
|
||||||
NOTHING = "nothing",
|
NOTHING: "nothing",
|
||||||
SPACE = "space",
|
SPACE: "space",
|
||||||
TAB = "tab",
|
TAB: "tab",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export interface ILevelsOptions {
|
export interface ILevelsOptions {
|
||||||
readonly level: number;
|
readonly level: number;
|
||||||
readonly format?: LevelFormat;
|
readonly format?: (typeof LevelFormat)[keyof typeof LevelFormat];
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
readonly alignment?: AlignmentType;
|
readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
|
||||||
readonly start?: number;
|
readonly start?: number;
|
||||||
readonly suffix?: LevelSuffix;
|
readonly suffix?: (typeof LevelSuffix)[keyof typeof LevelSuffix];
|
||||||
readonly isLegalNumberingStyle?: boolean;
|
readonly isLegalNumberingStyle?: boolean;
|
||||||
readonly style?: {
|
readonly style?: {
|
||||||
readonly run?: IRunStylePropertiesOptions;
|
readonly run?: IRunStylePropertiesOptions;
|
||||||
@ -223,7 +227,7 @@ export interface ILevelsOptions {
|
|||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
class Suffix extends XmlComponent {
|
class Suffix extends XmlComponent {
|
||||||
public constructor(value: LevelSuffix) {
|
public constructor(value: (typeof LevelSuffix)[keyof typeof LevelSuffix]) {
|
||||||
super("w:suff");
|
super("w:suff");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
|
@ -216,7 +216,7 @@ export class Numbering extends XmlComponent {
|
|||||||
abstractNumId: abstractNumbering.id,
|
abstractNumId: abstractNumbering.id,
|
||||||
reference,
|
reference,
|
||||||
instance,
|
instance,
|
||||||
overrideLevel:
|
overrideLevels: [
|
||||||
firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)
|
firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)
|
||||||
? {
|
? {
|
||||||
num: 0,
|
num: 0,
|
||||||
@ -226,6 +226,7 @@ export class Numbering extends XmlComponent {
|
|||||||
num: 0,
|
num: 0,
|
||||||
start: 1,
|
start: 1,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings));
|
this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings));
|
||||||
|
@ -19,41 +19,47 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
// <xsd:enumeration value="right"/>
|
// <xsd:enumeration value="right"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum AlignmentType {
|
|
||||||
/** Align Start */
|
|
||||||
START = "start",
|
|
||||||
/** Align Center */
|
|
||||||
CENTER = "center",
|
|
||||||
/** End */
|
|
||||||
END = "end",
|
|
||||||
/** Justified */
|
|
||||||
BOTH = "both",
|
|
||||||
/** Medium Kashida Length */
|
|
||||||
MEDIUM_KASHIDA = "mediumKashida",
|
|
||||||
/** Distribute All Characters Equally */
|
|
||||||
DISTRIBUTE = "distribute",
|
|
||||||
/** Align to List Tab */
|
|
||||||
NUM_TAB = "numTab",
|
|
||||||
/** Widest Kashida Length */
|
|
||||||
HIGH_KASHIDA = "highKashida",
|
|
||||||
/** Low Kashida Length */
|
|
||||||
LOW_KASHIDA = "lowKashida",
|
|
||||||
/** Thai Language Justification */
|
|
||||||
THAI_DISTRIBUTE = "thaiDistribute",
|
|
||||||
/** Align Left */
|
|
||||||
LEFT = "left",
|
|
||||||
/** Align Right */
|
|
||||||
RIGHT = "right",
|
|
||||||
/** Justified */
|
|
||||||
JUSTIFIED = "both",
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
export const AlignmentType = {
|
||||||
|
/** Align Start */
|
||||||
|
START: "start",
|
||||||
|
/** Align Center */
|
||||||
|
CENTER: "center",
|
||||||
|
/** End */
|
||||||
|
END: "end",
|
||||||
|
/** Justified */
|
||||||
|
BOTH: "both",
|
||||||
|
/** Medium Kashida Length */
|
||||||
|
MEDIUM_KASHIDA: "mediumKashida",
|
||||||
|
/** Distribute All Characters Equally */
|
||||||
|
DISTRIBUTE: "distribute",
|
||||||
|
/** Align to List Tab */
|
||||||
|
NUM_TAB: "numTab",
|
||||||
|
/** Widest Kashida Length */
|
||||||
|
HIGH_KASHIDA: "highKashida",
|
||||||
|
/** Low Kashida Length */
|
||||||
|
LOW_KASHIDA: "lowKashida",
|
||||||
|
/** Thai Language Justification */
|
||||||
|
THAI_DISTRIBUTE: "thaiDistribute",
|
||||||
|
/** Align Left */
|
||||||
|
LEFT: "left",
|
||||||
|
/** Align Right */
|
||||||
|
RIGHT: "right",
|
||||||
|
/** Justified */
|
||||||
|
JUSTIFIED: "both",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
|
export class AlignmentAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly val: (typeof AlignmentType)[keyof typeof AlignmentType];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Alignment extends XmlComponent {
|
export class Alignment extends XmlComponent {
|
||||||
public constructor(type: AlignmentType) {
|
public constructor(type: (typeof AlignmentType)[keyof typeof AlignmentType]) {
|
||||||
super("w:jc");
|
super("w:jc");
|
||||||
this.root.push(new AlignmentAttributes({ val: type }));
|
this.root.push(new AlignmentAttributes({ val: type }));
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||||
import { Run } from "../run";
|
import { Run } from "../run";
|
||||||
|
|
||||||
enum BreakType {
|
const BreakType = {
|
||||||
COLUMN = "column",
|
COLUMN: "column",
|
||||||
PAGE = "page",
|
PAGE: "page",
|
||||||
// textWrapping breaks are the default and already exposed via the "Run" class
|
// textWrapping breaks are the default and already exposed via the "Run" class
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
class Break extends XmlComponent {
|
class Break extends XmlComponent {
|
||||||
public constructor(type: BreakType) {
|
public constructor(type: (typeof BreakType)[keyof typeof BreakType]) {
|
||||||
super("w:br");
|
super("w:br");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
// http://officeopenxml.com/WPspacing.php
|
// http://officeopenxml.com/WPspacing.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export enum LineRuleType {
|
export const LineRuleType = {
|
||||||
AT_LEAST = "atLeast",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
EXACTLY = "exactly",
|
AT_LEAST: "atLeast",
|
||||||
EXACT = "exact",
|
EXACTLY: "exactly",
|
||||||
AUTO = "auto",
|
EXACT: "exact",
|
||||||
}
|
AUTO: "auto",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export interface ISpacingProperties {
|
export interface ISpacingProperties {
|
||||||
readonly after?: number;
|
readonly after?: number;
|
||||||
readonly before?: number;
|
readonly before?: number;
|
||||||
readonly line?: number;
|
readonly line?: number;
|
||||||
readonly lineRule?: LineRuleType;
|
readonly lineRule?: (typeof LineRuleType)[keyof typeof LineRuleType];
|
||||||
readonly beforeAutoSpacing?: boolean;
|
readonly beforeAutoSpacing?: boolean;
|
||||||
readonly afterAutoSpacing?: boolean;
|
readonly afterAutoSpacing?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export enum HeadingLevel {
|
export const HeadingLevel = {
|
||||||
HEADING_1 = "Heading1",
|
HEADING_1: "Heading1",
|
||||||
HEADING_2 = "Heading2",
|
HEADING_2: "Heading2",
|
||||||
HEADING_3 = "Heading3",
|
HEADING_3: "Heading3",
|
||||||
HEADING_4 = "Heading4",
|
HEADING_4: "Heading4",
|
||||||
HEADING_5 = "Heading5",
|
HEADING_5: "Heading5",
|
||||||
HEADING_6 = "Heading6",
|
HEADING_6: "Heading6",
|
||||||
TITLE = "Title",
|
TITLE: "Title",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class Style extends XmlComponent {
|
export class Style extends XmlComponent {
|
||||||
public constructor(styleId: string) {
|
public constructor(styleId: string) {
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export interface TabStopDefinition {
|
export interface TabStopDefinition {
|
||||||
readonly type: TabStopType;
|
readonly type: (typeof TabStopType)[keyof typeof TabStopType];
|
||||||
readonly position: number | TabStopPosition;
|
readonly position: number | (typeof TabStopPosition)[keyof typeof TabStopPosition];
|
||||||
readonly leader?: LeaderType;
|
readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TabStop extends XmlComponent {
|
export class TabStop extends XmlComponent {
|
||||||
@ -17,34 +17,35 @@ export class TabStop extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TabStopType {
|
export const TabStopType = {
|
||||||
LEFT = "left",
|
LEFT: "left",
|
||||||
RIGHT = "right",
|
RIGHT: "right",
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
BAR = "bar",
|
BAR: "bar",
|
||||||
CLEAR = "clear",
|
CLEAR: "clear",
|
||||||
DECIMAL = "decimal",
|
DECIMAL: "decimal",
|
||||||
END = "end",
|
END: "end",
|
||||||
NUM = "num",
|
NUM: "num",
|
||||||
START = "start",
|
START: "start",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum LeaderType {
|
export const LeaderType = {
|
||||||
DOT = "dot",
|
DOT: "dot",
|
||||||
HYPHEN = "hyphen",
|
HYPHEN: "hyphen",
|
||||||
MIDDLE_DOT = "middleDot",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
NONE = "none",
|
MIDDLE_DOT: "middleDot",
|
||||||
UNDERSCORE = "underscore",
|
NONE: "none",
|
||||||
}
|
UNDERSCORE: "underscore",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export enum TabStopPosition {
|
export const TabStopPosition = {
|
||||||
MAX = 9026,
|
MAX: 9026,
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class TabAttributes extends XmlAttributeComponent<{
|
export class TabAttributes extends XmlAttributeComponent<{
|
||||||
readonly val: TabStopType;
|
readonly val: (typeof TabStopType)[keyof typeof TabStopType];
|
||||||
readonly pos: string | number;
|
readonly pos: string | number;
|
||||||
readonly leader?: LeaderType;
|
readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
|
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
|
||||||
}
|
}
|
||||||
|
@ -3,43 +3,44 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
|
|||||||
import { HeightRule } from "@file/table";
|
import { HeightRule } from "@file/table";
|
||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export enum DropCapType {
|
export const DropCapType = {
|
||||||
NONE = "none",
|
NONE: "none",
|
||||||
DROP = "drop",
|
DROP: "drop",
|
||||||
MARGIN = "margin",
|
MARGIN: "margin",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum FrameAnchorType {
|
export const FrameAnchorType = {
|
||||||
MARGIN = "margin",
|
MARGIN: "margin",
|
||||||
PAGE = "page",
|
PAGE: "page",
|
||||||
TEXT = "text",
|
TEXT: "text",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum FrameWrap {
|
export const FrameWrap = {
|
||||||
AROUND = "around",
|
AROUND: "around",
|
||||||
AUTO = "auto",
|
AUTO: "auto",
|
||||||
NONE = "none",
|
NONE: "none",
|
||||||
NOT_BESIDE = "notBeside",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
THROUGH = "through",
|
NOT_BESIDE: "notBeside",
|
||||||
TIGHT = "tight",
|
THROUGH: "through",
|
||||||
}
|
TIGHT: "tight",
|
||||||
|
} as const;
|
||||||
|
|
||||||
interface IBaseFrameOptions {
|
interface IBaseFrameOptions {
|
||||||
readonly anchorLock?: boolean;
|
readonly anchorLock?: boolean;
|
||||||
readonly dropCap?: DropCapType;
|
readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
readonly wrap?: FrameWrap;
|
readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap];
|
||||||
readonly lines?: number;
|
readonly lines?: number;
|
||||||
readonly anchor: {
|
readonly anchor: {
|
||||||
readonly horizontal: FrameAnchorType;
|
readonly horizontal: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
|
||||||
readonly vertical: FrameAnchorType;
|
readonly vertical: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
|
||||||
};
|
};
|
||||||
readonly space?: {
|
readonly space?: {
|
||||||
readonly horizontal: number;
|
readonly horizontal: number;
|
||||||
readonly vertical: number;
|
readonly vertical: number;
|
||||||
};
|
};
|
||||||
readonly rule?: HeightRule;
|
readonly rule?: (typeof HeightRule)[keyof typeof HeightRule];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IXYFrameOptions extends IBaseFrameOptions {
|
export interface IXYFrameOptions extends IBaseFrameOptions {
|
||||||
@ -51,8 +52,8 @@ export interface IXYFrameOptions extends IBaseFrameOptions {
|
|||||||
|
|
||||||
export interface IAlignmentFrameOptions extends IBaseFrameOptions {
|
export interface IAlignmentFrameOptions extends IBaseFrameOptions {
|
||||||
readonly alignment: {
|
readonly alignment: {
|
||||||
readonly x: HorizontalPositionAlign;
|
readonly x: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
|
||||||
readonly y: VerticalPositionAlign;
|
readonly y: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,20 +63,20 @@ export type IFrameOptions = IXYFrameOptions | IAlignmentFrameOptions;
|
|||||||
|
|
||||||
export class FramePropertiesAttributes extends XmlAttributeComponent<{
|
export class FramePropertiesAttributes extends XmlAttributeComponent<{
|
||||||
readonly anchorLock?: boolean;
|
readonly anchorLock?: boolean;
|
||||||
readonly dropCap?: DropCapType;
|
readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType];
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
readonly x?: number;
|
readonly x?: number;
|
||||||
readonly y?: number;
|
readonly y?: number;
|
||||||
readonly wrap?: FrameWrap;
|
readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap];
|
||||||
readonly lines?: number;
|
readonly lines?: number;
|
||||||
readonly anchorHorizontal?: FrameAnchorType;
|
readonly anchorHorizontal?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
|
||||||
readonly anchorVertical?: FrameAnchorType;
|
readonly anchorVertical?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType];
|
||||||
readonly spaceHorizontal?: number;
|
readonly spaceHorizontal?: number;
|
||||||
readonly spaceVertical?: number;
|
readonly spaceVertical?: number;
|
||||||
readonly rule?: HeightRule;
|
readonly rule?: (typeof HeightRule)[keyof typeof HeightRule];
|
||||||
readonly alignmentX?: HorizontalPositionAlign;
|
readonly alignmentX?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
|
||||||
readonly alignmentY?: VerticalPositionAlign;
|
readonly alignmentY?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
|
||||||
}> {
|
}> {
|
||||||
protected readonly xmlKeys = {
|
protected readonly xmlKeys = {
|
||||||
anchorLock: "w:anchorLock",
|
anchorLock: "w:anchorLock",
|
||||||
|
@ -5,10 +5,10 @@ import { uniqueId } from "@util/convenience-functions";
|
|||||||
import { ParagraphChild } from "../paragraph";
|
import { ParagraphChild } from "../paragraph";
|
||||||
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
||||||
|
|
||||||
export enum HyperlinkType {
|
export const HyperlinkType = {
|
||||||
INTERNAL = "INTERNAL",
|
INTERNAL: "INTERNAL",
|
||||||
EXTERNAL = "EXTERNAL",
|
EXTERNAL: "EXTERNAL",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class ConcreteHyperlink extends XmlComponent {
|
export class ConcreteHyperlink extends XmlComponent {
|
||||||
public readonly linkId: string;
|
public readonly linkId: string;
|
||||||
@ -39,7 +39,12 @@ export class InternalHyperlink extends ConcreteHyperlink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ExternalHyperlink extends XmlComponent {
|
export class ExternalHyperlink extends XmlComponent {
|
||||||
public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) {
|
public constructor(
|
||||||
|
public readonly options: {
|
||||||
|
readonly children: readonly ParagraphChild[];
|
||||||
|
readonly link: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
super("w:externalHyperlink");
|
super("w:externalHyperlink");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { SpaceType } from "@file/shared";
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { TextAttributes } from "../run/text-attributes";
|
import { TextAttributes } from "../run/text-attributes";
|
||||||
import { IPageReferenceOptions } from "./pageref-properties";
|
import { IPageReferenceOptions } from "./pageref";
|
||||||
|
|
||||||
export class PageReferenceFieldInstruction extends XmlComponent {
|
export class PageReferenceFieldInstruction extends XmlComponent {
|
||||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
|
||||||
|
|
||||||
export interface IPageReferenceOptions {
|
|
||||||
/**
|
|
||||||
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
|
||||||
*/
|
|
||||||
readonly hyperlink?: boolean;
|
|
||||||
/**
|
|
||||||
* \p option - Causes the field to display its position relative to the source
|
|
||||||
* bookmark. If the PAGEREF field is on the same page as the
|
|
||||||
* bookmark, it omits "on page #" and returns "above" or "below"
|
|
||||||
* only. If the PAGEREF field is not on the same page as the
|
|
||||||
* bookmark, the string "on page #" is used.
|
|
||||||
*/
|
|
||||||
readonly useRelativePosition?: boolean;
|
|
||||||
}
|
|
@ -2,7 +2,22 @@
|
|||||||
import { Begin, End } from "@file/paragraph/run/field";
|
import { Begin, End } from "@file/paragraph/run/field";
|
||||||
import { Run } from "../run";
|
import { Run } from "../run";
|
||||||
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
||||||
import type { IPageReferenceOptions } from "./pageref-properties";
|
|
||||||
|
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
||||||
|
export type IPageReferenceOptions = {
|
||||||
|
/**
|
||||||
|
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
||||||
|
*/
|
||||||
|
readonly hyperlink?: boolean;
|
||||||
|
/**
|
||||||
|
* \p option - Causes the field to display its position relative to the source
|
||||||
|
* bookmark. If the PAGEREF field is on the same page as the
|
||||||
|
* bookmark, it omits "on page #" and returns "above" or "below"
|
||||||
|
* only. If the PAGEREF field is not on the same page as the
|
||||||
|
* bookmark, the string "on page #" is used.
|
||||||
|
*/
|
||||||
|
readonly useRelativePosition?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export class PageReference extends Run {
|
export class PageReference extends Run {
|
||||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
|
@ -158,5 +158,52 @@ describe("ParagraphProperties", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should create with the overflowPunct property", () => {
|
||||||
|
const properties = new ParagraphProperties({
|
||||||
|
overflowPunctuation: true,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pPr": [
|
||||||
|
{
|
||||||
|
"w:overflowPunct": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create with the run property", () => {
|
||||||
|
const properties = new ParagraphProperties({
|
||||||
|
run: {
|
||||||
|
size: "10pt",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(properties);
|
||||||
|
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:pPr": [
|
||||||
|
{
|
||||||
|
"w:rPr": [
|
||||||
|
{
|
||||||
|
"w:sz": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "10pt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"w:szCs": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": "10pt",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// http://officeopenxml.com/WPparagraphProperties.php
|
// http://officeopenxml.com/WPparagraphProperties.php
|
||||||
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_suppressLineNumbers_topic_ID0ECJAO.html
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_suppressLineNumbers_topic_ID0ECJAO.html
|
||||||
|
/* eslint-disable functional/immutable-data */
|
||||||
import { IContext, IgnoreIfEmptyXmlComponent, IXmlableObject, OnOffElement, XmlComponent } from "@file/xml-components";
|
import { IContext, IgnoreIfEmptyXmlComponent, IXmlableObject, OnOffElement, XmlComponent } from "@file/xml-components";
|
||||||
import { DocumentWrapper } from "../document-wrapper";
|
import { DocumentWrapper } from "../document-wrapper";
|
||||||
import { IShadingAttributesProperties, Shading } from "../shading";
|
import { IShadingAttributesProperties, Shading } from "../shading";
|
||||||
@ -14,9 +15,10 @@ import { NumberProperties } from "./formatting/unordered-list";
|
|||||||
import { WordWrap } from "./formatting/word-wrap";
|
import { WordWrap } from "./formatting/word-wrap";
|
||||||
import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
|
import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
|
||||||
import { OutlineLevel } from "./links";
|
import { OutlineLevel } from "./links";
|
||||||
|
import { IRunOptions, RunProperties } from ".";
|
||||||
|
|
||||||
export interface ILevelParagraphStylePropertiesOptions {
|
export interface ILevelParagraphStylePropertiesOptions {
|
||||||
readonly alignment?: AlignmentType;
|
readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
|
||||||
readonly thematicBreak?: boolean;
|
readonly thematicBreak?: boolean;
|
||||||
readonly contextualSpacing?: boolean;
|
readonly contextualSpacing?: boolean;
|
||||||
readonly rightTabStop?: number;
|
readonly rightTabStop?: number;
|
||||||
@ -45,7 +47,7 @@ export interface IParagraphStylePropertiesOptions extends ILevelParagraphStylePr
|
|||||||
|
|
||||||
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
|
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
|
||||||
readonly border?: IBordersOptions;
|
readonly border?: IBordersOptions;
|
||||||
readonly heading?: HeadingLevel;
|
readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel];
|
||||||
readonly bidirectional?: boolean;
|
readonly bidirectional?: boolean;
|
||||||
readonly pageBreakBefore?: boolean;
|
readonly pageBreakBefore?: boolean;
|
||||||
readonly tabStops?: readonly TabStopDefinition[];
|
readonly tabStops?: readonly TabStopDefinition[];
|
||||||
@ -58,12 +60,17 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
|||||||
readonly frame?: IFrameOptions;
|
readonly frame?: IFrameOptions;
|
||||||
readonly suppressLineNumbers?: boolean;
|
readonly suppressLineNumbers?: boolean;
|
||||||
readonly wordWrap?: boolean;
|
readonly wordWrap?: boolean;
|
||||||
|
readonly overflowPunctuation?: boolean;
|
||||||
readonly scale?: number;
|
readonly scale?: number;
|
||||||
/**
|
/**
|
||||||
* This element specifies whether inter-character spacing shall automatically be adjusted between regions of numbers and regions of East Asian text in the current paragraph. These regions shall be determined by the Unicode character values of the text content within the paragraph.
|
* This element specifies whether inter-character spacing shall automatically be adjusted between regions of numbers and regions of East Asian text in the current paragraph. These regions shall be determined by the Unicode character values of the text content within the paragraph.
|
||||||
* This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard.
|
* This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard.
|
||||||
*/
|
*/
|
||||||
readonly autoSpaceEastAsianText?: boolean;
|
readonly autoSpaceEastAsianText?: boolean;
|
||||||
|
/**
|
||||||
|
* Reference: ECMA-376, 3rd Edition (June, 2011), Fundamentals and Markup Language Reference § 17.3.1.29.
|
||||||
|
*/
|
||||||
|
readonly run?: IRunOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
@ -146,14 +153,18 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
this.push(new WordWrap());
|
this.push(new WordWrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.overflowPunctuation) {
|
||||||
|
this.push(new OnOffElement("w:overflowPunct", options.overflowPunctuation));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIX: Multitab support for Libre Writer
|
* FIX: Multitab support for Libre Writer
|
||||||
* Ensure there is only one w:tabs tag with multiple w:tab
|
* Ensure there is only one w:tabs tag with multiple w:tab
|
||||||
*/
|
*/
|
||||||
const tabDefinitions: readonly TabStopDefinition[] = [
|
const tabDefinitions: readonly TabStopDefinition[] = [
|
||||||
...(options.rightTabStop ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
...(options.rightTabStop !== undefined ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
||||||
...(options.tabStops ? options.tabStops : []),
|
...(options.tabStops ? options.tabStops : []),
|
||||||
...(options.leftTabStop ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
...(options.leftTabStop !== undefined ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (tabDefinitions.length > 0) {
|
if (tabDefinitions.length > 0) {
|
||||||
@ -194,6 +205,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
if (options.autoSpaceEastAsianText !== undefined) {
|
if (options.autoSpaceEastAsianText !== undefined) {
|
||||||
this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText));
|
this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.run) {
|
||||||
|
this.push(new RunProperties(options.run));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(item: XmlComponent): void {
|
public push(item: XmlComponent): void {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export enum EmphasisMarkType {
|
export const EmphasisMarkType = {
|
||||||
DOT = "dot",
|
DOT: "dot",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export abstract class BaseEmphasisMark extends XmlComponent {
|
export abstract class BaseEmphasisMark extends XmlComponent {
|
||||||
protected constructor(emphasisMarkType: EmphasisMarkType) {
|
protected constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType]) {
|
||||||
super("w:em");
|
super("w:em");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
@ -16,7 +16,7 @@ export abstract class BaseEmphasisMark extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EmphasisMark extends BaseEmphasisMark {
|
export class EmphasisMark extends BaseEmphasisMark {
|
||||||
public constructor(emphasisMarkType: EmphasisMarkType = EmphasisMarkType.DOT) {
|
public constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType] = EmphasisMarkType.DOT) {
|
||||||
super(emphasisMarkType);
|
super(emphasisMarkType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
enum FieldCharacterType {
|
const FieldCharacterType = {
|
||||||
BEGIN = "begin",
|
BEGIN: "begin",
|
||||||
END = "end",
|
END: "end",
|
||||||
SEPARATE = "separate",
|
SEPARATE: "separate",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> {
|
class FidCharAttrs extends XmlAttributeComponent<{
|
||||||
|
readonly type: (typeof FieldCharacterType)[keyof typeof FieldCharacterType];
|
||||||
|
readonly dirty?: boolean;
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { uniqueId } from "@util/convenience-functions";
|
|||||||
import { IContext, IXmlableObject } from "@file/xml-components";
|
import { IContext, IXmlableObject } from "@file/xml-components";
|
||||||
import { DocPropertiesOptions } from "@file/drawing/doc-properties/doc-properties";
|
import { DocPropertiesOptions } from "@file/drawing/doc-properties/doc-properties";
|
||||||
|
|
||||||
|
import { OutlineOptions } from "../../drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||||
import { Drawing, IFloating } from "../../drawing";
|
import { Drawing, IFloating } from "../../drawing";
|
||||||
import { IMediaTransformation } from "../../media";
|
import { IMediaTransformation } from "../../media";
|
||||||
import { IMediaData } from "../../media/data";
|
import { IMediaData } from "../../media/data";
|
||||||
@ -13,6 +14,7 @@ export interface IImageOptions {
|
|||||||
readonly transformation: IMediaTransformation;
|
readonly transformation: IMediaTransformation;
|
||||||
readonly floating?: IFloating;
|
readonly floating?: IFloating;
|
||||||
readonly altText?: DocPropertiesOptions;
|
readonly altText?: DocPropertiesOptions;
|
||||||
|
readonly outline?: OutlineOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImageRun extends Run {
|
export class ImageRun extends Run {
|
||||||
@ -39,7 +41,11 @@ export class ImageRun extends Run {
|
|||||||
rotation: options.transformation.rotation ? options.transformation.rotation * 60000 : undefined,
|
rotation: options.transformation.rotation ? options.transformation.rotation * 60000 : undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const drawing = new Drawing(this.imageData, { floating: options.floating, docProperties: options.altText });
|
const drawing = new Drawing(this.imageData, {
|
||||||
|
floating: options.floating,
|
||||||
|
docProperties: options.altText,
|
||||||
|
outline: options.outline,
|
||||||
|
});
|
||||||
|
|
||||||
this.root.push(drawing);
|
this.root.push(drawing);
|
||||||
}
|
}
|
||||||
@ -65,6 +71,8 @@ export class ImageRun extends Run {
|
|||||||
.map((c) => c.charCodeAt(0)),
|
.map((c) => c.charCodeAt(0)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
/* c8 ignore next 4 */
|
||||||
|
// Not possible to test this branch in NodeJS
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||||
const b = require("buf" + "fer");
|
const b = require("buf" + "fer");
|
||||||
return new b.Buffer(dataURI, "base64");
|
return new b.Buffer(dataURI, "base64");
|
||||||
|
@ -26,3 +26,11 @@ export class NumberOfPagesSection extends XmlComponent {
|
|||||||
this.root.push("SECTIONPAGES");
|
this.root.push("SECTIONPAGES");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class CurrentPageInSection extends XmlComponent {
|
||||||
|
public constructor() {
|
||||||
|
super("w:instrText");
|
||||||
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
|
this.root.push("SECTION");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,11 +7,11 @@ import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
// <xsd:enumeration value="right" />
|
// <xsd:enumeration value="right" />
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PositionalTabAlignment {
|
export const PositionalTabAlignment = {
|
||||||
LEFT = "left",
|
LEFT: "left",
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
RIGHT = "right",
|
RIGHT: "right",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PTabRelativeTo">
|
// <xsd:simpleType name="ST_PTabRelativeTo">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -19,10 +19,10 @@ export enum PositionalTabAlignment {
|
|||||||
// <xsd:enumeration value="indent" />
|
// <xsd:enumeration value="indent" />
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PositionalTabRelativeTo {
|
export const PositionalTabRelativeTo = {
|
||||||
MARGIN = "margin",
|
MARGIN: "margin",
|
||||||
INDENT = "indent",
|
INDENT: "indent",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_PTabLeader">
|
// <xsd:simpleType name="ST_PTabLeader">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -33,18 +33,19 @@ export enum PositionalTabRelativeTo {
|
|||||||
// <xsd:enumeration value="middleDot" />
|
// <xsd:enumeration value="middleDot" />
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum PositionalTabLeader {
|
export const PositionalTabLeader = {
|
||||||
NONE = "none",
|
NONE: "none",
|
||||||
DOT = "dot",
|
DOT: "dot",
|
||||||
HYPHEN = "hyphen",
|
HYPHEN: "hyphen",
|
||||||
UNDERSCORE = "underscore",
|
UNDERSCORE: "underscore",
|
||||||
MIDDLE_DOT = "middleDot",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
}
|
MIDDLE_DOT: "middleDot",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export interface PositionalTabOptions {
|
export interface PositionalTabOptions {
|
||||||
readonly alignment: PositionalTabAlignment;
|
readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment];
|
||||||
readonly relativeTo: PositionalTabRelativeTo;
|
readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo];
|
||||||
readonly leader: PositionalTabLeader;
|
readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader];
|
||||||
}
|
}
|
||||||
|
|
||||||
// <xsd:complexType name="CT_PTab">
|
// <xsd:complexType name="CT_PTab">
|
||||||
@ -58,9 +59,9 @@ export class PositionalTab extends XmlComponent {
|
|||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new NextAttributeComponent<{
|
new NextAttributeComponent<{
|
||||||
readonly alignment: PositionalTabAlignment;
|
readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment];
|
||||||
readonly relativeTo: PositionalTabRelativeTo;
|
readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo];
|
||||||
readonly leader: PositionalTabLeader;
|
readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader];
|
||||||
}>({
|
}>({
|
||||||
alignment: {
|
alignment: {
|
||||||
key: "w:alignment",
|
key: "w:alignment",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// https://www.ecma-international.org/wp-content/uploads/ECMA-376-1_5th_edition_december_2016.zip page 297, section 17.3.2.21
|
// https://www.ecma-international.org/wp-content/uploads/ECMA-376-1_5th_edition_december_2016.zip page 297, section 17.3.2.21
|
||||||
|
/* eslint-disable functional/immutable-data */
|
||||||
import { BorderElement, IBorderOptions } from "@file/border";
|
import { BorderElement, IBorderOptions } from "@file/border";
|
||||||
import { IShadingAttributesProperties, Shading } from "@file/shading";
|
import { IShadingAttributesProperties, Shading } from "@file/shading";
|
||||||
import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision";
|
import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision";
|
||||||
@ -24,15 +25,18 @@ interface IFontOptions {
|
|||||||
readonly hint?: string;
|
readonly hint?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TextEffect {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
BLINK_BACKGROUND = "blinkBackground",
|
export const TextEffect = {
|
||||||
LIGHTS = "lights",
|
BLINK_BACKGROUND: "blinkBackground",
|
||||||
ANTS_BLACK = "antsBlack",
|
LIGHTS: "lights",
|
||||||
ANTS_RED = "antsRed",
|
ANTS_BLACK: "antsBlack",
|
||||||
SHIMMER = "shimmer",
|
ANTS_RED: "antsRed",
|
||||||
SPARKLE = "sparkle",
|
SHIMMER: "shimmer",
|
||||||
NONE = "none",
|
SPARKLE: "sparkle",
|
||||||
}
|
NONE: "none",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
export interface IRunStylePropertiesOptions {
|
export interface IRunStylePropertiesOptions {
|
||||||
readonly noProof?: boolean;
|
readonly noProof?: boolean;
|
||||||
@ -42,11 +46,11 @@ export interface IRunStylePropertiesOptions {
|
|||||||
readonly italicsComplexScript?: boolean;
|
readonly italicsComplexScript?: boolean;
|
||||||
readonly underline?: {
|
readonly underline?: {
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly type?: UnderlineType;
|
readonly type?: (typeof UnderlineType)[keyof typeof UnderlineType];
|
||||||
};
|
};
|
||||||
readonly effect?: TextEffect;
|
readonly effect?: (typeof TextEffect)[keyof typeof TextEffect];
|
||||||
readonly emphasisMark?: {
|
readonly emphasisMark?: {
|
||||||
readonly type?: EmphasisMarkType;
|
readonly type?: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType];
|
||||||
};
|
};
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly kern?: number | PositiveUniversalMeasure;
|
readonly kern?: number | PositiveUniversalMeasure;
|
||||||
@ -126,6 +130,8 @@ export interface IRunPropertiesChangeOptions extends IRunPropertiesOptions, ICha
|
|||||||
// <xsd:element name="oMath" type="CT_OnOff"/>
|
// <xsd:element name="oMath" type="CT_OnOff"/>
|
||||||
// </xsd:choice>
|
// </xsd:choice>
|
||||||
// </xsd:group>
|
// </xsd:group>
|
||||||
|
/* eslint-disable functional/immutable-data */
|
||||||
|
|
||||||
export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
public constructor(options?: IRunPropertiesOptions) {
|
public constructor(options?: IRunPropertiesOptions) {
|
||||||
super("w:rPr");
|
super("w:rPr");
|
||||||
@ -260,7 +266,7 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
this.push(new BorderElement("w:bdr", options.border));
|
this.push(new BorderElement("w:bdr", options.border));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.snapToGrid) {
|
if (options.snapToGrid !== undefined) {
|
||||||
this.push(new OnOffElement("w:snapToGrid", options.snapToGrid));
|
this.push(new OnOffElement("w:snapToGrid", options.snapToGrid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +299,8 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
export class RunPropertiesChange extends XmlComponent {
|
export class RunPropertiesChange extends XmlComponent {
|
||||||
public constructor(options: IRunPropertiesChangeOptions) {
|
public constructor(options: IRunPropertiesChangeOptions) {
|
||||||
super("w:rPrChange");
|
super("w:rPrChange");
|
||||||
|
@ -12,7 +12,7 @@ import { TextAttributes } from "../text-attributes";
|
|||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
interface ITextOptions {
|
interface ITextOptions {
|
||||||
readonly space?: SpaceType;
|
readonly space?: (typeof SpaceType)[keyof typeof SpaceType];
|
||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,6 +432,23 @@ describe("Run", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#section", () => {
|
||||||
|
it("should set the run to the RTL mode", () => {
|
||||||
|
const run = new Run({
|
||||||
|
children: [PageNumber.CURRENT_SECTION],
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||||
|
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTION"] },
|
||||||
|
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||||
|
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#style", () => {
|
describe("#style", () => {
|
||||||
it("should set the style to the given styleId", () => {
|
it("should set the style to the given styleId", () => {
|
||||||
const run = new Run({
|
const run = new Run({
|
||||||
|
@ -6,7 +6,7 @@ import { FieldInstruction } from "@file/table-of-contents/field-instruction";
|
|||||||
|
|
||||||
import { Break } from "./break";
|
import { Break } from "./break";
|
||||||
import { Begin, End, Separate } from "./field";
|
import { Begin, End, Separate } from "./field";
|
||||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
import { NumberOfPages, NumberOfPagesSection, Page, CurrentPageInSection } 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 {
|
import {
|
||||||
@ -71,7 +71,7 @@ export interface IRunOptions extends IRunPropertiesOptions {
|
|||||||
| FieldInstruction
|
| FieldInstruction
|
||||||
| Separate
|
| Separate
|
||||||
| End
|
| End
|
||||||
| PageNumber
|
| (typeof PageNumber)[keyof typeof PageNumber]
|
||||||
| FootnoteReferenceRun
|
| FootnoteReferenceRun
|
||||||
| Break
|
| Break
|
||||||
| AnnotationReference
|
| AnnotationReference
|
||||||
@ -98,11 +98,15 @@ export interface IRunOptions extends IRunPropertiesOptions {
|
|||||||
readonly text?: string;
|
readonly text?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PageNumber {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
CURRENT = "CURRENT",
|
export const PageNumber = {
|
||||||
TOTAL_PAGES = "TOTAL_PAGES",
|
CURRENT: "CURRENT",
|
||||||
TOTAL_PAGES_IN_SECTION = "TOTAL_PAGES_IN_SECTION",
|
TOTAL_PAGES: "TOTAL_PAGES",
|
||||||
}
|
TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION",
|
||||||
|
CURRENT_SECTION: "SECTION",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
export class Run extends XmlComponent {
|
export class Run extends XmlComponent {
|
||||||
protected readonly properties: RunProperties;
|
protected readonly properties: RunProperties;
|
||||||
@ -140,6 +144,12 @@ export class Run extends XmlComponent {
|
|||||||
this.root.push(new Separate());
|
this.root.push(new Separate());
|
||||||
this.root.push(new End());
|
this.root.push(new End());
|
||||||
break;
|
break;
|
||||||
|
case PageNumber.CURRENT_SECTION:
|
||||||
|
this.root.push(new Begin());
|
||||||
|
this.root.push(new CurrentPageInSection());
|
||||||
|
this.root.push(new Separate());
|
||||||
|
this.root.push(new End());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
this.root.push(new Text(child));
|
this.root.push(new Text(child));
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { SpaceType } from "@file/shared";
|
import { SpaceType } from "@file/shared";
|
||||||
import { XmlAttributeComponent } from "@file/xml-components";
|
import { XmlAttributeComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
export class TextAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly space: (typeof SpaceType)[keyof typeof SpaceType];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { space: "xml:space" };
|
protected readonly xmlKeys = { space: "xml:space" };
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||||
import { hexColorValue } from "@util/values";
|
import { hexColorValue } from "@util/values";
|
||||||
|
|
||||||
export enum UnderlineType {
|
export const UnderlineType = {
|
||||||
SINGLE = "single",
|
SINGLE: "single",
|
||||||
WORDS = "words",
|
WORDS: "words",
|
||||||
DOUBLE = "double",
|
DOUBLE: "double",
|
||||||
THICK = "thick",
|
THICK: "thick",
|
||||||
DOTTED = "dotted",
|
DOTTED: "dotted",
|
||||||
DOTTEDHEAVY = "dottedHeavy",
|
DOTTEDHEAVY: "dottedHeavy",
|
||||||
DASH = "dash",
|
DASH: "dash",
|
||||||
DASHEDHEAVY = "dashedHeavy",
|
DASHEDHEAVY: "dashedHeavy",
|
||||||
DASHLONG = "dashLong",
|
DASHLONG: "dashLong",
|
||||||
DASHLONGHEAVY = "dashLongHeavy",
|
DASHLONGHEAVY: "dashLongHeavy",
|
||||||
DOTDASH = "dotDash",
|
DOTDASH: "dotDash",
|
||||||
DASHDOTHEAVY = "dashDotHeavy",
|
DASHDOTHEAVY: "dashDotHeavy",
|
||||||
DOTDOTDASH = "dotDotDash",
|
DOTDOTDASH: "dotDotDash",
|
||||||
DASHDOTDOTHEAVY = "dashDotDotHeavy",
|
DASHDOTDOTHEAVY: "dashDotDotHeavy",
|
||||||
WAVE = "wave",
|
WAVE: "wave",
|
||||||
WAVYHEAVY = "wavyHeavy",
|
WAVYHEAVY: "wavyHeavy",
|
||||||
WAVYDOUBLE = "wavyDouble",
|
WAVYDOUBLE: "wavyDouble",
|
||||||
NONE = "none",
|
NONE: "none",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class Underline extends XmlComponent {
|
export class Underline extends XmlComponent {
|
||||||
public constructor(underlineType: UnderlineType = UnderlineType.SINGLE, color?: string) {
|
public constructor(underlineType: (typeof UnderlineType)[keyof typeof UnderlineType] = UnderlineType.SINGLE, color?: string) {
|
||||||
super("w:u");
|
super("w:u");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Attributes({
|
new Attributes({
|
||||||
|
@ -19,12 +19,17 @@ export type RelationshipType =
|
|||||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
|
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
|
||||||
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
|
| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
|
||||||
|
|
||||||
export enum TargetModeType {
|
export const TargetModeType = {
|
||||||
EXTERNAL = "External",
|
EXTERNAL: "External",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export class Relationship extends XmlComponent {
|
export class Relationship extends XmlComponent {
|
||||||
public constructor(id: string, type: RelationshipType, target: string, targetMode?: TargetModeType) {
|
public constructor(
|
||||||
|
id: string,
|
||||||
|
type: RelationshipType,
|
||||||
|
target: string,
|
||||||
|
targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType],
|
||||||
|
) {
|
||||||
super("Relationship");
|
super("Relationship");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -12,7 +12,12 @@ export class Relationships extends XmlComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: TargetModeType): Relationship {
|
public createRelationship(
|
||||||
|
id: number | string,
|
||||||
|
type: RelationshipType,
|
||||||
|
target: string,
|
||||||
|
targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType],
|
||||||
|
): Relationship {
|
||||||
const relationship = new Relationship(`rId${id}`, type, target, targetMode);
|
const relationship = new Relationship(`rId${id}`, type, target, targetMode);
|
||||||
this.root.push(relationship);
|
this.root.push(relationship);
|
||||||
|
|
||||||
|
@ -112,6 +112,23 @@ describe("Settings", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should add defaultTabStop setting with version", () => {
|
||||||
|
const settings = new Settings({
|
||||||
|
defaultTabStop: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(settings);
|
||||||
|
expect(Object.keys(tree)).has.length(1);
|
||||||
|
expect(tree["w:settings"]).to.be.an("array");
|
||||||
|
expect(tree["w:settings"]).to.deep.include({
|
||||||
|
"w:defaultTabStop": {
|
||||||
|
_attr: {
|
||||||
|
"w:val": 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: Remove when deprecating compatibilityModeVersion
|
// TODO: Remove when deprecating compatibilityModeVersion
|
||||||
it("should add compatibility setting with legacy version", () => {
|
it("should add compatibility setting with legacy version", () => {
|
||||||
const settings = new Settings({
|
const settings = new Settings({
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { NumberValueElement, OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { Compatibility, ICompatibilityOptions } from "./compatibility";
|
import { Compatibility, ICompatibilityOptions } from "./compatibility";
|
||||||
|
|
||||||
@ -152,6 +152,7 @@ export interface ISettingsOptions {
|
|||||||
readonly trackRevisions?: boolean;
|
readonly trackRevisions?: boolean;
|
||||||
readonly updateFields?: boolean;
|
readonly updateFields?: boolean;
|
||||||
readonly compatibility?: ICompatibilityOptions;
|
readonly compatibility?: ICompatibilityOptions;
|
||||||
|
readonly defaultTabStop?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Settings extends XmlComponent {
|
export class Settings extends XmlComponent {
|
||||||
@ -198,6 +199,11 @@ export class Settings extends XmlComponent {
|
|||||||
this.root.push(new OnOffElement("w:updateFields", options.updateFields));
|
this.root.push(new OnOffElement("w:updateFields", options.updateFields));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_defaultTabStop_topic_ID0EIXSX.html
|
||||||
|
if (options.defaultTabStop !== undefined) {
|
||||||
|
this.root.push(new NumberValueElement("w:defaultTabStop", options.defaultTabStop));
|
||||||
|
}
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new Compatibility({
|
new Compatibility({
|
||||||
...(options.compatibility ?? {}),
|
...(options.compatibility ?? {}),
|
||||||
|
@ -23,7 +23,7 @@ import { hexColorValue } from "@util/values";
|
|||||||
export interface IShadingAttributesProperties {
|
export interface IShadingAttributesProperties {
|
||||||
readonly fill?: string;
|
readonly fill?: string;
|
||||||
readonly color?: string;
|
readonly color?: string;
|
||||||
readonly type?: ShadingType;
|
readonly type?: (typeof ShadingType)[keyof typeof ShadingType];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShadingAttributes extends XmlAttributeComponent<IShadingAttributesProperties> {
|
class ShadingAttributes extends XmlAttributeComponent<IShadingAttributesProperties> {
|
||||||
@ -47,42 +47,44 @@ export class Shading extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ShadingType {
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
CLEAR = "clear",
|
export const ShadingType = {
|
||||||
DIAGONAL_CROSS = "diagCross",
|
CLEAR: "clear",
|
||||||
DIAGONAL_STRIPE = "diagStripe",
|
DIAGONAL_CROSS: "diagCross",
|
||||||
HORIZONTAL_CROSS = "horzCross",
|
DIAGONAL_STRIPE: "diagStripe",
|
||||||
HORIZONTAL_STRIPE = "horzStripe",
|
HORIZONTAL_CROSS: "horzCross",
|
||||||
NIL = "nil",
|
HORIZONTAL_STRIPE: "horzStripe",
|
||||||
PERCENT_5 = "pct5",
|
NIL: "nil",
|
||||||
PERCENT_10 = "pct10",
|
PERCENT_5: "pct5",
|
||||||
PERCENT_12 = "pct12",
|
PERCENT_10: "pct10",
|
||||||
PERCENT_15 = "pct15",
|
PERCENT_12: "pct12",
|
||||||
PERCENT_20 = "pct20",
|
PERCENT_15: "pct15",
|
||||||
PERCENT_25 = "pct25",
|
PERCENT_20: "pct20",
|
||||||
PERCENT_30 = "pct30",
|
PERCENT_25: "pct25",
|
||||||
PERCENT_35 = "pct35",
|
PERCENT_30: "pct30",
|
||||||
PERCENT_37 = "pct37",
|
PERCENT_35: "pct35",
|
||||||
PERCENT_40 = "pct40",
|
PERCENT_37: "pct37",
|
||||||
PERCENT_45 = "pct45",
|
PERCENT_40: "pct40",
|
||||||
PERCENT_50 = "pct50",
|
PERCENT_45: "pct45",
|
||||||
PERCENT_55 = "pct55",
|
PERCENT_50: "pct50",
|
||||||
PERCENT_60 = "pct60",
|
PERCENT_55: "pct55",
|
||||||
PERCENT_62 = "pct62",
|
PERCENT_60: "pct60",
|
||||||
PERCENT_65 = "pct65",
|
PERCENT_62: "pct62",
|
||||||
PERCENT_70 = "pct70",
|
PERCENT_65: "pct65",
|
||||||
PERCENT_75 = "pct75",
|
PERCENT_70: "pct70",
|
||||||
PERCENT_80 = "pct80",
|
PERCENT_75: "pct75",
|
||||||
PERCENT_85 = "pct85",
|
PERCENT_80: "pct80",
|
||||||
PERCENT_87 = "pct87",
|
PERCENT_85: "pct85",
|
||||||
PERCENT_90 = "pct90",
|
PERCENT_87: "pct87",
|
||||||
PERCENT_95 = "pct95",
|
PERCENT_90: "pct90",
|
||||||
REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe",
|
PERCENT_95: "pct95",
|
||||||
SOLID = "solid",
|
REVERSE_DIAGONAL_STRIPE: "reverseDiagStripe",
|
||||||
THIN_DIAGONAL_CROSS = "thinDiagCross",
|
SOLID: "solid",
|
||||||
THIN_DIAGONAL_STRIPE = "thinDiagStripe",
|
THIN_DIAGONAL_CROSS: "thinDiagCross",
|
||||||
THIN_HORIZONTAL_CROSS = "thinHorzCross",
|
THIN_DIAGONAL_STRIPE: "thinDiagStripe",
|
||||||
THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe",
|
THIN_HORIZONTAL_CROSS: "thinHorzCross",
|
||||||
THIN_VERTICAL_STRIPE = "thinVertStripe",
|
THIN_REVERSE_DIAGONAL_STRIPE: "thinReverseDiagStripe",
|
||||||
VERTICAL_STRIPE = "vertStripe",
|
THIN_VERTICAL_STRIPE: "thinVertStripe",
|
||||||
}
|
VERTICAL_STRIPE: "vertStripe",
|
||||||
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
export enum HorizontalPositionAlign {
|
export const HorizontalPositionAlign = {
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
INSIDE = "inside",
|
INSIDE: "inside",
|
||||||
LEFT = "left",
|
LEFT: "left",
|
||||||
OUTSIDE = "outside",
|
OUTSIDE: "outside",
|
||||||
RIGHT = "right",
|
RIGHT: "right",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum VerticalPositionAlign {
|
export const VerticalPositionAlign = {
|
||||||
BOTTOM = "bottom",
|
BOTTOM: "bottom",
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
INSIDE = "inside",
|
INSIDE: "inside",
|
||||||
OUTSIDE = "outside",
|
OUTSIDE: "outside",
|
||||||
TOP = "top",
|
TOP: "top",
|
||||||
}
|
} as const;
|
||||||
|
@ -66,68 +66,70 @@
|
|||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
|
|
||||||
export enum NumberFormat {
|
/* eslint-disable @typescript-eslint/naming-convention*/
|
||||||
DECIMAL = "decimal",
|
export const NumberFormat = {
|
||||||
UPPER_ROMAN = "upperRoman",
|
DECIMAL: "decimal",
|
||||||
LOWER_ROMAN = "lowerRoman",
|
UPPER_ROMAN: "upperRoman",
|
||||||
UPPER_LETTER = "upperLetter",
|
LOWER_ROMAN: "lowerRoman",
|
||||||
LOWER_LETTER = "lowerLetter",
|
UPPER_LETTER: "upperLetter",
|
||||||
ORDINAL = "ordinal",
|
LOWER_LETTER: "lowerLetter",
|
||||||
CARDINAL_TEXT = "cardinalText",
|
ORDINAL: "ordinal",
|
||||||
ORDINAL_TEXT = "ordinalText",
|
CARDINAL_TEXT: "cardinalText",
|
||||||
HEX = "hex",
|
ORDINAL_TEXT: "ordinalText",
|
||||||
CHICAGO = "chicago",
|
HEX: "hex",
|
||||||
IDEOGRAPH_DIGITAL = "ideographDigital",
|
CHICAGO: "chicago",
|
||||||
JAPANESE_COUNTING = "japaneseCounting",
|
IDEOGRAPH_DIGITAL: "ideographDigital",
|
||||||
AIUEO = "aiueo",
|
JAPANESE_COUNTING: "japaneseCounting",
|
||||||
IROHA = "iroha",
|
AIUEO: "aiueo",
|
||||||
DECIMAL_FULL_WIDTH = "decimalFullWidth",
|
IROHA: "iroha",
|
||||||
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
|
DECIMAL_FULL_WIDTH: "decimalFullWidth",
|
||||||
JAPANESE_LEGAL = "japaneseLegal",
|
DECIMAL_HALF_WIDTH: "decimalHalfWidth",
|
||||||
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
|
JAPANESE_LEGAL: "japaneseLegal",
|
||||||
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand",
|
||||||
DECIMAL_FULL_WIDTH_2 = "decimalFullWidth2",
|
DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle",
|
||||||
AIUEO_FULL_WIDTH = "aiueoFullWidth",
|
DECIMAL_FULL_WIDTH_2: "decimalFullWidth2",
|
||||||
IROHA_FULL_WIDTH = "irohaFullWidth",
|
AIUEO_FULL_WIDTH: "aiueoFullWidth",
|
||||||
DECIMAL_ZERO = "decimalZero",
|
IROHA_FULL_WIDTH: "irohaFullWidth",
|
||||||
BULLET = "bullet",
|
DECIMAL_ZERO: "decimalZero",
|
||||||
GANADA = "ganada",
|
BULLET: "bullet",
|
||||||
CHOSUNG = "chosung",
|
GANADA: "ganada",
|
||||||
DECIMAL_ENCLOSED_FULL_STOP = "decimalEnclosedFullstop",
|
CHOSUNG: "chosung",
|
||||||
DECIMAL_ENCLOSED_PAREN = "decimalEnclosedParen",
|
DECIMAL_ENCLOSED_FULL_STOP: "decimalEnclosedFullstop",
|
||||||
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
|
DECIMAL_ENCLOSED_PAREN: "decimalEnclosedParen",
|
||||||
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
|
DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese",
|
||||||
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
|
IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle",
|
||||||
IDEOGRAPH_ZODIAC = "ideographZodiac",
|
IDEOGRAPH_TRADITIONAL: "ideographTraditional",
|
||||||
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
|
IDEOGRAPH_ZODIAC: "ideographZodiac",
|
||||||
TAIWANESE_COUNTING = "taiwaneseCounting",
|
IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional",
|
||||||
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
|
TAIWANESE_COUNTING: "taiwaneseCounting",
|
||||||
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
|
IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional",
|
||||||
TAIWANESE_DIGITAL = "taiwaneseDigital",
|
TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand",
|
||||||
CHINESE_COUNTING = "chineseCounting",
|
TAIWANESE_DIGITAL: "taiwaneseDigital",
|
||||||
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
|
CHINESE_COUNTING: "chineseCounting",
|
||||||
CHINESE_COUNTING_TEN_THOUSAND = "chineseCountingThousand",
|
CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified",
|
||||||
KOREAN_DIGITAL = "koreanDigital",
|
CHINESE_COUNTING_TEN_THOUSAND: "chineseCountingThousand",
|
||||||
KOREAN_COUNTING = "koreanCounting",
|
KOREAN_DIGITAL: "koreanDigital",
|
||||||
KOREAN_LEGAL = "koreanLegal",
|
KOREAN_COUNTING: "koreanCounting",
|
||||||
KOREAN_DIGITAL_2 = "koreanDigital2",
|
KOREAN_LEGAL: "koreanLegal",
|
||||||
VIETNAMESE_COUNTING = "vietnameseCounting",
|
KOREAN_DIGITAL_2: "koreanDigital2",
|
||||||
RUSSIAN_LOWER = "russianLower",
|
VIETNAMESE_COUNTING: "vietnameseCounting",
|
||||||
RUSSIAN_UPPER = "russianUpper",
|
RUSSIAN_LOWER: "russianLower",
|
||||||
NONE = "none",
|
RUSSIAN_UPPER: "russianUpper",
|
||||||
NUMBER_IN_DASH = "numberInDash",
|
NONE: "none",
|
||||||
HEBREW_1 = "hebrew1",
|
NUMBER_IN_DASH: "numberInDash",
|
||||||
HEBREW_2 = "hebrew2",
|
HEBREW_1: "hebrew1",
|
||||||
ARABIC_ALPHA = "arabicAlpha",
|
HEBREW_2: "hebrew2",
|
||||||
ARABIC_ABJAD = "arabicAbjad",
|
ARABIC_ALPHA: "arabicAlpha",
|
||||||
HINDI_VOWELS = "hindiVowels",
|
ARABIC_ABJAD: "arabicAbjad",
|
||||||
HINDI_CONSONANTS = "hindiConsonants",
|
HINDI_VOWELS: "hindiVowels",
|
||||||
HINDI_NUMBERS = "hindiNumbers",
|
HINDI_CONSONANTS: "hindiConsonants",
|
||||||
HINDI_COUNTING = "hindiCounting",
|
HINDI_NUMBERS: "hindiNumbers",
|
||||||
THAI_LETTERS = "thaiLetters",
|
HINDI_COUNTING: "hindiCounting",
|
||||||
THAI_NUMBERS = "thaiNumbers",
|
THAI_LETTERS: "thaiLetters",
|
||||||
THAI_COUNTING = "thaiCounting",
|
THAI_NUMBERS: "thaiNumbers",
|
||||||
BAHT_TEXT = "bahtText",
|
THAI_COUNTING: "thaiCounting",
|
||||||
DOLLAR_TEXT = "dollarText",
|
BAHT_TEXT: "bahtText",
|
||||||
|
DOLLAR_TEXT: "dollarText",
|
||||||
// <xsd:enumeration value="custom"/>
|
// <xsd:enumeration value="custom"/>
|
||||||
}
|
} as const;
|
||||||
|
/* eslint-enable */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export enum SpaceType {
|
export const SpaceType = {
|
||||||
DEFAULT = "default",
|
DEFAULT: "default",
|
||||||
PRESERVE = "preserve",
|
PRESERVE: "preserve",
|
||||||
}
|
} as const;
|
||||||
|
@ -80,18 +80,20 @@ export class GridSpan extends XmlComponent {
|
|||||||
/**
|
/**
|
||||||
* Vertical merge types.
|
* Vertical merge types.
|
||||||
*/
|
*/
|
||||||
export enum VerticalMergeType {
|
export const VerticalMergeType = {
|
||||||
/**
|
/**
|
||||||
* Cell that is merged with upper one.
|
* Cell that is merged with upper one.
|
||||||
*/
|
*/
|
||||||
CONTINUE = "continue",
|
CONTINUE: "continue",
|
||||||
/**
|
/**
|
||||||
* Cell that is starting the vertical merge.
|
* Cell that is starting the vertical merge.
|
||||||
*/
|
*/
|
||||||
RESTART = "restart",
|
RESTART: "restart",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: VerticalMergeType }> {
|
class VerticalMergeAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly val: (typeof VerticalMergeType)[keyof typeof VerticalMergeType];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: Vert
|
|||||||
* Vertical merge element. Should be used in a table cell.
|
* Vertical merge element. Should be used in a table cell.
|
||||||
*/
|
*/
|
||||||
export class VerticalMerge extends XmlComponent {
|
export class VerticalMerge extends XmlComponent {
|
||||||
public constructor(value: VerticalMergeType) {
|
public constructor(value: (typeof VerticalMergeType)[keyof typeof VerticalMergeType]) {
|
||||||
super("w:vMerge");
|
super("w:vMerge");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
@ -110,13 +112,18 @@ export class VerticalMerge extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum TextDirection {
|
export const TextDirection = {
|
||||||
BOTTOM_TO_TOP_LEFT_TO_RIGHT = "btLr",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb",
|
BOTTOM_TO_TOP_LEFT_TO_RIGHT: "btLr",
|
||||||
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
}
|
LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl",
|
||||||
|
} as const;
|
||||||
|
|
||||||
class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDirection }> {
|
class TDirectionAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly val: (typeof TextDirection)[keyof typeof TextDirection];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { val: "w:val" };
|
protected readonly xmlKeys = { val: "w:val" };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +131,7 @@ class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDir
|
|||||||
* Text Direction within a table cell
|
* Text Direction within a table cell
|
||||||
*/
|
*/
|
||||||
export class TDirection extends XmlComponent {
|
export class TDirection extends XmlComponent {
|
||||||
public constructor(value: TextDirection) {
|
public constructor(value: (typeof TextDirection)[keyof typeof TextDirection]) {
|
||||||
super("w:textDirection");
|
super("w:textDirection");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -17,9 +17,9 @@ import {
|
|||||||
export interface ITableCellPropertiesOptions {
|
export interface ITableCellPropertiesOptions {
|
||||||
readonly shading?: IShadingAttributesProperties;
|
readonly shading?: IShadingAttributesProperties;
|
||||||
readonly margins?: ITableCellMarginOptions;
|
readonly margins?: ITableCellMarginOptions;
|
||||||
readonly verticalAlign?: VerticalAlign;
|
readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
|
||||||
readonly textDirection?: TextDirection;
|
readonly textDirection?: (typeof TextDirection)[keyof typeof TextDirection];
|
||||||
readonly verticalMerge?: VerticalMergeType;
|
readonly verticalMerge?: (typeof VerticalMergeType)[keyof typeof VerticalMergeType];
|
||||||
readonly width?: ITableWidthProperties;
|
readonly width?: ITableWidthProperties;
|
||||||
readonly columnSpan?: number;
|
readonly columnSpan?: number;
|
||||||
readonly rowSpan?: number;
|
readonly rowSpan?: number;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { IgnoreIfEmptyXmlComponent } from "@file/xml-components";
|
import { IgnoreIfEmptyXmlComponent } from "@file/xml-components";
|
||||||
import { TableWidthElement, WidthType } from "../table-width";
|
import { TableWidthElement, WidthType } from "@file/table";
|
||||||
|
|
||||||
export interface ITableCellMarginOptions {
|
export interface ITableCellMarginOptions {
|
||||||
readonly marginUnitType?: WidthType;
|
readonly marginUnitType?: (typeof WidthType)[keyof typeof WidthType];
|
||||||
readonly top?: number;
|
readonly top?: number;
|
||||||
readonly bottom?: number;
|
readonly bottom?: number;
|
||||||
readonly left?: number;
|
readonly left?: number;
|
||||||
@ -33,14 +33,15 @@ export interface ITableCellMarginOptions {
|
|||||||
// </xsd:sequence>
|
// </xsd:sequence>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export enum TableCellMarginElementType {
|
export const TableCellMarginElementType = {
|
||||||
TABLE = "w:tblCellMar",
|
TABLE: "w:tblCellMar",
|
||||||
TABLE_CELL = "w:tcMar",
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
}
|
TABLE_CELL: "w:tcMar",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
|
export class TableCellMargin extends IgnoreIfEmptyXmlComponent {
|
||||||
public constructor(
|
public constructor(
|
||||||
type: TableCellMarginElementType,
|
type: (typeof TableCellMarginElementType)[keyof typeof TableCellMarginElementType],
|
||||||
{ marginUnitType = WidthType.DXA, top, left, bottom, right }: ITableCellMarginOptions,
|
{ marginUnitType = WidthType.DXA, top, left, bottom, right }: ITableCellMarginOptions,
|
||||||
) {
|
) {
|
||||||
super(type);
|
super(type);
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components";
|
import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components";
|
||||||
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
|
||||||
|
|
||||||
export enum TableAnchorType {
|
export const TableAnchorType = {
|
||||||
MARGIN = "margin",
|
MARGIN: "margin",
|
||||||
PAGE = "page",
|
PAGE: "page",
|
||||||
TEXT = "text",
|
TEXT: "text",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum RelativeHorizontalPosition {
|
export const RelativeHorizontalPosition = {
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
INSIDE = "inside",
|
INSIDE: "inside",
|
||||||
LEFT = "left",
|
LEFT: "left",
|
||||||
OUTSIDE = "outside",
|
OUTSIDE: "outside",
|
||||||
RIGHT = "right",
|
RIGHT: "right",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export enum RelativeVerticalPosition {
|
export const RelativeVerticalPosition = {
|
||||||
CENTER = "center",
|
CENTER: "center",
|
||||||
INSIDE = "inside",
|
INSIDE: "inside",
|
||||||
BOTTOM = "bottom",
|
BOTTOM: "bottom",
|
||||||
OUTSIDE = "outside",
|
OUTSIDE: "outside",
|
||||||
INLINE = "inline",
|
INLINE: "inline",
|
||||||
TOP = "top",
|
TOP: "top",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_TblOverlap">
|
// <xsd:simpleType name="ST_TblOverlap">
|
||||||
// <xsd:restriction base="xsd:string">
|
// <xsd:restriction base="xsd:string">
|
||||||
@ -30,10 +30,10 @@ export enum RelativeVerticalPosition {
|
|||||||
// <xsd:enumeration value="overlap"/>
|
// <xsd:enumeration value="overlap"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum OverlapType {
|
export const OverlapType = {
|
||||||
NEVER = "never",
|
NEVER: "never",
|
||||||
OVERLAP = "overlap",
|
OVERLAP: "overlap",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
export type ITableFloatOptions = {
|
export type ITableFloatOptions = {
|
||||||
/* cSpell:disable */
|
/* cSpell:disable */
|
||||||
@ -46,7 +46,7 @@ export type ITableFloatOptions = {
|
|||||||
* If omitted, the value is assumed to be page.
|
* If omitted, the value is assumed to be page.
|
||||||
*/
|
*/
|
||||||
/* cSpell:enable */
|
/* cSpell:enable */
|
||||||
readonly horizontalAnchor?: TableAnchorType;
|
readonly horizontalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
|
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
|
||||||
@ -67,7 +67,7 @@ export type ITableFloatOptions = {
|
|||||||
* outside - the table should be outside of the anchor
|
* outside - the table should be outside of the anchor
|
||||||
* right - the table should be right aligned with respect to the anchor
|
* right - the table should be right aligned with respect to the anchor
|
||||||
*/
|
*/
|
||||||
readonly relativeHorizontalPosition?: RelativeHorizontalPosition;
|
readonly relativeHorizontalPosition?: (typeof RelativeHorizontalPosition)[keyof typeof RelativeHorizontalPosition];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the vertical anchor or the base object from which the vertical positioning
|
* Specifies the vertical anchor or the base object from which the vertical positioning
|
||||||
@ -77,7 +77,7 @@ export type ITableFloatOptions = {
|
|||||||
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
|
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
|
||||||
* If omitted, the value is assumed to be page.
|
* If omitted, the value is assumed to be page.
|
||||||
*/
|
*/
|
||||||
readonly verticalAnchor?: TableAnchorType;
|
readonly verticalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
|
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
|
||||||
@ -98,7 +98,7 @@ export type ITableFloatOptions = {
|
|||||||
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
|
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
|
||||||
* top - the table should be vertically aligned to the top edge of the anchor
|
* top - the table should be vertically aligned to the top edge of the anchor
|
||||||
*/
|
*/
|
||||||
readonly relativeVerticalPosition?: RelativeVerticalPosition;
|
readonly relativeVerticalPosition?: (typeof RelativeVerticalPosition)[keyof typeof RelativeVerticalPosition];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
|
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
|
||||||
@ -123,7 +123,7 @@ export type ITableFloatOptions = {
|
|||||||
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
|
||||||
*/
|
*/
|
||||||
readonly rightFromText?: number | PositiveUniversalMeasure;
|
readonly rightFromText?: number | PositiveUniversalMeasure;
|
||||||
readonly overlap?: OverlapType;
|
readonly overlap?: (typeof OverlapType)[keyof typeof OverlapType];
|
||||||
};
|
};
|
||||||
|
|
||||||
// <xsd:complexType name="CT_TblPPr">
|
// <xsd:complexType name="CT_TblPPr">
|
||||||
@ -156,12 +156,18 @@ export class TableFloatProperties extends XmlComponent {
|
|||||||
super("w:tblpPr");
|
super("w:tblpPr");
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
|
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
|
||||||
leftFromText: { key: "w:leftFromText", value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText) },
|
leftFromText: {
|
||||||
|
key: "w:leftFromText",
|
||||||
|
value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText),
|
||||||
|
},
|
||||||
rightFromText: {
|
rightFromText: {
|
||||||
key: "w:rightFromText",
|
key: "w:rightFromText",
|
||||||
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
|
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
|
||||||
},
|
},
|
||||||
topFromText: { key: "w:topFromText", value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText) },
|
topFromText: {
|
||||||
|
key: "w:topFromText",
|
||||||
|
value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText),
|
||||||
|
},
|
||||||
bottomFromText: {
|
bottomFromText: {
|
||||||
key: "w:bottomFromText",
|
key: "w:bottomFromText",
|
||||||
value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText),
|
value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText),
|
||||||
@ -197,7 +203,7 @@ export class TableFloatProperties extends XmlComponent {
|
|||||||
// <xsd:complexType name="CT_TblOverlap">
|
// <xsd:complexType name="CT_TblOverlap">
|
||||||
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
|
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
this.root.push(new StringEnumValueElement<OverlapType>("w:tblOverlap", overlap));
|
this.root.push(new StringEnumValueElement<(typeof OverlapType)[keyof typeof OverlapType]>("w:tblOverlap", overlap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|||||||
// <xsd:enumeration value="autofit"/>
|
// <xsd:enumeration value="autofit"/>
|
||||||
// </xsd:restriction>
|
// </xsd:restriction>
|
||||||
// </xsd:simpleType>
|
// </xsd:simpleType>
|
||||||
export enum TableLayoutType {
|
export const TableLayoutType = {
|
||||||
AUTOFIT = "autofit",
|
AUTOFIT: "autofit",
|
||||||
FIXED = "fixed",
|
FIXED: "fixed",
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> {
|
class TableLayoutAttributes extends XmlAttributeComponent<{
|
||||||
|
readonly type: (typeof TableLayoutType)[keyof typeof TableLayoutType];
|
||||||
|
}> {
|
||||||
protected readonly xmlKeys = { type: "w:type" };
|
protected readonly xmlKeys = { type: "w:type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +21,7 @@ class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: Table
|
|||||||
// <xsd:attribute name="type" type="ST_TblLayoutType"/>
|
// <xsd:attribute name="type" type="ST_TblLayoutType"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
export class TableLayout extends XmlComponent {
|
export class TableLayout extends XmlComponent {
|
||||||
public constructor(type: TableLayoutType) {
|
public constructor(type: (typeof TableLayoutType)[keyof typeof TableLayoutType]) {
|
||||||
super("w:tblLayout");
|
super("w:tblLayout");
|
||||||
this.root.push(new TableLayoutAttributes({ type }));
|
this.root.push(new TableLayoutAttributes({ type }));
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user