@seamless-co/pagemark 0.0.0-stage → 0.5.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 +21 -0
- package/README.md +25 -2
- package/behaviours/behaviour.d.ts +43 -0
- package/behaviours/behaviour.js +84 -0
- package/behaviours/comparison.d.ts +62 -0
- package/behaviours/comparison.js +129 -0
- package/behaviours/document-viewer.d.ts +9 -0
- package/behaviours/document-viewer.js +9 -0
- package/behaviours/hidden.d.ts +24 -0
- package/behaviours/hidden.js +38 -0
- package/behaviours/hover.d.ts +34 -0
- package/behaviours/hover.js +49 -0
- package/behaviours/index.d.ts +24 -0
- package/behaviours/index.js +14 -0
- package/behaviours/linked-viewers.d.ts +14 -0
- package/behaviours/linked-viewers.js +25 -0
- package/behaviours/links.d.ts +4 -0
- package/behaviours/links.js +4 -0
- package/behaviours/marks.d.ts +64 -0
- package/behaviours/marks.js +33 -0
- package/behaviours/quotes.d.ts +7 -0
- package/behaviours/quotes.js +9 -0
- package/behaviours/region.d.ts +27 -0
- package/behaviours/region.js +40 -0
- package/behaviours/search.d.ts +38 -0
- package/behaviours/search.js +63 -0
- package/behaviours/selection.d.ts +30 -0
- package/behaviours/selection.js +41 -0
- package/behaviours/text.d.ts +8 -0
- package/behaviours/text.js +24 -0
- package/behaviours/viewer-state.d.ts +36 -0
- package/behaviours/viewer-state.js +58 -0
- package/browser/blob-pieces.d.ts +9 -0
- package/browser/blob-pieces.js +50 -0
- package/browser/browser-source.d.ts +25 -0
- package/browser/browser-source.js +62 -0
- package/browser/index.d.ts +2 -0
- package/browser/index.js +1 -0
- package/browser/local-pdf.d.ts +27 -0
- package/browser/local-pdf.js +61 -0
- package/browser/worker-engine.d.ts +21 -0
- package/browser/worker-engine.js +1 -0
- package/browser/worker.d.ts +1 -0
- package/browser/worker.js +51 -0
- package/core/compare.d.ts +55 -0
- package/core/compare.js +350 -0
- package/core/find.d.ts +12 -0
- package/core/find.js +177 -0
- package/core/hidden.d.ts +12 -0
- package/core/hidden.js +26 -0
- package/core/index.d.ts +11 -0
- package/core/index.js +6 -0
- package/core/links.d.ts +7 -0
- package/core/links.js +19 -0
- package/core/locate.d.ts +21 -0
- package/core/locate.js +140 -0
- package/core/paragraphs.d.ts +37 -0
- package/core/paragraphs.js +141 -0
- package/core/types.d.ts +89 -0
- package/core/types.js +1 -0
- package/document/document.d.ts +83 -0
- package/document/document.js +215 -0
- package/document/handover-source.d.ts +18 -0
- package/document/handover-source.js +39 -0
- package/document/index.d.ts +10 -0
- package/document/index.js +5 -0
- package/document/reading-source.d.ts +7 -0
- package/document/reading-source.js +16 -0
- package/document/server-source.d.ts +10 -0
- package/document/server-source.js +23 -0
- package/document/source.d.ts +21 -0
- package/document/source.js +1 -0
- package/document/split-source.d.ts +9 -0
- package/document/split-source.js +25 -0
- package/document/store.d.ts +12 -0
- package/document/store.js +21 -0
- package/engine/engine-thread.d.ts +10 -0
- package/engine/engine-thread.js +1 -0
- package/engine/index.d.ts +2 -0
- package/engine/index.js +1 -0
- package/engine/pdfium.d.ts +16 -0
- package/engine/pdfium.js +222 -0
- package/engine/remote.d.ts +51 -0
- package/engine/remote.js +109 -0
- package/package.json +65 -4
- package/react/hooks.d.ts +128 -0
- package/react/hooks.js +129 -0
- package/react/index.d.ts +3 -0
- package/react/index.js +2 -0
- package/react/viewer.d.ts +48 -0
- package/react/viewer.js +127 -0
- package/reader/assemble.d.ts +4 -0
- package/reader/assemble.js +29 -0
- package/reader/index.d.ts +7 -0
- package/reader/index.js +5 -0
- package/reader/layer-page.d.ts +30 -0
- package/reader/layer-page.js +40 -0
- package/reader/layer-words.d.ts +4 -0
- package/reader/layer-words.js +102 -0
- package/reader/letter-edges.d.ts +13 -0
- package/reader/letter-edges.js +60 -0
- package/reader/links.d.ts +7 -0
- package/reader/links.js +22 -0
- package/reader/seams.d.ts +92 -0
- package/reader/seams.js +3 -0
- package/reader/seen.d.ts +16 -0
- package/reader/seen.js +67 -0
- package/reader/trust.d.ts +9 -0
- package/reader/trust.js +34 -0
- package/viewer/attachments.d.ts +11 -0
- package/viewer/attachments.js +104 -0
- package/viewer/dom.d.ts +14 -0
- package/viewer/dom.js +38 -0
- package/viewer/events.d.ts +17 -0
- package/viewer/events.js +20 -0
- package/viewer/index.d.ts +17 -0
- package/viewer/index.js +8 -0
- package/viewer/links.d.ts +16 -0
- package/viewer/links.js +59 -0
- package/viewer/marks.d.ts +24 -0
- package/viewer/marks.js +171 -0
- package/viewer/page-layers.d.ts +13 -0
- package/viewer/page-layers.js +33 -0
- package/viewer/pictures.d.ts +24 -0
- package/viewer/pictures.js +293 -0
- package/viewer/pointer.d.ts +21 -0
- package/viewer/pointer.js +244 -0
- package/viewer/stage.d.ts +21 -0
- package/viewer/stage.js +31 -0
- package/viewer/text-between.d.ts +13 -0
- package/viewer/text-between.js +28 -0
- package/viewer/text.d.ts +20 -0
- package/viewer/text.js +180 -0
- package/viewer/tile-grid.d.ts +20 -0
- package/viewer/tile-grid.js +36 -0
- package/viewer/tiles.d.ts +15 -0
- package/viewer/tiles.js +190 -0
- package/viewer/turn.d.ts +18 -0
- package/viewer/turn.js +40 -0
- package/viewer/types.d.ts +238 -0
- package/viewer/types.js +1 -0
- package/viewer/view-over.d.ts +21 -0
- package/viewer/view-over.js +191 -0
- package/viewer/view.d.ts +59 -0
- package/viewer/view.js +1 -0
- package/viewer/viewer.css +301 -0
- package/viewer/viewer.d.ts +11 -0
- package/viewer/viewer.js +104 -0
- package/viewer/viewport.d.ts +37 -0
- package/viewer/viewport.js +429 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { element, glide } from "./dom.js";
|
|
2
|
+
/** NOTE: a move the view makes itself is over once no scroll has been heard for this long. */
|
|
3
|
+
const OWN_MOVE_REST_MS = 200;
|
|
4
|
+
const SAME_ZOOM = 0.0005;
|
|
5
|
+
/**
|
|
6
|
+
* NOTE: a view over a frame an application built itself: its own scrolling element and its own page elements, laid
|
|
7
|
+
* out and zoomed its own way. Everything a part asks is measured from those elements, so the application implements
|
|
8
|
+
* nothing and says nothing when it zooms: the view sees the pages change size.
|
|
9
|
+
* CONSTRAINT: each page element's box is the page. It is as wide and as high as the page times one zoom, the same
|
|
10
|
+
* zoom for every page, with no border or padding of its own and no transform on it or around it.
|
|
11
|
+
* CONSTRAINT: `pane` is an element that scrolls and holds every page element. The pane and the page elements are
|
|
12
|
+
* given `position: relative` where they have no position, since the parts lay their layers inside them.
|
|
13
|
+
*/
|
|
14
|
+
export function viewOver(pane, pages, options = {}) {
|
|
15
|
+
const staged = pages.map((page, index) => ({ index, size: page.size, node: page.node }));
|
|
16
|
+
const listeners = new Set();
|
|
17
|
+
const STILL = { x: 0, y: 0, byReader: true };
|
|
18
|
+
const positioned = [];
|
|
19
|
+
let zoom = 1;
|
|
20
|
+
let floats = null;
|
|
21
|
+
let lastScrollAt = 0;
|
|
22
|
+
let scrollFrame = 0;
|
|
23
|
+
let told = { left: pane.scrollLeft, top: pane.scrollTop };
|
|
24
|
+
let lastHit = null;
|
|
25
|
+
let isOwnMove = false;
|
|
26
|
+
let ownMoveTimer;
|
|
27
|
+
const notify = (reason, shift = STILL) => {
|
|
28
|
+
for (const listener of [...listeners])
|
|
29
|
+
listener(reason, shift);
|
|
30
|
+
};
|
|
31
|
+
const ownMove = () => {
|
|
32
|
+
isOwnMove = true;
|
|
33
|
+
clearTimeout(ownMoveTimer);
|
|
34
|
+
ownMoveTimer = setTimeout(() => {
|
|
35
|
+
isOwnMove = false;
|
|
36
|
+
}, OWN_MOVE_REST_MS);
|
|
37
|
+
};
|
|
38
|
+
for (const node of [pane, ...staged.map((page) => page.node)]) {
|
|
39
|
+
if (getComputedStyle(node).position !== "static")
|
|
40
|
+
continue;
|
|
41
|
+
node.style.position = "relative";
|
|
42
|
+
positioned.push(node);
|
|
43
|
+
}
|
|
44
|
+
/** NOTE: the zoom is read from the first page that has a size, since the frame, not the view, decides it. */
|
|
45
|
+
const measuredZoom = () => {
|
|
46
|
+
for (const page of staged) {
|
|
47
|
+
const { width } = page.node.getBoundingClientRect();
|
|
48
|
+
if (width > 0 && page.size.width > 0)
|
|
49
|
+
return width / page.size.width;
|
|
50
|
+
}
|
|
51
|
+
return zoom;
|
|
52
|
+
};
|
|
53
|
+
/** NOTE: the text over a page sizes its letters from this, as it does from the pane's in pagemark's own viewer. */
|
|
54
|
+
const publishZoom = () => {
|
|
55
|
+
for (const page of staged)
|
|
56
|
+
page.node.style.setProperty("--pm-zoom", String(zoom));
|
|
57
|
+
};
|
|
58
|
+
const pointOn = (index, clientX, clientY) => {
|
|
59
|
+
const page = staged[index];
|
|
60
|
+
if (!page)
|
|
61
|
+
return null;
|
|
62
|
+
const bounds = page.node.getBoundingClientRect();
|
|
63
|
+
if (bounds.width <= 0 || bounds.height <= 0)
|
|
64
|
+
return null;
|
|
65
|
+
return { page: index, x: ((clientX - bounds.left) / bounds.width) * page.size.width, y: ((clientY - bounds.top) / bounds.height) * page.size.height };
|
|
66
|
+
};
|
|
67
|
+
const isOver = (page, clientX, clientY) => {
|
|
68
|
+
const bounds = page.node.getBoundingClientRect();
|
|
69
|
+
return clientX >= bounds.left && clientX <= bounds.right && clientY >= bounds.top && clientY <= bounds.bottom;
|
|
70
|
+
};
|
|
71
|
+
/** NOTE: a pointer mostly stays over the page it was last over, so that page is asked first. */
|
|
72
|
+
const pointAt = (clientX, clientY) => {
|
|
73
|
+
if (!lastHit || !isOver(lastHit, clientX, clientY))
|
|
74
|
+
lastHit = staged.find((page) => isOver(page, clientX, clientY)) ?? null;
|
|
75
|
+
return lastHit ? pointOn(lastHit.index, clientX, clientY) : null;
|
|
76
|
+
};
|
|
77
|
+
const inContent = (index, box) => {
|
|
78
|
+
const page = staged[index];
|
|
79
|
+
if (!page)
|
|
80
|
+
return null;
|
|
81
|
+
const bounds = page.node.getBoundingClientRect();
|
|
82
|
+
const frame = pane.getBoundingClientRect();
|
|
83
|
+
return {
|
|
84
|
+
x: bounds.left - frame.left - pane.clientLeft + pane.scrollLeft + box.x * zoom,
|
|
85
|
+
y: bounds.top - frame.top - pane.clientTop + pane.scrollTop + box.y * zoom,
|
|
86
|
+
width: box.width * zoom,
|
|
87
|
+
height: box.height * zoom,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
const inPage = (index, content) => {
|
|
91
|
+
const origin = inContent(index, { x: 0, y: 0, width: 0, height: 0 });
|
|
92
|
+
return origin ? { x: (content.x - origin.x) / zoom, y: (content.y - origin.y) / zoom, width: content.width / zoom, height: content.height / zoom } : null;
|
|
93
|
+
};
|
|
94
|
+
const onScroll = () => {
|
|
95
|
+
lastScrollAt = performance.now();
|
|
96
|
+
if (isOwnMove)
|
|
97
|
+
ownMove();
|
|
98
|
+
if (scrollFrame)
|
|
99
|
+
return;
|
|
100
|
+
scrollFrame = requestAnimationFrame(() => {
|
|
101
|
+
scrollFrame = 0;
|
|
102
|
+
const shift = { x: (pane.scrollLeft - told.left) / zoom, y: (pane.scrollTop - told.top) / zoom, byReader: !isOwnMove };
|
|
103
|
+
told = { left: pane.scrollLeft, top: pane.scrollTop };
|
|
104
|
+
notify("scroll", shift);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
/** NOTE: a page that changed size is the frame zooming; the pane alone changing size is a resize. */
|
|
108
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
109
|
+
const next = measuredZoom();
|
|
110
|
+
if (Math.abs(next - zoom) <= SAME_ZOOM * zoom) {
|
|
111
|
+
notify("resize");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
zoom = next;
|
|
115
|
+
publishZoom();
|
|
116
|
+
told = { left: pane.scrollLeft, top: pane.scrollTop };
|
|
117
|
+
notify("zoom");
|
|
118
|
+
});
|
|
119
|
+
zoom = measuredZoom();
|
|
120
|
+
publishZoom();
|
|
121
|
+
resizeObserver.observe(pane);
|
|
122
|
+
for (const page of staged)
|
|
123
|
+
resizeObserver.observe(page.node);
|
|
124
|
+
pane.addEventListener("scroll", onScroll, { passive: true });
|
|
125
|
+
const scrollTo = (place, align) => {
|
|
126
|
+
ownMove();
|
|
127
|
+
pane.scrollTo({
|
|
128
|
+
left: align === "middle" ? place.x + place.width / 2 - pane.clientWidth / 2 : pane.scrollLeft,
|
|
129
|
+
top: align === "middle" ? place.y + place.height / 2 - pane.clientHeight / 2 : place.y,
|
|
130
|
+
behavior: glide(),
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
pane,
|
|
135
|
+
pages: staged,
|
|
136
|
+
pointOn,
|
|
137
|
+
pointAt,
|
|
138
|
+
inContent,
|
|
139
|
+
inPage,
|
|
140
|
+
get zoom() {
|
|
141
|
+
return zoom;
|
|
142
|
+
},
|
|
143
|
+
get lastScrollAt() {
|
|
144
|
+
return lastScrollAt;
|
|
145
|
+
},
|
|
146
|
+
/** NOTE: made when first asked for, so a frame that attaches nothing beside a place gets no element it did not ask for. */
|
|
147
|
+
get floats() {
|
|
148
|
+
if (!floats) {
|
|
149
|
+
floats = element("pm-floats");
|
|
150
|
+
pane.append(floats);
|
|
151
|
+
}
|
|
152
|
+
return floats;
|
|
153
|
+
},
|
|
154
|
+
paneBox: () => ({ x: pane.scrollLeft, y: pane.scrollTop, width: pane.clientWidth, height: pane.clientHeight }),
|
|
155
|
+
revealRect(index, rect) {
|
|
156
|
+
const place = inContent(index, rect);
|
|
157
|
+
if (place)
|
|
158
|
+
scrollTo(place, "middle");
|
|
159
|
+
},
|
|
160
|
+
goToPage(index) {
|
|
161
|
+
const page = staged[index];
|
|
162
|
+
if (!page)
|
|
163
|
+
return;
|
|
164
|
+
if (options.goToPage) {
|
|
165
|
+
options.goToPage(index);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const place = inContent(index, { x: 0, y: 0, width: page.size.width, height: page.size.height });
|
|
169
|
+
if (place)
|
|
170
|
+
scrollTo(place, "top");
|
|
171
|
+
},
|
|
172
|
+
onChange(listener) {
|
|
173
|
+
listeners.add(listener);
|
|
174
|
+
return () => {
|
|
175
|
+
listeners.delete(listener);
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
destroy() {
|
|
179
|
+
listeners.clear();
|
|
180
|
+
cancelAnimationFrame(scrollFrame);
|
|
181
|
+
clearTimeout(ownMoveTimer);
|
|
182
|
+
resizeObserver.disconnect();
|
|
183
|
+
pane.removeEventListener("scroll", onScroll);
|
|
184
|
+
floats?.remove();
|
|
185
|
+
for (const page of staged)
|
|
186
|
+
page.node.style.removeProperty("--pm-zoom");
|
|
187
|
+
for (const node of positioned)
|
|
188
|
+
node.style.position = "";
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
package/viewer/view.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Box } from "../core/index.js";
|
|
2
|
+
import type { PagePoint, ViewerPage } from "./types.js";
|
|
3
|
+
export type ViewChange = "zoom" | "scroll" | "resize";
|
|
4
|
+
/** NOTE: how far the pages moved under the pane, in page units, and whether a reader moved them. */
|
|
5
|
+
export type ViewShift = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
byReader: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* NOTE: one page's place in a view: the element sized to it, which every part lays its own layer over. A view may
|
|
12
|
+
* show the element turned; what is laid in it turns with it, and the view's own conversions say where it is.
|
|
13
|
+
*/
|
|
14
|
+
export type ViewPage = {
|
|
15
|
+
readonly index: number;
|
|
16
|
+
readonly size: ViewerPage;
|
|
17
|
+
readonly node: HTMLElement;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* NOTE: what every part of a viewer stands on: the pages' elements, where each is on the screen, and word of every
|
|
21
|
+
* change. A part knows nothing else of the frame around it, so the same part works in pagemark's own viewer and in a
|
|
22
|
+
* frame an application built itself.
|
|
23
|
+
* NOTE: pagemark's viewer makes one with its own layout and zoom. `viewOver` makes one over elements an application
|
|
24
|
+
* lays out.
|
|
25
|
+
*/
|
|
26
|
+
export type View = {
|
|
27
|
+
/** NOTE: the element that scrolls the pages. A part listens on it, and watches which pages are near it. */
|
|
28
|
+
readonly pane: HTMLElement;
|
|
29
|
+
/** NOTE: the element that holds what floats beside a place, inside the scrolled content. */
|
|
30
|
+
readonly floats: HTMLElement;
|
|
31
|
+
readonly pages: ReadonlyArray<ViewPage>;
|
|
32
|
+
/** NOTE: screen pixels per page unit. */
|
|
33
|
+
readonly zoom: number;
|
|
34
|
+
/** NOTE: when the pane last scrolled, on the `performance.now()` clock. */
|
|
35
|
+
readonly lastScrollAt: number;
|
|
36
|
+
/** NOTE: the point of `page` under a screen position, which may lie outside the page's own box. */
|
|
37
|
+
pointOn(page: number, clientX: number, clientY: number): PagePoint | null;
|
|
38
|
+
/** NOTE: the page point under a screen position, or null when it is over no page. */
|
|
39
|
+
pointAt(clientX: number, clientY: number): PagePoint | null;
|
|
40
|
+
/** NOTE: where a place sits inside the scrolled content, in pixels from its top-left corner. */
|
|
41
|
+
inContent(page: number, box: Box): Box | null;
|
|
42
|
+
/** NOTE: the box of `page`, in page units, that a box of the scrolled content covers: `inContent` the other way. It may reach past the page. */
|
|
43
|
+
inPage(page: number, content: Box): Box | null;
|
|
44
|
+
/** NOTE: the part of the scrolled content the pane shows, in the same pixels as `inContent`. */
|
|
45
|
+
paneBox(): Box;
|
|
46
|
+
revealRect(page: number, rect: Box): void;
|
|
47
|
+
goToPage(page: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* NOTE: calls `listener` after a zoom has been laid out, once per frame while scrolling, and after a resize that
|
|
50
|
+
* did not zoom, until the function it returns is called.
|
|
51
|
+
* INVARIANT: listeners hear of a change in the order they were added, so a viewer orders its parts by the order it
|
|
52
|
+
* makes them in.
|
|
53
|
+
*/
|
|
54
|
+
onChange(listener: (reason: ViewChange, shift: ViewShift) => void): () => void;
|
|
55
|
+
};
|
|
56
|
+
/** NOTE: what every part is: something made over a view that lets go of it when asked. */
|
|
57
|
+
export type Part = {
|
|
58
|
+
destroy(): void;
|
|
59
|
+
};
|
package/viewer/view.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
.pm-viewer {
|
|
2
|
+
position: relative;
|
|
3
|
+
min-width: 0;
|
|
4
|
+
min-height: 0;
|
|
5
|
+
height: 100%;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.pm-scroll {
|
|
10
|
+
position: relative;
|
|
11
|
+
height: 100%;
|
|
12
|
+
overflow: auto;
|
|
13
|
+
outline: none;
|
|
14
|
+
user-select: none;
|
|
15
|
+
touch-action: pan-x pan-y;
|
|
16
|
+
background: var(--pm-backdrop, #e8e9ed);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.pm-scroll[data-hand] {
|
|
20
|
+
cursor: grab;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.pm-scroll[data-hand="moving"] {
|
|
24
|
+
cursor: grabbing;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* CONSTRAINT: a press with Space held moves the pages whatever is under it, so no cursor of a page, a word, a link or an attached element may stand over the hand. */
|
|
28
|
+
.pm-scroll[data-hand] * {
|
|
29
|
+
cursor: inherit !important;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.pm-scroll[data-hand] .pm-text {
|
|
33
|
+
user-select: none;
|
|
34
|
+
-webkit-user-select: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.pm-column {
|
|
38
|
+
box-sizing: border-box;
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
align-items: center;
|
|
42
|
+
gap: 16px;
|
|
43
|
+
width: max-content;
|
|
44
|
+
min-width: 100%;
|
|
45
|
+
padding: 24px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.pm-page {
|
|
49
|
+
position: relative;
|
|
50
|
+
flex: none;
|
|
51
|
+
background: #fff;
|
|
52
|
+
box-shadow:
|
|
53
|
+
0 1px 3px rgb(0 0 0 / 0.18),
|
|
54
|
+
0 0 0 1px rgb(0 0 0 / 0.06);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.pm-scroll[data-spread="double"] .pm-column {
|
|
58
|
+
display: grid;
|
|
59
|
+
grid-template-columns: max-content max-content;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
align-items: center;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.pm-scroll[data-spread="double"] .pm-page:nth-child(odd) {
|
|
65
|
+
justify-self: end;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.pm-scroll[data-spread="double"] .pm-page:nth-child(even) {
|
|
69
|
+
justify-self: start;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.pm-sheet {
|
|
73
|
+
position: absolute;
|
|
74
|
+
top: 0;
|
|
75
|
+
left: 0;
|
|
76
|
+
transform-origin: 0 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.pm-scroll[data-rotation="90"] .pm-sheet {
|
|
80
|
+
transform: rotate(90deg) translateY(-100%);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.pm-scroll[data-rotation="180"] .pm-sheet {
|
|
84
|
+
transform: rotate(180deg) translate(-100%, -100%);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.pm-scroll[data-rotation="270"] .pm-sheet {
|
|
88
|
+
transform: rotate(270deg) translateX(-100%);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.pm-image {
|
|
92
|
+
display: block;
|
|
93
|
+
width: 100%;
|
|
94
|
+
height: 100%;
|
|
95
|
+
user-select: none;
|
|
96
|
+
-webkit-user-drag: none;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.pm-image:not([data-scale]) {
|
|
100
|
+
visibility: hidden;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.pm-tiles {
|
|
104
|
+
position: absolute;
|
|
105
|
+
inset: 0;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
pointer-events: none;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.pm-tile {
|
|
111
|
+
position: absolute;
|
|
112
|
+
display: block;
|
|
113
|
+
max-width: none;
|
|
114
|
+
user-select: none;
|
|
115
|
+
-webkit-user-drag: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.pm-marks,
|
|
119
|
+
.pm-text {
|
|
120
|
+
position: absolute;
|
|
121
|
+
inset: 0;
|
|
122
|
+
overflow: hidden;
|
|
123
|
+
font: 0/1 sans-serif;
|
|
124
|
+
color: transparent;
|
|
125
|
+
white-space: pre;
|
|
126
|
+
pointer-events: none;
|
|
127
|
+
user-select: text;
|
|
128
|
+
-webkit-user-select: text;
|
|
129
|
+
forced-color-adjust: none;
|
|
130
|
+
text-size-adjust: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.pm-word {
|
|
134
|
+
position: absolute;
|
|
135
|
+
transform-origin: 0 0;
|
|
136
|
+
white-space: pre;
|
|
137
|
+
cursor: text;
|
|
138
|
+
pointer-events: auto;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.pm-text ::selection {
|
|
142
|
+
background: var(--pm-text-selection, rgb(47 95 208 / 0.3));
|
|
143
|
+
color: transparent;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.pm-text br::selection {
|
|
147
|
+
background: transparent;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.pm-links {
|
|
151
|
+
position: absolute;
|
|
152
|
+
inset: 0;
|
|
153
|
+
pointer-events: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.pm-link {
|
|
157
|
+
position: absolute;
|
|
158
|
+
pointer-events: auto;
|
|
159
|
+
cursor: pointer;
|
|
160
|
+
border-radius: 2px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.pm-link:hover {
|
|
164
|
+
background: var(--pm-link-hover, rgb(47 95 208 / 0.12));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.pm-link:focus-visible {
|
|
168
|
+
outline: 2px solid var(--pm-link-focus, rgb(47 95 208 / 0.9));
|
|
169
|
+
outline-offset: 1px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.pm-layer {
|
|
173
|
+
position: absolute;
|
|
174
|
+
inset: 0;
|
|
175
|
+
pointer-events: none;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.pm-mark {
|
|
179
|
+
position: absolute;
|
|
180
|
+
box-sizing: content-box;
|
|
181
|
+
padding: 1px 2px;
|
|
182
|
+
transform: translate(-2px, -1px);
|
|
183
|
+
border-radius: 2px;
|
|
184
|
+
background: var(--pm-mark, rgb(255 214 10 / 0.45));
|
|
185
|
+
mix-blend-mode: multiply;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.pm-mark[role="button"]:focus-visible {
|
|
189
|
+
outline: 2px solid var(--pm-mark-keyboard-ring, #1d3f96);
|
|
190
|
+
outline-offset: 2px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/*
|
|
194
|
+
* CONSTRAINT: two classes, so focus wins over the colour of any one tone wherever that tone's rule stands in a
|
|
195
|
+
* stylesheet. A tone that keeps its own colour in focus says so below with a rule of two classes of its own.
|
|
196
|
+
*/
|
|
197
|
+
.pm-mark.pm-mark-focused {
|
|
198
|
+
background: var(--pm-mark-focused, rgb(255 138 0 / 0.6));
|
|
199
|
+
box-shadow: 0 0 0 2px var(--pm-mark-focused-ring, rgb(214 98 0 / 0.9));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.pm-mark-hover {
|
|
203
|
+
background: var(--pm-hover, rgb(47 95 208 / 0.1));
|
|
204
|
+
box-shadow: 0 0 0 1px var(--pm-hover-ring, rgb(47 95 208 / 0.55));
|
|
205
|
+
mix-blend-mode: normal;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.pm-mark-selection {
|
|
209
|
+
padding: 0;
|
|
210
|
+
transform: none;
|
|
211
|
+
border-radius: 0;
|
|
212
|
+
background: var(--pm-selection, rgb(64 132 255 / 0.32));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.pm-mark-region {
|
|
216
|
+
padding: 0;
|
|
217
|
+
transform: none;
|
|
218
|
+
border-radius: 2px;
|
|
219
|
+
background: var(--pm-region, rgb(20 150 110 / 0.08));
|
|
220
|
+
box-shadow: 0 0 0 1.5px var(--pm-region-ring, rgb(20 150 110 / 0.9));
|
|
221
|
+
mix-blend-mode: normal;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.pm-mark-quote {
|
|
225
|
+
background: var(--pm-quote, rgb(120 220 150 / 0.45));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.pm-mark-hidden {
|
|
229
|
+
background: var(--pm-hidden, rgb(214 60 60 / 0.12));
|
|
230
|
+
box-shadow: 0 0 0 1.5px var(--pm-hidden-ring, rgb(214 60 60 / 0.85));
|
|
231
|
+
mix-blend-mode: normal;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.pm-mark-hidden.pm-mark-focused {
|
|
235
|
+
background: var(--pm-hidden-focused, rgb(214 60 60 / 0.32));
|
|
236
|
+
box-shadow: 0 0 0 3px var(--pm-hidden-ring, rgb(214 60 60 / 0.85));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.pm-attached-layer {
|
|
240
|
+
position: absolute;
|
|
241
|
+
inset: 0;
|
|
242
|
+
pointer-events: none;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.pm-attached {
|
|
246
|
+
position: absolute;
|
|
247
|
+
box-sizing: border-box;
|
|
248
|
+
pointer-events: auto;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.pm-floats {
|
|
252
|
+
position: absolute;
|
|
253
|
+
top: 0;
|
|
254
|
+
left: 0;
|
|
255
|
+
width: 0;
|
|
256
|
+
height: 0;
|
|
257
|
+
z-index: 2;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.pm-float {
|
|
261
|
+
position: absolute;
|
|
262
|
+
top: 0;
|
|
263
|
+
left: 0;
|
|
264
|
+
width: max-content;
|
|
265
|
+
max-width: 320px;
|
|
266
|
+
pointer-events: auto;
|
|
267
|
+
user-select: text;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.pm-mark-added {
|
|
271
|
+
background: var(--pm-added, rgb(100 210 135 / 0.5));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.pm-mark-removed {
|
|
275
|
+
background: var(--pm-removed, rgb(255 125 125 / 0.45));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.pm-mark-moved {
|
|
279
|
+
background: var(--pm-moved, rgb(140 123 255 / 0.4));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.pm-mark-place {
|
|
283
|
+
background: var(--pm-place, rgb(110 120 150 / 0.14));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* NOTE: a change in focus keeps its colour, which says what kind of change it is; the ring says it is the one in hand. */
|
|
287
|
+
.pm-mark-added.pm-mark-focused {
|
|
288
|
+
background: var(--pm-added, rgb(100 210 135 / 0.5));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.pm-mark-removed.pm-mark-focused {
|
|
292
|
+
background: var(--pm-removed, rgb(255 125 125 / 0.45));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
.pm-mark-moved.pm-mark-focused {
|
|
296
|
+
background: var(--pm-moved, rgb(140 123 255 / 0.4));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.pm-mark-place.pm-mark-focused {
|
|
300
|
+
background: var(--pm-place, rgb(110 120 150 / 0.14));
|
|
301
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Viewer, ViewerOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: pagemark's own viewer is one view and six parts over it, and this is the only place that knows all of them.
|
|
4
|
+
* The view says where the pages are. Pictures fills them, text lays their words over them for a reader to select,
|
|
5
|
+
* links lays the file's links over them, marks and attachments draw over them, and the pointer reports what a reader
|
|
6
|
+
* does on them. Each part knows the view alone, so an application can make the same parts over a view of its own.
|
|
7
|
+
* NOTE: everything a part reports is told here as one of the viewer's events, which a caller listens to with `on`.
|
|
8
|
+
* CONSTRAINT: the parts hear of a change in the order they are made here, and that order is part of the behaviour:
|
|
9
|
+
* the pointer and the floats first, then the caller, and pictures are asked for last.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createViewer(container: HTMLElement, options: ViewerOptions): Viewer;
|
package/viewer/viewer.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createAttachments } from "./attachments.js";
|
|
2
|
+
import { createEvents } from "./events.js";
|
|
3
|
+
import { createLinks } from "./links.js";
|
|
4
|
+
import { createMarks } from "./marks.js";
|
|
5
|
+
import { createPictures } from "./pictures.js";
|
|
6
|
+
import { createPointer } from "./pointer.js";
|
|
7
|
+
import { createStage } from "./stage.js";
|
|
8
|
+
import { createText } from "./text.js";
|
|
9
|
+
import { createViewport, MAX_ZOOM, MIN_ZOOM } from "./viewport.js";
|
|
10
|
+
const DEFAULT_LAYER = "marks";
|
|
11
|
+
/**
|
|
12
|
+
* NOTE: pagemark's own viewer is one view and six parts over it, and this is the only place that knows all of them.
|
|
13
|
+
* The view says where the pages are. Pictures fills them, text lays their words over them for a reader to select,
|
|
14
|
+
* links lays the file's links over them, marks and attachments draw over them, and the pointer reports what a reader
|
|
15
|
+
* does on them. Each part knows the view alone, so an application can make the same parts over a view of its own.
|
|
16
|
+
* NOTE: everything a part reports is told here as one of the viewer's events, which a caller listens to with `on`.
|
|
17
|
+
* CONSTRAINT: the parts hear of a change in the order they are made here, and that order is part of the behaviour:
|
|
18
|
+
* the pointer and the floats first, then the caller, and pictures are asked for last.
|
|
19
|
+
*/
|
|
20
|
+
export function createViewer(container, options) {
|
|
21
|
+
const events = createEvents();
|
|
22
|
+
const stage = createStage(container, options.pages, options.label);
|
|
23
|
+
const view = createViewport(stage, { onPageInView: (page) => events.emit("pageInView", page), fit: options.fit });
|
|
24
|
+
const marks = createMarks(view, { onPress: (point, under) => events.emit("press", point, under) });
|
|
25
|
+
const text = createText(view);
|
|
26
|
+
const links = createLinks(view);
|
|
27
|
+
const pointer = createPointer(view, {
|
|
28
|
+
marksAt: marks.marksAt,
|
|
29
|
+
onPointer: (point) => events.emit("pointer", point),
|
|
30
|
+
onPointerMarks: (under, point) => events.emit("pointerMarks", under, point),
|
|
31
|
+
onDrag: (drag) => events.emit("drag", drag),
|
|
32
|
+
onPress: (point, under) => events.emit("press", point, under),
|
|
33
|
+
});
|
|
34
|
+
const attachments = createAttachments(view);
|
|
35
|
+
view.onChange((reason, shift) => {
|
|
36
|
+
if (reason === "zoom")
|
|
37
|
+
events.emit("zoom", view.zoom);
|
|
38
|
+
events.emit("view", { zoom: view.zoom, ...shift });
|
|
39
|
+
});
|
|
40
|
+
const pictures = createPictures(view, {
|
|
41
|
+
...options,
|
|
42
|
+
onIdle: () => events.emit("idle"),
|
|
43
|
+
onFailures: (pages) => events.emit("failures", pages),
|
|
44
|
+
onNear: (pages) => events.emit("pagesNear", pages),
|
|
45
|
+
});
|
|
46
|
+
view.reportPageInView();
|
|
47
|
+
return {
|
|
48
|
+
get zoom() {
|
|
49
|
+
return view.zoom;
|
|
50
|
+
},
|
|
51
|
+
get pageInView() {
|
|
52
|
+
return view.pageInView;
|
|
53
|
+
},
|
|
54
|
+
pageCount: options.pages.length,
|
|
55
|
+
get failedPages() {
|
|
56
|
+
return pictures.failedPages;
|
|
57
|
+
},
|
|
58
|
+
retry: pictures.retry,
|
|
59
|
+
minZoom: MIN_ZOOM,
|
|
60
|
+
maxZoom: MAX_ZOOM,
|
|
61
|
+
pane: view.pane,
|
|
62
|
+
get fit() {
|
|
63
|
+
return view.fit;
|
|
64
|
+
},
|
|
65
|
+
get rotation() {
|
|
66
|
+
return view.rotation;
|
|
67
|
+
},
|
|
68
|
+
get spread() {
|
|
69
|
+
return view.spread;
|
|
70
|
+
},
|
|
71
|
+
on: events.on,
|
|
72
|
+
setLayer: marks.setLayer,
|
|
73
|
+
setMarks: (drawn) => marks.setLayer(DEFAULT_LAYER, drawn),
|
|
74
|
+
setText: text.setText,
|
|
75
|
+
setLinks: links.setLinks,
|
|
76
|
+
focusMark: marks.focusMark,
|
|
77
|
+
attach: attachments.attach,
|
|
78
|
+
revealRect: view.revealRect,
|
|
79
|
+
toScreen: view.toScreen,
|
|
80
|
+
toPage: view.pointAt,
|
|
81
|
+
goToPage: view.goToPage,
|
|
82
|
+
zoomIn: view.zoomIn,
|
|
83
|
+
zoomOut: view.zoomOut,
|
|
84
|
+
zoomTo: view.zoomTo,
|
|
85
|
+
fitWidth: view.fitWidth,
|
|
86
|
+
fitPage: view.fitPage,
|
|
87
|
+
rotateRight: () => view.rotateTo(((view.rotation + 90) % 360)),
|
|
88
|
+
rotateLeft: () => view.rotateTo(((view.rotation + 270) % 360)),
|
|
89
|
+
rotateTo: view.rotateTo,
|
|
90
|
+
setSpread: view.setSpread,
|
|
91
|
+
moveBy: view.moveBy,
|
|
92
|
+
destroy() {
|
|
93
|
+
events.clear();
|
|
94
|
+
pictures.destroy();
|
|
95
|
+
pointer.destroy();
|
|
96
|
+
attachments.destroy();
|
|
97
|
+
marks.destroy();
|
|
98
|
+
text.destroy();
|
|
99
|
+
links.destroy();
|
|
100
|
+
view.destroy();
|
|
101
|
+
stage.destroy();
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|