@dloizides/poster-render 0.4.0 → 0.6.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/CHANGELOG.md +19 -0
- package/README.md +15 -0
- package/dist/index.d.mts +111 -28
- package/dist/index.d.ts +111 -28
- package/dist/index.js +623 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +618 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var BackgroundStyle = /* @__PURE__ */ ((BackgroundStyle2) => {
|
|
|
5
5
|
BackgroundStyle2["Solid"] = "solid";
|
|
6
6
|
BackgroundStyle2["Tint"] = "tint";
|
|
7
7
|
BackgroundStyle2["Horizon"] = "horizon";
|
|
8
|
+
BackgroundStyle2["Brush"] = "brush";
|
|
8
9
|
return BackgroundStyle2;
|
|
9
10
|
})(BackgroundStyle || {});
|
|
10
11
|
|
|
@@ -14,6 +15,7 @@ var FontSetId = /* @__PURE__ */ ((FontSetId2) => {
|
|
|
14
15
|
FontSetId2["Modern"] = "modern";
|
|
15
16
|
FontSetId2["Elegant"] = "elegant";
|
|
16
17
|
FontSetId2["Coastal"] = "coastal";
|
|
18
|
+
FontSetId2["KizombaSample"] = "kizomba-sample";
|
|
17
19
|
return FontSetId2;
|
|
18
20
|
})(FontSetId || {});
|
|
19
21
|
|
|
@@ -48,6 +50,7 @@ var PaletteId = /* @__PURE__ */ ((PaletteId2) => {
|
|
|
48
50
|
PaletteId2["Sea"] = "sea";
|
|
49
51
|
PaletteId2["Rose"] = "rose";
|
|
50
52
|
PaletteId2["GoldenHorizon"] = "golden-horizon";
|
|
53
|
+
PaletteId2["KizombaSample"] = "kizomba-sample";
|
|
51
54
|
return PaletteId2;
|
|
52
55
|
})(PaletteId || {});
|
|
53
56
|
|
|
@@ -59,6 +62,79 @@ var PictureAnchor = /* @__PURE__ */ ((PictureAnchor2) => {
|
|
|
59
62
|
return PictureAnchor2;
|
|
60
63
|
})(PictureAnchor || {});
|
|
61
64
|
|
|
65
|
+
// src/enums/LineAlign.ts
|
|
66
|
+
var LineAlign = /* @__PURE__ */ ((LineAlign2) => {
|
|
67
|
+
LineAlign2["Left"] = "left";
|
|
68
|
+
LineAlign2["Center"] = "center";
|
|
69
|
+
LineAlign2["Right"] = "right";
|
|
70
|
+
return LineAlign2;
|
|
71
|
+
})(LineAlign || {});
|
|
72
|
+
|
|
73
|
+
// src/enums/LineTieKind.ts
|
|
74
|
+
var LineTieKind = /* @__PURE__ */ ((LineTieKind2) => {
|
|
75
|
+
LineTieKind2["Width"] = "width";
|
|
76
|
+
LineTieKind2["Size"] = "size";
|
|
77
|
+
return LineTieKind2;
|
|
78
|
+
})(LineTieKind || {});
|
|
79
|
+
|
|
80
|
+
// src/enums/RowIcon.ts
|
|
81
|
+
var RowIcon = /* @__PURE__ */ ((RowIcon2) => {
|
|
82
|
+
RowIcon2["Person"] = "person";
|
|
83
|
+
RowIcon2["People"] = "people";
|
|
84
|
+
RowIcon2["Ticket"] = "ticket";
|
|
85
|
+
return RowIcon2;
|
|
86
|
+
})(RowIcon || {});
|
|
87
|
+
|
|
88
|
+
// src/schema/lineStyleSchema.ts
|
|
89
|
+
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
|
+
var MAX_FONT = 40;
|
|
91
|
+
var MIN_SIZE_SCALE = 0.25;
|
|
92
|
+
var MAX_SIZE_SCALE = 3;
|
|
93
|
+
var MIN_SPACING = -0.1;
|
|
94
|
+
var MAX_SPACING = 0.5;
|
|
95
|
+
var MAX_TIES = 12;
|
|
96
|
+
var WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
97
|
+
var lineKey = { type: "string", pattern: LINE_KEY_PATTERN };
|
|
98
|
+
var lineStyle = {
|
|
99
|
+
type: "object",
|
|
100
|
+
additionalProperties: false,
|
|
101
|
+
properties: {
|
|
102
|
+
font: { type: "string", minLength: 1, maxLength: MAX_FONT, pattern: "^[A-Za-z0-9 ]+$" },
|
|
103
|
+
sizeScale: { type: "number", minimum: MIN_SIZE_SCALE, maximum: MAX_SIZE_SCALE },
|
|
104
|
+
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
105
|
+
weight: { type: "integer", enum: WEIGHTS },
|
|
106
|
+
italic: { type: "boolean" },
|
|
107
|
+
letterSpacing: { type: "number", minimum: MIN_SPACING, maximum: MAX_SPACING },
|
|
108
|
+
align: { type: "string", enum: Object.values(LineAlign) }
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var lineStylesSchema = { type: "object", propertyNames: lineKey, additionalProperties: lineStyle };
|
|
112
|
+
var lineTiesSchema = {
|
|
113
|
+
type: "array",
|
|
114
|
+
maxItems: MAX_TIES,
|
|
115
|
+
items: {
|
|
116
|
+
type: "object",
|
|
117
|
+
required: ["kind", "lines"],
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
properties: {
|
|
120
|
+
kind: { type: "string", enum: Object.values(LineTieKind) },
|
|
121
|
+
lines: { type: "array", minItems: 2, maxItems: 2, items: lineKey }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/lineTies.ts
|
|
127
|
+
function tie(doc, kind, a, b) {
|
|
128
|
+
const ties = doc.lineTies ?? [];
|
|
129
|
+
const exists = ties.some((t) => t.kind === kind && t.lines.includes(a) && t.lines.includes(b));
|
|
130
|
+
if (a === b || exists) {
|
|
131
|
+
return doc;
|
|
132
|
+
}
|
|
133
|
+
return { ...doc, lineTies: [...ties, { kind, lines: [a, b] }] };
|
|
134
|
+
}
|
|
135
|
+
var sameWidth = (doc, a, b) => tie(doc, "width" /* Width */, a, b);
|
|
136
|
+
var sameSize = (doc, a, b) => tie(doc, "size" /* Size */, a, b);
|
|
137
|
+
|
|
62
138
|
// src/formats.ts
|
|
63
139
|
var FORMAT_SIZES = {
|
|
64
140
|
["story" /* Story */]: { width: 1080, height: 1920 },
|
|
@@ -84,6 +160,20 @@ var PALETTES = {
|
|
|
84
160
|
arch: "#c7d4d6",
|
|
85
161
|
sky: [[0, "#bfd3d8"], [0.55, "#d4dddd"], [1, "#eadccb"]]
|
|
86
162
|
},
|
|
163
|
+
["kizomba-sample" /* KizombaSample */]: {
|
|
164
|
+
background: "#fefefe",
|
|
165
|
+
tint: "#f3eee9",
|
|
166
|
+
title: "#6d645d",
|
|
167
|
+
accent: "#ad8164",
|
|
168
|
+
ink: "#45372f",
|
|
169
|
+
soft: "#9c8f84",
|
|
170
|
+
card: "#ffffff",
|
|
171
|
+
arch: "#efe8e1",
|
|
172
|
+
script: "#e5bb97",
|
|
173
|
+
icon: "#cca383",
|
|
174
|
+
rule: "#d5bca8",
|
|
175
|
+
brush: ["#cdc3b9", "#96918b", "#daae81"]
|
|
176
|
+
},
|
|
87
177
|
["rose" /* Rose */]: { background: "#f8efec", tint: "#f1e2dd", title: "#9b6b63", accent: "#c9846f", ink: "#4a3934", soft: "#b39a92", card: "#ffffff", arch: "#f1e5e1" }
|
|
88
178
|
};
|
|
89
179
|
|
|
@@ -92,15 +182,65 @@ var FONT_SETS = {
|
|
|
92
182
|
["classic" /* Classic */]: { display: '"Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Fredoka", sans-serif' },
|
|
93
183
|
["modern" /* Modern */]: { display: '"Bebas Neue", "Arial Narrow", sans-serif', script: '"Great Vibes", cursive', body: '"Montserrat", sans-serif' },
|
|
94
184
|
["elegant" /* Elegant */]: { display: '"Playfair Display", serif', script: '"Allura", cursive', body: '"Lato", sans-serif' },
|
|
185
|
+
["kizomba-sample" /* KizombaSample */]: { display: '"Anton", "Oswald", "Arial Narrow", sans-serif', script: '"Sacramento", cursive', body: '"Barlow Semi Condensed", "Fredoka", sans-serif' },
|
|
95
186
|
["coastal" /* Coastal */]: { display: '"Fraunces", Georgia, serif', script: '"Allura", cursive', body: '"Jost", sans-serif' }
|
|
96
187
|
};
|
|
97
188
|
|
|
189
|
+
// src/schema/rowsSchema.ts
|
|
190
|
+
var MAX_ROWS = 6;
|
|
191
|
+
var MAX_PRICES = 4;
|
|
192
|
+
var MIN_ICON = 16;
|
|
193
|
+
var MAX_ICON = 300;
|
|
194
|
+
var MIN_THICKNESS = 0.5;
|
|
195
|
+
var MAX_THICKNESS = 20;
|
|
196
|
+
var MAX_GAP = 120;
|
|
197
|
+
var MAX_OVERLAP = 1.5;
|
|
198
|
+
var MAX_SHIFT = 0.5;
|
|
199
|
+
var MAX_TOP = 600;
|
|
200
|
+
var MAX_LINE_GAP = 200;
|
|
201
|
+
var MIN_TITLE_SCALE = 0.3;
|
|
202
|
+
var MAX_TITLE_SCALE = 2.5;
|
|
203
|
+
var num = (minimum, maximum) => ({ type: "number", minimum, maximum });
|
|
204
|
+
var icons = (maxItems) => ({ type: "array", items: { type: "string", enum: Object.values(RowIcon) }, minItems: 1, maxItems });
|
|
205
|
+
var rowsSchema = {
|
|
206
|
+
type: "object",
|
|
207
|
+
additionalProperties: false,
|
|
208
|
+
properties: {
|
|
209
|
+
icons: { type: "object", additionalProperties: false, properties: { schedule: icons(MAX_ROWS), prices: icons(MAX_PRICES), size: num(MIN_ICON, MAX_ICON) } },
|
|
210
|
+
dividers: {
|
|
211
|
+
type: "object",
|
|
212
|
+
required: ["thickness"],
|
|
213
|
+
additionalProperties: false,
|
|
214
|
+
properties: {
|
|
215
|
+
thickness: num(MIN_THICKNESS, MAX_THICKNESS),
|
|
216
|
+
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
217
|
+
gap: num(0, MAX_GAP),
|
|
218
|
+
toPicture: { type: "boolean" },
|
|
219
|
+
reach: num(0, 1)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var overlapSchema = {
|
|
225
|
+
type: "object",
|
|
226
|
+
required: ["scale", "dx", "dy"],
|
|
227
|
+
additionalProperties: false,
|
|
228
|
+
properties: { scale: num(1, MAX_OVERLAP), dx: num(-MAX_SHIFT, MAX_SHIFT), dy: num(-MAX_SHIFT, MAX_SHIFT) }
|
|
229
|
+
};
|
|
230
|
+
var headerTuningSchema = {
|
|
231
|
+
headerTop: num(0, MAX_TOP),
|
|
232
|
+
titleScriptGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
233
|
+
scriptTitleGap: num(-MAX_LINE_GAP, MAX_LINE_GAP),
|
|
234
|
+
titleScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE),
|
|
235
|
+
titleBottomScale: num(MIN_TITLE_SCALE, MAX_TITLE_SCALE)
|
|
236
|
+
};
|
|
237
|
+
|
|
98
238
|
// src/schema/flierDocSchema.ts
|
|
99
239
|
var SHORT = 60;
|
|
100
240
|
var LINE = 120;
|
|
101
|
-
var
|
|
241
|
+
var MAX_ROWS2 = 6;
|
|
102
242
|
var MAX_ITEMS = 8;
|
|
103
|
-
var
|
|
243
|
+
var MAX_PRICES2 = 4;
|
|
104
244
|
var MAX_VENUE = 3;
|
|
105
245
|
var MIN_SCALE = 0.3;
|
|
106
246
|
var MAX_HEADER_GAP = 200;
|
|
@@ -113,7 +253,7 @@ var scheduleRow = {
|
|
|
113
253
|
additionalProperties: false,
|
|
114
254
|
properties: { label: text(SHORT), time: text(SHORT) }
|
|
115
255
|
};
|
|
116
|
-
var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems:
|
|
256
|
+
var scheduleList = { type: "array", items: scheduleRow, minItems: 1, maxItems: MAX_ROWS2 };
|
|
117
257
|
var blocks = {
|
|
118
258
|
type: "object",
|
|
119
259
|
required: ["title"],
|
|
@@ -127,7 +267,7 @@ var blocks = {
|
|
|
127
267
|
prices: {
|
|
128
268
|
type: "array",
|
|
129
269
|
minItems: 1,
|
|
130
|
-
maxItems:
|
|
270
|
+
maxItems: MAX_PRICES2,
|
|
131
271
|
items: {
|
|
132
272
|
type: "object",
|
|
133
273
|
required: ["amount", "label"],
|
|
@@ -139,7 +279,7 @@ var blocks = {
|
|
|
139
279
|
type: "object",
|
|
140
280
|
required: ["heading", "items"],
|
|
141
281
|
additionalProperties: false,
|
|
142
|
-
properties: { heading: text(SHORT), items: { type: "array", items: text(LINE), minItems: 1, maxItems:
|
|
282
|
+
properties: { heading: text(SHORT), items: { type: "array", items: text(LINE), minItems: 1, maxItems: MAX_ROWS2 } }
|
|
143
283
|
},
|
|
144
284
|
footer: text(LINE)
|
|
145
285
|
}
|
|
@@ -166,7 +306,8 @@ var flierDocSchema = {
|
|
|
166
306
|
properties: {
|
|
167
307
|
imageId: text(SHORT),
|
|
168
308
|
anchor: { type: "string", enum: Object.values(PictureAnchor) },
|
|
169
|
-
scale: { type: "number", minimum: MIN_SCALE, maximum: 1 }
|
|
309
|
+
scale: { type: "number", minimum: MIN_SCALE, maximum: 1 },
|
|
310
|
+
overlap: overlapSchema
|
|
170
311
|
}
|
|
171
312
|
},
|
|
172
313
|
logo: { type: "object", required: ["imageId"], additionalProperties: false, properties: { imageId: text(SHORT) } },
|
|
@@ -176,9 +317,13 @@ var flierDocSchema = {
|
|
|
176
317
|
additionalProperties: false,
|
|
177
318
|
properties: {
|
|
178
319
|
headerGap: { type: "number", minimum: 0, maximum: MAX_HEADER_GAP },
|
|
179
|
-
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE }
|
|
320
|
+
itemDateScale: { type: "number", minimum: MIN_DATE_SCALE, maximum: MAX_DATE_SCALE },
|
|
321
|
+
...headerTuningSchema
|
|
180
322
|
}
|
|
181
323
|
},
|
|
324
|
+
lineStyles: lineStylesSchema,
|
|
325
|
+
lineTies: lineTiesSchema,
|
|
326
|
+
rows: rowsSchema,
|
|
182
327
|
items: {
|
|
183
328
|
type: "array",
|
|
184
329
|
minItems: 1,
|
|
@@ -202,7 +347,7 @@ var typeName = (v) => {
|
|
|
202
347
|
};
|
|
203
348
|
var join = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
204
349
|
var show = (v) => JSON.stringify(v) ?? typeName(v);
|
|
205
|
-
var ARTICLE = { object: "an object", array: "an array", string: "a string", number: "a number", integer: "an integer" };
|
|
350
|
+
var ARTICLE = { object: "an object", array: "an array", string: "a string", number: "a number", integer: "an integer", boolean: "a boolean" };
|
|
206
351
|
function matchesType(schema, value) {
|
|
207
352
|
switch (schema.type) {
|
|
208
353
|
case void 0:
|
|
@@ -222,6 +367,9 @@ function checkString(schema, value, path, errors) {
|
|
|
222
367
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
223
368
|
errors.push(`${path}: must be at most ${schema.maxLength} characters (got ${value.length})`);
|
|
224
369
|
}
|
|
370
|
+
if (schema.pattern !== void 0 && !new RegExp(schema.pattern).test(value)) {
|
|
371
|
+
errors.push(`${path}: has an invalid format`);
|
|
372
|
+
}
|
|
225
373
|
}
|
|
226
374
|
function checkNumber(schema, value, path, errors) {
|
|
227
375
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
@@ -244,6 +392,14 @@ function checkArray(schema, value, path, errors) {
|
|
|
244
392
|
value.forEach((item, i) => validateAgainst(itemSchema, item, `${path}[${i}]`, errors));
|
|
245
393
|
}
|
|
246
394
|
}
|
|
395
|
+
function extraSchema(schema, key) {
|
|
396
|
+
const extra = schema.additionalProperties;
|
|
397
|
+
if (typeof extra !== "object") {
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
const names = schema.propertyNames?.pattern;
|
|
401
|
+
return names === void 0 || new RegExp(names).test(key) ? extra : void 0;
|
|
402
|
+
}
|
|
247
403
|
function checkObject(schema, value, path, errors) {
|
|
248
404
|
const props = schema.properties ?? {};
|
|
249
405
|
for (const key of schema.required ?? []) {
|
|
@@ -252,9 +408,9 @@ function checkObject(schema, value, path, errors) {
|
|
|
252
408
|
}
|
|
253
409
|
}
|
|
254
410
|
for (const [key, child] of Object.entries(value)) {
|
|
255
|
-
const childSchema = Object.hasOwn(props, key) ? props[key] :
|
|
411
|
+
const childSchema = Object.hasOwn(props, key) ? props[key] : extraSchema(schema, key);
|
|
256
412
|
if (childSchema === void 0) {
|
|
257
|
-
if (schema.additionalProperties
|
|
413
|
+
if (schema.additionalProperties !== void 0 && schema.additionalProperties !== true) {
|
|
258
414
|
errors.push(`${join(path, key)}: is not allowed`);
|
|
259
415
|
}
|
|
260
416
|
} else if (child !== void 0) {
|
|
@@ -296,6 +452,13 @@ var FlierDocError = class extends Error {
|
|
|
296
452
|
this.errors = errors;
|
|
297
453
|
}
|
|
298
454
|
};
|
|
455
|
+
function sameLineTies(doc) {
|
|
456
|
+
const ties = doc.lineTies;
|
|
457
|
+
if (!Array.isArray(ties)) {
|
|
458
|
+
return [];
|
|
459
|
+
}
|
|
460
|
+
return ties.flatMap((tie2, i) => Array.isArray(tie2?.lines) && tie2.lines.length === 2 && tie2.lines[0] === tie2.lines[1] ? [i] : []);
|
|
461
|
+
}
|
|
299
462
|
function validateFlierDoc(input) {
|
|
300
463
|
if (typeName(input) !== "object") {
|
|
301
464
|
return { ok: false, errors: ["doc: must be an object"] };
|
|
@@ -306,6 +469,7 @@ function validateFlierDoc(input) {
|
|
|
306
469
|
if (doc.layout === "list" /* List */ && (doc.items === void 0 || doc.items.length === 0)) {
|
|
307
470
|
errors.push('items: layout "list" needs at least one item');
|
|
308
471
|
}
|
|
472
|
+
sameLineTies(doc).forEach((i) => errors.push(`lineTies[${i}].lines: must name two different lines`));
|
|
309
473
|
return errors.length === 0 ? { ok: true, doc } : { ok: false, errors };
|
|
310
474
|
}
|
|
311
475
|
function missingAssets(doc, assets) {
|
|
@@ -319,6 +483,92 @@ function missingAssets(doc, assets) {
|
|
|
319
483
|
return errors;
|
|
320
484
|
}
|
|
321
485
|
|
|
486
|
+
// src/render/shapes.ts
|
|
487
|
+
function polygon(ctx, pts) {
|
|
488
|
+
const first = pts[0];
|
|
489
|
+
if (!first) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
ctx.beginPath();
|
|
493
|
+
ctx.moveTo(first[0], first[1]);
|
|
494
|
+
pts.slice(1).forEach((p, i) => {
|
|
495
|
+
const next = pts[i + 2] ?? first;
|
|
496
|
+
ctx.arcTo(p[0], p[1], next[0], next[1], 0);
|
|
497
|
+
});
|
|
498
|
+
ctx.closePath();
|
|
499
|
+
ctx.fill();
|
|
500
|
+
}
|
|
501
|
+
function disc(ctx, c, r3, color) {
|
|
502
|
+
ctx.fillStyle = color;
|
|
503
|
+
ctx.beginPath();
|
|
504
|
+
ctx.arc(c[0], c[1], Math.max(0, r3), 0, Math.PI * 2);
|
|
505
|
+
ctx.fill();
|
|
506
|
+
}
|
|
507
|
+
function turnedRect(c, size, angle) {
|
|
508
|
+
const cos = Math.cos(angle);
|
|
509
|
+
const sin = Math.sin(angle);
|
|
510
|
+
const hw = size.w / 2;
|
|
511
|
+
const hh = size.h / 2;
|
|
512
|
+
const corners = [[-hw, -hh], [hw, -hh], [hw, hh], [-hw, hh]];
|
|
513
|
+
return corners.map(([px, py]) => [c[0] + px * cos - py * sin, c[1] + px * sin + py * cos]);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// src/render/brush.ts
|
|
517
|
+
var CLUSTERS = [
|
|
518
|
+
{ x: -0.14, y: 0.13, w: 0.42, h: 0.35, tone: 0 },
|
|
519
|
+
{ x: -0.16, y: 0.78, w: 0.36, h: 0.22, tone: 1 },
|
|
520
|
+
{ x: 0.78, y: 0.63, w: 0.3, h: 0.3, tone: 2 }
|
|
521
|
+
];
|
|
522
|
+
var STROKES = 7;
|
|
523
|
+
var ALPHA = 0.55;
|
|
524
|
+
var SLANT = -0.3;
|
|
525
|
+
var TAPER = 0.3;
|
|
526
|
+
var SEED = 42;
|
|
527
|
+
var PM_A = 16807;
|
|
528
|
+
var PM_M = 2147483647;
|
|
529
|
+
var JITTER = 0.3;
|
|
530
|
+
var MIN_LENGTH = 0.7;
|
|
531
|
+
var MIN_THICK = 0.6;
|
|
532
|
+
var THICK_RANGE = 0.8;
|
|
533
|
+
var HALF = 0.5;
|
|
534
|
+
function random(seed) {
|
|
535
|
+
let s = seed;
|
|
536
|
+
return () => {
|
|
537
|
+
s = s * PM_A % PM_M;
|
|
538
|
+
return s / PM_M;
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function stroke(ctx, c, length, thick) {
|
|
542
|
+
const dx = Math.cos(SLANT) * length / 2;
|
|
543
|
+
const dy = Math.sin(SLANT) * length / 2;
|
|
544
|
+
const nx = -Math.sin(SLANT);
|
|
545
|
+
const ny = Math.cos(SLANT);
|
|
546
|
+
const a = thick / 2;
|
|
547
|
+
const b = thick * TAPER / 2;
|
|
548
|
+
polygon(ctx, [
|
|
549
|
+
[c[0] - dx + nx * a, c[1] - dy + ny * a],
|
|
550
|
+
[c[0] + dx + nx * b, c[1] + dy + ny * b],
|
|
551
|
+
[c[0] + dx - nx * b, c[1] + dy - ny * b],
|
|
552
|
+
[c[0] - dx - nx * a, c[1] - dy - ny * a]
|
|
553
|
+
]);
|
|
554
|
+
}
|
|
555
|
+
function paintBrush(ctx, picture, colors) {
|
|
556
|
+
if (colors.length === 0) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const next = random(SEED);
|
|
560
|
+
ctx.globalAlpha = ALPHA;
|
|
561
|
+
CLUSTERS.forEach((cl) => {
|
|
562
|
+
ctx.fillStyle = colors[cl.tone % colors.length] ?? colors[0] ?? "";
|
|
563
|
+
const box = { x: picture.x + picture.w * cl.x, y: picture.y + picture.h * cl.y, w: picture.w * cl.w, h: picture.h * cl.h };
|
|
564
|
+
for (let i = 0; i < STROKES; i++) {
|
|
565
|
+
const c = [box.x + box.w * (HALF + (next() - HALF) * JITTER), box.y + box.h * (i + HALF) / STROKES];
|
|
566
|
+
stroke(ctx, c, box.w * (MIN_LENGTH + (1 - MIN_LENGTH) * next()), box.h / STROKES * (MIN_THICK + THICK_RANGE * next()));
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
ctx.globalAlpha = 1;
|
|
570
|
+
}
|
|
571
|
+
|
|
322
572
|
// src/render/background.ts
|
|
323
573
|
function paintGround(ctx, style, palette, size) {
|
|
324
574
|
ctx.fillStyle = palette.background;
|
|
@@ -330,6 +580,17 @@ function paintGround(ctx, style, palette, size) {
|
|
|
330
580
|
}
|
|
331
581
|
ctx.fillRect(0, 0, size.width, size.height);
|
|
332
582
|
}
|
|
583
|
+
function paintPage(ctx, doc, palette, page) {
|
|
584
|
+
ctx.globalAlpha = 1;
|
|
585
|
+
paintGround(ctx, doc.background, palette, page);
|
|
586
|
+
if (doc.background === "tint" /* Tint */) {
|
|
587
|
+
ctx.fillStyle = palette.tint;
|
|
588
|
+
[page.geo.header, page.geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
|
|
589
|
+
}
|
|
590
|
+
if (doc.background === "brush" /* Brush */ && page.picture) {
|
|
591
|
+
paintBrush(ctx, page.picture, palette.brush ?? [palette.tint, palette.arch]);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
333
594
|
|
|
334
595
|
// src/layout/layoutSpecs.ts
|
|
335
596
|
var flanksBeside = (pic, top, bottom2, m) => [
|
|
@@ -485,6 +746,47 @@ function placeContain(image, region, fit) {
|
|
|
485
746
|
};
|
|
486
747
|
}
|
|
487
748
|
|
|
749
|
+
// src/layout/lineStyle.ts
|
|
750
|
+
function tieIds(ties, kind) {
|
|
751
|
+
const ids = /* @__PURE__ */ new Map();
|
|
752
|
+
ties.filter((t) => t.kind === kind).forEach((t, n) => {
|
|
753
|
+
const [a, b] = t.lines;
|
|
754
|
+
const ia = ids.get(a);
|
|
755
|
+
const ib = ids.get(b);
|
|
756
|
+
const id = ia ?? ib ?? n;
|
|
757
|
+
ids.set(a, id);
|
|
758
|
+
ids.set(b, id);
|
|
759
|
+
if (ib !== void 0 && ib !== id) {
|
|
760
|
+
[...ids.entries()].filter(([, v]) => v === ib).forEach(([key]) => ids.set(key, id));
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
return ids;
|
|
764
|
+
}
|
|
765
|
+
function styleContext(doc) {
|
|
766
|
+
const ties = doc.lineTies ?? [];
|
|
767
|
+
return { styles: doc.lineStyles ?? {}, width: tieIds(ties, "width" /* Width */), size: tieIds(ties, "size" /* Size */) };
|
|
768
|
+
}
|
|
769
|
+
function styled(line, key, sc) {
|
|
770
|
+
const style = Object.hasOwn(sc.styles, key) ? sc.styles[key] : void 0;
|
|
771
|
+
const widthTie = sc.width.get(key);
|
|
772
|
+
const sizeTie = sc.size.get(key);
|
|
773
|
+
if (style === void 0 && widthTie === void 0 && sizeTie === void 0) {
|
|
774
|
+
return line;
|
|
775
|
+
}
|
|
776
|
+
return {
|
|
777
|
+
...line,
|
|
778
|
+
size: line.size * (style?.sizeScale ?? 1),
|
|
779
|
+
color: style?.color ?? line.color,
|
|
780
|
+
weight: style?.weight ?? line.weight,
|
|
781
|
+
family: style?.font,
|
|
782
|
+
italic: style?.italic,
|
|
783
|
+
spacing: style?.letterSpacing,
|
|
784
|
+
align: style?.align,
|
|
785
|
+
widthTie,
|
|
786
|
+
sizeTie
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
488
790
|
// src/layout/blockGroups.ts
|
|
489
791
|
var BOLD = 700;
|
|
490
792
|
var SEMI = 600;
|
|
@@ -511,32 +813,51 @@ var GAP = {
|
|
|
511
813
|
row: 30,
|
|
512
814
|
venue: 40,
|
|
513
815
|
includes: 24,
|
|
514
|
-
rule: 8
|
|
816
|
+
rule: 8,
|
|
817
|
+
divider: 24
|
|
515
818
|
};
|
|
516
|
-
var makers = (p, u) => ({
|
|
517
|
-
display: (text2, size) => ({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }),
|
|
518
|
-
venue: (text2, size) => ({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }),
|
|
519
|
-
script: (text2, size) => ({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.accent }),
|
|
520
|
-
strong: (text2, size) => ({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }),
|
|
521
|
-
accent: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }),
|
|
522
|
-
item: (text2, size) => ({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }),
|
|
523
|
-
soft: (text2, size) => ({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft })
|
|
819
|
+
var makers = (p, u, sc) => ({
|
|
820
|
+
display: (text2, size, key) => styled({ text: text2, role: "display", weight: BOLD, size: size * u, color: p.title }, key, sc),
|
|
821
|
+
venue: (text2, size, key) => styled({ text: text2, role: "display", weight: MEDIUM, size: size * u, color: p.ink }, key, sc),
|
|
822
|
+
script: (text2, size, key) => styled({ text: text2, role: "script", weight: SCRIPT, size: size * u, color: p.script ?? p.accent }, key, sc),
|
|
823
|
+
strong: (text2, size, key) => styled({ text: text2, role: "body", weight: BOLD, size: size * u, color: p.ink }, key, sc),
|
|
824
|
+
accent: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.accent }, key, sc),
|
|
825
|
+
item: (text2, size, key) => styled({ text: text2, role: "body", weight: SEMI, size: size * u, color: p.ink, bullet: p.accent }, key, sc),
|
|
826
|
+
soft: (text2, size, key) => styled({ text: text2, role: "body", weight: MEDIUM, size: size * u, color: p.soft }, key, sc)
|
|
524
827
|
});
|
|
525
828
|
function headerGroups(doc, p, u) {
|
|
526
|
-
const l = makers(p, u);
|
|
829
|
+
const l = makers(p, u, styleContext(doc));
|
|
527
830
|
const b = doc.blocks;
|
|
528
|
-
const
|
|
831
|
+
const t = doc.tuning;
|
|
832
|
+
const gap = (line, after) => after === void 0 ? line : { ...line, gapAfter: after * u };
|
|
833
|
+
const title = gap(l.display(b.title, SIZE.title * (t?.titleScale ?? 1), "title"), b.script ?? b.titleBottom ? t?.titleScriptGap : void 0);
|
|
834
|
+
const script = b.script ? gap(l.script(b.script, SIZE.headerScript, "script"), b.titleBottom ? t?.scriptTitleGap : void 0) : void 0;
|
|
835
|
+
const lines = [title, script, b.titleBottom ? l.display(b.titleBottom, SIZE.title * (t?.titleBottomScale ?? 1), "titleBottom") : void 0];
|
|
529
836
|
return [{ lines: lines.filter((x) => x !== void 0), gapAfter: 0 }];
|
|
530
837
|
}
|
|
531
|
-
function itemGroup(item,
|
|
532
|
-
const
|
|
533
|
-
|
|
838
|
+
function itemGroup(item, n, l, scale) {
|
|
839
|
+
const { u, dateScale } = scale;
|
|
840
|
+
const lines = [l.script(item.date, SIZE.itemDate * dateScale, `items.${n}.date`)];
|
|
841
|
+
item.schedule.forEach((row, m) => lines.push(l.strong(`${row.label} ${row.time}`, SIZE.itemRow, `items.${n}.schedule.${m}`)));
|
|
534
842
|
if (item.price) {
|
|
535
|
-
lines.push(l.accent(item.price, SIZE.itemRow));
|
|
843
|
+
lines.push(l.accent(item.price, SIZE.itemRow, `items.${n}.price`));
|
|
536
844
|
}
|
|
537
845
|
return { lines, gapAfter: GAP.item * u };
|
|
538
846
|
}
|
|
539
847
|
var WRAP_FROM = 14;
|
|
848
|
+
function dividerOf(doc, p, u) {
|
|
849
|
+
const d = doc.rows?.dividers;
|
|
850
|
+
return d === void 0 ? void 0 : { color: d.color ?? p.rule ?? p.accent, height: d.thickness * u, gap: (d.gap ?? GAP.divider) * u };
|
|
851
|
+
}
|
|
852
|
+
function rowMarks(doc, p, u) {
|
|
853
|
+
const divider = dividerOf(doc, p, u);
|
|
854
|
+
const size = doc.rows?.icons?.size;
|
|
855
|
+
return (icons2, i, last) => {
|
|
856
|
+
const kind = icons2 === void 0 || icons2.length === 0 ? void 0 : icons2[Math.min(i, icons2.length - 1)];
|
|
857
|
+
const icon = kind === void 0 ? {} : { icon: { color: p.icon ?? p.accent, glyph: p.background, kind, size: size === void 0 ? void 0 : size * u } };
|
|
858
|
+
return { ...icon, ...divider === void 0 || last ? {} : { rule: divider, ruleBelow: true, ruleAbove: false } };
|
|
859
|
+
};
|
|
860
|
+
}
|
|
540
861
|
function halves(text2) {
|
|
541
862
|
const mid = text2.length / 2;
|
|
542
863
|
const spaces = [...text2].flatMap((c, i) => c === " " ? [i] : []);
|
|
@@ -554,80 +875,149 @@ function eventGroups(doc, l, u, options) {
|
|
|
554
875
|
const b = doc.blocks;
|
|
555
876
|
const groups = [];
|
|
556
877
|
const schedule2 = b.schedule ?? [];
|
|
878
|
+
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
879
|
+
const lastRow = schedule2.length + prices.length - 1;
|
|
880
|
+
const icons2 = doc.rows?.icons;
|
|
557
881
|
schedule2.forEach((row, i) => {
|
|
558
|
-
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel)] : [l.strong(row.label, SIZE.scheduleLabel), l.accent(row.time, SIZE.scheduleTime)];
|
|
559
|
-
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1 });
|
|
882
|
+
const lines = options.compact ? [l.strong(`${row.label} ${row.time}`, SIZE.scheduleLabel, `schedule.${i}.label`)] : [l.strong(row.label, SIZE.scheduleLabel, `schedule.${i}.label`), l.accent(row.time, SIZE.scheduleTime, `schedule.${i}.time`)];
|
|
883
|
+
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < schedule2.length - 1, ...options.marks(icons2?.schedule, i, i === lastRow) });
|
|
560
884
|
});
|
|
561
|
-
const prices = (options.withPrices === false ? void 0 : b.prices) ?? [];
|
|
562
885
|
prices.forEach((row, i) => {
|
|
563
|
-
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount)] : [l.strong(row.amount, SIZE.priceAmount), l.accent(row.label, SIZE.priceLabel)];
|
|
564
|
-
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1 });
|
|
886
|
+
const lines = options.compact ? [l.strong(`${row.amount} ${row.label}`, SIZE.priceAmount, `prices.${i}.amount`)] : [l.strong(row.amount, SIZE.priceAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.priceLabel, `prices.${i}.label`)];
|
|
887
|
+
groups.push({ lines, gapAfter: GAP.row * u, keepWithNext: i < prices.length - 1, ...options.marks(icons2?.prices, i, schedule2.length + i === lastRow) });
|
|
565
888
|
});
|
|
566
889
|
return groups;
|
|
567
890
|
}
|
|
568
891
|
function listGroups(doc, l, u, dateScale) {
|
|
569
|
-
const groups = (doc.items ?? []).map((item) => itemGroup(item, l, u, dateScale));
|
|
570
|
-
const prices = doc.blocks.prices?.map((row) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice)) ?? [];
|
|
892
|
+
const groups = (doc.items ?? []).map((item, n) => itemGroup(item, n, l, { u, dateScale }));
|
|
893
|
+
const prices = doc.blocks.prices?.map((row, i) => l.strong(`${row.amount} ${row.label}`, SIZE.listPrice, `prices.${i}.amount`)) ?? [];
|
|
571
894
|
if (prices.length > 0) {
|
|
572
895
|
groups.push({ lines: prices, gapAfter: GAP.row * u });
|
|
573
896
|
}
|
|
574
897
|
return groups;
|
|
575
898
|
}
|
|
576
899
|
function flankPriceGroups(doc, p, u) {
|
|
577
|
-
const l = makers(p, u);
|
|
578
|
-
return (doc.blocks.prices ?? []).map((row) => ({ lines: [l.strong(row.amount, SIZE.flankAmount), l.accent(row.label, SIZE.flankLabel)], gapAfter: GAP.row * u }));
|
|
900
|
+
const l = makers(p, u, styleContext(doc));
|
|
901
|
+
return (doc.blocks.prices ?? []).map((row, i) => ({ lines: [l.strong(row.amount, SIZE.flankAmount, `prices.${i}.amount`), l.accent(row.label, SIZE.flankLabel, `prices.${i}.label`)], gapAfter: GAP.row * u }));
|
|
579
902
|
}
|
|
580
903
|
function bodyGroups(doc, p, u, options = {}) {
|
|
581
|
-
const l = makers(p, u);
|
|
904
|
+
const l = makers(p, u, styleContext(doc));
|
|
582
905
|
const b = doc.blocks;
|
|
583
906
|
const groups = [];
|
|
584
907
|
const isList = doc.layout === "list" /* List */;
|
|
585
908
|
if (b.venue) {
|
|
586
909
|
const size = isList ? SIZE.listVenue : SIZE.venue;
|
|
587
910
|
const keepWithNext = !isList && (b.schedule?.length ?? 0) > 0;
|
|
588
|
-
groups.push({ lines: b.venue.map((v) => l.venue(v, size)), gapAfter: GAP.venue * u, rule: { color: p.accent, height: GAP.rule * u }, ruleBelow: true, icon: { color: p.accent, glyph: p.background }, keepWithNext });
|
|
911
|
+
groups.push({ lines: b.venue.map((v, i) => l.venue(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 }, keepWithNext });
|
|
589
912
|
}
|
|
590
|
-
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, options));
|
|
913
|
+
groups.push(...isList ? listGroups(doc, l, u, options.dateScale ?? 1) : eventGroups(doc, l, u, { ...options, marks: rowMarks(doc, p, u) }));
|
|
591
914
|
if (b.includes) {
|
|
592
|
-
const lines = [l.accent(b.includes.heading, SIZE.small), ...b.includes.items.map((i) => l.item(
|
|
915
|
+
const lines = [l.accent(b.includes.heading, SIZE.small, "includes.heading"), ...b.includes.items.map((item, i) => l.item(item, SIZE.small, `includes.items.${i}`))].flatMap((line) => wrapped(line, options.wrap));
|
|
593
916
|
groups.push({ lines, gapAfter: GAP.includes * u, uniform: true, keepWithNext: b.footer !== void 0, attachNext: b.footer !== void 0 });
|
|
594
917
|
}
|
|
595
918
|
if (b.footer) {
|
|
596
|
-
groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small), options.wrap), gapAfter: 0 });
|
|
919
|
+
groups.push({ lines: wrapped(l.soft(b.footer, SIZE.small, "footer"), options.wrap), gapAfter: 0 });
|
|
597
920
|
}
|
|
598
921
|
return groups;
|
|
599
922
|
}
|
|
600
923
|
|
|
601
|
-
// src/layout/
|
|
924
|
+
// src/layout/lineSizes.ts
|
|
602
925
|
var LINE_HEIGHT = 1.2;
|
|
603
926
|
var BULLET_INDENT = 1.1;
|
|
604
|
-
var BULLET_RADIUS = 0.2;
|
|
605
|
-
var RULE_GAP = 2.5;
|
|
606
|
-
var RULE_WIDTH = 0.9;
|
|
607
|
-
var WIDE = 1.6;
|
|
608
|
-
var COLUMN_GAP = 0.04;
|
|
609
|
-
var TWO_COLUMN_MIN = 0.75;
|
|
610
|
-
var TWO_COLUMN_GAIN = 1.15;
|
|
611
|
-
var MIN_K = 0.02;
|
|
612
|
-
var STEPS = 22;
|
|
613
927
|
var ICON_SCALE = 1.6;
|
|
614
928
|
var ICON_GAP = 0.35;
|
|
615
|
-
var fontOf = (line, size, fonts) => `${line.weight} ${size}px ${fonts[line.role]}`;
|
|
616
|
-
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
617
929
|
var indented = (line) => line.bullet !== void 0 || line.hang === true;
|
|
930
|
+
var bulletIndent = (line, k) => indented(line) ? line.size * k * BULLET_INDENT : 0;
|
|
618
931
|
var iconSize = (group, k) => {
|
|
619
932
|
const first = group.lines[0];
|
|
933
|
+
if (group.icon?.size !== void 0) {
|
|
934
|
+
return group.icon.size * k;
|
|
935
|
+
}
|
|
620
936
|
return group.icon && first ? first.size * k * LINE_HEIGHT * ICON_SCALE : 0;
|
|
621
937
|
};
|
|
938
|
+
function groupBox(group, k, colW) {
|
|
939
|
+
const pad = group.card ? group.card.pad * k : 0;
|
|
940
|
+
const d = iconSize(group, k);
|
|
941
|
+
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
942
|
+
return { pad, d, iconIndent, avail: colW - 2 * pad - iconIndent };
|
|
943
|
+
}
|
|
622
944
|
function lineSize(line, width, k, avail) {
|
|
623
|
-
const indent =
|
|
945
|
+
const indent = bulletIndent(line, k);
|
|
624
946
|
return Math.max(0, Math.min(line.size * k, line.size * (avail - indent) / Math.max(width, 1)));
|
|
625
947
|
}
|
|
626
|
-
function
|
|
948
|
+
function groupSizes(m, k, avail) {
|
|
949
|
+
const own = m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail));
|
|
627
950
|
if (!m.group.uniform) {
|
|
628
|
-
return
|
|
951
|
+
return own;
|
|
952
|
+
}
|
|
953
|
+
const ratio = Math.min(...m.group.lines.map((line, i) => (own[i] ?? 0) / line.size));
|
|
954
|
+
return m.group.lines.map((line) => line.size * ratio);
|
|
955
|
+
}
|
|
956
|
+
function tieMembers(all, k, colW, table, pick) {
|
|
957
|
+
const byId = /* @__PURE__ */ new Map();
|
|
958
|
+
all.forEach((m) => {
|
|
959
|
+
const { avail } = groupBox(m.group, k, colW);
|
|
960
|
+
const sizes = table.get(m) ?? [];
|
|
961
|
+
m.group.lines.forEach((line, i) => {
|
|
962
|
+
const id = pick(line);
|
|
963
|
+
if (id !== void 0) {
|
|
964
|
+
const member = { line, width: Math.max(m.widths[i] ?? 1, 1), cap: Math.max(0, avail - bulletIndent(line, k)), sizes, i };
|
|
965
|
+
byId.set(id, [...byId.get(id) ?? [], member]);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
});
|
|
969
|
+
return [...byId.values()].filter((list) => list.length > 1);
|
|
970
|
+
}
|
|
971
|
+
function sameSizes(list) {
|
|
972
|
+
const target = Math.min(Math.max(...list.map((x) => x.sizes[x.i] ?? 0)), ...list.map((x) => x.line.size * x.cap / x.width));
|
|
973
|
+
list.forEach((x) => {
|
|
974
|
+
x.sizes[x.i] = target;
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
function sameWidths(list) {
|
|
978
|
+
const drawn = list.map((x) => x.width * (x.sizes[x.i] ?? 0) / x.line.size);
|
|
979
|
+
const target = Math.min(Math.max(...drawn), ...list.map((x) => x.cap));
|
|
980
|
+
list.forEach((x) => {
|
|
981
|
+
x.sizes[x.i] = target * x.line.size / x.width;
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
function sizeTable(all, k, colW) {
|
|
985
|
+
const table = new Map(all.map((m) => [m, groupSizes(m, k, groupBox(m.group, k, colW).avail)]));
|
|
986
|
+
tieMembers(all, k, colW, table, (line) => line.sizeTie).forEach(sameSizes);
|
|
987
|
+
tieMembers(all, k, colW, table, (line) => line.widthTie).forEach(sameWidths);
|
|
988
|
+
return table;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// src/layout/textFlow.ts
|
|
992
|
+
var BULLET_RADIUS = 0.2;
|
|
993
|
+
var RULE_GAP = 2.5;
|
|
994
|
+
var RULE_WIDTH = 0.9;
|
|
995
|
+
var WIDE = 1.6;
|
|
996
|
+
var COLUMN_GAP = 0.04;
|
|
997
|
+
var TWO_COLUMN_MIN = 0.75;
|
|
998
|
+
var TWO_COLUMN_GAIN = 1.15;
|
|
999
|
+
var MIN_K = 0.02;
|
|
1000
|
+
var STEPS = 22;
|
|
1001
|
+
var NO_SPACING = "0px";
|
|
1002
|
+
var fontOf = (line, size, fonts) => {
|
|
1003
|
+
const family = line.family === void 0 ? fonts[line.role] : `"${line.family}", ${fonts[line.role]}`;
|
|
1004
|
+
return `${line.italic === true ? "italic " : ""}${line.weight} ${size}px ${family}`;
|
|
1005
|
+
};
|
|
1006
|
+
var emptyFlow = () => ({ texts: [], cards: [], rules: [], bullets: [], icons: [] });
|
|
1007
|
+
function lineX(line, box) {
|
|
1008
|
+
const { col, pad, indent, w } = box;
|
|
1009
|
+
const left = col.x + pad + indent;
|
|
1010
|
+
const right = col.x + col.w - pad - w;
|
|
1011
|
+
switch (line.align) {
|
|
1012
|
+
case "left" /* Left */:
|
|
1013
|
+
return left;
|
|
1014
|
+
case "right" /* Right */:
|
|
1015
|
+
return right;
|
|
1016
|
+
case "center" /* Center */:
|
|
1017
|
+
return left + (right - left) / 2;
|
|
1018
|
+
default:
|
|
1019
|
+
return col.right ? right : left;
|
|
629
1020
|
}
|
|
630
|
-
return Math.min(...m.group.lines.map((line, i) => lineSize(line, m.widths[i] ?? 1, k, avail) / line.size));
|
|
631
1021
|
}
|
|
632
1022
|
function placeIcon(group, box, out) {
|
|
633
1023
|
const { d, x, top, bottom: bottom2 } = box;
|
|
@@ -635,39 +1025,35 @@ function placeIcon(group, box, out) {
|
|
|
635
1025
|
return bottom2;
|
|
636
1026
|
}
|
|
637
1027
|
const textH = bottom2 - top;
|
|
638
|
-
out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph });
|
|
1028
|
+
out?.icons.push({ rect: { x, y: top + Math.max(0, (textH - d) / 2), w: d, h: d }, color: group.icon.color, glyph: group.icon.glyph, kind: group.icon.kind });
|
|
639
1029
|
return top + Math.max(textH, d);
|
|
640
1030
|
}
|
|
641
1031
|
function placeGroup(m, at, out) {
|
|
642
|
-
const { k, col, y0 } = at;
|
|
1032
|
+
const { k, col, y0, sizes } = at;
|
|
643
1033
|
const { group } = m;
|
|
644
1034
|
let y = y0;
|
|
645
|
-
if (group.rule) {
|
|
1035
|
+
if (group.rule && group.ruleAbove !== false) {
|
|
646
1036
|
out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
|
|
647
|
-
y += group.rule.height * k * RULE_GAP;
|
|
1037
|
+
y += group.rule.gap === void 0 ? group.rule.height * k * RULE_GAP : (group.rule.height + group.rule.gap) * k;
|
|
648
1038
|
}
|
|
649
|
-
const pad
|
|
1039
|
+
const { pad, d, iconIndent } = groupBox(group, k, col.w);
|
|
650
1040
|
const top = y;
|
|
651
1041
|
y += pad;
|
|
652
|
-
const d = iconSize(group, k);
|
|
653
|
-
const iconIndent = d > 0 ? d * (1 + ICON_GAP) : 0;
|
|
654
|
-
const avail = col.w - 2 * pad - iconIndent;
|
|
655
|
-
const ratio = groupRatio(m, k, avail);
|
|
656
1042
|
group.lines.forEach((line, i) => {
|
|
657
|
-
const size =
|
|
1043
|
+
const size = sizes[i] ?? 0;
|
|
658
1044
|
const indent = (indented(line) ? line.size * k * BULLET_INDENT : 0) + iconIndent;
|
|
659
1045
|
const w = (m.widths[i] ?? 0) * size / line.size;
|
|
660
|
-
const x =
|
|
1046
|
+
const x = lineX(line, { col, pad, indent, w });
|
|
661
1047
|
out?.texts.push({ text: line.text, font: "", color: line.color, box: { x, y, w, h: size * LINE_HEIGHT } });
|
|
662
1048
|
if (line.bullet && out) {
|
|
663
1049
|
out.bullets.push({ x: col.x + pad + size * BULLET_RADIUS, y: y + size * LINE_HEIGHT / 2, r: size * BULLET_RADIUS, color: line.bullet });
|
|
664
1050
|
}
|
|
665
|
-
y += size * LINE_HEIGHT;
|
|
1051
|
+
y += size * LINE_HEIGHT + (line.gapAfter ?? 0) * k;
|
|
666
1052
|
});
|
|
667
1053
|
y = placeIcon(group, { d, x: col.x + pad, top: top + pad, bottom: y }, out);
|
|
668
1054
|
y += pad;
|
|
669
1055
|
if (group.rule && group.ruleBelow) {
|
|
670
|
-
y += group.rule.height * k * (RULE_GAP - 1);
|
|
1056
|
+
y += group.rule.gap === void 0 ? group.rule.height * k * (RULE_GAP - 1) : group.rule.gap * k;
|
|
671
1057
|
out?.rules.push({ rect: { x: col.x, y, w: col.w * RULE_WIDTH, h: group.rule.height * k }, color: group.rule.color });
|
|
672
1058
|
y += group.rule.height * k;
|
|
673
1059
|
}
|
|
@@ -677,10 +1063,10 @@ function placeGroup(m, at, out) {
|
|
|
677
1063
|
return y + group.gapAfter * k - y0;
|
|
678
1064
|
}
|
|
679
1065
|
function placeColumn(groups, at, out) {
|
|
680
|
-
const { k, col, spread = 0 } = at;
|
|
1066
|
+
const { k, col, table, spread = 0 } = at;
|
|
681
1067
|
let h = 0;
|
|
682
1068
|
groups.forEach((g, i) => {
|
|
683
|
-
h += placeGroup(g, { k, col, y0: col.y + h }, out);
|
|
1069
|
+
h += placeGroup(g, { k, col, y0: col.y + h, sizes: table.get(g) ?? [] }, out);
|
|
684
1070
|
if (i < groups.length - 1 && g.group.attachNext !== true) {
|
|
685
1071
|
h += spread;
|
|
686
1072
|
}
|
|
@@ -713,7 +1099,8 @@ function keepTogether(groups, heights, cut) {
|
|
|
713
1099
|
function splitColumns(groups, zone) {
|
|
714
1100
|
const gap = Math.round(zone.w * COLUMN_GAP);
|
|
715
1101
|
const w = (zone.w - gap) / 2;
|
|
716
|
-
const
|
|
1102
|
+
const table = sizeTable(groups, 1, w);
|
|
1103
|
+
const heights = groups.map((g) => placeGroup(g, { k: 1, col: { ...zone, w }, y0: 0, sizes: table.get(g) ?? [] }, null));
|
|
717
1104
|
const total = columnSum(heights, 0, heights.length);
|
|
718
1105
|
let cut = 1;
|
|
719
1106
|
for (let c = 2; c < groups.length; c++) {
|
|
@@ -727,8 +1114,12 @@ function splitColumns(groups, zone) {
|
|
|
727
1114
|
{ col: { ...zone, x: zone.x + w + gap, w }, groups: groups.slice(cut) }
|
|
728
1115
|
];
|
|
729
1116
|
}
|
|
1117
|
+
var tableFor = (columns, k) => sizeTable(columns.flatMap((c) => c.groups), k, columns[0]?.col.w ?? 0);
|
|
730
1118
|
function largestK(columns, zoneH) {
|
|
731
|
-
const fits = (k) =>
|
|
1119
|
+
const fits = (k) => {
|
|
1120
|
+
const table = tableFor(columns, k);
|
|
1121
|
+
return columns.every((c) => placeColumn(c.groups, { k, col: c.col, table }, null) <= zoneH);
|
|
1122
|
+
};
|
|
732
1123
|
let lo = MIN_K;
|
|
733
1124
|
let hi = 1;
|
|
734
1125
|
if (fits(1)) {
|
|
@@ -755,26 +1146,37 @@ function bestColumns(measured, zone) {
|
|
|
755
1146
|
const forced = zone.w / Math.max(zone.h, 1) > WIDE;
|
|
756
1147
|
return forced || k2 > k1 * TWO_COLUMN_GAIN ? { columns: split, k: k2 } : { columns: single, k: k1 };
|
|
757
1148
|
}
|
|
1149
|
+
function measure(ctx, line, fonts) {
|
|
1150
|
+
ctx.font = fontOf(line, line.size, fonts);
|
|
1151
|
+
if (line.spacing === void 0) {
|
|
1152
|
+
return ctx.measureText(line.text).width;
|
|
1153
|
+
}
|
|
1154
|
+
ctx.letterSpacing = `${line.spacing * line.size}px`;
|
|
1155
|
+
const width = ctx.measureText(line.text).width;
|
|
1156
|
+
ctx.letterSpacing = NO_SPACING;
|
|
1157
|
+
return width;
|
|
1158
|
+
}
|
|
758
1159
|
function flow(ctx, groups, zone, fonts) {
|
|
759
1160
|
const measured = groups.map((group) => ({
|
|
760
1161
|
group,
|
|
761
|
-
widths: group.lines.map((line) =>
|
|
762
|
-
ctx.font = fontOf(line, line.size, fonts);
|
|
763
|
-
return ctx.measureText(line.text).width;
|
|
764
|
-
})
|
|
1162
|
+
widths: group.lines.map((line) => measure(ctx, line, fonts))
|
|
765
1163
|
}));
|
|
766
1164
|
const { columns, k: lo } = bestColumns(measured, zone);
|
|
767
1165
|
const out = emptyFlow();
|
|
768
|
-
const
|
|
1166
|
+
const table = tableFor(columns, lo);
|
|
1167
|
+
const heights = columns.map((c) => placeColumn(c.groups, { k: lo, col: c.col, table }, null));
|
|
769
1168
|
const end = Math.max(...heights);
|
|
770
1169
|
columns.forEach((c, i) => {
|
|
771
1170
|
const gaps = spreadGaps(c.groups);
|
|
772
|
-
placeColumn(c.groups, { k: lo, col: c.col, spread: gaps > 0 && columns.length > 1 ? (end - (heights[i] ?? end)) / gaps : 0 }, out);
|
|
1171
|
+
placeColumn(c.groups, { k: lo, col: c.col, table, spread: gaps > 0 && columns.length > 1 ? (end - (heights[i] ?? end)) / gaps : 0 }, out);
|
|
773
1172
|
});
|
|
774
1173
|
const lines = groups.flatMap((g) => g.lines);
|
|
775
1174
|
out.texts.forEach((t, i) => {
|
|
776
1175
|
const line = lines[i];
|
|
777
1176
|
t.font = line ? fontOf(line, t.box.h / LINE_HEIGHT, fonts) : t.font;
|
|
1177
|
+
if (line?.spacing !== void 0) {
|
|
1178
|
+
t.spacing = `${line.spacing * (t.box.h / LINE_HEIGHT)}px`;
|
|
1179
|
+
}
|
|
778
1180
|
});
|
|
779
1181
|
return out;
|
|
780
1182
|
}
|
|
@@ -829,6 +1231,13 @@ function splitHeader(header, hasLogo) {
|
|
|
829
1231
|
const logoW = hasLogo ? Math.round(header.w * LOGO_SHARE) : 0;
|
|
830
1232
|
return { text: { ...header, w: header.w - logoW * 1.1 }, logo: { ...header, x: header.x + header.w - logoW, w: logoW } };
|
|
831
1233
|
}
|
|
1234
|
+
function headerAt(zones, top, u) {
|
|
1235
|
+
if (top === void 0) {
|
|
1236
|
+
return zones;
|
|
1237
|
+
}
|
|
1238
|
+
const y = Math.round(top * u);
|
|
1239
|
+
return { ...zones, text: { ...zones.text, y, h: Math.max(1, zones.text.y + zones.text.h - y) } };
|
|
1240
|
+
}
|
|
832
1241
|
function closeHeaderGap(geo, head, gap, u) {
|
|
833
1242
|
const { header, body } = geo;
|
|
834
1243
|
const stacked = header.y + header.h <= body.y && header.x < body.x + body.w && body.x < header.x + header.w;
|
|
@@ -841,7 +1250,7 @@ function closeHeaderGap(geo, head, gap, u) {
|
|
|
841
1250
|
function flowAll(ctx, input, geo, reflow) {
|
|
842
1251
|
const { doc, palette, fonts } = input;
|
|
843
1252
|
const u = Math.min(input.width, input.height) / BASE;
|
|
844
|
-
const zones = geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0);
|
|
1253
|
+
const zones = headerAt(geo.logo ? { text: geo.header, logo: geo.logo } : splitHeader(geo.header, doc.logo !== void 0), doc.tuning?.headerTop, u);
|
|
845
1254
|
const head = flow(ctx, headerGroups(doc, palette, u), zones.text, fonts);
|
|
846
1255
|
const flanks = geo.flanks ?? [];
|
|
847
1256
|
const tight = closeHeaderGap(geo, head, doc.tuning?.headerGap, u);
|
|
@@ -915,8 +1324,90 @@ function fitToFloor(ctx, input) {
|
|
|
915
1324
|
return best ?? flowAll(ctx, input, base2, { compact: false, wrap: false});
|
|
916
1325
|
}
|
|
917
1326
|
|
|
1327
|
+
// src/render/overlap.ts
|
|
1328
|
+
var clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
|
|
1329
|
+
function placePicture(image, region, slot, fit) {
|
|
1330
|
+
const base2 = placeContain(image, region, { anchor: slot.anchor, alignX: fit.alignX, scale: slot.scale });
|
|
1331
|
+
const o = slot.overlap;
|
|
1332
|
+
if (o === void 0) {
|
|
1333
|
+
return base2;
|
|
1334
|
+
}
|
|
1335
|
+
const { width, height } = fit.frame;
|
|
1336
|
+
const s = Math.min(o.scale, width / Math.max(base2.w, 1), height / Math.max(base2.h, 1));
|
|
1337
|
+
const w = Math.floor(base2.w * s);
|
|
1338
|
+
const h = Math.floor(base2.h * s);
|
|
1339
|
+
const x = base2.x + (base2.w - w) * fit.alignX + o.dx * width;
|
|
1340
|
+
const y = base2.y + (base2.h - h) * ANCHOR_Y[slot.anchor] + o.dy * height;
|
|
1341
|
+
return { x: Math.round(clamp(x, 0, width - w)), y: Math.round(clamp(y, 0, height - h)), w, h };
|
|
1342
|
+
}
|
|
1343
|
+
function reachPicture(rules, picture, reach) {
|
|
1344
|
+
const end = picture.x + picture.w * reach;
|
|
1345
|
+
rules.filter((r3) => r3.rect.y >= picture.y && r3.rect.y <= picture.y + picture.h).forEach((r3) => {
|
|
1346
|
+
r3.rect.w = Math.max(0, end - r3.rect.x);
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// src/render/rowIcons.ts
|
|
1351
|
+
var LINE2 = 0.03;
|
|
1352
|
+
var HEAD_Y = -0.15;
|
|
1353
|
+
var HEAD_R = 0.1;
|
|
1354
|
+
var BODY_Y = 0.25;
|
|
1355
|
+
var BODY_R = 0.2;
|
|
1356
|
+
var BACK_DX = 0.12;
|
|
1357
|
+
var BACK_DY = -0.04;
|
|
1358
|
+
var FRONT_DX = -0.08;
|
|
1359
|
+
var PAIR_SCALE = 0.85;
|
|
1360
|
+
var TICKET_W = 0.52;
|
|
1361
|
+
var TICKET_H = 0.3;
|
|
1362
|
+
var TICKET_TURN = -Math.PI / 4;
|
|
1363
|
+
var PERFORATION = 0.14;
|
|
1364
|
+
var DOTS = [-0.3, 0, 0.3];
|
|
1365
|
+
var DOT = 0.035;
|
|
1366
|
+
function halfDisc(ctx, c, r3, color) {
|
|
1367
|
+
ctx.fillStyle = color;
|
|
1368
|
+
ctx.beginPath();
|
|
1369
|
+
ctx.arc(c[0], c[1], Math.max(0, r3), Math.PI, Math.PI * 2);
|
|
1370
|
+
ctx.closePath();
|
|
1371
|
+
ctx.fill();
|
|
1372
|
+
}
|
|
1373
|
+
function person(ctx, c, d, colors) {
|
|
1374
|
+
const w = d * LINE2;
|
|
1375
|
+
const head = [c[0], c[1] + d * HEAD_Y];
|
|
1376
|
+
disc(ctx, head, d * HEAD_R, colors.glyph);
|
|
1377
|
+
disc(ctx, head, d * HEAD_R - w, colors.fill);
|
|
1378
|
+
halfDisc(ctx, [c[0], c[1] + d * BODY_Y], d * BODY_R, colors.glyph);
|
|
1379
|
+
halfDisc(ctx, [c[0], c[1] + d * BODY_Y - w], d * BODY_R - 2 * w, colors.fill);
|
|
1380
|
+
}
|
|
1381
|
+
function people(ctx, c, d, colors) {
|
|
1382
|
+
const s = d * PAIR_SCALE;
|
|
1383
|
+
person(ctx, [c[0] + d * BACK_DX, c[1] + d * BACK_DY], s, colors);
|
|
1384
|
+
person(ctx, [c[0] + d * FRONT_DX, c[1]], s, colors);
|
|
1385
|
+
}
|
|
1386
|
+
function ticket(ctx, c, d, colors) {
|
|
1387
|
+
const w = d * LINE2;
|
|
1388
|
+
ctx.fillStyle = colors.glyph;
|
|
1389
|
+
polygon(ctx, turnedRect(c, { w: d * TICKET_W, h: d * TICKET_H }, TICKET_TURN));
|
|
1390
|
+
ctx.fillStyle = colors.fill;
|
|
1391
|
+
polygon(ctx, turnedRect(c, { w: d * TICKET_W - 2 * w, h: d * TICKET_H - 2 * w }, TICKET_TURN));
|
|
1392
|
+
const along = [Math.cos(TICKET_TURN), Math.sin(TICKET_TURN)];
|
|
1393
|
+
const across = [-along[1], along[0]];
|
|
1394
|
+
const x = d * PERFORATION;
|
|
1395
|
+
DOTS.forEach((t) => disc(ctx, [c[0] + along[0] * x + across[0] * t * d * TICKET_H, c[1] + along[1] * x + across[1] * t * d * TICKET_H], d * DOT, colors.glyph));
|
|
1396
|
+
}
|
|
1397
|
+
var GLYPHS = {
|
|
1398
|
+
["person" /* Person */]: person,
|
|
1399
|
+
["people" /* People */]: people,
|
|
1400
|
+
["ticket" /* Ticket */]: ticket
|
|
1401
|
+
};
|
|
1402
|
+
function drawRowIcon(ctx, r3, kind, colors) {
|
|
1403
|
+
const c = [r3.x + r3.w / 2, r3.y + r3.h / 2];
|
|
1404
|
+
disc(ctx, c, r3.w / 2, colors.fill);
|
|
1405
|
+
GLYPHS[kind](ctx, c, r3.w, colors);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
918
1408
|
// src/render/render.ts
|
|
919
1409
|
var BASE2 = 1080;
|
|
1410
|
+
var NO_SPACING2 = "0px";
|
|
920
1411
|
var CARD_RADIUS = 0.035;
|
|
921
1412
|
var CAP_TOP = 0.15;
|
|
922
1413
|
var PIN_HEAD_Y = 0.08;
|
|
@@ -956,11 +1447,13 @@ function roundRect(ctx, r3, radius) {
|
|
|
956
1447
|
ctx.closePath();
|
|
957
1448
|
ctx.fill();
|
|
958
1449
|
}
|
|
959
|
-
function
|
|
1450
|
+
function drawRules(ctx, f) {
|
|
960
1451
|
f.rules.forEach((r3) => {
|
|
961
1452
|
ctx.fillStyle = r3.color;
|
|
962
1453
|
ctx.fillRect(r3.rect.x, r3.rect.y, r3.rect.w, r3.rect.h);
|
|
963
1454
|
});
|
|
1455
|
+
}
|
|
1456
|
+
function drawMarks(ctx, f, radius) {
|
|
964
1457
|
f.cards.forEach((c) => {
|
|
965
1458
|
ctx.fillStyle = c.color;
|
|
966
1459
|
roundRect(ctx, c.rect, radius);
|
|
@@ -971,15 +1464,25 @@ function drawFlow(ctx, f, radius) {
|
|
|
971
1464
|
ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2);
|
|
972
1465
|
ctx.fill();
|
|
973
1466
|
});
|
|
974
|
-
f.icons.forEach((i) => drawPin(ctx, i.rect, i.color, i.glyph));
|
|
1467
|
+
f.icons.forEach((i) => i.kind === void 0 ? drawPin(ctx, i.rect, i.color, i.glyph) : drawRowIcon(ctx, i.rect, i.kind, { fill: i.color, glyph: i.glyph }));
|
|
975
1468
|
ctx.textAlign = "left";
|
|
976
1469
|
ctx.textBaseline = "top";
|
|
977
1470
|
f.texts.forEach((t) => {
|
|
978
1471
|
ctx.font = t.font;
|
|
979
1472
|
ctx.fillStyle = t.color;
|
|
1473
|
+
if (t.spacing !== void 0) {
|
|
1474
|
+
ctx.letterSpacing = t.spacing;
|
|
1475
|
+
}
|
|
980
1476
|
ctx.fillText(t.text, t.box.x, t.box.y);
|
|
1477
|
+
if (t.spacing !== void 0) {
|
|
1478
|
+
ctx.letterSpacing = NO_SPACING2;
|
|
1479
|
+
}
|
|
981
1480
|
});
|
|
982
1481
|
}
|
|
1482
|
+
function drawFlow(ctx, f, radius) {
|
|
1483
|
+
drawRules(ctx, f);
|
|
1484
|
+
drawMarks(ctx, f, radius);
|
|
1485
|
+
}
|
|
983
1486
|
function checked(input, assets) {
|
|
984
1487
|
const result = validateFlierDoc(input);
|
|
985
1488
|
if (!result.ok) {
|
|
@@ -1011,6 +1514,25 @@ function capAligned(zone, head) {
|
|
|
1011
1514
|
const shift = first ? Math.min(Math.max(0, Math.round(first.y + first.h * CAP_TOP) - zone.y), Math.round(zone.h / 2)) : 0;
|
|
1012
1515
|
return { ...zone, y: zone.y + shift, h: zone.h - shift };
|
|
1013
1516
|
}
|
|
1517
|
+
function placeOnPage(doc, assets, fitted, frame) {
|
|
1518
|
+
const image = doc.picture ? assets[doc.picture.imageId] : void 0;
|
|
1519
|
+
const region = pictureRegion(doc.layout, fitted.geo, fitted.body, frame);
|
|
1520
|
+
const picture = image && doc.picture ? placePicture(image, region, doc.picture, { alignX: fitted.geo.alignX, frame }) : null;
|
|
1521
|
+
const dividers = doc.rows?.dividers;
|
|
1522
|
+
if (picture && dividers?.toPicture === true) {
|
|
1523
|
+
reachPicture(fitted.body.rules, picture, dividers.reach ?? 0);
|
|
1524
|
+
}
|
|
1525
|
+
return { image, region, picture };
|
|
1526
|
+
}
|
|
1527
|
+
function drawLogo(ctx, doc, assets, fitted) {
|
|
1528
|
+
const logoImage = doc.logo ? assets[doc.logo.imageId] : void 0;
|
|
1529
|
+
const zone = fitted.geo.logo ? fitted.zones.logo : capAligned(fitted.zones.logo, fitted.head);
|
|
1530
|
+
const logo = logoImage ? placeContain(logoImage, zone, { anchor: "top" /* Top */, alignX: 1, scale: 1 }) : null;
|
|
1531
|
+
if (logoImage && logo) {
|
|
1532
|
+
ctx.drawImage(logoImage, logo.x, logo.y, logo.w, logo.h);
|
|
1533
|
+
}
|
|
1534
|
+
return logo;
|
|
1535
|
+
}
|
|
1014
1536
|
function render(input, assets, canvas) {
|
|
1015
1537
|
const doc = checked(input, assets);
|
|
1016
1538
|
const { width, height } = FORMAT_SIZES[doc.format];
|
|
@@ -1021,40 +1543,34 @@ function render(input, assets, canvas) {
|
|
|
1021
1543
|
throw new Error("poster-render: the canvas has no 2d context");
|
|
1022
1544
|
}
|
|
1023
1545
|
const palette = PALETTES[doc.palette];
|
|
1024
|
-
const
|
|
1025
|
-
const
|
|
1026
|
-
const {
|
|
1027
|
-
ctx
|
|
1028
|
-
paintGround(ctx, doc.background, palette, { width, height });
|
|
1029
|
-
if (doc.background === "tint" /* Tint */) {
|
|
1030
|
-
ctx.fillStyle = palette.tint;
|
|
1031
|
-
[geo.header, geo.body].forEach((r3) => ctx.fillRect(r3.x, r3.y, r3.w, r3.h));
|
|
1032
|
-
}
|
|
1546
|
+
const fitted = fitToFloor(ctx, { doc, palette, fonts: FONT_SETS[doc.fonts], width, height });
|
|
1547
|
+
const { geo, head, body, sides } = fitted;
|
|
1548
|
+
const { image, region, picture } = placeOnPage(doc, assets, fitted, { width, height, u: Math.min(width, height) / BASE2 });
|
|
1549
|
+
paintPage(ctx, doc, palette, { geo, width, height, picture });
|
|
1033
1550
|
const radius = Math.min(width, height) * CARD_RADIUS;
|
|
1034
|
-
[head, body, ...sides]
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
ctx.drawImage(logoImage, logo.x, logo.y, logo.w, logo.h);
|
|
1039
|
-
}
|
|
1040
|
-
const image = doc.picture ? assets[doc.picture.imageId] : void 0;
|
|
1551
|
+
const flows = [head, body, ...sides];
|
|
1552
|
+
const layered = doc.picture?.overlap !== void 0;
|
|
1553
|
+
flows.forEach((f) => layered ? drawRules(ctx, f) : drawFlow(ctx, f, radius));
|
|
1554
|
+
const logo = drawLogo(ctx, doc, assets, fitted);
|
|
1041
1555
|
const backdrop = image ? archRect(geo) : null;
|
|
1042
1556
|
if (backdrop) {
|
|
1043
1557
|
drawArch(ctx, backdrop, palette.arch);
|
|
1044
1558
|
}
|
|
1045
|
-
const region = pictureRegion(doc.layout, geo, body, { height, u });
|
|
1046
|
-
const picture = image && doc.picture ? placeContain(image, region, { anchor: doc.picture.anchor, alignX: geo.alignX, scale: doc.picture.scale }) : null;
|
|
1047
1559
|
if (image && picture) {
|
|
1048
1560
|
ctx.drawImage(image, picture.x, picture.y, picture.w, picture.h);
|
|
1049
1561
|
}
|
|
1562
|
+
if (layered) {
|
|
1563
|
+
flows.forEach((f) => drawMarks(ctx, f, radius));
|
|
1564
|
+
}
|
|
1050
1565
|
return {
|
|
1051
1566
|
width,
|
|
1052
1567
|
height,
|
|
1053
1568
|
picture,
|
|
1054
1569
|
pictureRegion: region,
|
|
1055
|
-
textBoxes:
|
|
1570
|
+
textBoxes: flows.flatMap((f) => f.texts.map((t) => t.box)),
|
|
1056
1571
|
cardBoxes: body.cards.map((c) => c.rect),
|
|
1057
|
-
iconBoxes:
|
|
1572
|
+
iconBoxes: flows.flatMap((f) => f.icons.map((i) => i.rect)),
|
|
1573
|
+
ruleBoxes: flows.flatMap((f) => f.rules.map((r3) => r3.rect)),
|
|
1058
1574
|
logo,
|
|
1059
1575
|
backdrop
|
|
1060
1576
|
};
|
|
@@ -1157,16 +1673,22 @@ exports.FlierDocError = FlierDocError;
|
|
|
1157
1673
|
exports.FontSetId = FontSetId;
|
|
1158
1674
|
exports.FormatId = FormatId;
|
|
1159
1675
|
exports.LAYOUT_CATALOGUE = LAYOUT_CATALOGUE;
|
|
1676
|
+
exports.LINE_KEY_PATTERN = LINE_KEY_PATTERN;
|
|
1160
1677
|
exports.LayoutId = LayoutId;
|
|
1678
|
+
exports.LineAlign = LineAlign;
|
|
1679
|
+
exports.LineTieKind = LineTieKind;
|
|
1161
1680
|
exports.PALETTES = PALETTES;
|
|
1162
1681
|
exports.PaletteId = PaletteId;
|
|
1163
1682
|
exports.PictureAnchor = PictureAnchor;
|
|
1683
|
+
exports.RowIcon = RowIcon;
|
|
1164
1684
|
exports.defaultLayoutFor = defaultLayoutFor;
|
|
1165
1685
|
exports.exportPng = exportPng;
|
|
1166
1686
|
exports.flierDocSchema = flierDocSchema;
|
|
1167
1687
|
exports.kizombaWorkshop = kizombaWorkshop;
|
|
1168
1688
|
exports.kizombaWorkshopDocs = kizombaWorkshopDocs;
|
|
1169
1689
|
exports.render = render;
|
|
1690
|
+
exports.sameSize = sameSize;
|
|
1691
|
+
exports.sameWidth = sameWidth;
|
|
1170
1692
|
exports.validateFlierDoc = validateFlierDoc;
|
|
1171
1693
|
//# sourceMappingURL=index.js.map
|
|
1172
1694
|
//# sourceMappingURL=index.js.map
|