@cosmicdrift/kumiko-renderer-puppeteer-client 0.387.0 → 0.388.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.
@@ -10,6 +10,7 @@ import { collectRegionResourceKeys, compileDocumentSource, createDocumentHandleb
10
10
  const LINE_BREAKS = /[\r\n]+/g;
11
11
  const IMAGE_CONTENT_TYPE_PREFIX = "image/";
12
12
  const MAX_RECORD_IMAGES = 24;
13
+ const MAX_RECORD_IMAGE_LOOKUPS = 100;
13
14
  const MAX_RECORD_IMAGES_TOTAL_BYTES = 20 * 1024 * 1024;
14
15
  const PREVIEW_PAGE_NUMBER = "1";
15
16
  const EMPTY_CHROMIUM_REGION = "<span></span>";
@@ -176,8 +177,10 @@ async function loadRecordImageDataUris(ctx, variables, imageVariableNames) {
176
177
  for (const fileRefId of fileRefIdsOf(variables[name])) {
177
178
  if (seenIds.has(fileRefId))
178
179
  continue;
180
+ if (seenIds.size >= MAX_RECORD_IMAGE_LOOKUPS)
181
+ break;
179
182
  seenIds.add(fileRefId);
180
- if (loadedCount >= MAX_RECORD_IMAGES)
183
+ if (loadedCount >= MAX_RECORD_IMAGES || loadedBytes >= MAX_RECORD_IMAGES_TOTAL_BYTES)
181
184
  break;
182
185
  const image = await readRecordImage(ctx, filesForTenant, fileRefId, Math.min(maxBytes, MAX_RECORD_IMAGES_TOTAL_BYTES - loadedBytes));
183
186
  if (image === null)
@@ -190,10 +193,22 @@ async function loadRecordImageDataUris(ctx, variables, imageVariableNames) {
190
193
  }
191
194
  return dataUrisByVariable;
192
195
  }
193
- // Text context without images variables: their value is file ids, which no placeholder,
194
- // title or file name pattern may print.
195
- function withoutImageVariables(variables, definitions) {
196
- return Object.fromEntries(Object.entries(variables).filter(([name]) => !(Object.hasOwn(definitions, name) && definitions[name]?.type === "images")));
196
+ function isImagesVariable(definitions, name) {
197
+ return Object.hasOwn(definitions, name) && definitions[name]?.type === "images";
198
+ }
199
+ // An images variable's value is file ids, which no placeholder, title or file name pattern
200
+ // may print; the text context carries only whether images exist, so a condition on it works.
201
+ function imagesAsPresenceFlags(variables, definitions, recordImages, recordImageUris) {
202
+ const hasImages = (name) => {
203
+ if (recordImages === "placeholder")
204
+ return true;
205
+ const resolved = recordImageUris.get(name);
206
+ return resolved !== undefined ? resolved.length > 0 : fileRefIdsOf(variables[name]).length > 0;
207
+ };
208
+ return Object.fromEntries(Object.entries(variables).map(([name, value]) => [
209
+ name,
210
+ isImagesVariable(definitions, name) ? hasImages(name) : value,
211
+ ]));
197
212
  }
198
213
  function renderRegion(hbs, region, context, resourceSrc) {
199
214
  if (region.trim() === "")
@@ -304,17 +319,17 @@ async function assembleDocument(input, ctx, markers, recordImages = "placeholder
304
319
  ]);
305
320
  const hbs = createDocumentHandlebars(format);
306
321
  const variableDefinitions = resolveTemplateVariables(ctx.registry, slug, template.variableSchema);
322
+ const recordImageUris = recordImages === "resolve"
323
+ ? await loadRecordImageDataUris(ctx, variables, collectDocumentImageVariables(template.content).filter((name) => isImagesVariable(variableDefinitions, name)))
324
+ : new Map();
307
325
  const context = {
308
- ...withoutImageVariables(variables, variableDefinitions),
326
+ ...imagesAsPresenceFlags(variables, variableDefinitions, recordImages, recordImageUris),
309
327
  tenantName,
310
328
  signature: "",
311
329
  imprint: "",
312
330
  page: "",
313
331
  pages: "",
314
332
  };
315
- const recordImageUris = recordImages === "resolve"
316
- ? await loadRecordImageDataUris(ctx, variables, collectDocumentImageVariables(template.content))
317
- : new Map();
318
333
  const bodyKeys = collectDocumentResourceKeys(template.content);
319
334
  const layoutKeys = collectRegionResourceKeys(layout.regions);
320
335
  const bodyRefs = await resolveResourceFileRefs(tplApi, ctx, template, bodyKeys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-renderer-puppeteer-client",
3
- "version": "0.387.0",
3
+ "version": "0.388.0",
4
4
  "description": "Renderer-Foundation plugin: HTTP client for puppeteer-service (PDF + image snapshot via remote browser).",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -19,13 +19,13 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@cosmicdrift/kumiko-bundled-features": "0.387.0",
23
- "@cosmicdrift/kumiko-framework": "0.387.0",
24
- "@cosmicdrift/kumiko-renderer-mail-html": "0.387.0",
25
- "@cosmicdrift/kumiko-types": "0.387.0"
22
+ "@cosmicdrift/kumiko-bundled-features": "0.388.0",
23
+ "@cosmicdrift/kumiko-framework": "0.388.0",
24
+ "@cosmicdrift/kumiko-renderer-mail-html": "0.388.0",
25
+ "@cosmicdrift/kumiko-types": "0.388.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@cosmicdrift/kumiko-testing": "0.387.0"
28
+ "@cosmicdrift/kumiko-testing": "0.388.0"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
package/src/changes.json CHANGED
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.388.0",
4
+ "type": "fix",
5
+ "title": "Conditions on images variables work in the PDF render",
6
+ "detail": "A data-condition on an images variable now shows its block when the record has resolvable images, instead of never. Record image loading stops once the byte budget is used up, caps the number of looked-up ids, and ignores image blocks whose variable is not declared as images."
7
+ },
2
8
  {
3
9
  "version": "0.379.0",
4
10
  "type": "improvement",