ts-d2 0.0.1 → 0.0.2

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/dist/index.mjs ADDED
@@ -0,0 +1,896 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Border/index.ts
8
+ import Proto from "docframe-types";
9
+ var Border = class {
10
+ constructor(width, color) {
11
+ this.width = width;
12
+ this.color = color;
13
+ }
14
+ toDocFrame() {
15
+ return new Proto.ProtoBorder({
16
+ weight: this.width.toDocFrame(),
17
+ color: this.color.toDocFrame()
18
+ });
19
+ }
20
+ };
21
+ var SideBorders = class {
22
+ constructor(settings) {
23
+ this.value = settings;
24
+ }
25
+ toDocFrame() {
26
+ var _a, _b, _c, _d;
27
+ return new Proto.ProtoSideBorders({
28
+ top: (_a = this.value.top) == null ? void 0 : _a.toDocFrame(),
29
+ right: (_b = this.value.right) == null ? void 0 : _b.toDocFrame(),
30
+ bottom: (_c = this.value.bottom) == null ? void 0 : _c.toDocFrame(),
31
+ left: (_d = this.value.left) == null ? void 0 : _d.toDocFrame()
32
+ });
33
+ }
34
+ };
35
+
36
+ // src/Color/index.ts
37
+ import Proto2 from "docframe-types";
38
+ var Color = class _Color {
39
+ static rgb(r, g, b) {
40
+ if (r < 0 || r > 255) {
41
+ throw new Error(`Invalid red value: ${r}`);
42
+ }
43
+ if (g < 0 || g > 255) {
44
+ throw new Error(`Invalid green value: ${g}`);
45
+ }
46
+ if (b < 0 || b > 255) {
47
+ throw new Error(`Invalid blue value: ${b}`);
48
+ }
49
+ return new _Color(Proto2.ProtoColor.create({
50
+ type: Proto2.ProtoColorType.RGB,
51
+ r,
52
+ g,
53
+ b
54
+ }));
55
+ }
56
+ static cmyk(c, m, y, k) {
57
+ if (c < 0 || c > 100) {
58
+ throw new Error(`Invalid cyan value: ${c}`);
59
+ }
60
+ if (m < 0 || m > 100) {
61
+ throw new Error(`Invalid magenta value: ${m}`);
62
+ }
63
+ if (y < 0 || y > 100) {
64
+ throw new Error(`Invalid yellow value: ${y}`);
65
+ }
66
+ if (k < 0 || k > 100) {
67
+ throw new Error(`Invalid black value: ${k}`);
68
+ }
69
+ return new _Color(Proto2.ProtoColor.create({
70
+ type: Proto2.ProtoColorType.CMYK,
71
+ c,
72
+ m,
73
+ y,
74
+ k
75
+ }));
76
+ }
77
+ static fromHex(hex) {
78
+ if (hex.startsWith("#")) {
79
+ hex = hex.slice(1);
80
+ }
81
+ if (hex.length !== 6) {
82
+ throw new Error(`Invalid hex color: ${hex}`);
83
+ }
84
+ const r = parseInt(hex.slice(0, 2), 16);
85
+ const g = parseInt(hex.slice(2, 4), 16);
86
+ const b = parseInt(hex.slice(4, 6), 16);
87
+ return new _Color(Proto2.ProtoColor.create({
88
+ type: Proto2.ProtoColorType.RGB,
89
+ r,
90
+ g,
91
+ b
92
+ }));
93
+ }
94
+ constructor(color) {
95
+ this.color = color;
96
+ }
97
+ toDocFrame() {
98
+ return this.color;
99
+ }
100
+ };
101
+ var Colors;
102
+ ((Colors2) => {
103
+ Colors2.white = Color.rgb(255, 255, 255);
104
+ Colors2.black = Color.cmyk(0, 0, 0, 100);
105
+ })(Colors || (Colors = {}));
106
+
107
+ // src/Content/Barcode/index.ts
108
+ import Proto5 from "docframe-types";
109
+
110
+ // src/Content/DocumentElement/index.ts
111
+ var DocumentElement = class {
112
+ };
113
+
114
+ // src/Measure/index.ts
115
+ var Measure_exports = {};
116
+ __export(Measure_exports, {
117
+ AbsoluteMeasure: () => AbsoluteMeasure,
118
+ Measure: () => Measure,
119
+ SideMeasures: () => SideMeasures
120
+ });
121
+
122
+ // src/Measure/Measure.ts
123
+ import Proto3 from "docframe-types";
124
+ var _Measure = class _Measure {
125
+ constructor(value, unit) {
126
+ this.value = value;
127
+ this.unit = unit;
128
+ }
129
+ toDocFrame() {
130
+ switch (this.unit) {
131
+ case "pt":
132
+ return new Proto3.ProtoMeasure({
133
+ value: this.value,
134
+ mtype: Proto3.ProtoMeasureType.PT
135
+ });
136
+ case "cm":
137
+ return new Proto3.ProtoMeasure({
138
+ value: this.value,
139
+ mtype: Proto3.ProtoMeasureType.CM
140
+ });
141
+ case "mm":
142
+ return new Proto3.ProtoMeasure({
143
+ value: this.value,
144
+ mtype: Proto3.ProtoMeasureType.MM
145
+ });
146
+ case "in":
147
+ return new Proto3.ProtoMeasure({
148
+ value: this.value,
149
+ mtype: Proto3.ProtoMeasureType.IN
150
+ });
151
+ case "px":
152
+ return new Proto3.ProtoMeasure({
153
+ value: this.value,
154
+ mtype: Proto3.ProtoMeasureType.PX
155
+ });
156
+ case "%":
157
+ return new Proto3.ProtoMeasure({
158
+ value: this.value,
159
+ mtype: Proto3.ProtoMeasureType.PERCENT
160
+ });
161
+ default:
162
+ throw new Error(`Unknown measure unit: ${this.unit}`);
163
+ }
164
+ }
165
+ };
166
+ _Measure.zero = new _Measure(0, "pt");
167
+ var Measure = _Measure;
168
+ var AbsoluteMeasure = class extends Measure {
169
+ };
170
+ var SideMeasures = class {
171
+ constructor(settings) {
172
+ this.value = settings;
173
+ }
174
+ toDocFrame() {
175
+ var _a, _b, _c, _d;
176
+ return new Proto3.ProtoSideMeasures({
177
+ top: (_a = this.value.top) == null ? void 0 : _a.toDocFrame(),
178
+ right: (_b = this.value.right) == null ? void 0 : _b.toDocFrame(),
179
+ bottom: (_c = this.value.bottom) == null ? void 0 : _c.toDocFrame(),
180
+ left: (_d = this.value.left) == null ? void 0 : _d.toDocFrame()
181
+ });
182
+ }
183
+ };
184
+
185
+ // src/Content/ReferencePoint/index.ts
186
+ import Proto4 from "docframe-types";
187
+ function referencePointToDocFrame(point) {
188
+ switch (point) {
189
+ case "top-left":
190
+ return Proto4.ProtoImageReferencePoint.REF_POINT_TOP_LEFT;
191
+ case "top-right":
192
+ return Proto4.ProtoImageReferencePoint.REF_POINT_TOP_RIGHT;
193
+ case "center":
194
+ return Proto4.ProtoImageReferencePoint.REF_POINT_CENTER;
195
+ case "bottom-left":
196
+ return Proto4.ProtoImageReferencePoint.REF_POINT_BOTTOM_LEFT;
197
+ case "bottom-right":
198
+ return Proto4.ProtoImageReferencePoint.REF_POINT_BOTTOM_RIGHT;
199
+ default:
200
+ throw new Error(`Unknown reference point: ${point}`);
201
+ }
202
+ }
203
+
204
+ // src/Content/Barcode/index.ts
205
+ var Barcode = class extends DocumentElement {
206
+ constructor(props) {
207
+ super();
208
+ this.props = props;
209
+ }
210
+ toDocFrame() {
211
+ return Proto5.Node.create({
212
+ barcode: Proto5.ProtoBarcode.create({
213
+ type: this.props.type,
214
+ positionAbsolute: this.props.positionAbsolute,
215
+ referencePoint: referencePointToDocFrame(this.props.referencePoint),
216
+ x: this.props.x.toDocFrame(),
217
+ y: this.props.y.toDocFrame(),
218
+ rotation: this.props.rotation,
219
+ width: this.props.width.toDocFrame(),
220
+ height: this.props.height.toDocFrame(),
221
+ padding: Measure.zero.toDocFrame(),
222
+ data: this.props.data
223
+ })
224
+ });
225
+ }
226
+ };
227
+
228
+ // src/Content/ColumnDefinition/index.ts
229
+ import Proto6 from "docframe-types";
230
+ import { v4 as uuidv4 } from "uuid";
231
+ var ColumnPositionMode = class {
232
+ constructor(value) {
233
+ this.value = value;
234
+ }
235
+ toDocFrame() {
236
+ return this.value;
237
+ }
238
+ };
239
+ var ColumnPosition;
240
+ ((ColumnPosition2) => {
241
+ ColumnPosition2.Center = new ColumnPositionMode(Proto6.ProtoPositionMode.CENTER);
242
+ ColumnPosition2.Left = new ColumnPositionMode(Proto6.ProtoPositionMode.LEFT);
243
+ ColumnPosition2.Folio = new ColumnPositionMode(Proto6.ProtoPositionMode.FOLIO);
244
+ ColumnPosition2.Right = new ColumnPositionMode(Proto6.ProtoPositionMode.RIGHT);
245
+ ColumnPosition2.ReverseFolio = new ColumnPositionMode(
246
+ Proto6.ProtoPositionMode.REVERSE_FOLIO
247
+ );
248
+ })(ColumnPosition || (ColumnPosition = {}));
249
+ var ColumnDefinition = class {
250
+ constructor(props) {
251
+ this.props = props;
252
+ this.uuid = uuidv4();
253
+ }
254
+ toDocFrame(applyImmediate) {
255
+ const result = [
256
+ Proto6.Node.create({
257
+ cDef: Proto6.ProtoCDef.create({
258
+ Uuid: this.uuid,
259
+ columSettings: Proto6.ProtoColumnSettings.create({
260
+ width: Proto6.ProtoBoxedMeasure.create({
261
+ isNull: false,
262
+ value: this.props.width.toDocFrame()
263
+ }),
264
+ positionOffset: Proto6.ProtoBoxedMeasure.create({
265
+ isNull: false,
266
+ value: this.props.positionOffset.toDocFrame()
267
+ }),
268
+ positionMode: this.props.position.toDocFrame(),
269
+ interColumnSpace: Proto6.ProtoBoxedMeasure.create({
270
+ isNull: false,
271
+ value: this.props.interColumnSpace.toDocFrame()
272
+ })
273
+ })
274
+ })
275
+ })
276
+ ];
277
+ if (applyImmediate) {
278
+ result.push(
279
+ Proto6.Node.create({
280
+ applyCDef: Proto6.ProtoApplyProtoCDef.create({
281
+ cDefUuid: this.uuid
282
+ })
283
+ })
284
+ );
285
+ }
286
+ return result;
287
+ }
288
+ };
289
+ var ColumnDefinitions = {
290
+ A4: {
291
+ Single: new ColumnDefinition({
292
+ width: new AbsoluteMeasure(490, "pt"),
293
+ position: ColumnPosition.Left,
294
+ positionOffset: new AbsoluteMeasure(70, "pt"),
295
+ interColumnSpace: new AbsoluteMeasure(30, "pt")
296
+ }),
297
+ Double: new ColumnDefinition({
298
+ width: new AbsoluteMeasure(230, "pt"),
299
+ position: ColumnPosition.Left,
300
+ positionOffset: new AbsoluteMeasure(70, "pt"),
301
+ interColumnSpace: new AbsoluteMeasure(30, "pt")
302
+ })
303
+ }
304
+ };
305
+
306
+ // src/Content/Document/index.ts
307
+ import Proto14 from "docframe-types";
308
+
309
+ // src/Connection/index.ts
310
+ import axios from "axios";
311
+ import FormData from "form-data";
312
+ import Proto7 from "docframe-types";
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 = Proto7.Node.encode(node).finish();
324
+ const form = new FormData();
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
+ axios.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();
362
+
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
+
374
+ // src/Content/Text/index.ts
375
+ import Proto8 from "docframe-types";
376
+ var Text = class extends DocumentElement {
377
+ constructor(content) {
378
+ super();
379
+ this.content = content;
380
+ }
381
+ toDocFrame() {
382
+ return Proto8.Node.create({
383
+ text: Proto8.ProtoText.create({
384
+ content: this.content
385
+ })
386
+ });
387
+ }
388
+ };
389
+
390
+ // src/Content/BranchDocumentElement/index.ts
391
+ var BranchDocumentElement = class extends DocumentElement {
392
+ constructor(children, props) {
393
+ super();
394
+ this.children = [];
395
+ this._props = props;
396
+ if (children === void 0) {
397
+ this.children = [];
398
+ return;
399
+ }
400
+ this.children = documentElementsFromContent(children);
401
+ }
402
+ appendChildren(children) {
403
+ this.children = this.children.concat(children);
404
+ }
405
+ appendChild(child) {
406
+ this.children.push(child);
407
+ }
408
+ prependChildren(children) {
409
+ this.children = children.concat(this.children);
410
+ }
411
+ prependChild(child) {
412
+ this.children.unshift(child);
413
+ }
414
+ childrenToDocFrame() {
415
+ return this.children.map((child) => child.toDocFrame());
416
+ }
417
+ set props(props) {
418
+ this._props = props;
419
+ }
420
+ get props() {
421
+ return this._props;
422
+ }
423
+ };
424
+ function documentElementsFromContent(content) {
425
+ if (typeof content === "string") {
426
+ return [new Text(content)];
427
+ } else if (Array.isArray(content)) {
428
+ return content.map(documentElementsFromContent).flat();
429
+ } else {
430
+ return [content];
431
+ }
432
+ }
433
+
434
+ // src/Content/Footer/index.ts
435
+ import Proto9 from "docframe-types";
436
+ var Footer = class extends BranchDocumentElement {
437
+ toDocFrame() {
438
+ return Proto9.Node.create({
439
+ footer: Proto9.ProtoFooter.create(),
440
+ children: this.childrenToDocFrame()
441
+ });
442
+ }
443
+ };
444
+
445
+ // src/Content/Header/index.ts
446
+ import Proto10 from "docframe-types";
447
+ var Header = class extends BranchDocumentElement {
448
+ toDocFrame() {
449
+ return Proto10.Node.create({
450
+ header: Proto10.ProtoHeader.create(),
451
+ children: this.childrenToDocFrame()
452
+ });
453
+ }
454
+ };
455
+
456
+ // src/Content/PageDefinition/index.ts
457
+ import Proto11 from "docframe-types";
458
+ import { v4 } from "uuid";
459
+ var PageDefinition = class {
460
+ constructor(width, height) {
461
+ this.width = width;
462
+ this.height = height;
463
+ this.uuid = v4();
464
+ }
465
+ toDocFrame() {
466
+ var _a, _b;
467
+ return new Proto11.ProtoPDef({
468
+ pageDepth: new Proto11.ProtoBoxedMeasure({
469
+ isNull: this.height === void 0,
470
+ value: (_a = this.height) == null ? void 0 : _a.toDocFrame()
471
+ }),
472
+ pageWidth: new Proto11.ProtoBoxedMeasure({
473
+ isNull: this.width === void 0,
474
+ value: (_b = this.width) == null ? void 0 : _b.toDocFrame()
475
+ }),
476
+ Uuid: this.uuid
477
+ });
478
+ }
479
+ };
480
+ var PageDefinitions;
481
+ ((PageDefinitions2) => {
482
+ PageDefinitions2.A3 = new PageDefinition(
483
+ new AbsoluteMeasure(297, "mm"),
484
+ new AbsoluteMeasure(420, "mm")
485
+ );
486
+ PageDefinitions2.A4 = new PageDefinition(
487
+ new AbsoluteMeasure(210, "mm"),
488
+ new AbsoluteMeasure(297, "mm")
489
+ );
490
+ PageDefinitions2.A5 = new PageDefinition(
491
+ new AbsoluteMeasure(148, "mm"),
492
+ new AbsoluteMeasure(210, "mm")
493
+ );
494
+ })(PageDefinitions || (PageDefinitions = {}));
495
+
496
+ // src/ParagraphFormat/index.ts
497
+ import Proto12 from "docframe-types";
498
+ import { v4 as uuidv42 } from "uuid";
499
+ var ParagraphFormat = class {
500
+ constructor(props) {
501
+ this.props = props;
502
+ this.props.name = props.name || uuidv42();
503
+ }
504
+ toDocFrame() {
505
+ let format = {
506
+ default: Proto12.ProtoBoxedBool.create({
507
+ isNull: false,
508
+ value: this.props.default || false
509
+ }),
510
+ name: Proto12.ProtoBoxedString.create({
511
+ isNull: false,
512
+ value: this.props.name
513
+ })
514
+ };
515
+ if (this.props.alignment) {
516
+ format.alignment = Proto12.ProtoBoxedHorizontalAlignment.create({
517
+ isNull: false,
518
+ value: this.props.alignment.toDocFrame()
519
+ });
520
+ }
521
+ if (this.props.font) {
522
+ format.font = Proto12.ProtoBoxedFont.create({
523
+ isNull: false,
524
+ value: this.props.font.toDocFrame()
525
+ });
526
+ }
527
+ if (this.props.fontSize) {
528
+ format.fontSize = Proto12.ProtoBoxedMeasure.create({
529
+ isNull: false,
530
+ value: this.props.fontSize.toDocFrame()
531
+ });
532
+ }
533
+ if (this.props.characterWidth) {
534
+ format.characterWidth = Proto12.ProtoBoxedMeasure.create({
535
+ isNull: false,
536
+ value: this.props.characterWidth.toDocFrame()
537
+ });
538
+ }
539
+ if (this.props.characterSpacing) {
540
+ format.characterSpacing = Proto12.ProtoBoxedMeasure.create({
541
+ isNull: false,
542
+ value: this.props.characterSpacing.toDocFrame()
543
+ });
544
+ }
545
+ if (this.props.lineFeed) {
546
+ format.lineFeed = Proto12.ProtoBoxedMeasure.create({
547
+ isNull: false,
548
+ value: this.props.lineFeed.toDocFrame()
549
+ });
550
+ }
551
+ if (this.props.indentionLevel !== void 0) {
552
+ format.indentionLevel = Proto12.ProtoBoxedInt32.create({
553
+ isNull: false,
554
+ value: this.props.indentionLevel
555
+ });
556
+ }
557
+ if (this.props.indentionWidth) {
558
+ format.indentionWidth = Proto12.ProtoBoxedMeasure.create({
559
+ isNull: false,
560
+ value: this.props.indentionWidth.toDocFrame()
561
+ });
562
+ }
563
+ if (this.props.bold !== void 0) {
564
+ format.bold = Proto12.ProtoBoxedBool.create({
565
+ isNull: false,
566
+ value: !!this.props.bold
567
+ });
568
+ }
569
+ if (this.props.italic !== void 0) {
570
+ format.italic = Proto12.ProtoBoxedBool.create({
571
+ isNull: false,
572
+ value: !!this.props.italic
573
+ });
574
+ }
575
+ if (this.props.spaceAbove) {
576
+ format.spaceAbove = Proto12.ProtoBoxedMeasure.create({
577
+ isNull: false,
578
+ value: this.props.spaceAbove.toDocFrame()
579
+ });
580
+ }
581
+ if (this.props.spaceBelow) {
582
+ format.spaceBelow = Proto12.ProtoBoxedMeasure.create({
583
+ isNull: false,
584
+ value: this.props.spaceBelow.toDocFrame()
585
+ });
586
+ }
587
+ return Proto12.ProtoParagraphFormat.create(format);
588
+ }
589
+ };
590
+
591
+ // src/Content/SpaceVertically/index.ts
592
+ import Proto13 from "docframe-types";
593
+ var SpaceVertically = class extends DocumentElement {
594
+ constructor(space) {
595
+ super();
596
+ this.space = space;
597
+ }
598
+ toDocFrame() {
599
+ return Proto13.Node.create({
600
+ spaceVertically: Proto13.ProtoSpaceVertically.create({
601
+ space: this.space.toDocFrame()
602
+ })
603
+ });
604
+ }
605
+ };
606
+
607
+ // src/Font/index.ts
608
+ import { ProtoFont } from "docframe-types";
609
+ var Font = class {
610
+ constructor(name) {
611
+ this.name = name;
612
+ }
613
+ toDocFrame() {
614
+ return ProtoFont.create({
615
+ name: this.name
616
+ });
617
+ }
618
+ };
619
+ var StandardFonts = {
620
+ Helvetica: new Font("helvetica")
621
+ };
622
+
623
+ // src/Content/Document/index.ts
624
+ var Document = class extends BranchDocumentElement {
625
+ constructor(content, props) {
626
+ super(content, props);
627
+ this.paragraphFormats = {};
628
+ if (props === void 0) {
629
+ this.props = {
630
+ pageDefinition: PageDefinitions.A4,
631
+ columnDefinition: ColumnDefinitions.A4.Single,
632
+ defaultHeader: new Header(
633
+ new SpaceVertically(new AbsoluteMeasure(40, "pt"))
634
+ ),
635
+ defaultFooter: new Footer(
636
+ new SpaceVertically(new AbsoluteMeasure(40, "pt"))
637
+ )
638
+ };
639
+ } else {
640
+ this.props = props;
641
+ }
642
+ this.paragraphFormats = this.props.paragraphFormats || {
643
+ Text: new ParagraphFormat({
644
+ font: StandardFonts.Helvetica,
645
+ fontSize: new AbsoluteMeasure(12, "pt"),
646
+ lineFeed: new AbsoluteMeasure(14, "pt"),
647
+ indentionWidth: new AbsoluteMeasure(15, "pt"),
648
+ name: "Text",
649
+ default: true
650
+ })
651
+ };
652
+ }
653
+ getParagraphFormat(name) {
654
+ return this.paragraphFormats[name];
655
+ }
656
+ registerParagraphFormat(name, pf) {
657
+ this.paragraphFormats[name] = pf;
658
+ }
659
+ convertTo(outputFormat, outputParams) {
660
+ return defaultConnection.convertTo(outputFormat, this, outputParams);
661
+ }
662
+ convertToPDF(outputParams) {
663
+ return defaultConnection.convertTo("pdf" /* PDF */, this, outputParams);
664
+ }
665
+ /*
666
+ public getProtoParagraphFormat(format?: ParagraphFormat): Proto.IProtoParagraphFormat {
667
+ if (!format) {
668
+ return this.defaultParagraphFormat;
669
+ }
670
+
671
+ if (!format.format.name) {
672
+ throw new Error("ParagraphFormat must have a name");
673
+ }
674
+
675
+ if (!this.paragraphFormats[format.format.name]) {
676
+ this.paragraphFormats[format.format.name] = format.toDocFrame();
677
+ }
678
+
679
+ return this.paragraphFormats[format.format.name];
680
+ }
681
+ */
682
+ toDocFrame() {
683
+ const props = this.props;
684
+ const docSettings = Object.values(this.paragraphFormats).map(
685
+ (pf) => Proto14.Node.create({
686
+ paragraphFormat: pf.toDocFrame()
687
+ })
688
+ ).concat([
689
+ Proto14.Node.create({
690
+ pDef: props.pageDefinition.toDocFrame()
691
+ }),
692
+ Proto14.Node.create({
693
+ applyPDef: Proto14.ProtoApplyProtoPDef.create({
694
+ pDefUuid: props.pageDefinition.uuid
695
+ })
696
+ }),
697
+ ...props.columnDefinition.toDocFrame(true)
698
+ ]);
699
+ if (props.defaultHeader) {
700
+ docSettings.push(props.defaultHeader.toDocFrame());
701
+ }
702
+ if (props.defaultFooter) {
703
+ docSettings.push(props.defaultFooter.toDocFrame());
704
+ }
705
+ const content = this.childrenToDocFrame();
706
+ for (const format of Object.values(this.paragraphFormats)) {
707
+ docSettings.push(
708
+ Proto14.Node.create({
709
+ paragraphFormat: format.toDocFrame()
710
+ })
711
+ );
712
+ }
713
+ return Proto14.Node.create({
714
+ children: docSettings.concat(...content)
715
+ });
716
+ }
717
+ };
718
+
719
+ // src/Content/Formatted/index.ts
720
+ import Proto15 from "docframe-types";
721
+ var Formatted = class extends DocumentElement {
722
+ constructor(doctypeContent, htmlContent) {
723
+ super();
724
+ this.content = {
725
+ doctype: doctypeContent,
726
+ html: htmlContent
727
+ };
728
+ }
729
+ toDocFrame() {
730
+ return Proto15.Node.create({
731
+ formatted: Proto15.ProtoFormatted.create({
732
+ doctypeContent: this.content.doctype,
733
+ htmlContent: this.content.html
734
+ })
735
+ });
736
+ }
737
+ };
738
+
739
+ // src/Content/Pagebreak/index.ts
740
+ import Proto16 from "docframe-types";
741
+ var Pagebreak = class extends DocumentElement {
742
+ toDocFrame() {
743
+ return Proto16.Node.create({
744
+ newPage: Proto16.ProtoNewPage.create({})
745
+ });
746
+ }
747
+ };
748
+
749
+ // src/Content/Paragraph/index.ts
750
+ import Proto17 from "docframe-types";
751
+ var Paragraph = class extends BranchDocumentElement {
752
+ constructor(content, paragraphFormatName, overwrite) {
753
+ var _a;
754
+ super(content, {
755
+ overwrite,
756
+ paragraphFormatName: typeof paragraphFormatName === "string" ? paragraphFormatName : (_a = paragraphFormatName == null ? void 0 : paragraphFormatName.props) == null ? void 0 : _a.name
757
+ });
758
+ }
759
+ toDocFrame() {
760
+ const par = {};
761
+ if (this.props.overwrite) {
762
+ par.overwrite = this.props.overwrite.toDocFrame();
763
+ }
764
+ if (this.props.paragraphFormatName) {
765
+ par.format = Proto17.ProtoParagraphFormat.create({
766
+ name: Proto17.ProtoBoxedString.create({
767
+ isNull: false,
768
+ value: this.props.paragraphFormatName
769
+ })
770
+ });
771
+ }
772
+ return Proto17.Node.create({
773
+ paragraph: Proto17.ProtoParagraph.create(par),
774
+ children: this.childrenToDocFrame()
775
+ });
776
+ }
777
+ };
778
+
779
+ // src/Content/Table/index.ts
780
+ import Proto18 from "docframe-types";
781
+ var Table = class extends BranchDocumentElement {
782
+ constructor(content, props) {
783
+ super(content, props || {});
784
+ if (!this.props.xOffset) {
785
+ this.props.xOffset = Measure.zero;
786
+ }
787
+ }
788
+ toDocFrame() {
789
+ var _a, _b;
790
+ const props = this.props;
791
+ return Proto18.Node.create({
792
+ table: Proto18.ProtoTable.create({
793
+ settings: Proto18.ProtoTableSettings.create({
794
+ width: (_a = props.width) == null ? void 0 : _a.toDocFrame(),
795
+ leftMeasure: Proto18.ProtoBoxedBool.create({
796
+ isNull: false,
797
+ value: false
798
+ }),
799
+ xOffset: (_b = props.xOffset) == null ? void 0 : _b.toDocFrame()
800
+ })
801
+ }),
802
+ children: this.childrenToDocFrame()
803
+ });
804
+ }
805
+ };
806
+
807
+ // src/Content/TableCell/index.ts
808
+ import Proto19 from "docframe-types";
809
+ var TableCell = class extends BranchDocumentElement {
810
+ constructor(content, props) {
811
+ super(content, props || {});
812
+ }
813
+ toDocFrame() {
814
+ var _a, _b, _c, _d, _e, _f, _g;
815
+ const props = this.props;
816
+ return Proto19.Node.create({
817
+ tableCell: Proto19.ProtoTableCell.create({
818
+ settings: Proto19.ProtoTableCellSettings.create({
819
+ align: Proto19.ProtoBoxedHorizontalAlignment.create({
820
+ isNull: false,
821
+ value: ((_a = props.alignment) == null ? void 0 : _a.toDocFrame()) || Proto19.ProtoHorizontalAlignment.ALIGN_LEFT
822
+ }),
823
+ backgroundColor: (_b = props.backgroundColor) == null ? void 0 : _b.toDocFrame(),
824
+ border: (_c = props.border) == null ? void 0 : _c.toDocFrame(),
825
+ margin: (_d = props.margin) == null ? void 0 : _d.toDocFrame(),
826
+ padding: (_e = props.padding) == null ? void 0 : _e.toDocFrame(),
827
+ valign: Proto19.ProtoBoxedVerticalAlignment.create({
828
+ isNull: false,
829
+ value: ((_f = props.verticalAlignment) == null ? void 0 : _f.toDocFrame()) || Proto19.ProtoVerticalAlignment.TOP
830
+ }),
831
+ width: (_g = props.width) == null ? void 0 : _g.toDocFrame()
832
+ })
833
+ }),
834
+ children: this.childrenToDocFrame()
835
+ });
836
+ }
837
+ };
838
+
839
+ // src/Content/TableRow/index.ts
840
+ import Proto20 from "docframe-types";
841
+ var TableRow = class extends BranchDocumentElement {
842
+ constructor(content, props) {
843
+ super(content, props || {});
844
+ }
845
+ toDocFrame() {
846
+ var _a;
847
+ return Proto20.Node.create({
848
+ tableRow: Proto20.ProtoTableRow.create({
849
+ settings: Proto20.ProtoTableRowSettings.create({
850
+ minHeight: (_a = this.props.minHeight) == null ? void 0 : _a.toDocFrame()
851
+ })
852
+ }),
853
+ children: this.childrenToDocFrame()
854
+ });
855
+ }
856
+ };
857
+
858
+ // src/Content/index.ts
859
+ var Content_default = {
860
+ Barcode,
861
+ ColumnDefinition,
862
+ ColumnPosition,
863
+ Document,
864
+ Formatted,
865
+ PageDefinition,
866
+ Pagebreak,
867
+ Paragraph,
868
+ SpaceVertically,
869
+ Table,
870
+ TableCell,
871
+ TableRow,
872
+ Text
873
+ };
874
+
875
+ // src/index.ts
876
+ var index_default = {
877
+ Border: {
878
+ Border,
879
+ SideBorders
880
+ },
881
+ Color: {
882
+ Color,
883
+ Colors
884
+ },
885
+ Content: Content_default,
886
+ Font: {
887
+ Font,
888
+ StandardFonts
889
+ },
890
+ Measure: Measure_exports,
891
+ OutputFormat,
892
+ ParagraphFormat
893
+ };
894
+ export {
895
+ index_default as default
896
+ };