cvdl-ts 1.0.4 → 1.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.
@@ -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 [_, item] of section.items.entries()) {
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();
@@ -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() {
@@ -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-schemas2.json").then((response) => {
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("Resume not found");
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("Data schema not found");
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("Layout schema not found");
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("Resume layout not found");
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);
@@ -110,14 +108,12 @@ class LocalStorage {
110
108
  schema.header_layout_schema = layout_schema.header_layout_schema;
111
109
  schema.item_layout_schema = layout_schema.item_layout_schema;
112
110
  }
113
- console.error(schemas);
114
111
  localStorage.setItem("section_layouts", JSON.stringify(schemas.map((schema) => schema.toJson())));
115
112
  }
116
113
  save_resume_layout(resume_layout) {
117
114
  throw new Error("Method not implemented.");
118
115
  }
119
116
  async load_font(font) {
120
- console.error(font);
121
117
  const path = `fonts/${font.full_name()}.ttf`;
122
118
  if (!localStorage.getItem(path)) {
123
119
  const response = await fetch(`https://d2bnplhbawocbk.cloudfront.net/data/${path}`);
package/dist/Resume.js CHANGED
@@ -35,8 +35,6 @@ class Resume {
35
35
  }
36
36
  }
37
37
  data_schemas() {
38
- console.error(this.sections);
39
- console.error(this.sections.map(section => section.data_schema));
40
38
  return this.sections.map(section => section.data_schema);
41
39
  }
42
40
  layout_schemas() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cvdl-ts",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Typescript Implementation of CVDL Compiler",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",