cvdl-ts 1.0.18 → 1.0.20

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/Alignment.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default_ = void 0;
3
+ exports.default_ = default_;
4
4
  function default_() {
5
5
  return "Left";
6
6
  }
7
- exports.default_ = default_;
@@ -1,37 +1,38 @@
1
1
  import { DataSchema } from "./DataSchema";
2
2
  import { LayoutSchema } from "./LayoutSchema";
3
3
  import { Storage } from "./Storage";
4
- import { Resume } from "./Resume";
5
4
  import { ResumeLayout } from "./ResumeLayout";
6
- import * as fontkit from 'fontkit';
7
- import { Layout } from ".";
5
+ import * as fontkit from "fontkit";
6
+ import * as Layout from "./Layout";
7
+ import * as Resume from "./Resume";
8
8
  export type ElementPath = {
9
- tag: 'none';
9
+ tag: "none";
10
10
  } | {
11
- tag: 'section';
11
+ tag: "section";
12
12
  section: string;
13
13
  } | {
14
- tag: 'item';
14
+ tag: "item";
15
15
  section: string;
16
16
  item: number;
17
17
  } | {
18
- tag: 'field';
18
+ tag: "field";
19
19
  section: string;
20
20
  item: number;
21
21
  field: string;
22
22
  };
23
23
  export type RenderProps = {
24
- resume: Resume;
24
+ resume: Resume.t;
25
25
  layout_schemas: LayoutSchema[];
26
- data_schemas: DataSchema[];
26
+ data_schemas: DataSchema.t[];
27
27
  resume_layout: ResumeLayout;
28
+ bindings: Map<string, unknown>;
28
29
  storage: Storage;
29
30
  fontDict?: FontDict;
30
31
  };
31
32
  export declare class FontDict {
32
33
  fonts: Map<string, fontkit.Font>;
33
34
  constructor();
34
- load_fonts_from_schema(schema: LayoutSchema, storage: Storage): Promise<void>;
35
+ load_fonts(storage: Storage): Promise<this>;
35
36
  get_font(name: string): fontkit.Font;
36
37
  }
37
- export declare function render({ resume, layout_schemas, data_schemas, resume_layout, storage, fontDict }: RenderProps): Promise<Layout.RenderedLayout[]>;
38
+ export declare function render({ resume, layout_schemas, data_schemas, resume_layout, bindings, fontDict, }: RenderProps): Promise<Layout.RenderedLayout[]>;
package/dist/AnyLayout.js CHANGED
@@ -23,26 +23,30 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.render = exports.FontDict = void 0;
26
+ exports.FontDict = void 0;
27
+ exports.render = render;
27
28
  const ResumeLayout_1 = require("./ResumeLayout");
28
29
  const fontkit = __importStar(require("fontkit"));
29
- const _1 = require(".");
30
+ const Layout = __importStar(require("./Layout"));
31
+ const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat())));
30
32
  class FontDict {
31
33
  constructor() {
32
34
  this.fonts = new Map();
33
35
  }
34
- async load_fonts_from_schema(schema, storage) {
35
- for (const font of schema.fonts()) {
36
- const fontName = _1.Font.full_name(font);
37
- console.log(`Loading font ${fontName}`);
36
+ async load_fonts(storage) {
37
+ const variants = cartesian(["Exo", "OpenSans", "SourceCodePro"], ["Medium", "Bold"], ["", "Italic"]);
38
+ await Promise.all(variants.map(async ([name, weight, style]) => {
39
+ const fontName = `${name}-${weight}${style}`;
40
+ console.error(`Loading font ${fontName}`);
38
41
  if (this.fonts.has(fontName)) {
39
42
  console.log(`Font ${fontName} is already loaded`);
40
- continue;
43
+ return;
41
44
  }
42
- const font_data = await storage.load_font(font);
45
+ const font_data = await storage.load_font(fontName);
43
46
  const fontkit_font = fontkit.create(font_data);
44
47
  this.fonts.set(fontName, fontkit_font);
45
- }
48
+ }));
49
+ return this;
46
50
  }
47
51
  get_font(name) {
48
52
  const font = this.fonts.get(name);
@@ -53,37 +57,37 @@ class FontDict {
53
57
  }
54
58
  }
55
59
  exports.FontDict = FontDict;
56
- async function render({ resume, layout_schemas, data_schemas, resume_layout, storage, fontDict }) {
60
+ async function render({ resume, layout_schemas, data_schemas, resume_layout, bindings, fontDict, }) {
57
61
  // Compute the total usable width by subtracting the margins from the document width
58
- const width = resume_layout.width - (resume_layout.margin.left + resume_layout.margin.right);
62
+ const width = resume_layout.width -
63
+ (resume_layout.margin.left + resume_layout.margin.right);
59
64
  // If the resume is double column, then the usable width is halved
60
65
  const column_width = resume_layout.column_type.tag === "SingleColumn"
61
66
  ? width
62
- : (width - (0, ResumeLayout_1.vertical_margin)(resume_layout.column_type) / 2.0);
67
+ : width - (0, ResumeLayout_1.vertical_margin)(resume_layout.column_type) / 2.0;
63
68
  const layouts = [];
64
69
  console.error("Rendering sections...");
65
70
  for (const section of resume.sections) {
66
71
  // Render Section Header
67
72
  // 1. Find the layout schema for the section
68
73
  console.info("Computing section: ", section.section_name);
69
- const layout_schema = layout_schemas
70
- .find(s => s.schema_name === section.layout_schema);
74
+ const layout_schema = layout_schemas.find((s) => s.schema_name === section.layout_schema);
71
75
  if (layout_schema === undefined) {
72
76
  throw new Error(`Could not find layout schema ${section.layout_schema}`);
73
77
  }
74
78
  let start_time = Date.now();
75
- await fontDict.load_fonts_from_schema(layout_schema, storage);
79
+ // await fontDict.load_fonts_from_schema(layout_schema, storage);
76
80
  let end_time = Date.now();
77
81
  console.info(`Font loading time: ${end_time - start_time}ms for section ${section.section_name}`);
78
82
  // 2. Find the data schema for the section
79
- const data_schema = data_schemas.find(s => s.schema_name === section.data_schema);
83
+ const data_schema = data_schemas.find((s) => s.schema_name === section.data_schema);
80
84
  if (data_schema === undefined) {
81
85
  throw new Error(`Could not find data schema ${section.data_schema}`);
82
86
  }
83
87
  start_time = Date.now();
84
88
  // 3. Render the header
85
- const layout = _1.Layout.computeBoxes(_1.Layout.normalize(_1.Layout.instantiate(layout_schema.header_layout_schema, section.data, data_schema.header_schema), column_width, fontDict), fontDict);
86
- layout.path = { tag: 'section', section: section.section_name };
89
+ const layout = Layout.computeBoxes(Layout.normalize(Layout.instantiate(layout_schema.header_layout_schema, section.data, data_schema.header_schema, bindings), column_width, fontDict), fontDict);
90
+ layout.path = { tag: "section", section: section.section_name };
87
91
  console.info("Header is computed");
88
92
  layouts.push(layout);
89
93
  end_time = Date.now();
@@ -92,8 +96,8 @@ async function render({ resume, layout_schemas, data_schemas, resume_layout, sto
92
96
  // Render Section Items
93
97
  for (const [index, item] of section.items.entries()) {
94
98
  // 3. Render the item
95
- const layout = _1.Layout.computeBoxes(_1.Layout.normalize(_1.Layout.instantiate(layout_schema.item_layout_schema, item.fields, data_schema.item_schema), column_width, fontDict), fontDict);
96
- layout.path = { tag: 'item', section: section.section_name, item: index };
99
+ const layout = Layout.computeBoxes(Layout.normalize(Layout.instantiate(layout_schema.item_layout_schema, item, data_schema.item_schema, bindings), column_width, fontDict), fontDict);
100
+ layout.path = { tag: "item", section: section.section_name, item: index };
97
101
  layouts.push(layout);
98
102
  }
99
103
  end_time = Date.now();
@@ -102,4 +106,3 @@ async function render({ resume, layout_schemas, data_schemas, resume_layout, sto
102
106
  console.log("Position calculations are completed.");
103
107
  return layouts;
104
108
  }
105
- exports.render = render;
File without changes
File without changes
@@ -32,27 +32,16 @@ export declare namespace DocumentDataType {
32
32
  };
33
33
  type t = Date | PureString | MarkdownString | PureNumber | Type | List | Types;
34
34
  type DocumentDataType = t;
35
- function parse(s: string): DocumentDataType;
36
- function print(d: DocumentDataType): string;
37
35
  }
38
- export declare namespace Field {
36
+ export type Field = {
37
+ name: string;
38
+ type: DocumentDataType.t;
39
+ };
40
+ export declare namespace DataSchema {
39
41
  type t = {
40
- name: string;
41
- type: DocumentDataType.t;
42
- };
43
- type Field = t;
44
- function fromJson(json: unknown): Field;
45
- function toJson(f: Field): unknown;
46
- }
47
- export declare class DataSchema {
48
- schema_name: string;
49
- header_schema: Field.t[];
50
- item_schema: Field.t[];
51
- constructor(schema_name: string, header_schema: Field.t[], item_schema: Field.t[]);
52
- static fromJson(json: unknown): DataSchema;
53
- toJson(): {
54
42
  schema_name: string;
55
- header_schema: unknown[];
56
- item_schema: unknown[];
43
+ header_schema: Field[];
44
+ item_schema: Field[];
57
45
  };
46
+ function dataSchema(schema_name: string, header_schema: Field[], item_schema: Field[]): t;
58
47
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataSchema = exports.Field = exports.DocumentDataType = exports.DateFormat = void 0;
3
+ exports.DataSchema = exports.DateFormat = void 0;
4
4
  var DateFormat;
5
5
  (function (DateFormat) {
6
6
  DateFormat.formats = [
@@ -16,10 +16,9 @@ var DateFormat;
16
16
  "Mon YYYY",
17
17
  "Mon DD, YYYY",
18
18
  "YYYY",
19
- "unknown"
19
+ "unknown",
20
20
  ];
21
21
  DateFormat.print = (date, format) => {
22
- console.error(date);
23
22
  const d = new Date(date + "T00:00:00");
24
23
  const year = d.getFullYear();
25
24
  const month = d.getMonth() + 1;
@@ -29,115 +28,22 @@ var DateFormat;
29
28
  result = result.replace("YY", year.toString().slice(-2));
30
29
  result = result.replace("MM", month.toString().padStart(2, "0"));
31
30
  result = result.replace("DD", day.toString().padStart(2, "0"));
32
- result = result.replace("Month", d.toLocaleString('default', { month: 'long' }));
33
- result = result.replace("Mon", d.toLocaleString('default', { month: 'short' }));
31
+ result = result.replace("Month", d.toLocaleString("default", { month: "long" }));
32
+ result = result.replace("Mon", d.toLocaleString("default", { month: "short" }));
34
33
  return result;
35
34
  };
36
35
  DateFormat.parse = (date) => {
37
36
  const d = new Date(date + "T00:00:00");
38
- console.error(d);
39
37
  if (isNaN(d.getTime())) {
40
38
  return "";
41
39
  }
42
40
  return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
43
41
  };
44
42
  })(DateFormat || (exports.DateFormat = DateFormat = {}));
45
- var DocumentDataType;
46
- (function (DocumentDataType) {
47
- function parse(s) {
48
- if (s === "Date") {
49
- return { tag: "Date", format: s.length > 4 ? s.slice(5, -1).trim() : "YYYY-MM-DD" };
50
- }
51
- else if (s === "String") {
52
- return { tag: "String" };
53
- }
54
- else if (s === "MarkdownString") {
55
- return { tag: "MarkdownString" };
56
- }
57
- else if (s === "Number") {
58
- return { tag: "Number" };
59
- }
60
- else if (s.startsWith("List")) {
61
- return { tag: "List", value: parse(s.slice(5, -1).trim()) };
62
- }
63
- else if (s.includes("|")) {
64
- return { tag: "Types", value: s.split("|").map((s) => s.trim()).map(parse) };
65
- }
66
- else {
67
- throw new Error("Invalid DocumentDataType: " + s);
68
- }
69
- }
70
- DocumentDataType.parse = parse;
71
- function print(d) {
72
- switch (d.tag) {
73
- case "Date":
74
- return "Date";
75
- case "String":
76
- return "String";
77
- case "MarkdownString":
78
- return "MarkdownString";
79
- case "Number":
80
- return "Number";
81
- case "Type":
82
- return d.value;
83
- case "List":
84
- return "List<" + print(d.value) + ">";
85
- case "Types":
86
- return d.value.map(print).join(" | ");
87
- }
88
- }
89
- DocumentDataType.print = print;
90
- })(DocumentDataType || (exports.DocumentDataType = DocumentDataType = {}));
91
- var Field;
92
- (function (Field) {
93
- function fromJson(json) {
94
- if (typeof json !== "object" || json === null) {
95
- throw new Error("Field must be an object");
96
- }
97
- if (!("name" in json) || !("type" in json)) {
98
- throw new Error("Field must have a name and type");
99
- }
100
- if (typeof json.name !== "string") {
101
- throw new Error("Field name must be a string");
102
- }
103
- if (typeof json.type !== "string") {
104
- throw new Error("Field type must be a string");
105
- }
106
- return {
107
- name: json.name,
108
- type: DocumentDataType.parse(json.type),
109
- };
110
- }
111
- Field.fromJson = fromJson;
112
- function toJson(f) {
113
- return {
114
- name: f.name,
115
- type: DocumentDataType.print(f.type),
116
- };
117
- }
118
- Field.toJson = toJson;
119
- })(Field || (exports.Field = Field = {}));
120
- class DataSchema {
121
- constructor(schema_name, header_schema, item_schema) {
122
- this.schema_name = schema_name;
123
- this.header_schema = header_schema;
124
- this.item_schema = item_schema;
125
- }
126
- static fromJson(json) {
127
- if (typeof json !== "object" || json === null) {
128
- throw new Error("DataSchema must be an object");
129
- }
130
- if (!("schema_name" in json) || !("header_schema" in json) || !("item_schema" in json)) {
131
- throw new Error("DataSchema must have a schema_name, header_schema, and item_schema");
132
- }
133
- return new DataSchema(json.schema_name, json.header_schema.map(Field.fromJson), json.item_schema.map(Field.fromJson));
134
- }
135
- toJson() {
136
- return {
137
- schema_name: this.schema_name,
138
- header_schema: this.header_schema.map(Field.toJson),
139
- item_schema: this.item_schema.map(Field.toJson),
140
- };
43
+ var DataSchema;
44
+ (function (DataSchema) {
45
+ function dataSchema(schema_name, header_schema, item_schema) {
46
+ return { schema_name, header_schema, item_schema };
141
47
  }
142
- }
143
- exports.DataSchema = DataSchema;
48
+ DataSchema.dataSchema = dataSchema;
49
+ })(DataSchema || (exports.DataSchema = DataSchema = {}));
@@ -0,0 +1,35 @@
1
+ import { DataSchema } from "./DataSchema";
2
+ import { LayoutSchema } from "./LayoutSchema";
3
+ import { ResumeLayout } from "./ResumeLayout";
4
+ import * as Resume from "./Resume";
5
+ import { ResumeSection } from "./Resume";
6
+ export declare const Basics: DataSchema.t;
7
+ export declare const BasicsLayout: LayoutSchema;
8
+ export declare const Work: DataSchema.t;
9
+ export declare const WorkLayout: LayoutSchema;
10
+ export declare const Volunteer: DataSchema.t;
11
+ export declare const VolunteerLayout: LayoutSchema;
12
+ export declare const Education: DataSchema.t;
13
+ export declare const EducationLayout: LayoutSchema;
14
+ export declare const Awards: DataSchema.t;
15
+ export declare const AwardsLayout: LayoutSchema;
16
+ export declare const Certificates: DataSchema.t;
17
+ export declare const CertificatesLayout: LayoutSchema;
18
+ export declare const Publications: DataSchema.t;
19
+ export declare const PublicationsLayout: LayoutSchema;
20
+ export declare const Skills: DataSchema.t;
21
+ export declare const SkillsLayout: LayoutSchema;
22
+ export declare const Languages: DataSchema.t;
23
+ export declare const LanguagesLayout: LayoutSchema;
24
+ export declare const Interests: DataSchema.t;
25
+ export declare const InterestsLayout: LayoutSchema;
26
+ export declare const References: DataSchema.t;
27
+ export declare const ReferencesLayout: LayoutSchema;
28
+ export declare const Projects: DataSchema.t;
29
+ export declare const ProjectsLayout: LayoutSchema;
30
+ export declare const DefaultDataSchemas: DataSchema.t[];
31
+ export declare const DefaultLayoutSchemas: LayoutSchema[];
32
+ export declare const DefaultBindings: Map<string, unknown>;
33
+ export declare const DefaultResumeLayout: ResumeLayout;
34
+ export declare const DefaultSections: ResumeSection.t[];
35
+ export declare const DefaultResume: Resume.t;