@littlepress/renderer-web 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +229 -2
- package/dist/answer/answerComponents.d.ts +107 -0
- package/dist/answer/answerComponents.js +637 -0
- package/dist/answer/download.d.ts +63 -0
- package/dist/answer/download.js +109 -0
- package/dist/answer/downloadExport.d.ts +44 -0
- package/dist/answer/downloadExport.js +266 -0
- package/dist/answer/hostValues.d.ts +28 -0
- package/dist/answer/hostValues.js +379 -0
- package/dist/answer/mapComponent.d.ts +6 -0
- package/dist/answer/mapComponent.js +213 -0
- package/dist/answer/math.d.ts +57 -0
- package/dist/answer/math.js +168 -0
- package/dist/answer/surfaceStream.d.ts +51 -0
- package/dist/answer/surfaceStream.js +260 -0
- package/dist/answer/tableLayout.d.ts +42 -0
- package/dist/answer/tableLayout.js +89 -0
- package/dist/controls/ActionFeedback.d.ts +5 -0
- package/dist/controls/ActionFeedback.js +43 -0
- package/dist/controls/actionDispatch.d.ts +51 -0
- package/dist/controls/actionDispatch.js +211 -0
- package/dist/controls/actionOutcome.generated.d.ts +64 -0
- package/dist/controls/actionOutcome.generated.js +64 -0
- package/dist/controls/calculationPublisher.d.ts +14 -0
- package/dist/controls/calculationPublisher.js +6 -0
- package/dist/controls/calculations.d.ts +20 -0
- package/dist/controls/calculations.generated.d.ts +73 -0
- package/dist/controls/calculations.generated.js +85 -0
- package/dist/controls/calculations.js +208 -0
- package/dist/controls/controlState.d.ts +84 -0
- package/dist/controls/controlState.js +256 -0
- package/dist/controls/fieldMessages.d.ts +41 -0
- package/dist/controls/fieldMessages.js +81 -0
- package/dist/controls/fieldValidation.d.ts +19 -0
- package/dist/controls/fieldValidation.js +98 -0
- package/dist/controls/formComponents.d.ts +23 -0
- package/dist/controls/formComponents.js +738 -0
- package/dist/controls/formProgress.d.ts +63 -0
- package/dist/controls/formProgress.js +122 -0
- package/dist/controls/inputDrafts.d.ts +55 -0
- package/dist/controls/inputDrafts.js +183 -0
- package/dist/controls/inputValidation.d.ts +33 -0
- package/dist/controls/inputValidation.js +119 -0
- package/dist/controls/localWrites.d.ts +9 -0
- package/dist/controls/localWrites.js +29 -0
- package/dist/core/A2uiSurface.d.ts +13 -0
- package/dist/core/A2uiSurface.js +15 -0
- package/dist/core/AtlasIcon.d.ts +18 -0
- package/dist/core/AtlasIcon.js +22 -0
- package/dist/core/AtlasMedia.d.ts +22 -0
- package/dist/core/AtlasMedia.js +45 -0
- package/dist/core/Carousel.d.ts +61 -0
- package/dist/core/Carousel.js +183 -0
- package/dist/core/CoreMedia.d.ts +19 -0
- package/dist/core/CoreMedia.js +25 -0
- package/dist/core/FoundationA2uiSurface.d.ts +86 -0
- package/dist/core/FoundationA2uiSurface.js +440 -0
- package/dist/core/ImagePreview.d.ts +42 -0
- package/dist/core/ImagePreview.js +73 -0
- package/dist/core/LucideIcon.d.ts +19 -0
- package/dist/core/LucideIcon.js +42 -0
- package/dist/core/SurfaceLink.d.ts +35 -0
- package/dist/core/SurfaceLink.js +60 -0
- package/dist/core/appearance/aegis.d.ts +49 -0
- package/dist/core/appearance/aegis.js +34 -0
- package/dist/core/appearance/colour.d.ts +24 -0
- package/dist/core/appearance/colour.js +103 -0
- package/dist/core/appearance/css.d.ts +17 -0
- package/dist/core/appearance/css.js +153 -0
- package/dist/core/appearance/presets.generated.d.ts +4 -0
- package/dist/core/appearance/presets.generated.js +1184 -0
- package/dist/core/appearance/react.d.ts +29 -0
- package/dist/core/appearance/react.js +110 -0
- package/dist/core/appearance/resolve.d.ts +76 -0
- package/dist/core/appearance/resolve.js +127 -0
- package/dist/core/appearance/textScale.d.ts +11 -0
- package/dist/core/appearance/textScale.js +51 -0
- package/dist/core/appearance/theme.d.ts +138 -0
- package/dist/core/appearance/theme.js +274 -0
- package/dist/core/baseComponents.d.ts +53 -0
- package/dist/core/baseComponents.js +480 -0
- package/dist/core/binding.d.ts +46 -0
- package/dist/core/binding.js +118 -0
- package/dist/core/bundle.d.ts +23 -0
- package/dist/core/bundle.js +75 -0
- package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
- package/dist/core/catalog/catalog-index.generated.js +79 -0
- package/dist/core/catalog/icons.generated.d.ts +6 -0
- package/dist/core/catalog/icons.generated.js +1788 -0
- package/dist/core/catalog.d.ts +6 -0
- package/dist/core/catalog.generated.d.ts +50 -0
- package/dist/core/catalog.generated.js +2174 -0
- package/dist/core/catalog.js +8 -0
- package/dist/core/chartRows.d.ts +7 -0
- package/dist/core/chartRows.js +38 -0
- package/dist/core/component-support.d.ts +39 -0
- package/dist/core/component-support.js +127 -0
- package/dist/core/components/actions.d.ts +4 -0
- package/dist/core/components/actions.js +21 -0
- package/dist/core/components/cards.d.ts +9 -0
- package/dist/core/components/cards.js +227 -0
- package/dist/core/components/charts.d.ts +18 -0
- package/dist/core/components/charts.js +412 -0
- package/dist/core/components/comparisonTable.d.ts +50 -0
- package/dist/core/components/comparisonTable.js +89 -0
- package/dist/core/components/content.d.ts +13 -0
- package/dist/core/components/content.js +108 -0
- package/dist/core/components/seriesCharts.d.ts +531 -0
- package/dist/core/components/seriesCharts.js +1053 -0
- package/dist/core/components/stepFlow.d.ts +7 -0
- package/dist/core/components/stepFlow.js +13 -0
- package/dist/core/components.full.d.ts +10 -0
- package/dist/core/components.full.js +41 -0
- package/dist/core/context.d.ts +207 -0
- package/dist/core/context.js +172 -0
- package/dist/core/coverage.d.ts +30 -0
- package/dist/core/coverage.js +93 -0
- package/dist/core/foundation.d.ts +21 -0
- package/dist/core/foundation.js +22 -0
- package/dist/core/fullTheme.d.ts +5 -0
- package/dist/core/fullTheme.js +9 -0
- package/dist/core/iconNodes.generated.d.ts +7 -0
- package/dist/core/iconNodes.generated.js +5 -0
- package/dist/core/lucideIcons.d.ts +5 -0
- package/dist/core/lucideIcons.js +7 -0
- package/dist/core/messages.d.ts +111 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/pointer.d.ts +17 -0
- package/dist/core/pointer.js +104 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +114 -0
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +6 -0
- package/dist/core/state.d.ts +73 -0
- package/dist/core/state.js +274 -0
- package/dist/core/surfaceMotion.d.ts +5 -0
- package/dist/core/surfaceMotion.js +46 -0
- package/dist/core/theme.d.ts +5 -0
- package/dist/core/theme.js +7 -0
- package/dist/core/useSurfaceImage.d.ts +20 -0
- package/dist/core/useSurfaceImage.js +65 -0
- package/dist/graph/RelationshipGraph.d.ts +14 -0
- package/dist/graph/RelationshipGraph.js +206 -0
- package/dist/graph/model.d.ts +20 -0
- package/dist/graph/model.js +36 -0
- package/dist/graph/program/assets.d.ts +3 -0
- package/dist/graph/program/assets.js +3 -0
- package/dist/graph/program/bridge.d.ts +6 -0
- package/dist/graph/program/bridge.generated.d.ts +136 -0
- package/dist/graph/program/bridge.generated.js +1 -0
- package/dist/graph/program/bridge.js +24 -0
- package/dist/graph/program/bridge.schema.json +717 -0
- package/dist/graph/program/bridgeValidator.cjs +2 -0
- package/dist/graph/program/bridgeValidator.d.cts +4 -0
- package/dist/graph/program/runner.d.ts +1 -0
- package/dist/graph/program/runner.html +2193 -0
- package/dist/graph/program/runner.js +157 -0
- package/dist/graph/program/runtime-manifest.json +1 -0
- package/dist/graph/program/view.d.ts +11 -0
- package/dist/graph/program/view.js +210 -0
- package/dist/graph/program/worker.d.ts +1 -0
- package/dist/graph/program/worker.js +2186 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/dist/internal/dsh.d.ts +4 -0
- package/dist/internal/dsh.js +3 -0
- package/dist/internal/relationship-graph.d.ts +4 -0
- package/dist/internal/relationship-graph.js +7202 -0
- package/dist/page/layoutComponents.d.ts +6 -0
- package/dist/page/layoutComponents.js +123 -0
- package/dist/page/layoutGeometry.d.ts +68 -0
- package/dist/page/layoutGeometry.js +174 -0
- package/dist/page/pageFormat.d.ts +34 -0
- package/dist/page/pageFormat.js +119 -0
- package/dist/page/printFit.d.ts +81 -0
- package/dist/page/printFit.js +338 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +2 -0
- package/dist/report/locate.d.ts +42 -0
- package/dist/report/locate.js +34 -0
- package/dist/styles/renderer.css +4580 -0
- package/licenses/LUCIDE-LICENSE.txt +43 -0
- package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
- package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
- package/package.json +68 -3
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
const TOLERANCE_PX = 1;
|
|
2
|
+
function finite(value, fallback = 0) {
|
|
3
|
+
const parsed = typeof value === "string" ? Number.parseFloat(value) : Number(value);
|
|
4
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
5
|
+
}
|
|
6
|
+
function overflows(node) {
|
|
7
|
+
return (node.scrollHeight > node.clientHeight + TOLERANCE_PX ||
|
|
8
|
+
node.scrollWidth > node.clientWidth + TOLERANCE_PX);
|
|
9
|
+
}
|
|
10
|
+
/** Pure allocation check; the engine and DOM tests can exercise the same rule. */
|
|
11
|
+
export function validateSlotAllocation(input) {
|
|
12
|
+
const fillChildren = input.children.filter((child) => child.mode === "fill");
|
|
13
|
+
if (fillChildren.length > 0 && input.children.length > 1) {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
kind: "allocation-overflow",
|
|
17
|
+
detail: "fill child must be the slot's only child",
|
|
18
|
+
componentIds: input.children.map((child) => child.componentId),
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
const rectChildren = input.children.filter((child) => child.rect !== undefined);
|
|
23
|
+
if (rectChildren.length === input.children.length && rectChildren.length > 0) {
|
|
24
|
+
const issues = [];
|
|
25
|
+
for (const child of rectChildren) {
|
|
26
|
+
const rect = child.rect;
|
|
27
|
+
if (rect.xPt < -TOLERANCE_PX ||
|
|
28
|
+
rect.yPt < -TOLERANCE_PX ||
|
|
29
|
+
(input.slotWidthPt !== undefined && rect.xPt + rect.widthPt > input.slotWidthPt + TOLERANCE_PX) ||
|
|
30
|
+
rect.yPt + rect.heightPt > input.slotHeightPt + TOLERANCE_PX) {
|
|
31
|
+
issues.push({
|
|
32
|
+
kind: "child-out-of-bounds",
|
|
33
|
+
detail: "child rectangle exceeds its owning slot",
|
|
34
|
+
componentIds: [child.componentId],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
rectChildren.forEach((first, index) => {
|
|
39
|
+
for (const second of rectChildren.slice(index + 1)) {
|
|
40
|
+
const a = first.rect;
|
|
41
|
+
const b = second.rect;
|
|
42
|
+
const overlapWidth = Math.min(a.xPt + a.widthPt, b.xPt + b.widthPt) - Math.max(a.xPt, b.xPt);
|
|
43
|
+
const overlapHeight = Math.min(a.yPt + a.heightPt, b.yPt + b.heightPt) - Math.max(a.yPt, b.yPt);
|
|
44
|
+
if (overlapWidth > TOLERANCE_PX && overlapHeight > TOLERANCE_PX) {
|
|
45
|
+
issues.push({
|
|
46
|
+
kind: "child-overlap",
|
|
47
|
+
detail: "non-overlay child rectangles overlap",
|
|
48
|
+
componentIds: [first.componentId, second.componentId],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return issues;
|
|
54
|
+
}
|
|
55
|
+
const allocated = input.children.reduce((total, child) => total + child.heightPt, 0);
|
|
56
|
+
const gaps = Math.max(input.children.length - 1, 0) * input.gapPt;
|
|
57
|
+
if (allocated + gaps <= input.slotHeightPt + TOLERANCE_PX)
|
|
58
|
+
return [];
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
kind: "allocation-overflow",
|
|
62
|
+
detail: `${allocated.toFixed(2)}pt children + ${gaps.toFixed(2)}pt gaps exceeds ${input.slotHeightPt.toFixed(2)}pt slot`,
|
|
63
|
+
componentIds: input.children.map((child) => child.componentId),
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
function readPolicy(node) {
|
|
68
|
+
const value = node.dataset.printPolicy;
|
|
69
|
+
return value === "clamp" || value === "crop" || value === "protected" ? value : "content";
|
|
70
|
+
}
|
|
71
|
+
function outsideOwner(node, owner) {
|
|
72
|
+
const part = node.getBoundingClientRect();
|
|
73
|
+
const boundary = owner.getBoundingClientRect();
|
|
74
|
+
return (part.left < boundary.left - TOLERANCE_PX ||
|
|
75
|
+
part.top < boundary.top - TOLERANCE_PX ||
|
|
76
|
+
part.right > boundary.right + TOLERANCE_PX ||
|
|
77
|
+
part.bottom > boundary.bottom + TOLERANCE_PX);
|
|
78
|
+
}
|
|
79
|
+
function measurePart(node, owner) {
|
|
80
|
+
const policy = readPolicy(node);
|
|
81
|
+
const clipped = overflows(node) || outsideOwner(node, owner);
|
|
82
|
+
const partRect = node.getBoundingClientRect();
|
|
83
|
+
const ownerRect = owner.getBoundingClientRect();
|
|
84
|
+
const scaleY = owner.clientHeight > 0 && ownerRect.height > 0
|
|
85
|
+
? ownerRect.height / owner.clientHeight
|
|
86
|
+
: 1;
|
|
87
|
+
const offsetTopPx = (partRect.top - ownerRect.top) / scaleY;
|
|
88
|
+
let status = "fit";
|
|
89
|
+
if (policy === "crop")
|
|
90
|
+
status = "declared-crop";
|
|
91
|
+
else if (clipped && policy === "protected")
|
|
92
|
+
status = "protected-hidden";
|
|
93
|
+
else if (clipped && policy === "clamp")
|
|
94
|
+
status = "declared-clamp";
|
|
95
|
+
else if (clipped)
|
|
96
|
+
status = "clipped";
|
|
97
|
+
return {
|
|
98
|
+
part: node.dataset.printPart || "content",
|
|
99
|
+
policy,
|
|
100
|
+
status,
|
|
101
|
+
offsetTopPx,
|
|
102
|
+
requiredBottomPx: Math.max(offsetTopPx, 0) + Math.max(node.clientHeight, node.scrollHeight),
|
|
103
|
+
clientWidth: node.clientWidth,
|
|
104
|
+
clientHeight: node.clientHeight,
|
|
105
|
+
scrollWidth: node.scrollWidth,
|
|
106
|
+
scrollHeight: node.scrollHeight,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function childStatus(parts, childClipped) {
|
|
110
|
+
if (parts.some((part) => part.status === "protected-hidden"))
|
|
111
|
+
return "protected-hidden";
|
|
112
|
+
if (parts.some((part) => part.status === "clipped"))
|
|
113
|
+
return "clipped";
|
|
114
|
+
if (childClipped)
|
|
115
|
+
return "clipped";
|
|
116
|
+
if (parts.some((part) => part.status === "declared-clamp"))
|
|
117
|
+
return "declared-clamp";
|
|
118
|
+
if (parts.some((part) => part.status === "declared-crop"))
|
|
119
|
+
return "declared-crop";
|
|
120
|
+
return "fit";
|
|
121
|
+
}
|
|
122
|
+
function contentDemand(node) {
|
|
123
|
+
const ownerRect = node.getBoundingClientRect();
|
|
124
|
+
const scaleX = node.clientWidth > 0 && ownerRect.width > 0 ? ownerRect.width / node.clientWidth : 1;
|
|
125
|
+
const scaleY = node.clientHeight > 0 && ownerRect.height > 0 ? ownerRect.height / node.clientHeight : 1;
|
|
126
|
+
let width = 0;
|
|
127
|
+
let height = 0;
|
|
128
|
+
for (const child of Array.from(node.children)) {
|
|
129
|
+
if (!(child instanceof HTMLElement))
|
|
130
|
+
continue;
|
|
131
|
+
const rect = child.getBoundingClientRect();
|
|
132
|
+
const left = (rect.left - ownerRect.left) / scaleX;
|
|
133
|
+
const top = (rect.top - ownerRect.top) / scaleY;
|
|
134
|
+
width = Math.max(width, Math.max(left, 0) + Math.max(child.clientWidth, child.scrollWidth));
|
|
135
|
+
height = Math.max(height, Math.max(top, 0) + Math.max(child.clientHeight, child.scrollHeight));
|
|
136
|
+
}
|
|
137
|
+
return { width, height };
|
|
138
|
+
}
|
|
139
|
+
function measureChild(node) {
|
|
140
|
+
const parts = Array.from(node.querySelectorAll("[data-print-part]")).map((part) => measurePart(part, node));
|
|
141
|
+
const allocatedHeightPt = finite(node.dataset.declaredHeight, node.clientHeight);
|
|
142
|
+
const clipped = overflows(node);
|
|
143
|
+
const nestedHiddenHeight = parts.reduce((total, part) => total + (part.policy === "content" || part.policy === "protected"
|
|
144
|
+
? Math.max(part.scrollHeight - part.clientHeight, 0)
|
|
145
|
+
: 0), 0);
|
|
146
|
+
const nestedHiddenWidth = parts.reduce((maximum, part) => Math.max(maximum, part.policy === "content" || part.policy === "protected"
|
|
147
|
+
? Math.max(part.scrollWidth - part.clientWidth, 0)
|
|
148
|
+
: 0), 0);
|
|
149
|
+
const content = contentDemand(node);
|
|
150
|
+
const demandHeight = content.height + nestedHiddenHeight;
|
|
151
|
+
const demandWidth = content.width + nestedHiddenWidth;
|
|
152
|
+
return {
|
|
153
|
+
componentId: node.dataset.childId || "unknown",
|
|
154
|
+
component: node.dataset.childComponent || null,
|
|
155
|
+
mode: node.dataset.printMode || null,
|
|
156
|
+
allocatedHeightPt,
|
|
157
|
+
allocatedRectPt: {
|
|
158
|
+
xPt: node.offsetLeft,
|
|
159
|
+
yPt: node.offsetTop,
|
|
160
|
+
widthPt: node.offsetWidth,
|
|
161
|
+
heightPt: node.offsetHeight,
|
|
162
|
+
},
|
|
163
|
+
clientWidth: node.clientWidth,
|
|
164
|
+
clientHeight: node.clientHeight,
|
|
165
|
+
scrollWidth: node.scrollWidth,
|
|
166
|
+
scrollHeight: node.scrollHeight,
|
|
167
|
+
measuredDemandWidthPx: demandWidth,
|
|
168
|
+
measuredDemandHeightPx: demandHeight,
|
|
169
|
+
measuredDemandRatio: allocatedHeightPt > 0 ? demandHeight / allocatedHeightPt : 0,
|
|
170
|
+
status: childStatus(parts, clipped),
|
|
171
|
+
parts,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function rectIssue(first, second) {
|
|
175
|
+
const a = first.getBoundingClientRect();
|
|
176
|
+
const b = second.getBoundingClientRect();
|
|
177
|
+
const overlapWidth = Math.min(a.right, b.right) - Math.max(a.left, b.left);
|
|
178
|
+
const overlapHeight = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
|
|
179
|
+
if (overlapWidth <= TOLERANCE_PX || overlapHeight <= TOLERANCE_PX)
|
|
180
|
+
return null;
|
|
181
|
+
return {
|
|
182
|
+
kind: "child-overlap",
|
|
183
|
+
detail: "non-overlay child rectangles overlap",
|
|
184
|
+
componentIds: [first.dataset.childId || "unknown", second.dataset.childId || "unknown"],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export function measurePrintSlot(slot) {
|
|
188
|
+
const childNodes = Array.from(slot.querySelectorAll(":scope > .a2ui-print-sized"));
|
|
189
|
+
const children = childNodes.map(measureChild);
|
|
190
|
+
const style = getComputedStyle(slot);
|
|
191
|
+
const gapPt = finite(style.rowGap === "normal" ? style.gap : style.rowGap, 0);
|
|
192
|
+
const rectLayout = slot.dataset.childLayout === "rects";
|
|
193
|
+
const allocatedHeightPt = rectLayout
|
|
194
|
+
? Math.max(0, ...children.map((child) => child.allocatedRectPt.yPt + child.allocatedRectPt.heightPt))
|
|
195
|
+
: children.reduce((total, child) => total + child.allocatedHeightPt, 0);
|
|
196
|
+
const geometryIssues = [
|
|
197
|
+
...validateSlotAllocation({
|
|
198
|
+
slotWidthPt: slot.clientWidth,
|
|
199
|
+
slotHeightPt: slot.clientHeight,
|
|
200
|
+
gapPt,
|
|
201
|
+
children: children.map((child) => ({
|
|
202
|
+
componentId: child.componentId,
|
|
203
|
+
heightPt: child.allocatedHeightPt,
|
|
204
|
+
mode: child.mode,
|
|
205
|
+
rect: rectLayout ? child.allocatedRectPt : undefined,
|
|
206
|
+
})),
|
|
207
|
+
}),
|
|
208
|
+
];
|
|
209
|
+
const protectedHidden = children.some((child) => child.status === "protected-hidden");
|
|
210
|
+
const clipped = children.some((child) => child.status === "clipped");
|
|
211
|
+
const declaredClamp = children.some((child) => child.status === "declared-clamp");
|
|
212
|
+
const declaredCrop = children.some((child) => child.status === "declared-crop");
|
|
213
|
+
let status = "fit";
|
|
214
|
+
if (geometryIssues.length > 0)
|
|
215
|
+
status = "geometry-failure";
|
|
216
|
+
else if (protectedHidden)
|
|
217
|
+
status = "protected-hidden";
|
|
218
|
+
else if (clipped)
|
|
219
|
+
status = "clipped";
|
|
220
|
+
else if (declaredClamp)
|
|
221
|
+
status = "declared-clamp";
|
|
222
|
+
else if (declaredCrop)
|
|
223
|
+
status = "declared-crop";
|
|
224
|
+
const demand = rectLayout
|
|
225
|
+
? Math.max(0, ...children.map((child) => child.allocatedRectPt.yPt + child.measuredDemandHeightPx))
|
|
226
|
+
: children.reduce((total, child) => total + child.measuredDemandHeightPx, 0)
|
|
227
|
+
+ Math.max(children.length - 1, 0) * gapPt;
|
|
228
|
+
const measuredDemandRatio = rectLayout
|
|
229
|
+
? children.reduce((total, child) => total + child.allocatedRectPt.widthPt * child.measuredDemandHeightPx, 0) / Math.max(slot.clientWidth * slot.clientHeight, 1)
|
|
230
|
+
: slot.clientHeight > 0 ? demand / slot.clientHeight : 0;
|
|
231
|
+
return {
|
|
232
|
+
slotId: slot.dataset.slot || "unknown",
|
|
233
|
+
slotRectPt: {
|
|
234
|
+
xPt: finite(slot.dataset.xPt, slot.offsetLeft),
|
|
235
|
+
yPt: finite(slot.dataset.yPt, slot.offsetTop),
|
|
236
|
+
widthPt: slot.clientWidth,
|
|
237
|
+
heightPt: slot.clientHeight,
|
|
238
|
+
},
|
|
239
|
+
widthPt: slot.clientWidth,
|
|
240
|
+
heightPt: slot.clientHeight,
|
|
241
|
+
allocatedHeightPt,
|
|
242
|
+
gapPt,
|
|
243
|
+
measuredDemandRatio,
|
|
244
|
+
measuredDemandHeightPx: demand,
|
|
245
|
+
status,
|
|
246
|
+
blocking: status === "geometry-failure" || status === "protected-hidden" || status === "clipped",
|
|
247
|
+
geometryIssues,
|
|
248
|
+
children,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function pageGeometryIssues(page) {
|
|
252
|
+
const pageRect = page.getBoundingClientRect();
|
|
253
|
+
const slots = Array.from(page.querySelectorAll(".a2ui-print-slot"));
|
|
254
|
+
const issues = [];
|
|
255
|
+
for (const slot of slots) {
|
|
256
|
+
const rect = slot.getBoundingClientRect();
|
|
257
|
+
if (rect.left < pageRect.left - TOLERANCE_PX ||
|
|
258
|
+
rect.top < pageRect.top - TOLERANCE_PX ||
|
|
259
|
+
rect.right > pageRect.right + TOLERANCE_PX ||
|
|
260
|
+
rect.bottom > pageRect.bottom + TOLERANCE_PX) {
|
|
261
|
+
issues.push({
|
|
262
|
+
kind: "slot-out-of-page",
|
|
263
|
+
detail: `slot ${slot.dataset.slot || "unknown"} exceeds the page rectangle`,
|
|
264
|
+
componentIds: [],
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const ordinary = slots.filter((slot) => slot.dataset.overlay !== "true");
|
|
269
|
+
ordinary.forEach((first, index) => {
|
|
270
|
+
for (const second of ordinary.slice(index + 1)) {
|
|
271
|
+
const issue = rectIssue(first, second);
|
|
272
|
+
if (issue) {
|
|
273
|
+
issues.push({
|
|
274
|
+
...issue,
|
|
275
|
+
detail: `slots ${first.dataset.slot || "unknown"} and ${second.dataset.slot || "unknown"} overlap`,
|
|
276
|
+
componentIds: [],
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return issues;
|
|
282
|
+
}
|
|
283
|
+
export function measurePrintPage(page) {
|
|
284
|
+
const slots = Array.from(page.querySelectorAll(".a2ui-print-slot")).map(measurePrintSlot);
|
|
285
|
+
const geometryIssues = pageGeometryIssues(page);
|
|
286
|
+
const blocking = geometryIssues.length > 0 || slots.some((slot) => slot.blocking);
|
|
287
|
+
const declared = slots.some((slot) => slot.status === "declared-clamp" || slot.status === "declared-crop");
|
|
288
|
+
return {
|
|
289
|
+
status: blocking ? "failed" : declared ? "declared-clipping" : "fit",
|
|
290
|
+
blocking,
|
|
291
|
+
slotCount: slots.length,
|
|
292
|
+
failedSlotCount: slots.filter((slot) => slot.blocking).length,
|
|
293
|
+
slots,
|
|
294
|
+
geometryIssues,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/** Observe the content that can change while its fixed wrapper stays the same size. */
|
|
298
|
+
export function observePrintSlot(slot, onReport) {
|
|
299
|
+
let frame = 0;
|
|
300
|
+
const measure = () => {
|
|
301
|
+
if (frame)
|
|
302
|
+
cancelAnimationFrame(frame);
|
|
303
|
+
frame = requestAnimationFrame(() => onReport(measurePrintSlot(slot)));
|
|
304
|
+
};
|
|
305
|
+
const resize = new ResizeObserver(measure);
|
|
306
|
+
resize.observe(slot);
|
|
307
|
+
const observed = new Set();
|
|
308
|
+
const observeContents = () => {
|
|
309
|
+
for (const node of slot.querySelectorAll(".a2ui-print-sized, [data-print-part]")) {
|
|
310
|
+
if (observed.has(node))
|
|
311
|
+
continue;
|
|
312
|
+
observed.add(node);
|
|
313
|
+
resize.observe(node);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
observeContents();
|
|
317
|
+
const mutation = new MutationObserver(() => {
|
|
318
|
+
observeContents();
|
|
319
|
+
measure();
|
|
320
|
+
});
|
|
321
|
+
mutation.observe(slot, {
|
|
322
|
+
subtree: true,
|
|
323
|
+
childList: true,
|
|
324
|
+
characterData: true,
|
|
325
|
+
attributes: true,
|
|
326
|
+
attributeFilter: ["class", "hidden", "src", "srcset", "style"],
|
|
327
|
+
});
|
|
328
|
+
slot.addEventListener("load", measure, true);
|
|
329
|
+
void document.fonts?.ready.then(measure);
|
|
330
|
+
measure();
|
|
331
|
+
return () => {
|
|
332
|
+
if (frame)
|
|
333
|
+
cancelAnimationFrame(frame);
|
|
334
|
+
resize.disconnect();
|
|
335
|
+
mutation.disconnect();
|
|
336
|
+
slot.removeEventListener("load", measure, true);
|
|
337
|
+
};
|
|
338
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { A2uiSurface, type A2uiSurfaceProps } from "../core/A2uiSurface.tsx";
|
|
2
|
+
export { LittlePressAppearance, useLittlePressAppearance, useSystemAppearance, type AppearanceProblemHandler, type LittlePressAppearanceProps, type LittlePressAppearanceValues, } from "../core/appearance/react.tsx";
|
|
3
|
+
export type { A2uiInputChange, A2uiInputChangeHandler, A2uiInputValue, AegisBlockRenderProps, AegisBlockRenderer, LayoutRenderMode, MapAdapterProps, MapAdapterRenderer, MapPlace, MapPlaceGroup, ResolvedAction, SaveFileHandler, SaveFileResult, SurfaceImageLoader, } from "../core/context.ts";
|
|
4
|
+
export type { A2uiLocateOptions, A2uiSurfaceHandle } from "../report/locate.ts";
|
|
5
|
+
export type { ActionOutcome, ActionInvocation, A2uiActionHandler } from "../controls/actionDispatch.ts";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving the reader to one component, for example from a Host table of contents.
|
|
3
|
+
*
|
|
4
|
+
* Only a Foundation text heading (`role` `title` or `headline`, drawn as an H2) that is
|
|
5
|
+
* drawn once gets a DOM id. The id starts with a prefix owned by one mounted surface, so
|
|
6
|
+
* two surfaces that both contain `title_02` never share an id, and the lookup only
|
|
7
|
+
* searches inside the surface's own element.
|
|
8
|
+
*/
|
|
9
|
+
export type A2uiLocateOptions = {
|
|
10
|
+
/** Passed to `scrollIntoView`. Defaults to `auto` (an instant jump). */
|
|
11
|
+
behavior?: ScrollBehavior;
|
|
12
|
+
};
|
|
13
|
+
/** The imperative handle a Host gets through the `ref` of `A2uiSurface`. */
|
|
14
|
+
export type A2uiSurfaceHandle = {
|
|
15
|
+
/**
|
|
16
|
+
* Scrolls the component to the top of its scroll container and moves keyboard focus
|
|
17
|
+
* to it. Returns false, and changes nothing, when this surface draws no locatable
|
|
18
|
+
* element for that id: the id is unknown, the component is not a heading, it sits in
|
|
19
|
+
* a repeated row, or it is drawn more than once.
|
|
20
|
+
*/
|
|
21
|
+
locateComponent(componentId: string, options?: A2uiLocateOptions): boolean;
|
|
22
|
+
};
|
|
23
|
+
/** Turns React's `useId()` value into a plain id prefix. */
|
|
24
|
+
export declare function surfaceAnchorPrefix(reactId: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* DOM id of a locatable component. `encodeURIComponent` keeps the mapping one-to-one and
|
|
27
|
+
* leaves no quote, backslash or space, so the id is safe inside an attribute selector.
|
|
28
|
+
*/
|
|
29
|
+
export declare function componentAnchorId(prefix: string, componentId: string): string;
|
|
30
|
+
type LocatableElement = {
|
|
31
|
+
tabIndex: number;
|
|
32
|
+
hasAttribute(name: string): boolean;
|
|
33
|
+
setAttribute(name: string, value: string): void;
|
|
34
|
+
scrollIntoView(options: ScrollIntoViewOptions): void;
|
|
35
|
+
focus(options: FocusOptions): void;
|
|
36
|
+
};
|
|
37
|
+
type LocateRoot = {
|
|
38
|
+
querySelectorAll(selector: string): ArrayLike<LocatableElement>;
|
|
39
|
+
};
|
|
40
|
+
/** The work behind `A2uiSurfaceHandle.locateComponent`, searching only under `root`. */
|
|
41
|
+
export declare function locateComponentIn(root: LocateRoot | null, prefix: string, componentId: string, options?: A2uiLocateOptions): boolean;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving the reader to one component, for example from a Host table of contents.
|
|
3
|
+
*
|
|
4
|
+
* Only a Foundation text heading (`role` `title` or `headline`, drawn as an H2) that is
|
|
5
|
+
* drawn once gets a DOM id. The id starts with a prefix owned by one mounted surface, so
|
|
6
|
+
* two surfaces that both contain `title_02` never share an id, and the lookup only
|
|
7
|
+
* searches inside the surface's own element.
|
|
8
|
+
*/
|
|
9
|
+
/** Turns React's `useId()` value into a plain id prefix. */
|
|
10
|
+
export function surfaceAnchorPrefix(reactId) {
|
|
11
|
+
return `lp-a2ui-${reactId.replace(/[^A-Za-z0-9_-]/g, "")}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* DOM id of a locatable component. `encodeURIComponent` keeps the mapping one-to-one and
|
|
15
|
+
* leaves no quote, backslash or space, so the id is safe inside an attribute selector.
|
|
16
|
+
*/
|
|
17
|
+
export function componentAnchorId(prefix, componentId) {
|
|
18
|
+
return `${prefix}-${encodeURIComponent(componentId)}`;
|
|
19
|
+
}
|
|
20
|
+
/** The work behind `A2uiSurfaceHandle.locateComponent`, searching only under `root`. */
|
|
21
|
+
export function locateComponentIn(root, prefix, componentId, options = {}) {
|
|
22
|
+
if (!root || typeof componentId !== "string" || componentId.length === 0)
|
|
23
|
+
return false;
|
|
24
|
+
const matches = root.querySelectorAll(`[id="${componentAnchorId(prefix, componentId)}"]`);
|
|
25
|
+
if (matches.length !== 1)
|
|
26
|
+
return false;
|
|
27
|
+
const element = matches[0];
|
|
28
|
+
// A heading cannot take focus; tabindex -1 lets script focus it without adding a Tab stop.
|
|
29
|
+
if (element.tabIndex < 0 && !element.hasAttribute("tabindex"))
|
|
30
|
+
element.setAttribute("tabindex", "-1");
|
|
31
|
+
element.scrollIntoView({ block: "start", behavior: options.behavior ?? "auto" });
|
|
32
|
+
element.focus({ preventScroll: true });
|
|
33
|
+
return true;
|
|
34
|
+
}
|