@homepages/concrete 12.0.0 → 13.0.1
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 +192 -0
- package/README.md +8 -10
- package/codemods/fixtures-are-data.mjs +7 -0
- package/codemods/fixtures-list-properties.mjs +6 -0
- package/codemods/manifest.json +15 -0
- package/codemods/steps/fixtures-list-properties.mjs +16 -0
- package/codemods/steps/fixtures-to-data.mjs +41 -0
- package/dist/artifact/playground/client/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
- package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +1338 -0
- package/dist/artifact/playground/client/assets/index-C01UCAWD.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +110 -59
- package/dist/base.css +2 -2
- package/dist/cli/build/icons.js +1 -1
- package/dist/cli/build/index.js +11 -10
- package/dist/cli/build/manifest.js +44 -0
- package/dist/cli/build/record.js +123 -0
- package/dist/cli/build/sections.js +28 -18
- package/dist/cli/build/source.js +1 -1
- package/dist/cli/build/static.js +8 -5
- package/dist/cli/build/template-build.js +614 -0
- package/dist/cli/check/analyze.js +18 -1
- package/dist/cli/check/load-workspace.js +2 -2
- package/dist/cli/check/portable-names.js +1 -1
- package/dist/cli/check/render/corpus.js +119 -0
- package/dist/cli/check/render/invariants.js +1 -0
- package/dist/cli/check/stages/bundles.js +15 -18
- package/dist/cli/check/stages/composition.js +8 -25
- package/dist/cli/check/stages/fixtures.js +14 -10
- package/dist/cli/check/stages/logic.js +7 -23
- package/dist/cli/check/stages/render.js +12 -14
- package/dist/cli/check/stages/sections.js +22 -66
- package/dist/cli/check/stages/stylesheet.js +4 -26
- package/dist/cli/check/stages/workspace.js +27 -22
- package/dist/cli/commands.js +51 -23
- package/dist/cli/currency/preamble.js +1 -1
- package/dist/cli/currency/resolve-latest.js +3 -2
- package/dist/cli/dev/capture-browser.js +26 -0
- package/dist/cli/dev/fixture-schema.js +441 -0
- package/dist/cli/dev/folder-files.js +244 -0
- package/dist/cli/dev/index.js +7 -3
- package/dist/cli/dev/playground-server.js +34 -0
- package/dist/cli/dev/section-ladders.js +76 -0
- package/dist/cli/dev/server.js +120 -304
- package/dist/cli/install/background.js +16 -0
- package/dist/cli/install/index.js +45 -0
- package/dist/cli/install/tools.js +27 -0
- package/dist/cli/media/derive.js +19 -13
- package/dist/cli/media/deriver-plugin.js +14 -3
- package/dist/cli/property/fixture-list.js +46 -0
- package/dist/cli/property/index.js +12 -9
- package/dist/cli/property/library.js +12 -10
- package/dist/cli/publish/artifact.js +90 -0
- package/dist/cli/publish/captures.js +61 -0
- package/dist/cli/publish/fixtures.js +17 -0
- package/dist/cli/publish/index.js +10 -18
- package/dist/cli/{build → publish}/playground.js +3 -3
- package/dist/cli/publish/report.js +15 -33
- package/dist/cli/upgrade/codemod.d.ts +14 -0
- package/dist/cli/upgrade/fixture-conversion.d.ts +11 -0
- package/dist/cli/upgrade/fixture-conversion.js +54 -0
- package/dist/cli/upgrade/fixture-modules.js +125 -0
- package/dist/cli/upgrade/fixtures-to-data.d.ts +40 -0
- package/dist/cli/upgrade/fixtures-to-data.js +498 -0
- package/dist/cli/upgrade/index.js +18 -2
- package/dist/cli/upgrade/legacy-fixtures.d.ts +34 -0
- package/dist/cli/upgrade/legacy-fixtures.js +22 -0
- package/dist/cli/upgrade/stage.js +1 -1
- package/dist/cli/workspace-fixtures.js +80 -0
- package/dist/cli.js +1 -0
- package/dist/css/compile.js +9 -3
- package/dist/fixtures/bundle-rule.js +16 -16
- package/dist/fixtures/media-plugin.js +12 -33
- package/dist/fixtures/synthesize-empties.js +3 -2
- package/dist/index.d.ts +7 -7
- package/dist/{playground-island-runtime.d.ts → island-runtime.d.ts} +1 -2
- package/dist/{playground-island-runtime.js → island-runtime.js} +1 -2
- package/dist/islands/client-module.js +1 -1
- package/dist/{cli/dev → islands}/tsconfig-paths.js +2 -14
- package/dist/islands/wrap.js +40 -0
- package/dist/node_modules/.pnpm/acorn@8.18.0/node_modules/acorn/dist/acorn.js +5119 -0
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/bundle-evaluation/dist/cache.js +36 -0
- package/dist/packages/internal/bundle-evaluation/dist/evaluate.js +174 -0
- package/dist/packages/internal/bundle-evaluation/dist/index.js +5 -0
- package/dist/packages/internal/bundle-evaluation/dist/section-code.js +10 -0
- package/dist/packages/internal/capture-settle/dist/index.js +2 -2
- package/dist/packages/internal/capture-settle/dist/settle.js +88 -13
- package/dist/packages/internal/code-fingerprint/dist/index.js +57 -0
- package/dist/packages/internal/content-doc-ops/dist/index.js +176 -0
- package/dist/packages/internal/content-doc-ops/dist/made-rows.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/bootstrap.js +81 -0
- package/dist/packages/internal/deliverable-reads/dist/display.js +21 -0
- package/dist/packages/internal/deliverable-reads/dist/format.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/index.js +7 -0
- package/dist/packages/internal/deliverable-reads/dist/pages.js +29 -0
- package/dist/packages/internal/deliverable-reads/dist/requirements.js +72 -0
- package/dist/{cli/capture → packages/internal/download-files/dist}/bundle.js +8 -4
- package/dist/packages/internal/download-files/dist/capture-origin.js +126 -0
- package/dist/packages/internal/download-files/dist/capture-routes.js +139 -0
- package/dist/packages/internal/download-files/dist/capture-shell.js +38 -0
- package/dist/packages/internal/download-files/dist/capture.js +74 -0
- package/dist/packages/internal/download-files/dist/egress-watch.js +38 -0
- package/dist/packages/internal/download-files/dist/files.js +7 -0
- package/dist/packages/internal/download-files/dist/finish.js +35 -0
- package/dist/packages/internal/download-files/dist/fleet.js +94 -0
- package/dist/packages/internal/download-files/dist/format.js +40 -0
- package/dist/packages/internal/download-files/dist/make.js +105 -0
- package/dist/packages/internal/download-files/dist/master-tally.js +32 -0
- package/dist/packages/internal/download-files/dist/names.js +24 -0
- package/dist/packages/internal/download-files/dist/pdf-boxes.js +33 -0
- package/dist/packages/internal/download-files/dist/pdf-image-placements.js +194 -0
- package/dist/packages/internal/download-files/dist/pdf-images.js +289 -0
- package/dist/packages/internal/file-store/dist/files.js +8 -0
- package/dist/packages/internal/file-store/dist/lru.js +40 -0
- package/dist/packages/internal/file-store/dist/refusal.js +12 -0
- package/dist/packages/internal/file-store/dist/trees.js +151 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +1 -1
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +47 -21
- package/dist/packages/internal/fill-bake/dist/index.js +5 -1
- package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
- package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
- package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
- package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
- package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
- package/dist/packages/internal/island-runtime/dist/index.js +1 -10
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
- package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
- package/dist/packages/internal/media-resolution/dist/video.js +6 -2
- package/dist/packages/internal/page-render/dist/addresses.js +57 -0
- package/dist/packages/internal/page-render/dist/index.js +6 -0
- package/dist/packages/internal/page-render/dist/kept.js +30 -0
- package/dist/packages/internal/page-render/dist/nav.js +42 -0
- package/dist/packages/internal/page-render/dist/render.js +152 -0
- package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
- package/dist/packages/internal/page-shell/dist/escape.js +10 -0
- package/dist/packages/internal/page-shell/dist/frame.js +23 -0
- package/dist/packages/internal/page-shell/dist/index.js +26 -0
- package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
- package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
- package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
- package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
- package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
- package/dist/packages/internal/playground/dist/host/built.js +202 -0
- package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
- package/dist/packages/internal/playground/dist/host/download.js +34 -0
- package/dist/packages/internal/playground/dist/host/env.js +11 -0
- package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
- package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
- package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
- package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
- package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
- package/dist/packages/internal/playground/dist/host/leads.js +41 -0
- package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
- package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
- package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
- package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
- package/dist/packages/internal/playground/dist/host/program.js +54 -0
- package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
- package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
- package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
- package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
- package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
- package/dist/packages/internal/playground/dist/host/save.js +429 -0
- package/dist/packages/internal/playground/dist/host/serve.js +952 -0
- package/dist/packages/internal/playground/dist/host/site.js +79 -0
- package/dist/packages/internal/playground/dist/host/slots.js +202 -0
- package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
- package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
- package/dist/packages/internal/playground/dist/host/violations.js +7 -0
- package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
- package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
- package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
- package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
- package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
- package/dist/packages/internal/playground/dist/layout.js +14 -0
- package/dist/packages/internal/playground/dist/platform.js +33 -0
- package/dist/packages/internal/playground/dist/server/changes.js +57 -0
- package/dist/packages/internal/playground/dist/server/crop.js +47 -0
- package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
- package/dist/packages/internal/playground/dist/server/download.js +158 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
- package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
- package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
- package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
- package/dist/packages/internal/playground/dist/server/verification.js +75 -0
- package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
- package/dist/packages/internal/playground/dist/wire.js +78 -0
- package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
- package/dist/packages/internal/site-files/dist/head.js +59 -0
- package/dist/packages/internal/site-files/dist/index.js +4 -0
- package/dist/packages/internal/site-files/dist/site.js +211 -0
- package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
- package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
- package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
- package/dist/packages/internal/template-artifact/dist/build.js +148 -0
- package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
- package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
- package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
- package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
- package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
- package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
- package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
- package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
- package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
- package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
- package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
- package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
- package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
- package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
- package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
- package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
- package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
- package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
- package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
- package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
- package/dist/packages/internal/upload-formats/dist/index.js +80 -0
- package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
- package/dist/platform/paths.js +1 -0
- package/dist/platform/process.js +49 -1
- package/dist/rules/registry.js +27 -3
- package/dist/schema/fact.d.ts +2 -2
- package/dist/schema/facts-view.d.ts +1 -1
- package/dist/schema/section-props.d.ts +1 -1
- package/dist/schema/section-schema.d.ts +1 -1
- package/dist/schema/section-schema.js +1 -0
- package/dist/section/declare.d.ts +1 -1
- package/dist/section/discovery.js +6 -2
- package/dist/section/publish-shape.js +38 -0
- package/dist/section/section.d.ts +1 -1
- package/dist/template/define-template.d.ts +14 -4
- package/dist/template/define-template.js +2 -0
- package/dist/template/logic-shim.d.ts +1 -1
- package/dist/template/materialize.js +1 -1
- package/dist/template/running-copy.js +0 -1
- package/dist/template/section-reads.js +1 -1
- package/guide/reference/cli/INDEX.md +6 -5
- package/guide/reference/cli/build.md +10 -8
- package/guide/reference/cli/check.md +4 -2
- package/guide/reference/cli/dev.md +6 -2
- package/guide/reference/cli/install.md +41 -0
- package/guide/reference/cli/property-add.md +5 -4
- package/guide/reference/cli/property-list.md +2 -2
- package/guide/reference/cli/publish.md +5 -5
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +8 -4
- package/package.json +14 -30
- package/dist/artifact/playground/client/assets/index-BcLGpWLR.js +0 -1266
- package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
- package/dist/cli/build/artifact.js +0 -220
- package/dist/cli/build/captures.js +0 -48
- package/dist/cli/build/fixtures.js +0 -92
- package/dist/cli/capture/capture-browser.js +0 -37
- package/dist/cli/capture/capture.js +0 -115
- package/dist/cli/check/render/inputs.js +0 -60
- package/dist/cli/check/render/nav.js +0 -31
- package/dist/cli/dev/crop.js +0 -20
- package/dist/cli/dev/fixture-ladders.js +0 -96
- package/dist/cli/dev/hmr.js +0 -26
- package/dist/cli/dev/islands.js +0 -234
- package/dist/cli/dev/load-template.js +0 -52
- package/dist/cli/dev/vite.js +0 -114
- package/dist/cli/dev/workspace-reader.js +0 -249
- package/dist/cli/publish/freshness.js +0 -64
- package/dist/fixtures/brand.d.ts +0 -4
- package/dist/fixtures/brand.js +0 -8
- package/dist/fixtures/load.js +0 -159
- package/dist/fixtures/resolve.js +0 -392
- package/dist/fixtures.d.ts +0 -429
- package/dist/fixtures.js +0 -23
- package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
- package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
- package/dist/playground/canvas-island-host.d.ts +0 -11
- package/dist/playground/canvas-island-host.js +0 -29
- package/dist/playground/canvas-markers.js +0 -14
- package/dist/playground/host/paths.js +0 -8
- package/dist/playground/layout.js +0 -17
- package/dist/playground/wire.js +0 -28
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { resolveFormatGeometry } from "../../format-geometry/dist/geometry.js";
|
|
2
|
+
import { bundlePages } from "./bundle.js";
|
|
3
|
+
import { stampPdfBoxes } from "./pdf-boxes.js";
|
|
4
|
+
import { finishPdfImages } from "./pdf-images.js";
|
|
5
|
+
|
|
6
|
+
//#region ../../internal/download-files/dist/finish.js
|
|
7
|
+
async function finishDownload(input) {
|
|
8
|
+
const geometry = resolveFormatGeometry(input.format);
|
|
9
|
+
const files = [];
|
|
10
|
+
for (const file of input.captured) files.push(file.mime === "application/pdf" ? {
|
|
11
|
+
...file,
|
|
12
|
+
bytes: await stampPdfBoxes(await finishPdfImages(file.bytes, {
|
|
13
|
+
geometry,
|
|
14
|
+
log: input.log
|
|
15
|
+
}), {
|
|
16
|
+
geometry,
|
|
17
|
+
title: input.naming.title,
|
|
18
|
+
log: input.log
|
|
19
|
+
})
|
|
20
|
+
} : file);
|
|
21
|
+
if (input.output === "image" && files.length > 1) files.push({
|
|
22
|
+
pageId: null,
|
|
23
|
+
mime: "application/zip",
|
|
24
|
+
bytes: bundlePages(files.map((file) => ({
|
|
25
|
+
name: (file.pageId === null ? void 0 : input.naming.pageFilenames[file.pageId]) ?? `${file.pageId ?? "page"}.png`,
|
|
26
|
+
bytes: file.bytes
|
|
27
|
+
}))),
|
|
28
|
+
width: null,
|
|
29
|
+
height: null
|
|
30
|
+
});
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { finishDownload };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//#region ../../internal/download-files/dist/fleet.js
|
|
2
|
+
function createBrowserFleet(options) {
|
|
3
|
+
let current = null;
|
|
4
|
+
let launching = null;
|
|
5
|
+
const emit = options.onEvent ?? (() => {});
|
|
6
|
+
async function reapIfDone(generation) {
|
|
7
|
+
if (!generation.retired || generation.live > 0) return;
|
|
8
|
+
try {
|
|
9
|
+
await generation.browser.close();
|
|
10
|
+
emit("browser_closed", { served: generation.served });
|
|
11
|
+
} catch (err) {
|
|
12
|
+
emit("browser_close_failed", { err });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function generation() {
|
|
16
|
+
if (current && !current.retired && current.browser.isConnected()) return current;
|
|
17
|
+
if (current) {
|
|
18
|
+
const stale = current;
|
|
19
|
+
current = null;
|
|
20
|
+
if (!stale.retired) {
|
|
21
|
+
stale.retired = true;
|
|
22
|
+
emit("browser_disconnected", {
|
|
23
|
+
served: stale.served,
|
|
24
|
+
live: stale.live
|
|
25
|
+
});
|
|
26
|
+
await reapIfDone(stale);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
launching ??= (async () => {
|
|
30
|
+
const browser = await options.launch();
|
|
31
|
+
emit("browser_launched", { version: browser.version() });
|
|
32
|
+
return {
|
|
33
|
+
browser,
|
|
34
|
+
served: 0,
|
|
35
|
+
live: 0,
|
|
36
|
+
retired: false
|
|
37
|
+
};
|
|
38
|
+
})().finally(() => {
|
|
39
|
+
launching = null;
|
|
40
|
+
});
|
|
41
|
+
const launched = await launching;
|
|
42
|
+
current ??= launched;
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
async acquire(contextOptions) {
|
|
47
|
+
const gen = await generation();
|
|
48
|
+
gen.served += 1;
|
|
49
|
+
gen.live += 1;
|
|
50
|
+
if (gen.served >= options.maxJobsPerBrowser) {
|
|
51
|
+
gen.retired = true;
|
|
52
|
+
if (current === gen) current = null;
|
|
53
|
+
emit("browser_retired", {
|
|
54
|
+
served: gen.served,
|
|
55
|
+
live: gen.live
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
let context;
|
|
59
|
+
try {
|
|
60
|
+
context = await gen.browser.newContext(contextOptions);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
gen.live -= 1;
|
|
63
|
+
await reapIfDone(gen);
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
let released = false;
|
|
67
|
+
return {
|
|
68
|
+
context,
|
|
69
|
+
async release() {
|
|
70
|
+
if (released) return;
|
|
71
|
+
released = true;
|
|
72
|
+
try {
|
|
73
|
+
await context.close();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
emit("context_close_failed", { err });
|
|
76
|
+
}
|
|
77
|
+
gen.live -= 1;
|
|
78
|
+
if (!gen.browser.isConnected()) gen.retired = true;
|
|
79
|
+
await reapIfDone(gen);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
async close() {
|
|
84
|
+
const gen = current;
|
|
85
|
+
current = null;
|
|
86
|
+
if (!gen) return;
|
|
87
|
+
gen.retired = true;
|
|
88
|
+
await reapIfDone(gen);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { createBrowserFleet };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region ../../internal/download-files/dist/format.js
|
|
2
|
+
const PHYSICAL_LENGTH_RE = /^\d+(?:\.\d+)?(?:in|mm)$/;
|
|
3
|
+
function isPhysicalLength(value) {
|
|
4
|
+
return typeof value === "string" && PHYSICAL_LENGTH_RE.test(value);
|
|
5
|
+
}
|
|
6
|
+
function isPositiveNumber(value) {
|
|
7
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
8
|
+
}
|
|
9
|
+
function refuse(format, why) {
|
|
10
|
+
throw new Error(`format "${format.id}" is not a usable geometry value: ${why} (width=${JSON.stringify(format.width)}, height=${JSON.stringify(format.height)}, dpi=${JSON.stringify(format.dpi)}, bleed=${JSON.stringify(format.bleed)})`);
|
|
11
|
+
}
|
|
12
|
+
function toGeometryFormat(output, format) {
|
|
13
|
+
const identity = {
|
|
14
|
+
id: format.id,
|
|
15
|
+
label: format.label,
|
|
16
|
+
category: format.category,
|
|
17
|
+
...format.preset === void 0 ? {} : { preset: format.preset }
|
|
18
|
+
};
|
|
19
|
+
if (isPositiveNumber(format.width) && isPositiveNumber(format.height)) return {
|
|
20
|
+
...identity,
|
|
21
|
+
width: format.width,
|
|
22
|
+
height: format.height
|
|
23
|
+
};
|
|
24
|
+
if (isPhysicalLength(format.width) && isPhysicalLength(format.height)) {
|
|
25
|
+
if (output === "image") refuse(format, "an image format renders at output pixels and cannot be physical");
|
|
26
|
+
if (!isPositiveNumber(format.dpi)) refuse(format, "a physical document format must declare a positive dpi");
|
|
27
|
+
if (format.bleed !== void 0 && !isPhysicalLength(format.bleed)) refuse(format, "bleed must be a physical length");
|
|
28
|
+
return {
|
|
29
|
+
...identity,
|
|
30
|
+
width: format.width,
|
|
31
|
+
height: format.height,
|
|
32
|
+
dpi: format.dpi,
|
|
33
|
+
...format.bleed === void 0 ? {} : { bleed: format.bleed }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
refuse(format, "width and height must both be pixels or both be physical lengths");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { toGeometryFormat };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { resolveFormatGeometry } from "../../format-geometry/dist/geometry.js";
|
|
2
|
+
import { toGeometryFormat } from "./format.js";
|
|
3
|
+
import { captureImagePage, capturePrintDocument, newCaptureContextOptions } from "./capture.js";
|
|
4
|
+
import { captureDocuments, captureRoutes } from "./capture-routes.js";
|
|
5
|
+
import { startCaptureOrigin } from "./capture-origin.js";
|
|
6
|
+
import { finishDownload } from "./finish.js";
|
|
7
|
+
import { createMasterTally } from "./master-tally.js";
|
|
8
|
+
|
|
9
|
+
//#region ../../internal/download-files/dist/make.js
|
|
10
|
+
function isKept(page) {
|
|
11
|
+
return "kept" in page;
|
|
12
|
+
}
|
|
13
|
+
async function makeDownloadFiles(input) {
|
|
14
|
+
const format = toGeometryFormat(input.output, input.format);
|
|
15
|
+
const pagesAlone = input.shoot === "pages";
|
|
16
|
+
const shotAs = pagesAlone ? "image" : input.output;
|
|
17
|
+
const kept = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const page of input.pages.filter(isKept)) {
|
|
19
|
+
if (shotAs !== "image" || page.kept.mime !== "image/png" || page.kept.pageId !== page.id) throw new Error(`only an image page's PNG is kept from an earlier download, not page "${page.id}"'s ${page.kept.mime}`);
|
|
20
|
+
kept.set(page.id, page.kept);
|
|
21
|
+
}
|
|
22
|
+
const toShoot = input.pages.filter((page) => !isKept(page));
|
|
23
|
+
const shot = toShoot.length === 0 ? [] : await shoot(input, format, shotAs, toShoot);
|
|
24
|
+
const shotById = new Map(shot.map((file) => [file.pageId, file]));
|
|
25
|
+
const captured = shotAs === "image" ? input.pages.map((page) => kept.get(page.id) ?? shotById.get(page.id)) : shot;
|
|
26
|
+
if (pagesAlone) return captured;
|
|
27
|
+
return finishDownload({
|
|
28
|
+
output: input.output,
|
|
29
|
+
format,
|
|
30
|
+
naming: input.naming,
|
|
31
|
+
captured,
|
|
32
|
+
log: input.log
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async function shoot(input, format, shotAs, pages) {
|
|
36
|
+
const geometry = resolveFormatGeometry(format);
|
|
37
|
+
const documents = captureDocuments({
|
|
38
|
+
output: shotAs,
|
|
39
|
+
format,
|
|
40
|
+
pages,
|
|
41
|
+
binding: input.binding,
|
|
42
|
+
bases: input.bases
|
|
43
|
+
});
|
|
44
|
+
if (shotAs === "document" && documents.length !== 1) throw new Error(`a document download is shot from exactly one print document, got ${documents.length}`);
|
|
45
|
+
const masters = createMasterTally();
|
|
46
|
+
const log = input.log;
|
|
47
|
+
const origin = await startCaptureOrigin({
|
|
48
|
+
documents,
|
|
49
|
+
routes: captureRoutes({
|
|
50
|
+
binding: input.binding,
|
|
51
|
+
media: input.media,
|
|
52
|
+
bases: input.bases
|
|
53
|
+
}),
|
|
54
|
+
bases: input.bases,
|
|
55
|
+
reads: input.reads,
|
|
56
|
+
onError: (message, err) => log.error({ err }, message),
|
|
57
|
+
onAbsentBuildFile: (path) => masters.recordAbsent(path),
|
|
58
|
+
onImageServed: (event) => {
|
|
59
|
+
masters.record(event);
|
|
60
|
+
if (event.kind === "master") log.info({
|
|
61
|
+
pathname: event.pathname,
|
|
62
|
+
served_key: event.servedKey,
|
|
63
|
+
asked_for: event.askedFor
|
|
64
|
+
}, "download: served master in place of rung");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
let captured;
|
|
68
|
+
try {
|
|
69
|
+
const lease = await input.browser.acquire(newCaptureContextOptions(format));
|
|
70
|
+
try {
|
|
71
|
+
const context = lease.context;
|
|
72
|
+
captured = [];
|
|
73
|
+
for (const document of documents) {
|
|
74
|
+
const target = {
|
|
75
|
+
url: origin.urlFor(document),
|
|
76
|
+
origin: origin.origin,
|
|
77
|
+
format,
|
|
78
|
+
masters
|
|
79
|
+
};
|
|
80
|
+
if (shotAs === "image") captured.push({
|
|
81
|
+
pageId: document.pageId,
|
|
82
|
+
mime: "image/png",
|
|
83
|
+
bytes: await captureImagePage(context, target),
|
|
84
|
+
width: geometry.pixelWidth,
|
|
85
|
+
height: geometry.pixelHeight
|
|
86
|
+
});
|
|
87
|
+
else captured.push({
|
|
88
|
+
pageId: null,
|
|
89
|
+
mime: "application/pdf",
|
|
90
|
+
bytes: await capturePrintDocument(context, target),
|
|
91
|
+
width: null,
|
|
92
|
+
height: null
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
} finally {
|
|
96
|
+
await lease.release();
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
await origin.close();
|
|
100
|
+
}
|
|
101
|
+
return captured;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { makeDownloadFiles };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region ../../internal/download-files/dist/master-tally.js
|
|
2
|
+
function createMasterTally() {
|
|
3
|
+
const misses = [];
|
|
4
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5
|
+
const absent = [];
|
|
6
|
+
return {
|
|
7
|
+
record(event) {
|
|
8
|
+
if (event.kind === "master") return;
|
|
9
|
+
if (seen.has(event.pathname)) return;
|
|
10
|
+
seen.add(event.pathname);
|
|
11
|
+
misses.push(event.pathname);
|
|
12
|
+
},
|
|
13
|
+
misses,
|
|
14
|
+
recordAbsent(path) {
|
|
15
|
+
if (!absent.includes(path)) absent.push(path);
|
|
16
|
+
},
|
|
17
|
+
absent,
|
|
18
|
+
assertBuildFilesServed() {
|
|
19
|
+
const [first] = absent;
|
|
20
|
+
if (first === void 0) return;
|
|
21
|
+
throw new Error(`render blocked: the template's build has no ${first}` + (absent.length > 1 ? ` (${absent.length} missing files in total)` : "") + ", which a page asked for. Republish the template so its build is whole.");
|
|
22
|
+
},
|
|
23
|
+
assertMastersServed() {
|
|
24
|
+
const [first] = misses;
|
|
25
|
+
if (first === void 0) return;
|
|
26
|
+
throw new Error(`render blocked: served a ladder rung with no master behind it — ${first}` + (misses.length > 1 ? ` (${misses.length} such assets in total)` : "") + ". The download would ship one generation below the quality the platform holds for those assets. Re-release the pinned template so its author masters exist.");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createMasterTally };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region ../../internal/download-files/dist/names.js
|
|
2
|
+
const EXTENSION_BY_MIME = {
|
|
3
|
+
"image/png": "png",
|
|
4
|
+
"application/pdf": "pdf",
|
|
5
|
+
"application/zip": "zip"
|
|
6
|
+
};
|
|
7
|
+
const UNSAFE_IN_FILENAME = /[/\\:*?"<>|\x00-\x1f\x7f]/g;
|
|
8
|
+
function sanitizeSegment(value) {
|
|
9
|
+
return value.replace(UNSAFE_IN_FILENAME, " ").replace(/\s+/g, " ").trim();
|
|
10
|
+
}
|
|
11
|
+
function downloadStem(parts) {
|
|
12
|
+
const stem = [
|
|
13
|
+
parts.propertyAddress,
|
|
14
|
+
parts.templateDisplayName,
|
|
15
|
+
parts.pageLabel
|
|
16
|
+
].map((part) => sanitizeSegment(part ?? "")).filter((part) => part.length > 0).join(" - ");
|
|
17
|
+
return stem.length > 0 ? stem : "download";
|
|
18
|
+
}
|
|
19
|
+
function downloadFilename(parts) {
|
|
20
|
+
return `${downloadStem(parts)}.${EXTENSION_BY_MIME[parts.mime]}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { downloadFilename, downloadStem };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PDFDocument } from "pdf-lib";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/download-files/dist/pdf-boxes.js
|
|
4
|
+
const PRODUCER = "HomePages";
|
|
5
|
+
const PAGE_BOX_TOLERANCE_PT = 1;
|
|
6
|
+
async function stampPdfBoxes(bytes, args) {
|
|
7
|
+
const inset = args.geometry.bleedPoints;
|
|
8
|
+
const doc = await PDFDocument.load(bytes, { updateMetadata: false });
|
|
9
|
+
doc.setTitle(args.title);
|
|
10
|
+
doc.setProducer(PRODUCER);
|
|
11
|
+
doc.setCreator(PRODUCER);
|
|
12
|
+
for (const [index, page] of doc.getPages().entries()) {
|
|
13
|
+
const media = page.getMediaBox();
|
|
14
|
+
if (Math.abs(media.width - args.geometry.pointWidth) > PAGE_BOX_TOLERANCE_PT || Math.abs(media.height - args.geometry.pointHeight) > PAGE_BOX_TOLERANCE_PT) args.log.warn({
|
|
15
|
+
page_index: index,
|
|
16
|
+
media_box: {
|
|
17
|
+
width: media.width,
|
|
18
|
+
height: media.height
|
|
19
|
+
},
|
|
20
|
+
expected: {
|
|
21
|
+
width: args.geometry.pointWidth,
|
|
22
|
+
height: args.geometry.pointHeight
|
|
23
|
+
}
|
|
24
|
+
}, "captured PDF page box disagrees with the format geometry; boxes stamped against the page as captured");
|
|
25
|
+
if (inset * 2 >= media.width || inset * 2 >= media.height) throw new Error(`download: format bleed (${inset}pt) leaves no trim box inside a ${media.width}×${media.height}pt page`);
|
|
26
|
+
page.setBleedBox(media.x, media.y, media.width, media.height);
|
|
27
|
+
page.setTrimBox(media.x + inset, media.y + inset, media.width - 2 * inset, media.height - 2 * inset);
|
|
28
|
+
}
|
|
29
|
+
return Buffer.from(await doc.save());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { stampPdfBoxes };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { PDFArray, PDFDict, PDFName, PDFNumber, PDFRawStream, PDFRef, decodePDFRawStream } from "pdf-lib";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/download-files/dist/pdf-image-placements.js
|
|
4
|
+
const IDENTITY = [
|
|
5
|
+
1,
|
|
6
|
+
0,
|
|
7
|
+
0,
|
|
8
|
+
1,
|
|
9
|
+
0,
|
|
10
|
+
0
|
|
11
|
+
];
|
|
12
|
+
function multiply(m, n) {
|
|
13
|
+
return [
|
|
14
|
+
m[0] * n[0] + m[1] * n[2],
|
|
15
|
+
m[0] * n[1] + m[1] * n[3],
|
|
16
|
+
m[2] * n[0] + m[3] * n[2],
|
|
17
|
+
m[2] * n[1] + m[3] * n[3],
|
|
18
|
+
m[4] * n[0] + m[5] * n[2] + n[4],
|
|
19
|
+
m[4] * n[1] + m[5] * n[3] + n[5]
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
var UnfollowableContent = class extends Error {};
|
|
23
|
+
const WHITESPACE = /* @__PURE__ */ new Set([
|
|
24
|
+
0,
|
|
25
|
+
9,
|
|
26
|
+
10,
|
|
27
|
+
12,
|
|
28
|
+
13,
|
|
29
|
+
32
|
|
30
|
+
]);
|
|
31
|
+
const DELIMITERS = /* @__PURE__ */ new Set([
|
|
32
|
+
40,
|
|
33
|
+
41,
|
|
34
|
+
60,
|
|
35
|
+
62,
|
|
36
|
+
91,
|
|
37
|
+
93,
|
|
38
|
+
123,
|
|
39
|
+
125,
|
|
40
|
+
47,
|
|
41
|
+
37
|
|
42
|
+
]);
|
|
43
|
+
const KEYWORD_OPERANDS = /* @__PURE__ */ new Set([
|
|
44
|
+
"true",
|
|
45
|
+
"false",
|
|
46
|
+
"null"
|
|
47
|
+
]);
|
|
48
|
+
function isRegular(byte) {
|
|
49
|
+
return !WHITESPACE.has(byte) && !DELIMITERS.has(byte);
|
|
50
|
+
}
|
|
51
|
+
function* contentOperations(content) {
|
|
52
|
+
let operands = [];
|
|
53
|
+
let i = 0;
|
|
54
|
+
while (i < content.length) {
|
|
55
|
+
const byte = content[i];
|
|
56
|
+
if (WHITESPACE.has(byte)) i += 1;
|
|
57
|
+
else if (byte === 37) while (i < content.length && content[i] !== 10 && content[i] !== 13) i += 1;
|
|
58
|
+
else if (byte === 40) {
|
|
59
|
+
let depth = 0;
|
|
60
|
+
do {
|
|
61
|
+
const c = content[i];
|
|
62
|
+
if (c === 92) i += 1;
|
|
63
|
+
else if (c === 40) depth += 1;
|
|
64
|
+
else if (c === 41) depth -= 1;
|
|
65
|
+
i += 1;
|
|
66
|
+
} while (depth > 0 && i < content.length);
|
|
67
|
+
operands.push(null);
|
|
68
|
+
} else if (byte === 60 && content[i + 1] === 60) {
|
|
69
|
+
i += 2;
|
|
70
|
+
operands.push(null);
|
|
71
|
+
} else if (byte === 62 && content[i + 1] === 62) {
|
|
72
|
+
i += 2;
|
|
73
|
+
operands.push(null);
|
|
74
|
+
} else if (byte === 60) {
|
|
75
|
+
while (i < content.length && content[i] !== 62) i += 1;
|
|
76
|
+
i += 1;
|
|
77
|
+
operands.push(null);
|
|
78
|
+
} else if (byte === 91 || byte === 93 || byte === 123 || byte === 125 || byte === 41 || byte === 62) {
|
|
79
|
+
i += 1;
|
|
80
|
+
operands.push(null);
|
|
81
|
+
} else if (byte === 47) {
|
|
82
|
+
const start = i;
|
|
83
|
+
i += 1;
|
|
84
|
+
while (i < content.length && isRegular(content[i])) i += 1;
|
|
85
|
+
operands.push(Buffer.from(content.subarray(start, i)).toString("latin1"));
|
|
86
|
+
} else {
|
|
87
|
+
const start = i;
|
|
88
|
+
while (i < content.length && isRegular(content[i])) i += 1;
|
|
89
|
+
const word = Buffer.from(content.subarray(start, i)).toString("latin1");
|
|
90
|
+
const number = Number(word);
|
|
91
|
+
if (word !== "" && Number.isFinite(number) && /^[+-]?(\d+\.?\d*|\.\d+)$/.test(word)) operands.push(number);
|
|
92
|
+
else if (KEYWORD_OPERANDS.has(word)) operands.push(null);
|
|
93
|
+
else {
|
|
94
|
+
if (word === "BI") throw new UnfollowableContent("inline image in content stream");
|
|
95
|
+
yield {
|
|
96
|
+
operator: word,
|
|
97
|
+
operands
|
|
98
|
+
};
|
|
99
|
+
operands = [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function numberOf(object) {
|
|
105
|
+
return object instanceof PDFNumber ? object.asNumber() : void 0;
|
|
106
|
+
}
|
|
107
|
+
function streamContent(stream) {
|
|
108
|
+
return decodePDFRawStream(stream).decode();
|
|
109
|
+
}
|
|
110
|
+
const MAX_FORM_DEPTH = 32;
|
|
111
|
+
function measureImagePlacements(doc) {
|
|
112
|
+
const context = doc.context;
|
|
113
|
+
const largest = /* @__PURE__ */ new Map();
|
|
114
|
+
const walkedXObjectDicts = /* @__PURE__ */ new Set();
|
|
115
|
+
function walk(content, resources, start, depth) {
|
|
116
|
+
if (depth > MAX_FORM_DEPTH) throw new UnfollowableContent("form XObject nesting too deep");
|
|
117
|
+
const xobjects = resources ? context.lookupMaybe(resources.get(PDFName.of("XObject")), PDFDict) : void 0;
|
|
118
|
+
if (xobjects) walkedXObjectDicts.add(xobjects);
|
|
119
|
+
let ctm = start;
|
|
120
|
+
const saved = [];
|
|
121
|
+
for (const { operator, operands } of contentOperations(content)) if (operator === "q") saved.push(ctm);
|
|
122
|
+
else if (operator === "Q") ctm = saved.pop() ?? start;
|
|
123
|
+
else if (operator === "cm") {
|
|
124
|
+
const m = operands.slice(-6);
|
|
125
|
+
if (m.length !== 6 || m.some((v) => typeof v !== "number")) throw new UnfollowableContent("malformed cm");
|
|
126
|
+
ctm = multiply(m, ctm);
|
|
127
|
+
} else if (operator === "Do") {
|
|
128
|
+
const name = operands.at(-1);
|
|
129
|
+
if (typeof name !== "string" || !xobjects) continue;
|
|
130
|
+
const ref = xobjects.get(PDFName.of(name.slice(1)));
|
|
131
|
+
const xobject = context.lookup(ref);
|
|
132
|
+
if (!(ref instanceof PDFRef) || !(xobject instanceof PDFRawStream)) continue;
|
|
133
|
+
const subtype = xobject.dict.get(PDFName.of("Subtype"));
|
|
134
|
+
if (subtype === PDFName.of("Image")) {
|
|
135
|
+
const key = ref.toString();
|
|
136
|
+
const widthPt = Math.hypot(ctm[0], ctm[1]);
|
|
137
|
+
const heightPt = Math.hypot(ctm[2], ctm[3]);
|
|
138
|
+
const prior = largest.get(key);
|
|
139
|
+
largest.set(key, {
|
|
140
|
+
widthPt: Math.max(prior?.widthPt ?? 0, widthPt),
|
|
141
|
+
heightPt: Math.max(prior?.heightPt ?? 0, heightPt)
|
|
142
|
+
});
|
|
143
|
+
} else if (subtype === PDFName.of("Form")) {
|
|
144
|
+
const matrix = context.lookupMaybe(xobject.dict.get(PDFName.of("Matrix")), PDFArray);
|
|
145
|
+
const formMatrix = matrix ? matrix.asArray().map((v) => numberOf(context.lookup(v)) ?? 0) : IDENTITY;
|
|
146
|
+
const formResources = context.lookupMaybe(xobject.dict.get(PDFName.of("Resources")), PDFDict) ?? resources;
|
|
147
|
+
walk(streamContent(xobject), formResources, multiply(formMatrix, ctm), depth + 1);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
for (const page of doc.getPages()) {
|
|
153
|
+
const contents = page.node.Contents();
|
|
154
|
+
const parts = (contents instanceof PDFArray ? contents.asArray().map((ref) => context.lookup(ref)) : [contents]).filter((s) => s instanceof PDFRawStream).map((s) => streamContent(s));
|
|
155
|
+
walk(Buffer.concat(parts.flatMap((p) => [Buffer.from(p), Buffer.from("\n")])), page.node.Resources(), IDENTITY, 0);
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof UnfollowableContent) return {
|
|
159
|
+
largest: /* @__PURE__ */ new Map(),
|
|
160
|
+
unmeasured: /* @__PURE__ */ new Set(),
|
|
161
|
+
complete: false
|
|
162
|
+
};
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
largest,
|
|
167
|
+
unmeasured: imagesNamedOutside(doc, walkedXObjectDicts),
|
|
168
|
+
complete: true
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function imagesNamedOutside(doc, walked) {
|
|
172
|
+
const context = doc.context;
|
|
173
|
+
const unmeasured = /* @__PURE__ */ new Set();
|
|
174
|
+
const visited = /* @__PURE__ */ new Set();
|
|
175
|
+
function visit(object) {
|
|
176
|
+
if (object === void 0 || visited.has(object)) return;
|
|
177
|
+
visited.add(object);
|
|
178
|
+
if (object instanceof PDFRawStream) visit(object.dict);
|
|
179
|
+
else if (object instanceof PDFArray) for (const element of object.asArray()) visit(element);
|
|
180
|
+
else if (object instanceof PDFDict) {
|
|
181
|
+
const xobjects = context.lookupMaybe(object.get(PDFName.of("XObject")), PDFDict);
|
|
182
|
+
if (xobjects && !walked.has(xobjects)) for (const [, ref] of xobjects.entries()) {
|
|
183
|
+
const target = context.lookup(ref);
|
|
184
|
+
if (ref instanceof PDFRef && target instanceof PDFRawStream && target.dict.get(PDFName.of("Subtype")) === PDFName.of("Image")) unmeasured.add(ref.toString());
|
|
185
|
+
}
|
|
186
|
+
for (const [, value] of object.entries()) visit(value);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const [, object] of context.enumerateIndirectObjects()) visit(object);
|
|
190
|
+
return unmeasured;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { contentOperations, measureImagePlacements };
|