cvdl-ts 1.0.11 → 1.0.13

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/Elem.js ADDED
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.instantiate = exports.boundWidth = exports.break_lines = exports.justifiedLines = exports.fillFonts = exports.parseMarkdownItem = exports.scaleWidth = exports.withBackgroundColor = exports.withWidth = exports.withAlignment = exports.withMargin = exports.withFont = exports.withTextWidth = exports.withIsFill = exports.asRef = exports.withIsRef = exports.withUrl = exports.withItem = exports.from = exports.default_ = exports.copy = exports.elem = void 0;
27
+ const Font = __importStar(require("./Font"));
28
+ const _1 = require(".");
29
+ const Row_1 = require("./Row");
30
+ const Resume_1 = require("./Resume");
31
+ const marked = __importStar(require("marked"));
32
+ const ts_pattern_1 = require("ts-pattern");
33
+ const Utils_1 = require("./Utils");
34
+ function defaultSpanProps() {
35
+ return {
36
+ is_italic: false,
37
+ is_bold: false,
38
+ is_code: false,
39
+ is_link: false,
40
+ };
41
+ }
42
+ function elem(item, url, is_ref, is_fill, is_markdown, text_width, font, margin, alignment, width, background_color) {
43
+ return {
44
+ tag: "Elem",
45
+ item,
46
+ url,
47
+ is_ref,
48
+ is_fill,
49
+ is_markdown,
50
+ text_width,
51
+ font,
52
+ margin,
53
+ alignment,
54
+ width,
55
+ background_color,
56
+ };
57
+ }
58
+ exports.elem = elem;
59
+ function copy(e) {
60
+ return { ...e };
61
+ }
62
+ exports.copy = copy;
63
+ function default_() {
64
+ return {
65
+ tag: "Elem",
66
+ item: "",
67
+ url: null,
68
+ is_ref: false,
69
+ is_fill: false,
70
+ is_markdown: false,
71
+ text_width: _1.Width.default_(),
72
+ font: Font.default_(),
73
+ margin: _1.Margin.default_(),
74
+ alignment: _1.Alignment.default_(),
75
+ width: _1.Width.default_(),
76
+ background_color: "Transparent",
77
+ };
78
+ }
79
+ exports.default_ = default_;
80
+ function from(w) {
81
+ return { ...default_(), ...w };
82
+ }
83
+ exports.from = from;
84
+ function withItem(e, item) {
85
+ return { ...e, item };
86
+ }
87
+ exports.withItem = withItem;
88
+ function withUrl(e, url) {
89
+ return { ...e, url };
90
+ }
91
+ exports.withUrl = withUrl;
92
+ function withIsRef(e, is_ref) {
93
+ return { ...e, is_ref };
94
+ }
95
+ exports.withIsRef = withIsRef;
96
+ function asRef(e) {
97
+ return withIsRef(e, true);
98
+ }
99
+ exports.asRef = asRef;
100
+ function withIsFill(e, is_fill) {
101
+ return { ...e, is_fill };
102
+ }
103
+ exports.withIsFill = withIsFill;
104
+ function withTextWidth(e, text_width) {
105
+ return { ...e, text_width };
106
+ }
107
+ exports.withTextWidth = withTextWidth;
108
+ function withFont(e, font) {
109
+ return { ...e, font };
110
+ }
111
+ exports.withFont = withFont;
112
+ function withMargin(e, margin) {
113
+ return { ...e, margin };
114
+ }
115
+ exports.withMargin = withMargin;
116
+ function withAlignment(e, alignment) {
117
+ return { ...e, alignment };
118
+ }
119
+ exports.withAlignment = withAlignment;
120
+ function withWidth(e, width) {
121
+ return { ...e, width };
122
+ }
123
+ exports.withWidth = withWidth;
124
+ function withBackgroundColor(e, background_color) {
125
+ return { ...e, background_color };
126
+ }
127
+ exports.withBackgroundColor = withBackgroundColor;
128
+ function scaleWidth(e, scale) {
129
+ return withWidth(e, _1.Width.scale(e.width, scale));
130
+ }
131
+ exports.scaleWidth = scaleWidth;
132
+ function flatten(ts, sp) {
133
+ const spans = [];
134
+ for (const t of ts) {
135
+ spans.push(...flattenToken(t, sp));
136
+ }
137
+ return spans;
138
+ }
139
+ function flattenToken(t, sp) {
140
+ return (0, ts_pattern_1.match)(t)
141
+ .returnType()
142
+ .with({ type: "paragraph", tokens: ts_pattern_1.P.select("tokens") }, ({ tokens }) => {
143
+ // console.log("[paragraph]", tokens);
144
+ return flatten(tokens, sp);
145
+ })
146
+ .with({ type: "strong", tokens: ts_pattern_1.P.select("tokens") }, ({ tokens }) => {
147
+ // console.log("[strong]", tokens);
148
+ return flatten(tokens, { ...sp, is_bold: true });
149
+ })
150
+ .with({ type: "em", tokens: ts_pattern_1.P.select("tokens") }, ({ tokens }) => {
151
+ // console.log("[em]", tokens);
152
+ return flatten(tokens, { ...sp, is_italic: true });
153
+ })
154
+ .with({ type: "codespan", text: ts_pattern_1.P.select("text") }, ({ text }) => {
155
+ // console.log("[codespan]", text);
156
+ return [{ ...sp, is_code: true, text, link: null }];
157
+ })
158
+ .with({ type: "text", tokens: ts_pattern_1.P.select("tokens") }, ({ tokens }) => {
159
+ return flatten(tokens, sp);
160
+ })
161
+ .with({ type: "text", text: ts_pattern_1.P.select("text") }, ({ text }) => {
162
+ const result = [];
163
+ if (text.startsWith(" ")) {
164
+ result.push({ ...sp, text: " ", link: null });
165
+ }
166
+ result.push({ ...sp, text: text.trim(), link: null });
167
+ if (text.endsWith(" ")) {
168
+ result.push({ ...sp, text: " ", link: null });
169
+ }
170
+ else if (text.endsWith("\n")) {
171
+ result.push({ ...sp, text: "\n", link: null });
172
+ }
173
+ return result;
174
+ })
175
+ .otherwise((e) => {
176
+ // console.log(`Unknown token type: ${JSON.stringify(e)}`);
177
+ return [{ ...defaultSpanProps(), text: e.raw, link: null }];
178
+ });
179
+ }
180
+ function parseMarkdownItem(item) {
181
+ const spans = [];
182
+ for (const token of marked.lexer(item)) {
183
+ spans.push(...flatten([token], defaultSpanProps()));
184
+ }
185
+ return spans;
186
+ }
187
+ exports.parseMarkdownItem = parseMarkdownItem;
188
+ function fillFonts(e, fonts) {
189
+ const simpleSpans = e.is_markdown ? parseMarkdownItem(e.item) : [{ ...defaultSpanProps(), text: e.item, font: e.font, link: null }];
190
+ const spans = [];
191
+ for (const span of simpleSpans) {
192
+ const font = e.is_markdown ? (0, Utils_1.with_)(e.font, ({
193
+ // style: span.is_italic ? "Italic" : "Normal",
194
+ weight: span.is_bold ? "Bold" : "Medium",
195
+ })) : e.font;
196
+ if (span.text === " " || span.text === "\n") {
197
+ const width = Font.get_width(font, span.text, fonts);
198
+ spans.push({ ...span, font, width });
199
+ continue;
200
+ }
201
+ span.text.split(/\s+/).forEach(word => {
202
+ const width = Font.get_width(font, word, fonts);
203
+ spans.push({ ...span, text: word, font, width });
204
+ spans.push({ ...span, text: " ", font, width: Font.get_width(font, " ", fonts) });
205
+ });
206
+ }
207
+ const text_width = spans.reduce((acc, span) => acc + span.width, 0);
208
+ if (e.is_fill) {
209
+ return (0, Utils_1.with_)(e, {
210
+ width: _1.Width.absolute(Math.min(_1.Width.get_fixed_unchecked(e.width), text_width)),
211
+ text_width: _1.Width.absolute(text_width),
212
+ spans
213
+ });
214
+ }
215
+ else {
216
+ return (0, Utils_1.with_)(e, { text_width: _1.Width.absolute(text_width), spans });
217
+ }
218
+ }
219
+ exports.fillFonts = fillFonts;
220
+ function justifiedLines(e, lines, font_dict) {
221
+ const rowLines = [];
222
+ for (const line of lines.slice(0, -1)) {
223
+ const words = line.item.split(/\s+/);
224
+ const r = (0, Row_1.row)([], line.margin, line.alignment, line.width, false, false);
225
+ words.forEach(word => {
226
+ const word_width = Font.get_width(e.font, word, font_dict);
227
+ r.elements.push(elem(word, null, false, false, false, _1.Width.absolute(word_width), this.font, _1.Margin.default_(), _1.Alignment.default_(), _1.Width.absolute(word_width), this.background_color));
228
+ });
229
+ rowLines.push(Row_1.row);
230
+ }
231
+ rowLines.push((0, Row_1.row)([withAlignment(lines[lines.length - 1], "Left")], lines[0].margin, "Left", lines[0].width, false, false));
232
+ return rowLines;
233
+ }
234
+ exports.justifiedLines = justifiedLines;
235
+ function break_lines(e, font_dict) {
236
+ if (_1.Width.get_fixed_unchecked(e.text_width) <= _1.Width.get_fixed_unchecked(e.width)) {
237
+ return [e];
238
+ }
239
+ const lines = [];
240
+ // todo: I'm sure this implementation is pretty buggy. Note to future me, fix
241
+ // this.
242
+ const words = e.item.split(/\s+/);
243
+ const widths = words.map((word) => Font.get_width(e.font, word, font_dict));
244
+ const space_width = Font.get_width(e.font, " ", font_dict);
245
+ let start = 0;
246
+ let width = widths[0];
247
+ const max_width = _1.Width.get_fixed_unchecked(e.width);
248
+ for (let i = 1; i < words.length; i++) {
249
+ const candidate_width = width + space_width + widths[i];
250
+ if (candidate_width > max_width) {
251
+ const line = words.slice(start, i).join(" ");
252
+ const line_width = Font.get_width(e.font, line, font_dict);
253
+ lines.push(withTextWidth(withItem(e, line), _1.Width.absolute(line_width)));
254
+ start = i;
255
+ width = widths[i];
256
+ }
257
+ else {
258
+ width += space_width + widths[i];
259
+ }
260
+ }
261
+ const line = words.slice(start).join(" ");
262
+ const line_width = Font.get_width(e.font, line, font_dict);
263
+ lines.push(withTextWidth(withItem(e, line), _1.Width.absolute(line_width)));
264
+ if (e.alignment === "Justified") {
265
+ return justifiedLines(e, lines, font_dict);
266
+ }
267
+ return lines;
268
+ }
269
+ exports.break_lines = break_lines;
270
+ function boundWidth(e, width) {
271
+ if (!_1.Width.is_fill(e.width)) {
272
+ return withIsFill(withWidth(e, _1.Width.absolute(Math.min(_1.Width.get_fixed_unchecked(e.width), width))), false);
273
+ }
274
+ else {
275
+ return withIsFill(withWidth(e, _1.Width.absolute(width)), true);
276
+ }
277
+ }
278
+ exports.boundWidth = boundWidth;
279
+ function instantiate(e, section, fields) {
280
+ if (!e.is_ref) {
281
+ return e;
282
+ }
283
+ const itemType = fields.find(f => f.name === e.item);
284
+ console.log(`Found item type: ${JSON.stringify(itemType)}`);
285
+ if (itemType.type.tag === "MarkdownString") {
286
+ console.log(`Found markdown string: ${e.item}`);
287
+ e.is_markdown = true;
288
+ }
289
+ const text = section.get(e.item);
290
+ if (text === undefined) {
291
+ return withIsRef(withItem(e, ""), false);
292
+ }
293
+ else {
294
+ if (text.tag === "Url") {
295
+ return withIsRef(withUrl(withItem(e, text.value.text), text.value.url), false);
296
+ }
297
+ else {
298
+ return withIsRef(withItem(e, Resume_1.ItemContent.toString(text)), false);
299
+ }
300
+ }
301
+ }
302
+ exports.instantiate = instantiate;
@@ -4,11 +4,11 @@ import { DataSchema } from "./DataSchema";
4
4
  import { LayoutSchema } from "./LayoutSchema";
5
5
  import { ResumeLayout } from "./ResumeLayout";
6
6
  import { Storage } from "./Storage";
7
- import { Font } from "./Font";
7
+ import * as Font from "./Font";
8
8
  export declare class FileStorage implements Storage {
9
9
  dir: string;
10
10
  constructor(dir: string);
11
- load_font(font: Font): Promise<Buffer>;
11
+ load_font(font: Font.t): Promise<Buffer>;
12
12
  initiate_storage(): Promise<void>;
13
13
  list_resumes(): Promise<string[]>;
14
14
  list_data_schemas(): Promise<string[]>;
@@ -1,5 +1,28 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
3
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
28
  };
@@ -30,13 +53,14 @@ const Resume_1 = require("./Resume");
30
53
  const DataSchema_1 = require("./DataSchema");
31
54
  const LayoutSchema_1 = require("./LayoutSchema");
32
55
  const ResumeLayout_1 = require("./ResumeLayout");
56
+ const Font = __importStar(require("./Font"));
33
57
  class FileStorage {
34
58
  constructor(dir) {
35
59
  this.dir = "";
36
60
  this.dir = dir;
37
61
  }
38
62
  load_font(font) {
39
- return Promise.resolve(fs_1.default.readFileSync(this.dir + font.full_name() + ".ttf"));
63
+ return Promise.resolve(fs_1.default.readFileSync(this.dir + Font.full_name(font) + ".ttf"));
40
64
  }
41
65
  initiate_storage() {
42
66
  // Create data_dir/resumes if it does not exist
package/dist/Font.d.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  import { FontDict } from "./AnyLayout";
2
- export declare class Font {
2
+ export type t = {
3
3
  name: string;
4
4
  size: number;
5
5
  weight: FontWeight;
6
6
  style: FontStyle;
7
7
  source: FontSource;
8
- constructor(name: string, size: number, weight: FontWeight, style: FontStyle, source: FontSource);
9
- static fromJson(json: unknown): Font;
10
- toJson(): unknown;
11
- static default_(): Font;
12
- full_name(): string;
13
- get_width(text: string, fonts: FontDict): number;
14
- get_height(fonts: FontDict): number;
15
- }
8
+ };
9
+ type Font = t;
10
+ export declare function font(name: string, size: number, weight: FontWeight, style: FontStyle, source: FontSource): Font;
11
+ export declare function fromJson(json: unknown): Font;
12
+ export declare function default_(): Font;
13
+ export declare function full_name(f: Font): string;
14
+ export declare function get_width(f: Font, text: string, fonts: FontDict): number;
15
+ export declare function get_height(f: Font, fonts: FontDict): number;
16
16
  export type FontSource = "Local" | "System" | "Remote";
17
17
  export type FontWeight = "Light" | "Medium" | "Bold";
18
18
  export type FontStyle = "Normal" | "Italic";
19
+ export {};
package/dist/Font.js CHANGED
@@ -1,47 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Font = void 0;
4
- class Font {
5
- constructor(name, size, weight, style, source) {
6
- this.name = name;
7
- this.size = size;
8
- this.weight = weight;
9
- this.style = style;
10
- this.source = source;
11
- }
12
- static fromJson(json) {
13
- if (typeof json !== "object" || json === null) {
14
- return Font.default_();
15
- }
16
- const name = ("name" in json) ? json.name : "Exo";
17
- const size = ("size" in json) ? json.size : 12;
18
- const weight = ("weight" in json) ? json.weight : "Medium";
19
- const style = ("style" in json) ? json.style : "Normal";
20
- const source = ("source" in json) ? json.source : "System";
21
- return new Font(name, size, weight, style, source);
22
- }
23
- toJson() {
24
- return {
25
- name: this.name,
26
- size: this.size,
27
- weight: this.weight,
28
- style: this.style,
29
- source: this.source
30
- };
31
- }
32
- static default_() {
33
- return new Font("Exo", 12, "Medium", "Normal", "System");
34
- }
35
- full_name() {
36
- return this.name + "-" + this.weight + (this.style === "Italic" ? "Italic" : "");
37
- }
38
- get_width(text, fonts) {
39
- const font = fonts.get_font(this.full_name());
40
- return (font.layout(text).glyphs.reduce((acc, glyph) => acc + glyph.advanceWidth, 0) / font.unitsPerEm) * this.size;
41
- }
42
- get_height(fonts) {
43
- const font = fonts.get_font(this.full_name());
44
- return (font.bbox.height / font.unitsPerEm) * this.size;
45
- }
3
+ exports.get_height = exports.get_width = exports.full_name = exports.default_ = exports.fromJson = exports.font = void 0;
4
+ function font(name, size, weight, style, source) {
5
+ return {
6
+ name,
7
+ size,
8
+ weight,
9
+ style,
10
+ source,
11
+ };
46
12
  }
47
- exports.Font = Font;
13
+ exports.font = font;
14
+ function fromJson(json) {
15
+ return {
16
+ ...default_(),
17
+ name: json["name"],
18
+ size: json["size"],
19
+ weight: json["weight"],
20
+ style: json["style"],
21
+ source: json["source"],
22
+ };
23
+ }
24
+ exports.fromJson = fromJson;
25
+ function default_() {
26
+ return {
27
+ name: "Exo",
28
+ size: 12,
29
+ weight: "Medium",
30
+ style: "Normal",
31
+ source: "System",
32
+ };
33
+ }
34
+ exports.default_ = default_;
35
+ function full_name(f) {
36
+ return f.name + "-" + f.weight + (f.style === "Italic" ? "Italic" : "");
37
+ }
38
+ exports.full_name = full_name;
39
+ function get_width(f, text, fonts) {
40
+ const font = fonts.get_font(full_name(f));
41
+ return (font.layout(text).glyphs.reduce((acc, glyph) => acc + glyph.advanceWidth, 0) / font.unitsPerEm) * f.size;
42
+ }
43
+ exports.get_width = get_width;
44
+ function get_height(f, fonts) {
45
+ const font = fonts.get_font(full_name(f));
46
+ return (font.bbox.height / font.unitsPerEm) * f.size;
47
+ }
48
+ exports.get_height = get_height;
package/dist/Layout.d.ts CHANGED
@@ -1,85 +1,56 @@
1
1
  import * as Margin from "./Margin";
2
2
  import * as Alignment from "./Alignment";
3
3
  import * as Width from "./Width";
4
- import { Font } from "./Font";
4
+ import * as Font from "./Font";
5
5
  import { ItemContent } from "./Resume";
6
6
  import { Box } from "./Box";
7
- import { ElementBox, FontDict } from "./AnyLayout";
7
+ import { FontDict } from "./AnyLayout";
8
8
  import { Point } from "./Point";
9
- export type ContainerType = Stack | Row;
10
- export type LayoutType = Stack | Row | Elem;
11
- export declare class SectionLayout {
12
- inner: Stack | Row | Elem;
13
- bounding_box: Box | null;
14
- constructor(inner: Stack | Row | Elem);
15
- copy(): SectionLayout;
16
- static constrMap(tag: string): Stack | Row | Elem;
17
- static empty(): SectionLayout;
18
- static fromJson(json: unknown): SectionLayout;
19
- toJson(): any;
20
- width(): Width.t;
21
- is_container(): boolean;
22
- is_fill(): boolean;
23
- is_ref(): boolean;
24
- type_(): "Stack" | "Row" | "Elem";
25
- tag_(): "Stack" | "FlexRow" | "FrozenRow" | "Ref" | "Text";
26
- fonts(): Font[];
27
- with_margin(margin: Margin.t): SectionLayout;
28
- with_alignment(alignment: Alignment.t): SectionLayout;
29
- with_width(width: Width.t): SectionLayout;
30
- total_elements_width(): number;
31
- is_instantiated(): boolean;
32
- instantiate(section: Map<string, ItemContent>): SectionLayout;
33
- static instantiate_ref_element(element: Elem, section: Map<string, ItemContent>): SectionLayout;
34
- bound_width(width: number): SectionLayout;
35
- scale_width(document_width: number): SectionLayout;
36
- normalize(width: number, font_dict: FontDict): SectionLayout;
37
- fill_fonts(font_dict: FontDict): SectionLayout;
38
- break_lines(font_dict: FontDict): SectionLayout;
39
- compute_boxes(font_dict: FontDict): [ElementBox, SectionLayout];
40
- compute_textbox_positions(textbox_positions: [Box, Elem][], top_left: Point, font_dict: FontDict): number;
41
- }
42
- export declare class Stack {
43
- tag: "Stack";
44
- elements: SectionLayout[];
45
- margin: Margin.t;
46
- alignment: Alignment.t;
47
- width: Width.t;
48
- is_fill: boolean;
49
- constructor(elements: SectionLayout[], margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean);
50
- static stack(elements: SectionLayout[], margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean): SectionLayout;
51
- copy(): Stack;
52
- static default_(): Stack;
53
- instantiate(section: Map<string, ItemContent>): Stack;
54
- with_elements(elements: SectionLayout[]): Stack;
55
- with_margin(margin: Margin.t): Stack;
56
- with_alignment(alignment: Alignment.t): Stack;
57
- with_width(width: Width.t): Stack;
58
- bound_width(width: number): Stack;
59
- scale_width(w: number): Stack;
60
- }
61
- export declare class Row {
62
- tag: "Row";
63
- elements: SectionLayout[];
64
- margin: Margin.t;
65
- alignment: Alignment.t;
66
- width: Width.t;
67
- is_frozen: boolean;
68
- is_fill: boolean;
69
- constructor(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean);
70
- static row(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean): SectionLayout;
71
- copy(): Row;
72
- static default_(): Row;
73
- instantiate(section: Map<string, ItemContent>): Row;
74
- with_elements(elements: SectionLayout[]): Row;
75
- with_margin(margin: Margin.t): Row;
76
- with_alignment(alignment: Alignment.t): Row;
77
- with_width(width: Width.t): Row;
78
- elements_width(): number;
79
- bound_width(width: number): Row;
80
- scale_width(w: number): Row;
81
- break_lines(font_dict: FontDict): Row[];
82
- }
9
+ import * as Stack from "./Stack";
10
+ import * as Row from "./Row";
11
+ import * as Elem from "./Elem";
12
+ import { Field } from "./DataSchema";
13
+ export type Container = Stack.t | Row.t;
14
+ export type t = Stack.t | Row.t | Elem.t;
15
+ type Layout = t;
16
+ export type RenderedStack = Stack.t & {
17
+ bounding_box: Box;
18
+ elements: RenderedLayout[];
19
+ };
20
+ export type RenderedRow = Row.t & {
21
+ bounding_box: Box;
22
+ elements: RenderedLayout[];
23
+ };
24
+ export type RenderedElem = Elem.t & {
25
+ bounding_box: Box;
26
+ };
27
+ export type RenderedLayout = RenderedStack | RenderedRow | RenderedElem;
28
+ export declare function default_(tag: string): Stack.t | Row.t | Elem.t;
29
+ export declare function empty(): Layout;
30
+ export declare function fromJson(json: unknown): Layout;
31
+ export declare function type_(l: Layout): string;
32
+ export declare function tag_(l: Layout): string;
33
+ export declare function toJson(l: Layout): unknown;
34
+ export declare function isContainer(l: Layout): boolean;
35
+ export declare function isFill(l: Layout): boolean;
36
+ export declare function isRef(l: Layout): boolean;
37
+ export declare function fonts(l: Layout): Font.t[];
38
+ export declare function withMargin(l: Layout, margin: Margin.t): Layout;
39
+ export declare function withAlignment(l: Layout, alignment: Alignment.t): Layout;
40
+ export declare function withWidth(l: Layout, width: Width.t): Layout;
41
+ export declare function totalElementsWidth(l: Layout): number;
42
+ export declare function isInstantiated(l: Layout): boolean;
43
+ export declare function instantiate(l: Layout, section: Map<string, ItemContent>, fields: Field.t[]): Layout;
44
+ export declare function boundWidth(l: Layout, width: number): Layout;
45
+ export declare function scaleWidth(l: Layout, document_width: number): Layout;
46
+ export declare function normalize(l: Layout, width: number, font_dict: FontDict): Layout;
47
+ export declare function fillFonts(l: Layout, font_dict: FontDict): Layout;
48
+ export declare function breakLines(l: Layout, font_dict: FontDict): Layout;
49
+ export declare function computeBoxes(l: Layout, font_dict: FontDict): RenderedLayout;
50
+ export declare function computeTextboxPositions(l: Layout, top_left: Point, font_dict: FontDict): {
51
+ depth: number;
52
+ renderedLayout: RenderedLayout;
53
+ };
83
54
  export type Color = "Transparent" | "Light Yellow" | "Light Brown" | "Light Green" | "Light Beige" | "Light Blue" | "Blue";
84
55
  export declare const ColorMap: {
85
56
  Transparent: string;
@@ -90,34 +61,4 @@ export declare const ColorMap: {
90
61
  "Light Blue": string;
91
62
  Blue: string;
92
63
  };
93
- export declare class Elem {
94
- tag: "Elem";
95
- item: string;
96
- url: string | null;
97
- is_ref: boolean;
98
- is_fill: boolean;
99
- text_width: Width.t;
100
- font: Font;
101
- margin: Margin.t;
102
- alignment: Alignment.t;
103
- width: Width.t;
104
- background_color: Color;
105
- constructor(item: string, url: string | null, is_ref: boolean, is_fill: boolean, text_width: Width.t, font: Font, margin: Margin.t, alignment: Alignment.t, width: Width.t, background_color: Color);
106
- static elem(item: string, url: string | null, is_ref: boolean, is_fill: boolean, text_width: Width.t, font: Font, margin: Margin.t, alignment: Alignment.t, width: Width.t, background_color: Color): SectionLayout;
107
- copy(): Elem;
108
- static default_(): Elem;
109
- with_item(item: string): Elem;
110
- as_ref(): Elem;
111
- with_font(font: Font): Elem;
112
- with_url(url: string): Elem;
113
- with_margin(margin: Margin.t): Elem;
114
- with_alignment(alignment: Alignment.t): Elem;
115
- with_width(width: Width.t): Elem;
116
- with_text_width(text_width: Width.t): Elem;
117
- with_is_fill(is_fill: boolean): Elem;
118
- scale_width(w: number): Elem;
119
- fill_fonts(fonts: FontDict): Elem;
120
- justified_lines(lines: Elem[], font_dict: FontDict): Row[];
121
- break_lines(font_dict: FontDict): LayoutType[];
122
- bound_width(width: number): Elem;
123
- }
64
+ export {};