@homepages/concrete 1.0.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 +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { resolveFormatGeometry } from "./geometry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/format-geometry/dist/capture.js
|
|
4
|
+
/**
|
|
5
|
+
* The frame shell's root class — the static half of the frame contract, laid
|
|
6
|
+
* out and clipped by the authoring kit's base stylesheet. Shared so a canvas
|
|
7
|
+
* host or a capturing worker can stamp the identical class on its own page
|
|
8
|
+
* root and resolve the frame from the same stylesheet the captured page uses.
|
|
9
|
+
*/
|
|
10
|
+
const FRAME_ROOT_CLASS = "tr-frame";
|
|
11
|
+
/** The frame shell's per-format tokens: trim box + bleed, exact CSS px. */
|
|
12
|
+
function frameTokens(format) {
|
|
13
|
+
const geometry = resolveFormatGeometry(format);
|
|
14
|
+
return {
|
|
15
|
+
"--frame-w": `${geometry.frameWidth}px`,
|
|
16
|
+
"--frame-h": `${geometry.frameHeight}px`,
|
|
17
|
+
"--frame-bleed": `${geometry.bleed}px`
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The viewport a capturer opens for a format: the bleed box rounded to whole
|
|
22
|
+
* CSS px (a browser viewport holds no fraction; the shell's `overflow: clip`
|
|
23
|
+
* absorbs the sub-pixel slack) at the format's device scale factor.
|
|
24
|
+
*/
|
|
25
|
+
function captureViewport(format) {
|
|
26
|
+
const geometry = resolveFormatGeometry(format);
|
|
27
|
+
return {
|
|
28
|
+
width: Math.round(geometry.viewportWidth),
|
|
29
|
+
height: Math.round(geometry.viewportHeight),
|
|
30
|
+
deviceScaleFactor: geometry.deviceScaleFactor
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The printed paper size for a document format: the bleed box as exact CSS
|
|
35
|
+
* inch strings. Inches are the lossless unit here — a browser driver converts
|
|
36
|
+
* them to PDF points at exactly 72/in, so the emitted page boxes carry the
|
|
37
|
+
* declared physical geometry verbatim (they equal the resolved
|
|
38
|
+
* `pointWidth`/`pointHeight`).
|
|
39
|
+
*/
|
|
40
|
+
function printPageSize(format) {
|
|
41
|
+
const geometry = resolveFormatGeometry(format);
|
|
42
|
+
return {
|
|
43
|
+
width: `${geometry.pointWidth / 72}in`,
|
|
44
|
+
height: `${geometry.pointHeight / 72}in`
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The navigation wait a capturer passes to its browser driver. `"load"`, not
|
|
49
|
+
* `"networkidle"`: a dev host keeps a live event stream open, so network idle
|
|
50
|
+
* never arrives there, and the load event already covers every static asset.
|
|
51
|
+
*/
|
|
52
|
+
const CAPTURE_WAIT_UNTIL = "load";
|
|
53
|
+
/**
|
|
54
|
+
* The in-page expression a capturer awaits after {@link CAPTURE_WAIT_UNTIL}
|
|
55
|
+
* before shooting. The load event is not the settle point: web fonts may still
|
|
56
|
+
* swap in after it, and an image whose bytes have arrived may still be
|
|
57
|
+
* decoding — a capture taken mid-swap is a layout the shell never showed a
|
|
58
|
+
* user, and one taken mid-decode ships a blank or half-painted region. So,
|
|
59
|
+
* in order: fonts settled, every image un-deferred, then a decode of every
|
|
60
|
+
* `<img>` on the page, then one `requestAnimationFrame` tick to flush the
|
|
61
|
+
* layout those swaps produced.
|
|
62
|
+
*
|
|
63
|
+
* The un-deferring step is load-bearing, not tidying. A capturer opens ONE
|
|
64
|
+
* viewport over a document that is routinely taller than it: a frame shell
|
|
65
|
+
* clips at the format's box, and a print document stacks every page into one
|
|
66
|
+
* window. A browser never starts a `loading="lazy"` image outside that
|
|
67
|
+
* viewport, and a decode of an image whose fetch was never started never
|
|
68
|
+
* settles — so a single lazy image below the fold hangs the capture forever
|
|
69
|
+
* instead of shooting it. Image primitives default to lazy (it is the right
|
|
70
|
+
* default for a published page), which puts every clipped or off-page photo
|
|
71
|
+
* in that state. Promoting them to `eager` first makes the wait total and
|
|
72
|
+
* terminating; the capture page is discarded after the shot, so the mutation
|
|
73
|
+
* costs nothing and is invisible to the artifact.
|
|
74
|
+
*
|
|
75
|
+
* A decode that fails rejects the whole expression and so **fails the
|
|
76
|
+
* capture** — a broken image is a defect to surface, not a hole to ship — and
|
|
77
|
+
* the message names the offending URL. Every capture surface awaits this one
|
|
78
|
+
* string (CLI screenshot, print preview, View live, `check`, the render
|
|
79
|
+
* worker), so the playground preview cannot drift from the shipped artifact.
|
|
80
|
+
*
|
|
81
|
+
* This readiness pair is one leg of the settle, not the whole of it: every
|
|
82
|
+
* page also waits out network quiescence afterwards, and a page that ships
|
|
83
|
+
* islands hydrates before it and gets a paint-grace beat after; see
|
|
84
|
+
* {@link settleCapture} for the order.
|
|
85
|
+
*
|
|
86
|
+
* Typed `string`, not the inferred literal: the expression is a program, and
|
|
87
|
+
* its literal type would put the whole escaped source in every signature that
|
|
88
|
+
* names it — including the kit's generated reference page — while telling a
|
|
89
|
+
* consumer nothing the prose above does not. Nothing may branch on its text.
|
|
90
|
+
*/
|
|
91
|
+
const CAPTURE_READY_EXPRESSION = `(async () => {
|
|
92
|
+
await document.fonts.ready;
|
|
93
|
+
for (const img of document.images) {
|
|
94
|
+
if (img.loading === "lazy") img.loading = "eager";
|
|
95
|
+
}
|
|
96
|
+
await Promise.all(
|
|
97
|
+
Array.from(document.images, async (img) => {
|
|
98
|
+
try {
|
|
99
|
+
await img.decode();
|
|
100
|
+
} catch (cause) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"capture blocked: an <img> failed to decode — " +
|
|
103
|
+
(img.currentSrc || img.getAttribute("src") || "(no src)"),
|
|
104
|
+
{ cause },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
await new Promise((resolve) => {
|
|
110
|
+
requestAnimationFrame(() => resolve(undefined));
|
|
111
|
+
});
|
|
112
|
+
})()`;
|
|
113
|
+
/**
|
|
114
|
+
* The in-page test for "this page ships islands" — the presence of one island
|
|
115
|
+
* marker. It is the derived signal the whole widening branches on: markers are
|
|
116
|
+
* what the renderer emits for an island and what the loader hydrates, so a page
|
|
117
|
+
* with none has no runtime, nothing to mount, and nothing to wait for. A
|
|
118
|
+
* capturer that finds this false runs {@link CAPTURE_READY_EXPRESSION} and
|
|
119
|
+
* nothing else — an island-free page's settle is byte-identical to what it was
|
|
120
|
+
* before islands existed.
|
|
121
|
+
*
|
|
122
|
+
* The attribute is spelled out rather than imported from the island runtime:
|
|
123
|
+
* this module sits below it and is inlined into published packages, and a
|
|
124
|
+
* capture constant may not drag a browser loader into their graphs.
|
|
125
|
+
*/
|
|
126
|
+
const CAPTURE_HAS_ISLANDS_EXPRESSION = `!!document.querySelector("[data-tr-island]")`;
|
|
127
|
+
/**
|
|
128
|
+
* The window property an island-bearing page's host publishes: a promise that
|
|
129
|
+
* settles when every island the host set out to hydrate has mounted. This is
|
|
130
|
+
* the island runtime's own mount tracking, surfaced — not a per-island export
|
|
131
|
+
* (the design rejects those) and not a heuristic the capturer invents.
|
|
132
|
+
*
|
|
133
|
+
* Published by the HOST that runs the loader, because only the host knows what
|
|
134
|
+
* it asked the loader to do: the CLI dev bootstrap and the render worker's
|
|
135
|
+
* shell each set it around their own `hydrateIslands` call. A rejected promise
|
|
136
|
+
* fails the capture — an island that threw paints nothing, and a hole is a
|
|
137
|
+
* defect to surface rather than to ship.
|
|
138
|
+
*/
|
|
139
|
+
const CAPTURE_ISLANDS_READY_GLOBAL = "__trIslandsReady";
|
|
140
|
+
/**
|
|
141
|
+
* The in-page expression for the hydration leg: await the host's readiness
|
|
142
|
+
* promise. A page carrying markers but no such promise is a broken host (a
|
|
143
|
+
* shell that shipped markers without the runtime), and it fails the capture
|
|
144
|
+
* saying so rather than shooting the un-hydrated server frames — which look
|
|
145
|
+
* plausible and are the wrong pixels.
|
|
146
|
+
*/
|
|
147
|
+
const CAPTURE_ISLANDS_READY_EXPRESSION = `(async () => {
|
|
148
|
+
const ready = window.${CAPTURE_ISLANDS_READY_GLOBAL};
|
|
149
|
+
if (ready === undefined) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
"capture blocked: the page ships island markers but its host published no " +
|
|
152
|
+
"window.${CAPTURE_ISLANDS_READY_GLOBAL} — the island runtime never ran",
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
await ready;
|
|
156
|
+
})()`;
|
|
157
|
+
/**
|
|
158
|
+
* The in-page diagnostic a capturer reads when the hydration leg times out:
|
|
159
|
+
* how many capture holds are still open, and which islands the page carries —
|
|
160
|
+
* the difference between "the runtime never ran" and "an island took a hold
|
|
161
|
+
* and never released it". The holds global is spelled out rather than
|
|
162
|
+
* imported for the same layering reason the marker attribute above is; the
|
|
163
|
+
* settle test asserts both spellings against the runtime's own constants.
|
|
164
|
+
*/
|
|
165
|
+
const CAPTURE_ISLANDS_DIAGNOSTIC_EXPRESSION = `(() => {
|
|
166
|
+
const holds = window.__trCaptureHolds;
|
|
167
|
+
const keys = [...new Set(Array.from(
|
|
168
|
+
document.querySelectorAll("[data-tr-island]"),
|
|
169
|
+
(el) => el.getAttribute("data-tr-island"),
|
|
170
|
+
))];
|
|
171
|
+
return JSON.stringify({ openHolds: holds ? holds.size : 0, islands: keys });
|
|
172
|
+
})()`;
|
|
173
|
+
/**
|
|
174
|
+
* How long the page must produce no request activity before the network is
|
|
175
|
+
* called quiescent. Observed HOST-side (the driver below subscribes to the
|
|
176
|
+
* browser's own request events) rather than through an in-page or driver-level
|
|
177
|
+
* network-idle wait: a dev host keeps a live event stream open for the life of
|
|
178
|
+
* the page, so a definition resting on "no connections are open" never arrives
|
|
179
|
+
* there. "Nothing has started or finished for a while" is true on both hosts.
|
|
180
|
+
*
|
|
181
|
+
* The island half of the name records the design that introduced the leg; the
|
|
182
|
+
* wait itself runs for EVERY captured page — it is what makes "a failed
|
|
183
|
+
* external request is the defect" a sound contract, since a request still in
|
|
184
|
+
* flight at shot time is neither failed nor painted.
|
|
185
|
+
*/
|
|
186
|
+
const CAPTURE_ISLAND_QUIET_WINDOW_MS = 500;
|
|
187
|
+
/**
|
|
188
|
+
* The paint-grace beat after quiescence: an engine that has all its bytes is
|
|
189
|
+
* still animating them in (a map's tile and symbol fades are ~300ms), and those
|
|
190
|
+
* frames are the difference between the artifact and a half-transparent one.
|
|
191
|
+
* Bounded and unconditional — there is no cross-engine "done fading" signal to
|
|
192
|
+
* derive, so this is the design's one deliberate constant beat.
|
|
193
|
+
*/
|
|
194
|
+
const CAPTURE_ISLAND_PAINT_GRACE_MS = 400;
|
|
195
|
+
/**
|
|
196
|
+
* The ceiling on each widened-settle leg. A page that never hydrates or never
|
|
197
|
+
* goes quiet fails the capture NAMING the leg it died on, rather than being
|
|
198
|
+
* shot mid-paint: a truncated artifact reaches a customer looking finished,
|
|
199
|
+
* while a failed job is a defect someone can act on.
|
|
200
|
+
*/
|
|
201
|
+
const CAPTURE_ISLAND_SETTLE_TIMEOUT_MS = 15e3;
|
|
202
|
+
/**
|
|
203
|
+
* The in-page tail of the island settle: the paint-grace beat, then one
|
|
204
|
+
* `requestAnimationFrame` tick so the frames it bought are flushed to the
|
|
205
|
+
* compositor before the shot.
|
|
206
|
+
*/
|
|
207
|
+
const CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION = `(async () => {
|
|
208
|
+
await new Promise((resolve) => {
|
|
209
|
+
setTimeout(resolve, ${400});
|
|
210
|
+
});
|
|
211
|
+
await new Promise((resolve) => {
|
|
212
|
+
requestAnimationFrame(() => resolve(undefined));
|
|
213
|
+
});
|
|
214
|
+
})()`;
|
|
215
|
+
/**
|
|
216
|
+
* How many finish-and-look-again passes {@link CAPTURE_ANIMATIONS_SETTLED_EXPRESSION}
|
|
217
|
+
* makes. A chain is normally one deep (a stagger sets every delay up front and
|
|
218
|
+
* needs no pass at all); the ceiling is what keeps a page whose animations
|
|
219
|
+
* restart each other from spinning in the settle.
|
|
220
|
+
*/
|
|
221
|
+
const CAPTURE_ANIMATION_SETTLE_PASSES = 5;
|
|
222
|
+
/**
|
|
223
|
+
* The in-page program that lands every finite animation on its END state:
|
|
224
|
+
* `Animation.finish()` over `document.getAnimations()`, repeated until a pass
|
|
225
|
+
* finds nothing left running, then a frame to flush what that changed.
|
|
226
|
+
*
|
|
227
|
+
* An entrance animation's end state IS the page — the fade-in exists for a
|
|
228
|
+
* reader arriving at the content, and an artifact has no arrival. Fast-forward
|
|
229
|
+
* rather than wait: waiting out a 900ms fade plus its stagger makes the shot
|
|
230
|
+
* depend on how the machine was loaded that second, and a shot that lands one
|
|
231
|
+
* frame early ships half-transparent content at HTTP 200. Finishing is exact,
|
|
232
|
+
* costs nothing, and is the same pixels the wait was hoping for. The repeat
|
|
233
|
+
* covers a chain — an animation started from another's `animationend` — and is
|
|
234
|
+
* bounded, so a page whose animations restart each other cannot spin here.
|
|
235
|
+
*
|
|
236
|
+
* INFINITE animations are left alone: `finish()` on one throws and there is no
|
|
237
|
+
* end state to land on. Nothing downstream resolves them either — a looping
|
|
238
|
+
* decoration is captured mid-loop, at whatever frame the shutter found, and
|
|
239
|
+
* that is the accepted outcome rather than a defect any gate reports. Cancelled
|
|
240
|
+
* or already finished animations are skipped for the same reason — nothing to
|
|
241
|
+
* do.
|
|
242
|
+
*
|
|
243
|
+
* Runs for every captured page, island-bearing or not: a pure-CSS load reveal
|
|
244
|
+
* needs this exactly as much as one an island triggers, and it is a no-op on a
|
|
245
|
+
* page that animates nothing.
|
|
246
|
+
*/
|
|
247
|
+
const CAPTURE_ANIMATIONS_SETTLED_EXPRESSION = `(async () => {
|
|
248
|
+
const frame = () => new Promise((resolve) => {
|
|
249
|
+
requestAnimationFrame(() => resolve(undefined));
|
|
250
|
+
});
|
|
251
|
+
for (let pass = 0; pass < ${5}; pass += 1) {
|
|
252
|
+
const running = document.getAnimations().filter((animation) => {
|
|
253
|
+
if (animation.playState === "finished" || animation.playState === "idle") return false;
|
|
254
|
+
const timing = animation.effect && animation.effect.getComputedTiming();
|
|
255
|
+
return !!timing && Number.isFinite(Number(timing.endTime));
|
|
256
|
+
});
|
|
257
|
+
if (running.length === 0) break;
|
|
258
|
+
for (const animation of running) {
|
|
259
|
+
try {
|
|
260
|
+
animation.finish();
|
|
261
|
+
} catch {
|
|
262
|
+
// Nothing to land on (an infinite or unfinishable animation) — leave it.
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
await frame();
|
|
266
|
+
}
|
|
267
|
+
await frame();
|
|
268
|
+
})()`;
|
|
269
|
+
function legTimeout(leg) {
|
|
270
|
+
return /* @__PURE__ */ new Error(`capture blocked: ${leg} did not settle within ${CAPTURE_ISLAND_SETTLE_TIMEOUT_MS}ms`);
|
|
271
|
+
}
|
|
272
|
+
/** Await `work` under the island-leg ceiling, failing with the leg's name. */
|
|
273
|
+
async function withLegTimeout(leg, work) {
|
|
274
|
+
let timer;
|
|
275
|
+
try {
|
|
276
|
+
return await Promise.race([work, new Promise((_resolve, reject) => {
|
|
277
|
+
timer = setTimeout(() => reject(legTimeout(leg)), CAPTURE_ISLAND_SETTLE_TIMEOUT_MS);
|
|
278
|
+
})]);
|
|
279
|
+
} finally {
|
|
280
|
+
if (timer) clearTimeout(timer);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The ceiling on the diagnostic read itself. A hydration-leg timeout is
|
|
285
|
+
* exactly the page a wedged main thread produces, and that same wedge blocks
|
|
286
|
+
* an `evaluate()` call as surely as it blocked hydration — so the read that is
|
|
287
|
+
* meant to explain the failure cannot itself be allowed to hang the capture.
|
|
288
|
+
*/
|
|
289
|
+
const CAPTURE_ISLANDS_DIAGNOSTIC_TIMEOUT_MS = 2e3;
|
|
290
|
+
/**
|
|
291
|
+
* Append the page's island diagnostic to a hydration-leg timeout. Best-effort:
|
|
292
|
+
* a page too broken to evaluate — or too wedged to finish the read within
|
|
293
|
+
* {@link CAPTURE_ISLANDS_DIAGNOSTIC_TIMEOUT_MS} — keeps the original error
|
|
294
|
+
* untouched.
|
|
295
|
+
*/
|
|
296
|
+
async function withIslandDiagnostic(host, error) {
|
|
297
|
+
if (!(error instanceof Error) || !error.message.includes("island hydration")) return error;
|
|
298
|
+
let timer;
|
|
299
|
+
try {
|
|
300
|
+
const raw = await Promise.race([host.evaluate(CAPTURE_ISLANDS_DIAGNOSTIC_EXPRESSION), new Promise((_resolve, reject) => {
|
|
301
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("diagnostic read timed out")), CAPTURE_ISLANDS_DIAGNOSTIC_TIMEOUT_MS);
|
|
302
|
+
})]);
|
|
303
|
+
const parsed = JSON.parse(String(raw));
|
|
304
|
+
return new Error(`${error.message} — ${String(parsed.openHolds)} capture hold${parsed.openHolds === 1 ? "" : "s"} still open (islands on this page: ${parsed.islands.join(", ")})`, { cause: error });
|
|
305
|
+
} catch {
|
|
306
|
+
return error;
|
|
307
|
+
} finally {
|
|
308
|
+
if (timer) clearTimeout(timer);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Resolve once the page has produced no request activity for
|
|
313
|
+
* {@link CAPTURE_ISLAND_QUIET_WINDOW_MS}; reject on the leg ceiling. The quiet
|
|
314
|
+
* window is armed immediately, so a page that never requests anything settles
|
|
315
|
+
* after one window rather than waiting for an event that will not come.
|
|
316
|
+
*/
|
|
317
|
+
function awaitNetworkQuiescence(host) {
|
|
318
|
+
return new Promise((resolve, reject) => {
|
|
319
|
+
let quiet;
|
|
320
|
+
let ceiling;
|
|
321
|
+
let unsubscribe;
|
|
322
|
+
const finish = (err) => {
|
|
323
|
+
if (quiet) clearTimeout(quiet);
|
|
324
|
+
if (ceiling) clearTimeout(ceiling);
|
|
325
|
+
unsubscribe?.();
|
|
326
|
+
if (err) reject(err);
|
|
327
|
+
else resolve();
|
|
328
|
+
};
|
|
329
|
+
const arm = () => {
|
|
330
|
+
if (quiet) clearTimeout(quiet);
|
|
331
|
+
quiet = setTimeout(() => finish(), 500);
|
|
332
|
+
};
|
|
333
|
+
ceiling = setTimeout(() => finish(legTimeout("network quiescence")), CAPTURE_ISLAND_SETTLE_TIMEOUT_MS);
|
|
334
|
+
unsubscribe = host.onNetworkActivity(arm);
|
|
335
|
+
arm();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The in-page tail of an island-free settle: one `requestAnimationFrame` tick,
|
|
340
|
+
* so anything the quiescence window let arrive is flushed to the compositor
|
|
341
|
+
* before the shot. The island tail is {@link CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION},
|
|
342
|
+
* which buys the engine's fades first — an island-free page has no engine to
|
|
343
|
+
* fade, so it skips straight to the flush.
|
|
344
|
+
*/
|
|
345
|
+
const CAPTURE_RAF_FLUSH_EXPRESSION = `(async () => {
|
|
346
|
+
await new Promise((resolve) => {
|
|
347
|
+
requestAnimationFrame(() => resolve(undefined));
|
|
348
|
+
});
|
|
349
|
+
})()`;
|
|
350
|
+
/**
|
|
351
|
+
* The whole capture settle, for every surface that shoots a page: the CLI's
|
|
352
|
+
* screenshot and print-preview routes and the render worker. One function
|
|
353
|
+
* rather than a recipe each host retypes, because the legs and their ORDER are
|
|
354
|
+
* the contract — a surface that waits differently flattens different pixels
|
|
355
|
+
* than the artifact its preview promised.
|
|
356
|
+
*
|
|
357
|
+
* Every page gets, in order:
|
|
358
|
+
*
|
|
359
|
+
* 1. **hydration complete** — island pages only. The host's readiness promise,
|
|
360
|
+
* FIRST, before the font/decode pass below: an island's DOM does not exist
|
|
361
|
+
* until it mounts, so a decode pass run before hydration measures a document
|
|
362
|
+
* the artifact will not contain, and every image an island renders would go
|
|
363
|
+
* unwaited.
|
|
364
|
+
* 2. **fonts, images, rAF** — the standing readiness pair, over the (hydrated)
|
|
365
|
+
* DOM.
|
|
366
|
+
* 3. **network quiescence** — host-observed, for whatever the page is still
|
|
367
|
+
* fetching: an island's tiles and glyph ranges, or a stylesheet's own
|
|
368
|
+
* off-origin refs, which no other leg waits for (a `background-image` is in
|
|
369
|
+
* no decode pass). Unconditional, because the egress contract — a FAILED
|
|
370
|
+
* external request fails the job — is only sound once nothing is still in
|
|
371
|
+
* flight. It is a wait for *activity to stop*, not a proof that what arrived
|
|
372
|
+
* is painted, and it detects nothing about a decoded image failing to raster
|
|
373
|
+
* — that class is contention between browsers over one machine, and no
|
|
374
|
+
* amount of settling reaches it.
|
|
375
|
+
* 4. **animations landed** — every finite animation fast-forwarded to its end
|
|
376
|
+
* state. Unconditional, and AFTER quiescence: a reveal fires at hydration,
|
|
377
|
+
* but a load reveal is pure CSS and an island-free page has them too. This
|
|
378
|
+
* is the leg that decides what a scroll-driven reveal contributes to the
|
|
379
|
+
* artifact, together with {@link CAPTURE_IN_VIEW_SCRIPT}, which is what made
|
|
380
|
+
* it fire at all.
|
|
381
|
+
* 5. **paint grace + rAF flush** — an island engine's own fades, then the tick
|
|
382
|
+
* that puts them on screen. An island-free page has no engine to fade and
|
|
383
|
+
* takes only the flush. The grace stays a constant beat because a canvas
|
|
384
|
+
* engine's fades are its own, painted outside the animation timeline leg 4
|
|
385
|
+
* can reach.
|
|
386
|
+
*
|
|
387
|
+
* Legs 1 and 3 are bounded by {@link CAPTURE_ISLAND_SETTLE_TIMEOUT_MS} and
|
|
388
|
+
* fail naming themselves.
|
|
389
|
+
*/
|
|
390
|
+
async function settleCapture(host) {
|
|
391
|
+
const hasIslands = await host.evaluate(CAPTURE_HAS_ISLANDS_EXPRESSION) === true;
|
|
392
|
+
if (hasIslands) try {
|
|
393
|
+
await withLegTimeout("island hydration", host.evaluate(CAPTURE_ISLANDS_READY_EXPRESSION));
|
|
394
|
+
} catch (error) {
|
|
395
|
+
throw await withIslandDiagnostic(host, error);
|
|
396
|
+
}
|
|
397
|
+
await host.evaluate(CAPTURE_READY_EXPRESSION);
|
|
398
|
+
await awaitNetworkQuiescence(host);
|
|
399
|
+
await host.evaluate(CAPTURE_ANIMATIONS_SETTLED_EXPRESSION);
|
|
400
|
+
await host.evaluate(hasIslands ? CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION : CAPTURE_RAF_FLUSH_EXPRESSION);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
export { CAPTURE_ANIMATIONS_SETTLED_EXPRESSION, CAPTURE_HAS_ISLANDS_EXPRESSION, CAPTURE_ISLANDS_DIAGNOSTIC_EXPRESSION, CAPTURE_ISLANDS_READY_EXPRESSION, CAPTURE_ISLANDS_READY_GLOBAL, CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION, CAPTURE_ISLAND_SETTLE_TIMEOUT_MS, CAPTURE_READY_EXPRESSION, CAPTURE_WAIT_UNTIL, FRAME_ROOT_CLASS, captureViewport, frameTokens, printPageSize, settleCapture };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ContentCategory } from "../../template-contracts/dist/content-categories.js";
|
|
2
|
+
//#region ../../internal/format-geometry/dist/format.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A physical page dimension: a number immediately followed by the unit, "in"
|
|
5
|
+
* or "mm" (`"8.5in"`, `"210mm"`). No space, lowercase unit, positive.
|
|
6
|
+
*/
|
|
7
|
+
type PhysicalLength = `${number}in` | `${number}mm`;
|
|
8
|
+
/**
|
|
9
|
+
* What identifies a format independent of its geometry. `id` is the stable
|
|
10
|
+
* reference identity a deliverable stores, unique within the template; `label`
|
|
11
|
+
* is picker display text; `category` is curated browsing metadata; `preset` is
|
|
12
|
+
* a provenance tag naming the library entry this format's geometry matches —
|
|
13
|
+
* picker-only display, never pipeline-read.
|
|
14
|
+
*/
|
|
15
|
+
interface FormatIdentity {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly label: string;
|
|
18
|
+
readonly category: ContentCategory;
|
|
19
|
+
readonly preset?: string;
|
|
20
|
+
}
|
|
21
|
+
/** An image format renders at exactly its output pixels. */
|
|
22
|
+
type ImageFormat = FormatIdentity & {
|
|
23
|
+
readonly width: number;
|
|
24
|
+
readonly height: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A document format is either a pixel sheet (decks) or a physical print size
|
|
28
|
+
* with a capture `dpi` and optional `bleed`. The union keeps a physical width
|
|
29
|
+
* from ever pairing with a pixel height.
|
|
30
|
+
*/
|
|
31
|
+
type DocumentFormat = FormatIdentity & ({
|
|
32
|
+
readonly width: number;
|
|
33
|
+
readonly height: number;
|
|
34
|
+
} | {
|
|
35
|
+
readonly width: PhysicalLength;
|
|
36
|
+
readonly height: PhysicalLength;
|
|
37
|
+
readonly dpi: number;
|
|
38
|
+
readonly bleed?: PhysicalLength;
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { DocumentFormat, FormatIdentity, ImageFormat, PhysicalLength };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region ../../internal/format-geometry/dist/geometry.js
|
|
2
|
+
const CSS_PX_PER_INCH = 96;
|
|
3
|
+
const POINTS_PER_INCH = 72;
|
|
4
|
+
const MM_PER_INCH = 25.4;
|
|
5
|
+
const PHYSICAL_LENGTH_RE = /^(\d+(?:\.\d+)?)(in|mm)$/;
|
|
6
|
+
/** A physical length in inches. Throws on a malformed unit string. */
|
|
7
|
+
function toInches(length) {
|
|
8
|
+
const [, digits, unit] = PHYSICAL_LENGTH_RE.exec(length) ?? [];
|
|
9
|
+
if (digits === void 0 || unit === void 0) throw new Error(`malformed physical length: "${length}"`);
|
|
10
|
+
const value = Number.parseFloat(digits);
|
|
11
|
+
return unit === "mm" ? value / MM_PER_INCH : value;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Derive a rendered format's geometry. Physical dimensions resolve to CSS px
|
|
15
|
+
* at 96/in; pixel formats are their own viewport at scale factor 1. The
|
|
16
|
+
* website format has no geometry and never reaches this function.
|
|
17
|
+
*/
|
|
18
|
+
function resolveFormatGeometry(format) {
|
|
19
|
+
if (typeof format.width === "number" && typeof format.height === "number") return {
|
|
20
|
+
frameWidth: format.width,
|
|
21
|
+
frameHeight: format.height,
|
|
22
|
+
bleed: 0,
|
|
23
|
+
viewportWidth: format.width,
|
|
24
|
+
viewportHeight: format.height,
|
|
25
|
+
deviceScaleFactor: 1,
|
|
26
|
+
pixelWidth: format.width,
|
|
27
|
+
pixelHeight: format.height,
|
|
28
|
+
pointWidth: format.width / CSS_PX_PER_INCH * 72,
|
|
29
|
+
pointHeight: format.height / CSS_PX_PER_INCH * 72,
|
|
30
|
+
bleedPoints: 0
|
|
31
|
+
};
|
|
32
|
+
const physical = format;
|
|
33
|
+
const widthIn = toInches(physical.width);
|
|
34
|
+
const heightIn = toInches(physical.height);
|
|
35
|
+
const bleedIn = physical.bleed === void 0 ? 0 : toInches(physical.bleed);
|
|
36
|
+
const frameWidth = widthIn * CSS_PX_PER_INCH;
|
|
37
|
+
const frameHeight = heightIn * CSS_PX_PER_INCH;
|
|
38
|
+
const bleed = bleedIn * CSS_PX_PER_INCH;
|
|
39
|
+
const viewportWidth = frameWidth + 2 * bleed;
|
|
40
|
+
const viewportHeight = frameHeight + 2 * bleed;
|
|
41
|
+
const deviceScaleFactor = physical.dpi / CSS_PX_PER_INCH;
|
|
42
|
+
return {
|
|
43
|
+
frameWidth,
|
|
44
|
+
frameHeight,
|
|
45
|
+
bleed,
|
|
46
|
+
viewportWidth,
|
|
47
|
+
viewportHeight,
|
|
48
|
+
deviceScaleFactor,
|
|
49
|
+
pixelWidth: Math.round(viewportWidth * deviceScaleFactor),
|
|
50
|
+
pixelHeight: Math.round(viewportHeight * deviceScaleFactor),
|
|
51
|
+
pointWidth: (widthIn + 2 * bleedIn) * 72,
|
|
52
|
+
pointHeight: (heightIn + 2 * bleedIn) * 72,
|
|
53
|
+
bleedPoints: bleedIn * 72
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { resolveFormatGeometry };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { resolveFormatGeometry } from "./geometry.js";
|
|
2
|
+
import { CAPTURE_ANIMATIONS_SETTLED_EXPRESSION, CAPTURE_HAS_ISLANDS_EXPRESSION, CAPTURE_ISLANDS_READY_EXPRESSION, CAPTURE_ISLANDS_READY_GLOBAL, CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION, CAPTURE_ISLAND_SETTLE_TIMEOUT_MS, CAPTURE_READY_EXPRESSION, CAPTURE_WAIT_UNTIL, FRAME_ROOT_CLASS, captureViewport, frameTokens, printPageSize, settleCapture } from "./capture.js";
|
|
3
|
+
|
|
4
|
+
export { CAPTURE_ISLANDS_READY_GLOBAL, CAPTURE_WAIT_UNTIL, FRAME_ROOT_CLASS, captureViewport, frameTokens, printPageSize, settleCapture };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region ../../internal/image-descriptor/dist/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* One image format's candidate set within a `ResponsiveImage`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks Every rung in `srcset` is the same image in the same format at a
|
|
6
|
+
* different rendered width, ascending. It is a set of sizes to choose between,
|
|
7
|
+
* never a set of different images.
|
|
8
|
+
*/
|
|
9
|
+
interface ResponsiveSource {
|
|
10
|
+
/** Image MIME type: 'image/avif' | 'image/webp' | 'image/jpeg' | 'image/png'. */
|
|
11
|
+
type: string;
|
|
12
|
+
/** "<presigned-url> 320w, … 2048w" — rungs ascending by ACTUAL width. */
|
|
13
|
+
srcset: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The responsive rendition of one image: a candidate set per format, plus the intrinsic size of its largest rung.
|
|
17
|
+
*
|
|
18
|
+
* `width` and `height` describe the ceiling rung rather than the original
|
|
19
|
+
* upload, so a layout can reserve the correct aspect ratio before any image
|
|
20
|
+
* bytes arrive.
|
|
21
|
+
*
|
|
22
|
+
* @remarks `sources` is ordered by preference and a browser takes the first
|
|
23
|
+
* entry whose `type` it supports, so reordering it changes which format readers
|
|
24
|
+
* actually receive.
|
|
25
|
+
*/
|
|
26
|
+
interface ResponsiveImage {
|
|
27
|
+
/** Per-format candidate sets, ordered preferred→fallback: avif, webp, jpeg, png. */
|
|
28
|
+
sources: ResponsiveSource[];
|
|
29
|
+
/** Ceiling-rung (MAX edge) actual width — drives <img> width/aspect/sizes. */
|
|
30
|
+
width: number;
|
|
31
|
+
/** Ceiling-rung actual height. */
|
|
32
|
+
height: number;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ResponsiveImage, ResponsiveSource };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region ../../internal/image-ladder/dist/crop.js
|
|
2
|
+
/** The query parameter a cropped image URL carries. */
|
|
3
|
+
const CROP_PARAM = "crop";
|
|
4
|
+
/** Six decimals is finer than a pixel of any image the ladder serves, and keeps a URL stable across float noise. */
|
|
5
|
+
const round = (n) => String(Math.round(n * 1e6) / 1e6);
|
|
6
|
+
const clamp01 = (n) => Math.min(Math.max(n, 0), 1);
|
|
7
|
+
/** `url` serving only `rect` of the image. */
|
|
8
|
+
function croppedUrl(url, rect) {
|
|
9
|
+
const value = [
|
|
10
|
+
rect.nx,
|
|
11
|
+
rect.ny,
|
|
12
|
+
rect.nw,
|
|
13
|
+
rect.nh
|
|
14
|
+
].map(round).join(",");
|
|
15
|
+
return `${url}${url.includes("?") ? "&" : "?"}${CROP_PARAM}=${value}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The rect a `crop` query value names, clamped into the frame, or null when it names none
|
|
19
|
+
* a render could have minted: not four finite numbers, an empty region, or the whole image.
|
|
20
|
+
*/
|
|
21
|
+
function parseCropParam(value) {
|
|
22
|
+
const parts = value.split(",");
|
|
23
|
+
if (parts.length !== 4 || parts.some((part) => part.trim() === "")) return null;
|
|
24
|
+
const [nx, ny, nw, nh] = parts.map(Number);
|
|
25
|
+
if (![
|
|
26
|
+
nx,
|
|
27
|
+
ny,
|
|
28
|
+
nw,
|
|
29
|
+
nh
|
|
30
|
+
].every((n) => Number.isFinite(n))) return null;
|
|
31
|
+
const x = clamp01(nx);
|
|
32
|
+
const y = clamp01(ny);
|
|
33
|
+
const rect = {
|
|
34
|
+
nx: x,
|
|
35
|
+
ny: y,
|
|
36
|
+
nw: Math.min(clamp01(nw), 1 - x),
|
|
37
|
+
nh: Math.min(clamp01(nh), 1 - y)
|
|
38
|
+
};
|
|
39
|
+
if (rect.nw <= 0 || rect.nh <= 0) return null;
|
|
40
|
+
return rect.nx === 0 && rect.ny === 0 && rect.nw === 1 && rect.nh === 1 ? null : rect;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `rect` of an image's bytes, in its own format. The rect is over the ORIENTED frame, as
|
|
44
|
+
* the cropper drew it over the image the browser displayed, so EXIF orientation is applied
|
|
45
|
+
* before the region is measured.
|
|
46
|
+
*/
|
|
47
|
+
async function cutRegion(sharp, master, rect) {
|
|
48
|
+
const { format } = await sharp(master).metadata();
|
|
49
|
+
const { data, info } = await sharp(master).rotate().raw().toBuffer({ resolveWithObject: true });
|
|
50
|
+
const { width, height, channels } = info;
|
|
51
|
+
const left = Math.min(Math.max(Math.round(rect.nx * width), 0), width - 1);
|
|
52
|
+
const top = Math.min(Math.max(Math.round(rect.ny * height), 0), height - 1);
|
|
53
|
+
const region = {
|
|
54
|
+
left,
|
|
55
|
+
top,
|
|
56
|
+
width: Math.max(Math.min(Math.round(rect.nw * width), width - left), 1),
|
|
57
|
+
height: Math.max(Math.min(Math.round(rect.nh * height), height - top), 1)
|
|
58
|
+
};
|
|
59
|
+
const pipeline = sharp(data, { raw: {
|
|
60
|
+
width,
|
|
61
|
+
height,
|
|
62
|
+
channels
|
|
63
|
+
} }).extract(region);
|
|
64
|
+
if (format === "png") return {
|
|
65
|
+
bytes: await pipeline.png().toBuffer(),
|
|
66
|
+
contentType: "image/png"
|
|
67
|
+
};
|
|
68
|
+
if (format === "webp") return {
|
|
69
|
+
bytes: await pipeline.webp({ quality: 95 }).toBuffer(),
|
|
70
|
+
contentType: "image/webp"
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
bytes: await pipeline.jpeg({
|
|
74
|
+
quality: 95,
|
|
75
|
+
chromaSubsampling: "4:4:4"
|
|
76
|
+
}).toBuffer(),
|
|
77
|
+
contentType: "image/jpeg"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { CROP_PARAM, croppedUrl, cutRegion, parseCropParam };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
2
|
+
|
|
3
|
+
//#region ../../internal/image-ladder/dist/encode.js
|
|
4
|
+
async function encodeRung(srcBytes, edge, spec) {
|
|
5
|
+
const resized = sharp(srcBytes).resize(edge, edge, {
|
|
6
|
+
fit: "inside",
|
|
7
|
+
withoutEnlargement: true
|
|
8
|
+
});
|
|
9
|
+
const out = await spec.encode(resized).toBuffer();
|
|
10
|
+
const meta = await sharp(out).metadata();
|
|
11
|
+
return {
|
|
12
|
+
edge,
|
|
13
|
+
format: spec.format,
|
|
14
|
+
bytes: out,
|
|
15
|
+
width: meta.width ?? 0,
|
|
16
|
+
height: meta.height ?? 0,
|
|
17
|
+
contentType: spec.contentType,
|
|
18
|
+
ext: spec.ext
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { encodeRung };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LADDER, LADDER_CEILING, LADDER_POLICY_FINGERPRINT, formatPolicyFor, ladderVariantKey, policyFingerprint, rungsFor } from "./policy.js";
|
|
2
|
+
import { encodeRung } from "./encode.js";
|
|
3
|
+
|
|
4
|
+
export { LADDER, LADDER_CEILING, LADDER_POLICY_FINGERPRINT, encodeRung, formatPolicyFor, ladderVariantKey, policyFingerprint, rungsFor };
|