Compare commits

..

4 Commits
9.1.0 ... fork

259 changed files with 6692 additions and 10302 deletions

View File

@ -47,28 +47,23 @@ rules:
"@typescript-eslint/array-type":
- error
- default: array
"@typescript-eslint/no-restricted-types":
"@typescript-eslint/ban-types":
- error
- types:
Object:
message: Avoid using the `Object` type. Did you mean `object`?
fixWith: object
Function:
message: >-
Avoid using the `Function` type. Prefer a specific function type,
like `() => void`.
Boolean:
message: Avoid using the `Boolean` type. Did you mean `boolean`?
fixWith: boolean
Number:
message: Avoid using the `Number` type. Did you mean `number`?
fixWith: number
String:
message: Avoid using the `String` type. Did you mean `string`?
fixWith: string
Symbol:
message: Avoid using the `Symbol` type. Did you mean `symbol`?
fixWith: symbol
"@typescript-eslint/consistent-type-assertions": error
"@typescript-eslint/dot-notation": error
"@typescript-eslint/explicit-function-return-type":
@ -97,7 +92,7 @@ rules:
format:
- camelCase
- PascalCase
- UPPER_CASE # for constants
- UPPER_CASE # for constants
filter:
regex: (^[a-z]+:.+)|_attr|[0-9]
match: false

View File

@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- name: Archive Production Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@master
with:
name: build
path: build
@ -25,24 +25,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Test
run: npm run test:ci
- name: Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Lint
@ -52,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Prettier
@ -62,7 +60,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Prettier

View File

@ -12,7 +12,7 @@ jobs:
name: Demos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@master
- uses: "./.github/actions/install-and-build"
- name: Run Demos
run: npm run run-ts -- ./demo/1-basic.ts

View File

@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Build 🔧
@ -19,7 +19,7 @@ jobs:
echo "docx.js.org" > docs/.nojekyll
echo "docx.js.org" > docs/CNAME
- name: Archive Production Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@master
with:
name: docs
path: docs
@ -28,11 +28,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo 🛎️
uses: actions/checkout@v4
uses: actions/checkout@master
- name: Install Dependencies
run: npm ci --force
- name: Download Artifact
uses: actions/download-artifact@v4
uses: actions/download-artifact@master
with:
name: docs
path: docs

View File

@ -1,46 +0,0 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package
on:
release:
types: [created]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm ci --force
- run: npm run cspell
- run: npm run prettier
- run: npm run lint
- run: npm run test:ci
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
- run: npm ci --force
- run: npm run build
publish-npm:
needs: [test, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: https://registry.npmjs.org/
- run: npm ci --force
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

View File

@ -5,6 +5,5 @@
"editor.formatOnSave": false,
"prettier.tabWidth": 4,
"prettier.arrowParens": "always",
"prettier.bracketSpacing": true,
"eslint.useFlatConfig": true
"prettier.bracketSpacing": true
}

View File

@ -88,7 +88,6 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
[<img src="https://i.imgur.com/AKGhtlh.png" alt="drawing"/>](https://lexense.com/)
[<img src="https://i.imgur.com/9tqJaHw.png" alt="drawing" height="50"/>](https://novelpad.co/)
[<img src="https://i.imgur.com/5bLKFeP.png" alt="drawing" height="50"/>](https://proton.me/)
...and many more!

View File

@ -1,24 +0,0 @@
# Security Policy
## Supported Versions
Use this section to tell people about which versions of your project are
currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 9.0.x | :white_check_mark: |
## Reporting a Vulnerability
We encourage responsible disclosure of security vulnerabilities. If you believe you have found a security vulnerability in this project, please report it via the [Security Tab](https://github.com/dolanmiu/docx/security/advisories)
Please include the following information in your report:
* A description of the vulnerability
* Steps to reproduce the vulnerability
* Impact of the vulnerability
We will investigate all reported vulnerabilities and take appropriate action.
We appreciate your help in keeping this project secure.

View File

@ -1,72 +0,0 @@
// Patch a document with patches
import * as fs from "fs";
import { patchDocument, PatchType, TextRun } from "docx";
patchDocument({
outputType: "nodebuffer",
data: fs.readFileSync("demo/assets/field-trip.docx"),
patches: {
todays_date: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: new Date().toLocaleDateString() })],
},
school_name: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
address: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "blah blah" })],
},
city: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
state: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
zip: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
phone: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
first_name: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
last_name: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
email_address: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
ft_dates: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
grade: {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: "test" })],
},
},
}).then((doc) => {
fs.writeFileSync("My Document.docx", doc);
});

View File

@ -1,43 +0,0 @@
// Simple example to add textbox to a document
import { Document, Packer, Paragraph, Textbox, TextRun } from "docx";
import * as fs from "fs";
const doc = new Document({
sections: [
{
properties: {},
children: [
new Textbox({
alignment: "center",
children: [
new Paragraph({
children: [new TextRun("Hi i'm a textbox!")],
}),
],
style: {
width: "200pt",
height: "auto",
},
}),
new Textbox({
alignment: "center",
children: [
new Paragraph({
children: [new TextRun("Hi i'm a textbox with a hidden box!")],
}),
],
style: {
width: "300pt",
height: 400,
visibility: "hidden",
zIndex: "auto",
},
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

Binary file not shown.

View File

@ -22,7 +22,7 @@ const doc = new Document({
}
})
],
}]
}];
});
```

View File

@ -22,30 +22,19 @@ const doc = new docx.Document({
### Full list of options:
| Property | Type | Notes |
| -------------------------- | -------------------------------------------------------- | -------- |
| sections | `ISectionOptions[]` | Optional |
| title | `string` | Optional |
| subject | `string` | Optional |
| creator | `string` | Optional |
| keywords | `string` | Optional |
| description | `string` | Optional |
| lastModifiedBy | `string` | Optional |
| revision | `number` | Optional |
| externalStyles | `string` | Optional |
| styles | `IStylesOptions` | Optional |
| numbering | `INumberingOptions` | Optional |
| comments | `ICommentsOptions` | Optional |
| footnotes | `Record<string, { children: Paragraph[] }>` | Optional |
| background | `IDocumentBackgroundOptions` | Optional |
| features | `{ trackRevisions?: boolean; updateFields?: boolean; }` | Optional |
| compatabilityModeVersion | `number` | Optional |
| compatibility | `ICompatibilityOptions` | Optional |
| customProperties | ` ICustomPropertyOptions`[] | Optional |
| evenAndOddHeaderAndFooters | `boolean` | Optional |
| defaultTabStop | `number` | Optional |
| fonts | ` FontOptions[]` | Optional |
| hyphenation | `IHyphenationOptions` | Optional |
- creator
- description
- title
- subject
- keywords
- lastModifiedBy
- revision
- externalStyles
- styles
- numbering
- footnotes
- hyperlinks
- background
### Change background color of Document

View File

@ -130,62 +130,6 @@ new Paragraph({
}),
```
## Disabling numbering inherited from paragraph style
If the numbering is set on a paragraph style, you may wish to disable it for a specific paragraph:
```ts
const doc = new Document({
...
numbering: {
config: [
{
reference: "my-bullet-points",
levels: [
{
level: 0,
format: LevelFormat.BULLET,
text: "\u1F60",
alignment: AlignmentType.LEFT,
style: {
paragraph: {
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
},
},
},
],
},
],
},
styles: {
paragraphStyles: [
{
id: 'bullet',
name: 'Bullet',
basedOn: 'Normal',
next: 'Normal',
run: {},
paragraph: {
numbering: {
reference: 'my-bullet-points',
level: 0,
},
},
},
],
},
...
});
```
```ts
new Paragraph({
text: "No bullet points!",
style: "Bullet",
numbering: false,
}),
```
## Full Example
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/3-numbering-and-bullet-points.ts ":include")

View File

@ -35,9 +35,6 @@ interface Patch {
| type | `PatchType` | Required | `DOCUMENT`, `PARAGRAPH` |
| children | `FileChild[] or ParagraphChild[]` | Required | The contents to replace with. A `FileChild` is a `Paragraph` or `Table`, whereas a `ParagraphChild` is typical `Paragraph` children. |
The patcher also takes in a `keepOriginalStyles` boolean, which will preserve the styles of the patched text when set to true.
### How to patch existing document
1. Open your existing word document in your favorite Word Processor

View File

@ -126,10 +126,10 @@ const doc = new Document({
next: "Normal",
quickFormat: true,
run: {
size: 26,
size: 26
bold: true,
color: "999999",
underline: {
{
type: UnderlineType.DOUBLE,
color: "FF0000",
},

View File

@ -22,7 +22,7 @@ Then add the table in the `section`
const doc = new Document({
sections: [{
children: [table],
}],
}];
});
```

View File

@ -1,26 +0,0 @@
# Text Box
Similar `Text Frames`, but the difference being that it is `VML` `Shape` based.
!> `Text Boxes` requires an understanding of [Paragraphs](usage/paragraph.md).
> `Text boxes` are paragraphs of text in a document which are positioned in a separate region or frame in the document, and can be positioned with a specific size and position relative to non-frame paragraphs in the current document.
## Intro
To make a `Text Box`, simply create a `Textbox` object inside the `Document`:
```ts
new Textbox({
alignment: "center",
children: [
new Paragraph({
children: [new TextRun("Hi i'm a textbox!")],
}),
],
style: {
width: "200pt",
height: "auto",
},
});
```

View File

@ -1,6 +1,6 @@
# Text Frames
> Similar to `Text Boxes`!
Also known as `Text Boxes`
!> Text Frames requires an understanding of [Paragraphs](usage/paragraph.md).

View File

@ -1,370 +0,0 @@
import eslint from "@eslint/js";
import type { Linter } from "eslint";
import importPlugin from "eslint-plugin-import";
import unicorn from "eslint-plugin-unicorn";
import jsdoc from "eslint-plugin-jsdoc";
import preferArrow from "eslint-plugin-prefer-arrow";
import functional from "eslint-plugin-functional";
import globals from "globals";
import tsEslint from "typescript-eslint";
const config: Linter.Config<Linter.RulesRecord>[] = [
{
ignores: ["**/vite.config.ts", "**/build/**", "**/coverage/**", "**/*.js", "eslint.config.ts", "**/demo/**", "**/scripts/**"],
},
eslint.configs.recommended,
importPlugin.flatConfigs.recommended,
...tsEslint.configs.recommended,
...tsEslint.configs.stylistic,
{
files: ["**/src/**/*.ts"],
plugins: {
unicorn,
jsdoc,
"prefer-arrow": preferArrow,
functional,
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
"import/resolver": {
typescript: true,
node: true,
},
},
rules: {
"no-undef": "off",
"no-extra-boolean-cast": "off",
"no-alert": "error",
"no-self-compare": "error",
"no-unreachable-loop": "error",
"no-template-curly-in-string": "error",
"no-unused-private-class-members": "error",
"no-extend-native": "error",
"no-floating-decimal": "error",
"no-implied-eval": "error",
"no-iterator": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-new-object": "error",
"no-proto": "error",
"no-useless-catch": "error",
"one-var-declaration-per-line": "error",
"prefer-arrow-callback": "error",
"prefer-destructuring": "error",
"prefer-exponentiation-operator": "error",
"prefer-promise-reject-errors": "error",
"prefer-regex-literals": "error",
"prefer-spread": "error",
"prefer-template": "error",
"require-await": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": [
"error",
{
default: "array",
},
],
"@typescript-eslint/no-restricted-types": [
"error",
{
types: {
Object: {
message: "Avoid using the `Object` type. Did you mean `object`?",
fixWith: "object",
},
Function: {
message: "Avoid using the `Function` type. Prefer a specific function type, like `() => void`.",
},
Boolean: {
message: "Avoid using the `Boolean` type. Did you mean `boolean`?",
fixWith: "boolean",
},
Number: {
message: "Avoid using the `Number` type. Did you mean `number`?",
fixWith: "number",
},
String: {
message: "Avoid using the `String` type. Did you mean `string`?",
fixWith: "string",
},
Symbol: {
message: "Avoid using the `Symbol` type. Did you mean `symbol`?",
fixWith: "symbol",
},
},
},
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: false,
allowDirectConstAssertionInArrowFunctions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
},
],
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
},
},
],
"@typescript-eslint/explicit-module-boundary-types": [
"error",
{
allowArgumentsExplicitlyTypedAsAny: true,
allowDirectConstAssertionInArrowFunctions: true,
allowHigherOrderFunctions: false,
allowTypedFunctionExpressions: false,
},
],
"@typescript-eslint/naming-convention": [
"error",
{
selector: ["objectLiteralProperty"],
leadingUnderscore: "allow",
format: ["camelCase", "PascalCase", "UPPER_CASE"],
filter: {
regex: "(^[a-z]+:.+)|_attr|[0-9]",
match: false,
},
},
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-shadow": [
"error",
{
hoist: "all",
},
],
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/triple-slash-reference": [
"error",
{
path: "always",
types: "prefer-import",
lib: "always",
},
],
"@typescript-eslint/typedef": [
"error",
{
parameter: true,
propertyDeclaration: true,
},
],
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": "error",
complexity: "off",
"consistent-return": "error",
"constructor-super": "error",
curly: "error",
"dot-notation": "off",
eqeqeq: ["error", "smart"],
"guard-for-in": "error",
"id-denylist": ["error", "any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"],
"id-match": "error",
"import/no-default-export": "error",
"import/no-extraneous-dependencies": "off",
"import/no-internal-modules": "off",
"sort-imports": [
"error",
{
allowSeparatedGroups: true,
ignoreDeclarationSort: true,
},
],
"import/order": [
"error",
{
groups: [["external", "builtin"], "internal", ["sibling", "parent", "index"]],
"newlines-between": "always",
pathGroups: [
{ pattern: "@file/**/*", group: "internal" },
{ pattern: "@file/**", group: "internal" },
{ pattern: "@export/**", group: "internal" },
],
pathGroupsExcludedImportTypes: ["internal"],
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
indent: "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "off",
"max-classes-per-file": "off",
"max-len": "off",
"new-parens": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": "error",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-empty-function": "off",
"no-eval": "error",
"no-extra-bind": "error",
"no-fallthrough": "off",
"no-invalid-this": "off",
"no-multiple-empty-lines": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-param-reassign": "error",
"no-redeclare": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-sparse-arrays": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-underscore-dangle": [
"error",
{
allow: ["_attr"],
},
],
"no-unsafe-finally": "error",
"no-unused-expressions": "off",
"no-unused-labels": "error",
"no-use-before-define": "off",
"no-useless-constructor": "error",
"no-var": "error",
"object-shorthand": "off",
"one-var": ["error", "never"],
"prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
radix: "error",
"space-in-parens": ["error", "never"],
"spaced-comment": [
"error",
"always",
{
markers: ["/"],
},
],
"unicorn/filename-case": "error",
"unicorn/prefer-ternary": "error",
"use-isnan": "error",
"valid-typeof": "off",
"functional/immutable-data": [
"error",
{
ignoreImmediateMutation: true,
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
},
],
"functional/prefer-property-signatures": "error",
"functional/no-mixed-types": "error",
"functional/prefer-readonly-type": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^[_]+$",
},
],
},
},
{
files: ["**/*.spec.ts"],
plugins: {
unicorn,
jsdoc,
"prefer-arrow": preferArrow,
functional,
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
sourceType: "module",
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
project: ["tsconfig.json"],
},
},
rules: {
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/dot-notation": "off",
"prefer-destructuring": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^[_]+$",
},
],
},
},
];
export default config;

13503
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "docx",
"version": "9.1.0",
"version": "8.5.0",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
"type": "module",
"main": "build/index.umd.js",
@ -22,7 +22,7 @@
"test": "vitest --ui --coverage",
"test:ci": "vitest run --coverage",
"prepublishOnly": "npm run build --omit=dev",
"lint": "eslint --flag unstable_ts_config --config eslint.config.ts",
"lint": "eslint --ext .ts src",
"predemo": "npm run build",
"demo": "tsx ./demo/index.ts",
"typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
@ -54,8 +54,7 @@
"clippy"
],
"dependencies": {
"@types/node": "^22.7.5",
"hash.js": "^1.1.7",
"@types/node": "^20.3.1",
"jszip": "^3.10.1",
"nanoid": "^5.0.4",
"xml": "^1.0.1",
@ -68,43 +67,38 @@
},
"homepage": "https://docx.js.org",
"devDependencies": {
"@eslint/compat": "^1.2.1",
"@types/eslint__js": "^8.42.3",
"@types/inquirer": "^9.0.3",
"@types/prompt": "^1.1.1",
"@types/unzipper": "^0.10.4",
"@types/xml": "^1.0.8",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@vitest/coverage-v8": "^1.1.0",
"@vitest/ui": "^2.1.2",
"@vitest/ui": "^1.1.0",
"cspell": "^8.2.3",
"docsify-cli": "^4.3.0",
"eslint": "^9.13.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-functional": "^7.0.2",
"eslint": "^8.23.0",
"eslint-plugin-functional": "^6.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^50.3.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-unicorn": "^56.0.0",
"execa": "^9.4.0",
"glob": "^11.0.0",
"inquirer": "^12.0.0",
"jiti": "^2.3.3",
"jsdom": "^25.0.1",
"eslint-plugin-unicorn": "^50.0.1",
"execa": "^8.0.1",
"glob": "^10.2.7",
"inquirer": "^9.2.7",
"jsdom": "^23.0.1",
"pre-commit": "^1.2.2",
"prettier": "^3.1.1",
"tsconfig-paths": "^4.0.0",
"tsx": "^4.7.0",
"typedoc": "^0.26.9",
"typedoc": "^0.25.4",
"typescript": "5.3.3",
"typescript-eslint": "^8.10.0",
"unzipper": "^0.12.3",
"unzipper": "^0.10.11",
"vite": "^5.0.10",
"vite-plugin-dts": "^4.2.4",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-tsconfig-paths": "^5.0.1",
"vite-plugin-dts": "^3.3.1",
"vite-plugin-node-polyfills": "^0.19.0",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^1.1.0"
},
"engines": {

View File

@ -1,6 +1,7 @@
import { BaseXmlComponent, IContext, IXmlableObject } from "@file/xml-components";
export class Formatter {
// tslint:disable-next-line: no-object-literal-type-assertion
public format(input: BaseXmlComponent, context: IContext = { stack: [] } as unknown as IContext): IXmlableObject {
const output = input.prepForXml(context);

View File

@ -125,6 +125,7 @@ describe("Compiler", () => {
],
});
// tslint:disable-next-line: no-string-literal
const spy = vi.spyOn(compiler["formatter"], "format");
compiler.compile(file);

View File

@ -9,12 +9,12 @@ import { ImageReplacer } from "./image-replacer";
import { NumberingReplacer } from "./numbering-replacer";
import { PrettifyType } from "./packer";
type IXmlifyedFile = {
interface IXmlifyedFile {
readonly data: string;
readonly path: string;
};
}
type IXmlifyedFileMapping = {
interface IXmlifyedFileMapping {
readonly Document: IXmlifyedFile;
readonly Styles: IXmlifyedFile;
readonly Properties: IXmlifyedFile;
@ -34,7 +34,7 @@ type IXmlifyedFileMapping = {
readonly Comments?: IXmlifyedFile;
readonly FontTable?: IXmlifyedFile;
readonly FontTableRelationships?: IXmlifyedFile;
};
}
export class Compiler {
private readonly formatter: Formatter;
@ -109,12 +109,6 @@ export class Compiler {
);
});
file.Document.Relationships.createRelationship(
file.Document.Relationships.RelationshipCount + 1,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
"fontTable.xml",
);
return xml(
this.formatter.format(file.Document.Relationships, {
viewWrapper: file.Document,

View File

@ -139,6 +139,7 @@ describe("Packer", () => {
it("should create a standard docx file", async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
vi.spyOn((Packer as any).compiler, "compile").mockReturnValue({
// tslint:disable-next-line: no-empty
generateAsync: () => vi.fn(),
});
const str = await Packer.toBlob(file);
@ -166,6 +167,7 @@ describe("Packer", () => {
it("should create a standard docx file", async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
vi.spyOn((Packer as any).compiler, "compile").mockReturnValue({
// tslint:disable-next-line: no-empty
generateAsync: () => Promise.resolve(vi.fn()),
});
const stream = Packer.toStream(file);

View File

@ -1,5 +1,4 @@
import { Stream } from "stream";
import { File } from "@file/file";
import { Compiler } from "./next-compiler";
@ -11,7 +10,7 @@ export const PrettifyType = {
NONE: "",
WITH_2_BLANKS: " ",
WITH_4_BLANKS: " ",
// eslint-disable-next-line @typescript-eslint/naming-convention
WITH_TAB: "\t",
} as const;

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { AppPropertiesAttributes } from "./app-properties-attributes";
export class AppProperties extends XmlComponent {

View File

@ -22,7 +22,7 @@
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values";
export type IBorderOptions = {
export interface IBorderOptions {
readonly style: (typeof BorderStyle)[keyof typeof BorderStyle];
/** Border color, in hex (eg 'FF00AA') */
readonly color?: string;
@ -30,7 +30,7 @@ export type IBorderOptions = {
readonly size?: number;
/** Spacing offset. Values are specified in pt */
readonly space?: number;
};
}
export class BorderElement extends XmlComponent {
public constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
@ -55,6 +55,7 @@ class BordersAttributes extends XmlAttributeComponent<IBorderOptions> {
};
}
/* eslint-disable @typescript-eslint/naming-convention */
export const BorderStyle = {
SINGLE: "single",
DASH_DOT_STROKED: "dashDotStroked",
@ -84,3 +85,4 @@ export const BorderStyle = {
TRIPLE: "triple",
WAVE: "wave",
} as const;
/* eslint-enable */

View File

@ -1,7 +1,5 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { CheckBoxUtil } from ".";
describe("CheckBoxUtil", () => {

View File

@ -7,20 +7,20 @@
// </xsd:complexType>
// <xsd:element name="checkbox" type="CT_SdtCheckbox"/>
import { CheckBoxSymbolElement } from "@file/checkbox/checkbox-symbol";
import { XmlComponent } from "@file/xml-components";
import { CheckBoxSymbolElement } from "@file/checkbox/checkbox-symbol";
export type ICheckboxSymbolProperties = {
export interface ICheckboxSymbolProperties {
readonly value?: string;
readonly font?: string;
};
}
export type ICheckboxSymbolOptions = {
export interface ICheckboxSymbolOptions {
readonly alias?: string;
readonly checked?: boolean;
readonly checkedState?: ICheckboxSymbolProperties;
readonly uncheckedState?: ICheckboxSymbolProperties;
};
}
export class CheckBoxUtil extends XmlComponent {
private readonly DEFAULT_UNCHECKED_SYMBOL: string = "2610";

View File

@ -1,5 +1,4 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { CheckBox } from "./checkbox";

View File

@ -1,8 +1,7 @@
import { SymbolRun } from "@file/paragraph/run/symbol-run";
import { StructuredDocumentTagContent } from "@file/table-of-contents/sdt-content";
import { StructuredDocumentTagProperties } from "@file/table-of-contents/sdt-properties";
import { StructuredDocumentTagContent } from "@file/table-of-contents/sdt-content";
import { XmlComponent } from "@file/xml-components";
import { CheckBoxUtil, ICheckboxSymbolOptions } from "./checkbox-util";
export class CheckBox extends XmlComponent {

View File

@ -1,3 +1,5 @@
// tslint:disable:no-string-literal
import { beforeEach, describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { ContentTypeAttributes } from "./content-types-attributes";
import { Default } from "./default/default";
import { Override } from "./override/override";

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { DefaultAttributes } from "./default-attributes";
export class Default extends XmlComponent {

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { OverrideAttributes } from "./override-attributes";
export class Override extends XmlComponent {

View File

@ -45,7 +45,7 @@ describe("Properties", () => {
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const key = (obj: Readonly<Record<string, any>>) => Object.keys(obj)[0];
const key = (obj: { readonly [key: string]: any }) => Object.keys(obj)[0];
expect(tree["cp:coreProperties"].map(key)).to.include.members([
"_attr",
"cp:keywords",

View File

@ -1,19 +1,21 @@
import { FontOptions } from "@file/fonts/font-table";
import { ICommentsOptions } from "@file/paragraph/run/comment-run";
import { IHyphenationOptions } from "@file/settings";
import { ICompatibilityOptions } from "@file/settings/compatibility";
import { FontOptions } from "@file/fonts/font-table";
import { StringContainer, XmlComponent } from "@file/xml-components";
import { dateTimeValue } from "@util/values";
import { IHyphenationOptions } from "@file/settings";
import { IFootnoteProperties } from "@file/settings/footnote-properties";
import { ICustomPropertyOptions } from "../custom-properties";
import { IDocumentBackgroundOptions } from "../document";
import { DocumentAttributes } from "../document/document-attributes";
import { ISectionOptions } from "../file";
import { INumberingOptions } from "../numbering";
import { Paragraph } from "../paragraph";
import { IStylesOptions } from "../styles";
export type IPropertiesOptions = {
export interface IPropertiesOptions {
readonly sections: readonly ISectionOptions[];
readonly title?: string;
readonly subject?: string;
@ -26,14 +28,11 @@ export type IPropertiesOptions = {
readonly styles?: IStylesOptions;
readonly numbering?: INumberingOptions;
readonly comments?: ICommentsOptions;
readonly footnotes?: Readonly<
Record<
string,
{
readonly children: readonly Paragraph[];
}
>
>;
readonly footnotes?: {
readonly [key: string]: {
readonly children: readonly Paragraph[];
};
};
readonly background?: IDocumentBackgroundOptions;
readonly features?: {
readonly trackRevisions?: boolean;
@ -46,7 +45,8 @@ export type IPropertiesOptions = {
readonly defaultTabStop?: number;
readonly fonts?: readonly FontOptions[];
readonly hyphenation?: IHyphenationOptions;
};
readonly footnoteProperties?: IFootnoteProperties;
}
// <xs:element name="coreProperties" type="CT_CoreProperties"/>

View File

@ -1,5 +1,4 @@
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
import { CustomPropertiesAttributes } from "./custom-properties-attributes";
import { CustomProperty, ICustomPropertyOptions } from "./custom-property";

View File

@ -1,11 +1,10 @@
import { XmlComponent } from "@file/xml-components";
import { CustomPropertyAttributes } from "./custom-property-attributes";
export type ICustomPropertyOptions = {
export interface ICustomPropertyOptions {
readonly name: string;
readonly value: string;
};
}
export class CustomProperty extends XmlComponent {
public constructor(id: number, properties: ICustomPropertyOptions) {

View File

@ -1,14 +1,14 @@
import { XmlComponent } from "./xml-components";
import { Document, IDocumentOptions } from "./document";
import { Footer } from "./footer/footer";
import { FootNotes } from "./footnotes";
import { Header } from "./header/header";
import { Relationships } from "./relationships";
import { XmlComponent } from "./xml-components";
export type IViewWrapper = {
export interface IViewWrapper {
readonly View: Document | Footer | Header | FootNotes | XmlComponent;
readonly Relationships: Relationships;
};
}
export class DocumentWrapper implements IViewWrapper {
private readonly document: Document;

View File

@ -1,5 +1,5 @@
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, decimalNumber, twipsMeasureValue } from "@util/values";
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
import { Column } from "./column";

View File

@ -17,6 +17,7 @@ import { decimalNumber } from "@util/values";
// <xsd:attribute name="charSpace" type="ST_DecimalNumber"/>
// </xsd:complexType>
/* eslint-disable @typescript-eslint/naming-convention */
export const DocumentGridType = {
DEFAULT: "default",
LINES: "lines",
@ -24,11 +25,12 @@ export const DocumentGridType = {
SNAP_TO_CHARS: "snapToChars",
} as const;
export type IDocGridAttributesProperties = {
/* eslint-enable */
export interface IDocGridAttributesProperties {
readonly type?: (typeof DocumentGridType)[keyof typeof DocumentGridType];
readonly linePitch?: number;
readonly charSpace?: number;
};
}
export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> {
protected readonly xmlKeys = {

View File

@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./header-footer-reference";
describe("HeaderFooterReference", () => {

View File

@ -32,10 +32,10 @@ export const HeaderFooterReferenceType = {
// <xsd:attribute ref="r:id" use="required"/>
// </xsd:complexType>
export type IHeaderFooterOptions = {
export interface IHeaderFooterOptions {
readonly type?: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
readonly id?: number;
};
}
class FooterReferenceAttributes extends XmlAttributeComponent<{
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];

View File

@ -1,34 +0,0 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { createLineNumberType } from "./line-number";
describe("createLineNumberType", () => {
it("should work", () => {
const textDirection = createLineNumberType({ countBy: 0, start: 0, restart: "newPage", distance: 10 });
const tree = new Formatter().format(textDirection);
expect(tree).to.deep.equal({
"w:lnNumType": { _attr: { "w:countBy": 0, "w:start": 0, "w:restart": "newPage", "w:distance": 10 } },
});
});
it("should work with string measures for distance", () => {
const textDirection = createLineNumberType({ countBy: 0, start: 0, restart: "newPage", distance: "10mm" });
const tree = new Formatter().format(textDirection);
expect(tree).to.deep.equal({
"w:lnNumType": { _attr: { "w:countBy": 0, "w:start": 0, "w:restart": "newPage", "w:distance": "10mm" } },
});
});
it("should work with blank entries", () => {
const textDirection = createLineNumberType({});
const tree = new Formatter().format(textDirection);
expect(tree).to.deep.equal({
"w:lnNumType": { _attr: {} },
});
});
});

View File

@ -1,6 +1,6 @@
// http://officeopenxml.com/WPsectionLineNumbering.php
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, decimalNumber, twipsMeasureValue } from "@util/values";
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
// <xsd:simpleType name="ST_LineNumberRestart">
// <xsd:restriction base="xsd:string">
@ -10,11 +10,13 @@ import { PositiveUniversalMeasure, decimalNumber, twipsMeasureValue } from "@uti
// </xsd:restriction>
// </xsd:simpleType>
/* eslint-disable @typescript-eslint/naming-convention */
export const LineNumberRestartFormat = {
NEW_PAGE: "newPage",
NEW_SECTION: "newSection",
CONTINUOUS: "continuous",
} as const;
/* eslint-enable */
// <xsd:complexType name="CT_LineNumber">
// <xsd:attribute name="countBy" type="ST_DecimalNumber" use="optional"/>

View File

@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { BorderStyle } from "@file/border";
import { PageBorderDisplay, PageBorderZOrder, PageBorders } from "./page-borders";
import { PageBorderDisplay, PageBorders, PageBorderZOrder } from "./page-borders";
describe("PageBorders", () => {
describe("#constructor()", () => {

View File

@ -10,11 +10,13 @@ import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-comp
// </xsd:restriction>
// </xsd:simpleType>
/* eslint-disable @typescript-eslint/naming-convention */
export const PageBorderDisplay = {
ALL_PAGES: "allPages",
FIRST_PAGE: "firstPage",
NOT_FIRST_PAGE: "notFirstPage",
} as const;
/* eslint-enable */
// <xsd:simpleType name="ST_PageBorderOffset">
// <xsd:restriction base="xsd:string">
@ -38,19 +40,19 @@ export const PageBorderZOrder = {
FRONT: "front",
} as const;
export type IPageBorderAttributes = {
export interface IPageBorderAttributes {
readonly display?: (typeof PageBorderDisplay)[keyof typeof PageBorderDisplay];
readonly offsetFrom?: (typeof PageBorderOffsetFrom)[keyof typeof PageBorderOffsetFrom];
readonly zOrder?: (typeof PageBorderZOrder)[keyof typeof PageBorderZOrder];
};
}
export type IPageBordersOptions = {
export interface IPageBordersOptions {
readonly pageBorders?: IPageBorderAttributes;
readonly pageBorderTop?: IBorderOptions;
readonly pageBorderRight?: IBorderOptions;
readonly pageBorderBottom?: IBorderOptions;
readonly pageBorderLeft?: IBorderOptions;
};
}
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
protected readonly xmlKeys = {

View File

@ -1,5 +1,5 @@
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, UniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue } from "@util/values";
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
// <xsd:complexType name="CT_PageMar">
// <xsd:attribute name="top" type="ST_SignedTwipsMeasure" use="required"/>

View File

@ -13,6 +13,7 @@ import { decimalNumber } from "@util/values";
// </xsd:restriction>
// </xsd:simpleType>
/* eslint-disable @typescript-eslint/naming-convention */
export const PageNumberSeparator = {
HYPHEN: "hyphen",
PERIOD: "period",
@ -21,11 +22,13 @@ export const PageNumberSeparator = {
EN_DASH: "endash",
} as const;
export type IPageNumberTypeAttributes = {
/* eslint-enable */
export interface IPageNumberTypeAttributes {
readonly start?: number;
readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator];
};
}
// <xsd:complexType name="CT_PageNumber">
// <xsd:attribute name="fmt" type="ST_NumberFormat" use="optional" default="decimal"/>

View File

@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { PageTextDirection, PageTextDirectionType } from "./page-text-direction";
describe("PageTextDirection", () => {

View File

@ -1,10 +1,13 @@
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
/* eslint-disable @typescript-eslint/naming-convention */
export const PageTextDirectionType = {
LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb",
TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl",
} as const;
/* eslint-enable */
class PageTextDirectionAttributes extends XmlAttributeComponent<{
readonly val: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
}> {

View File

@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { SectionType, Type } from "./section-type";
describe("Type", () => {

View File

@ -11,6 +11,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
// </xsd:restriction>
// </xsd:simpleType>
/* eslint-disable @typescript-eslint/naming-convention */
export const SectionType = {
NEXT_PAGE: "nextPage",
NEXT_COLUMN: "nextColumn",
@ -18,6 +19,7 @@ export const SectionType = {
EVEN_PAGE: "evenPage",
ODD_PAGE: "oddPage",
} as const;
/* eslint-enable */
// <xsd:complexType name="CT_SectType">
// <xsd:attribute name="val" type="ST_SectionMark"/>

View File

@ -15,7 +15,7 @@ import { LineNumberRestartFormat } from "./properties/line-number";
import { PageBorderOffsetFrom } from "./properties/page-borders";
import { PageTextDirectionType } from "./properties/page-text-direction";
import { SectionType } from "./properties/section-type";
import { SectionProperties, sectionMarginDefaults, sectionPageSizeDefaults } from "./section-properties";
import { sectionMarginDefaults, sectionPageSizeDefaults, SectionProperties } from "./section-properties";
const DEFAULT_MARGINS = {
"w:bottom": sectionMarginDefaults.BOTTOM,

View File

@ -1,13 +1,15 @@
// http://officeopenxml.com/WPsection.php
// tslint:disable: no-unnecessary-initializer
import { FooterWrapper } from "@file/footer-wrapper";
import { HeaderWrapper } from "@file/header-wrapper";
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
import { OnOffElement, XmlComponent } from "@file/xml-components";
import { FootnoteProperties, IFootnoteProperties } from "@file/settings/footnote-properties";
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
import { Columns, IColumnsAttributes } from "./properties/columns";
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
import { ILineNumberAttributes, createLineNumberType } from "./properties/line-number";
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
@ -16,13 +18,13 @@ import { IPageSizeAttributes, PageOrientation, PageSize } from "./properties/pag
import { PageTextDirection, PageTextDirectionType } from "./properties/page-text-direction";
import { SectionType, Type } from "./properties/section-type";
export type IHeaderFooterGroup<T> = {
export interface IHeaderFooterGroup<T> {
readonly default?: T;
readonly first?: T;
readonly even?: T;
};
}
export type ISectionPropertiesOptions = {
export interface ISectionPropertiesOptions {
readonly page?: {
readonly size?: IPageSizeAttributes;
readonly margin?: IPageMarginAttributes;
@ -38,7 +40,8 @@ export type ISectionPropertiesOptions = {
readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
readonly column?: IColumnsAttributes;
readonly type?: (typeof SectionType)[keyof typeof SectionType];
};
readonly footnoteProperties?: IFootnoteProperties;
}
// <xsd:complexType name="CT_SectPr">
// <xsd:sequence>
@ -118,6 +121,7 @@ export class SectionProperties extends XmlComponent {
verticalAlign,
column,
type,
footnoteProperties,
}: ISectionPropertiesOptions = {}) {
super("w:sectPr");
@ -157,6 +161,10 @@ export class SectionProperties extends XmlComponent {
this.root.push(new PageTextDirection(textDirection));
}
if (footnoteProperties) {
this.root.push(new FootnoteProperties(footnoteProperties));
}
this.root.push(new DocumentGrid(linePitch, charSpace, gridType));
}

View File

@ -1,7 +1,7 @@
import { XmlAttributeComponent } from "@file/xml-components";
/* cSpell:disable */
export type IDocumentAttributesProperties = {
export interface IDocumentAttributesProperties {
readonly wpc?: string;
readonly mc?: string;
readonly o?: string;
@ -41,7 +41,7 @@ export type IDocumentAttributesProperties = {
readonly w16?: string;
readonly w16sdtdh?: string;
readonly w16se?: string;
};
}
/* cSpell:enable */
export class DocumentAttributes extends XmlAttributeComponent<IDocumentAttributesProperties> {

View File

@ -39,12 +39,12 @@ export class DocumentBackgroundAttributes extends XmlAttributeComponent<{
};
}
export type IDocumentBackgroundOptions = {
export interface IDocumentBackgroundOptions {
readonly color?: string;
readonly themeColor?: string;
readonly themeShade?: string;
readonly themeTint?: string;
};
}
// <xsd:complexType name="CT_Background">
// <xsd:sequence>

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/WPdocument.php
import { XmlComponent } from "@file/xml-components";
import { ConcreteHyperlink, Paragraph } from "../paragraph";
import { Table } from "../table";
import { TableOfContents } from "../table-of-contents";
@ -8,9 +7,9 @@ import { Body } from "./body";
import { DocumentAttributes } from "./document-attributes";
import { DocumentBackground, IDocumentBackgroundOptions } from "./document-background";
export type IDocumentOptions = {
export interface IDocumentOptions {
readonly background?: IDocumentBackgroundOptions;
};
}
// <xsd:element name="document" type="CT_Document"/>
//
@ -81,6 +80,7 @@ export class Document extends XmlComponent {
}
public add(item: Paragraph | Table | TableOfContents | ConcreteHyperlink): Document {
// eslint-disable-next-line functional/immutable-data
this.body.push(item);
return this;
}

View File

@ -1,15 +1,14 @@
import { XmlAttributeComponent } from "@file/xml-components";
import { IDistance } from "../drawing";
export type IAnchorAttributes = {
export interface IAnchorAttributes extends IDistance {
readonly allowOverlap?: "0" | "1";
readonly behindDoc?: "0" | "1";
readonly layoutInCell?: "0" | "1";
readonly locked?: "0" | "1";
readonly relativeHeight?: number;
readonly simplePos?: "0" | "1";
} & IDistance;
}
export class AnchorAttributes extends XmlAttributeComponent<IAnchorAttributes> {
protected readonly xmlKeys = {

View File

@ -1,6 +1,7 @@
import { assert, describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { Utility } from "tests/utility";
import { IDrawingOptions } from "../drawing";

View File

@ -1,7 +1,6 @@
// http://officeopenxml.com/drwPicFloating.php
import { IMediaData, IMediaDataTransformation } from "@file/media";
import { XmlComponent } from "@file/xml-components";
import { IDrawingOptions } from "../drawing";
import { HorizontalPosition, IFloating, SimplePos, VerticalPosition } from "../floating";
import { Graphic } from "../inline/graphic";

View File

@ -1,6 +1,7 @@
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_docPr_topic_ID0ES32OB.html
import { ConcreteHyperlink } from "@file/paragraph";
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
import { ConcreteHyperlink } from "@file/paragraph";
import { docPropertiesUniqueNumericIdGen } from "@util/convenience-functions";
import { createHyperlinkClick } from "./doc-properties-children";
@ -17,11 +18,11 @@ import { createHyperlinkClick } from "./doc-properties-children";
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
// </complexType>
export type DocPropertiesOptions = {
export interface DocPropertiesOptions {
readonly name: string;
readonly description: string;
readonly title: string;
};
}
export class DocProperties extends XmlComponent {
private readonly docPropertiesUniqueNumericId = docPropertiesUniqueNumericIdGen();

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { IContext } from "@file/xml-components";
import { Formatter } from "@export/formatter";
import { ConcreteHyperlink, TextRun } from "../";
import { Drawing, IDrawingOptions } from "./drawing";
@ -80,6 +80,7 @@ describe("Drawing", () => {
{
"a:graphicFrameLocks": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
noChangeAspect: 1,
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
},
@ -138,6 +139,7 @@ describe("Drawing", () => {
{
"a:blip": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
cstate: "none",
"r:embed": "rId{test.jpg}",
},
@ -309,6 +311,7 @@ describe("Drawing", () => {
{
"a:graphicFrameLocks": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
noChangeAspect: 1,
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
},
@ -367,6 +370,7 @@ describe("Drawing", () => {
{
"a:blip": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
cstate: "none",
"r:embed": "rId{test.jpg}",
},
@ -550,6 +554,7 @@ describe("Drawing", () => {
{
"a:graphicFrameLocks": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
noChangeAspect: 1,
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
},
@ -617,6 +622,7 @@ describe("Drawing", () => {
{
"a:blip": {
_attr: {
// tslint:disable-next-line:object-literal-key-quotes
cstate: "none",
"r:embed": "rId{test.jpg}",
},

View File

@ -14,11 +14,11 @@ export type IDistance = {
readonly distR?: number;
};
export type IDrawingOptions = {
export interface IDrawingOptions {
readonly floating?: IFloating;
readonly docProperties?: DocPropertiesOptions;
readonly outline?: OutlineOptions;
};
}
// <xsd:complexType name="CT_Drawing">
// <xsd:choice minOccurs="1" maxOccurs="unbounded">

View File

@ -7,12 +7,6 @@ export type EffectExtentAttributes = {
readonly left: number;
};
// <xsd:complexType name="CT_EffectExtent">
// <xsd:attribute name="l" type="a:ST_Coordinate" use="required"/>
// <xsd:attribute name="t" type="a:ST_Coordinate" use="required"/>
// <xsd:attribute name="r" type="a:ST_Coordinate" use="required"/>
// <xsd:attribute name="b" type="a:ST_Coordinate" use="required"/>
// </xsd:complexType>
export const createEffectExtent = ({ top, right, bottom, left }: EffectExtentAttributes): XmlComponent =>
new BuilderElement<EffectExtentAttributes>({
name: "wp:effectExtent",

View File

@ -4,6 +4,7 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali
import { ITextWrapping } from "../text-wrap";
/* eslint-disable @typescript-eslint/naming-convention */
export const HorizontalPositionRelativeFrom = {
CHARACTER: "character",
COLUMN: "column",
@ -26,26 +27,27 @@ export const VerticalPositionRelativeFrom = {
TOP_MARGIN: "topMargin",
} as const;
export type IHorizontalPositionOptions = {
/* eslint-enable */
export interface IHorizontalPositionOptions {
readonly relative?: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom];
readonly align?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign];
readonly offset?: number;
};
}
export type IVerticalPositionOptions = {
export interface IVerticalPositionOptions {
readonly relative?: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
readonly align?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign];
readonly offset?: number;
};
}
export type IMargins = {
export interface IMargins {
readonly left?: number;
readonly bottom?: number;
readonly top?: number;
readonly right?: number;
};
}
export type IFloating = {
export interface IFloating {
readonly horizontalPosition: IHorizontalPositionOptions;
readonly verticalPosition: IVerticalPositionOptions;
readonly allowOverlap?: boolean;
@ -55,4 +57,4 @@ export type IFloating = {
readonly margins?: IMargins;
readonly wrap?: ITextWrapping;
readonly zIndex?: number;
};
}

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/drwPicFloating-position.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { Align } from "./align";
import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./floating-position";
import { PositionOffset } from "./position-offset";

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/drwPicFloating-position.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { Align } from "./align";
import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floating-position";
import { PositionOffset } from "./position-offset";

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes";
export class GraphicFrameLocks extends XmlComponent {

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks";
export class GraphicFrameProperties extends XmlComponent {

View File

@ -1,5 +1,5 @@
import { IMediaData } from "@file/media";
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { IMediaData } from "@file/media";
const createSvgBlip = (mediaData: IMediaData): XmlComponent =>
new BuilderElement({

View File

@ -1,6 +1,5 @@
import { IMediaData } from "@file/media";
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { createExtentionList } from "./blip-extentions";
type BlipAttributes = {

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { PicLocks } from "./pic-locks/pic-locks";
export class ChildNonVisualProperties extends XmlComponent {

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { PicLocksAttributes } from "./pic-locks-attributes";
export class PicLocks extends XmlComponent {

View File

@ -1,5 +1,4 @@
import { XmlComponent } from "@file/xml-components";
import { ChildNonVisualProperties } from "./child-non-visual-pic-properties/child-non-visual-pic-properties";
import { NonVisualProperties } from "./non-visual-properties/non-visual-properties";

View File

@ -1,6 +1,6 @@
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
import { createHyperlinkClick } from "@file/drawing/doc-properties/doc-properties-children";
import { ConcreteHyperlink } from "@file/paragraph";
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";

View File

@ -5,8 +5,8 @@ import { XmlComponent } from "@file/xml-components";
import { BlipFill } from "./blip/blip-fill";
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
import { PicAttributes } from "./pic-attributes";
import { OutlineOptions } from "./shape-properties/outline/outline";
import { ShapeProperties } from "./shape-properties/shape-properties";
import { OutlineOptions } from "./shape-properties/outline/outline";
export class Pic extends XmlComponent {
public constructor({

View File

@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { Form } from "./form/form";
describe("Form", () => {

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/drwSp-size.php
import { XmlComponent } from "@file/xml-components";
import { ExtentsAttributes } from "./extents-attributes";
export class Extents extends XmlComponent {

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/drwSp-size.php
import { XmlComponent } from "@file/xml-components";
import { OffsetAttributes } from "./off-attributes";
export class Offset extends XmlComponent {

View File

@ -1,9 +1,8 @@
// http://officeopenxml.com/drwSp-outline.php
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { createNoFill } from "./no-fill";
import { SchemeColor } from "./scheme-color";
import { createSolidFill } from "./solid-fill";
import { SchemeColor } from "./scheme-color";
// <xsd:complexType name="CT_TextOutlineEffect">
// <xsd:sequence>

View File

@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { SchemeColor } from "./scheme-color";
import { createSolidFill } from "./solid-fill";
import { SchemeColor } from "./scheme-color";
describe("createSolidFill", () => {
it("should create of rgb", () => {

View File

@ -1,7 +1,7 @@
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { createSchemeColor, SchemeColor } from "./scheme-color";
import { createSolidRgbColor } from "./rgb-color";
import { SchemeColor, createSchemeColor } from "./scheme-color";
export type RgbColorOptions = {
readonly type: "rgb";

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/drwSp-prstGeom.php
import { XmlComponent } from "@file/xml-components";
import { AdjustmentValues } from "./adjustment-values/adjustment-values";
import { PresetGeometryAttributes } from "./preset-geometry-attributes";

View File

@ -1,12 +1,11 @@
// http://officeopenxml.com/drwSp-SpPr.php
import { IMediaDataTransformation } from "@file/media";
import { XmlComponent } from "@file/xml-components";
import { Form } from "./form";
import { createNoFill } from "./outline/no-fill";
import { OutlineOptions, createOutline } from "./outline/outline";
import { PresetGeometry } from "./preset-geometry/preset-geometry";
import { ShapePropertiesAttributes } from "./shape-properties-attributes";
import { createNoFill } from "./outline/no-fill";
export class ShapeProperties extends XmlComponent {
private readonly form: Form;

View File

@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import { Formatter } from "@export/formatter";
import { createInline } from "./inline";
describe("Inline", () => {

View File

@ -1,7 +1,6 @@
// http://officeopenxml.com/drwPicInline.php
import { IMediaData, IMediaDataTransformation } from "@file/media";
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { DocProperties, DocPropertiesOptions } from "./../doc-properties/doc-properties";
import { createEffectExtent } from "./../effect-extent/effect-extent";
import { Extent } from "./../extent/extent";

View File

@ -1,6 +1,7 @@
// http://officeopenxml.com/drwPicFloating-textWrap.php
import { IDistance } from "../drawing";
/* eslint-disable @typescript-eslint/naming-convention */
export const TextWrappingType = {
NONE: 0,
SQUARE: 1,
@ -15,8 +16,10 @@ export const TextWrappingSide = {
LARGEST: "largest",
} as const;
export type ITextWrapping = {
/* eslint-enable */
export interface ITextWrapping {
readonly type: (typeof TextWrappingType)[keyof typeof TextWrappingType];
readonly side?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
readonly margins?: IDistance;
};
}

View File

@ -5,9 +5,9 @@ import { IDistance } from "../drawing";
import { IMargins } from "../floating";
import { ITextWrapping, TextWrappingSide } from "./text-wrapping";
type IWrapSquareAttributes = {
interface IWrapSquareAttributes extends IDistance {
readonly wrapText?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide];
} & IDistance;
}
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
protected readonly xmlKeys = {

View File

@ -479,41 +479,4 @@ describe("File", () => {
expect(doc.Styles).to.not.be.undefined;
});
});
describe("#features", () => {
it("should work with updateFields", () => {
const doc = new File({
sections: [],
features: {
updateFields: true,
},
});
expect(doc.Styles).to.not.be.undefined;
});
it("should work with trackRevisions", () => {
const doc = new File({
sections: [],
features: {
trackRevisions: true,
},
});
expect(doc.Styles).to.not.be.undefined;
});
});
describe("#hyphenation", () => {
it("should work with autoHyphenation", () => {
const doc = new File({
sections: [],
hyphenation: {
autoHyphenation: true,
},
});
expect(doc.Styles).to.not.be.undefined;
});
});
});

View File

@ -2,10 +2,8 @@ import { AppProperties } from "./app-properties/app-properties";
import { ContentTypes } from "./content-types/content-types";
import { CoreProperties, IPropertiesOptions } from "./core-properties";
import { CustomProperties } from "./custom-properties";
import { HeaderFooterReferenceType, ISectionPropertiesOptions } from "./document/body/section-properties";
import { DocumentWrapper } from "./document-wrapper";
import { FileChild } from "./file-child";
import { FontWrapper } from "./fonts/font-wrapper";
import { HeaderFooterReferenceType, ISectionPropertiesOptions } from "./document/body/section-properties";
import { FooterWrapper, IDocumentFooter } from "./footer-wrapper";
import { FootnotesWrapper } from "./footnotes-wrapper";
import { Footer, Header } from "./header";
@ -18,8 +16,10 @@ import { Settings } from "./settings";
import { Styles } from "./styles";
import { ExternalStylesFactory } from "./styles/external-styles-factory";
import { DefaultStylesFactory } from "./styles/factory";
import { FileChild } from "./file-child";
import { FontWrapper } from "./fonts/font-wrapper";
export type ISectionOptions = {
export interface ISectionOptions {
readonly headers?: {
readonly default?: Header;
readonly first?: Header;
@ -32,7 +32,7 @@ export type ISectionOptions = {
};
readonly properties?: ISectionPropertiesOptions;
readonly children: readonly FileChild[];
};
}
export class File {
// eslint-disable-next-line functional/prefer-readonly-type
@ -85,7 +85,7 @@ export class File {
hyphenationZone: options.hyphenation?.hyphenationZone,
consecutiveHyphenLimit: options.hyphenation?.consecutiveHyphenLimit,
doNotHyphenateCaps: options.hyphenation?.doNotHyphenateCaps,
},
}
});
this.media = new Media();

View File

@ -1,8 +1,8 @@
import { BuilderElement, XmlComponent } from "@file/xml-components";
import { createRegularFont } from "./create-regular-font";
import { CharacterSet } from "./font";
import { FontOptionsWithKey } from "./font-wrapper";
import { CharacterSet } from "./font";
// <xsd:complexType name="CT_FontsList">
// <xsd:sequence>

View File

@ -1,4 +1,4 @@
import { BuilderElement, OnOffElement, XmlComponent, createStringElement } from "@file/xml-components";
import { BuilderElement, createStringElement, OnOffElement, XmlComponent } from "@file/xml-components";
// <xsd:complexType name="CT_Font">
// <xsd:sequence>
@ -27,7 +27,7 @@ import { BuilderElement, OnOffElement, XmlComponent, createStringElement } from
// </xsd:complexType>
// http://www.datypic.com/sc/ooxml/e-w_embedRegular-1.html
export type IFontRelationshipOptions = {
export interface IFontRelationshipOptions {
/**
* Relationship to Part
*/
@ -40,7 +40,7 @@ export type IFontRelationshipOptions = {
* Embedded Font Is Subsetted
*/
readonly subsetted?: boolean;
};
}
export const CharacterSet = {
ANSI: "00",

View File

@ -8,10 +8,10 @@ import { Paragraph } from "./paragraph";
import { Relationships } from "./relationships";
import { Table } from "./table";
export type IDocumentFooter = {
export interface IDocumentFooter {
readonly footer: FooterWrapper;
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
};
}
export class FooterWrapper implements IViewWrapper {
private readonly footer: Footer;

View File

@ -1,6 +1,5 @@
// http://officeopenxml.com/WPfooters.php
import { InitializableXmlComponent, XmlComponent } from "@file/xml-components";
import { Paragraph } from "../paragraph";
import { Table } from "../table";
import { FooterAttributes } from "./footer-attributes";

View File

@ -6,15 +6,15 @@ import { FootnoteRefRun } from "./run/footnote-ref-run";
export const FootnoteType = {
SEPERATOR: "separator",
// eslint-disable-next-line @typescript-eslint/naming-convention
CONTINUATION_SEPERATOR: "continuationSeparator",
} as const;
export type IFootnoteOptions = {
export interface IFootnoteOptions {
readonly id: number;
readonly type?: (typeof FootnoteType)[keyof typeof FootnoteType];
readonly children: readonly Paragraph[];
};
}
export class Footnote extends XmlComponent {
public constructor(options: IFootnoteOptions) {

View File

@ -1,5 +1,4 @@
import { Run } from "@file/paragraph";
import { ContinuationSeperator } from "./continuation-seperator";
export class ContinuationSeperatorRun extends Run {

Some files were not shown because too many files have changed in this diff Show More