cvdl-ts 1.0.4 → 1.0.6
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/AnyLayout.d.ts +16 -0
- package/dist/AnyLayout.js +11 -4
- package/dist/DataSchema.d.ts +5 -0
- package/dist/DataSchema.js +7 -0
- package/dist/Layout.d.ts +7 -2
- package/dist/Layout.js +24 -9
- package/dist/LayoutSchema.js +0 -1
- package/dist/LocalStorage.d.ts +1 -1
- package/dist/LocalStorage.js +16 -10
- package/dist/Resume.js +0 -2
- package/package.json +1 -1
package/dist/AnyLayout.d.ts
CHANGED
|
@@ -6,9 +6,25 @@ import { LocalStorage } from "./LocalStorage";
|
|
|
6
6
|
import { Resume } from "./Resume";
|
|
7
7
|
import { ResumeLayout } from "./ResumeLayout";
|
|
8
8
|
import * as fontkit from 'fontkit';
|
|
9
|
+
export type ElementPath = {
|
|
10
|
+
tag: 'none';
|
|
11
|
+
} | {
|
|
12
|
+
tag: 'section';
|
|
13
|
+
section: string;
|
|
14
|
+
} | {
|
|
15
|
+
tag: 'item';
|
|
16
|
+
section: string;
|
|
17
|
+
item: number;
|
|
18
|
+
} | {
|
|
19
|
+
tag: 'field';
|
|
20
|
+
section: string;
|
|
21
|
+
item: number;
|
|
22
|
+
field: string;
|
|
23
|
+
};
|
|
9
24
|
export declare class ElementBox {
|
|
10
25
|
bounding_box: Box;
|
|
11
26
|
elements: [Box, Elem][];
|
|
27
|
+
path?: ElementPath;
|
|
12
28
|
constructor(bounding_box: Box, elements: [Box, Elem][]);
|
|
13
29
|
move_y_by(y: number): ElementBox;
|
|
14
30
|
move_x_by(x: number): ElementBox;
|
package/dist/AnyLayout.js
CHANGED
|
@@ -30,6 +30,7 @@ class ElementBox {
|
|
|
30
30
|
constructor(bounding_box, elements) {
|
|
31
31
|
this.bounding_box = bounding_box;
|
|
32
32
|
this.elements = elements;
|
|
33
|
+
this.path = { tag: 'none' };
|
|
33
34
|
}
|
|
34
35
|
move_y_by(y) {
|
|
35
36
|
this.bounding_box = this.bounding_box.move_y_by(y);
|
|
@@ -58,9 +59,7 @@ class FontDict {
|
|
|
58
59
|
console.log(`Font ${font.full_name()} is already loaded`);
|
|
59
60
|
continue;
|
|
60
61
|
}
|
|
61
|
-
console.log(`Source ${font.source}`);
|
|
62
62
|
const font_data = await storage.load_font(font);
|
|
63
|
-
console.error(font_data);
|
|
64
63
|
const fontkit_font = fontkit.create(font_data);
|
|
65
64
|
this.fonts.set(font.full_name(), fontkit_font);
|
|
66
65
|
}
|
|
@@ -99,7 +98,6 @@ async function render({ resume, layout_schemas, data_schemas, resume_layout, sto
|
|
|
99
98
|
console.info(`Font loading time: ${end_time - start_time}ms for section ${section.section_name}`);
|
|
100
99
|
// 2. Find the data schema for the section
|
|
101
100
|
const _data_schema = data_schemas.find(s => s.schema_name === section.data_schema);
|
|
102
|
-
console.error(data_schemas);
|
|
103
101
|
if (_data_schema === undefined) {
|
|
104
102
|
throw new Error(`Could not find data schema ${section.data_schema}`);
|
|
105
103
|
}
|
|
@@ -113,12 +111,16 @@ async function render({ resume, layout_schemas, data_schemas, resume_layout, sto
|
|
|
113
111
|
.compute_boxes(font_dict);
|
|
114
112
|
end_time = Date.now();
|
|
115
113
|
console.info(`Header rendering time: ${end_time - start_time}ms for section ${section.section_name}`);
|
|
114
|
+
result.path = {
|
|
115
|
+
tag: 'section',
|
|
116
|
+
section: section.section_name
|
|
117
|
+
};
|
|
116
118
|
boxes.push(result);
|
|
117
119
|
start_time = Date.now();
|
|
118
120
|
// Render Section Items
|
|
119
121
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
120
122
|
// @ts-nocheck
|
|
121
|
-
for (const [
|
|
123
|
+
for (const [index, item] of section.items.entries()) {
|
|
122
124
|
console.log("Computing item");
|
|
123
125
|
// 1. Find the layout schema for the section
|
|
124
126
|
const layout_schema = layout_schemas
|
|
@@ -139,6 +141,11 @@ async function render({ resume, layout_schemas, data_schemas, resume_layout, sto
|
|
|
139
141
|
.instantiate(item.fields)
|
|
140
142
|
.normalize(column_width, font_dict)
|
|
141
143
|
.compute_boxes(font_dict);
|
|
144
|
+
result.path = {
|
|
145
|
+
tag: 'item',
|
|
146
|
+
section: section.section_name,
|
|
147
|
+
item: index
|
|
148
|
+
};
|
|
142
149
|
boxes.push(result);
|
|
143
150
|
}
|
|
144
151
|
end_time = Date.now();
|
package/dist/DataSchema.d.ts
CHANGED
|
@@ -24,4 +24,9 @@ export declare class DataSchema {
|
|
|
24
24
|
item_schema: Field[];
|
|
25
25
|
constructor(schema_name: string, header_schema: Field[], item_schema: Field[]);
|
|
26
26
|
static fromJson(json: unknown): DataSchema;
|
|
27
|
+
toJson(): {
|
|
28
|
+
schema_name: string;
|
|
29
|
+
header_schema: Field[];
|
|
30
|
+
item_schema: Field[];
|
|
31
|
+
};
|
|
27
32
|
}
|
package/dist/DataSchema.js
CHANGED
|
@@ -16,5 +16,12 @@ class DataSchema {
|
|
|
16
16
|
}
|
|
17
17
|
return new DataSchema(json.schema_name, json.header_schema, json.item_schema);
|
|
18
18
|
}
|
|
19
|
+
toJson() {
|
|
20
|
+
return {
|
|
21
|
+
schema_name: this.schema_name,
|
|
22
|
+
header_schema: this.header_schema,
|
|
23
|
+
item_schema: this.item_schema,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
27
|
exports.DataSchema = DataSchema;
|
package/dist/Layout.d.ts
CHANGED
|
@@ -42,7 +42,8 @@ export declare class Stack {
|
|
|
42
42
|
margin: Margin;
|
|
43
43
|
alignment: Alignment;
|
|
44
44
|
width: Width;
|
|
45
|
-
constructor(elements: SectionLayout[], margin
|
|
45
|
+
constructor(elements: SectionLayout[], margin?: Margin, alignment?: Alignment, width?: Width);
|
|
46
|
+
static stack(elements: SectionLayout[], margin?: Margin, alignment?: Alignment, width?: Width): SectionLayout;
|
|
46
47
|
copy(): Stack;
|
|
47
48
|
static default_(): Stack;
|
|
48
49
|
instantiate(section: Map<string, ItemContent>): Stack;
|
|
@@ -60,7 +61,8 @@ export declare class Row {
|
|
|
60
61
|
alignment: Alignment;
|
|
61
62
|
width: Width;
|
|
62
63
|
is_frozen: boolean;
|
|
63
|
-
constructor(elements: SectionLayout[], is_frozen
|
|
64
|
+
constructor(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin, alignment?: Alignment, width?: Width);
|
|
65
|
+
static row(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin, alignment?: Alignment, width?: Width): SectionLayout;
|
|
64
66
|
copy(): Row;
|
|
65
67
|
static default_(): Row;
|
|
66
68
|
instantiate(section: Map<string, ItemContent>): Row;
|
|
@@ -85,9 +87,12 @@ export declare class Elem {
|
|
|
85
87
|
alignment: Alignment;
|
|
86
88
|
width: Width;
|
|
87
89
|
constructor(item: string, url: string | null, is_ref: boolean, is_fill: boolean, text_width: Width, font: Font, margin: Margin, alignment: Alignment, width: Width);
|
|
90
|
+
static elem(item: string, url: string | null, is_ref: boolean, is_fill: boolean, text_width: Width, font: Font, margin: Margin, alignment: Alignment, width: Width): SectionLayout;
|
|
88
91
|
copy(): Elem;
|
|
89
92
|
static default_(): Elem;
|
|
90
93
|
with_item(item: string): Elem;
|
|
94
|
+
as_ref(): Elem;
|
|
95
|
+
with_font(font: Font): Elem;
|
|
91
96
|
with_url(url: string): Elem;
|
|
92
97
|
with_margin(margin: Margin): Elem;
|
|
93
98
|
with_alignment(alignment: Alignment): Elem;
|
package/dist/Layout.js
CHANGED
|
@@ -333,15 +333,18 @@ class Stack {
|
|
|
333
333
|
constructor(elements, margin, alignment, width) {
|
|
334
334
|
this.tag = "Stack";
|
|
335
335
|
this.elements = elements;
|
|
336
|
-
this.margin = margin;
|
|
337
|
-
this.alignment = alignment;
|
|
338
|
-
this.width = width;
|
|
336
|
+
this.margin = margin !== null && margin !== void 0 ? margin : Margin_1.Margin.default_();
|
|
337
|
+
this.alignment = alignment !== null && alignment !== void 0 ? alignment : Alignment_1.Alignment.default_();
|
|
338
|
+
this.width = width !== null && width !== void 0 ? width : Width_1.Width.default_();
|
|
339
|
+
}
|
|
340
|
+
static stack(elements, margin, alignment, width) {
|
|
341
|
+
return new SectionLayout(new Stack(elements, margin, alignment, width));
|
|
339
342
|
}
|
|
340
343
|
copy() {
|
|
341
344
|
return new Stack(this.elements.map((e) => e.copy()), this.margin.copy(), this.alignment, Width_1.Width.copy(this.width));
|
|
342
345
|
}
|
|
343
346
|
static default_() {
|
|
344
|
-
return new Stack([]
|
|
347
|
+
return new Stack([]);
|
|
345
348
|
}
|
|
346
349
|
instantiate(section) {
|
|
347
350
|
return new Stack(this.elements.map(e => e.instantiate(section)), this.margin, this.alignment, this.width);
|
|
@@ -376,16 +379,19 @@ class Row {
|
|
|
376
379
|
constructor(elements, is_frozen, margin, alignment, width) {
|
|
377
380
|
this.tag = "Row";
|
|
378
381
|
this.elements = elements;
|
|
379
|
-
this.is_frozen = is_frozen;
|
|
380
|
-
this.margin = margin;
|
|
381
|
-
this.alignment = alignment;
|
|
382
|
-
this.width = width;
|
|
382
|
+
this.is_frozen = is_frozen !== null && is_frozen !== void 0 ? is_frozen : false;
|
|
383
|
+
this.margin = margin !== null && margin !== void 0 ? margin : Margin_1.Margin.default_();
|
|
384
|
+
this.alignment = alignment !== null && alignment !== void 0 ? alignment : Alignment_1.Alignment.default_();
|
|
385
|
+
this.width = width !== null && width !== void 0 ? width : Width_1.Width.default_();
|
|
386
|
+
}
|
|
387
|
+
static row(elements, is_frozen, margin, alignment, width) {
|
|
388
|
+
return new SectionLayout(new Row(elements, is_frozen, margin, alignment, width));
|
|
383
389
|
}
|
|
384
390
|
copy() {
|
|
385
391
|
return new Row(this.elements.map((e) => e.copy()), this.is_frozen, this.margin.copy(), this.alignment, Width_1.Width.copy(this.width));
|
|
386
392
|
}
|
|
387
393
|
static default_() {
|
|
388
|
-
return new Row([]
|
|
394
|
+
return new Row([]);
|
|
389
395
|
}
|
|
390
396
|
instantiate(section) {
|
|
391
397
|
return new Row(this.elements.map(e => e.instantiate(section)), this.is_frozen, this.margin, this.alignment, this.width);
|
|
@@ -454,6 +460,9 @@ class Elem {
|
|
|
454
460
|
this.alignment = alignment;
|
|
455
461
|
this.width = width;
|
|
456
462
|
}
|
|
463
|
+
static elem(item, url, is_ref, is_fill, text_width, font, margin, alignment, width) {
|
|
464
|
+
return new SectionLayout(new Elem(item, url, is_ref, is_fill, text_width, font, margin, alignment, width));
|
|
465
|
+
}
|
|
457
466
|
copy() {
|
|
458
467
|
return new Elem(this.item, this.url, this.is_ref, this.is_fill, Width_1.Width.copy(this.text_width), this.font, this.margin.copy(), this.alignment, Width_1.Width.copy(this.width));
|
|
459
468
|
}
|
|
@@ -463,6 +472,12 @@ class Elem {
|
|
|
463
472
|
with_item(item) {
|
|
464
473
|
return new Elem(item, this.url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width);
|
|
465
474
|
}
|
|
475
|
+
as_ref() {
|
|
476
|
+
return new Elem(this.item, this.url, true, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width);
|
|
477
|
+
}
|
|
478
|
+
with_font(font) {
|
|
479
|
+
return new Elem(this.item, this.url, this.is_ref, this.is_fill, this.text_width, font, this.margin, this.alignment, this.width);
|
|
480
|
+
}
|
|
466
481
|
with_url(url) {
|
|
467
482
|
return new Elem(this.item, url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width);
|
|
468
483
|
}
|
package/dist/LayoutSchema.js
CHANGED
|
@@ -13,7 +13,6 @@ class LayoutSchema {
|
|
|
13
13
|
return new LayoutSchema(schema_name, data_schema_name, Layout_1.SectionLayout.empty(), Layout_1.SectionLayout.empty());
|
|
14
14
|
}
|
|
15
15
|
static fromJson(json) {
|
|
16
|
-
console.error(json);
|
|
17
16
|
return new LayoutSchema(json.schema_name, json.data_schema_name, Layout_1.SectionLayout.fromJson(json.header_layout_schema), Layout_1.SectionLayout.fromJson(json.item_layout_schema));
|
|
18
17
|
}
|
|
19
18
|
fonts() {
|
package/dist/LocalStorage.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class LocalStorage {
|
|
|
15
15
|
load_layout_schema(schema_name: string): LayoutSchema;
|
|
16
16
|
load_resume_layout(schema_name: string): ResumeLayout;
|
|
17
17
|
save_resume(resume_name: string, resume_data: Resume): void;
|
|
18
|
-
save_data_schema(data_schema: DataSchema):
|
|
18
|
+
save_data_schema(data_schema: DataSchema): void;
|
|
19
19
|
save_layout_schema(layout_schema: LayoutSchema): void;
|
|
20
20
|
save_resume_layout(resume_layout: ResumeLayout): void;
|
|
21
21
|
load_font(font: Font): Promise<Buffer>;
|
package/dist/LocalStorage.js
CHANGED
|
@@ -23,7 +23,7 @@ class LocalStorage {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
if (!localStorage.getItem("section_layouts")) {
|
|
26
|
-
fetch("https://d2bnplhbawocbk.cloudfront.net/data/layout-
|
|
26
|
+
fetch("https://d2bnplhbawocbk.cloudfront.net/data/layout-schemas3.json").then((response) => {
|
|
27
27
|
response.json().then((section_layouts) => {
|
|
28
28
|
localStorage.setItem("section_layouts", JSON.stringify(section_layouts));
|
|
29
29
|
});
|
|
@@ -54,25 +54,23 @@ class LocalStorage {
|
|
|
54
54
|
return schemas;
|
|
55
55
|
}
|
|
56
56
|
load_resume(resume_name) {
|
|
57
|
-
console.log(resume_name);
|
|
58
57
|
const resume = JSON.parse(localStorage.getItem("resumes") || "[]").find((resume) => resume.name === resume_name);
|
|
59
58
|
if (!resume) {
|
|
60
|
-
throw new Error(
|
|
59
|
+
throw new Error(`Resume(${resume_name}) not found`);
|
|
61
60
|
}
|
|
62
61
|
return Resume_1.Resume.fromJson(resume.data);
|
|
63
62
|
}
|
|
64
63
|
load_data_schema(schema_name) {
|
|
65
|
-
console.error(schema_name);
|
|
66
64
|
const schema = JSON.parse(localStorage.getItem("data_schemas") || "[]").find((schema) => schema.schema_name === schema_name);
|
|
67
65
|
if (!schema) {
|
|
68
|
-
throw new Error(
|
|
66
|
+
throw new Error(`Data Schema(${schema_name}) not found`);
|
|
69
67
|
}
|
|
70
68
|
return DataSchema_1.DataSchema.fromJson(schema);
|
|
71
69
|
}
|
|
72
70
|
load_layout_schema(schema_name) {
|
|
73
71
|
const schema = JSON.parse(localStorage.getItem("section_layouts") || "[]").find((schema) => schema.schema_name === schema_name);
|
|
74
72
|
if (!schema) {
|
|
75
|
-
throw new Error(
|
|
73
|
+
throw new Error(`Layout Schema(${schema_name}) not found`);
|
|
76
74
|
}
|
|
77
75
|
return LayoutSchema_1.LayoutSchema.fromJson(schema);
|
|
78
76
|
}
|
|
@@ -80,7 +78,7 @@ class LocalStorage {
|
|
|
80
78
|
console.log(schema_name);
|
|
81
79
|
const schema = JSON.parse(localStorage.getItem("resume_layouts") || "[]").find((schema) => schema.schema_name === schema_name);
|
|
82
80
|
if (!schema) {
|
|
83
|
-
throw new Error(
|
|
81
|
+
throw new Error(`Resume Layout(${schema_name}) not found`);
|
|
84
82
|
}
|
|
85
83
|
console.info(schema);
|
|
86
84
|
return ResumeLayout_1.ResumeLayout.fromJson(schema);
|
|
@@ -97,7 +95,17 @@ class LocalStorage {
|
|
|
97
95
|
localStorage.setItem("resumes", JSON.stringify(resumes));
|
|
98
96
|
}
|
|
99
97
|
save_data_schema(data_schema) {
|
|
100
|
-
|
|
98
|
+
const schemasDirectMapped = JSON.parse(localStorage.getItem("data_schemas") || "[]");
|
|
99
|
+
const schemas = schemasDirectMapped.map((schema) => DataSchema_1.DataSchema.fromJson(schema));
|
|
100
|
+
const schema = schemas.find((schema) => schema.schema_name === data_schema.schema_name);
|
|
101
|
+
if (!schema) {
|
|
102
|
+
schemas.push(data_schema);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
schema.header_schema = data_schema.header_schema;
|
|
106
|
+
schema.item_schema = data_schema.item_schema;
|
|
107
|
+
}
|
|
108
|
+
localStorage.setItem("data_schemas", JSON.stringify(schemas.map((schema) => schema.toJson())));
|
|
101
109
|
}
|
|
102
110
|
save_layout_schema(layout_schema) {
|
|
103
111
|
const schemasDirectMapped = JSON.parse(localStorage.getItem("section_layouts") || "[]");
|
|
@@ -110,14 +118,12 @@ class LocalStorage {
|
|
|
110
118
|
schema.header_layout_schema = layout_schema.header_layout_schema;
|
|
111
119
|
schema.item_layout_schema = layout_schema.item_layout_schema;
|
|
112
120
|
}
|
|
113
|
-
console.error(schemas);
|
|
114
121
|
localStorage.setItem("section_layouts", JSON.stringify(schemas.map((schema) => schema.toJson())));
|
|
115
122
|
}
|
|
116
123
|
save_resume_layout(resume_layout) {
|
|
117
124
|
throw new Error("Method not implemented.");
|
|
118
125
|
}
|
|
119
126
|
async load_font(font) {
|
|
120
|
-
console.error(font);
|
|
121
127
|
const path = `fonts/${font.full_name()}.ttf`;
|
|
122
128
|
if (!localStorage.getItem(path)) {
|
|
123
129
|
const response = await fetch(`https://d2bnplhbawocbk.cloudfront.net/data/${path}`);
|
package/dist/Resume.js
CHANGED