@homepages/concrete 5.0.0 → 6.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 +342 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +16 -0
- package/codemods/reads-replace-reconcile.mjs +285 -0
- package/dist/artifact/playground/client/assets/{index-D1fwOGVK.js → index-u3T7DiSN.js} +96 -96
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/host.mjs +23 -23
- package/dist/base.css +3 -8
- package/dist/browser/site-config.js +1 -16
- package/dist/browser/submit-lead.js +0 -31
- package/dist/cli/build/artifact.js +16 -23
- package/dist/cli/build/captures.js +0 -6
- package/dist/cli/build/esbuild.js +0 -17
- package/dist/cli/build/fixtures.js +15 -30
- package/dist/cli/build/icons.js +0 -3
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/build/playground.js +4 -8
- package/dist/cli/build/sections.js +9 -30
- package/dist/cli/build/source.js +52 -27
- package/dist/cli/build/static.js +4 -25
- package/dist/cli/capture/bundle.js +0 -9
- package/dist/cli/capture/capture-browser.js +0 -14
- package/dist/cli/capture/capture.js +1 -8
- package/dist/cli/check/analyze.js +2 -5
- package/dist/cli/check/index.js +1 -1
- package/dist/cli/check/line-endings.js +52 -0
- package/dist/cli/check/load-workspace.js +3 -8
- package/dist/cli/check/portable-names.js +48 -0
- package/dist/cli/check/render/class-conflicts.js +0 -5
- package/dist/cli/check/render/html.js +0 -1
- package/dist/cli/check/render/invariants.js +0 -5
- package/dist/cli/check/render/island-frames.js +0 -25
- package/dist/cli/check/render/marker-coverage.js +0 -20
- package/dist/cli/check/render/nav.js +0 -33
- package/dist/cli/check/report.js +0 -3
- package/dist/cli/check/stages/bundles.js +1 -9
- package/dist/cli/check/stages/composition.js +3 -2
- package/dist/cli/check/stages/dependencies.js +7 -38
- package/dist/cli/check/stages/fixtures.js +3 -31
- package/dist/cli/check/stages/lint.js +2 -2
- package/dist/cli/check/stages/logic.js +3 -34
- package/dist/cli/check/stages/relations.js +46 -0
- package/dist/cli/check/stages/render.js +0 -1
- package/dist/cli/check/stages/sections.js +3 -3
- package/dist/cli/check/stages/stylesheet.js +1 -1
- package/dist/cli/check/stages/typecheck.js +5 -11
- package/dist/cli/check/stages/workspace.js +36 -14
- package/dist/cli/commands.js +9 -56
- package/dist/cli/currency/cache.js +4 -17
- package/dist/cli/currency/decide.js +0 -14
- package/dist/cli/currency/opt-out.js +0 -7
- package/dist/cli/currency/preamble.js +3 -24
- package/dist/cli/currency/prompt.js +0 -1
- package/dist/cli/currency/refresh.js +5 -12
- package/dist/cli/currency/resolve-latest.js +3 -64
- package/dist/cli/currency/version-order.js +0 -12
- package/dist/cli/dev/crop.js +0 -2
- package/dist/cli/dev/http.js +0 -13
- package/dist/cli/dev/index.js +3 -4
- package/dist/cli/dev/islands.js +25 -70
- package/dist/cli/dev/listen.js +26 -0
- package/dist/cli/dev/load-template.js +0 -1
- package/dist/cli/dev/request-error.js +0 -4
- package/dist/cli/dev/server.js +46 -52
- package/dist/cli/dev/tsconfig-paths.js +0 -13
- package/dist/cli/dev/vite.js +9 -38
- package/dist/cli/dev/workspace-reader.js +4 -34
- package/dist/cli/media/cache.js +4 -51
- package/dist/cli/media/derive.js +2 -94
- package/dist/cli/media/deriver-plugin.js +0 -2
- package/dist/cli/media/frame-rung-floor.js +0 -6
- package/dist/cli/property/index.js +0 -4
- package/dist/cli/property/library.js +6 -24
- package/dist/cli/publish/client.js +0 -1
- package/dist/cli/publish/freshness.js +0 -2
- package/dist/cli/publish/git.js +2 -8
- package/dist/cli/publish/index.js +8 -15
- package/dist/cli/publish/pack.js +5 -6
- package/dist/cli/publish/report.js +0 -6
- package/dist/cli/publish/target.js +16 -13
- package/dist/cli/publish/wire.js +0 -6
- package/dist/cli/tar.js +2 -9
- package/dist/cli/upgrade/codemod.js +0 -8
- package/dist/cli/upgrade/index.js +0 -24
- package/dist/cli/upgrade/manifest.js +0 -12
- package/dist/cli/upgrade/plan.js +0 -17
- package/dist/cli/upgrade/stage.js +12 -15
- package/dist/cli/version.js +0 -8
- package/dist/cli/workspace.js +2 -34
- package/dist/cli.js +4 -21
- package/dist/css/compile.js +25 -28
- package/dist/css/graph.js +3 -10
- package/dist/css/inline.js +3 -16
- package/dist/css/rules.js +6 -43
- package/dist/design-system/format-variants.js +0 -22
- package/dist/eslint/authoring.js +0 -2
- package/dist/eslint/correctness.js +0 -7
- package/dist/eslint/rules/editor-reason.js +0 -11
- package/dist/eslint/rules/island-ids.js +0 -1
- package/dist/eslint/rules/jsx-visitor.js +0 -13
- package/dist/eslint/rules/no-editor-globals.js +0 -2
- package/dist/eslint/rules/no-raw-values.js +0 -1
- package/dist/fixtures/brand.js +0 -1
- package/dist/fixtures/bundle-rule.js +4 -9
- package/dist/fixtures/canonical.d.ts +20 -0
- package/dist/fixtures/image-dimensions.js +0 -1
- package/dist/fixtures/load.js +8 -17
- package/dist/fixtures/media-plugin.js +4 -31
- package/dist/fixtures/media.js +0 -21
- package/dist/fixtures/package-stylesheets.js +0 -6
- package/dist/fixtures/property.js +16 -15
- package/dist/fixtures/resolve.js +102 -29
- package/dist/fixtures/rows.js +12 -11
- package/dist/fixtures/synthesize-empties.js +0 -4
- package/dist/fixtures.d.ts +19 -4
- package/dist/fixtures.js +0 -18
- package/dist/index.d.ts +8 -9
- package/dist/index.js +2 -11
- package/dist/islands/client-module.js +0 -11
- package/dist/islands/marker.js +0 -33
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +0 -20
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +21 -35
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +4 -0
- package/dist/packages/internal/fill-bake/dist/derive-source.js +40 -0
- package/dist/packages/internal/fill-bake/dist/display.js +0 -1
- package/dist/packages/internal/fill-bake/dist/index.js +4 -4
- package/dist/packages/internal/fill-vocabulary/dist/origination.js +106 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +1 -49
- package/dist/packages/internal/format-geometry/dist/capture.js +10 -240
- package/dist/packages/internal/format-geometry/dist/geometry.js +0 -6
- package/dist/packages/internal/image-ladder/dist/crop.js +0 -12
- package/dist/packages/internal/image-ladder/dist/policy.js +0 -14
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +0 -13
- package/dist/packages/internal/island-runtime/dist/contract.js +0 -34
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/index.js +0 -34
- package/dist/packages/internal/island-runtime/dist/island-id-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +0 -15
- package/dist/packages/internal/island-runtime/dist/use-editor.js +0 -10
- package/dist/packages/internal/island-runtime/dist/use-island-id.js +0 -32
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +2 -17
- package/dist/packages/internal/property-facts/dist/index.js +1 -1
- package/dist/packages/internal/property-facts/dist/{property-facts-CSdkSuD7.js → property-facts-5pxZnlkh.js} +13 -2
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +1 -18
- package/dist/packages/internal/section-contracts/dist/catalog.js +16 -8
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +12 -16
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +5 -11
- package/dist/packages/internal/section-contracts/dist/display-contract.js +2 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +2 -8
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +13 -0
- package/dist/packages/internal/section-contracts/dist/index.js +2 -1
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +16 -42
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +24 -43
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +11 -18
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +10 -12
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +3 -13
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +6 -18
- package/dist/packages/internal/section-contracts/dist/runners.js +21 -13
- package/dist/packages/internal/section-contracts/dist/source-contract.js +13 -2
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +31 -0
- package/dist/packages/internal/source-resolution/dist/index.js +1 -9
- package/dist/packages/internal/template-artifact/dist/hash.js +0 -8
- package/dist/packages/internal/template-artifact/dist/index.js +1 -1
- package/dist/packages/internal/template-artifact/dist/layout.js +0 -39
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -9
- package/dist/packages/internal/template-artifact/dist/sha256.js +0 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +2 -4
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +0 -16
- package/dist/packages/internal/template-contracts/dist/content-categories.js +0 -4
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +16 -10
- package/dist/packages/internal/template-contracts/dist/facts-view.js +15 -28
- package/dist/packages/internal/template-contracts/dist/layout.js +0 -7
- package/dist/packages/internal/template-contracts/dist/markers.js +0 -29
- package/dist/packages/internal/template-contracts/dist/select-key.js +0 -6
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +56 -34
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +22 -389
- package/dist/platform/file-url.js +8 -0
- package/dist/platform/fs.js +73 -0
- package/dist/platform/names.js +63 -0
- package/dist/platform/order.js +7 -0
- package/dist/platform/paths.js +66 -0
- package/dist/platform/process.js +97 -0
- package/dist/playground/host/page-state.js +0 -2
- package/dist/playground/host/paths.js +0 -1
- package/dist/playground/layout.js +0 -7
- package/dist/playground/wire.js +0 -8
- package/dist/primitives/FrameShell.js +0 -18
- package/dist/primitives/Image.d.ts +5 -1
- package/dist/primitives/Image.js +2 -68
- package/dist/primitives/Section.js +0 -13
- package/dist/primitives/Tour.js +0 -26
- package/dist/primitives/Video.js +0 -32
- package/dist/primitives/embed-playback.js +0 -1
- package/dist/primitives/marker-attrs.js +0 -17
- package/dist/primitives/picture-sources.js +6 -1
- package/dist/primitives/probe-context.js +0 -7
- package/dist/primitives/slot-bindings.js +0 -46
- package/dist/primitives/slot-document.js +0 -11
- package/dist/primitives/slot-group.js +0 -9
- package/dist/primitives/slot-media.js +0 -27
- package/dist/primitives/slot-scalar.js +0 -4
- package/dist/primitives/slot.js +0 -6
- package/dist/rules/registry.js +42 -24
- package/dist/schema/compute.d.ts +46 -8
- package/dist/schema/compute.js +21 -15
- package/dist/schema/define-schema.d.ts +1 -1
- package/dist/schema/define-schema.js +37 -17
- package/dist/schema/extract-fill-spec.js +93 -180
- package/dist/schema/extract-used-facts.js +16 -158
- package/dist/schema/fact.d.ts +25 -12
- package/dist/schema/fact.js +7 -11
- package/dist/schema/fill-builders.d.ts +91 -366
- package/dist/schema/fill-builders.js +21 -259
- package/dist/schema/fill-declaration.d.ts +7 -69
- package/dist/schema/fill-declaration.js +5 -34
- package/dist/schema/fill-spec.js +59 -148
- package/dist/schema/format-presets.js +0 -12
- package/dist/schema/format.js +0 -7
- package/dist/schema/layout.js +0 -10
- package/dist/schema/manifest.js +0 -39
- package/dist/schema/property-facts.d.ts +20 -0
- package/dist/schema/section-nav.js +0 -15
- package/dist/schema/section-schema.d.ts +0 -1
- package/dist/schema/section-schema.js +4 -20
- package/dist/schema/slot-builders.d.ts +128 -117
- package/dist/schema/slot-builders.js +18 -201
- package/dist/schema/slot-ref.d.ts +63 -0
- package/dist/schema/slot-ref.js +33 -0
- package/dist/schema/slot-types.d.ts +3 -2
- package/dist/schema/slot-types.js +11 -20
- package/dist/section/declare.d.ts +14 -10
- package/dist/section/declare.js +13 -2
- package/dist/section/discovery.js +6 -21
- package/dist/section/groups.js +0 -6
- package/dist/section/materialize.js +0 -5
- package/dist/section/placements.js +0 -4
- package/dist/section/section.d.ts +8 -5
- package/dist/section/section.js +7 -29
- package/dist/styles.css +5 -0
- package/dist/template/define-template.d.ts +0 -4
- package/dist/template/define-template.js +1 -15
- package/dist/template/logic-build.js +8 -35
- package/dist/template/logic-shim.d.ts +4 -5
- package/dist/template/logic-shim.js +2 -6
- package/dist/template/logic-transform.js +0 -6
- package/dist/template/materialize.js +52 -43
- package/dist/template/mirror-types.js +43 -0
- package/dist/template/running-copy.js +5 -20
- package/dist/template/section-reads.js +83 -0
- package/guide/reference/cli/INDEX.md +12 -6
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +3 -3
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +4 -2
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +26 -13
- package/package.json +4 -2
- package/dist/packages/internal/fact-interpolation/dist/index.js +0 -22
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +0 -170
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +0 -32
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +0 -131
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +0 -11
- package/dist/schema/fill-spec.d.ts +0 -18
- package/dist/template/reconcile.d.ts +0 -67
- package/dist/template/reconcile.js +0 -25
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { resolveFormatGeometry } from "./geometry.js";
|
|
2
2
|
|
|
3
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 Concrete's base stylesheet. Shared so a canvas host or a
|
|
7
|
-
* capturing worker can stamp the identical class on its own page root and
|
|
8
|
-
* resolve the frame from the same stylesheet the captured page uses.
|
|
9
|
-
*/
|
|
10
4
|
const FRAME_ROOT_CLASS = "concrete-frame";
|
|
11
|
-
/** The frame shell's per-format tokens: trim box + bleed, exact CSS px. */
|
|
12
5
|
function frameTokens(format) {
|
|
13
6
|
const geometry = resolveFormatGeometry(format);
|
|
14
7
|
return {
|
|
@@ -17,11 +10,6 @@ function frameTokens(format) {
|
|
|
17
10
|
"--frame-bleed": `${geometry.bleed}px`
|
|
18
11
|
};
|
|
19
12
|
}
|
|
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
13
|
function captureViewport(format) {
|
|
26
14
|
const geometry = resolveFormatGeometry(format);
|
|
27
15
|
return {
|
|
@@ -30,13 +18,6 @@ function captureViewport(format) {
|
|
|
30
18
|
deviceScaleFactor: geometry.deviceScaleFactor
|
|
31
19
|
};
|
|
32
20
|
}
|
|
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
21
|
function printPageSize(format) {
|
|
41
22
|
const geometry = resolveFormatGeometry(format);
|
|
42
23
|
return {
|
|
@@ -44,50 +25,7 @@ function printPageSize(format) {
|
|
|
44
25
|
height: `${geometry.pointHeight / 72}in`
|
|
45
26
|
};
|
|
46
27
|
}
|
|
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
28
|
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
29
|
const CAPTURE_READY_EXPRESSION = `(async () => {
|
|
92
30
|
await document.fonts.ready;
|
|
93
31
|
for (const img of document.images) {
|
|
@@ -110,40 +48,8 @@ const CAPTURE_READY_EXPRESSION = `(async () => {
|
|
|
110
48
|
requestAnimationFrame(() => resolve(undefined));
|
|
111
49
|
});
|
|
112
50
|
})()`;
|
|
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
51
|
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
52
|
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
53
|
const CAPTURE_ISLANDS_READY_EXPRESSION = `(async () => {
|
|
148
54
|
const ready = window.${CAPTURE_ISLANDS_READY_GLOBAL};
|
|
149
55
|
if (ready === undefined) {
|
|
@@ -154,14 +60,6 @@ const CAPTURE_ISLANDS_READY_EXPRESSION = `(async () => {
|
|
|
154
60
|
}
|
|
155
61
|
await ready;
|
|
156
62
|
})()`;
|
|
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
63
|
const CAPTURE_ISLANDS_DIAGNOSTIC_EXPRESSION = `(() => {
|
|
166
64
|
const holds = window.__trCaptureHolds;
|
|
167
65
|
const keys = [...new Set(Array.from(
|
|
@@ -170,40 +68,9 @@ const CAPTURE_ISLANDS_DIAGNOSTIC_EXPRESSION = `(() => {
|
|
|
170
68
|
))];
|
|
171
69
|
return JSON.stringify({ openHolds: holds ? holds.size : 0, islands: keys });
|
|
172
70
|
})()`;
|
|
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
71
|
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
72
|
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
|
-
*/
|
|
73
|
+
const CAPTURE_ISLAND_SETTLE_TIMEOUT_MS = 6e4;
|
|
207
74
|
const CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION = `(async () => {
|
|
208
75
|
await new Promise((resolve) => {
|
|
209
76
|
setTimeout(resolve, ${400});
|
|
@@ -212,38 +79,7 @@ const CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION = `(async () => {
|
|
|
212
79
|
requestAnimationFrame(() => resolve(undefined));
|
|
213
80
|
});
|
|
214
81
|
})()`;
|
|
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
82
|
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
83
|
const CAPTURE_ANIMATIONS_SETTLED_EXPRESSION = `(async () => {
|
|
248
84
|
const frame = () => new Promise((resolve) => {
|
|
249
85
|
requestAnimationFrame(() => resolve(undefined));
|
|
@@ -266,33 +102,20 @@ const CAPTURE_ANIMATIONS_SETTLED_EXPRESSION = `(async () => {
|
|
|
266
102
|
}
|
|
267
103
|
await frame();
|
|
268
104
|
})()`;
|
|
269
|
-
function legTimeout(leg) {
|
|
270
|
-
return /* @__PURE__ */ new Error(`capture blocked: ${leg} did not settle within ${
|
|
105
|
+
function legTimeout(leg, ceilingMs) {
|
|
106
|
+
return /* @__PURE__ */ new Error(`capture blocked: ${leg} did not settle within ${ceilingMs}ms`);
|
|
271
107
|
}
|
|
272
|
-
|
|
273
|
-
async function withLegTimeout(leg, work) {
|
|
108
|
+
async function withLegTimeout(leg, work, ceilingMs) {
|
|
274
109
|
let timer;
|
|
275
110
|
try {
|
|
276
111
|
return await Promise.race([work, new Promise((_resolve, reject) => {
|
|
277
|
-
timer = setTimeout(() => reject(legTimeout(leg)),
|
|
112
|
+
timer = setTimeout(() => reject(legTimeout(leg, ceilingMs)), ceilingMs);
|
|
278
113
|
})]);
|
|
279
114
|
} finally {
|
|
280
115
|
if (timer) clearTimeout(timer);
|
|
281
116
|
}
|
|
282
117
|
}
|
|
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
118
|
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
119
|
async function withIslandDiagnostic(host, error) {
|
|
297
120
|
if (!(error instanceof Error) || !error.message.includes("island hydration")) return error;
|
|
298
121
|
let timer;
|
|
@@ -308,13 +131,7 @@ async function withIslandDiagnostic(host, error) {
|
|
|
308
131
|
if (timer) clearTimeout(timer);
|
|
309
132
|
}
|
|
310
133
|
}
|
|
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) {
|
|
134
|
+
function awaitNetworkQuiescence(host, ceilingMs) {
|
|
318
135
|
return new Promise((resolve, reject) => {
|
|
319
136
|
let quiet;
|
|
320
137
|
let ceiling;
|
|
@@ -330,72 +147,25 @@ function awaitNetworkQuiescence(host) {
|
|
|
330
147
|
if (quiet) clearTimeout(quiet);
|
|
331
148
|
quiet = setTimeout(() => finish(), 500);
|
|
332
149
|
};
|
|
333
|
-
ceiling = setTimeout(() => finish(legTimeout("network quiescence")),
|
|
150
|
+
ceiling = setTimeout(() => finish(legTimeout("network quiescence", ceilingMs)), ceilingMs);
|
|
334
151
|
unsubscribe = host.onNetworkActivity(arm);
|
|
335
152
|
arm();
|
|
336
153
|
});
|
|
337
154
|
}
|
|
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
155
|
const CAPTURE_RAF_FLUSH_EXPRESSION = `(async () => {
|
|
346
156
|
await new Promise((resolve) => {
|
|
347
157
|
requestAnimationFrame(() => resolve(undefined));
|
|
348
158
|
});
|
|
349
159
|
})()`;
|
|
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) {
|
|
160
|
+
async function settleCapture(host, ceilingMs = CAPTURE_ISLAND_SETTLE_TIMEOUT_MS) {
|
|
391
161
|
const hasIslands = await host.evaluate(CAPTURE_HAS_ISLANDS_EXPRESSION) === true;
|
|
392
162
|
if (hasIslands) try {
|
|
393
|
-
await withLegTimeout("island hydration", host.evaluate(CAPTURE_ISLANDS_READY_EXPRESSION));
|
|
163
|
+
await withLegTimeout("island hydration", host.evaluate(CAPTURE_ISLANDS_READY_EXPRESSION), ceilingMs);
|
|
394
164
|
} catch (error) {
|
|
395
165
|
throw await withIslandDiagnostic(host, error);
|
|
396
166
|
}
|
|
397
167
|
await host.evaluate(CAPTURE_READY_EXPRESSION);
|
|
398
|
-
await awaitNetworkQuiescence(host);
|
|
168
|
+
await awaitNetworkQuiescence(host, ceilingMs);
|
|
399
169
|
await host.evaluate(CAPTURE_ANIMATIONS_SETTLED_EXPRESSION);
|
|
400
170
|
await host.evaluate(hasIslands ? CAPTURE_ISLAND_PAINT_GRACE_EXPRESSION : CAPTURE_RAF_FLUSH_EXPRESSION);
|
|
401
171
|
}
|
|
@@ -3,18 +3,12 @@ const CSS_PX_PER_INCH = 96;
|
|
|
3
3
|
const POINTS_PER_INCH = 72;
|
|
4
4
|
const MM_PER_INCH = 25.4;
|
|
5
5
|
const PHYSICAL_LENGTH_RE = /^(\d+(?:\.\d+)?)(in|mm)$/;
|
|
6
|
-
/** A physical length in inches. Throws on a malformed unit string. */
|
|
7
6
|
function toInches(length) {
|
|
8
7
|
const [, digits, unit] = PHYSICAL_LENGTH_RE.exec(length) ?? [];
|
|
9
8
|
if (digits === void 0 || unit === void 0) throw new Error(`malformed physical length: "${length}"`);
|
|
10
9
|
const value = Number.parseFloat(digits);
|
|
11
10
|
return unit === "mm" ? value / MM_PER_INCH : value;
|
|
12
11
|
}
|
|
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
12
|
function resolveFormatGeometry(format) {
|
|
19
13
|
if (typeof format.width === "number" && typeof format.height === "number") return {
|
|
20
14
|
frameWidth: format.width,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
//#region ../../internal/image-ladder/dist/crop.js
|
|
2
|
-
/** The query parameter a cropped image URL carries. */
|
|
3
2
|
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
3
|
const round = (n) => String(Math.round(n * 1e6) / 1e6);
|
|
6
4
|
const clamp01 = (n) => Math.min(Math.max(n, 0), 1);
|
|
7
|
-
/** `url` serving only `rect` of the image. */
|
|
8
5
|
function croppedUrl(url, rect) {
|
|
9
6
|
const value = [
|
|
10
7
|
rect.nx,
|
|
@@ -14,10 +11,6 @@ function croppedUrl(url, rect) {
|
|
|
14
11
|
].map(round).join(",");
|
|
15
12
|
return `${url}${url.includes("?") ? "&" : "?"}${CROP_PARAM}=${value}`;
|
|
16
13
|
}
|
|
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
14
|
function parseCropParam(value) {
|
|
22
15
|
const parts = value.split(",");
|
|
23
16
|
if (parts.length !== 4 || parts.some((part) => part.trim() === "")) return null;
|
|
@@ -39,11 +32,6 @@ function parseCropParam(value) {
|
|
|
39
32
|
if (rect.nw <= 0 || rect.nh <= 0) return null;
|
|
40
33
|
return rect.nx === 0 && rect.ny === 0 && rect.nw === 1 && rect.nh === 1 ? null : rect;
|
|
41
34
|
}
|
|
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
35
|
async function cutRegion(sharp, master, rect) {
|
|
48
36
|
const { format } = await sharp(master).metadata();
|
|
49
37
|
const { data, info } = await sharp(master).rotate().raw().toBuffer({ resolveWithObject: true });
|
|
@@ -69,19 +69,6 @@ function encoderSettings(spec) {
|
|
|
69
69
|
spec.encode(recorder);
|
|
70
70
|
return calls.join(".");
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
73
|
-
* A stable digest of every input the derived BYTES depend on: the rung ladder, the
|
|
74
|
-
* ceiling, and each format spec including the encoder settings it actually applies.
|
|
75
|
-
*
|
|
76
|
-
* Independent of how the module was built — no file bytes, no source text — so it
|
|
77
|
-
* is the same number whether this package is imported from its own `dist` or
|
|
78
|
-
* inlined into a published bundle. That is what lets a consumer's derivative cache
|
|
79
|
-
* key on it: change a quality number, a rung or a format list and every entry
|
|
80
|
-
* misses, with nobody having to remember to bump a version constant by hand.
|
|
81
|
-
*
|
|
82
|
-
* Exported separately from the constant below so a test can prove the sensitivity
|
|
83
|
-
* on synthetic specs rather than by editing the real policy.
|
|
84
|
-
*/
|
|
85
72
|
function policyFingerprint(ladder, ceiling, specs) {
|
|
86
73
|
const parts = [
|
|
87
74
|
ladder.join(","),
|
|
@@ -95,7 +82,6 @@ function policyFingerprint(ladder, ceiling, specs) {
|
|
|
95
82
|
];
|
|
96
83
|
return createHash("sha256").update(parts.join("\n")).digest("hex").slice(0, 16);
|
|
97
84
|
}
|
|
98
|
-
/** The fingerprint of the policy above — every branch of it, both format lists. */
|
|
99
85
|
const LADDER_POLICY_FINGERPRINT = policyFingerprint(LADDER, LADDER_CEILING, [...formatPolicyFor({ format: "jpeg" }), ...formatPolicyFor({ format: "png" })]);
|
|
100
86
|
|
|
101
87
|
//#endregion
|
|
@@ -10,11 +10,6 @@ function holdsRegistry() {
|
|
|
10
10
|
}
|
|
11
11
|
return holds;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Take one capture hold. The returned release is idempotent; the hold leaves
|
|
15
|
-
* the registry the moment it is released, so a capturer counting open holds
|
|
16
|
-
* for a diagnostic sees only what is still owed.
|
|
17
|
-
*/
|
|
18
13
|
function takeCaptureHold() {
|
|
19
14
|
const holds = holdsRegistry();
|
|
20
15
|
let release = () => {};
|
|
@@ -27,14 +22,6 @@ function takeCaptureHold() {
|
|
|
27
22
|
release();
|
|
28
23
|
};
|
|
29
24
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Settles when every handle has MOUNTED and every capture hold has been
|
|
32
|
-
* released — the whole readiness a capture host publishes under the capturer's
|
|
33
|
-
* readiness global. Holds registered while the drain is in flight (an island's
|
|
34
|
-
* mount effect runs before its handle's `mounted` settles, but another
|
|
35
|
-
* island's may not have) are drained too. Unbounded by design: the capturer's
|
|
36
|
-
* own per-leg ceiling is the timeout, and it fails naming the leg.
|
|
37
|
-
*/
|
|
38
25
|
async function islandsCaptureReady(handles) {
|
|
39
26
|
await Promise.all(handles.map((islandHandle) => islandHandle.mounted));
|
|
40
27
|
const holds = holdsRegistry();
|
|
@@ -1,43 +1,15 @@
|
|
|
1
1
|
//#region ../../internal/island-runtime/dist/contract.js
|
|
2
|
-
/** The custom element wrapping an island's server-rendered output. Layout-invisible (`display:contents`). */
|
|
3
2
|
const ISLAND_ELEMENT = "tr-island";
|
|
4
|
-
/** Island key on the marker: `<section-key>:<ComponentName>`, e.g. `spw-essential/floorplan:UnitFilter`. */
|
|
5
3
|
const ATTR_ISLAND_KEY = "data-tr-island";
|
|
6
|
-
/** Island id on the marker: unique in the document, stable across re-renders of the same island. */
|
|
7
4
|
const ATTR_ISLAND_ID = "data-tr-island-id";
|
|
8
|
-
/** On the JSON `<script>` sibling; its value is the island id of the marker the props belong to. */
|
|
9
5
|
const ATTR_ISLAND_PROPS = "data-tr-island-props";
|
|
10
|
-
/**
|
|
11
|
-
* Present on a marker holding no server-rendered output — the island mounts fresh
|
|
12
|
-
* instead of hydrating. Value-less: presence is the whole signal.
|
|
13
|
-
*
|
|
14
|
-
* The browser loader decides how to mount a marker before that island's module has
|
|
15
|
-
* loaded, so it cannot ask the module whether it declared `serverFrame = false`. The
|
|
16
|
-
* DOM has to carry the answer, and the marker is the one thing that knows it — an
|
|
17
|
-
* empty marker means there is nothing for React to hydrate against, whatever made it
|
|
18
|
-
* empty.
|
|
19
|
-
*/
|
|
20
6
|
const ATTR_ISLAND_FRAMELESS = "data-tr-island-frameless";
|
|
21
|
-
/** The window property an editor canvas publishes its {@link EditorBridge} on. Absent on published pages. */
|
|
22
7
|
const EDITOR_BRIDGE_PROP = "__trEditorBridge";
|
|
23
|
-
/** The bridge protocol this runtime speaks. See {@link EditorBridge} for the versioning discipline. */
|
|
24
8
|
const EDITOR_BRIDGE_PROTOCOL = 1;
|
|
25
|
-
/**
|
|
26
|
-
* The window property holding the page's OPEN capture holds, as a
|
|
27
|
-
* `Set<Promise<void>>`. An island that paints after mount takes a hold (the
|
|
28
|
-
* `useCaptureReady` hook) and the host's readiness promise drains the set —
|
|
29
|
-
* window-level because an island bundle and the page's runtime chunk are
|
|
30
|
-
* separate module graphs, so module state cannot cross between them.
|
|
31
|
-
*/
|
|
32
9
|
const ISLAND_CAPTURE_HOLDS_GLOBAL = "__trCaptureHolds";
|
|
33
|
-
/** A prop that cannot cross the server→browser boundary, or a payload that cannot be read back. */
|
|
34
10
|
var IslandPropsError = class extends Error {
|
|
35
11
|
name = "IslandPropsError";
|
|
36
12
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Compose an island id. `scope` is the emitter's per-section-instance identity —
|
|
39
|
-
* without it, two instances of one section on a page collide.
|
|
40
|
-
*/
|
|
41
13
|
function islandId(scope, islandKey, ordinal) {
|
|
42
14
|
return `${scope}~${islandKey}#${ordinal}`;
|
|
43
15
|
}
|
|
@@ -68,17 +40,11 @@ function assertSerializable(value, path) {
|
|
|
68
40
|
}
|
|
69
41
|
for (const [key, entry] of Object.entries(value)) assertSerializable(entry, `${path}.${key}`);
|
|
70
42
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Validate + encode island props for the `<script type="application/json">` payload.
|
|
73
|
-
* Throws IslandPropsError naming the offending path. Every `<` is emitted as its
|
|
74
|
-
* unicode escape so a string value containing a closing script tag cannot break out.
|
|
75
|
-
*/
|
|
76
43
|
function serializeIslandProps(props) {
|
|
77
44
|
if (props === null || typeof props !== "object" || Array.isArray(props)) throw new IslandPropsError("props must be a plain object, not an array or a bare value");
|
|
78
45
|
assertSerializable(props, "props");
|
|
79
46
|
return JSON.stringify(props).replace(/</g, "\\u003c");
|
|
80
47
|
}
|
|
81
|
-
/** Read a props payload back. Throws IslandPropsError on anything that is not a JSON object. */
|
|
82
48
|
function deserializeIslandProps(payload) {
|
|
83
49
|
let parsed;
|
|
84
50
|
try {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
//#region ../../internal/island-runtime/dist/editor-instance-context.js
|
|
2
2
|
const CONTEXT_KEY = Symbol.for("homepages.tr-island-editor-instance");
|
|
3
|
-
/** The one shared editor-instance context, created by whichever copy asks first. */
|
|
4
3
|
function editorInstanceContext(react) {
|
|
5
4
|
const registry = globalThis;
|
|
6
5
|
let context = registry[CONTEXT_KEY];
|
|
@@ -5,38 +5,8 @@ import { islandIdContext } from "./island-id-context.js";
|
|
|
5
5
|
import { scheduleViewport } from "./viewport-schedule.js";
|
|
6
6
|
|
|
7
7
|
//#region ../../internal/island-runtime/dist/index.js
|
|
8
|
-
/** The host-stamped section-root attribute the loader scopes each island's editor instance by. */
|
|
9
8
|
const ATTR_SECTION_INSTANCE_ID = "data-section-instance-id";
|
|
10
9
|
const roots = /* @__PURE__ */ new WeakMap();
|
|
11
|
-
/**
|
|
12
|
-
* Hydrate every island marker under `options.root` (default: the whole document)
|
|
13
|
-
* into its own React root, loading each one's module through `options.load`.
|
|
14
|
-
*
|
|
15
|
-
* A marker carrying `data-tr-island-frameless` holds no server-rendered output, so its
|
|
16
|
-
* island is mounted fresh rather than hydrated — there is nothing to hydrate against,
|
|
17
|
-
* and asking React to try reports a mismatch on every such island.
|
|
18
|
-
*
|
|
19
|
-
* A marker nested inside another marker is skipped — it belongs to the parent
|
|
20
|
-
* island's own render, so hydrating it separately would create a second root on
|
|
21
|
-
* DOM the parent already owns. A marker whose props payload is missing, or that
|
|
22
|
-
* shares its id with another payload, is refused rather than guessed at. A marker
|
|
23
|
-
* that leaves the document while its module is still loading is silently skipped:
|
|
24
|
-
* that is the host's own re-render racing this call, not a failure. Every other
|
|
25
|
-
* failure — a rejected `load()`, a thrown render — reaches `options.onError`
|
|
26
|
-
* rather than throwing out of this call, so one bad island never blocks its
|
|
27
|
-
* neighbors.
|
|
28
|
-
*
|
|
29
|
-
* Islands hydrate by viewport priority: the returned promise covers what is visible at
|
|
30
|
-
* first paint, and `onHydrated` reports the rest as the visitor approaches them or the
|
|
31
|
-
* main thread goes idle. `schedule: "eager"` hydrates every island before this call
|
|
32
|
-
* settles instead — see {@link HydrateIslandsOptions.schedule}.
|
|
33
|
-
*
|
|
34
|
-
* WHICH islands this promise covers is the schedule's business; WHETHER they have
|
|
35
|
-
* mounted is not. It settles once each covered island has a React root, which React
|
|
36
|
-
* commits a task later — so a caller that needs the islands' DOM to EXIST (a capturer,
|
|
37
|
-
* a measuring pass) must await {@link IslandContext.mounted} on the handles, which is
|
|
38
|
-
* why every handle carries one.
|
|
39
|
-
*/
|
|
40
10
|
async function hydrateIslands(options) {
|
|
41
11
|
const root = options.root ?? document;
|
|
42
12
|
const markers = Array.from(root.querySelectorAll(`[${ATTR_ISLAND_KEY}]`)).filter((element) => !roots.has(element) && element.parentElement?.closest(`[${"data-tr-island"}]`) == null);
|
|
@@ -147,10 +117,6 @@ async function hydrateIslands(options) {
|
|
|
147
117
|
}
|
|
148
118
|
return handles;
|
|
149
119
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Unmount every island hydrated under `root`. Synchronous, so the editor can call it
|
|
152
|
-
* immediately before replacing a section's innerHTML.
|
|
153
|
-
*/
|
|
154
120
|
function unmountIslands(root = document) {
|
|
155
121
|
const self = root instanceof Element && root.matches(`[${"data-tr-island"}]`) ? [root] : [];
|
|
156
122
|
for (const element of [...self, ...root.querySelectorAll(`[${ATTR_ISLAND_KEY}]`)]) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
//#region ../../internal/island-runtime/dist/island-id-context.js
|
|
2
2
|
const CONTEXT_KEY = Symbol.for("homepages.tr-island-id");
|
|
3
|
-
/** The one shared island-id context, created by whichever copy asks first. */
|
|
4
3
|
function islandIdContext(react) {
|
|
5
4
|
const registry = globalThis;
|
|
6
5
|
let context = registry[CONTEXT_KEY];
|
|
@@ -2,21 +2,6 @@ import { takeCaptureHold } from "./capture-holds.js";
|
|
|
2
2
|
import { useCallback, useEffect, useRef } from "react";
|
|
3
3
|
|
|
4
4
|
//#region ../../internal/island-runtime/dist/use-capture-ready.js
|
|
5
|
-
/**
|
|
6
|
-
* Hold the capture shutter until this island's pixels are real.
|
|
7
|
-
*
|
|
8
|
-
* An island that keeps painting after mount — a map engine loading tiles, an
|
|
9
|
-
* async decode — calls this hook and invokes the returned `ready` when its
|
|
10
|
-
* last pixel is painted (`map.once("idle", ready)` is the map-engine shape).
|
|
11
|
-
* Calling the hook takes a hold for this island instance at mount; `ready` is
|
|
12
|
-
* identity-stable and idempotent, an unmounted island releases automatically,
|
|
13
|
-
* and a branch with nothing to draw calls `ready()` immediately. An island
|
|
14
|
-
* that paints everything during mount needs none of this — never calling the
|
|
15
|
-
* hook is the default contract.
|
|
16
|
-
*
|
|
17
|
-
* Where nothing captures (an editor canvas, a published website) the hold is
|
|
18
|
-
* never read, so the hook costs nothing there.
|
|
19
|
-
*/
|
|
20
5
|
function useCaptureReady() {
|
|
21
6
|
const releaseRef = useRef(null);
|
|
22
7
|
const readyRef = useRef(false);
|
|
@@ -28,16 +28,6 @@ function scopeSelection(raw, instanceId) {
|
|
|
28
28
|
...raw.fieldName !== void 0 ? { fieldName: raw.fieldName } : {}
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Whether this island is live in an editor canvas, and what is selected inside
|
|
33
|
-
* its own section instance.
|
|
34
|
-
*
|
|
35
|
-
* During server rendering, on published pages, and under an incompatible bridge
|
|
36
|
-
* protocol it returns `{ inCanvas: false, selection: null }` — hydration-safe by
|
|
37
|
-
* construction. `selection` is already scoped to the island's own section
|
|
38
|
-
* instance and keeps its identity between publishes, so it is safe to use as an
|
|
39
|
-
* effect dependency.
|
|
40
|
-
*/
|
|
41
31
|
function useEditor() {
|
|
42
32
|
const instanceId = useContext(InstanceContext);
|
|
43
33
|
const bridge = compatibleBridge();
|