@oicana/node 0.1.0-alpha.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.md +131 -0
- package/README.md +9 -0
- package/biome.json +35 -0
- package/dist/CompilationMode.d.ts +4 -0
- package/dist/CompilationMode.js +6 -0
- package/dist/CompilationMode.js.map +1 -0
- package/dist/ExportFormat.d.ts +9 -0
- package/dist/ExportFormat.js +7 -0
- package/dist/ExportFormat.js.map +1 -0
- package/dist/Template.d.ts +54 -0
- package/dist/Template.js +67 -0
- package/dist/Template.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs/BlobInput.d.ts +17 -0
- package/dist/inputs/BlobInput.js +2 -0
- package/dist/inputs/BlobInput.js.map +1 -0
- package/dist/inputs/JsonInput.d.ts +5 -0
- package/dist/inputs/JsonInput.js +2 -0
- package/dist/inputs/JsonInput.js.map +1 -0
- package/dist/inputs/index.d.ts +7 -0
- package/dist/inputs/index.js +2 -0
- package/dist/inputs/index.js.map +1 -0
- package/package.json +39 -0
- package/src/CompilationMode.ts +4 -0
- package/src/ExportFormat.ts +10 -0
- package/src/Template.ts +162 -0
- package/src/index.ts +4 -0
- package/src/inputs/BlobInput.ts +20 -0
- package/src/inputs/JsonInput.ts +5 -0
- package/src/inputs/index.ts +9 -0
- package/tsconfig.json +21 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncommercial Purposes
|
|
53
|
+
|
|
54
|
+
Any noncommercial purpose is a permitted purpose.
|
|
55
|
+
|
|
56
|
+
## Personal Uses
|
|
57
|
+
|
|
58
|
+
Personal use for research, experiment, and testing for
|
|
59
|
+
the benefit of public knowledge, personal study, private
|
|
60
|
+
entertainment, hobby projects, amateur pursuits, or religious
|
|
61
|
+
observance, without any anticipated commercial application,
|
|
62
|
+
is use for a permitted purpose.
|
|
63
|
+
|
|
64
|
+
## Noncommercial Organizations
|
|
65
|
+
|
|
66
|
+
Use by any charitable organization, educational institution,
|
|
67
|
+
public research organization, public safety or health
|
|
68
|
+
organization, environmental protection organization,
|
|
69
|
+
or government institution is use for a permitted purpose
|
|
70
|
+
regardless of the source of funding or obligations resulting
|
|
71
|
+
from the funding.
|
|
72
|
+
|
|
73
|
+
## Fair Use
|
|
74
|
+
|
|
75
|
+
You may have "fair use" rights for the software under the
|
|
76
|
+
law. These terms do not limit them.
|
|
77
|
+
|
|
78
|
+
## No Other Rights
|
|
79
|
+
|
|
80
|
+
These terms do not allow you to sublicense or transfer any of
|
|
81
|
+
your licenses to anyone else, or prevent the licensor from
|
|
82
|
+
granting licenses to anyone else. These terms do not imply
|
|
83
|
+
any other licenses.
|
|
84
|
+
|
|
85
|
+
## Patent Defense
|
|
86
|
+
|
|
87
|
+
If you make any written claim that the software infringes or
|
|
88
|
+
contributes to infringement of any patent, your patent license
|
|
89
|
+
for the software granted under these terms ends immediately. If
|
|
90
|
+
your company makes such a claim, your patent license ends
|
|
91
|
+
immediately for work on behalf of your company.
|
|
92
|
+
|
|
93
|
+
## Violations
|
|
94
|
+
|
|
95
|
+
The first time you are notified in writing that you have
|
|
96
|
+
violated any of these terms, or done anything with the software
|
|
97
|
+
not covered by your licenses, your licenses can nonetheless
|
|
98
|
+
continue if you come into full compliance with these terms,
|
|
99
|
+
and take practical steps to correct past violations, within
|
|
100
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
101
|
+
end immediately.
|
|
102
|
+
|
|
103
|
+
## No Liability
|
|
104
|
+
|
|
105
|
+
***As far as the law allows, the software comes as is, without
|
|
106
|
+
any warranty or condition, and the licensor will not be liable
|
|
107
|
+
to you for any damages arising out of these terms or the use
|
|
108
|
+
or nature of the software, under any kind of legal claim.***
|
|
109
|
+
|
|
110
|
+
## Definitions
|
|
111
|
+
|
|
112
|
+
The **licensor** is the individual or entity offering these
|
|
113
|
+
terms, and the **software** is the software the licensor makes
|
|
114
|
+
available under these terms.
|
|
115
|
+
|
|
116
|
+
**You** refers to the individual or entity agreeing to these
|
|
117
|
+
terms.
|
|
118
|
+
|
|
119
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
120
|
+
or other kind of organization that you work for, plus all
|
|
121
|
+
organizations that have control over, are under the control of,
|
|
122
|
+
or are under common control with that organization. **Control**
|
|
123
|
+
means ownership of substantially all the assets of an entity,
|
|
124
|
+
or the power to direct its management and policies by vote,
|
|
125
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
126
|
+
|
|
127
|
+
**Your licenses** are all the licenses granted to you for the
|
|
128
|
+
software under these terms.
|
|
129
|
+
|
|
130
|
+
**Use** means anything you do with the software requiring one
|
|
131
|
+
of your licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Oicana
|
|
2
|
+
*Dynamic PDF Generation based on Typst*
|
|
3
|
+
|
|
4
|
+
https://oicana.com
|
|
5
|
+
|
|
6
|
+
Oicana offers seamless PDF templating across multiple platforms. Define your templates in Typst, specify dynamic inputs, and generate high quality PDFs from any environment - whether it's a web browser, server application, or desktop software.
|
|
7
|
+
|
|
8
|
+
> **Oicana is in Alpha! It is rough around the edges and has a limited number of integrations.**
|
|
9
|
+
|
package/biome.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": false,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": false
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false,
|
|
10
|
+
"includes": ["**", "!**/dist"]
|
|
11
|
+
},
|
|
12
|
+
"formatter": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"indentStyle": "space"
|
|
15
|
+
},
|
|
16
|
+
"linter": {
|
|
17
|
+
"enabled": true,
|
|
18
|
+
"rules": {
|
|
19
|
+
"recommended": true
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"javascript": {
|
|
23
|
+
"formatter": {
|
|
24
|
+
"quoteStyle": "single"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"assist": {
|
|
28
|
+
"enabled": true,
|
|
29
|
+
"actions": {
|
|
30
|
+
"source": {
|
|
31
|
+
"organizeImports": "on"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompilationMode.js","sourceRoot":"","sources":["../src/CompilationMode.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,8CAA2B,CAAA;IAC3B,4CAAyB,CAAA;AAC3B,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportFormat.js","sourceRoot":"","sources":["../src/ExportFormat.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,GAAG,GAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACnD,MAAM,CAAC,MAAM,GAAG,GAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACnD,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,WAAmB,EAAgB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,KAAK;IACb,WAAW;CACZ,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CompilationMode } from './CompilationMode';
|
|
2
|
+
import type { ExportFormat } from './ExportFormat';
|
|
3
|
+
import type { BlobWithMetadata } from './inputs';
|
|
4
|
+
/**
|
|
5
|
+
* A template
|
|
6
|
+
*
|
|
7
|
+
* The zip file is loaded during the instance creation and cached afterward.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Template {
|
|
10
|
+
private readonly template;
|
|
11
|
+
private defaultCompilationMode;
|
|
12
|
+
/**
|
|
13
|
+
* Register a template with the given name and template file
|
|
14
|
+
* @param name of the template
|
|
15
|
+
* @param template - the packed Oicana template file
|
|
16
|
+
*/
|
|
17
|
+
constructor(name: string, template: Uint8Array);
|
|
18
|
+
/**
|
|
19
|
+
* Register a template with the given name, template file, and inputs
|
|
20
|
+
* @param name of the template
|
|
21
|
+
* @param template - the packed Oicana template file
|
|
22
|
+
* @param jsonInputs for the initial rendering to warm up the cache
|
|
23
|
+
* @param blobInputs for the initial rendering to warm up the cache
|
|
24
|
+
*/
|
|
25
|
+
constructor(name: string, template: Uint8Array, jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>);
|
|
26
|
+
/**
|
|
27
|
+
* Compile the template to a PDF file without any inputs in production mode
|
|
28
|
+
*/
|
|
29
|
+
compile(): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Compile the template to a PDF file with given inputs in production mode
|
|
32
|
+
* @param jsonInputs
|
|
33
|
+
* @param blobInputs
|
|
34
|
+
*/
|
|
35
|
+
compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Compile the template with the given inputs
|
|
38
|
+
* @param jsonInputs
|
|
39
|
+
* @param blobInputs
|
|
40
|
+
* @param exportFormat
|
|
41
|
+
*/
|
|
42
|
+
compile(jsonInputs: Map<string, string>, blobInputs: Map<string, BlobWithMetadata>, exportFormat: ExportFormat): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Get the default compilation mode of this template
|
|
45
|
+
*/
|
|
46
|
+
defaultMode(): CompilationMode;
|
|
47
|
+
/**
|
|
48
|
+
* Set the default compilation mode of this template
|
|
49
|
+
* @param compilationMode to use as default when compiling this template
|
|
50
|
+
*/
|
|
51
|
+
setDefaultMode(compilationMode: CompilationMode): void;
|
|
52
|
+
private convertBlobWithMetadata;
|
|
53
|
+
private mapCompilationMode;
|
|
54
|
+
}
|
package/dist/Template.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { compileTemplate, registerTemplate, } from '@oicana/node-native';
|
|
2
|
+
import { CompilationMode } from './CompilationMode';
|
|
3
|
+
/**
|
|
4
|
+
* A template
|
|
5
|
+
*
|
|
6
|
+
* The zip file is loaded during the instance creation and cached afterward.
|
|
7
|
+
*/
|
|
8
|
+
export class Template {
|
|
9
|
+
template;
|
|
10
|
+
defaultCompilationMode;
|
|
11
|
+
/**
|
|
12
|
+
* Register a template with the given name, template file, and inputs
|
|
13
|
+
* @param name of the template
|
|
14
|
+
* @param template - the packed Oicana template file
|
|
15
|
+
* @param jsonInputs for the initial rendering to warm up the cache
|
|
16
|
+
* @param blobInputs for the initial rendering to warm up the cache
|
|
17
|
+
* @param compilation mode for the initial rendering to warm up the cache
|
|
18
|
+
*/
|
|
19
|
+
constructor(name, template, jsonInputs, blobInputs, compilationMode) {
|
|
20
|
+
this.template = name;
|
|
21
|
+
this.defaultCompilationMode = CompilationMode.Production;
|
|
22
|
+
const format = { format: 'pdf' };
|
|
23
|
+
registerTemplate(this.template, template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), JSON.stringify(format), this.mapCompilationMode(compilationMode ?? CompilationMode.Development));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compile the template with the given inputs
|
|
27
|
+
* @param jsonInputs
|
|
28
|
+
* @param blobInputs
|
|
29
|
+
* @param exportFormat
|
|
30
|
+
* @param compilationMode
|
|
31
|
+
*/
|
|
32
|
+
compile(jsonInputs, blobInputs, exportFormat, compilationMode) {
|
|
33
|
+
const format = exportFormat ?? { format: 'pdf' };
|
|
34
|
+
return compileTemplate(this.template, Object.fromEntries(jsonInputs ?? new Map()), this.convertBlobWithMetadata(blobInputs ?? new Map()), JSON.stringify(format), this.mapCompilationMode(compilationMode ?? CompilationMode.Production));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the default compilation mode of this template
|
|
38
|
+
*/
|
|
39
|
+
defaultMode() {
|
|
40
|
+
return this.defaultCompilationMode;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the default compilation mode of this template
|
|
44
|
+
* @param compilationMode to use as default when compiling this template
|
|
45
|
+
*/
|
|
46
|
+
setDefaultMode(compilationMode) {
|
|
47
|
+
this.defaultCompilationMode = compilationMode;
|
|
48
|
+
}
|
|
49
|
+
convertBlobWithMetadata(blobInputs) {
|
|
50
|
+
return Object.fromEntries(Array.from(blobInputs.entries(), ([key, value]) => {
|
|
51
|
+
const nativeValue = {
|
|
52
|
+
bytes: value.bytes,
|
|
53
|
+
meta: value.meta === undefined ? '{}' : JSON.stringify(value.meta),
|
|
54
|
+
};
|
|
55
|
+
return [key, nativeValue];
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
mapCompilationMode(mode) {
|
|
59
|
+
switch (mode) {
|
|
60
|
+
case CompilationMode.Development:
|
|
61
|
+
return 1 /* NativeCompilationMode.Development */;
|
|
62
|
+
case CompilationMode.Production:
|
|
63
|
+
return 0 /* NativeCompilationMode.Production */;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=Template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACF,QAAQ,CAAS;IAC1B,sBAAsB,CAAkB;IAuBhD;;;;;;;OAOG;IACH,YACE,IAAY,EACZ,QAAoB,EACpB,UAAgC,EAChC,UAA0C,EAC1C,eAAiC;QAEjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,sBAAsB,GAAG,eAAe,CAAC,UAAU,CAAC;QACzD,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAEjC,gBAAgB,CACd,IAAI,CAAC,QAAQ,EACb,QAAQ,EACR,MAAM,CAAC,WAAW,CAAC,UAAU,IAAI,IAAI,GAAG,EAAkB,CAAC,EAC3D,IAAI,CAAC,uBAAuB,CAC1B,UAAU,IAAI,IAAI,GAAG,EAA4B,CAClD,EACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EACtB,IAAI,CAAC,kBAAkB,CAAC,eAAe,IAAI,eAAe,CAAC,WAAW,CAAC,CACxE,CAAC;IACJ,CAAC;IA6BD;;;;;;OAMG;IACI,OAAO,CACZ,UAAgC,EAChC,UAA0C,EAC1C,YAA2B,EAC3B,eAAiC;QAEjC,MAAM,MAAM,GAAiB,YAAY,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAE/D,OAAO,eAAe,CACpB,IAAI,CAAC,QAAQ,EACb,MAAM,CAAC,WAAW,CAAC,UAAU,IAAI,IAAI,GAAG,EAAkB,CAAC,EAC3D,IAAI,CAAC,uBAAuB,CAC1B,UAAU,IAAI,IAAI,GAAG,EAA4B,CAClD,EACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EACtB,IAAI,CAAC,kBAAkB,CAAC,eAAe,IAAI,eAAe,CAAC,UAAU,CAAC,CACvE,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,sBAAsB,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,cAAc,CAAC,eAAgC;QACpD,IAAI,CAAC,sBAAsB,GAAG,eAAe,CAAC;IAChD,CAAC;IAEO,uBAAuB,CAC7B,UAAyC;QAEzC,OAAO,MAAM,CAAC,WAAW,CACvB,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAChD,MAAM,WAAW,GAAG;gBAClB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;aACnE,CAAC;YACF,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,kBAAkB,CAAC,IAAqB;QAC9C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,eAAe,CAAC,WAAW;gBAC9B,iDAAyC;YAC3C,KAAK,eAAe,CAAC,UAAU;gBAC7B,gDAAwC;QAC5C,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface BlobWithMetadata {
|
|
2
|
+
bytes: Uint8Array;
|
|
3
|
+
meta?: {
|
|
4
|
+
image_format?: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface BlobInputDefinition {
|
|
9
|
+
key: string;
|
|
10
|
+
default: {
|
|
11
|
+
file: string;
|
|
12
|
+
meta?: {
|
|
13
|
+
image_format?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlobInput.js","sourceRoot":"","sources":["../../src/inputs/BlobInput.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonInput.js","sourceRoot":"","sources":["../../src/inputs/JsonInput.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BlobInputDefinition, BlobWithMetadata } from './BlobInput';
|
|
2
|
+
import { JsonInputDefinition } from './JsonInput';
|
|
3
|
+
export { JsonInputDefinition, BlobInputDefinition, BlobWithMetadata };
|
|
4
|
+
export interface Inputs {
|
|
5
|
+
json: JsonInputDefinition[];
|
|
6
|
+
blob: BlobInputDefinition[];
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/inputs/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oicana/node",
|
|
3
|
+
"author": "Oicana <hello@oicana.com>",
|
|
4
|
+
"version": "0.1.0-alpha.1",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"readme": "README.md",
|
|
8
|
+
"license": "PolyForm-Noncommercial-1.0.0",
|
|
9
|
+
"homepage": "https://oicana.com",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/oicana/oicana.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/oicana/oicana/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"format": "biome check --write",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"lint": "biome ci"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@oicana/node-native": "0.1.0-alpha.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@biomejs/biome": "2.2.4",
|
|
29
|
+
"@types/node": "24.6.2",
|
|
30
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
31
|
+
"globals": "15.9.0",
|
|
32
|
+
"jsdom": "26.1.0",
|
|
33
|
+
"typescript": "5.7.3",
|
|
34
|
+
"vite": "7.1.3",
|
|
35
|
+
"vite-plugin-top-level-await": "1.6.0",
|
|
36
|
+
"vite-plugin-wasm": "3.5.0",
|
|
37
|
+
"vitest": "3.2.4"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ExportFormat =
|
|
2
|
+
| { format: 'pdf' | 'svg' }
|
|
3
|
+
| { format: 'png'; pixelsPerPt: number };
|
|
4
|
+
|
|
5
|
+
export const Pdf: ExportFormat = { format: 'pdf' };
|
|
6
|
+
export const Svg: ExportFormat = { format: 'svg' };
|
|
7
|
+
export const Png = (pixelsPerPt: number): ExportFormat => ({
|
|
8
|
+
format: 'png',
|
|
9
|
+
pixelsPerPt,
|
|
10
|
+
});
|
package/src/Template.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlobWithMetadata as BlobWithMetadataNative,
|
|
3
|
+
compileTemplate,
|
|
4
|
+
CompilationMode as NativeCompilationMode,
|
|
5
|
+
registerTemplate,
|
|
6
|
+
} from '@oicana/node-native';
|
|
7
|
+
import { CompilationMode } from './CompilationMode';
|
|
8
|
+
import type { ExportFormat } from './ExportFormat';
|
|
9
|
+
import type { BlobWithMetadata } from './inputs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A template
|
|
13
|
+
*
|
|
14
|
+
* The zip file is loaded during the instance creation and cached afterward.
|
|
15
|
+
*/
|
|
16
|
+
export class Template {
|
|
17
|
+
private readonly template: string;
|
|
18
|
+
private defaultCompilationMode: CompilationMode;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Register a template with the given name and template file
|
|
22
|
+
* @param name of the template
|
|
23
|
+
* @param template - the packed Oicana template file
|
|
24
|
+
*/
|
|
25
|
+
public constructor(name: string, template: Uint8Array);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register a template with the given name, template file, and inputs
|
|
29
|
+
* @param name of the template
|
|
30
|
+
* @param template - the packed Oicana template file
|
|
31
|
+
* @param jsonInputs for the initial rendering to warm up the cache
|
|
32
|
+
* @param blobInputs for the initial rendering to warm up the cache
|
|
33
|
+
*/
|
|
34
|
+
public constructor(
|
|
35
|
+
name: string,
|
|
36
|
+
template: Uint8Array,
|
|
37
|
+
jsonInputs: Map<string, string>,
|
|
38
|
+
blobInputs: Map<string, BlobWithMetadata>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Register a template with the given name, template file, and inputs
|
|
43
|
+
* @param name of the template
|
|
44
|
+
* @param template - the packed Oicana template file
|
|
45
|
+
* @param jsonInputs for the initial rendering to warm up the cache
|
|
46
|
+
* @param blobInputs for the initial rendering to warm up the cache
|
|
47
|
+
* @param compilation mode for the initial rendering to warm up the cache
|
|
48
|
+
*/
|
|
49
|
+
public constructor(
|
|
50
|
+
name: string,
|
|
51
|
+
template: Uint8Array,
|
|
52
|
+
jsonInputs?: Map<string, string>,
|
|
53
|
+
blobInputs?: Map<string, BlobWithMetadata>,
|
|
54
|
+
compilationMode?: CompilationMode,
|
|
55
|
+
) {
|
|
56
|
+
this.template = name;
|
|
57
|
+
this.defaultCompilationMode = CompilationMode.Production;
|
|
58
|
+
const format = { format: 'pdf' };
|
|
59
|
+
|
|
60
|
+
registerTemplate(
|
|
61
|
+
this.template,
|
|
62
|
+
template,
|
|
63
|
+
Object.fromEntries(jsonInputs ?? new Map<string, string>()),
|
|
64
|
+
this.convertBlobWithMetadata(
|
|
65
|
+
blobInputs ?? new Map<string, BlobWithMetadata>(),
|
|
66
|
+
),
|
|
67
|
+
JSON.stringify(format),
|
|
68
|
+
this.mapCompilationMode(compilationMode ?? CompilationMode.Development),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Compile the template to a PDF file without any inputs in production mode
|
|
74
|
+
*/
|
|
75
|
+
public compile(): Uint8Array;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Compile the template to a PDF file with given inputs in production mode
|
|
79
|
+
* @param jsonInputs
|
|
80
|
+
* @param blobInputs
|
|
81
|
+
*/
|
|
82
|
+
public compile(
|
|
83
|
+
jsonInputs: Map<string, string>,
|
|
84
|
+
blobInputs: Map<string, BlobWithMetadata>,
|
|
85
|
+
): Uint8Array;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Compile the template with the given inputs
|
|
89
|
+
* @param jsonInputs
|
|
90
|
+
* @param blobInputs
|
|
91
|
+
* @param exportFormat
|
|
92
|
+
*/
|
|
93
|
+
public compile(
|
|
94
|
+
jsonInputs: Map<string, string>,
|
|
95
|
+
blobInputs: Map<string, BlobWithMetadata>,
|
|
96
|
+
exportFormat: ExportFormat,
|
|
97
|
+
): Uint8Array;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compile the template with the given inputs
|
|
101
|
+
* @param jsonInputs
|
|
102
|
+
* @param blobInputs
|
|
103
|
+
* @param exportFormat
|
|
104
|
+
* @param compilationMode
|
|
105
|
+
*/
|
|
106
|
+
public compile(
|
|
107
|
+
jsonInputs?: Map<string, string>,
|
|
108
|
+
blobInputs?: Map<string, BlobWithMetadata>,
|
|
109
|
+
exportFormat?: ExportFormat,
|
|
110
|
+
compilationMode?: CompilationMode,
|
|
111
|
+
): Uint8Array {
|
|
112
|
+
const format: ExportFormat = exportFormat ?? { format: 'pdf' };
|
|
113
|
+
|
|
114
|
+
return compileTemplate(
|
|
115
|
+
this.template,
|
|
116
|
+
Object.fromEntries(jsonInputs ?? new Map<string, string>()),
|
|
117
|
+
this.convertBlobWithMetadata(
|
|
118
|
+
blobInputs ?? new Map<string, BlobWithMetadata>(),
|
|
119
|
+
),
|
|
120
|
+
JSON.stringify(format),
|
|
121
|
+
this.mapCompilationMode(compilationMode ?? CompilationMode.Production),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the default compilation mode of this template
|
|
127
|
+
*/
|
|
128
|
+
public defaultMode(): CompilationMode {
|
|
129
|
+
return this.defaultCompilationMode;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Set the default compilation mode of this template
|
|
134
|
+
* @param compilationMode to use as default when compiling this template
|
|
135
|
+
*/
|
|
136
|
+
public setDefaultMode(compilationMode: CompilationMode) {
|
|
137
|
+
this.defaultCompilationMode = compilationMode;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private convertBlobWithMetadata(
|
|
141
|
+
blobInputs: Map<string, BlobWithMetadata>,
|
|
142
|
+
): Record<string, BlobWithMetadataNative> {
|
|
143
|
+
return Object.fromEntries(
|
|
144
|
+
Array.from(blobInputs.entries(), ([key, value]) => {
|
|
145
|
+
const nativeValue = {
|
|
146
|
+
bytes: value.bytes,
|
|
147
|
+
meta: value.meta === undefined ? '{}' : JSON.stringify(value.meta),
|
|
148
|
+
};
|
|
149
|
+
return [key, nativeValue];
|
|
150
|
+
}),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private mapCompilationMode(mode: CompilationMode): NativeCompilationMode {
|
|
155
|
+
switch (mode) {
|
|
156
|
+
case CompilationMode.Development:
|
|
157
|
+
return NativeCompilationMode.Development;
|
|
158
|
+
case CompilationMode.Production:
|
|
159
|
+
return NativeCompilationMode.Production;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BlobWithMetadata {
|
|
2
|
+
bytes: Uint8Array;
|
|
3
|
+
meta?: {
|
|
4
|
+
image_format?: string;
|
|
5
|
+
// biome-ignore lint/suspicious/noExplicitAny: Really anything that can pe serilized and deserialized into a Typst Dict is OK
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BlobInputDefinition {
|
|
11
|
+
key: string;
|
|
12
|
+
default: {
|
|
13
|
+
file: string;
|
|
14
|
+
meta?: {
|
|
15
|
+
image_format?: string;
|
|
16
|
+
// biome-ignore lint/suspicious/noExplicitAny: Really anything that can pe serilized and deserialized into a Typst Dict is OK
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BlobInputDefinition, BlobWithMetadata } from './BlobInput';
|
|
2
|
+
import { JsonInputDefinition } from './JsonInput';
|
|
3
|
+
|
|
4
|
+
export { JsonInputDefinition, BlobInputDefinition, BlobWithMetadata };
|
|
5
|
+
|
|
6
|
+
export interface Inputs {
|
|
7
|
+
json: JsonInputDefinition[];
|
|
8
|
+
blob: BlobInputDefinition[];
|
|
9
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"sourceMap": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"module": "esnext",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"exclude": [
|
|
14
|
+
"dist/**",
|
|
15
|
+
"node_modules/**",
|
|
16
|
+
"**/*.test.ts/**",
|
|
17
|
+
"testOutput/**",
|
|
18
|
+
"test-setup.ts",
|
|
19
|
+
"vite.config.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|