ts-d2 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -44,6 +44,7 @@ The following leaf elements are currently supported:
44
44
  * Footer
45
45
  * Formatted (may be used to directly insert docTYPE code and/or HTML code)
46
46
  * Header
47
+ * Linebreak
47
48
  * Pagebreak
48
49
  * PageDefinition (only useful for page-based formats)
49
50
  * Paragraph
@@ -84,7 +85,6 @@ The following branch elements are supported:
84
85
  * Directory
85
86
  * Document
86
87
  * Footer
87
- * Formatted
88
88
  * Header
89
89
  * Paragraph
90
90
  * Span
package/dist/index.d.mts CHANGED
@@ -124,6 +124,17 @@ declare class Table extends BranchDocumentElement<TableSettings> {
124
124
  toDocFrame(): Proto.Node;
125
125
  }
126
126
 
127
+ interface SpanProperties {
128
+ bold?: boolean;
129
+ italic?: boolean;
130
+ underline?: boolean;
131
+ strikethrough?: boolean;
132
+ }
133
+ declare class Span extends BranchDocumentElement<SpanProperties> {
134
+ constructor(content?: Content, props?: SpanProperties);
135
+ toDocFrame(): Proto.Node;
136
+ }
137
+
127
138
  declare class SpaceVertically extends DocumentElement {
128
139
  space: AbsoluteMeasure;
129
140
  constructor(space: AbsoluteMeasure);
@@ -167,10 +178,6 @@ declare class Paragraph extends BranchDocumentElement<ParagraphSettings> {
167
178
  toDocFrame(): Proto.Node;
168
179
  }
169
180
 
170
- declare class Pagebreak extends DocumentElement {
171
- toDocFrame(): Proto.Node;
172
- }
173
-
174
181
  declare class PageDefinition {
175
182
  width?: AbsoluteMeasure;
176
183
  height?: AbsoluteMeasure;
@@ -179,6 +186,18 @@ declare class PageDefinition {
179
186
  toDocFrame(): Proto.ProtoPDef;
180
187
  }
181
188
 
189
+ declare class Pagebreak extends DocumentElement {
190
+ toDocFrame(): Proto.Node;
191
+ }
192
+
193
+ declare class Linebreak extends DocumentElement {
194
+ toDocFrame(): Proto.Node;
195
+ }
196
+
197
+ declare class Header extends BranchDocumentElement<never> {
198
+ toDocFrame(): Proto.Node;
199
+ }
200
+
182
201
  declare class Formatted extends DocumentElement {
183
202
  constructor(doctypeContent: string | undefined, htmlContent?: string);
184
203
  content: {
@@ -188,6 +207,10 @@ declare class Formatted extends DocumentElement {
188
207
  toDocFrame(): Proto.Node;
189
208
  }
190
209
 
210
+ declare class Footer extends BranchDocumentElement {
211
+ toDocFrame(): Proto.Node;
212
+ }
213
+
191
214
  declare enum OutputFormat {
192
215
  PDF = "pdf",
193
216
  PNG = "png",
@@ -196,7 +219,7 @@ declare enum OutputFormat {
196
219
  PS = "ps",
197
220
  TEXT = "text"
198
221
  }
199
- interface OutputParams {
222
+ type OutputParams = {
200
223
  [OutputFormat.HTML]: {};
201
224
  [OutputFormat.PDF]: {};
202
225
  [OutputFormat.JPEG]: {};
@@ -219,6 +242,13 @@ interface OutputParams {
219
242
  */
220
243
  dpi?: number;
221
244
  };
245
+ };
246
+
247
+ type Output_OutputFormat = OutputFormat;
248
+ declare const Output_OutputFormat: typeof OutputFormat;
249
+ type Output_OutputParams = OutputParams;
250
+ declare namespace Output {
251
+ export { Output_OutputFormat as OutputFormat, type Output_OutputParams as OutputParams };
222
252
  }
223
253
 
224
254
  declare class ColumnPositionMode {
@@ -246,14 +276,6 @@ declare class ColumnDefinition {
246
276
  toDocFrame(applyImmediate: boolean): Proto.Node[];
247
277
  }
248
278
 
249
- declare class Footer extends BranchDocumentElement {
250
- toDocFrame(): Proto.Node;
251
- }
252
-
253
- declare class Header extends BranchDocumentElement<never> {
254
- toDocFrame(): Proto.Node;
255
- }
256
-
257
279
  interface DocumentProperties {
258
280
  pageDefinition: PageDefinition;
259
281
  columnDefinition: ColumnDefinition;
@@ -271,6 +293,10 @@ declare class Document extends BranchDocumentElement<DocumentProperties> {
271
293
  toDocFrame(): Proto.Node;
272
294
  }
273
295
 
296
+ declare class Directory extends BranchDocumentElement {
297
+ toDocFrame(): Proto.Node;
298
+ }
299
+
274
300
  /**
275
301
  * A ReferencePoint is used for elements like barcodes to specify the reference point
276
302
  * of an object.
@@ -300,6 +326,14 @@ declare class Barcode extends DocumentElement {
300
326
  toDocFrame(): Proto.Node;
301
327
  }
302
328
 
329
+ declare class Connection {
330
+ url: string;
331
+ token: string;
332
+ constructor(url?: string, token?: string);
333
+ get docframeCallUrl(): string;
334
+ convertTo<K extends keyof OutputParams>(format: K, doc: Document, outputParams?: OutputParams[K]): Promise<Blob>;
335
+ }
336
+
303
337
  declare const _default: {
304
338
  Border: {
305
339
  Border: typeof Border;
@@ -309,16 +343,22 @@ declare const _default: {
309
343
  Color: typeof Color;
310
344
  Colors: typeof Colors;
311
345
  };
346
+ Connection: typeof Connection;
312
347
  Content: {
313
348
  Barcode: typeof Barcode;
314
349
  ColumnDefinition: typeof ColumnDefinition;
315
350
  ColumnPosition: typeof ColumnPosition;
351
+ Directory: typeof Directory;
316
352
  Document: typeof Document;
353
+ Footer: typeof Footer;
317
354
  Formatted: typeof Formatted;
318
- PageDefinition: typeof PageDefinition;
355
+ Header: typeof Header;
356
+ Linebreak: typeof Linebreak;
319
357
  Pagebreak: typeof Pagebreak;
358
+ PageDefinition: typeof PageDefinition;
320
359
  Paragraph: typeof Paragraph;
321
360
  SpaceVertically: typeof SpaceVertically;
361
+ Span: typeof Span;
322
362
  Table: typeof Table;
323
363
  TableCell: typeof TableCell;
324
364
  TableRow: typeof TableRow;
@@ -331,7 +371,7 @@ declare const _default: {
331
371
  };
332
372
  };
333
373
  Measure: typeof Measure;
334
- OutputFormat: typeof OutputFormat;
374
+ Output: typeof Output;
335
375
  ParagraphFormat: typeof ParagraphFormat;
336
376
  };
337
377
 
package/dist/index.d.ts CHANGED
@@ -124,6 +124,17 @@ declare class Table extends BranchDocumentElement<TableSettings> {
124
124
  toDocFrame(): Proto.Node;
125
125
  }
126
126
 
127
+ interface SpanProperties {
128
+ bold?: boolean;
129
+ italic?: boolean;
130
+ underline?: boolean;
131
+ strikethrough?: boolean;
132
+ }
133
+ declare class Span extends BranchDocumentElement<SpanProperties> {
134
+ constructor(content?: Content, props?: SpanProperties);
135
+ toDocFrame(): Proto.Node;
136
+ }
137
+
127
138
  declare class SpaceVertically extends DocumentElement {
128
139
  space: AbsoluteMeasure;
129
140
  constructor(space: AbsoluteMeasure);
@@ -167,10 +178,6 @@ declare class Paragraph extends BranchDocumentElement<ParagraphSettings> {
167
178
  toDocFrame(): Proto.Node;
168
179
  }
169
180
 
170
- declare class Pagebreak extends DocumentElement {
171
- toDocFrame(): Proto.Node;
172
- }
173
-
174
181
  declare class PageDefinition {
175
182
  width?: AbsoluteMeasure;
176
183
  height?: AbsoluteMeasure;
@@ -179,6 +186,18 @@ declare class PageDefinition {
179
186
  toDocFrame(): Proto.ProtoPDef;
180
187
  }
181
188
 
189
+ declare class Pagebreak extends DocumentElement {
190
+ toDocFrame(): Proto.Node;
191
+ }
192
+
193
+ declare class Linebreak extends DocumentElement {
194
+ toDocFrame(): Proto.Node;
195
+ }
196
+
197
+ declare class Header extends BranchDocumentElement<never> {
198
+ toDocFrame(): Proto.Node;
199
+ }
200
+
182
201
  declare class Formatted extends DocumentElement {
183
202
  constructor(doctypeContent: string | undefined, htmlContent?: string);
184
203
  content: {
@@ -188,6 +207,10 @@ declare class Formatted extends DocumentElement {
188
207
  toDocFrame(): Proto.Node;
189
208
  }
190
209
 
210
+ declare class Footer extends BranchDocumentElement {
211
+ toDocFrame(): Proto.Node;
212
+ }
213
+
191
214
  declare enum OutputFormat {
192
215
  PDF = "pdf",
193
216
  PNG = "png",
@@ -196,7 +219,7 @@ declare enum OutputFormat {
196
219
  PS = "ps",
197
220
  TEXT = "text"
198
221
  }
199
- interface OutputParams {
222
+ type OutputParams = {
200
223
  [OutputFormat.HTML]: {};
201
224
  [OutputFormat.PDF]: {};
202
225
  [OutputFormat.JPEG]: {};
@@ -219,6 +242,13 @@ interface OutputParams {
219
242
  */
220
243
  dpi?: number;
221
244
  };
245
+ };
246
+
247
+ type Output_OutputFormat = OutputFormat;
248
+ declare const Output_OutputFormat: typeof OutputFormat;
249
+ type Output_OutputParams = OutputParams;
250
+ declare namespace Output {
251
+ export { Output_OutputFormat as OutputFormat, type Output_OutputParams as OutputParams };
222
252
  }
223
253
 
224
254
  declare class ColumnPositionMode {
@@ -246,14 +276,6 @@ declare class ColumnDefinition {
246
276
  toDocFrame(applyImmediate: boolean): Proto.Node[];
247
277
  }
248
278
 
249
- declare class Footer extends BranchDocumentElement {
250
- toDocFrame(): Proto.Node;
251
- }
252
-
253
- declare class Header extends BranchDocumentElement<never> {
254
- toDocFrame(): Proto.Node;
255
- }
256
-
257
279
  interface DocumentProperties {
258
280
  pageDefinition: PageDefinition;
259
281
  columnDefinition: ColumnDefinition;
@@ -271,6 +293,10 @@ declare class Document extends BranchDocumentElement<DocumentProperties> {
271
293
  toDocFrame(): Proto.Node;
272
294
  }
273
295
 
296
+ declare class Directory extends BranchDocumentElement {
297
+ toDocFrame(): Proto.Node;
298
+ }
299
+
274
300
  /**
275
301
  * A ReferencePoint is used for elements like barcodes to specify the reference point
276
302
  * of an object.
@@ -300,6 +326,14 @@ declare class Barcode extends DocumentElement {
300
326
  toDocFrame(): Proto.Node;
301
327
  }
302
328
 
329
+ declare class Connection {
330
+ url: string;
331
+ token: string;
332
+ constructor(url?: string, token?: string);
333
+ get docframeCallUrl(): string;
334
+ convertTo<K extends keyof OutputParams>(format: K, doc: Document, outputParams?: OutputParams[K]): Promise<Blob>;
335
+ }
336
+
303
337
  declare const _default: {
304
338
  Border: {
305
339
  Border: typeof Border;
@@ -309,16 +343,22 @@ declare const _default: {
309
343
  Color: typeof Color;
310
344
  Colors: typeof Colors;
311
345
  };
346
+ Connection: typeof Connection;
312
347
  Content: {
313
348
  Barcode: typeof Barcode;
314
349
  ColumnDefinition: typeof ColumnDefinition;
315
350
  ColumnPosition: typeof ColumnPosition;
351
+ Directory: typeof Directory;
316
352
  Document: typeof Document;
353
+ Footer: typeof Footer;
317
354
  Formatted: typeof Formatted;
318
- PageDefinition: typeof PageDefinition;
355
+ Header: typeof Header;
356
+ Linebreak: typeof Linebreak;
319
357
  Pagebreak: typeof Pagebreak;
358
+ PageDefinition: typeof PageDefinition;
320
359
  Paragraph: typeof Paragraph;
321
360
  SpaceVertically: typeof SpaceVertically;
361
+ Span: typeof Span;
322
362
  Table: typeof Table;
323
363
  TableCell: typeof TableCell;
324
364
  TableRow: typeof TableRow;
@@ -331,7 +371,7 @@ declare const _default: {
331
371
  };
332
372
  };
333
373
  Measure: typeof Measure;
334
- OutputFormat: typeof OutputFormat;
374
+ Output: typeof Output;
335
375
  ParagraphFormat: typeof ParagraphFormat;
336
376
  };
337
377
 
package/dist/index.js CHANGED
@@ -104,6 +104,60 @@ var Colors;
104
104
  Colors2.black = Color.cmyk(0, 0, 0, 100);
105
105
  })(Colors || (Colors = {}));
106
106
 
107
+ // src/Connection/index.ts
108
+ var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
109
+ var _formdata = require('form-data'); var _formdata2 = _interopRequireDefault(_formdata);
110
+
111
+ var Connection = class {
112
+ constructor(url = "http://localhost:8080", token = "") {
113
+ this.url = url;
114
+ this.token = token;
115
+ }
116
+ get docframeCallUrl() {
117
+ return `${this.url}/api/docframe?token=${this.token}`;
118
+ }
119
+ convertTo(format, doc, outputParams) {
120
+ const node = doc.toDocFrame();
121
+ const protoData = _docframetypes2.default.Node.encode(node).finish();
122
+ const form = new (0, _formdata2.default)();
123
+ let meta = {
124
+ format
125
+ };
126
+ if (outputParams) {
127
+ meta = {
128
+ ...meta,
129
+ ...outputParams
130
+ };
131
+ }
132
+ form.append("meta", JSON.stringify(meta), {
133
+ contentType: "application/json",
134
+ filename: "meta"
135
+ });
136
+ form.append("proto-data", protoData, {
137
+ contentType: "application/protobuf",
138
+ filename: "data.proto"
139
+ });
140
+ return new Promise((resolve, reject) => {
141
+ _axios2.default.postForm(this.docframeCallUrl, form, {
142
+ headers: {
143
+ ...form.getHeaders()
144
+ },
145
+ responseType: "arraybuffer"
146
+ }).then(async (res) => {
147
+ const blob = await new Response(res.data, {
148
+ headers: {
149
+ "Content-Type": res.headers["content-type"]
150
+ }
151
+ }).blob();
152
+ resolve(blob);
153
+ }).catch((err) => {
154
+ reject(err);
155
+ });
156
+ });
157
+ }
158
+ };
159
+ var defaultConnection = new Connection();
160
+
107
161
  // src/Content/Barcode/index.ts
108
162
 
109
163
 
@@ -303,73 +357,8 @@ var ColumnDefinitions = {
303
357
  }
304
358
  };
305
359
 
306
- // src/Content/Document/index.ts
307
-
308
-
309
- // src/Connection/index.ts
310
- var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
311
- var _formdata = require('form-data'); var _formdata2 = _interopRequireDefault(_formdata);
312
-
313
- var Connection = class {
314
- constructor(url = "http://localhost:8080", token = "") {
315
- this.url = url;
316
- this.token = token;
317
- }
318
- get docframeCallUrl() {
319
- return `${this.url}/api/docframe?token=${this.token}`;
320
- }
321
- convertTo(format, doc, outputParams) {
322
- const node = doc.toDocFrame();
323
- const protoData = _docframetypes2.default.Node.encode(node).finish();
324
- const form = new (0, _formdata2.default)();
325
- let meta = {
326
- format
327
- };
328
- if (outputParams) {
329
- meta = {
330
- ...meta,
331
- ...outputParams
332
- };
333
- }
334
- form.append("meta", JSON.stringify(meta), {
335
- contentType: "application/json",
336
- filename: "meta"
337
- });
338
- form.append("proto-data", protoData, {
339
- contentType: "application/protobuf",
340
- filename: "data.proto"
341
- });
342
- return new Promise((resolve, reject) => {
343
- _axios2.default.postForm(this.docframeCallUrl, form, {
344
- headers: {
345
- ...form.getHeaders()
346
- },
347
- responseType: "arraybuffer"
348
- }).then(async (res) => {
349
- const blob = await new Response(res.data, {
350
- headers: {
351
- "Content-Type": res.headers["content-type"]
352
- }
353
- }).blob();
354
- resolve(blob);
355
- }).catch((err) => {
356
- reject(err);
357
- });
358
- });
359
- }
360
- };
361
- var defaultConnection = new Connection();
360
+ // src/Content/Directory/index.ts
362
361
 
363
- // src/OutputFormat/index.ts
364
- var OutputFormat = /* @__PURE__ */ ((OutputFormat2) => {
365
- OutputFormat2["PDF"] = "pdf";
366
- OutputFormat2["PNG"] = "png";
367
- OutputFormat2["JPEG"] = "jpeg";
368
- OutputFormat2["HTML"] = "html";
369
- OutputFormat2["PS"] = "ps";
370
- OutputFormat2["TEXT"] = "text";
371
- return OutputFormat2;
372
- })(OutputFormat || {});
373
362
 
374
363
  // src/Content/Text/index.ts
375
364
 
@@ -431,6 +420,34 @@ function documentElementsFromContent(content) {
431
420
  }
432
421
  }
433
422
 
423
+ // src/Content/Directory/index.ts
424
+ var Directory = class extends BranchDocumentElement {
425
+ toDocFrame() {
426
+ return _docframetypes2.default.Node.create({
427
+ directory: _docframetypes2.default.ProtoDirectory.create({}),
428
+ children: this.childrenToDocFrame()
429
+ });
430
+ }
431
+ };
432
+
433
+ // src/Content/Document/index.ts
434
+
435
+
436
+ // src/OutputFormat/index.ts
437
+ var OutputFormat_exports = {};
438
+ __export(OutputFormat_exports, {
439
+ OutputFormat: () => OutputFormat
440
+ });
441
+ var OutputFormat = /* @__PURE__ */ ((OutputFormat2) => {
442
+ OutputFormat2["PDF"] = "pdf";
443
+ OutputFormat2["PNG"] = "png";
444
+ OutputFormat2["JPEG"] = "jpeg";
445
+ OutputFormat2["HTML"] = "html";
446
+ OutputFormat2["PS"] = "ps";
447
+ OutputFormat2["TEXT"] = "text";
448
+ return OutputFormat2;
449
+ })(OutputFormat || {});
450
+
434
451
  // src/Content/Footer/index.ts
435
452
 
436
453
  var Footer = class extends BranchDocumentElement {
@@ -612,7 +629,9 @@ var Font = class {
612
629
  }
613
630
  toDocFrame() {
614
631
  return _docframetypes.ProtoFont.create({
615
- name: this.name
632
+ name: this.name,
633
+ // TODO: suppot font mapping for docframe step
634
+ id: 5
616
635
  });
617
636
  }
618
637
  };
@@ -736,6 +755,16 @@ var Formatted = class extends DocumentElement {
736
755
  }
737
756
  };
738
757
 
758
+ // src/Content/Linebreak/index.ts
759
+
760
+ var Linebreak = class extends DocumentElement {
761
+ toDocFrame() {
762
+ return _docframetypes2.default.Node.create({
763
+ linebreak: _docframetypes2.default.ProtoLinebreak.create({})
764
+ });
765
+ }
766
+ };
767
+
739
768
  // src/Content/Pagebreak/index.ts
740
769
 
741
770
  var Pagebreak = class extends DocumentElement {
@@ -776,6 +805,54 @@ var Paragraph = class extends BranchDocumentElement {
776
805
  }
777
806
  };
778
807
 
808
+ // src/Content/Span/index.ts
809
+
810
+ var Span = class extends BranchDocumentElement {
811
+ constructor(content, props) {
812
+ super(content, props || {});
813
+ }
814
+ toDocFrame() {
815
+ var _a, _b, _c, _d;
816
+ let bold = void 0;
817
+ if (((_a = this.props) == null ? void 0 : _a.bold) !== void 0) {
818
+ bold = _docframetypes2.default.ProtoBoxedBool.create({
819
+ isNull: false,
820
+ value: this.props.bold
821
+ });
822
+ }
823
+ let italic = void 0;
824
+ if (((_b = this.props) == null ? void 0 : _b.italic) !== void 0) {
825
+ italic = _docframetypes2.default.ProtoBoxedBool.create({
826
+ isNull: false,
827
+ value: this.props.italic
828
+ });
829
+ }
830
+ let underline = void 0;
831
+ if (((_c = this.props) == null ? void 0 : _c.underline) !== void 0) {
832
+ underline = _docframetypes2.default.ProtoBoxedBool.create({
833
+ isNull: false,
834
+ value: this.props.underline
835
+ });
836
+ }
837
+ let strikethrough = void 0;
838
+ if (((_d = this.props) == null ? void 0 : _d.strikethrough) !== void 0) {
839
+ strikethrough = _docframetypes2.default.ProtoBoxedBool.create({
840
+ isNull: false,
841
+ value: this.props.strikethrough
842
+ });
843
+ }
844
+ return _docframetypes2.default.Node.create({
845
+ span: _docframetypes2.default.ProtoSpan.create({
846
+ bold,
847
+ italic,
848
+ underline,
849
+ strikethrough
850
+ }),
851
+ children: this.childrenToDocFrame()
852
+ });
853
+ }
854
+ };
855
+
779
856
  // src/Content/Table/index.ts
780
857
 
781
858
  var Table = class extends BranchDocumentElement {
@@ -860,12 +937,17 @@ var Content_default = {
860
937
  Barcode,
861
938
  ColumnDefinition,
862
939
  ColumnPosition,
940
+ Directory,
863
941
  Document,
942
+ Footer,
864
943
  Formatted,
865
- PageDefinition,
944
+ Header,
945
+ Linebreak,
866
946
  Pagebreak,
947
+ PageDefinition,
867
948
  Paragraph,
868
949
  SpaceVertically,
950
+ Span,
869
951
  Table,
870
952
  TableCell,
871
953
  TableRow,
@@ -882,13 +964,14 @@ var index_default = {
882
964
  Color,
883
965
  Colors
884
966
  },
967
+ Connection,
885
968
  Content: Content_default,
886
969
  Font: {
887
970
  Font,
888
971
  StandardFonts
889
972
  },
890
973
  Measure: Measure_exports,
891
- OutputFormat,
974
+ Output: OutputFormat_exports,
892
975
  ParagraphFormat
893
976
  };
894
977