ts-d2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +109 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 spa5k
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# ts-d2
|
|
2
|
+
|
|
3
|
+
This is the TypeScript version of the [Deuterium](https://www.d2lib.io) library.
|
|
4
|
+
|
|
5
|
+
Deuterium is a "document as code" library, which allows you to create format-independent documents, which then are converted into a specific format using the three components DocFrame, docPIPE and docTYPE.
|
|
6
|
+
|
|
7
|
+
The following output formats are supported:
|
|
8
|
+
* HTML
|
|
9
|
+
* PDF (including PDF/UA support)
|
|
10
|
+
* Plaintext
|
|
11
|
+
* Images (BMP, PNG and more)
|
|
12
|
+
* PostScript
|
|
13
|
+
|
|
14
|
+
This is a small example creating a document with the content "Hello World" as PDF:
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import * as fs from "fs";
|
|
18
|
+
import Deuterium from "ts-d2";
|
|
19
|
+
|
|
20
|
+
new Deuterium.Content.Document("Hello World")
|
|
21
|
+
.convertTo(Deuterium.OutputFormat.PDF)
|
|
22
|
+
.then(async (buffer) => {
|
|
23
|
+
// save blob to file
|
|
24
|
+
fs.writeFileSync("output.pdf", Buffer.from(await buffer.arrayBuffer()));
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
# Basics
|
|
29
|
+
|
|
30
|
+
Documents are divided into DocumentElements, which are the smallest part of a document (like text, vertical space, etc.).
|
|
31
|
+
|
|
32
|
+
DocumentElements also may be branch elements and therefore have child-elements (like tables, paragraphs, etc.).
|
|
33
|
+
|
|
34
|
+
DocumentElements may be grouped together to a document, which then may be converted to the desired output format.
|
|
35
|
+
|
|
36
|
+
All the supported DocumentElements are placed in the package `Deuterium.Content`.
|
|
37
|
+
|
|
38
|
+
## Leaf elements
|
|
39
|
+
|
|
40
|
+
The following leaf elements are currently supported:
|
|
41
|
+
* Barcode
|
|
42
|
+
* ColumnDefinition (only useful for page-based formats)
|
|
43
|
+
* Directory
|
|
44
|
+
* Footer
|
|
45
|
+
* Formatted (may be used to directly insert docTYPE code and/or HTML code)
|
|
46
|
+
* Header
|
|
47
|
+
* Pagebreak
|
|
48
|
+
* PageDefinition (only useful for page-based formats)
|
|
49
|
+
* Paragraph
|
|
50
|
+
* SpaceVertically
|
|
51
|
+
* Span
|
|
52
|
+
* Table
|
|
53
|
+
* TableCell
|
|
54
|
+
* TableRow
|
|
55
|
+
* Text
|
|
56
|
+
|
|
57
|
+
Any leaf element may be added to multiple branch elements (there is no connection from a leaf element to its parent element).
|
|
58
|
+
|
|
59
|
+
### Text
|
|
60
|
+
|
|
61
|
+
To create a text element you may use the following code:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
new Deuterium.Content.Text("Hello World!")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The text may then be added to any branch element.
|
|
68
|
+
|
|
69
|
+
When creating branch elements, you may also pass strings directly in order to create a text element.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
new Deuterium.Content.Span("Hello World!", {
|
|
73
|
+
bold: true
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Branch elements
|
|
78
|
+
|
|
79
|
+
Branch elements have two functionalities:
|
|
80
|
+
* Group elements together (like Directory)
|
|
81
|
+
* Apply formatting/properties to their child elements.
|
|
82
|
+
|
|
83
|
+
The following branch elements are supported:
|
|
84
|
+
* Directory
|
|
85
|
+
* Document
|
|
86
|
+
* Footer
|
|
87
|
+
* Formatted
|
|
88
|
+
* Header
|
|
89
|
+
* Paragraph
|
|
90
|
+
* Span
|
|
91
|
+
* Table
|
|
92
|
+
* TableCell
|
|
93
|
+
* TableRow
|
|
94
|
+
|
|
95
|
+
### Content parameter
|
|
96
|
+
|
|
97
|
+
When creating branch document elements, the first parameter is the so called "content" parameter, which is used to define the child elements of the new branch document element.
|
|
98
|
+
|
|
99
|
+
The content parameter may be one of the following:
|
|
100
|
+
|
|
101
|
+
* string -> Creates a Text Document Element for the given string
|
|
102
|
+
* DocumentElement -> Just uses the passed DocumentElement
|
|
103
|
+
* (DocumentElement | string)[] -> Uses all the passed DocumentElements (and converts passed strings to Text objects)
|
|
104
|
+
|
|
105
|
+
Especially the first variant of the content parameter can result in small code:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
new Deuterium.Content.Footer("...");
|
|
109
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-d2",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Deuterium is a TypeScript library for professional output creation.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pdf",
|
|
7
|
+
"postscript",
|
|
8
|
+
"output",
|
|
9
|
+
"formatting",
|
|
10
|
+
"rendering",
|
|
11
|
+
"typescript",
|
|
12
|
+
"document"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://d2lib.io",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/documatrix/ts-d2/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/documatrix/ts-d2.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "DocuMatrix GmbH",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.esm.js",
|
|
26
|
+
"typings": "dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "cross-env NODE_ENV=production tsup-node",
|
|
32
|
+
"build:dev": " cross-env NODE_ENV=development tsup-node",
|
|
33
|
+
"format": "dprint fmt",
|
|
34
|
+
"lint": "eslint src --ext .ts",
|
|
35
|
+
"prepare": "husky",
|
|
36
|
+
"test": "jest"
|
|
37
|
+
},
|
|
38
|
+
"husky": {
|
|
39
|
+
"hooks": {
|
|
40
|
+
"pre-commit": "pnpm format && pnpm lint",
|
|
41
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"commitlint": {
|
|
45
|
+
"extends": [
|
|
46
|
+
"@commitlint/config-conventional"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
51
|
+
"@commitlint/cli": "19.8.0",
|
|
52
|
+
"@commitlint/config-conventional": "19.8.0",
|
|
53
|
+
"@jest/globals": "^29.5.0",
|
|
54
|
+
"@swc/core": "^1.11.9",
|
|
55
|
+
"@swc/helpers": "^0.5.15",
|
|
56
|
+
"@types/jest": "^29.5.14",
|
|
57
|
+
"@types/node": "22.13.10",
|
|
58
|
+
"@types/uuid": "^10.0.0",
|
|
59
|
+
"typescript-eslint": "8.26.1",
|
|
60
|
+
"cross-env": "^7.0.3",
|
|
61
|
+
"dotenv": "16.4.7",
|
|
62
|
+
"dprint": "^0.49.0",
|
|
63
|
+
"esbuild": "0.25.1",
|
|
64
|
+
"eslint": "9.22.0",
|
|
65
|
+
"husky": "^9.1.7",
|
|
66
|
+
"jest": "^29.7.0",
|
|
67
|
+
"semantic-release": "24.2.3",
|
|
68
|
+
"ts-jest": "^29.2.6",
|
|
69
|
+
"tslib": "2.8.1",
|
|
70
|
+
"tsup": "8.4.0",
|
|
71
|
+
"typescript": "5.8.2",
|
|
72
|
+
"uuid": "^11.1.0"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"axios": "^1.8.3",
|
|
76
|
+
"docframe-types": "^0.4.2",
|
|
77
|
+
"form-data": "^4.0.2"
|
|
78
|
+
}
|
|
79
|
+
}
|