cvdl-ts 1.0.26 → 1.0.27
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 +2 -1
- package/dist/Layout.js +15 -12
- package/dist/Row.d.ts +1 -0
- package/dist/Row.js +31 -4
- package/package.json +1 -1
package/dist/Elem.js
CHANGED
|
@@ -354,12 +354,13 @@ function bind(t, bindings) {
|
|
|
354
354
|
return result;
|
|
355
355
|
}
|
|
356
356
|
function instantiate(e, section, fields, bindings) {
|
|
357
|
+
var _a;
|
|
357
358
|
e = bind(e, bindings);
|
|
358
359
|
if (!e.is_ref) {
|
|
359
360
|
return e;
|
|
360
361
|
}
|
|
361
362
|
const itemType = fields.find((f) => f.name === e.item);
|
|
362
|
-
if ((itemType === null || itemType === void 0 ? void 0 : itemType.type.tag) === "MarkdownString") {
|
|
363
|
+
if (((_a = itemType === null || itemType === void 0 ? void 0 : itemType.type) === null || _a === void 0 ? void 0 : _a.tag) === "MarkdownString") {
|
|
363
364
|
e.is_markdown = true;
|
|
364
365
|
}
|
|
365
366
|
const text = section.fields[e.item];
|
package/dist/Layout.js
CHANGED
|
@@ -261,25 +261,27 @@ function computeTextboxPositions(l, top_left, font_dict) {
|
|
|
261
261
|
top_left = top_left.move_y_by(row.margin.top).move_x_by(row.margin.left);
|
|
262
262
|
const originalTopLeft = top_left;
|
|
263
263
|
let per_elem_space = 0.0;
|
|
264
|
+
const rowElementsWidth = Row.elementsWidth(row);
|
|
264
265
|
switch (row.alignment) {
|
|
265
266
|
case "Center":
|
|
266
|
-
top_left = top_left.move_x_by((Width.get_fixed_unchecked(row.width) -
|
|
267
|
-
2.0);
|
|
267
|
+
top_left = top_left.move_x_by((Width.get_fixed_unchecked(row.width) - rowElementsWidth) / 2.0);
|
|
268
268
|
break;
|
|
269
269
|
case "Right":
|
|
270
|
-
top_left = top_left.move_x_by(Width.get_fixed_unchecked(row.width) -
|
|
270
|
+
top_left = top_left.move_x_by(Width.get_fixed_unchecked(row.width) - rowElementsWidth);
|
|
271
271
|
break;
|
|
272
272
|
case "Justified":
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(row.
|
|
273
|
+
if (row.elements.length > 1) {
|
|
274
|
+
per_elem_space =
|
|
275
|
+
(Width.get_fixed_unchecked(row.width) - rowElementsWidth) /
|
|
276
|
+
(row.elements.length - 1);
|
|
277
|
+
}
|
|
276
278
|
break;
|
|
277
279
|
}
|
|
278
280
|
const renderedElements = [];
|
|
279
281
|
for (const element of row.elements) {
|
|
280
282
|
const result = computeTextboxPositions(element, top_left, font_dict);
|
|
281
283
|
depth = Math.max(depth, result.depth);
|
|
282
|
-
top_left = top_left.move_x_by(
|
|
284
|
+
top_left = top_left.move_x_by(Row.elementOuterWidth(element) + per_elem_space);
|
|
283
285
|
renderedElements.push(result.renderedLayout);
|
|
284
286
|
}
|
|
285
287
|
depth += row.margin.bottom;
|
|
@@ -304,15 +306,16 @@ function computeTextboxPositions(l, top_left, font_dict) {
|
|
|
304
306
|
.move_y_by(elem.margin.top)
|
|
305
307
|
.move_x_by(elem.margin.left);
|
|
306
308
|
let line = 1;
|
|
307
|
-
let cursor =
|
|
309
|
+
let cursor = 0;
|
|
310
|
+
const maxLineWidth = Width.get_fixed_unchecked(elem.width) - elem.margin.right;
|
|
311
|
+
const wrapTolerance = 1e-6;
|
|
308
312
|
elem.spans.forEach((span) => {
|
|
309
|
-
if (cursor
|
|
310
|
-
Width.get_fixed_unchecked(elem.width) - elem.margin.right ||
|
|
313
|
+
if (cursor + span.width > maxLineWidth + wrapTolerance ||
|
|
311
314
|
span.text === "\n\n") {
|
|
312
|
-
cursor =
|
|
315
|
+
cursor = 0;
|
|
313
316
|
line += 1;
|
|
314
317
|
}
|
|
315
|
-
span.bbox = new Box_1.Box(new Point_1.Point(cursor
|
|
318
|
+
span.bbox = new Box_1.Box(new Point_1.Point(cursor, (line - 1) * height), new Point_1.Point(cursor + span.width, line * height));
|
|
316
319
|
span.line = line;
|
|
317
320
|
cursor += span.width;
|
|
318
321
|
});
|
package/dist/Row.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function from(w: Optional<Row>): Row;
|
|
|
17
17
|
export declare function row(elements: Layout.t[], margin: Margin.t, alignment: Alignment.t, width: Width.t, is_frozen: boolean, is_fill: boolean): Row;
|
|
18
18
|
export declare function default_(): Row;
|
|
19
19
|
export declare function elementsWidth(r: Row): number;
|
|
20
|
+
export declare function elementOuterWidth(e: Layout.t): number;
|
|
20
21
|
export declare function boundWidth(r: Row, width: number): Row;
|
|
21
22
|
export declare function scaleWidth(r: Row, w: number): Row;
|
|
22
23
|
export {};
|
package/dist/Row.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.from = from;
|
|
|
27
27
|
exports.row = row;
|
|
28
28
|
exports.default_ = default_;
|
|
29
29
|
exports.elementsWidth = elementsWidth;
|
|
30
|
+
exports.elementOuterWidth = elementOuterWidth;
|
|
30
31
|
exports.boundWidth = boundWidth;
|
|
31
32
|
exports.scaleWidth = scaleWidth;
|
|
32
33
|
const Margin = __importStar(require("./Margin"));
|
|
@@ -60,9 +61,10 @@ function default_() {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
function elementsWidth(r) {
|
|
63
|
-
return r.elements
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
return r.elements.map(elementOuterWidth).reduce((a, b) => a + b, 0.0);
|
|
65
|
+
}
|
|
66
|
+
function elementOuterWidth(e) {
|
|
67
|
+
return e.margin.left + Width.get_fixed_unchecked(e.width) + e.margin.right;
|
|
66
68
|
}
|
|
67
69
|
function boundWidth(r, width) {
|
|
68
70
|
const bound = r.width.tag === "Absolute"
|
|
@@ -73,7 +75,32 @@ function boundWidth(r, width) {
|
|
|
73
75
|
if (bound === null) {
|
|
74
76
|
throw new Error("Cannot bound width of non-unitized widths!");
|
|
75
77
|
}
|
|
76
|
-
|
|
78
|
+
const fixedWidths = r.elements.map((e) => {
|
|
79
|
+
switch (e.width.tag) {
|
|
80
|
+
case "Fill":
|
|
81
|
+
return null;
|
|
82
|
+
case "Absolute":
|
|
83
|
+
return Math.min(e.width.value, bound);
|
|
84
|
+
case "Percent":
|
|
85
|
+
// Row children are usually scaled before bounding, but this keeps
|
|
86
|
+
// direct boundWidth() calls stable if Percent widths appear.
|
|
87
|
+
return Math.min((e.width.value * bound) / 100.0, bound);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const totalFixedOuterWidth = fixedWidths.reduce((acc, next, index) => next === null
|
|
91
|
+
? acc
|
|
92
|
+
: acc + r.elements[index].margin.left + next + r.elements[index].margin.right, 0);
|
|
93
|
+
const fillElementCount = fixedWidths.filter((next) => next === null).length;
|
|
94
|
+
const totalFillMargins = fixedWidths.reduce((acc, next, index) => next === null
|
|
95
|
+
? acc +
|
|
96
|
+
r.elements[index].margin.left +
|
|
97
|
+
r.elements[index].margin.right
|
|
98
|
+
: acc, 0);
|
|
99
|
+
const fillWidth = fillElementCount > 0
|
|
100
|
+
? Math.max(0, bound - totalFixedOuterWidth - totalFillMargins) /
|
|
101
|
+
fillElementCount
|
|
102
|
+
: 0;
|
|
103
|
+
return row(r.elements.map((e, index) => { var _a; return Layout.boundWidth(e, (_a = fixedWidths[index]) !== null && _a !== void 0 ? _a : fillWidth); }), r.margin, r.alignment, Width.absolute(bound), r.is_frozen, Width.is_fill(r.width));
|
|
77
104
|
}
|
|
78
105
|
function scaleWidth(r, w) {
|
|
79
106
|
return (0, Utils_1.with_)(r, {
|