@dloizides/poster-render 0.11.2 → 0.12.0
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/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +162 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -77
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,17 @@ var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
|
|
|
7
7
|
return BackgroundStyle2;
|
|
8
8
|
})(BackgroundStyle || {});
|
|
9
9
|
|
|
10
|
+
// src/enums/BodySection.ts
|
|
11
|
+
var BodySection = /* @__PURE__ */ ((BodySection2) => {
|
|
12
|
+
BodySection2["Venue"] = "venue";
|
|
13
|
+
BodySection2["Schedule"] = "schedule";
|
|
14
|
+
BodySection2["Items"] = "items";
|
|
15
|
+
BodySection2["Prices"] = "prices";
|
|
16
|
+
BodySection2["Includes"] = "includes";
|
|
17
|
+
BodySection2["Footer"] = "footer";
|
|
18
|
+
return BodySection2;
|
|
19
|
+
})(BodySection || {});
|
|
20
|
+
|
|
10
21
|
// src/enums/FontSetId.ts
|
|
11
22
|
var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
|
|
12
23
|
FontSetId2["Classic"] = "classic";
|
|
@@ -86,10 +97,6 @@ var RowIcon = /* @__PURE__ */ ((RowIcon2) => {
|
|
|
86
97
|
// src/schema/lineStyleSchema.ts
|
|
87
98
|
var LINE_KEY_PATTERN = "^(title|titleBottom|script|footer|includes[.]heading|includes[.]items[.][0-5]|venue[.][0-2]|schedule[.][0-5][.](label|time)|prices[.][0-3][.](amount|label)|items[.][0-7][.](date|price|schedule[.][0-5]))$";
|
|
88
99
|
var MAX_FONT = 40;
|
|
89
|
-
var MIN_SIZE_SCALE = 0.25;
|
|
90
|
-
var MAX_SIZE_SCALE = 3;
|
|
91
|
-
var MIN_WIDTH_SCALE = 0.5;
|
|
92
|
-
var MAX_WIDTH_SCALE = 1.5;
|
|
93
100
|
var MIN_SPACING = -0.1;
|
|
94
101
|
var MAX_SPACING = 0.5;
|
|
95
102
|
var MAX_TIES = 12;
|
|
@@ -100,8 +107,8 @@ var lineStyle = {
|
|
|
100
107
|
additionalProperties: false,
|
|
101
108
|
properties: {
|
|
102
109
|
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
103
|
-
sizeScale: { type: "number", minimum:
|
|
104
|
-
widthScale: { type: "number", minimum:
|
|
110
|
+
sizeScale: { type: "number", minimum: 0 },
|
|
111
|
+
widthScale: { type: "number", minimum: 0 },
|
|
105
112
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
106
113
|
weight: { type: "integer", enum: WEIGHTS },
|
|
107
114
|
italic: { type: "boolean" },
|
|
@@ -270,6 +277,7 @@ var MIN_SCALE = 0.3;
|
|
|
270
277
|
var MAX_HEADER_GAP = 200;
|
|
271
278
|
var MIN_DATE_SCALE = 0.5;
|
|
272
279
|
var MAX_DATE_SCALE = 2;
|
|
280
|
+
var MAX_SECTIONS = 6;
|
|
273
281
|
var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
|
|
274
282
|
var scheduleRow = {
|
|
275
283
|
type: "object",
|
|
@@ -348,6 +356,7 @@ var flierDocSchema = {
|
|
|
348
356
|
lineStyles: lineStylesSchema,
|
|
349
357
|
lineTies: lineTiesSchema,
|
|
350
358
|
rows: rowsSchema,
|
|
359
|
+
sectionOrder: { type: "array", maxItems: MAX_SECTIONS, items: { type: "string", enum: Object.values(BodySection) } },
|
|
351
360
|
items: {
|
|
352
361
|
type: "array",
|
|
353
362
|
minItems: 1,
|
|
@@ -807,12 +816,25 @@ function styled(line, key, sc) {
|
|
|
807
816
|
italic: style?.italic,
|
|
808
817
|
spacing: style?.letterSpacing,
|
|
809
818
|
widthScale: style?.widthScale,
|
|
819
|
+
fixedSize: style?.sizeScale === void 0 ? void 0 : true,
|
|
810
820
|
align: style?.align,
|
|
811
821
|
widthTie,
|
|
812
822
|
sizeTie
|
|
813
823
|
};
|
|
814
824
|
}
|
|
815
825
|
|
|
826
|
+
// src/layout/sectionOrder.ts
|
|
827
|
+
var EVENT_ORDER = ["venue" /* Venue */, "schedule" /* Schedule */, "prices" /* Prices */, "includes" /* Includes */, "footer" /* Footer */];
|
|
828
|
+
var LIST_ORDER = ["venue" /* Venue */, "items" /* Items */, "prices" /* Prices */, "includes" /* Includes */, "footer" /* Footer */];
|
|
829
|
+
function defaultSectionOrder(layout) {
|
|
830
|
+
return [...layout === "list" /* List */ ? LIST_ORDER : EVENT_ORDER];
|
|
831
|
+
}
|
|
832
|
+
function sectionOrderOf(doc) {
|
|
833
|
+
const base2 = defaultSectionOrder(doc.layout);
|
|
834
|
+
const own = (doc.sectionOrder ?? []).filter((s, i, all) => base2.includes(s) && all.indexOf(s) === i);
|
|
835
|
+
return [...own, ...base2.filter((s) => !own.includes(s))];
|
|
836
|
+
}
|
|
837
|
+
|
|
816
838
|
// src/layout/blockGroups.ts
|
|
817
839
|
var BOLD = 700;
|
|
818
840
|
var SEMI = 600;
|
|
@@ -899,7 +921,7 @@ function halves(text2) {
|
|
|
899
921
|
}
|
|
900
922
|
function wrapped(line, wrap) {
|
|
901
923
|
const parts = wrap ? halves(line.text) : [line.text];
|
|
902
|
-
return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
|
|
924
|
+
return parts.length === 1 ? [line] : parts.map((text2, i) => i === 0 ? { ...line, text: text2, tail: void 0 } : { ...line, text: text2, tail: void 0, bullet: void 0, hang: line.bullet !== void 0 });
|
|
903
925
|
}
|
|
904
926
|
function scheduleLines(doc, l, row, i) {
|
|
905
927
|
const r3 = doc.rows;
|
|
@@ -907,31 +929,30 @@ function scheduleLines(doc, l, row, i) {
|
|
|
907
929
|
const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
|
|
908
930
|
return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
|
|
909
931
|
}
|
|
932
|
+
var tailed = (line, key, headLength) => ({ ...line, tail: { key, at: line.text.length - line.text.slice(headLength).trimStart().length } });
|
|
910
933
|
var priceAmount = (doc, line) => doc.rows?.priceGap === void 0 ? line : { ...line, gapAfter: doc.rows.priceGap };
|
|
911
934
|
function eventGroups(doc, l, u, options) {
|
|
912
935
|
const b = doc.blocks;
|
|
913
|
-
const
|
|
936
|
+
const rows = [];
|
|
937
|
+
const priced = [];
|
|
914
938
|
const schedule2 = b.schedule ?? [];
|
|
915
939
|
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
916
940
|
const lastRow = schedule2.length + prices.length - 1;
|
|
917
941
|
const icons2 = doc.rows?.icons;
|
|
918
942
|
schedule2.forEach((row, i) => {
|
|
919
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
|
|
920
|
-
|
|
943
|
+
const lines = options.compact ? [tailed(l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`), `schedule.${i}.time`, row.label.length)] : scheduleLines(doc, l, row, i);
|
|
944
|
+
rows.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
|
|
921
945
|
});
|
|
922
946
|
prices.forEach((row, i) => {
|
|
923
|
-
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`)] : [priceAmount(doc, l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`)), l.accent(row.label, SIZE.priceLabel * (doc.rows?.priceLabelScale ?? 1), `prices.${i}.label`)];
|
|
924
|
-
|
|
947
|
+
const lines = options.compact ? [tailed(l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`), `prices.${i}.label`, row.amount.length)] : [priceAmount(doc, l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`)), l.accent(row.label, SIZE.priceLabel * (doc.rows?.priceLabelScale ?? 1), `prices.${i}.label`)];
|
|
948
|
+
priced.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
|
|
925
949
|
});
|
|
926
|
-
return
|
|
950
|
+
return [rows, priced];
|
|
927
951
|
}
|
|
928
952
|
function listGroups(doc, l, u, dateScale) {
|
|
929
953
|
const groups = (doc.items ?? []).map((item, n) => itemGroup(item, n, l, { u, dateScale }));
|
|
930
|
-
const prices = doc.blocks.prices?.map((row, i) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`)) ?? [];
|
|
931
|
-
|
|
932
|
-
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
933
|
-
}
|
|
934
|
-
return groups;
|
|
954
|
+
const prices = doc.blocks.prices?.map((row, i) => tailed(l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`), `prices.${i}.label`, row.amount.length)) ?? [];
|
|
955
|
+
return [groups, prices.length > 0 ? [{ lines: prices, gapAfter: GAP.row * u }] : []];
|
|
935
956
|
}
|
|
936
957
|
function flankPriceGroups(doc, p, u) {
|
|
937
958
|
const l = makers(p, u, styleContext(doc));
|
|
@@ -940,28 +961,74 @@ function flankPriceGroups(doc, p, u) {
|
|
|
940
961
|
function pinOf(look, u) {
|
|
941
962
|
return { size: look?.pinSize === void 0 ? void 0 : look.pinSize * u, gap: look?.pinGap === void 0 ? void 0 : look.pinGap * u, shift: look?.pinShift === void 0 ? void 0 : look.pinShift * u, centre: look?.centred };
|
|
942
963
|
}
|
|
964
|
+
function venueGroups(doc, p, u, l) {
|
|
965
|
+
const b = doc.blocks;
|
|
966
|
+
if (!b.venue) {
|
|
967
|
+
return [];
|
|
968
|
+
}
|
|
969
|
+
const size = doc.layout === "list" /* List */ ? SIZE.listVenue : SIZE.venue;
|
|
970
|
+
const look = doc.rows?.venue;
|
|
971
|
+
const line = look?.body === true ? l.bodyVenue : l.venue;
|
|
972
|
+
const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
|
|
973
|
+
return [{ lines: venue.map((v, i) => line(v, size, `venue.${i}`)), gapAfter: GAP.venue * u, rule: dividerOf(doc, p, u) ?? { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.icon ?? p.accent, glyph: p.background, bare: look?.bare, ...pinOf(look, u) } }];
|
|
974
|
+
}
|
|
975
|
+
var bound = (s, next) => s === "venue" /* Venue */ && next === "schedule" /* Schedule */ || s === "includes" /* Includes */ && next === "footer" /* Footer */;
|
|
976
|
+
function joined(order, parts) {
|
|
977
|
+
const filled = order.filter((s) => parts[s].length > 0);
|
|
978
|
+
return filled.flatMap((s, n) => {
|
|
979
|
+
const groups = parts[s];
|
|
980
|
+
if (!bound(s, filled[n + 1])) {
|
|
981
|
+
return groups;
|
|
982
|
+
}
|
|
983
|
+
const attach = s === "includes" /* Includes */ ? { attachNext: true } : {};
|
|
984
|
+
return groups.map((g, i) => i === groups.length - 1 ? { ...g, keepWithNext: true, ...attach } : g);
|
|
985
|
+
});
|
|
986
|
+
}
|
|
943
987
|
function bodyGroups(doc, p, u, options = {}) {
|
|
944
988
|
const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
|
|
945
989
|
const b = doc.blocks;
|
|
946
|
-
const groups = [];
|
|
947
990
|
const isList = doc.layout === "list" /* List */;
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
991
|
+
const [rows, prices] = isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) });
|
|
992
|
+
const includeLines = b.includes ? [l.accent(b.includes.heading, SIZE.small, "includes.heading"), ...b.includes.items.map((item, i) => l.item(item, SIZE.small, `includes.items.${i}`))] : [];
|
|
993
|
+
const includes = includeLines.length > 0 ? [{ lines: includeLines.flatMap((line) => wrapped(line, options.wrap)), gapAfter: GAP.includes * u, uniform: true }] : [];
|
|
994
|
+
const footer = b.footer ? [{ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 }] : [];
|
|
995
|
+
const parts = {
|
|
996
|
+
["venue" /* Venue */]: venueGroups(doc, p, u, l),
|
|
997
|
+
["schedule" /* Schedule */]: isList ? [] : rows,
|
|
998
|
+
["items" /* Items */]: isList ? rows : [],
|
|
999
|
+
["prices" /* Prices */]: prices,
|
|
1000
|
+
["includes" /* Includes */]: includes,
|
|
1001
|
+
["footer" /* Footer */]: footer
|
|
1002
|
+
};
|
|
1003
|
+
return joined(sectionOrderOf(doc), parts);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/layout/lineRuns.ts
|
|
1007
|
+
var NO_SPACING = "0px";
|
|
1008
|
+
function widthOf(ctx, line, fonts, text2) {
|
|
1009
|
+
ctx.font = fontOf(line, line.size, fonts);
|
|
1010
|
+
if (line.spacing === void 0) {
|
|
1011
|
+
return ctx.measureText(text2).width;
|
|
955
1012
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1013
|
+
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
1014
|
+
const width = ctx.measureText(text2).width;
|
|
1015
|
+
ctx.letterSpacing = NO_SPACING;
|
|
1016
|
+
return width;
|
|
1017
|
+
}
|
|
1018
|
+
var measure = (ctx, line, fonts) => widthOf(ctx, line, fonts, line.text);
|
|
1019
|
+
function measureCut(ctx, line, fonts) {
|
|
1020
|
+
if (line.tail === void 0) {
|
|
1021
|
+
return void 0;
|
|
960
1022
|
}
|
|
961
|
-
|
|
962
|
-
|
|
1023
|
+
const head = line.text.slice(0, line.tail.at);
|
|
1024
|
+
return [widthOf(ctx, line, fonts, head.trimEnd()), widthOf(ctx, line, fonts, head)];
|
|
1025
|
+
}
|
|
1026
|
+
function runsOf(line, box, cut, scale) {
|
|
1027
|
+
if (line.tail === void 0 || line.key === void 0 || cut === void 0) {
|
|
1028
|
+
return {};
|
|
963
1029
|
}
|
|
964
|
-
|
|
1030
|
+
const start = cut[1] * scale;
|
|
1031
|
+
return { runs: [{ key: line.key, box: { ...box, w: cut[0] * scale } }, { key: line.tail.key, box: { ...box, x: box.x + start, w: Math.max(0, box.w - start) } }] };
|
|
965
1032
|
}
|
|
966
1033
|
|
|
967
1034
|
// src/layout/lineSizes.ts
|
|
@@ -986,16 +1053,19 @@ function groupBox(group, k, colW) {
|
|
|
986
1053
|
return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
|
|
987
1054
|
}
|
|
988
1055
|
function lineSize(line, width, k, avail) {
|
|
1056
|
+
if (line.fixedSize === true) {
|
|
1057
|
+
return line.size;
|
|
1058
|
+
}
|
|
989
1059
|
const indent = bulletIndent(line, k);
|
|
990
1060
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
991
1061
|
}
|
|
992
|
-
function groupSizes(m, k, avail
|
|
993
|
-
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k,
|
|
1062
|
+
function groupSizes(m, k, avail) {
|
|
1063
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail * (line.widthScale ?? 1)));
|
|
994
1064
|
if (!m.group.uniform) {
|
|
995
1065
|
return own;
|
|
996
1066
|
}
|
|
997
1067
|
const ratio = Math.min(...m.group.lines.map((line, i) => (own[i] ?? 0) / line.size));
|
|
998
|
-
return m.group.lines.map((line) => line.size * ratio);
|
|
1068
|
+
return m.group.lines.map((line) => line.fixedSize === true ? line.size : line.size * ratio);
|
|
999
1069
|
}
|
|
1000
1070
|
function tieMembers(all, k, colW, table, pick) {
|
|
1001
1071
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -1004,7 +1074,7 @@ function tieMembers(all, k, colW, table, pick) {
|
|
|
1004
1074
|
const sizes = table.get(m) ?? [];
|
|
1005
1075
|
m.group.lines.forEach((line, i) => {
|
|
1006
1076
|
const id = pick(line);
|
|
1007
|
-
if (id !== void 0) {
|
|
1077
|
+
if (id !== void 0 && line.fixedSize !== true) {
|
|
1008
1078
|
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, Math.min(1, line.widthScale ?? 1) * avail - bulletIndent(line, k)), sizes, i };
|
|
1009
1079
|
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
1010
1080
|
}
|
|
@@ -1025,8 +1095,8 @@ function sameWidths(list) {
|
|
|
1025
1095
|
x.sizes[x.i] = target * x.line.size / x.width;
|
|
1026
1096
|
});
|
|
1027
1097
|
}
|
|
1028
|
-
function sizeTable(all, k, colW
|
|
1029
|
-
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail
|
|
1098
|
+
function sizeTable(all, k, colW) {
|
|
1099
|
+
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
|
|
1030
1100
|
tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
|
|
1031
1101
|
tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
|
|
1032
1102
|
return table;
|
|
@@ -1042,7 +1112,6 @@ var TWO_COLUMN_MIN = 0.75;
|
|
|
1042
1112
|
var TWO_COLUMN_GAIN = 1.15;
|
|
1043
1113
|
var MIN_K = 0.02;
|
|
1044
1114
|
var STEPS = 22;
|
|
1045
|
-
var NO_SPACING = "0px";
|
|
1046
1115
|
var fontOf = (line, size, fonts) => {
|
|
1047
1116
|
const family = line.family === void 0 ? fonts[line.role] : `"${line.family}", ${fonts[line.role]}`;
|
|
1048
1117
|
return `${line.italic === true ? "italic " : ""}${line.weight} ${size}px ${family}`;
|
|
@@ -1092,7 +1161,8 @@ function placeGroup(m, at, out) {
|
|
|
1092
1161
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
1093
1162
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
1094
1163
|
const x = lineX(line, { col, pad, indent, w });
|
|
1095
|
-
|
|
1164
|
+
const box = { x, y, w, h: size * LINE_HEIGHT };
|
|
1165
|
+
out?.texts.push({ text: line.text, font: "", color: line.color, box, key: line.key, ...line.fixedSize === true ? { fixed: true } : {}, ...runsOf(line, box, m.cuts?.[i], size / line.size) });
|
|
1096
1166
|
if (line.bullet && out) {
|
|
1097
1167
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
1098
1168
|
}
|
|
@@ -1158,11 +1228,11 @@ function splitColumns(groups, zone) {
|
|
|
1158
1228
|
}
|
|
1159
1229
|
cut = keepTogether(groups, heights, cut);
|
|
1160
1230
|
return [
|
|
1161
|
-
{ col: { ...zone, w
|
|
1162
|
-
{ col: { ...zone, x: zone.x + w + gap, w
|
|
1231
|
+
{ col: { ...zone, w }, groups: groups.slice(0, cut) },
|
|
1232
|
+
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
1163
1233
|
];
|
|
1164
1234
|
}
|
|
1165
|
-
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0
|
|
1235
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
1166
1236
|
function largestK(columns, zoneH) {
|
|
1167
1237
|
const fits = (k) => {
|
|
1168
1238
|
const table = tableFor(columns, k);
|
|
@@ -1194,20 +1264,11 @@ function bestColumns(measured, zone) {
|
|
|
1194
1264
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
1195
1265
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
1196
1266
|
}
|
|
1197
|
-
function measure(ctx, line, fonts) {
|
|
1198
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
1199
|
-
if (line.spacing === void 0) {
|
|
1200
|
-
return ctx.measureText(line.text).width;
|
|
1201
|
-
}
|
|
1202
|
-
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
1203
|
-
const width = ctx.measureText(line.text).width;
|
|
1204
|
-
ctx.letterSpacing = NO_SPACING;
|
|
1205
|
-
return width;
|
|
1206
|
-
}
|
|
1207
1267
|
function flow(ctx, groups, zone, fonts) {
|
|
1208
1268
|
const measured = groups.map((group) => ({
|
|
1209
1269
|
group,
|
|
1210
|
-
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
1270
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts)),
|
|
1271
|
+
cuts: group.lines.map((line) => measureCut(ctx, line, fonts))
|
|
1211
1272
|
}));
|
|
1212
1273
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
1213
1274
|
const out = emptyFlow();
|
|
@@ -1321,11 +1382,11 @@ function flowAll(ctx, input, base2, reflow) {
|
|
|
1321
1382
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
1322
1383
|
const flanks = geo.flanks ?? [];
|
|
1323
1384
|
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
1324
|
-
const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }),
|
|
1385
|
+
const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }), tight.body, fonts);
|
|
1325
1386
|
const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
|
|
1326
1387
|
return { geo: tight, zones, head, body, sides };
|
|
1327
1388
|
}
|
|
1328
|
-
var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
|
|
1389
|
+
var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.filter((x) => x.fixed !== true).map((x) => x.box.h / LINE_HEIGHT3)));
|
|
1329
1390
|
function shiftHeader(geo, shift) {
|
|
1330
1391
|
const { header, body } = geo;
|
|
1331
1392
|
const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
|
|
@@ -1391,6 +1452,40 @@ function fitToFloor(ctx, input) {
|
|
|
1391
1452
|
return best ?? flowAll(ctx, input, base2, { compact: false, wrap: false});
|
|
1392
1453
|
}
|
|
1393
1454
|
|
|
1455
|
+
// src/render/lineBoxesOf.ts
|
|
1456
|
+
function union(a, b) {
|
|
1457
|
+
if (a === void 0) {
|
|
1458
|
+
return { ...b };
|
|
1459
|
+
}
|
|
1460
|
+
const x = Math.min(a.x, b.x);
|
|
1461
|
+
const y = Math.min(a.y, b.y);
|
|
1462
|
+
return { x, y, w: Math.max(a.x + a.w, b.x + b.w) - x, h: Math.max(a.y + a.h, b.y + b.h) - y };
|
|
1463
|
+
}
|
|
1464
|
+
function lineBoxesOf(texts) {
|
|
1465
|
+
const boxes = {};
|
|
1466
|
+
texts.forEach(({ key, box, runs }) => {
|
|
1467
|
+
(runs ?? (key === void 0 ? [] : [{ key, box }])).forEach((r3) => {
|
|
1468
|
+
boxes[r3.key] = union(boxes[r3.key], r3.box);
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
1471
|
+
return boxes;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/render/roleOrder.ts
|
|
1475
|
+
var INDEX = /^\d+$/;
|
|
1476
|
+
var roleOf = (key) => key.split(".").filter((part) => !INDEX.test(part)).join(".");
|
|
1477
|
+
function roleOrder(boxes) {
|
|
1478
|
+
const first = /* @__PURE__ */ new Map();
|
|
1479
|
+
Object.entries(boxes).forEach(([key, box]) => {
|
|
1480
|
+
const role = roleOf(key);
|
|
1481
|
+
const seen = first.get(role);
|
|
1482
|
+
if (box !== void 0 && (seen === void 0 || box.y < seen.y || box.y === seen.y && box.x < seen.x)) {
|
|
1483
|
+
first.set(role, box);
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1486
|
+
return [...first.entries()].sort(([, a], [, b]) => a.y - b.y || a.x - b.x).map(([role]) => role);
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1394
1489
|
// src/render/overlap.ts
|
|
1395
1490
|
var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
1396
1491
|
function placePicture(image, region, slot, fit) {
|
|
@@ -1613,23 +1708,6 @@ function drawLogo(ctx, doc, assets, fitted) {
|
|
|
1613
1708
|
}
|
|
1614
1709
|
return logo;
|
|
1615
1710
|
}
|
|
1616
|
-
function lineBoxesOf(texts) {
|
|
1617
|
-
const boxes = {};
|
|
1618
|
-
texts.forEach(({ key, box }) => {
|
|
1619
|
-
if (key !== void 0) {
|
|
1620
|
-
boxes[key] = union(boxes[key], box);
|
|
1621
|
-
}
|
|
1622
|
-
});
|
|
1623
|
-
return boxes;
|
|
1624
|
-
}
|
|
1625
|
-
function union(a, b) {
|
|
1626
|
-
if (a === void 0) {
|
|
1627
|
-
return { ...b };
|
|
1628
|
-
}
|
|
1629
|
-
const x = Math.min(a.x, b.x);
|
|
1630
|
-
const y = Math.min(a.y, b.y);
|
|
1631
|
-
return { x, y, w: Math.max(a.x + a.w, b.x + b.w) - x, h: Math.max(a.y + a.h, b.y + b.h) - y };
|
|
1632
|
-
}
|
|
1633
1711
|
function render(input, assets, canvas) {
|
|
1634
1712
|
const doc = checked(input, assets);
|
|
1635
1713
|
const { width, height } = FORMAT_SIZES[doc.format];
|
|
@@ -1659,18 +1737,21 @@ function render(input, assets, canvas) {
|
|
|
1659
1737
|
if (layered) {
|
|
1660
1738
|
flows.forEach((f) => drawMarks(ctx, f, radius));
|
|
1661
1739
|
}
|
|
1740
|
+
const lineBoxes = lineBoxesOf(flows.flatMap((f) => f.texts));
|
|
1662
1741
|
return {
|
|
1663
1742
|
width,
|
|
1664
1743
|
height,
|
|
1665
1744
|
picture,
|
|
1666
1745
|
pictureRegion: region,
|
|
1667
1746
|
textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
|
|
1668
|
-
lineBoxes
|
|
1747
|
+
lineBoxes,
|
|
1669
1748
|
cardBoxes: body.cards.map((c) => c.rect),
|
|
1670
1749
|
iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
|
|
1671
1750
|
ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
|
|
1672
1751
|
logo,
|
|
1673
|
-
backdrop
|
|
1752
|
+
backdrop,
|
|
1753
|
+
sectionOrder: sectionOrderOf(doc),
|
|
1754
|
+
roleOrder: roleOrder(lineBoxes)
|
|
1674
1755
|
};
|
|
1675
1756
|
}
|
|
1676
1757
|
|
|
@@ -1764,6 +1845,6 @@ var kizombaWorkshop = {
|
|
|
1764
1845
|
};
|
|
1765
1846
|
var kizombaWorkshopDocs = [...WORKSHOPS.map(workshopDoc), kizombaWorkshop];
|
|
1766
1847
|
|
|
1767
|
-
export { BackgroundStyle, FONT_SETS, FORMAT_SIZES, FlierDocError, FontSetId, FormatId, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, LayoutId, LineAlign, LineTieKind, PALETTES, PaletteId, PictureAnchor, RowIcon, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, sameSize, sameWidth, validateFlierDoc };
|
|
1848
|
+
export { BackgroundStyle, BodySection, FONT_SETS, FORMAT_SIZES, FlierDocError, FontSetId, FormatId, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, LayoutId, LineAlign, LineTieKind, PALETTES, PaletteId, PictureAnchor, RowIcon, defaultLayoutFor, defaultSectionOrder, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, roleOf, roleOrder, sameSize, sameWidth, sectionOrderOf, validateFlierDoc };
|
|
1768
1849
|
//# sourceMappingURL=index.mjs.map
|
|
1769
1850
|
//# sourceMappingURL=index.mjs.map
|