@embedpdf/react 3.0.0-next.5 → 3.0.0-next.6
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/dist/index.cjs +0 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/render.cjs +64 -48
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +6 -19
- package/dist/render.d.ts +6 -19
- package/dist/render.js +67 -50
- package/dist/render.js.map +1 -1
- package/package.json +23 -23
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,6 @@ exports.SelectionClipboard = require_selection.SelectionClipboard;
|
|
|
43
43
|
exports.SelectionLayer = require_selection.SelectionLayer;
|
|
44
44
|
exports.SelectionMenu = require_selection.SelectionMenu;
|
|
45
45
|
exports.Stage = require_stage.Stage;
|
|
46
|
-
exports.TileLayer = require_render.TileLayer;
|
|
47
46
|
exports.Toolbar = require_toolbar.Toolbar;
|
|
48
47
|
exports.Viewer = require_runtime.Viewer;
|
|
49
48
|
Object.defineProperty(exports, "copySelection", {
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ import { useI18n, useLocale, useT } from "./i18n.cjs";
|
|
|
8
8
|
import { Stage, StageProps, StageTokenProp, useLayout, usePageList, usePages, useStage, useStageSettings, useZoom } from "./stage.cjs";
|
|
9
9
|
import { Scrollbar, ScrollbarAxis, ScrollbarProps, useScrollMetrics } from "./scrollbar.cjs";
|
|
10
10
|
import { PageView, PageViewProps } from "./page-view.cjs";
|
|
11
|
-
import { RenderLayer, RenderLayerProps
|
|
11
|
+
import { RenderLayer, RenderLayerProps } from "./render.cjs";
|
|
12
12
|
import { PagePointerSource, ToolCursorImage, ToolCursorSpec, createClickCounter, useTool, useToolCursor } from "./interaction.cjs";
|
|
13
13
|
import { SelectionClipboard, SelectionClipboardProps, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, copySelection, useSelection } from "./selection.cjs";
|
|
14
14
|
import { LinkLayer, LinkLayerProps, useLink } from "./link.cjs";
|
|
@@ -35,4 +35,4 @@ export * from "@embedpdf/plugin-redaction";
|
|
|
35
35
|
export * from "@embedpdf/plugin-stamp";
|
|
36
36
|
export * from "@embedpdf/plugin-shell";
|
|
37
37
|
export * from "@embedpdf/core-ui";
|
|
38
|
-
export { type AnchorTarget, Anchored, type AnchoredPlacement, AnchoredProps, AnnotationDraftMenu, AnnotationDraftMenuProps, type AnnotationFlags, AnnotationLayer, AnnotationLayerProps, AnnotationMenu, AnnotationMenuProps, type AnnotationProps, type AnnotationPropsPatch, AnnotationRenderer, AnnotationRendererProps, type Border, CollapsedGroupView, type CreationDraftAnchor, CustomSlotCtx, DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, FormLayer, type FormScriptingUiHandlers, type Geom, GroupDisclosureView, type LineEnding, type LineEndings, LinkLayer, LinkLayerProps, MenusHandle, OverflowMenuView, PageContextValue, PagePointerSource, PageProvider, PageView, PageViewProps, ProjectorBinding, ProjectorProvider, type PropKey, type PropSpec, type RenderItem, RenderLayer, RenderLayerProps, Scrollbar, ScrollbarAxis, ScrollbarProps, SearchLayer, SelectionAnchor, SelectionClipboard, SelectionClipboardProps, type SelectionFlags, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, type SelectionProps, Stage, StageProps, StageTokenProp, StripView, StripViewGroup, type Style, SurfaceHandle, type TextAlign, type TextStyle,
|
|
38
|
+
export { type AnchorTarget, Anchored, type AnchoredPlacement, AnchoredProps, AnnotationDraftMenu, AnnotationDraftMenuProps, type AnnotationFlags, AnnotationLayer, AnnotationLayerProps, AnnotationMenu, AnnotationMenuProps, type AnnotationProps, type AnnotationPropsPatch, AnnotationRenderer, AnnotationRendererProps, type Border, CollapsedGroupView, type CreationDraftAnchor, CustomSlotCtx, DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, FormLayer, type FormScriptingUiHandlers, type Geom, GroupDisclosureView, type LineEnding, type LineEndings, LinkLayer, LinkLayerProps, MenusHandle, OverflowMenuView, PageContextValue, PagePointerSource, PageProvider, PageView, PageViewProps, ProjectorBinding, ProjectorProvider, type PropKey, type PropSpec, type RenderItem, RenderLayer, RenderLayerProps, Scrollbar, ScrollbarAxis, ScrollbarProps, SearchLayer, SelectionAnchor, SelectionClipboard, SelectionClipboardProps, type SelectionFlags, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, type SelectionProps, Stage, StageProps, StageTokenProp, StripView, StripViewGroup, type Style, SurfaceHandle, type TextAlign, type TextStyle, ToolCursorImage, ToolCursorSpec, Toolbar, ToolbarProps, UseViews, type ViewProjector, Viewer, ViewerProps, copySelection, createClickCounter, filePickerProvider, isMacPlatform, makePageContext, sameAnchor, sameCreationDraftAnchor, shallowArray, useActiveDocumentId, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useArmStampAsset, useCapability, useCommand, useCommandShortcuts, useCommands, useDocumentId, useDocumentStatus, useDocuments, useFilePickerProvider, useForm, useFormField, useFormScriptingProvider, useI18n, useKernel, useKernelValue, useLayout, useLink, useLocale, useMenus, useMetadata, useOptionalCapability, useOptionalSelector, usePage, usePageEditor, usePageList, usePages, usePendingRedactions, useProjectorBinding, useRedaction, useScrollMetrics, useSearch, useSearchState, useSelection, useSelectionFlags, useSelectionProps, useSelector, useShell, useStage, useStageSettings, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampLibraries, useStripView, useSurface, useT, useTool, useToolCursor, useViews, useZoom };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { useI18n, useLocale, useT } from "./i18n.js";
|
|
|
8
8
|
import { Stage, StageProps, StageTokenProp, useLayout, usePageList, usePages, useStage, useStageSettings, useZoom } from "./stage.js";
|
|
9
9
|
import { Scrollbar, ScrollbarAxis, ScrollbarProps, useScrollMetrics } from "./scrollbar.js";
|
|
10
10
|
import { PageView, PageViewProps } from "./page-view.js";
|
|
11
|
-
import { RenderLayer, RenderLayerProps
|
|
11
|
+
import { RenderLayer, RenderLayerProps } from "./render.js";
|
|
12
12
|
import { PagePointerSource, ToolCursorImage, ToolCursorSpec, createClickCounter, useTool, useToolCursor } from "./interaction.js";
|
|
13
13
|
import { SelectionClipboard, SelectionClipboardProps, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, copySelection, useSelection } from "./selection.js";
|
|
14
14
|
import { LinkLayer, LinkLayerProps, useLink } from "./link.js";
|
|
@@ -35,4 +35,4 @@ export * from "@embedpdf/plugin-stamp";
|
|
|
35
35
|
export * from "@embedpdf/plugin-commands";
|
|
36
36
|
export * from "@embedpdf/plugin-shell";
|
|
37
37
|
export * from "@embedpdf/core-ui";
|
|
38
|
-
export { type AnchorTarget, Anchored, type AnchoredPlacement, AnchoredProps, AnnotationDraftMenu, AnnotationDraftMenuProps, type AnnotationFlags, AnnotationLayer, AnnotationLayerProps, AnnotationMenu, AnnotationMenuProps, type AnnotationProps, type AnnotationPropsPatch, AnnotationRenderer, AnnotationRendererProps, type Border, CollapsedGroupView, type CreationDraftAnchor, CustomSlotCtx, DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, FormLayer, type FormScriptingUiHandlers, type Geom, GroupDisclosureView, type LineEnding, type LineEndings, LinkLayer, LinkLayerProps, MenusHandle, OverflowMenuView, PageContextValue, PagePointerSource, PageProvider, PageView, PageViewProps, ProjectorBinding, ProjectorProvider, type PropKey, type PropSpec, type RenderItem, RenderLayer, RenderLayerProps, Scrollbar, ScrollbarAxis, ScrollbarProps, SearchLayer, SelectionAnchor, SelectionClipboard, SelectionClipboardProps, type SelectionFlags, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, type SelectionProps, Stage, StageProps, StageTokenProp, StripView, StripViewGroup, type Style, SurfaceHandle, type TextAlign, type TextStyle,
|
|
38
|
+
export { type AnchorTarget, Anchored, type AnchoredPlacement, AnchoredProps, AnnotationDraftMenu, AnnotationDraftMenuProps, type AnnotationFlags, AnnotationLayer, AnnotationLayerProps, AnnotationMenu, AnnotationMenuProps, type AnnotationProps, type AnnotationPropsPatch, AnnotationRenderer, AnnotationRendererProps, type Border, CollapsedGroupView, type CreationDraftAnchor, CustomSlotCtx, DocumentGate, DocumentGateProps, DocumentScope, DocumentScopeProps, EmbedPDF, FormLayer, type FormScriptingUiHandlers, type Geom, GroupDisclosureView, type LineEnding, type LineEndings, LinkLayer, LinkLayerProps, MenusHandle, OverflowMenuView, PageContextValue, PagePointerSource, PageProvider, PageView, PageViewProps, ProjectorBinding, ProjectorProvider, type PropKey, type PropSpec, type RenderItem, RenderLayer, RenderLayerProps, Scrollbar, ScrollbarAxis, ScrollbarProps, SearchLayer, SelectionAnchor, SelectionClipboard, SelectionClipboardProps, type SelectionFlags, SelectionLayer, SelectionLayerProps, SelectionMenu, SelectionMenuProps, type SelectionProps, Stage, StageProps, StageTokenProp, StripView, StripViewGroup, type Style, SurfaceHandle, type TextAlign, type TextStyle, ToolCursorImage, ToolCursorSpec, Toolbar, ToolbarProps, UseViews, type ViewProjector, Viewer, ViewerProps, copySelection, createClickCounter, filePickerProvider, isMacPlatform, makePageContext, sameAnchor, sameCreationDraftAnchor, shallowArray, useActiveDocumentId, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useArmStampAsset, useCapability, useCommand, useCommandShortcuts, useCommands, useDocumentId, useDocumentStatus, useDocuments, useFilePickerProvider, useForm, useFormField, useFormScriptingProvider, useI18n, useKernel, useKernelValue, useLayout, useLink, useLocale, useMenus, useMetadata, useOptionalCapability, useOptionalSelector, usePage, usePageEditor, usePageList, usePages, usePendingRedactions, useProjectorBinding, useRedaction, useScrollMetrics, useSearch, useSearchState, useSelection, useSelectionFlags, useSelectionProps, useSelector, useShell, useStage, useStageSettings, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampLibraries, useStripView, useSurface, useT, useTool, useToolCursor, useViews, useZoom };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { PagePointerSource, createClickCounter, useTool, useToolCursor } from ".
|
|
|
4
4
|
import { Stage, useLayout, usePageList, usePages, useStage, useStageSettings, useZoom } from "./stage.js";
|
|
5
5
|
import { Scrollbar, useScrollMetrics } from "./scrollbar.js";
|
|
6
6
|
import { PageView } from "./page-view.js";
|
|
7
|
-
import { RenderLayer
|
|
7
|
+
import { RenderLayer } from "./render.js";
|
|
8
8
|
import { SelectionClipboard, SelectionLayer, SelectionMenu, copySelection, useSelection } from "./selection.js";
|
|
9
9
|
import { AnnotationLayer, filePickerProvider, sameAnchor, sameCreationDraftAnchor, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useFilePickerProvider, useSelectionFlags, useSelectionProps } from "./annotation.js";
|
|
10
10
|
import { AnnotationDraftMenu, AnnotationMenu } from "./annotation-menu.js";
|
|
@@ -35,4 +35,4 @@ export * from "@embedpdf/plugin-stamp";
|
|
|
35
35
|
export * from "@embedpdf/plugin-commands";
|
|
36
36
|
export * from "@embedpdf/plugin-shell";
|
|
37
37
|
export * from "@embedpdf/core-ui";
|
|
38
|
-
export { Anchored, AnnotationDraftMenu, AnnotationLayer, AnnotationMenu, DocumentGate, DocumentScope, EmbedPDF, FormLayer, LinkLayer, PagePointerSource, PageProvider, PageView, ProjectorProvider, RenderLayer, Scrollbar, SearchLayer, SelectionClipboard, SelectionLayer, SelectionMenu, Stage,
|
|
38
|
+
export { Anchored, AnnotationDraftMenu, AnnotationLayer, AnnotationMenu, DocumentGate, DocumentScope, EmbedPDF, FormLayer, LinkLayer, PagePointerSource, PageProvider, PageView, ProjectorProvider, RenderLayer, Scrollbar, SearchLayer, SelectionClipboard, SelectionLayer, SelectionMenu, Stage, Toolbar, Viewer, copySelection, createClickCounter, filePickerProvider, isMacPlatform, makePageContext, sameAnchor, sameCreationDraftAnchor, shallowArray, useActiveDocumentId, useAnnotation, useAnnotationDefaults, useAnnotationSelected, useAnnotationSelection, useArmStampAsset, useCapability, useCommand, useCommandShortcuts, useCommands, useDocumentId, useDocumentStatus, useDocuments, useFilePickerProvider, useForm, useFormField, useFormScriptingProvider, useI18n, useKernel, useKernelValue, useLayout, useLink, useLocale, useMenus, useMetadata, useOptionalCapability, useOptionalSelector, usePage, usePageEditor, usePageList, usePages, usePendingRedactions, useProjectorBinding, useRedaction, useScrollMetrics, useSearch, useSearchState, useSelection, useSelectionFlags, useSelectionProps, useSelector, useShell, useStage, useStageSettings, useStamp, useStampAssetPreviewUrl, useStampAssets, useStampLibraries, useStripView, useSurface, useT, useTool, useToolCursor, useViews, useZoom };
|
package/dist/render.cjs
CHANGED
|
@@ -4,11 +4,14 @@ const require_runtime = require("./runtime.cjs");
|
|
|
4
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
5
|
let react = require("react");
|
|
6
6
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
7
|
+
let _embedpdf_web = require("@embedpdf/web");
|
|
7
8
|
let _embedpdf_plugin_render = require("@embedpdf/plugin-render");
|
|
8
9
|
//#region src/render.tsx
|
|
9
|
-
|
|
10
|
+
let warnedTileSize = false;
|
|
11
|
+
function RenderLayer({ annotations = true, tiles = true } = {}) {
|
|
10
12
|
const page = require_runtime.usePage();
|
|
11
13
|
const render = require_runtime.useCapability(_embedpdf_plugin_render.RenderToken);
|
|
14
|
+
const settings = render.paintSettings();
|
|
12
15
|
const ref = (0, react.useRef)(null);
|
|
13
16
|
const sourceKey = require_runtime.useSelector(_embedpdf_plugin_render.RenderToken, (c) => c.renderSourceKey(page.pon, {
|
|
14
17
|
scale: page.transform.renderScale,
|
|
@@ -41,7 +44,7 @@ function RenderLayer({ annotations = true } = {}) {
|
|
|
41
44
|
page.pon,
|
|
42
45
|
sourceKey
|
|
43
46
|
]);
|
|
44
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
47
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
45
48
|
ref,
|
|
46
49
|
alt: "",
|
|
47
50
|
draggable: false,
|
|
@@ -52,19 +55,26 @@ function RenderLayer({ annotations = true } = {}) {
|
|
|
52
55
|
height: "100%",
|
|
53
56
|
pointerEvents: "none"
|
|
54
57
|
}
|
|
55
|
-
})
|
|
58
|
+
}), tiles && settings.tiles ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TilePlane, {
|
|
59
|
+
annotations,
|
|
60
|
+
fadeMs: settings.fadeMs
|
|
61
|
+
}) : null] });
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
|
-
*
|
|
64
|
+
* The sharp plane above the base — the plugin's retention-safe paint plan
|
|
65
|
+
* as keyed <img>s. Each tile reports painted after its first presentation
|
|
66
|
+
* opportunity (and its inverse on unmount), so retained coarser generations
|
|
67
|
+
* release only when their replacement is truly compositable.
|
|
59
68
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
69
|
+
* Tiles are placed in VIEW (CSS px) space directly — never in page points
|
|
70
|
+
* under a scaled container. Blink quantizes layout lengths to 1/64 CSS px
|
|
71
|
+
* BEFORE transforms apply, so a pt-space rect under a ×25 zoom transform
|
|
72
|
+
* turns that harmless 1/64 into ±0.4px+ of per-tile misplacement — visible
|
|
73
|
+
* seams and per-zoom-step letter shifts that grow with depth. In view
|
|
74
|
+
* space the same quantization is a fixed ~1/64 CSS px at every zoom.
|
|
75
|
+
* (v2 placed tiles in screen px for exactly this reason.)
|
|
66
76
|
*/
|
|
67
|
-
function
|
|
77
|
+
function TilePlane({ annotations, fadeMs }) {
|
|
68
78
|
const page = require_runtime.usePage();
|
|
69
79
|
const render = require_runtime.useCapability(_embedpdf_plugin_render.RenderToken);
|
|
70
80
|
const demand = page.getViewDemand?.() ?? { desiredDeviceWidth: page.transform.deviceWidth };
|
|
@@ -72,64 +82,70 @@ function TileLayer({ annotations = true } = {}) {
|
|
|
72
82
|
(0, react.useEffect)(() => () => render.releaseTiles(page.pon), [render, page.pon]);
|
|
73
83
|
if (plan.paint.length === 0) return null;
|
|
74
84
|
const t = page.transform;
|
|
75
|
-
const
|
|
76
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
85
|
+
const s = t.viewScale;
|
|
86
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
77
87
|
style: {
|
|
78
88
|
position: "absolute",
|
|
79
89
|
left: 0,
|
|
80
90
|
top: 0,
|
|
81
|
-
width: t.contentWidth
|
|
82
|
-
height: t.contentHeight
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
pointerEvents: "none"
|
|
91
|
+
width: t.contentWidth,
|
|
92
|
+
height: t.contentHeight,
|
|
93
|
+
pointerEvents: "none",
|
|
94
|
+
isolation: "isolate"
|
|
86
95
|
},
|
|
87
|
-
children: plan.paint.map((source) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TileImg, {
|
|
96
|
+
children: [fadeMs > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: `@keyframes epdf-tile-in { from { opacity: 0 } to { opacity: 1 } }` }) : null, plan.paint.map((source) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TileImg, {
|
|
88
97
|
source,
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
view: {
|
|
99
|
+
x: source.rect.x * s,
|
|
100
|
+
y: source.rect.y * s,
|
|
101
|
+
width: source.rect.width * s,
|
|
102
|
+
height: source.rect.height * s
|
|
103
|
+
},
|
|
104
|
+
fadeMs,
|
|
105
|
+
onPainted: () => render.tilePainted(page.pon, source.key),
|
|
106
|
+
onUnpainted: () => render.tileUnpainted(page.pon, source.key)
|
|
107
|
+
}, source.key))]
|
|
91
108
|
});
|
|
92
109
|
}
|
|
93
|
-
/** One tile:
|
|
94
|
-
|
|
110
|
+
/** One tile: geometry plus the shared browser image binding. The binding
|
|
111
|
+
* hides the incomplete image, reports painted after its first presentation
|
|
112
|
+
* opportunity, and inverts that report when the element leaves the DOM. */
|
|
113
|
+
function TileImg({ source, view, fadeMs, onPainted, onUnpainted }) {
|
|
95
114
|
const ref = (0, react.useRef)(null);
|
|
96
|
-
(0, react.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (controller.signal.aborted) {
|
|
103
|
-
obj.revoke();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
revoke = obj.revoke;
|
|
107
|
-
if (ref.current) ref.current.src = obj.url;
|
|
108
|
-
} catch {}
|
|
109
|
-
})();
|
|
110
|
-
return () => {
|
|
111
|
-
controller.abort();
|
|
112
|
-
revoke?.();
|
|
113
|
-
};
|
|
115
|
+
(0, react.useLayoutEffect)(() => {
|
|
116
|
+
if (!ref.current) return;
|
|
117
|
+
return (0, _embedpdf_web.bindPaintedImage)(ref.current, source.handle, {
|
|
118
|
+
onPainted,
|
|
119
|
+
onUnpainted
|
|
120
|
+
});
|
|
114
121
|
}, [source.handle]);
|
|
115
122
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
116
123
|
ref,
|
|
117
124
|
alt: "",
|
|
118
125
|
draggable: false,
|
|
119
|
-
onLoad:
|
|
126
|
+
onLoad: (e) => {
|
|
127
|
+
const w = e.currentTarget.naturalWidth;
|
|
128
|
+
if (w > 0 && !warnedTileSize) {
|
|
129
|
+
const expected = Math.round(source.rect.width * source.scale);
|
|
130
|
+
if (Math.abs(w - expected) > 1) {
|
|
131
|
+
warnedTileSize = true;
|
|
132
|
+
console.warn(`[render] tile bitmap ${w}px wide does not match its rect (expected ~${expected}px) — stale raster identity? key=${source.key}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
120
136
|
style: {
|
|
121
137
|
position: "absolute",
|
|
122
|
-
left:
|
|
123
|
-
top:
|
|
124
|
-
width:
|
|
125
|
-
height:
|
|
126
|
-
zIndex: source.z
|
|
138
|
+
left: view.x,
|
|
139
|
+
top: view.y,
|
|
140
|
+
width: view.width,
|
|
141
|
+
height: view.height,
|
|
142
|
+
zIndex: source.z,
|
|
143
|
+
...fadeMs > 0 ? { animation: `epdf-tile-in ${fadeMs}ms ease-out` } : null
|
|
127
144
|
}
|
|
128
145
|
});
|
|
129
146
|
}
|
|
130
147
|
//#endregion
|
|
131
148
|
exports.RenderLayer = RenderLayer;
|
|
132
|
-
exports.TileLayer = TileLayer;
|
|
133
149
|
Object.keys(_embedpdf_plugin_render).forEach(function(k) {
|
|
134
150
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
135
151
|
enumerable: true,
|
package/dist/render.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.cjs","names":["usePage","useCapability","RenderToken","useSelector"],"sources":["../src/render.tsx"],"sourcesContent":["/**\n * RenderLayer + TileLayer — the React views of @embedpdf/plugin-render.\n *\n * RenderLayer paints the BASE rung to an <img> from the engine's ENCODED\n * image() (identical for local & cloud). TileLayer paints the tile paint-plan\n * ABOVE it when the deployment lattice caps the base below the demand — mount\n * it per lens (the main stage yes, a thumbnail rail no); where the demand is\n * small it engages nothing. Both are dumb painters: every decision (policy\n * conformance, want sets, retention, release) is plugin-render's.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-render';\nimport * as React from 'react';\nimport { useEffect, useRef } from 'react';\nimport { RenderToken } from '@embedpdf/plugin-render';\nimport type { PageViewDemand, TilePaintSource } from '@embedpdf/plugin-render';\nimport { useCapability, usePage, useSelector } from './runtime';\n\nexport interface RenderLayerProps {\n /**\n * Bake annotations into the page bitmap (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.\n */\n annotations?: boolean;\n}\n\nexport function RenderLayer({ annotations = true }: RenderLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n const ref = useRef<HTMLImageElement>(null);\n // ONE dependency: the raster's canonical identity — conformed viewport +\n // annotations flag + epoch. Inside a lattice\n // rung, zoom changes don't move it: no refetch, no DOM churn — the stage's\n // CSS transform does the scaling. It changes exactly at rung crossings and\n // on CONFIRMED mutations (epoch bumps at commit, never mid-gesture). Under\n // `continuous` it embeds the exact scale — v2 behavior byte-for-byte. The\n // policy behind it is a document fact the kernel materialized before\n // publish, so the key is always computable.\n const sourceKey = useSelector(RenderToken, (c) =>\n c.renderSourceKey(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n }),\n );\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n // The capability conforms this to the policy (lattice → ladder width,\n // continuous → this exact scale) and collapses same-key asks in its\n // raster store. A stale-closure scale is harmless by construction:\n // any scale in this rung produces this key's canonical request.\n const image = await render.renderPage(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n signal: controller.signal,\n });\n const obj = await image.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (camera moved / unmounted) or render failed */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- sourceKey IS the\n // render identity; scale/annotations/epoch are folded into it upstream.\n }, [render, page.pon, sourceKey]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n }}\n />\n );\n}\n\nexport interface TileLayerProps {\n /**\n * Bake annotations into tile bitmaps (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering — the composition that keeps\n * tile artifacts annotation-version-free (CDN-stable across edits).\n */\n annotations?: boolean;\n}\n\n/**\n * TileLayer — the sharp plane above the base rung.\n *\n * Mounting it is the per-lens OPT-IN; whether it spends anything is demand\n * arithmetic (a thumbnail rail's demand never engages). The paint list is the\n * plugin's retention-safe plan: keyed <img>s inside ONE container that carries\n * the page scale as a single transform (one rounding context — no tile seams),\n * with `onLoad` reporting the decode boundary back so retained coarser\n * generations release only when their replacement is truly on screen.\n */\nexport function TileLayer({ annotations = true }: TileLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n // Demand: the host's live camera view (Stage) or whole-page (PageView).\n const demand: PageViewDemand = page.getViewDemand?.() ?? {\n desiredDeviceWidth: page.transform.deviceWidth,\n };\n const plan = useSelector(RenderToken, (c) =>\n c.tilePlan(page.pon, demand, { includeAnnotations: annotations }),\n );\n // Lens unmounted: stop in-flight tile fetches; resolved bytes stay cached.\n useEffect(() => () => render.releaseTiles(page.pon), [render, page.pon]);\n if (plan.paint.length === 0) return null;\n const t = page.transform;\n const scale = t.viewScale;\n return (\n <div\n style={{\n position: 'absolute',\n left: 0,\n top: 0,\n width: t.contentWidth / scale,\n height: t.contentHeight / scale,\n transform: `scale(${scale})`,\n transformOrigin: '0 0',\n pointerEvents: 'none',\n }}\n >\n {plan.paint.map((source) => (\n <TileImg\n key={source.key}\n source={source}\n onPainted={() => render.tilePainted(page.pon, source.key)}\n />\n ))}\n </div>\n );\n}\n\n/** One tile: object-URL lifecycle + the painted (decode-boundary) report. */\nfunction TileImg({ source, onPainted }: { source: TilePaintSource; onPainted: () => void }) {\n const ref = useRef<HTMLImageElement>(null);\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n const obj = await source.handle.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (plan moved on) */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n }, [source.handle]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n onLoad={onPainted}\n style={{\n position: 'absolute',\n left: source.rect.x,\n top: source.rect.y,\n width: source.rect.width,\n height: source.rect.height,\n z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AAA,kBAAA,IAAA,CAAC,OAAD;EACO;EACL,KAAI;EACJ,WAAW;EACX,QAAQ;EACR,OAAO;GACL,UAAU;GACV,MAAM,OAAO,KAAK;GAClB,KAAK,OAAO,KAAK;GACjB,OAAO,OAAO,KAAK;GACnB,QAAQ,OAAO,KAAK;GACpB,QAAQ,OAAO;EACjB;CACD,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"render.cjs","names":["usePage","useCapability","RenderToken","useSelector"],"sources":["../src/render.tsx"],"sourcesContent":["/**\n * RenderLayer — the React view of @embedpdf/plugin-render. The page raster\n * is ONE concern with two planes:\n *\n * - the BASE plane: a whole-page <img> at the plugin's resolved render\n * points — the exact settled demand capped at the pixel budget on a\n * continuous (local) engine, the advertised ladder on a lattice (cloud)\n * deployment. Always present; the instant backdrop.\n * - the TILE plane: the plugin's retention-safe paint plan above it,\n * engaging by demand arithmetic when the view wants more pixels than\n * the base may spend. A thumbnail-sized demand engages nothing — the\n * arithmetic is the configuration.\n *\n * The layer is a DUMB painter, deliberately thin: plain <img>s bound through\n * the shared browser adapter, with painted/unpainted reports around their\n * visible lifetime. Every decision — strategy ∧ policy conformance, want\n * sets, level settling, retention, release — is plugin-render's; anything\n * mid-gesture simply CSS-scales until the plugin hands down new pixels.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-render';\nimport * as React from 'react';\nimport { useEffect, useLayoutEffect, useRef } from 'react';\nimport { RenderToken } from '@embedpdf/plugin-render';\nimport type { PageViewDemand, TilePaintSource } from '@embedpdf/plugin-render';\nimport { bindPaintedImage } from '@embedpdf/web';\nimport { useCapability, usePage, useSelector } from './runtime';\n\nexport interface RenderLayerProps {\n /**\n * Bake annotations into the page bitmap (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.\n */\n annotations?: boolean;\n /**\n * Mount the tile plane (default true). Whether it SPENDS anything is\n * demand arithmetic — leave it on; pass false only for a lens that must\n * never tile even under deep zoom.\n */\n tiles?: boolean;\n}\n\nlet warnedTileSize = false;\n\nexport function RenderLayer({ annotations = true, tiles = true }: RenderLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n const settings = render.paintSettings();\n const ref = useRef<HTMLImageElement>(null);\n\n // ONE dependency: the raster's canonical identity — conformed width +\n // annotations flag + epoch. Under a lattice it moves only at rung\n // crossings; under exact mode it tracks the demand and is CONSTANT above\n // the budget — so the deep-zoom backdrop never refetches, and the sub-\n // budget range refetches per settled demand exactly like v2 did.\n const sourceKey = useSelector(RenderToken, (c) =>\n c.renderSourceKey(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n }),\n );\n\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n // The capability conforms this to the resolved render points and\n // collapses same-key asks in its raster store. A stale-closure scale\n // is harmless by construction: any scale mapping to this key\n // produces this key's canonical request.\n const image = await render.renderPage(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n signal: controller.signal,\n });\n const obj = await image.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n // Imperative src on a STABLE element: the browser keeps the old\n // bitmap until the new one decodes, and nothing ever re-requests the\n // old URL — so revoke-on-cleanup is safe here by construction.\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (camera moved / unmounted) or render failed */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- sourceKey IS the\n // render identity; scale/annotations/epoch are folded into it upstream.\n }, [render, page.pon, sourceKey]);\n\n return (\n <>\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n }}\n />\n {tiles && settings.tiles ? (\n <TilePlane annotations={annotations} fadeMs={settings.fadeMs} />\n ) : null}\n </>\n );\n}\n\n/**\n * The sharp plane above the base — the plugin's retention-safe paint plan\n * as keyed <img>s. Each tile reports painted after its first presentation\n * opportunity (and its inverse on unmount), so retained coarser generations\n * release only when their replacement is truly compositable.\n *\n * Tiles are placed in VIEW (CSS px) space directly — never in page points\n * under a scaled container. Blink quantizes layout lengths to 1/64 CSS px\n * BEFORE transforms apply, so a pt-space rect under a ×25 zoom transform\n * turns that harmless 1/64 into ±0.4px+ of per-tile misplacement — visible\n * seams and per-zoom-step letter shifts that grow with depth. In view\n * space the same quantization is a fixed ~1/64 CSS px at every zoom.\n * (v2 placed tiles in screen px for exactly this reason.)\n */\nfunction TilePlane({ annotations, fadeMs }: { annotations: boolean; fadeMs: number }) {\n const page = usePage();\n const render = useCapability(RenderToken);\n // Demand: the host's live camera view (Stage) or whole-page (PageView).\n // Level settling lives in the plugin (its settle gate), pan stays live.\n const demand: PageViewDemand = page.getViewDemand?.() ?? {\n desiredDeviceWidth: page.transform.deviceWidth,\n };\n const plan = useSelector(RenderToken, (c) =>\n c.tilePlan(page.pon, demand, { includeAnnotations: annotations }),\n );\n // Lens unmounted: stop in-flight tile fetches; resolved bytes stay cached.\n useEffect(() => () => render.releaseTiles(page.pon), [render, page.pon]);\n if (plan.paint.length === 0) return null;\n const t = page.transform;\n const s = t.viewScale;\n return (\n <div\n style={{\n position: 'absolute',\n left: 0,\n top: 0,\n width: t.contentWidth,\n height: t.contentHeight,\n pointerEvents: 'none',\n // STACKING CONTRACT: tile <img>s carry zIndex ranks (coarse under\n // fine) that exist only while generations are mixed — mid-zoom. This\n // container MUST be a stacking context so those ranks stay internal;\n // without it they join the Stage's context and paint above every\n // z-auto sibling (annotations, page chrome, menus) exactly while\n // zooming. The old scaled container created one implicitly via its\n // transform; `isolation` is the explicit, no-side-effect way.\n isolation: 'isolate',\n }}\n >\n {fadeMs > 0 ? (\n <style>{`@keyframes epdf-tile-in { from { opacity: 0 } to { opacity: 1 } }`}</style>\n ) : null}\n {plan.paint.map((source) => (\n <TileImg\n key={source.key}\n source={source}\n view={{\n x: source.rect.x * s,\n y: source.rect.y * s,\n width: source.rect.width * s,\n height: source.rect.height * s,\n }}\n fadeMs={fadeMs}\n onPainted={() => render.tilePainted(page.pon, source.key)}\n onUnpainted={() => render.tileUnpainted(page.pon, source.key)}\n />\n ))}\n </div>\n );\n}\n\n/** One tile: geometry plus the shared browser image binding. The binding\n * hides the incomplete image, reports painted after its first presentation\n * opportunity, and inverts that report when the element leaves the DOM. */\nfunction TileImg({\n source,\n view,\n fadeMs,\n onPainted,\n onUnpainted,\n}: {\n source: TilePaintSource;\n /** Placement rect in VIEW (CSS px) space. */\n view: { x: number; y: number; width: number; height: number };\n fadeMs: number;\n onPainted: () => void;\n onUnpainted: () => void;\n}) {\n const ref = useRef<HTMLImageElement>(null);\n useLayoutEffect(() => {\n if (!ref.current) return;\n return bindPaintedImage(ref.current, source.handle, { onPainted, onUnpainted });\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the handle is\n // the bitmap's identity; the report callbacks carry stable values.\n }, [source.handle]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n onLoad={(e) => {\n // A raster whose intrinsic size disagrees with its rect would be\n // silently stretched into place — the stale-handle bug class.\n const w = e.currentTarget.naturalWidth;\n if (w > 0 && !warnedTileSize) {\n const expected = Math.round(source.rect.width * source.scale);\n if (Math.abs(w - expected) > 1) {\n warnedTileSize = true;\n console.warn(\n `[render] tile bitmap ${w}px wide does not match its rect ` +\n `(expected ~${expected}px) — stale raster identity? key=${source.key}`,\n );\n }\n }\n }}\n style={{\n position: 'absolute',\n left: view.x,\n top: view.y,\n width: view.width,\n height: view.height,\n zIndex: source.z,\n ...(fadeMs > 0 ? { animation: `epdf-tile-in ${fadeMs}ms ease-out` } : null),\n }}\n />\n );\n}\n"],"mappings":";;;;;;;;;AA2CA,IAAI,iBAAiB;AAErB,SAAgB,YAAY,EAAE,cAAc,MAAM,QAAQ,SAA2B,CAAC,GAAG;CACvF,MAAM,OAAOA,gBAAAA,QAAQ;CACrB,MAAM,SAASC,gBA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IAAI,SAAS,OAAO,QAAQ;GAAE;GAAW;EAAY,CAAC;CAGhF,GAAG,CAAC,OAAO,MAAM,CAAC;CAClB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACO;EACL,KAAI;EACJ,WAAW;EACX,SAAS,MAAM;GAGb,MAAM,IAAI,EAAE,cAAc;GAC1B,IAAI,IAAI,KAAK,CAAC,gBAAgB;IAC5B,MAAM,WAAW,KAAK,MAAM,OAAO,KAAK,QAAQ,OAAO,KAAK;IAC5D,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,GAAG;KAC9B,iBAAiB;KACjB,QAAQ,KACN,wBAAwB,EAAE,6CACV,SAAS,mCAAmC,OAAO,KACrE;IACF;GACF;EACF;EACA,OAAO;GACL,UAAU;GACV,MAAM,KAAK;GACX,KAAK,KAAK;GACV,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,QAAQ,OAAO;GACf,GAAI,SAAS,IAAI,EAAE,WAAW,gBAAgB,OAAO,aAAa,IAAI;EACxE;CACD,CAAA;AAEL"}
|
package/dist/render.d.cts
CHANGED
|
@@ -6,27 +6,14 @@ interface RenderLayerProps {
|
|
|
6
6
|
* <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.
|
|
7
7
|
*/
|
|
8
8
|
annotations?: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare function RenderLayer({ annotations }?: RenderLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
interface TileLayerProps {
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* tile
|
|
10
|
+
* Mount the tile plane (default true). Whether it SPENDS anything is
|
|
11
|
+
* demand arithmetic — leave it on; pass false only for a lens that must
|
|
12
|
+
* never tile even under deep zoom.
|
|
16
13
|
*/
|
|
17
|
-
|
|
14
|
+
tiles?: boolean;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
* TileLayer — the sharp plane above the base rung.
|
|
21
|
-
*
|
|
22
|
-
* Mounting it is the per-lens OPT-IN; whether it spends anything is demand
|
|
23
|
-
* arithmetic (a thumbnail rail's demand never engages). The paint list is the
|
|
24
|
-
* plugin's retention-safe plan: keyed <img>s inside ONE container that carries
|
|
25
|
-
* the page scale as a single transform (one rounding context — no tile seams),
|
|
26
|
-
* with `onLoad` reporting the decode boundary back so retained coarser
|
|
27
|
-
* generations release only when their replacement is truly on screen.
|
|
28
|
-
*/
|
|
29
|
-
declare function TileLayer({ annotations }?: TileLayerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
declare function RenderLayer({ annotations, tiles }?: RenderLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
30
17
|
//#endregion
|
|
31
|
-
export { RenderLayer, RenderLayerProps
|
|
18
|
+
export { RenderLayer, RenderLayerProps };
|
|
32
19
|
//# sourceMappingURL=render.d.cts.map
|
package/dist/render.d.ts
CHANGED
|
@@ -6,27 +6,14 @@ interface RenderLayerProps {
|
|
|
6
6
|
* <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.
|
|
7
7
|
*/
|
|
8
8
|
annotations?: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare function RenderLayer({ annotations }?: RenderLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
interface TileLayerProps {
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* tile
|
|
10
|
+
* Mount the tile plane (default true). Whether it SPENDS anything is
|
|
11
|
+
* demand arithmetic — leave it on; pass false only for a lens that must
|
|
12
|
+
* never tile even under deep zoom.
|
|
16
13
|
*/
|
|
17
|
-
|
|
14
|
+
tiles?: boolean;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
* TileLayer — the sharp plane above the base rung.
|
|
21
|
-
*
|
|
22
|
-
* Mounting it is the per-lens OPT-IN; whether it spends anything is demand
|
|
23
|
-
* arithmetic (a thumbnail rail's demand never engages). The paint list is the
|
|
24
|
-
* plugin's retention-safe plan: keyed <img>s inside ONE container that carries
|
|
25
|
-
* the page scale as a single transform (one rounding context — no tile seams),
|
|
26
|
-
* with `onLoad` reporting the decode boundary back so retained coarser
|
|
27
|
-
* generations release only when their replacement is truly on screen.
|
|
28
|
-
*/
|
|
29
|
-
declare function TileLayer({ annotations }?: TileLayerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
declare function RenderLayer({ annotations, tiles }?: RenderLayerProps): import("react/jsx-runtime").JSX.Element;
|
|
30
17
|
//#endregion
|
|
31
|
-
export { RenderLayer, RenderLayerProps
|
|
18
|
+
export { RenderLayer, RenderLayerProps };
|
|
32
19
|
//# sourceMappingURL=render.d.ts.map
|
package/dist/render.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { useCapability, usePage, useSelector } from "./runtime.js";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { bindPaintedImage } from "@embedpdf/web";
|
|
4
5
|
import { RenderToken } from "@embedpdf/plugin-render";
|
|
5
6
|
export * from "@embedpdf/plugin-render";
|
|
6
7
|
//#region src/render.tsx
|
|
7
|
-
|
|
8
|
+
let warnedTileSize = false;
|
|
9
|
+
function RenderLayer({ annotations = true, tiles = true } = {}) {
|
|
8
10
|
const page = usePage();
|
|
9
11
|
const render = useCapability(RenderToken);
|
|
12
|
+
const settings = render.paintSettings();
|
|
10
13
|
const ref = useRef(null);
|
|
11
14
|
const sourceKey = useSelector(RenderToken, (c) => c.renderSourceKey(page.pon, {
|
|
12
15
|
scale: page.transform.renderScale,
|
|
@@ -39,7 +42,7 @@ function RenderLayer({ annotations = true } = {}) {
|
|
|
39
42
|
page.pon,
|
|
40
43
|
sourceKey
|
|
41
44
|
]);
|
|
42
|
-
return /* @__PURE__ */ jsx("img", {
|
|
45
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("img", {
|
|
43
46
|
ref,
|
|
44
47
|
alt: "",
|
|
45
48
|
draggable: false,
|
|
@@ -50,19 +53,26 @@ function RenderLayer({ annotations = true } = {}) {
|
|
|
50
53
|
height: "100%",
|
|
51
54
|
pointerEvents: "none"
|
|
52
55
|
}
|
|
53
|
-
})
|
|
56
|
+
}), tiles && settings.tiles ? /* @__PURE__ */ jsx(TilePlane, {
|
|
57
|
+
annotations,
|
|
58
|
+
fadeMs: settings.fadeMs
|
|
59
|
+
}) : null] });
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
56
|
-
*
|
|
62
|
+
* The sharp plane above the base — the plugin's retention-safe paint plan
|
|
63
|
+
* as keyed <img>s. Each tile reports painted after its first presentation
|
|
64
|
+
* opportunity (and its inverse on unmount), so retained coarser generations
|
|
65
|
+
* release only when their replacement is truly compositable.
|
|
57
66
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
67
|
+
* Tiles are placed in VIEW (CSS px) space directly — never in page points
|
|
68
|
+
* under a scaled container. Blink quantizes layout lengths to 1/64 CSS px
|
|
69
|
+
* BEFORE transforms apply, so a pt-space rect under a ×25 zoom transform
|
|
70
|
+
* turns that harmless 1/64 into ±0.4px+ of per-tile misplacement — visible
|
|
71
|
+
* seams and per-zoom-step letter shifts that grow with depth. In view
|
|
72
|
+
* space the same quantization is a fixed ~1/64 CSS px at every zoom.
|
|
73
|
+
* (v2 placed tiles in screen px for exactly this reason.)
|
|
64
74
|
*/
|
|
65
|
-
function
|
|
75
|
+
function TilePlane({ annotations, fadeMs }) {
|
|
66
76
|
const page = usePage();
|
|
67
77
|
const render = useCapability(RenderToken);
|
|
68
78
|
const demand = page.getViewDemand?.() ?? { desiredDeviceWidth: page.transform.deviceWidth };
|
|
@@ -70,62 +80,69 @@ function TileLayer({ annotations = true } = {}) {
|
|
|
70
80
|
useEffect(() => () => render.releaseTiles(page.pon), [render, page.pon]);
|
|
71
81
|
if (plan.paint.length === 0) return null;
|
|
72
82
|
const t = page.transform;
|
|
73
|
-
const
|
|
74
|
-
return /* @__PURE__ */
|
|
83
|
+
const s = t.viewScale;
|
|
84
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
75
85
|
style: {
|
|
76
86
|
position: "absolute",
|
|
77
87
|
left: 0,
|
|
78
88
|
top: 0,
|
|
79
|
-
width: t.contentWidth
|
|
80
|
-
height: t.contentHeight
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
pointerEvents: "none"
|
|
89
|
+
width: t.contentWidth,
|
|
90
|
+
height: t.contentHeight,
|
|
91
|
+
pointerEvents: "none",
|
|
92
|
+
isolation: "isolate"
|
|
84
93
|
},
|
|
85
|
-
children: plan.paint.map((source) => /* @__PURE__ */ jsx(TileImg, {
|
|
94
|
+
children: [fadeMs > 0 ? /* @__PURE__ */ jsx("style", { children: `@keyframes epdf-tile-in { from { opacity: 0 } to { opacity: 1 } }` }) : null, plan.paint.map((source) => /* @__PURE__ */ jsx(TileImg, {
|
|
86
95
|
source,
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
view: {
|
|
97
|
+
x: source.rect.x * s,
|
|
98
|
+
y: source.rect.y * s,
|
|
99
|
+
width: source.rect.width * s,
|
|
100
|
+
height: source.rect.height * s
|
|
101
|
+
},
|
|
102
|
+
fadeMs,
|
|
103
|
+
onPainted: () => render.tilePainted(page.pon, source.key),
|
|
104
|
+
onUnpainted: () => render.tileUnpainted(page.pon, source.key)
|
|
105
|
+
}, source.key))]
|
|
89
106
|
});
|
|
90
107
|
}
|
|
91
|
-
/** One tile:
|
|
92
|
-
|
|
108
|
+
/** One tile: geometry plus the shared browser image binding. The binding
|
|
109
|
+
* hides the incomplete image, reports painted after its first presentation
|
|
110
|
+
* opportunity, and inverts that report when the element leaves the DOM. */
|
|
111
|
+
function TileImg({ source, view, fadeMs, onPainted, onUnpainted }) {
|
|
93
112
|
const ref = useRef(null);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (controller.signal.aborted) {
|
|
101
|
-
obj.revoke();
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
revoke = obj.revoke;
|
|
105
|
-
if (ref.current) ref.current.src = obj.url;
|
|
106
|
-
} catch {}
|
|
107
|
-
})();
|
|
108
|
-
return () => {
|
|
109
|
-
controller.abort();
|
|
110
|
-
revoke?.();
|
|
111
|
-
};
|
|
113
|
+
useLayoutEffect(() => {
|
|
114
|
+
if (!ref.current) return;
|
|
115
|
+
return bindPaintedImage(ref.current, source.handle, {
|
|
116
|
+
onPainted,
|
|
117
|
+
onUnpainted
|
|
118
|
+
});
|
|
112
119
|
}, [source.handle]);
|
|
113
120
|
return /* @__PURE__ */ jsx("img", {
|
|
114
121
|
ref,
|
|
115
122
|
alt: "",
|
|
116
123
|
draggable: false,
|
|
117
|
-
onLoad:
|
|
124
|
+
onLoad: (e) => {
|
|
125
|
+
const w = e.currentTarget.naturalWidth;
|
|
126
|
+
if (w > 0 && !warnedTileSize) {
|
|
127
|
+
const expected = Math.round(source.rect.width * source.scale);
|
|
128
|
+
if (Math.abs(w - expected) > 1) {
|
|
129
|
+
warnedTileSize = true;
|
|
130
|
+
console.warn(`[render] tile bitmap ${w}px wide does not match its rect (expected ~${expected}px) — stale raster identity? key=${source.key}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
118
134
|
style: {
|
|
119
135
|
position: "absolute",
|
|
120
|
-
left:
|
|
121
|
-
top:
|
|
122
|
-
width:
|
|
123
|
-
height:
|
|
124
|
-
zIndex: source.z
|
|
136
|
+
left: view.x,
|
|
137
|
+
top: view.y,
|
|
138
|
+
width: view.width,
|
|
139
|
+
height: view.height,
|
|
140
|
+
zIndex: source.z,
|
|
141
|
+
...fadeMs > 0 ? { animation: `epdf-tile-in ${fadeMs}ms ease-out` } : null
|
|
125
142
|
}
|
|
126
143
|
});
|
|
127
144
|
}
|
|
128
145
|
//#endregion
|
|
129
|
-
export { RenderLayer
|
|
146
|
+
export { RenderLayer };
|
|
130
147
|
|
|
131
148
|
//# sourceMappingURL=render.js.map
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","names":[],"sources":["../src/render.tsx"],"sourcesContent":["/**\n * RenderLayer + TileLayer — the React views of @embedpdf/plugin-render.\n *\n * RenderLayer paints the BASE rung to an <img> from the engine's ENCODED\n * image() (identical for local & cloud). TileLayer paints the tile paint-plan\n * ABOVE it when the deployment lattice caps the base below the demand — mount\n * it per lens (the main stage yes, a thumbnail rail no); where the demand is\n * small it engages nothing. Both are dumb painters: every decision (policy\n * conformance, want sets, retention, release) is plugin-render's.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-render';\nimport * as React from 'react';\nimport { useEffect, useRef } from 'react';\nimport { RenderToken } from '@embedpdf/plugin-render';\nimport type { PageViewDemand, TilePaintSource } from '@embedpdf/plugin-render';\nimport { useCapability, usePage, useSelector } from './runtime';\n\nexport interface RenderLayerProps {\n /**\n * Bake annotations into the page bitmap (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.\n */\n annotations?: boolean;\n}\n\nexport function RenderLayer({ annotations = true }: RenderLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n const ref = useRef<HTMLImageElement>(null);\n // ONE dependency: the raster's canonical identity — conformed viewport +\n // annotations flag + epoch. Inside a lattice\n // rung, zoom changes don't move it: no refetch, no DOM churn — the stage's\n // CSS transform does the scaling. It changes exactly at rung crossings and\n // on CONFIRMED mutations (epoch bumps at commit, never mid-gesture). Under\n // `continuous` it embeds the exact scale — v2 behavior byte-for-byte. The\n // policy behind it is a document fact the kernel materialized before\n // publish, so the key is always computable.\n const sourceKey = useSelector(RenderToken, (c) =>\n c.renderSourceKey(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n }),\n );\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n // The capability conforms this to the policy (lattice → ladder width,\n // continuous → this exact scale) and collapses same-key asks in its\n // raster store. A stale-closure scale is harmless by construction:\n // any scale in this rung produces this key's canonical request.\n const image = await render.renderPage(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n signal: controller.signal,\n });\n const obj = await image.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (camera moved / unmounted) or render failed */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- sourceKey IS the\n // render identity; scale/annotations/epoch are folded into it upstream.\n }, [render, page.pon, sourceKey]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n }}\n />\n );\n}\n\nexport interface TileLayerProps {\n /**\n * Bake annotations into tile bitmaps (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering — the composition that keeps\n * tile artifacts annotation-version-free (CDN-stable across edits).\n */\n annotations?: boolean;\n}\n\n/**\n * TileLayer — the sharp plane above the base rung.\n *\n * Mounting it is the per-lens OPT-IN; whether it spends anything is demand\n * arithmetic (a thumbnail rail's demand never engages). The paint list is the\n * plugin's retention-safe plan: keyed <img>s inside ONE container that carries\n * the page scale as a single transform (one rounding context — no tile seams),\n * with `onLoad` reporting the decode boundary back so retained coarser\n * generations release only when their replacement is truly on screen.\n */\nexport function TileLayer({ annotations = true }: TileLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n // Demand: the host's live camera view (Stage) or whole-page (PageView).\n const demand: PageViewDemand = page.getViewDemand?.() ?? {\n desiredDeviceWidth: page.transform.deviceWidth,\n };\n const plan = useSelector(RenderToken, (c) =>\n c.tilePlan(page.pon, demand, { includeAnnotations: annotations }),\n );\n // Lens unmounted: stop in-flight tile fetches; resolved bytes stay cached.\n useEffect(() => () => render.releaseTiles(page.pon), [render, page.pon]);\n if (plan.paint.length === 0) return null;\n const t = page.transform;\n const scale = t.viewScale;\n return (\n <div\n style={{\n position: 'absolute',\n left: 0,\n top: 0,\n width: t.contentWidth / scale,\n height: t.contentHeight / scale,\n transform: `scale(${scale})`,\n transformOrigin: '0 0',\n pointerEvents: 'none',\n }}\n >\n {plan.paint.map((source) => (\n <TileImg\n key={source.key}\n source={source}\n onPainted={() => render.tilePainted(page.pon, source.key)}\n />\n ))}\n </div>\n );\n}\n\n/** One tile: object-URL lifecycle + the painted (decode-boundary) report. */\nfunction TileImg({ source, onPainted }: { source: TilePaintSource; onPainted: () => void }) {\n const ref = useRef<HTMLImageElement>(null);\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n const obj = await source.handle.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (plan moved on) */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n }, [source.handle]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n onLoad={onPainted}\n style={{\n position: 'absolute',\n left: source.rect.x,\n top: source.rect.y,\n width: source.rect.width,\n height: source.rect.height,\n zIndex: source.z,\n }}\n />\n );\n}\n"],"mappings":";;;;;;AA2BA,SAAgB,YAAY,EAAE,cAAc,SAA2B,CAAC,GAAG;CACzE,MAAM,OAAO,QAAQ;CACrB,MAAM,SAAS,cAAc,WAAW;CACxC,MAAM,MAAM,OAAyB,IAAI;CASzC,MAAM,YAAY,YAAY,cAAc,MAC1C,EAAE,gBAAgB,KAAK,KAAK;EAC1B,OAAO,KAAK,UAAU;EACtB,oBAAoB;CACtB,CAAC,CACH;CACA,gBAAgB;EACd,MAAM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AAe;EACjB;EAEC,UAAA,KAAK,MAAM,KAAK,WACf,oBAAC,SAAD;GAEU;GACR,iBAAiB,OAAO,YAAY,KAAK,KAAK,OAAO,GAAG;EACzD,GAHM,OAAO,GAGb,CACF;CACE,CAAA;AAET;;AAGA,SAAS,QAAQ,EAAE,QAAQ,aAAiE;CAC1F,MAAM,MAAM,OAAyB,IAAI;CACzC,gBAAgB;EACd,MAAM,aAAa,IAAI,gBAAgB;EACvC,IAAI;EACJ,CAAC,YAAY;GACX,IAAI;IACF,MAAM,MAAM,MAAM,OAAO,OAAO,UAAU,WAAW,MAAM;IAC3D,IAAI,WAAW,OAAO,SAAS;KAC7B,IAAI,OAAO;KACX;IACF;IACA,SAAS,IAAI;IACb,IAAI,IAAI,SAAS,IAAI,QAAQ,MAAM,IAAI;GACzC,QAAQ,CAER;EACF,EAAA,CAAG;EACH,aAAa;GACX,WAAW,MAAM;GACjB,SAAS;EACX;CACF,GAAG,CAAC,OAAO,MAAM,CAAC;CAClB,OACE,oBAAC,OAAD;EACO;EACL,KAAI;EACJ,WAAW;EACX,QAAQ;EACR,OAAO;GACL,UAAU;GACV,MAAM,OAAO,KAAK;GAClB,KAAK,OAAO,KAAK;GACjB,OAAO,OAAO,KAAK;GACnB,QAAQ,OAAO,KAAK;GACpB,QAAQ,OAAO;EACjB;CACD,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"render.js","names":[],"sources":["../src/render.tsx"],"sourcesContent":["/**\n * RenderLayer — the React view of @embedpdf/plugin-render. The page raster\n * is ONE concern with two planes:\n *\n * - the BASE plane: a whole-page <img> at the plugin's resolved render\n * points — the exact settled demand capped at the pixel budget on a\n * continuous (local) engine, the advertised ladder on a lattice (cloud)\n * deployment. Always present; the instant backdrop.\n * - the TILE plane: the plugin's retention-safe paint plan above it,\n * engaging by demand arithmetic when the view wants more pixels than\n * the base may spend. A thumbnail-sized demand engages nothing — the\n * arithmetic is the configuration.\n *\n * The layer is a DUMB painter, deliberately thin: plain <img>s bound through\n * the shared browser adapter, with painted/unpainted reports around their\n * visible lifetime. Every decision — strategy ∧ policy conformance, want\n * sets, level settling, retention, release — is plugin-render's; anything\n * mid-gesture simply CSS-scales until the plugin hands down new pixels.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-render';\nimport * as React from 'react';\nimport { useEffect, useLayoutEffect, useRef } from 'react';\nimport { RenderToken } from '@embedpdf/plugin-render';\nimport type { PageViewDemand, TilePaintSource } from '@embedpdf/plugin-render';\nimport { bindPaintedImage } from '@embedpdf/web';\nimport { useCapability, usePage, useSelector } from './runtime';\n\nexport interface RenderLayerProps {\n /**\n * Bake annotations into the page bitmap (default true). Pass false when an\n * <AnnotationLayer> owns annotation rendering, so they aren't drawn twice.\n */\n annotations?: boolean;\n /**\n * Mount the tile plane (default true). Whether it SPENDS anything is\n * demand arithmetic — leave it on; pass false only for a lens that must\n * never tile even under deep zoom.\n */\n tiles?: boolean;\n}\n\nlet warnedTileSize = false;\n\nexport function RenderLayer({ annotations = true, tiles = true }: RenderLayerProps = {}) {\n const page = usePage();\n const render = useCapability(RenderToken);\n const settings = render.paintSettings();\n const ref = useRef<HTMLImageElement>(null);\n\n // ONE dependency: the raster's canonical identity — conformed width +\n // annotations flag + epoch. Under a lattice it moves only at rung\n // crossings; under exact mode it tracks the demand and is CONSTANT above\n // the budget — so the deep-zoom backdrop never refetches, and the sub-\n // budget range refetches per settled demand exactly like v2 did.\n const sourceKey = useSelector(RenderToken, (c) =>\n c.renderSourceKey(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n }),\n );\n\n useEffect(() => {\n const controller = new AbortController();\n let revoke: (() => void) | undefined;\n (async () => {\n try {\n // The capability conforms this to the resolved render points and\n // collapses same-key asks in its raster store. A stale-closure scale\n // is harmless by construction: any scale mapping to this key\n // produces this key's canonical request.\n const image = await render.renderPage(page.pon, {\n scale: page.transform.renderScale,\n includeAnnotations: annotations,\n signal: controller.signal,\n });\n const obj = await image.objectUrl(controller.signal);\n if (controller.signal.aborted) {\n obj.revoke();\n return;\n }\n revoke = obj.revoke;\n // Imperative src on a STABLE element: the browser keeps the old\n // bitmap until the new one decodes, and nothing ever re-requests the\n // old URL — so revoke-on-cleanup is safe here by construction.\n if (ref.current) ref.current.src = obj.url;\n } catch {\n /* aborted (camera moved / unmounted) or render failed */\n }\n })();\n return () => {\n controller.abort();\n revoke?.();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- sourceKey IS the\n // render identity; scale/annotations/epoch are folded into it upstream.\n }, [render, page.pon, sourceKey]);\n\n return (\n <>\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n pointerEvents: 'none',\n }}\n />\n {tiles && settings.tiles ? (\n <TilePlane annotations={annotations} fadeMs={settings.fadeMs} />\n ) : null}\n </>\n );\n}\n\n/**\n * The sharp plane above the base — the plugin's retention-safe paint plan\n * as keyed <img>s. Each tile reports painted after its first presentation\n * opportunity (and its inverse on unmount), so retained coarser generations\n * release only when their replacement is truly compositable.\n *\n * Tiles are placed in VIEW (CSS px) space directly — never in page points\n * under a scaled container. Blink quantizes layout lengths to 1/64 CSS px\n * BEFORE transforms apply, so a pt-space rect under a ×25 zoom transform\n * turns that harmless 1/64 into ±0.4px+ of per-tile misplacement — visible\n * seams and per-zoom-step letter shifts that grow with depth. In view\n * space the same quantization is a fixed ~1/64 CSS px at every zoom.\n * (v2 placed tiles in screen px for exactly this reason.)\n */\nfunction TilePlane({ annotations, fadeMs }: { annotations: boolean; fadeMs: number }) {\n const page = usePage();\n const render = useCapability(RenderToken);\n // Demand: the host's live camera view (Stage) or whole-page (PageView).\n // Level settling lives in the plugin (its settle gate), pan stays live.\n const demand: PageViewDemand = page.getViewDemand?.() ?? {\n desiredDeviceWidth: page.transform.deviceWidth,\n };\n const plan = useSelector(RenderToken, (c) =>\n c.tilePlan(page.pon, demand, { includeAnnotations: annotations }),\n );\n // Lens unmounted: stop in-flight tile fetches; resolved bytes stay cached.\n useEffect(() => () => render.releaseTiles(page.pon), [render, page.pon]);\n if (plan.paint.length === 0) return null;\n const t = page.transform;\n const s = t.viewScale;\n return (\n <div\n style={{\n position: 'absolute',\n left: 0,\n top: 0,\n width: t.contentWidth,\n height: t.contentHeight,\n pointerEvents: 'none',\n // STACKING CONTRACT: tile <img>s carry zIndex ranks (coarse under\n // fine) that exist only while generations are mixed — mid-zoom. This\n // container MUST be a stacking context so those ranks stay internal;\n // without it they join the Stage's context and paint above every\n // z-auto sibling (annotations, page chrome, menus) exactly while\n // zooming. The old scaled container created one implicitly via its\n // transform; `isolation` is the explicit, no-side-effect way.\n isolation: 'isolate',\n }}\n >\n {fadeMs > 0 ? (\n <style>{`@keyframes epdf-tile-in { from { opacity: 0 } to { opacity: 1 } }`}</style>\n ) : null}\n {plan.paint.map((source) => (\n <TileImg\n key={source.key}\n source={source}\n view={{\n x: source.rect.x * s,\n y: source.rect.y * s,\n width: source.rect.width * s,\n height: source.rect.height * s,\n }}\n fadeMs={fadeMs}\n onPainted={() => render.tilePainted(page.pon, source.key)}\n onUnpainted={() => render.tileUnpainted(page.pon, source.key)}\n />\n ))}\n </div>\n );\n}\n\n/** One tile: geometry plus the shared browser image binding. The binding\n * hides the incomplete image, reports painted after its first presentation\n * opportunity, and inverts that report when the element leaves the DOM. */\nfunction TileImg({\n source,\n view,\n fadeMs,\n onPainted,\n onUnpainted,\n}: {\n source: TilePaintSource;\n /** Placement rect in VIEW (CSS px) space. */\n view: { x: number; y: number; width: number; height: number };\n fadeMs: number;\n onPainted: () => void;\n onUnpainted: () => void;\n}) {\n const ref = useRef<HTMLImageElement>(null);\n useLayoutEffect(() => {\n if (!ref.current) return;\n return bindPaintedImage(ref.current, source.handle, { onPainted, onUnpainted });\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the handle is\n // the bitmap's identity; the report callbacks carry stable values.\n }, [source.handle]);\n return (\n <img\n ref={ref}\n alt=\"\"\n draggable={false}\n onLoad={(e) => {\n // A raster whose intrinsic size disagrees with its rect would be\n // silently stretched into place — the stale-handle bug class.\n const w = e.currentTarget.naturalWidth;\n if (w > 0 && !warnedTileSize) {\n const expected = Math.round(source.rect.width * source.scale);\n if (Math.abs(w - expected) > 1) {\n warnedTileSize = true;\n console.warn(\n `[render] tile bitmap ${w}px wide does not match its rect ` +\n `(expected ~${expected}px) — stale raster identity? key=${source.key}`,\n );\n }\n }\n }}\n style={{\n position: 'absolute',\n left: view.x,\n top: view.y,\n width: view.width,\n height: view.height,\n zIndex: source.z,\n ...(fadeMs > 0 ? { animation: `epdf-tile-in ${fadeMs}ms ease-out` } : null),\n }}\n />\n );\n}\n"],"mappings":";;;;;;;AA2CA,IAAI,iBAAiB;AAErB,SAAgB,YAAY,EAAE,cAAc,MAAM,QAAQ,SAA2B,CAAC,GAAG;CACvF,MAAM,OAAO,QAAQ;CACrB,MAAM,SAAS,cAAc,WAAW;CACxC,MAAM,WAAW,OAAO,cAAc;CACtC,MAAM,MAAM,OAAyB,IAAI;CAOzC,MAAM,YAAY,YAAY,cAAc,MAC1C,EAAE,gBAAgB,KAAK,KAAK;EAC1B,OAAO,KAAK,UAAU;EACtB,oBAAoB;CACtB,CAAC,CACH;CAEA,gBAAgB;EACd,MAAM,aAAa,IAAI,gBAAgB;EACvC,IAAI;EACJ,CAAC,YAAY;GACX,IAAI;IAUF,MAAM,MAAM,OAAM,MALE,OAAO,WAAW,KAAK,KAAK;KAC9C,OAAO,KAAK,UAAU;KACtB,oBAAoB;KACpB,QAAQ,WAAW;IACrB,CAAC,EAAA,CACuB,UAAU,WAAW,MAAM;IACnD,IAAI,WAAW,OAAO,SAAS;KAC7B,IAAI,OAAO;KACX;IACF;IACA,SAAS,IAAI;IAIb,IAAI,IAAI,SAAS,IAAI,QAAQ,MAAM,IAAI;GACzC,QAAQ,CAER;EACF,EAAA,CAAG;EACH,aAAa;GACX,WAAW,MAAM;GACjB,SAAS;EACX;CAGF,GAAG;EAAC;EAAQ,KAA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AAO,GAAG;EAC7D,GAXM,OAAO,GAWb,CACF,CACE;;AAET;;;;AAKA,SAAS,QAAQ,EACf,QACA,MACA,QACA,WACA,eAQC;CACD,MAAM,MAAM,OAAyB,IAAI;CACzC,sBAAsB;EACpB,IAAI,CAAC,IAAI,SAAS;EAClB,OAAO,iBAAiB,IAAI,SAAS,OAAO,QAAQ;GAAE;GAAW;EAAY,CAAC;CAGhF,GAAG,CAAC,OAAO,MAAM,CAAC;CAClB,OACE,oBAAC,OAAD;EACO;EACL,KAAI;EACJ,WAAW;EACX,SAAS,MAAM;GAGb,MAAM,IAAI,EAAE,cAAc;GAC1B,IAAI,IAAI,KAAK,CAAC,gBAAgB;IAC5B,MAAM,WAAW,KAAK,MAAM,OAAO,KAAK,QAAQ,OAAO,KAAK;IAC5D,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,GAAG;KAC9B,iBAAiB;KACjB,QAAQ,KACN,wBAAwB,EAAE,6CACV,SAAS,mCAAmC,OAAO,KACrE;IACF;GACF;EACF;EACA,OAAO;GACL,UAAU;GACV,MAAM,KAAK;GACX,KAAK,KAAK;GACV,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,QAAQ,OAAO;GACf,GAAI,SAAS,IAAI,EAAE,WAAW,gBAAgB,OAAO,aAAa,IAAI;EACxE;CACD,CAAA;AAEL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/react",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React adapter for EmbedPDF v3: one generic reactive binding + structural components (Viewer, Stage, PageView) + headless layers & hooks. The whole framework surface.",
|
|
6
6
|
"type": "module",
|
|
@@ -107,28 +107,28 @@
|
|
|
107
107
|
"dist"
|
|
108
108
|
],
|
|
109
109
|
"dependencies": {
|
|
110
|
-
"@embedpdf/core-annotation": "3.0.0-next.
|
|
111
|
-
"@embedpdf/core
|
|
112
|
-
"@embedpdf/plugin-commands": "3.0.0-next.
|
|
113
|
-
"@embedpdf/plugin-annotation": "3.0.0-next.
|
|
114
|
-
"@embedpdf/plugin-form": "3.0.0-next.
|
|
115
|
-
"@embedpdf/
|
|
116
|
-
"@embedpdf/plugin-interaction": "3.0.0-next.
|
|
117
|
-
"@embedpdf/plugin-
|
|
118
|
-
"@embedpdf/
|
|
119
|
-
"@embedpdf/plugin-metadata": "3.0.0-next.
|
|
120
|
-
"@embedpdf/plugin-
|
|
121
|
-
"@embedpdf/plugin-
|
|
122
|
-
"@embedpdf/plugin-
|
|
123
|
-
"@embedpdf/plugin-
|
|
124
|
-
"@embedpdf/plugin-
|
|
125
|
-
"@embedpdf/plugin-
|
|
126
|
-
"@embedpdf/plugin-
|
|
127
|
-
"@embedpdf/plugin-
|
|
128
|
-
"@embedpdf/
|
|
129
|
-
"@embedpdf/
|
|
130
|
-
"@embedpdf/core-ui": "3.0.0-next.
|
|
131
|
-
"@embedpdf/web": "3.0.0-next.
|
|
110
|
+
"@embedpdf/core-annotation": "3.0.0-next.6",
|
|
111
|
+
"@embedpdf/core": "3.0.0-next.6",
|
|
112
|
+
"@embedpdf/plugin-commands": "3.0.0-next.6",
|
|
113
|
+
"@embedpdf/plugin-annotation": "3.0.0-next.6",
|
|
114
|
+
"@embedpdf/plugin-form": "3.0.0-next.6",
|
|
115
|
+
"@embedpdf/plugin-i18n": "3.0.0-next.6",
|
|
116
|
+
"@embedpdf/plugin-interaction": "3.0.0-next.6",
|
|
117
|
+
"@embedpdf/plugin-link": "3.0.0-next.6",
|
|
118
|
+
"@embedpdf/core-geometry": "3.0.0-next.6",
|
|
119
|
+
"@embedpdf/plugin-metadata": "3.0.0-next.6",
|
|
120
|
+
"@embedpdf/plugin-redaction": "3.0.0-next.6",
|
|
121
|
+
"@embedpdf/plugin-render": "3.0.0-next.6",
|
|
122
|
+
"@embedpdf/plugin-page-edit": "3.0.0-next.6",
|
|
123
|
+
"@embedpdf/plugin-search": "3.0.0-next.6",
|
|
124
|
+
"@embedpdf/plugin-shell": "3.0.0-next.6",
|
|
125
|
+
"@embedpdf/plugin-stage": "3.0.0-next.6",
|
|
126
|
+
"@embedpdf/plugin-selection": "3.0.0-next.6",
|
|
127
|
+
"@embedpdf/plugin-view-manager": "3.0.0-next.6",
|
|
128
|
+
"@embedpdf/plugin-stamp": "3.0.0-next.6",
|
|
129
|
+
"@embedpdf/core-stage": "3.0.0-next.6",
|
|
130
|
+
"@embedpdf/core-ui": "3.0.0-next.6",
|
|
131
|
+
"@embedpdf/web": "3.0.0-next.6"
|
|
132
132
|
},
|
|
133
133
|
"peerDependencies": {
|
|
134
134
|
"react": ">=18",
|