@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.d.mts
CHANGED
|
@@ -5,6 +5,15 @@ declare enum BackgroundStyle {
|
|
|
5
5
|
Brush = "brush"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
declare enum BodySection {
|
|
9
|
+
Venue = "venue",
|
|
10
|
+
Schedule = "schedule",
|
|
11
|
+
Items = "items",
|
|
12
|
+
Prices = "prices",
|
|
13
|
+
Includes = "includes",
|
|
14
|
+
Footer = "footer"
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
declare enum FontSetId {
|
|
9
18
|
Classic = "classic",
|
|
10
19
|
Modern = "modern",
|
|
@@ -178,6 +187,7 @@ interface FlierDoc {
|
|
|
178
187
|
lineStyles?: Record<LineKey, LineStyle | undefined>;
|
|
179
188
|
lineTies?: LineTie[];
|
|
180
189
|
rows?: RowTheme;
|
|
190
|
+
sectionOrder?: BodySection[];
|
|
181
191
|
}
|
|
182
192
|
/** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
|
|
183
193
|
type LineKey = string;
|
|
@@ -267,6 +277,8 @@ interface RenderReport {
|
|
|
267
277
|
ruleBoxes: Rect[];
|
|
268
278
|
logo: Rect | null;
|
|
269
279
|
backdrop: Rect | null;
|
|
280
|
+
sectionOrder: BodySection[];
|
|
281
|
+
roleOrder: string[];
|
|
270
282
|
}
|
|
271
283
|
interface Palette {
|
|
272
284
|
background: string;
|
|
@@ -325,6 +337,16 @@ declare function validateFlierDoc(input: unknown): FlierDocResult;
|
|
|
325
337
|
/** Validates the doc, then draws it on the canvas (resized to the format); throws FlierDocError before touching the canvas. */
|
|
326
338
|
declare function render(input: unknown, assets: PosterAssets, canvas: PosterCanvas): RenderReport;
|
|
327
339
|
|
|
340
|
+
/** The body sections of a layout in the order it draws them; the title block always sits above. */
|
|
341
|
+
declare function defaultSectionOrder(layout: LayoutId): BodySection[];
|
|
342
|
+
/** The doc's own section order (unknown and repeated entries dropped), then the layout's remaining sections. */
|
|
343
|
+
declare function sectionOrderOf(doc: Pick<FlierDoc, 'layout' | 'sectionOrder'>): BodySection[];
|
|
344
|
+
|
|
345
|
+
/** The role of a line key: the key without its list indices, so "schedule.0.label" is "schedule.label". */
|
|
346
|
+
declare const roleOf: (key: LineKey) => string;
|
|
347
|
+
/** Every drawn role once, ordered by the top of its first line, then left to right. */
|
|
348
|
+
declare function roleOrder(boxes: Record<LineKey, Rect | undefined>): string[];
|
|
349
|
+
|
|
328
350
|
interface DataUrlCanvas {
|
|
329
351
|
toDataURL(type: string): string;
|
|
330
352
|
}
|
|
@@ -345,4 +367,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
|
|
|
345
367
|
declare const kizombaWorkshop: FlierDoc;
|
|
346
368
|
declare const kizombaWorkshopDocs: FlierDoc[];
|
|
347
369
|
|
|
348
|
-
export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureOverlap, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, RowIcon, type RowTheme, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, sameSize, sameWidth, validateFlierDoc };
|
|
370
|
+
export { BackgroundStyle, BodySection, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureOverlap, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, RowIcon, type RowTheme, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, defaultSectionOrder, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, roleOf, roleOrder, sameSize, sameWidth, sectionOrderOf, validateFlierDoc };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ declare enum BackgroundStyle {
|
|
|
5
5
|
Brush = "brush"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
declare enum BodySection {
|
|
9
|
+
Venue = "venue",
|
|
10
|
+
Schedule = "schedule",
|
|
11
|
+
Items = "items",
|
|
12
|
+
Prices = "prices",
|
|
13
|
+
Includes = "includes",
|
|
14
|
+
Footer = "footer"
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
declare enum FontSetId {
|
|
9
18
|
Classic = "classic",
|
|
10
19
|
Modern = "modern",
|
|
@@ -178,6 +187,7 @@ interface FlierDoc {
|
|
|
178
187
|
lineStyles?: Record<LineKey, LineStyle | undefined>;
|
|
179
188
|
lineTies?: LineTie[];
|
|
180
189
|
rows?: RowTheme;
|
|
190
|
+
sectionOrder?: BodySection[];
|
|
181
191
|
}
|
|
182
192
|
/** A text line path such as "title", "venue.1", "schedule.0.time" or "items.2.date" (see LINE_KEY_PATTERN). */
|
|
183
193
|
type LineKey = string;
|
|
@@ -267,6 +277,8 @@ interface RenderReport {
|
|
|
267
277
|
ruleBoxes: Rect[];
|
|
268
278
|
logo: Rect | null;
|
|
269
279
|
backdrop: Rect | null;
|
|
280
|
+
sectionOrder: BodySection[];
|
|
281
|
+
roleOrder: string[];
|
|
270
282
|
}
|
|
271
283
|
interface Palette {
|
|
272
284
|
background: string;
|
|
@@ -325,6 +337,16 @@ declare function validateFlierDoc(input: unknown): FlierDocResult;
|
|
|
325
337
|
/** Validates the doc, then draws it on the canvas (resized to the format); throws FlierDocError before touching the canvas. */
|
|
326
338
|
declare function render(input: unknown, assets: PosterAssets, canvas: PosterCanvas): RenderReport;
|
|
327
339
|
|
|
340
|
+
/** The body sections of a layout in the order it draws them; the title block always sits above. */
|
|
341
|
+
declare function defaultSectionOrder(layout: LayoutId): BodySection[];
|
|
342
|
+
/** The doc's own section order (unknown and repeated entries dropped), then the layout's remaining sections. */
|
|
343
|
+
declare function sectionOrderOf(doc: Pick<FlierDoc, 'layout' | 'sectionOrder'>): BodySection[];
|
|
344
|
+
|
|
345
|
+
/** The role of a line key: the key without its list indices, so "schedule.0.label" is "schedule.label". */
|
|
346
|
+
declare const roleOf: (key: LineKey) => string;
|
|
347
|
+
/** Every drawn role once, ordered by the top of its first line, then left to right. */
|
|
348
|
+
declare function roleOrder(boxes: Record<LineKey, Rect | undefined>): string[];
|
|
349
|
+
|
|
328
350
|
interface DataUrlCanvas {
|
|
329
351
|
toDataURL(type: string): string;
|
|
330
352
|
}
|
|
@@ -345,4 +367,4 @@ declare function defaultLayoutFor(format: FormatId): LayoutId;
|
|
|
345
367
|
declare const kizombaWorkshop: FlierDoc;
|
|
346
368
|
declare const kizombaWorkshopDocs: FlierDoc[];
|
|
347
369
|
|
|
348
|
-
export { BackgroundStyle, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureOverlap, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, RowIcon, type RowTheme, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, sameSize, sameWidth, validateFlierDoc };
|
|
370
|
+
export { BackgroundStyle, BodySection, type DataUrlCanvas, FONT_SETS, FORMAT_SIZES, type FlierBlocks, type FlierDoc, FlierDocError, type FlierDocResult, type FontSet, FontSetId, FormatId, type FormatSize, type IncludesBlock, type JsonSchema, LAYOUT_CATALOGUE, LINE_KEY_PATTERN, type LayoutCatalogueEntry, LayoutId, LineAlign, type LineKey, type LineStyle, type LineTie, LineTieKind, type ListItem, type LogoSlot, PALETTES, type Palette, PaletteId, PictureAnchor, type PictureOverlap, type PictureSlot, type PosterAssets, type PosterCanvas, type PosterContext, type PosterGradient, type PosterImage, type PosterTuning, type PriceRow, type Rect, type RenderReport, RowIcon, type RowTheme, type ScheduleRow, type SkyStop, type TextMetricsLike, defaultLayoutFor, defaultSectionOrder, exportPng, flierDocSchema, kizombaWorkshop, kizombaWorkshopDocs, render, roleOf, roleOrder, sameSize, sameWidth, sectionOrderOf, validateFlierDoc };
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,17 @@ var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
|
|
|
9
9
|
return BackgroundStyle2;
|
|
10
10
|
})(BackgroundStyle || {});
|
|
11
11
|
|
|
12
|
+
// src/enums/BodySection.ts
|
|
13
|
+
var BodySection = /* @__PURE__ */ ((BodySection2) => {
|
|
14
|
+
BodySection2["Venue"] = "venue";
|
|
15
|
+
BodySection2["Schedule"] = "schedule";
|
|
16
|
+
BodySection2["Items"] = "items";
|
|
17
|
+
BodySection2["Prices"] = "prices";
|
|
18
|
+
BodySection2["Includes"] = "includes";
|
|
19
|
+
BodySection2["Footer"] = "footer";
|
|
20
|
+
return BodySection2;
|
|
21
|
+
})(BodySection || {});
|
|
22
|
+
|
|
12
23
|
// src/enums/FontSetId.ts
|
|
13
24
|
var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
|
|
14
25
|
FontSetId2["Classic"] = "classic";
|
|
@@ -88,10 +99,6 @@ var RowIcon = /* @__PURE__ */ ((RowIcon2) => {
|
|
|
88
99
|
// src/schema/lineStyleSchema.ts
|
|
89
100
|
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]))$";
|
|
90
101
|
var MAX_FONT = 40;
|
|
91
|
-
var MIN_SIZE_SCALE = 0.25;
|
|
92
|
-
var MAX_SIZE_SCALE = 3;
|
|
93
|
-
var MIN_WIDTH_SCALE = 0.5;
|
|
94
|
-
var MAX_WIDTH_SCALE = 1.5;
|
|
95
102
|
var MIN_SPACING = -0.1;
|
|
96
103
|
var MAX_SPACING = 0.5;
|
|
97
104
|
var MAX_TIES = 12;
|
|
@@ -102,8 +109,8 @@ var lineStyle = {
|
|
|
102
109
|
additionalProperties: false,
|
|
103
110
|
properties: {
|
|
104
111
|
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
105
|
-
sizeScale: { type: "number", minimum:
|
|
106
|
-
widthScale: { type: "number", minimum:
|
|
112
|
+
sizeScale: { type: "number", minimum: 0 },
|
|
113
|
+
widthScale: { type: "number", minimum: 0 },
|
|
107
114
|
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
108
115
|
weight: { type: "integer", enum: WEIGHTS },
|
|
109
116
|
italic: { type: "boolean" },
|
|
@@ -272,6 +279,7 @@ var MIN_SCALE = 0.3;
|
|
|
272
279
|
var MAX_HEADER_GAP = 200;
|
|
273
280
|
var MIN_DATE_SCALE = 0.5;
|
|
274
281
|
var MAX_DATE_SCALE = 2;
|
|
282
|
+
var MAX_SECTIONS = 6;
|
|
275
283
|
var text = (maxLength) => ({ type: "string", minLength: 1, maxLength });
|
|
276
284
|
var scheduleRow = {
|
|
277
285
|
type: "object",
|
|
@@ -350,6 +358,7 @@ var flierDocSchema = {
|
|
|
350
358
|
lineStyles: lineStylesSchema,
|
|
351
359
|
lineTies: lineTiesSchema,
|
|
352
360
|
rows: rowsSchema,
|
|
361
|
+
sectionOrder: { type: "array", maxItems: MAX_SECTIONS, items: { type: "string", enum: Object.values(BodySection) } },
|
|
353
362
|
items: {
|
|
354
363
|
type: "array",
|
|
355
364
|
minItems: 1,
|
|
@@ -809,12 +818,25 @@ function styled(line, key, sc) {
|
|
|
809
818
|
italic: style?.italic,
|
|
810
819
|
spacing: style?.letterSpacing,
|
|
811
820
|
widthScale: style?.widthScale,
|
|
821
|
+
fixedSize: style?.sizeScale === void 0 ? void 0 : true,
|
|
812
822
|
align: style?.align,
|
|
813
823
|
widthTie,
|
|
814
824
|
sizeTie
|
|
815
825
|
};
|
|
816
826
|
}
|
|
817
827
|
|
|
828
|
+
// src/layout/sectionOrder.ts
|
|
829
|
+
var EVENT_ORDER = ["venue" /* Venue */, "schedule" /* Schedule */, "prices" /* Prices */, "includes" /* Includes */, "footer" /* Footer */];
|
|
830
|
+
var LIST_ORDER = ["venue" /* Venue */, "items" /* Items */, "prices" /* Prices */, "includes" /* Includes */, "footer" /* Footer */];
|
|
831
|
+
function defaultSectionOrder(layout) {
|
|
832
|
+
return [...layout === "list" /* List */ ? LIST_ORDER : EVENT_ORDER];
|
|
833
|
+
}
|
|
834
|
+
function sectionOrderOf(doc) {
|
|
835
|
+
const base2 = defaultSectionOrder(doc.layout);
|
|
836
|
+
const own = (doc.sectionOrder ?? []).filter((s, i, all) => base2.includes(s) && all.indexOf(s) === i);
|
|
837
|
+
return [...own, ...base2.filter((s) => !own.includes(s))];
|
|
838
|
+
}
|
|
839
|
+
|
|
818
840
|
// src/layout/blockGroups.ts
|
|
819
841
|
var BOLD = 700;
|
|
820
842
|
var SEMI = 600;
|
|
@@ -901,7 +923,7 @@ function halves(text2) {
|
|
|
901
923
|
}
|
|
902
924
|
function wrapped(line, wrap) {
|
|
903
925
|
const parts = wrap ? halves(line.text) : [line.text];
|
|
904
|
-
return parts.map((text2, i) => i === 0 ? { ...line, text: text2 } : { ...line, text: text2, bullet: void 0, hang: line.bullet !== void 0 });
|
|
926
|
+
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 });
|
|
905
927
|
}
|
|
906
928
|
function scheduleLines(doc, l, row, i) {
|
|
907
929
|
const r3 = doc.rows;
|
|
@@ -909,31 +931,30 @@ function scheduleLines(doc, l, row, i) {
|
|
|
909
931
|
const tied = r3?.labelScale === void 0 ? label : { ...label, sizeTie: label.sizeTie ?? LABEL_TIE };
|
|
910
932
|
return [tied, l.time(row.time, SIZE.scheduleTime * (r3?.timeScale ?? 1), `schedule.${i}.time`)];
|
|
911
933
|
}
|
|
934
|
+
var tailed = (line, key, headLength) => ({ ...line, tail: { key, at: line.text.length - line.text.slice(headLength).trimStart().length } });
|
|
912
935
|
var priceAmount = (doc, line) => doc.rows?.priceGap === void 0 ? line : { ...line, gapAfter: doc.rows.priceGap };
|
|
913
936
|
function eventGroups(doc, l, u, options) {
|
|
914
937
|
const b = doc.blocks;
|
|
915
|
-
const
|
|
938
|
+
const rows = [];
|
|
939
|
+
const priced = [];
|
|
916
940
|
const schedule2 = b.schedule ?? [];
|
|
917
941
|
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
918
942
|
const lastRow = schedule2.length + prices.length - 1;
|
|
919
943
|
const icons2 = doc.rows?.icons;
|
|
920
944
|
schedule2.forEach((row, i) => {
|
|
921
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : scheduleLines(doc, l, row, i);
|
|
922
|
-
|
|
945
|
+
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);
|
|
946
|
+
rows.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
|
|
923
947
|
});
|
|
924
948
|
prices.forEach((row, i) => {
|
|
925
|
-
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`)];
|
|
926
|
-
|
|
949
|
+
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`)];
|
|
950
|
+
priced.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
|
|
927
951
|
});
|
|
928
|
-
return
|
|
952
|
+
return [rows, priced];
|
|
929
953
|
}
|
|
930
954
|
function listGroups(doc, l, u, dateScale) {
|
|
931
955
|
const groups = (doc.items ?? []).map((item, n) => itemGroup(item, n, l, { u, dateScale }));
|
|
932
|
-
const prices = doc.blocks.prices?.map((row, i) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`)) ?? [];
|
|
933
|
-
|
|
934
|
-
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
935
|
-
}
|
|
936
|
-
return groups;
|
|
956
|
+
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)) ?? [];
|
|
957
|
+
return [groups, prices.length > 0 ? [{ lines: prices, gapAfter: GAP.row * u }] : []];
|
|
937
958
|
}
|
|
938
959
|
function flankPriceGroups(doc, p, u) {
|
|
939
960
|
const l = makers(p, u, styleContext(doc));
|
|
@@ -942,28 +963,74 @@ function flankPriceGroups(doc, p, u) {
|
|
|
942
963
|
function pinOf(look, u) {
|
|
943
964
|
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 };
|
|
944
965
|
}
|
|
966
|
+
function venueGroups(doc, p, u, l) {
|
|
967
|
+
const b = doc.blocks;
|
|
968
|
+
if (!b.venue) {
|
|
969
|
+
return [];
|
|
970
|
+
}
|
|
971
|
+
const size = doc.layout === "list" /* List */ ? SIZE.listVenue : SIZE.venue;
|
|
972
|
+
const look = doc.rows?.venue;
|
|
973
|
+
const line = look?.body === true ? l.bodyVenue : l.venue;
|
|
974
|
+
const venue = look?.oneLine === true ? [b.venue.join(" ")] : b.venue;
|
|
975
|
+
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) } }];
|
|
976
|
+
}
|
|
977
|
+
var bound = (s, next) => s === "venue" /* Venue */ && next === "schedule" /* Schedule */ || s === "includes" /* Includes */ && next === "footer" /* Footer */;
|
|
978
|
+
function joined(order, parts) {
|
|
979
|
+
const filled = order.filter((s) => parts[s].length > 0);
|
|
980
|
+
return filled.flatMap((s, n) => {
|
|
981
|
+
const groups = parts[s];
|
|
982
|
+
if (!bound(s, filled[n + 1])) {
|
|
983
|
+
return groups;
|
|
984
|
+
}
|
|
985
|
+
const attach = s === "includes" /* Includes */ ? { attachNext: true } : {};
|
|
986
|
+
return groups.map((g, i) => i === groups.length - 1 ? { ...g, keepWithNext: true, ...attach } : g);
|
|
987
|
+
});
|
|
988
|
+
}
|
|
945
989
|
function bodyGroups(doc, p, u, options = {}) {
|
|
946
990
|
const l = makers(p, u, styleContext(doc), doc.rows?.timeWeight);
|
|
947
991
|
const b = doc.blocks;
|
|
948
|
-
const groups = [];
|
|
949
992
|
const isList = doc.layout === "list" /* List */;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
993
|
+
const [rows, prices] = isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) });
|
|
994
|
+
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}`))] : [];
|
|
995
|
+
const includes = includeLines.length > 0 ? [{ lines: includeLines.flatMap((line) => wrapped(line, options.wrap)), gapAfter: GAP.includes * u, uniform: true }] : [];
|
|
996
|
+
const footer = b.footer ? [{ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 }] : [];
|
|
997
|
+
const parts = {
|
|
998
|
+
["venue" /* Venue */]: venueGroups(doc, p, u, l),
|
|
999
|
+
["schedule" /* Schedule */]: isList ? [] : rows,
|
|
1000
|
+
["items" /* Items */]: isList ? rows : [],
|
|
1001
|
+
["prices" /* Prices */]: prices,
|
|
1002
|
+
["includes" /* Includes */]: includes,
|
|
1003
|
+
["footer" /* Footer */]: footer
|
|
1004
|
+
};
|
|
1005
|
+
return joined(sectionOrderOf(doc), parts);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/layout/lineRuns.ts
|
|
1009
|
+
var NO_SPACING = "0px";
|
|
1010
|
+
function widthOf(ctx, line, fonts, text2) {
|
|
1011
|
+
ctx.font = fontOf(line, line.size, fonts);
|
|
1012
|
+
if (line.spacing === void 0) {
|
|
1013
|
+
return ctx.measureText(text2).width;
|
|
957
1014
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1015
|
+
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
1016
|
+
const width = ctx.measureText(text2).width;
|
|
1017
|
+
ctx.letterSpacing = NO_SPACING;
|
|
1018
|
+
return width;
|
|
1019
|
+
}
|
|
1020
|
+
var measure = (ctx, line, fonts) => widthOf(ctx, line, fonts, line.text);
|
|
1021
|
+
function measureCut(ctx, line, fonts) {
|
|
1022
|
+
if (line.tail === void 0) {
|
|
1023
|
+
return void 0;
|
|
962
1024
|
}
|
|
963
|
-
|
|
964
|
-
|
|
1025
|
+
const head = line.text.slice(0, line.tail.at);
|
|
1026
|
+
return [widthOf(ctx, line, fonts, head.trimEnd()), widthOf(ctx, line, fonts, head)];
|
|
1027
|
+
}
|
|
1028
|
+
function runsOf(line, box, cut, scale) {
|
|
1029
|
+
if (line.tail === void 0 || line.key === void 0 || cut === void 0) {
|
|
1030
|
+
return {};
|
|
965
1031
|
}
|
|
966
|
-
|
|
1032
|
+
const start = cut[1] * scale;
|
|
1033
|
+
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) } }] };
|
|
967
1034
|
}
|
|
968
1035
|
|
|
969
1036
|
// src/layout/lineSizes.ts
|
|
@@ -988,16 +1055,19 @@ function groupBox(group, k, colW) {
|
|
|
988
1055
|
return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
|
|
989
1056
|
}
|
|
990
1057
|
function lineSize(line, width, k, avail) {
|
|
1058
|
+
if (line.fixedSize === true) {
|
|
1059
|
+
return line.size;
|
|
1060
|
+
}
|
|
991
1061
|
const indent = bulletIndent(line, k);
|
|
992
1062
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
993
1063
|
}
|
|
994
|
-
function groupSizes(m, k, avail
|
|
995
|
-
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k,
|
|
1064
|
+
function groupSizes(m, k, avail) {
|
|
1065
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail * (line.widthScale ?? 1)));
|
|
996
1066
|
if (!m.group.uniform) {
|
|
997
1067
|
return own;
|
|
998
1068
|
}
|
|
999
1069
|
const ratio = Math.min(...m.group.lines.map((line, i) => (own[i] ?? 0) / line.size));
|
|
1000
|
-
return m.group.lines.map((line) => line.size * ratio);
|
|
1070
|
+
return m.group.lines.map((line) => line.fixedSize === true ? line.size : line.size * ratio);
|
|
1001
1071
|
}
|
|
1002
1072
|
function tieMembers(all, k, colW, table, pick) {
|
|
1003
1073
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -1006,7 +1076,7 @@ function tieMembers(all, k, colW, table, pick) {
|
|
|
1006
1076
|
const sizes = table.get(m) ?? [];
|
|
1007
1077
|
m.group.lines.forEach((line, i) => {
|
|
1008
1078
|
const id = pick(line);
|
|
1009
|
-
if (id !== void 0) {
|
|
1079
|
+
if (id !== void 0 && line.fixedSize !== true) {
|
|
1010
1080
|
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 };
|
|
1011
1081
|
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
1012
1082
|
}
|
|
@@ -1027,8 +1097,8 @@ function sameWidths(list) {
|
|
|
1027
1097
|
x.sizes[x.i] = target * x.line.size / x.width;
|
|
1028
1098
|
});
|
|
1029
1099
|
}
|
|
1030
|
-
function sizeTable(all, k, colW
|
|
1031
|
-
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail
|
|
1100
|
+
function sizeTable(all, k, colW) {
|
|
1101
|
+
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
|
|
1032
1102
|
tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
|
|
1033
1103
|
tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
|
|
1034
1104
|
return table;
|
|
@@ -1044,7 +1114,6 @@ var TWO_COLUMN_MIN = 0.75;
|
|
|
1044
1114
|
var TWO_COLUMN_GAIN = 1.15;
|
|
1045
1115
|
var MIN_K = 0.02;
|
|
1046
1116
|
var STEPS = 22;
|
|
1047
|
-
var NO_SPACING = "0px";
|
|
1048
1117
|
var fontOf = (line, size, fonts) => {
|
|
1049
1118
|
const family = line.family === void 0 ? fonts[line.role] : `"${line.family}", ${fonts[line.role]}`;
|
|
1050
1119
|
return `${line.italic === true ? "italic " : ""}${line.weight} ${size}px ${family}`;
|
|
@@ -1094,7 +1163,8 @@ function placeGroup(m, at, out) {
|
|
|
1094
1163
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
1095
1164
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
1096
1165
|
const x = lineX(line, { col, pad, indent, w });
|
|
1097
|
-
|
|
1166
|
+
const box = { x, y, w, h: size * LINE_HEIGHT };
|
|
1167
|
+
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) });
|
|
1098
1168
|
if (line.bullet && out) {
|
|
1099
1169
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
1100
1170
|
}
|
|
@@ -1160,11 +1230,11 @@ function splitColumns(groups, zone) {
|
|
|
1160
1230
|
}
|
|
1161
1231
|
cut = keepTogether(groups, heights, cut);
|
|
1162
1232
|
return [
|
|
1163
|
-
{ col: { ...zone, w
|
|
1164
|
-
{ col: { ...zone, x: zone.x + w + gap, w
|
|
1233
|
+
{ col: { ...zone, w }, groups: groups.slice(0, cut) },
|
|
1234
|
+
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
1165
1235
|
];
|
|
1166
1236
|
}
|
|
1167
|
-
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0
|
|
1237
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
1168
1238
|
function largestK(columns, zoneH) {
|
|
1169
1239
|
const fits = (k) => {
|
|
1170
1240
|
const table = tableFor(columns, k);
|
|
@@ -1196,20 +1266,11 @@ function bestColumns(measured, zone) {
|
|
|
1196
1266
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
1197
1267
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
1198
1268
|
}
|
|
1199
|
-
function measure(ctx, line, fonts) {
|
|
1200
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
1201
|
-
if (line.spacing === void 0) {
|
|
1202
|
-
return ctx.measureText(line.text).width;
|
|
1203
|
-
}
|
|
1204
|
-
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
1205
|
-
const width = ctx.measureText(line.text).width;
|
|
1206
|
-
ctx.letterSpacing = NO_SPACING;
|
|
1207
|
-
return width;
|
|
1208
|
-
}
|
|
1209
1269
|
function flow(ctx, groups, zone, fonts) {
|
|
1210
1270
|
const measured = groups.map((group) => ({
|
|
1211
1271
|
group,
|
|
1212
|
-
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
1272
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts)),
|
|
1273
|
+
cuts: group.lines.map((line) => measureCut(ctx, line, fonts))
|
|
1213
1274
|
}));
|
|
1214
1275
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
1215
1276
|
const out = emptyFlow();
|
|
@@ -1323,11 +1384,11 @@ function flowAll(ctx, input, base2, reflow) {
|
|
|
1323
1384
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
1324
1385
|
const flanks = geo.flanks ?? [];
|
|
1325
1386
|
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
1326
|
-
const body = flow(ctx, bodyGroups(doc, palette, u, { withPrices: flanks.length === 0, compact: reflow.compact, wrap: reflow.wrap, dateScale: doc.tuning?.itemDateScale }),
|
|
1387
|
+
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);
|
|
1327
1388
|
const sides = flanks.length > 0 ? equalFlanks(ctx, flankPriceGroups(doc, palette, u), flanks, fonts) : [emptyFlow()];
|
|
1328
1389
|
return { geo: tight, zones, head, body, sides };
|
|
1329
1390
|
}
|
|
1330
|
-
var smallest = (t) => Math.min(Infinity, ...[t.head, t.body, ...t.sides].flatMap((f) => f.texts.map((x) => x.box.h / LINE_HEIGHT3)));
|
|
1391
|
+
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)));
|
|
1331
1392
|
function shiftHeader(geo, shift) {
|
|
1332
1393
|
const { header, body } = geo;
|
|
1333
1394
|
const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
|
|
@@ -1393,6 +1454,40 @@ function fitToFloor(ctx, input) {
|
|
|
1393
1454
|
return best ?? flowAll(ctx, input, base2, { compact: false, wrap: false});
|
|
1394
1455
|
}
|
|
1395
1456
|
|
|
1457
|
+
// src/render/lineBoxesOf.ts
|
|
1458
|
+
function union(a, b) {
|
|
1459
|
+
if (a === void 0) {
|
|
1460
|
+
return { ...b };
|
|
1461
|
+
}
|
|
1462
|
+
const x = Math.min(a.x, b.x);
|
|
1463
|
+
const y = Math.min(a.y, b.y);
|
|
1464
|
+
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 };
|
|
1465
|
+
}
|
|
1466
|
+
function lineBoxesOf(texts) {
|
|
1467
|
+
const boxes = {};
|
|
1468
|
+
texts.forEach(({ key, box, runs }) => {
|
|
1469
|
+
(runs ?? (key === void 0 ? [] : [{ key, box }])).forEach((r3) => {
|
|
1470
|
+
boxes[r3.key] = union(boxes[r3.key], r3.box);
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
return boxes;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/render/roleOrder.ts
|
|
1477
|
+
var INDEX = /^\d+$/;
|
|
1478
|
+
var roleOf = (key) => key.split(".").filter((part) => !INDEX.test(part)).join(".");
|
|
1479
|
+
function roleOrder(boxes) {
|
|
1480
|
+
const first = /* @__PURE__ */ new Map();
|
|
1481
|
+
Object.entries(boxes).forEach(([key, box]) => {
|
|
1482
|
+
const role = roleOf(key);
|
|
1483
|
+
const seen = first.get(role);
|
|
1484
|
+
if (box !== void 0 && (seen === void 0 || box.y < seen.y || box.y === seen.y && box.x < seen.x)) {
|
|
1485
|
+
first.set(role, box);
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
return [...first.entries()].sort(([, a], [, b]) => a.y - b.y || a.x - b.x).map(([role]) => role);
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1396
1491
|
// src/render/overlap.ts
|
|
1397
1492
|
var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
1398
1493
|
function placePicture(image, region, slot, fit) {
|
|
@@ -1615,23 +1710,6 @@ function drawLogo(ctx, doc, assets, fitted) {
|
|
|
1615
1710
|
}
|
|
1616
1711
|
return logo;
|
|
1617
1712
|
}
|
|
1618
|
-
function lineBoxesOf(texts) {
|
|
1619
|
-
const boxes = {};
|
|
1620
|
-
texts.forEach(({ key, box }) => {
|
|
1621
|
-
if (key !== void 0) {
|
|
1622
|
-
boxes[key] = union(boxes[key], box);
|
|
1623
|
-
}
|
|
1624
|
-
});
|
|
1625
|
-
return boxes;
|
|
1626
|
-
}
|
|
1627
|
-
function union(a, b) {
|
|
1628
|
-
if (a === void 0) {
|
|
1629
|
-
return { ...b };
|
|
1630
|
-
}
|
|
1631
|
-
const x = Math.min(a.x, b.x);
|
|
1632
|
-
const y = Math.min(a.y, b.y);
|
|
1633
|
-
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 };
|
|
1634
|
-
}
|
|
1635
1713
|
function render(input, assets, canvas) {
|
|
1636
1714
|
const doc = checked(input, assets);
|
|
1637
1715
|
const { width, height } = FORMAT_SIZES[doc.format];
|
|
@@ -1661,18 +1739,21 @@ function render(input, assets, canvas) {
|
|
|
1661
1739
|
if (layered) {
|
|
1662
1740
|
flows.forEach((f) => drawMarks(ctx, f, radius));
|
|
1663
1741
|
}
|
|
1742
|
+
const lineBoxes = lineBoxesOf(flows.flatMap((f) => f.texts));
|
|
1664
1743
|
return {
|
|
1665
1744
|
width,
|
|
1666
1745
|
height,
|
|
1667
1746
|
picture,
|
|
1668
1747
|
pictureRegion: region,
|
|
1669
1748
|
textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
|
|
1670
|
-
lineBoxes
|
|
1749
|
+
lineBoxes,
|
|
1671
1750
|
cardBoxes: body.cards.map((c) => c.rect),
|
|
1672
1751
|
iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
|
|
1673
1752
|
ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
|
|
1674
1753
|
logo,
|
|
1675
|
-
backdrop
|
|
1754
|
+
backdrop,
|
|
1755
|
+
sectionOrder: sectionOrderOf(doc),
|
|
1756
|
+
roleOrder: roleOrder(lineBoxes)
|
|
1676
1757
|
};
|
|
1677
1758
|
}
|
|
1678
1759
|
|
|
@@ -1767,6 +1848,7 @@ var kizombaWorkshop = {
|
|
|
1767
1848
|
var kizombaWorkshopDocs = [...WORKSHOPS.map(workshopDoc), kizombaWorkshop];
|
|
1768
1849
|
|
|
1769
1850
|
exports.BackgroundStyle = BackgroundStyle;
|
|
1851
|
+
exports.BodySection = BodySection;
|
|
1770
1852
|
exports.FONT_SETS = FONT_SETS;
|
|
1771
1853
|
exports.FORMAT_SIZES = FORMAT_SIZES;
|
|
1772
1854
|
exports.FlierDocError = FlierDocError;
|
|
@@ -1782,13 +1864,17 @@ exports.PaletteId = PaletteId;
|
|
|
1782
1864
|
exports.PictureAnchor = PictureAnchor;
|
|
1783
1865
|
exports.RowIcon = RowIcon;
|
|
1784
1866
|
exports.defaultLayoutFor = defaultLayoutFor;
|
|
1867
|
+
exports.defaultSectionOrder = defaultSectionOrder;
|
|
1785
1868
|
exports.exportPng = exportPng;
|
|
1786
1869
|
exports.flierDocSchema = flierDocSchema;
|
|
1787
1870
|
exports.kizombaWorkshop = kizombaWorkshop;
|
|
1788
1871
|
exports.kizombaWorkshopDocs = kizombaWorkshopDocs;
|
|
1789
1872
|
exports.render = render;
|
|
1873
|
+
exports.roleOf = roleOf;
|
|
1874
|
+
exports.roleOrder = roleOrder;
|
|
1790
1875
|
exports.sameSize = sameSize;
|
|
1791
1876
|
exports.sameWidth = sameWidth;
|
|
1877
|
+
exports.sectionOrderOf = sectionOrderOf;
|
|
1792
1878
|
exports.validateFlierDoc = validateFlierDoc;
|
|
1793
1879
|
//# sourceMappingURL=index.js.map
|
|
1794
1880
|
//# sourceMappingURL=index.js.map
|