ts-d2 0.0.2 → 0.0.4

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.d.mts CHANGED
@@ -196,7 +196,7 @@ declare enum OutputFormat {
196
196
  PS = "ps",
197
197
  TEXT = "text"
198
198
  }
199
- interface OutputParams {
199
+ type OutputParams = {
200
200
  [OutputFormat.HTML]: {};
201
201
  [OutputFormat.PDF]: {};
202
202
  [OutputFormat.JPEG]: {};
@@ -219,6 +219,13 @@ interface OutputParams {
219
219
  */
220
220
  dpi?: number;
221
221
  };
222
+ };
223
+
224
+ type Output_OutputFormat = OutputFormat;
225
+ declare const Output_OutputFormat: typeof OutputFormat;
226
+ type Output_OutputParams = OutputParams;
227
+ declare namespace Output {
228
+ export { Output_OutputFormat as OutputFormat, type Output_OutputParams as OutputParams };
222
229
  }
223
230
 
224
231
  declare class ColumnPositionMode {
@@ -300,6 +307,14 @@ declare class Barcode extends DocumentElement {
300
307
  toDocFrame(): Proto.Node;
301
308
  }
302
309
 
310
+ declare class Connection {
311
+ url: string;
312
+ token: string;
313
+ constructor(url?: string, token?: string);
314
+ get docframeCallUrl(): string;
315
+ convertTo<K extends keyof OutputParams>(format: K, doc: Document, outputParams?: OutputParams[K]): Promise<Blob>;
316
+ }
317
+
303
318
  declare const _default: {
304
319
  Border: {
305
320
  Border: typeof Border;
@@ -309,6 +324,7 @@ declare const _default: {
309
324
  Color: typeof Color;
310
325
  Colors: typeof Colors;
311
326
  };
327
+ Connection: typeof Connection;
312
328
  Content: {
313
329
  Barcode: typeof Barcode;
314
330
  ColumnDefinition: typeof ColumnDefinition;
@@ -331,7 +347,7 @@ declare const _default: {
331
347
  };
332
348
  };
333
349
  Measure: typeof Measure;
334
- OutputFormat: typeof OutputFormat;
350
+ Output: typeof Output;
335
351
  ParagraphFormat: typeof ParagraphFormat;
336
352
  };
337
353
 
package/dist/index.d.ts CHANGED
@@ -196,7 +196,7 @@ declare enum OutputFormat {
196
196
  PS = "ps",
197
197
  TEXT = "text"
198
198
  }
199
- interface OutputParams {
199
+ type OutputParams = {
200
200
  [OutputFormat.HTML]: {};
201
201
  [OutputFormat.PDF]: {};
202
202
  [OutputFormat.JPEG]: {};
@@ -219,6 +219,13 @@ interface OutputParams {
219
219
  */
220
220
  dpi?: number;
221
221
  };
222
+ };
223
+
224
+ type Output_OutputFormat = OutputFormat;
225
+ declare const Output_OutputFormat: typeof OutputFormat;
226
+ type Output_OutputParams = OutputParams;
227
+ declare namespace Output {
228
+ export { Output_OutputFormat as OutputFormat, type Output_OutputParams as OutputParams };
222
229
  }
223
230
 
224
231
  declare class ColumnPositionMode {
@@ -300,6 +307,14 @@ declare class Barcode extends DocumentElement {
300
307
  toDocFrame(): Proto.Node;
301
308
  }
302
309
 
310
+ declare class Connection {
311
+ url: string;
312
+ token: string;
313
+ constructor(url?: string, token?: string);
314
+ get docframeCallUrl(): string;
315
+ convertTo<K extends keyof OutputParams>(format: K, doc: Document, outputParams?: OutputParams[K]): Promise<Blob>;
316
+ }
317
+
303
318
  declare const _default: {
304
319
  Border: {
305
320
  Border: typeof Border;
@@ -309,6 +324,7 @@ declare const _default: {
309
324
  Color: typeof Color;
310
325
  Colors: typeof Colors;
311
326
  };
327
+ Connection: typeof Connection;
312
328
  Content: {
313
329
  Barcode: typeof Barcode;
314
330
  ColumnDefinition: typeof ColumnDefinition;
@@ -331,7 +347,7 @@ declare const _default: {
331
347
  };
332
348
  };
333
349
  Measure: typeof Measure;
334
- OutputFormat: typeof OutputFormat;
350
+ Output: typeof Output;
335
351
  ParagraphFormat: typeof ParagraphFormat;
336
352
  };
337
353
 
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
 
@@ -306,61 +360,11 @@ var ColumnDefinitions = {
306
360
  // src/Content/Document/index.ts
307
361
 
308
362
 
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();
362
-
363
363
  // src/OutputFormat/index.ts
364
+ var OutputFormat_exports = {};
365
+ __export(OutputFormat_exports, {
366
+ OutputFormat: () => OutputFormat
367
+ });
364
368
  var OutputFormat = /* @__PURE__ */ ((OutputFormat2) => {
365
369
  OutputFormat2["PDF"] = "pdf";
366
370
  OutputFormat2["PNG"] = "png";
@@ -612,7 +616,9 @@ var Font = class {
612
616
  }
613
617
  toDocFrame() {
614
618
  return _docframetypes.ProtoFont.create({
615
- name: this.name
619
+ name: this.name,
620
+ // TODO: suppot font mapping for docframe step
621
+ id: 5
616
622
  });
617
623
  }
618
624
  };
@@ -882,13 +888,14 @@ var index_default = {
882
888
  Color,
883
889
  Colors
884
890
  },
891
+ Connection,
885
892
  Content: Content_default,
886
893
  Font: {
887
894
  Font,
888
895
  StandardFonts
889
896
  },
890
897
  Measure: Measure_exports,
891
- OutputFormat,
898
+ Output: OutputFormat_exports,
892
899
  ParagraphFormat
893
900
  };
894
901
 
package/dist/index.mjs CHANGED
@@ -104,8 +104,62 @@ var Colors;
104
104
  Colors2.black = Color.cmyk(0, 0, 0, 100);
105
105
  })(Colors || (Colors = {}));
106
106
 
107
+ // src/Connection/index.ts
108
+ import axios from "axios";
109
+ import FormData from "form-data";
110
+ import Proto3 from "docframe-types";
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 = Proto3.Node.encode(node).finish();
122
+ const form = new FormData();
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
+ axios.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
- import Proto5 from "docframe-types";
162
+ import Proto6 from "docframe-types";
109
163
 
110
164
  // src/Content/DocumentElement/index.ts
111
165
  var DocumentElement = class {
@@ -120,7 +174,7 @@ __export(Measure_exports, {
120
174
  });
121
175
 
122
176
  // src/Measure/Measure.ts
123
- import Proto3 from "docframe-types";
177
+ import Proto4 from "docframe-types";
124
178
  var _Measure = class _Measure {
125
179
  constructor(value, unit) {
126
180
  this.value = value;
@@ -129,34 +183,34 @@ var _Measure = class _Measure {
129
183
  toDocFrame() {
130
184
  switch (this.unit) {
131
185
  case "pt":
132
- return new Proto3.ProtoMeasure({
186
+ return new Proto4.ProtoMeasure({
133
187
  value: this.value,
134
- mtype: Proto3.ProtoMeasureType.PT
188
+ mtype: Proto4.ProtoMeasureType.PT
135
189
  });
136
190
  case "cm":
137
- return new Proto3.ProtoMeasure({
191
+ return new Proto4.ProtoMeasure({
138
192
  value: this.value,
139
- mtype: Proto3.ProtoMeasureType.CM
193
+ mtype: Proto4.ProtoMeasureType.CM
140
194
  });
141
195
  case "mm":
142
- return new Proto3.ProtoMeasure({
196
+ return new Proto4.ProtoMeasure({
143
197
  value: this.value,
144
- mtype: Proto3.ProtoMeasureType.MM
198
+ mtype: Proto4.ProtoMeasureType.MM
145
199
  });
146
200
  case "in":
147
- return new Proto3.ProtoMeasure({
201
+ return new Proto4.ProtoMeasure({
148
202
  value: this.value,
149
- mtype: Proto3.ProtoMeasureType.IN
203
+ mtype: Proto4.ProtoMeasureType.IN
150
204
  });
151
205
  case "px":
152
- return new Proto3.ProtoMeasure({
206
+ return new Proto4.ProtoMeasure({
153
207
  value: this.value,
154
- mtype: Proto3.ProtoMeasureType.PX
208
+ mtype: Proto4.ProtoMeasureType.PX
155
209
  });
156
210
  case "%":
157
- return new Proto3.ProtoMeasure({
211
+ return new Proto4.ProtoMeasure({
158
212
  value: this.value,
159
- mtype: Proto3.ProtoMeasureType.PERCENT
213
+ mtype: Proto4.ProtoMeasureType.PERCENT
160
214
  });
161
215
  default:
162
216
  throw new Error(`Unknown measure unit: ${this.unit}`);
@@ -173,7 +227,7 @@ var SideMeasures = class {
173
227
  }
174
228
  toDocFrame() {
175
229
  var _a, _b, _c, _d;
176
- return new Proto3.ProtoSideMeasures({
230
+ return new Proto4.ProtoSideMeasures({
177
231
  top: (_a = this.value.top) == null ? void 0 : _a.toDocFrame(),
178
232
  right: (_b = this.value.right) == null ? void 0 : _b.toDocFrame(),
179
233
  bottom: (_c = this.value.bottom) == null ? void 0 : _c.toDocFrame(),
@@ -183,19 +237,19 @@ var SideMeasures = class {
183
237
  };
184
238
 
185
239
  // src/Content/ReferencePoint/index.ts
186
- import Proto4 from "docframe-types";
240
+ import Proto5 from "docframe-types";
187
241
  function referencePointToDocFrame(point) {
188
242
  switch (point) {
189
243
  case "top-left":
190
- return Proto4.ProtoImageReferencePoint.REF_POINT_TOP_LEFT;
244
+ return Proto5.ProtoImageReferencePoint.REF_POINT_TOP_LEFT;
191
245
  case "top-right":
192
- return Proto4.ProtoImageReferencePoint.REF_POINT_TOP_RIGHT;
246
+ return Proto5.ProtoImageReferencePoint.REF_POINT_TOP_RIGHT;
193
247
  case "center":
194
- return Proto4.ProtoImageReferencePoint.REF_POINT_CENTER;
248
+ return Proto5.ProtoImageReferencePoint.REF_POINT_CENTER;
195
249
  case "bottom-left":
196
- return Proto4.ProtoImageReferencePoint.REF_POINT_BOTTOM_LEFT;
250
+ return Proto5.ProtoImageReferencePoint.REF_POINT_BOTTOM_LEFT;
197
251
  case "bottom-right":
198
- return Proto4.ProtoImageReferencePoint.REF_POINT_BOTTOM_RIGHT;
252
+ return Proto5.ProtoImageReferencePoint.REF_POINT_BOTTOM_RIGHT;
199
253
  default:
200
254
  throw new Error(`Unknown reference point: ${point}`);
201
255
  }
@@ -208,8 +262,8 @@ var Barcode = class extends DocumentElement {
208
262
  this.props = props;
209
263
  }
210
264
  toDocFrame() {
211
- return Proto5.Node.create({
212
- barcode: Proto5.ProtoBarcode.create({
265
+ return Proto6.Node.create({
266
+ barcode: Proto6.ProtoBarcode.create({
213
267
  type: this.props.type,
214
268
  positionAbsolute: this.props.positionAbsolute,
215
269
  referencePoint: referencePointToDocFrame(this.props.referencePoint),
@@ -226,7 +280,7 @@ var Barcode = class extends DocumentElement {
226
280
  };
227
281
 
228
282
  // src/Content/ColumnDefinition/index.ts
229
- import Proto6 from "docframe-types";
283
+ import Proto7 from "docframe-types";
230
284
  import { v4 as uuidv4 } from "uuid";
231
285
  var ColumnPositionMode = class {
232
286
  constructor(value) {
@@ -238,12 +292,12 @@ var ColumnPositionMode = class {
238
292
  };
239
293
  var ColumnPosition;
240
294
  ((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);
295
+ ColumnPosition2.Center = new ColumnPositionMode(Proto7.ProtoPositionMode.CENTER);
296
+ ColumnPosition2.Left = new ColumnPositionMode(Proto7.ProtoPositionMode.LEFT);
297
+ ColumnPosition2.Folio = new ColumnPositionMode(Proto7.ProtoPositionMode.FOLIO);
298
+ ColumnPosition2.Right = new ColumnPositionMode(Proto7.ProtoPositionMode.RIGHT);
245
299
  ColumnPosition2.ReverseFolio = new ColumnPositionMode(
246
- Proto6.ProtoPositionMode.REVERSE_FOLIO
300
+ Proto7.ProtoPositionMode.REVERSE_FOLIO
247
301
  );
248
302
  })(ColumnPosition || (ColumnPosition = {}));
249
303
  var ColumnDefinition = class {
@@ -253,20 +307,20 @@ var ColumnDefinition = class {
253
307
  }
254
308
  toDocFrame(applyImmediate) {
255
309
  const result = [
256
- Proto6.Node.create({
257
- cDef: Proto6.ProtoCDef.create({
310
+ Proto7.Node.create({
311
+ cDef: Proto7.ProtoCDef.create({
258
312
  Uuid: this.uuid,
259
- columSettings: Proto6.ProtoColumnSettings.create({
260
- width: Proto6.ProtoBoxedMeasure.create({
313
+ columSettings: Proto7.ProtoColumnSettings.create({
314
+ width: Proto7.ProtoBoxedMeasure.create({
261
315
  isNull: false,
262
316
  value: this.props.width.toDocFrame()
263
317
  }),
264
- positionOffset: Proto6.ProtoBoxedMeasure.create({
318
+ positionOffset: Proto7.ProtoBoxedMeasure.create({
265
319
  isNull: false,
266
320
  value: this.props.positionOffset.toDocFrame()
267
321
  }),
268
322
  positionMode: this.props.position.toDocFrame(),
269
- interColumnSpace: Proto6.ProtoBoxedMeasure.create({
323
+ interColumnSpace: Proto7.ProtoBoxedMeasure.create({
270
324
  isNull: false,
271
325
  value: this.props.interColumnSpace.toDocFrame()
272
326
  })
@@ -276,8 +330,8 @@ var ColumnDefinition = class {
276
330
  ];
277
331
  if (applyImmediate) {
278
332
  result.push(
279
- Proto6.Node.create({
280
- applyCDef: Proto6.ProtoApplyProtoCDef.create({
333
+ Proto7.Node.create({
334
+ applyCDef: Proto7.ProtoApplyProtoCDef.create({
281
335
  cDefUuid: this.uuid
282
336
  })
283
337
  })
@@ -306,61 +360,11 @@ var ColumnDefinitions = {
306
360
  // src/Content/Document/index.ts
307
361
  import Proto14 from "docframe-types";
308
362
 
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
363
  // src/OutputFormat/index.ts
364
+ var OutputFormat_exports = {};
365
+ __export(OutputFormat_exports, {
366
+ OutputFormat: () => OutputFormat
367
+ });
364
368
  var OutputFormat = /* @__PURE__ */ ((OutputFormat2) => {
365
369
  OutputFormat2["PDF"] = "pdf";
366
370
  OutputFormat2["PNG"] = "png";
@@ -612,7 +616,9 @@ var Font = class {
612
616
  }
613
617
  toDocFrame() {
614
618
  return ProtoFont.create({
615
- name: this.name
619
+ name: this.name,
620
+ // TODO: suppot font mapping for docframe step
621
+ id: 5
616
622
  });
617
623
  }
618
624
  };
@@ -882,13 +888,14 @@ var index_default = {
882
888
  Color,
883
889
  Colors
884
890
  },
891
+ Connection,
885
892
  Content: Content_default,
886
893
  Font: {
887
894
  Font,
888
895
  StandardFonts
889
896
  },
890
897
  Measure: Measure_exports,
891
- OutputFormat,
898
+ Output: OutputFormat_exports,
892
899
  ParagraphFormat
893
900
  };
894
901
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-d2",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Deuterium is a TypeScript library for professional output creation.",
5
5
  "keywords": [
6
6
  "pdf",
@@ -69,12 +69,12 @@
69
69
  "ts-jest": "^29.2.6",
70
70
  "tslib": "2.8.1",
71
71
  "tsup": "8.4.0",
72
- "typescript": "5.8.2",
73
- "uuid": "^11.1.0"
72
+ "typescript": "5.8.2"
74
73
  },
75
74
  "dependencies": {
76
75
  "axios": "^1.8.3",
77
76
  "docframe-types": "^0.4.2",
78
- "form-data": "^4.0.2"
77
+ "form-data": "^4.0.2",
78
+ "uuid": "^11.1.0"
79
79
  }
80
- }
80
+ }