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.
@@ -0,0 +1,691 @@
1
+ // import * as Margin from "./Margin";
2
+ // import * as Alignment from "./Alignment";
3
+ // import * as Width from "./Width";
4
+ // import { Font } from "./Font";
5
+ // import { ItemContent } from "./Resume";
6
+ // import { Box } from "./Box";
7
+ // import { ElementBox, FontDict } from "./AnyLayout";
8
+ // import { Point } from "./Point";
9
+ // export type ContainerType = Stack | Row;
10
+ // export type LayoutType = Stack | Row | Elem;
11
+ // export class SectionLayout {
12
+ // inner: Stack | Row | Elem;
13
+ // bounding_box: Box | null = null;
14
+ // constructor(inner: Stack | Row | Elem) {
15
+ // this.inner = inner;
16
+ // }
17
+ // copy(): SectionLayout {
18
+ // return new SectionLayout(this.inner.copy());
19
+ // }
20
+ // static constrMap(tag: string) {
21
+ // switch (tag) {
22
+ // case "Stack": return Stack.default_();
23
+ // case "FlexRow": return Row.default_();
24
+ // case "FrozenRow": {
25
+ // const row = Row.default_();
26
+ // row.is_frozen = true;
27
+ // return row;
28
+ // }
29
+ // case "Text": return Elem.default_();
30
+ // case "Ref": {
31
+ // const elem = Elem.default_();
32
+ // elem.is_ref = true;
33
+ // return elem;
34
+ // }
35
+ // }
36
+ // }
37
+ // static empty(): SectionLayout {
38
+ // return new SectionLayout(Stack.default_());
39
+ // }
40
+ // static fromJson(json: unknown): SectionLayout {
41
+ // const key = Object.keys(json)[0];
42
+ // switch (key) {
43
+ // case 'Stack':
44
+ // case 'FlexRow':
45
+ // case 'FrozenRow': {
46
+ // const container = SectionLayout.constrMap(key) as ContainerType;
47
+ // container.elements = json[key].elements.map((element: unknown) => SectionLayout.fromJson(element));
48
+ // container.margin = json[key].margin;
49
+ // container.alignment = json[key].alignment;
50
+ // container.width = Width.fromJson(json[key].width);
51
+ // return new SectionLayout(container);
52
+ // }
53
+ // case 'Ref':
54
+ // case 'Text': {
55
+ // const inner = SectionLayout.constrMap(key) as Elem;
56
+ // inner.item = json[key].item;
57
+ // inner.margin = json[key].margin;
58
+ // inner.alignment = json[key].alignment;
59
+ // inner.width = Width.fromJson(json[key].width);
60
+ // inner.text_width = Width.fromJson(json[key].text_width);
61
+ // inner.font = Font.fromJson(json[key].font);
62
+ // inner.url = json[key].url;
63
+ // inner.background_color = json[key].background_color ?? "Transparent";
64
+ // return new SectionLayout(inner);
65
+ // }
66
+ // }
67
+ // throw new Error(`Invalid layout ${key}`);
68
+ // }
69
+ // toJson() {
70
+ // switch (this.type_()) {
71
+ // case "Stack":
72
+ // case "Row": {
73
+ // const container = this.inner as ContainerType;
74
+ // return {
75
+ // [this.tag_()]: {
76
+ // elements: container.elements.map(e => e.toJson()),
77
+ // margin: container.margin,
78
+ // alignment: container.alignment,
79
+ // width: Width.toJson(container.width),
80
+ // },
81
+ // };
82
+ // }
83
+ // case "Elem": {
84
+ // const elem = this.inner as Elem;
85
+ // return {
86
+ // [this.tag_()]: {
87
+ // item: elem.item,
88
+ // margin: elem.margin,
89
+ // alignment: elem.alignment,
90
+ // width: Width.toJson(elem.width),
91
+ // text_width: Width.toJson(elem.text_width),
92
+ // font: elem.font.toJson(),
93
+ // url: elem.url,
94
+ // background_color: elem.background_color,
95
+ // },
96
+ // };
97
+ // }
98
+ // }
99
+ // }
100
+ // width(): Width.t {
101
+ // return this.inner.width;
102
+ // }
103
+ // is_container(): boolean {
104
+ // return this.inner.tag === "Stack" || this.inner.tag === "Row";
105
+ // }
106
+ // is_fill(): boolean {
107
+ // switch (this.type_()) {
108
+ // case "Stack":
109
+ // return this.inner.is_fill && (this.inner as Stack).elements.map(e => e.is_fill()).reduce((a, b) => a && b, true);
110
+ // case "Row":
111
+ // return this.inner.is_fill && (this.inner as Row).elements.map(e => e.is_fill()).reduce((a, b) => a && b, true);
112
+ // case "Elem":
113
+ // return this.inner.is_fill
114
+ // }
115
+ // }
116
+ // is_ref(): boolean {
117
+ // return this.inner.tag === "Elem" && this.inner.is_ref;
118
+ // }
119
+ // type_(): "Stack" | "Row" | "Elem" {
120
+ // return this.inner.tag;
121
+ // }
122
+ // tag_(): "Stack" | "FlexRow" | "FrozenRow" | "Ref" | "Text" {
123
+ // switch (this.type_()) {
124
+ // case "Stack":
125
+ // return "Stack";
126
+ // case "Row":
127
+ // return (this.inner as Row).is_frozen ? "FrozenRow" : "FlexRow";
128
+ // case "Elem":
129
+ // return this.is_ref() ? "Ref" : "Text";
130
+ // }
131
+ // }
132
+ // fonts(): Font[] {
133
+ // switch (this.type_()) {
134
+ // case "Stack":
135
+ // return (this.inner as Stack).elements.map(e => e.fonts()).reduce((a, b) => a.concat(b), []);
136
+ // case "Row":
137
+ // return (this.inner as Row).elements.map(e => e.fonts()).reduce((a, b) => a.concat(b), []);
138
+ // case "Elem":
139
+ // return [(this.inner as Elem).font];
140
+ // }
141
+ // }
142
+ // with_margin(margin: Margin.t): SectionLayout {
143
+ // this.inner = this.inner.with_margin(margin);
144
+ // return this;
145
+ // }
146
+ // with_alignment(alignment: Alignment.t): SectionLayout {
147
+ // this.inner = this.inner.with_alignment(alignment);
148
+ // return this;
149
+ // }
150
+ // with_width(width: Width.t): SectionLayout {
151
+ // this.inner = this.inner.with_width(width);
152
+ // return this;
153
+ // }
154
+ // total_elements_width(): number {
155
+ // if (this.is_container()) {
156
+ // return (this.inner as ContainerType).elements.map(e => e.total_elements_width()).reduce((a, b) => a + b, 0.0);
157
+ // } else {
158
+ // return Width.get_fixed_unchecked(this.width());
159
+ // }
160
+ // }
161
+ // is_instantiated(): boolean {
162
+ // if (this.is_container()) {
163
+ // return (this.inner as ContainerType).elements.map(e => e.is_instantiated()).reduce((a, b) => a && b, true);
164
+ // } else {
165
+ // return !(this.inner as Elem).is_ref;
166
+ // }
167
+ // }
168
+ // instantiate(section: & Map<string, ItemContent>): SectionLayout {
169
+ // if (this.is_container()) {
170
+ // return new SectionLayout((this.inner as ContainerType).instantiate(section));
171
+ // } else if ((this.inner as Elem).is_ref) {
172
+ // return SectionLayout.instantiate_ref_element(this.inner as Elem, section)
173
+ // } else {
174
+ // return this;
175
+ // }
176
+ // }
177
+ // static instantiate_ref_element(
178
+ // element: Elem,
179
+ // section: & Map<string, ItemContent>,
180
+ // ): SectionLayout {
181
+ // const text = section.get(element.item);
182
+ // if (text === undefined) {
183
+ // return new SectionLayout(new Stack([], Margin.default_(), Alignment.default_(), Width.default_()));
184
+ // } else {
185
+ // element.item = ItemContent.toString(text);
186
+ // element.is_ref = false;
187
+ // if (text.tag === "Url") {
188
+ // return new SectionLayout(
189
+ // element.with_url(text.value.url).with_item(text.value.text),
190
+ // )
191
+ // } else {
192
+ // return new SectionLayout(element)
193
+ // }
194
+ // }
195
+ // }
196
+ // bound_width(width: number): SectionLayout {
197
+ // const bound = this.inner.width.tag === "Absolute" ? Math.min(this.inner.width.value, width)
198
+ // : this.inner.width.tag === "Fill" ? width
199
+ // : null;
200
+ // if (bound === null) {
201
+ // throw new Error("Cannot bound width of non-unitized widths!")
202
+ // }
203
+ // if (this.inner.tag === "Elem" && this.inner.is_ref) {
204
+ // throw new Error("Cannot propagate widths of uninstantiated layout")
205
+ // }
206
+ // this.inner = this.inner.bound_width(bound - this.inner.margin.left - this.inner.margin.right);
207
+ // return this;
208
+ // }
209
+ // scale_width(document_width: number): SectionLayout {
210
+ // if (this.is_ref()) {
211
+ // throw new Error("Cannot scale width of uninstantiated layout")
212
+ // }
213
+ // return new SectionLayout(this.inner.scale_width(document_width));
214
+ // }
215
+ // normalize(width: number, font_dict: FontDict): SectionLayout {
216
+ // console.debug(
217
+ // `Normalizing document, checking if document is instantiated...`,
218
+ // );
219
+ // if (!this.is_instantiated()) {
220
+ // throw Error("Cannot normalize uninstantiated layout");
221
+ // }
222
+ // console.debug("Document is instantiated. Scaling widths...");
223
+ // const scaled_layout = this.scale_width(width);
224
+ // console.debug("Widths are scaled. Bounding widths...");
225
+ // const bounded_layout = scaled_layout.bound_width(width);
226
+ // console.debug("Widths are bounded. Filling fonts...");
227
+ // const font_filled_layout = bounded_layout.fill_fonts(font_dict);
228
+ // console.debug("Fonts filled. Breaking lines...");
229
+ // const broken_layout = font_filled_layout.break_lines(font_dict);
230
+ // console.debug("Lines broken.");
231
+ // return broken_layout;
232
+ // }
233
+ // fill_fonts(font_dict: FontDict): SectionLayout {
234
+ // if (this.is_ref()) {
235
+ // throw new Error("Cannot fill fonts of uninstantiated layout")
236
+ // }
237
+ // switch (this.type_()) {
238
+ // case "Stack":
239
+ // case "Row":
240
+ // (this.inner as ContainerType).elements = (this.inner as ContainerType).elements.map(e => e.fill_fonts(font_dict));
241
+ // if (this.is_fill()) {
242
+ // const total_width = this.total_elements_width();
243
+ // if (total_width <= Width.get_fixed_unchecked(this.width())) {
244
+ // // throw `Cannot fill fonts of row with width ${JSON.stringify(this.width())} and total width ${total_width}`
245
+ // this.inner = this.inner.with_width(Width.absolute(total_width));
246
+ // }
247
+ // }
248
+ // break;
249
+ // case "Elem":
250
+ // this.inner = (this.inner as Elem).fill_fonts(font_dict);
251
+ // break;
252
+ // }
253
+ // return this;
254
+ // }
255
+ // break_lines(font_dict: FontDict): SectionLayout {
256
+ // switch (this.type_()) {
257
+ // case "Stack": {
258
+ // const stack = (this.inner as Stack);
259
+ // stack.elements = stack.elements.map(e => e.break_lines(font_dict));
260
+ // return this;
261
+ // }
262
+ // case "Row": {
263
+ // const row = (this.inner as Row);
264
+ // if (row.is_frozen) {
265
+ // const total_width = row
266
+ // .elements
267
+ // .map(e => Width.get_fixed_unchecked(e.width()))
268
+ // .reduce((a, b) => a + b, 0.0);
269
+ // if (total_width > Width.get_fixed_unchecked(this.width())) {
270
+ // throw `Cannot break lines of frozen row with width ${this.width()} and total width ${total_width}`
271
+ // } else {
272
+ // row.elements = row.elements.map(e => e.break_lines(font_dict));
273
+ // }
274
+ // } else {
275
+ // const lines = row.break_lines(font_dict).map(l => new SectionLayout(l));
276
+ // return new SectionLayout(new Stack(lines, row.margin, row.alignment, row.width));
277
+ // }
278
+ // return this;
279
+ // }
280
+ // case "Elem": {
281
+ // if (this.is_ref()) {
282
+ // throw new Error("Cannot break lines of uninstantiated layout")
283
+ // }
284
+ // const elem = (this.inner as Elem);
285
+ // const lines = elem.break_lines(font_dict).map(l => new SectionLayout(l));
286
+ // // Make last line left if it's justified
287
+ // if (lines[lines.length - 1].inner.alignment === "Justified") {
288
+ // lines[lines.length - 1] = lines[lines.length - 1].with_alignment("Left");
289
+ // }
290
+ // return new SectionLayout(new Stack(
291
+ // lines,
292
+ // elem.margin,
293
+ // elem.alignment,
294
+ // elem.width,
295
+ // ));
296
+ // }
297
+ // }
298
+ // }
299
+ // compute_boxes(font_dict: FontDict): [ElementBox, SectionLayout] {
300
+ // const textbox_positions: [Box, Elem][] = [];
301
+ // const top_left: Point = new Point(0.0, 0.0);
302
+ // const depth = this.compute_textbox_positions(textbox_positions, top_left, font_dict);
303
+ // const bounding_box = new Box(
304
+ // new Point(0.0, 0.0),
305
+ // new Point(Width.get_fixed_unchecked(this.width()), depth),
306
+ // );
307
+ // return [new ElementBox(bounding_box, textbox_positions), this];
308
+ // }
309
+ // compute_textbox_positions(
310
+ // textbox_positions: [Box, Elem][], top_left: Point, font_dict: FontDict,
311
+ // ): number {
312
+ // let depth = top_left.y;
313
+ // switch (this.type_()) {
314
+ // case "Stack": {
315
+ // const stack = (this.inner as Stack);
316
+ // top_left = top_left.move_y_by(stack.margin.top).move_x_by(stack.margin.left);
317
+ // const originalTopLeft = top_left;
318
+ // for (const element of stack.elements) {
319
+ // depth = element.compute_textbox_positions(textbox_positions, top_left, font_dict);
320
+ // top_left = top_left.move_y_to(depth);
321
+ // }
322
+ // this.bounding_box = new Box(
323
+ // originalTopLeft,
324
+ // originalTopLeft.move_y_by(depth).move_x_by(Width.get_fixed_unchecked(stack.width)),
325
+ // );
326
+ // return depth;
327
+ // }
328
+ // case "Row": {
329
+ // const row = (this.inner as Row);
330
+ // top_left = top_left.move_y_by(row.margin.top).move_x_by(row.margin.left);
331
+ // const originalTopLeft = top_left;
332
+ // let per_elem_space: number = 0.0;
333
+ // switch (row.alignment) {
334
+ // case "Center":
335
+ // top_left = top_left.move_x_by((Width.get_fixed_unchecked(row.width) - row.elements_width()) / 2.0);
336
+ // break;
337
+ // case "Right":
338
+ // top_left = top_left.move_x_by(Width.get_fixed_unchecked(row.width) - row.elements_width());
339
+ // break;
340
+ // case "Justified":
341
+ // per_elem_space = (Width.get_fixed_unchecked(row.width) - row.elements_width()) / (row.elements.length - 1);
342
+ // break;
343
+ // }
344
+ // for (const element of row.elements) {
345
+ // depth = Math.max(depth,
346
+ // element.compute_textbox_positions(textbox_positions, top_left, font_dict));
347
+ // top_left =
348
+ // top_left.move_x_by(Width.get_fixed_unchecked(element.width()) + per_elem_space);
349
+ // }
350
+ // this.bounding_box = new Box(
351
+ // originalTopLeft,
352
+ // originalTopLeft.move_y_by(depth).move_x_by(Width.get_fixed_unchecked(row.width)),
353
+ // );
354
+ // return depth;
355
+ // }
356
+ // case "Elem": {
357
+ // const elem = (this.inner as Elem);
358
+ // if (elem.is_ref) {
359
+ // throw new Error("Cannot compute textbox positions of uninstantiated layout")
360
+ // }
361
+ // if (elem.item === "") {
362
+ // return top_left.y;
363
+ // }
364
+ // const height = elem.font.get_height(font_dict);
365
+ // const width = Width.get_fixed_unchecked(elem.text_width);
366
+ // top_left = top_left.move_y_by(elem.margin.top).move_x_by(elem.margin.left);
367
+ // switch (elem.alignment) {
368
+ // case "Center":
369
+ // top_left = top_left.move_x_by((Width.get_fixed_unchecked(elem.width) - width) / 2.0);
370
+ // break;
371
+ // case "Right":
372
+ // top_left = top_left.move_x_by(Width.get_fixed_unchecked(elem.width) - width);
373
+ // break;
374
+ // }
375
+ // const textbox = new Box(top_left, top_left.move_x_by(width).move_y_by(height));
376
+ // textbox_positions.push([textbox, elem]);
377
+ // this.bounding_box = textbox;
378
+ // return top_left.y + height;
379
+ // }
380
+ // }
381
+ // }
382
+ // }
383
+ // export class Stack {
384
+ // tag: "Stack";
385
+ // elements: SectionLayout[];
386
+ // margin: Margin.t;
387
+ // alignment: Alignment.t;
388
+ // width: Width.t;
389
+ // is_fill: boolean;
390
+ // constructor(elements: SectionLayout[], margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean) {
391
+ // this.tag = "Stack";
392
+ // this.elements = elements;
393
+ // this.margin = margin ?? Margin.default_();
394
+ // this.alignment = alignment ?? Alignment.default_();
395
+ // this.width = width ?? Width.default_();
396
+ // this.is_fill = is_fill ?? false;
397
+ // }
398
+ // static stack(elements: SectionLayout[], margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean): SectionLayout {
399
+ // return new SectionLayout(new Stack(elements, margin, alignment, width, is_fill));
400
+ // }
401
+ // copy(): Stack {
402
+ // return new Stack(
403
+ // this.elements.map((e) => e.copy()),
404
+ // Margin.copy(this.margin),
405
+ // this.alignment,
406
+ // Width.copy(this.width)
407
+ // )
408
+ // }
409
+ // static default_(): Stack {
410
+ // return new Stack([]);
411
+ // }
412
+ // instantiate(section: & Map<string, ItemContent>): Stack {
413
+ // return new Stack(this.elements.map(e => e.instantiate(section)), this.margin, this.alignment, this.width, this.is_fill);
414
+ // }
415
+ // with_elements(elements: SectionLayout[]): Stack {
416
+ // return new Stack(elements, this.margin, this.alignment, this.width, this.is_fill);
417
+ // }
418
+ // with_margin(margin: Margin.t): Stack {
419
+ // return new Stack(this.elements, margin, this.alignment, this.width, this.is_fill);
420
+ // }
421
+ // with_alignment(alignment: Alignment.t): Stack {
422
+ // return new Stack(this.elements, this.margin, alignment, this.width, this.is_fill);
423
+ // }
424
+ // with_width(width: Width.t): Stack {
425
+ // return new Stack(this.elements, this.margin, this.alignment, width, this.is_fill);
426
+ // }
427
+ // bound_width(width: number): Stack {
428
+ // const bound = this.width.tag === "Absolute" ? Math.min(this.width.value, width)
429
+ // : this.width.tag === "Fill" ? width
430
+ // : null;
431
+ // if (bound === null) {
432
+ // throw new Error("Cannot bound width of non-unitized widths!")
433
+ // }
434
+ // return new Stack(this.elements.map(e => e.bound_width(bound)), this.margin, this.alignment, Width.absolute(bound), Width.is_fill(this.width));
435
+ // }
436
+ // scale_width(w: number): Stack {
437
+ // return this.with_elements(this.elements.map(e => e.scale_width(w))).with_width(Width.scale(this.width, w));
438
+ // }
439
+ // }
440
+ // export class Row {
441
+ // tag: "Row";
442
+ // elements: SectionLayout[];
443
+ // margin: Margin.t;
444
+ // alignment: Alignment.t;
445
+ // width: Width.t;
446
+ // is_frozen: boolean;
447
+ // is_fill: boolean;
448
+ // constructor(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean) {
449
+ // this.tag = "Row";
450
+ // this.elements = elements;
451
+ // this.is_frozen = is_frozen ?? false;
452
+ // this.margin = margin ?? Margin.default_();
453
+ // this.alignment = alignment ?? Alignment.default_();
454
+ // this.width = width ?? Width.default_();
455
+ // this.is_fill = is_fill ?? false;
456
+ // }
457
+ // static row(elements: SectionLayout[], is_frozen?: boolean, margin?: Margin.t, alignment?: Alignment.t, width?: Width.t, is_fill?: boolean): SectionLayout {
458
+ // return new SectionLayout(new Row(elements, is_frozen, margin, alignment, width, is_fill));
459
+ // }
460
+ // copy() {
461
+ // return new Row(
462
+ // this.elements.map((e) => e.copy()),
463
+ // this.is_frozen,
464
+ // Margin.copy(this.margin),
465
+ // this.alignment,
466
+ // Width.copy(this.width),
467
+ // this.is_fill,
468
+ // )
469
+ // }
470
+ // static default_(): Row {
471
+ // return new Row([]);
472
+ // }
473
+ // instantiate(section: & Map<string, ItemContent>): Row {
474
+ // return new Row(this.elements.map(e => e.instantiate(section)), this.is_frozen, this.margin, this.alignment, this.width, this.is_fill);
475
+ // }
476
+ // with_elements(elements: SectionLayout[]): Row {
477
+ // return new Row(elements, this.is_frozen, this.margin, this.alignment, this.width, this.is_fill);
478
+ // }
479
+ // with_margin(margin: Margin.t): Row {
480
+ // return new Row(this.elements, this.is_frozen, margin, this.alignment, this.width, this.is_fill);
481
+ // }
482
+ // with_alignment(alignment: Alignment.t): Row {
483
+ // return new Row(this.elements, this.is_frozen, this.margin, alignment, this.width, this.is_fill);
484
+ // }
485
+ // with_width(width: Width.t): Row {
486
+ // return new Row(this.elements, this.is_frozen, this.margin, this.alignment, width, this.is_fill);
487
+ // }
488
+ // elements_width(): number {
489
+ // return this.elements.map(e => Width.get_fixed_unchecked(e.width())).reduce((a, b) => a + b, 0.0);
490
+ // }
491
+ // bound_width(width: number): Row {
492
+ // const bound = this.width.tag === "Absolute" ? Math.min(this.width.value, width)
493
+ // : this.width.tag === "Fill" ? width
494
+ // : null;
495
+ // if (bound === null) {
496
+ // throw new Error("Cannot bound width of non-unitized widths!")
497
+ // }
498
+ // return new Row(this.elements.map(e => e.bound_width(bound)), this.is_frozen, this.margin, this.alignment, Width.absolute(bound), Width.is_fill(this.width));
499
+ // }
500
+ // scale_width(w: number): Row {
501
+ // return this.with_elements(this.elements.map(e => e.scale_width(w))).with_width(Width.scale(this.width, w));
502
+ // }
503
+ // break_lines(font_dict: FontDict): Row[] {
504
+ // const lines: Row[] = [];
505
+ // let current_line: SectionLayout[] = [];
506
+ // let current_width = 0.0;
507
+ // const elements: SectionLayout[] = this
508
+ // .elements
509
+ // .map(e => e.break_lines(font_dict));
510
+ // for (const element of elements) {
511
+ // const element_width = Width.get_fixed_unchecked(element.width());
512
+ // if (current_width + element_width > Width.get_fixed_unchecked(this.width)) {
513
+ // lines.push(this.with_elements(current_line));
514
+ // current_line = [];
515
+ // current_width = 0.0;
516
+ // }
517
+ // current_line.push(element);
518
+ // current_width += element_width;
519
+ // }
520
+ // if (current_line.length > 0) {
521
+ // lines.push(this.with_elements(current_line));
522
+ // }
523
+ // return lines;
524
+ // }
525
+ // }
526
+ // export type Color =
527
+ // "Transparent" // transparent
528
+ // | "Light Yellow" // "#FFC96F"
529
+ // | "Light Brown" // "#ECB176"
530
+ // | "Light Green" // "#F6FAB9"
531
+ // | "Light Beige" // "#F6EEC9"
532
+ // | "Light Blue" // "#EEF7FF"
533
+ // | "Blue" // "#4793AF"
534
+ // export const ColorMap = {
535
+ // "Transparent": "transparent",
536
+ // "Light Yellow": "#FFC96F",
537
+ // "Light Brown": "#ECB176",
538
+ // "Light Green": "#F6FAB9",
539
+ // "Light Beige": "#F6EEC9",
540
+ // "Light Blue": "#EEF7FF",
541
+ // "Blue": "#4793AF",
542
+ // }
543
+ // export class Elem {
544
+ // tag: "Elem";
545
+ // item: string;
546
+ // url: string | null;
547
+ // is_ref: boolean;
548
+ // is_fill: boolean;
549
+ // text_width: Width.t;
550
+ // font: Font;
551
+ // margin: Margin.t;
552
+ // alignment: Alignment.t;
553
+ // width: Width.t;
554
+ // background_color: Color;
555
+ // 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) {
556
+ // this.tag = "Elem";
557
+ // this.item = item;
558
+ // this.url = url;
559
+ // this.is_ref = is_ref;
560
+ // this.is_fill = is_fill;
561
+ // this.text_width = text_width;
562
+ // this.font = font;
563
+ // this.margin = margin;
564
+ // this.alignment = alignment;
565
+ // this.width = width;
566
+ // this.background_color = background_color;
567
+ // }
568
+ // 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) {
569
+ // return new SectionLayout(
570
+ // new Elem(item, url, is_ref, is_fill, text_width, font, margin, alignment, width, background_color)
571
+ // );
572
+ // }
573
+ // copy() {
574
+ // return new Elem(
575
+ // this.item,
576
+ // this.url,
577
+ // this.is_ref,
578
+ // this.is_fill,
579
+ // Width.copy(this.text_width),
580
+ // this.font,
581
+ // Margin.copy(this.margin),
582
+ // this.alignment,
583
+ // Width.copy(this.width),
584
+ // this.background_color,
585
+ // )
586
+ // }
587
+ // static default_(): Elem {
588
+ // return new Elem("", null, false, false, Width.default_(), Font.default_(), Margin.default_(), Alignment.default_(), Width.default_(), "Transparent");
589
+ // }
590
+ // with_item(item: string): Elem {
591
+ // return new Elem(item, this.url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width, this.background_color);
592
+ // }
593
+ // as_ref(): Elem {
594
+ // return new Elem(this.item, this.url, true, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width, this.background_color);
595
+ // }
596
+ // with_font(font: Font) {
597
+ // return new Elem(this.item, this.url, this.is_ref, this.is_fill, this.text_width, font, this.margin, this.alignment, this.width, this.background_color);
598
+ // }
599
+ // with_url(url: string): Elem {
600
+ // return new Elem(this.item, url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, this.alignment, this.width, this.background_color);
601
+ // }
602
+ // with_margin(margin: Margin.t): Elem {
603
+ // return new Elem(this.item, this.url, this.is_ref, this.is_fill, this.text_width, this.font, margin, this.alignment, this.width, this.background_color);
604
+ // }
605
+ // with_alignment(alignment: Alignment.t): Elem {
606
+ // return new Elem(this.item, this.url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, alignment, this.width, this.background_color);
607
+ // }
608
+ // with_width(width: Width.t): Elem {
609
+ // return new Elem(this.item, this.url, this.is_ref, this.is_fill, this.text_width, this.font, this.margin, this.alignment, width, this.background_color);
610
+ // }
611
+ // with_text_width(text_width: Width.t): Elem {
612
+ // return new Elem(this.item, this.url, this.is_ref, this.is_fill, text_width, this.font, this.margin, this.alignment, this.width, this.background_color);
613
+ // }
614
+ // with_is_fill(is_fill: boolean): Elem {
615
+ // return new Elem(this.item, this.url, this.is_ref, is_fill, this.text_width, this.font, this.margin, this.alignment, this.width, this.background_color);
616
+ // }
617
+ // scale_width(w: number): Elem {
618
+ // return this.with_width(Width.scale(this.width, w));
619
+ // }
620
+ // fill_fonts(fonts: FontDict): Elem {
621
+ // const text_width_with_font = this.font.get_width(this.item, fonts);
622
+ // if (this.is_fill) {
623
+ // return this.with_width(Width.absolute(Math.min(Width.get_fixed_unchecked(this.width), text_width_with_font)))
624
+ // .with_text_width(Width.absolute(text_width_with_font));
625
+ // } else {
626
+ // return this.with_text_width(Width.absolute(text_width_with_font));
627
+ // }
628
+ // }
629
+ // justified_lines(lines: Elem[], font_dict: FontDict): Row[] {
630
+ // const rowLines = [];
631
+ // for (const line of lines.slice(0, -1)) {
632
+ // const words = line.item.split(/\s+/);
633
+ // const row = new Row([], false, line.margin, line.alignment, line.width);
634
+ // words.forEach(word => {
635
+ // const word_width = this.font.get_width(word, font_dict);
636
+ // row.elements.push(
637
+ // new SectionLayout(new Elem(word, null, false, false, Width.absolute(word_width), this.font, Margin.default_(), Alignment.default_(), Width.absolute(word_width), this.background_color)),
638
+ // );
639
+ // });
640
+ // rowLines.push(row);
641
+ // }
642
+ // rowLines.push(new Row([new SectionLayout(lines[lines.length - 1]).with_alignment("Left")], false, lines[0].margin, "Left", lines[0].width));
643
+ // return rowLines;
644
+ // }
645
+ // break_lines(font_dict: FontDict): LayoutType[] {
646
+ // if (Width.get_fixed_unchecked(this.text_width) <= Width.get_fixed_unchecked(this.width)) {
647
+ // return [this]
648
+ // }
649
+ // const lines: Elem[] = [];
650
+ // // todo: I'm sure this implementation is pretty buggy. Note to future me, fix
651
+ // // this.
652
+ // const words = this.item.split(/\s+/);
653
+ // const widths = words.map((word) => this.font.get_width(word, font_dict));
654
+ // const space_width = this.font.get_width(" ", font_dict);
655
+ // let start = 0;
656
+ // let width = widths[0];
657
+ // const max_width = Width.get_fixed_unchecked(this.width);
658
+ // for (let i = 1; i < words.length; i++) {
659
+ // const candidate_width = width + space_width + widths[i];
660
+ // if (candidate_width > max_width) {
661
+ // const line = words.slice(start, i).join(" ");
662
+ // const line_width = this.font.get_width(line, font_dict);
663
+ // lines.push(
664
+ // this.with_item(line)
665
+ // .with_text_width(Width.absolute(line_width)),
666
+ // );
667
+ // start = i;
668
+ // width = widths[i];
669
+ // } else {
670
+ // width += space_width + widths[i];
671
+ // }
672
+ // }
673
+ // const line = words.slice(start).join(" ");
674
+ // const line_width = this.font.get_width(line, font_dict);
675
+ // lines.push(
676
+ // this.with_item(line)
677
+ // .with_text_width(Width.absolute(line_width)),
678
+ // );
679
+ // if (this.alignment === "Justified") {
680
+ // return this.justified_lines(lines, font_dict);
681
+ // }
682
+ // return lines;
683
+ // }
684
+ // bound_width(width: number): Elem {
685
+ // if (!Width.is_fill(this.width)) {
686
+ // return this.with_width(Width.absolute(Math.min(Width.get_fixed_unchecked(this.width), width))).with_is_fill(false);
687
+ // } else {
688
+ // return this.with_width(Width.absolute(width)).with_is_fill(true);
689
+ // }
690
+ // }
691
+ // }