@salmonui/pdf-viewer 0.0.0-stage → 0.2.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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/dist/PdfViewer.d.ts +6 -0
  4. package/dist/PdfViewer.d.ts.map +1 -0
  5. package/dist/PdfViewer.js +151 -0
  6. package/dist/PdfViewer.js.map +1 -0
  7. package/dist/core.d.ts +163 -0
  8. package/dist/core.d.ts.map +1 -0
  9. package/dist/core.js +939 -0
  10. package/dist/core.js.map +1 -0
  11. package/dist/engine/controller.d.ts +57 -0
  12. package/dist/engine/controller.d.ts.map +1 -0
  13. package/dist/engine/controller.js +418 -0
  14. package/dist/engine/controller.js.map +1 -0
  15. package/dist/engine/pdf-worker.d.ts +2 -0
  16. package/dist/engine/pdf-worker.d.ts.map +1 -0
  17. package/dist/engine/pdf-worker.js +23 -0
  18. package/dist/engine/pdf-worker.js.map +1 -0
  19. package/dist/icons.d.ts +5 -0
  20. package/dist/icons.d.ts.map +1 -0
  21. package/dist/icons.js +17 -0
  22. package/dist/icons.js.map +1 -0
  23. package/dist/index.d.ts +8 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +12 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/layout.d.ts +49 -0
  28. package/dist/layout.d.ts.map +1 -0
  29. package/dist/layout.js +115 -0
  30. package/dist/layout.js.map +1 -0
  31. package/dist/locale.d.ts +49 -0
  32. package/dist/locale.d.ts.map +1 -0
  33. package/dist/locale.js +50 -0
  34. package/dist/locale.js.map +1 -0
  35. package/dist/markup.d.ts +54 -0
  36. package/dist/markup.d.ts.map +1 -0
  37. package/dist/markup.js +175 -0
  38. package/dist/markup.js.map +1 -0
  39. package/dist/pdf-viewer.css +1523 -0
  40. package/dist/search.d.ts +36 -0
  41. package/dist/search.d.ts.map +1 -0
  42. package/dist/search.js +89 -0
  43. package/dist/search.js.map +1 -0
  44. package/dist/toolbar.d.ts +19 -0
  45. package/dist/toolbar.d.ts.map +1 -0
  46. package/dist/toolbar.js +128 -0
  47. package/dist/toolbar.js.map +1 -0
  48. package/dist/types.d.ts +227 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +2 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/zoom.d.ts +35 -0
  53. package/dist/zoom.d.ts.map +1 -0
  54. package/dist/zoom.js +58 -0
  55. package/dist/zoom.js.map +1 -0
  56. package/package.json +44 -4
@@ -0,0 +1,23 @@
1
+ // pdf.js worker entry. The viewer starts it with
2
+ // `new Worker(new URL('./pdf-worker.js', import.meta.url), { type: 'module' })`,
3
+ // a pattern Vite, webpack 5, Rollup and Turbopack bundle as a worker chunk.
4
+ // The worker module of `pdfjs-dist` registers its message handler on the
5
+ // worker scope when it is evaluated; it loads with dynamic import() (the
6
+ // package never imports the engine statically), so the messages the viewer
7
+ // sends meanwhile are queued and replayed once the handler listens.
8
+ // Pass `workerSrc` to use another worker file.
9
+ const scope = globalThis;
10
+ const queued = [];
11
+ const hold = (event) => {
12
+ queued.push(event);
13
+ event.stopImmediatePropagation();
14
+ };
15
+ scope.addEventListener('message', hold);
16
+ // No top-level await: bundlers may emit the worker as a classic (IIFE) script.
17
+ void import('pdfjs-dist/build/pdf.worker.min.mjs').then(() => {
18
+ scope.removeEventListener('message', hold);
19
+ for (const event of queued)
20
+ scope.dispatchEvent(new MessageEvent('message', { data: event.data, ports: [...event.ports] }));
21
+ });
22
+ export {};
23
+ //# sourceMappingURL=pdf-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-worker.js","sourceRoot":"","sources":["../../src/engine/pdf-worker.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,iFAAiF;AACjF,4EAA4E;AAC5E,yEAAyE;AACzE,yEAAyE;AACzE,2EAA2E;AAC3E,oEAAoE;AACpE,+CAA+C;AAC/C,MAAM,KAAK,GAAG,UAAoC,CAAC;AACnD,MAAM,MAAM,GAAmB,EAAE,CAAC;AAClC,MAAM,IAAI,GAAG,CAAC,KAAY,EAAE,EAAE;IAC5B,MAAM,CAAC,IAAI,CAAC,KAAqB,CAAC,CAAC;IACnC,KAAK,CAAC,wBAAwB,EAAE,CAAC;AACnC,CAAC,CAAC;AACF,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACxC,+EAA+E;AAC/E,KAAK,MAAM,CAAC,qCAAqC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;IAC3D,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,KAAK,CAAC,aAAa,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9H,CAAC,CAAC,CAAC;AACH,OAAO,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ReactElement } from 'react';
2
+ type IconName = 'sidebar' | 'previous' | 'next' | 'zoomIn' | 'zoomOut' | 'search' | 'highlight' | 'underline' | 'strikethrough' | 'print' | 'download' | 'close';
3
+ export declare const ICONS: Readonly<Record<IconName, ReactElement>>;
4
+ export {};
5
+ //# sourceMappingURL=icons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../src/icons.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAQ1C,KAAK,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,eAAe,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;AAEjK,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAa1D,CAAC"}
package/dist/icons.js ADDED
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const icon = (d) => (_jsx("svg", { viewBox: "0 0 16 16", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: d }) }));
3
+ export const ICONS = {
4
+ sidebar: icon('M2.5 3h11v10h-11zM6 3v10'),
5
+ previous: icon('M4 10l4-4 4 4'),
6
+ next: icon('M4 6l4 4 4-4'),
7
+ zoomIn: icon('M7 3.5a3.5 3.5 0 1 1 0 7a3.5 3.5 0 0 1 0-7zM9.6 9.6L13 13M5.5 7h3M7 5.5v3'),
8
+ zoomOut: icon('M7 3.5a3.5 3.5 0 1 1 0 7a3.5 3.5 0 0 1 0-7zM9.6 9.6L13 13M5.5 7h3'),
9
+ search: icon('M7 3a4 4 0 1 1 0 8a4 4 0 0 1 0-8zM10 10l3.5 3.5'),
10
+ highlight: icon('M3 13h10M5 10l5.5-6.5 2 2L7 12H5z'),
11
+ underline: icon('M5 3v4.5a3 3 0 0 0 6 0V3M4 13.5h8'),
12
+ strikethrough: icon('M3 8h10M10.5 5C10 4 9 3.5 8 3.5c-1.5 0-2.5.8-2.5 2M5.5 11c.5 1 1.5 1.5 2.5 1.5 1.5 0 2.5-.8 2.5-2'),
13
+ print: icon('M4.5 6V2.5h7V6M4.5 11.5H3V6h10v5.5h-1.5M4.5 9.5h7v4h-7z'),
14
+ download: icon('M8 2.5v8M4.5 7L8 10.5 11.5 7M3 13.5h10'),
15
+ close: icon('M4 4l8 8M12 4l-8 8'),
16
+ };
17
+ //# sourceMappingURL=icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons.js","sourceRoot":"","sources":["../src/icons.tsx"],"names":[],"mappings":";AAGA,MAAM,IAAI,GAAG,CAAC,CAAS,EAAgB,EAAE,CAAC,CACxC,cAAK,OAAO,EAAC,WAAW,EAAC,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,MAAM,EAAC,cAAc,EAAC,WAAW,EAAC,KAAK,EAAC,aAAa,EAAC,OAAO,EAAC,cAAc,EAAC,OAAO,iBAAa,MAAM,EAAC,SAAS,EAAC,OAAO,YACnL,eAAM,CAAC,EAAE,CAAC,GAAI,GACV,CACP,CAAC;AAIF,MAAM,CAAC,MAAM,KAAK,GAA6C;IAC7D,OAAO,EAAE,IAAI,CAAC,0BAA0B,CAAC;IACzC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC;IAC/B,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC;IAC1B,MAAM,EAAE,IAAI,CAAC,2EAA2E,CAAC;IACzF,OAAO,EAAE,IAAI,CAAC,mEAAmE,CAAC;IAClF,MAAM,EAAE,IAAI,CAAC,iDAAiD,CAAC;IAC/D,SAAS,EAAE,IAAI,CAAC,mCAAmC,CAAC;IACpD,SAAS,EAAE,IAAI,CAAC,mCAAmC,CAAC;IACpD,aAAa,EAAE,IAAI,CAAC,mGAAmG,CAAC;IACxH,KAAK,EAAE,IAAI,CAAC,yDAAyD,CAAC;IACtE,QAAQ,EAAE,IAAI,CAAC,wCAAwC,CAAC;IACxD,KAAK,EAAE,IAAI,CAAC,oBAAoB,CAAC;CAClC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { PdfViewer } from './PdfViewer.js';
2
+ export { PDF_VIEWER_DEFAULT_LOCALE_TEXT } from './locale.js';
3
+ export type { PdfViewerLocaleText } from './locale.js';
4
+ export { DEFAULT_TOOLBAR as PDF_VIEWER_DEFAULT_TOOLBAR } from './toolbar.js';
5
+ export { resolveScale, stepScale, ZOOM_STEPS, PDF_TO_CSS } from './zoom.js';
6
+ export type { FitContext } from './zoom.js';
7
+ export type { PdfFormValue, PdfFormValues, PdfPageSize, PdfRect, PdfTextMarkupAnnotation, PdfTextMarkupKind, PdfViewerActions, PdfViewerAnnotationsChangeEvent, PdfViewerCancelableEvent, PdfViewerEventSource, PdfViewerLinkEvent, PdfViewerLoadInfo, PdfViewerOutlineItem, PdfViewerPart, PdfViewerPasswordRequest, PdfViewerProps, PdfViewerScrollMode, PdfViewerSearchOptions, PdfViewerSearchResult, PdfViewerSidebar, PdfViewerSource, PdfViewerSpreadMode, PdfViewerStateSnapshot, PdfViewerToolbarContext, PdfViewerToolbarCustomItem, PdfViewerToolbarItem, PdfViewerToolbarItemId, PdfViewerZoom, } from './types.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,eAAe,IAAI,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5E,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,YAAY,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,OAAO,EACP,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,+BAA+B,EAC/B,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,GACd,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ import { expectStylesheet } from '@salmonui/core/internal/dev';
3
+ // `@salmonui/pdf-viewer`: PdfViewer on pdf.js. pdf.js and its worker load with
4
+ // dynamic import() on the client only; everything this entry exports
5
+ // statically is server-safe. Styles: `@salmonui/pdf-viewer/styles.css`.
6
+ export { PdfViewer } from './PdfViewer.js';
7
+ export { PDF_VIEWER_DEFAULT_LOCALE_TEXT } from './locale.js';
8
+ export { DEFAULT_TOOLBAR as PDF_VIEWER_DEFAULT_TOOLBAR } from './toolbar.js';
9
+ export { resolveScale, stepScale, ZOOM_STEPS, PDF_TO_CSS } from './zoom.js';
10
+ if (process.env.NODE_ENV !== 'production')
11
+ expectStylesheet('@salmonui/pdf-viewer', 'salmon-pdf-viewer');
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,+EAA+E;AAC/E,qEAAqE;AACrE,wEAAwE;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,eAAe,IAAI,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAoC5E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,gBAAgB,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { type VariableRowMetrics } from '@salmonui/core/virtual';
2
+ import type { PdfPageSize, PdfViewerScrollMode, PdfViewerSpreadMode } from './types.js';
3
+ export interface PageBox {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ readonly width: number;
7
+ readonly height: number;
8
+ }
9
+ export interface LayoutRow {
10
+ readonly pages: readonly number[];
11
+ /** Extent along the scroll axis, gap included. */
12
+ readonly extent: number;
13
+ }
14
+ export interface ViewerLayout {
15
+ readonly axis: 'x' | 'y';
16
+ readonly mode: PdfViewerScrollMode;
17
+ readonly boxes: readonly PageBox[];
18
+ readonly rows: readonly LayoutRow[];
19
+ /** Row index of every page. */
20
+ readonly rowOf: Int32Array;
21
+ readonly metrics: VariableRowMetrics;
22
+ readonly width: number;
23
+ readonly height: number;
24
+ }
25
+ export interface LayoutInput {
26
+ readonly sizes: readonly PdfPageSize[];
27
+ readonly scale: number;
28
+ readonly scrollMode: PdfViewerScrollMode;
29
+ readonly spreadMode: PdfViewerSpreadMode;
30
+ /** Viewport width in CSS px (wrapping, centering). */
31
+ readonly viewportWidth: number;
32
+ }
33
+ /** Groups page indexes into spreads. */
34
+ export declare function spreads(count: number, spreadMode: PdfViewerSpreadMode): number[][];
35
+ export declare function computeLayout(input: LayoutInput): ViewerLayout;
36
+ export interface VisiblePages {
37
+ /** Rendered pages (overscan included), ascending. */
38
+ readonly pages: readonly number[];
39
+ /** The page the reader is on (0-based). */
40
+ readonly current: number;
41
+ }
42
+ /**
43
+ * Pages to render for a scroll position. `offset` and `extent` are along the
44
+ * layout axis; `pageRow` is the current row in `'page'` mode.
45
+ */
46
+ export declare function visiblePages(layout: ViewerLayout, offset: number, extent: number, overscan?: number, pageRow?: number): VisiblePages;
47
+ /** Scroll offset (along the axis) that brings a page to the start of the viewport. */
48
+ export declare function pageOffset(layout: ViewerLayout, page: number): number;
49
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0C,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,KAAK,EAAE,WAAW,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wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAwD9D;AAED,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAI,EAAE,OAAO,SAAI,GAAG,YAAY,CAiB1H;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIrE"}
package/dist/layout.js ADDED
@@ -0,0 +1,115 @@
1
+ // Page layout and virtualization for PdfViewer. Pure: page boxes
2
+ // for each scroll and spread mode, laid out in rows along the scroll axis
3
+ // and virtualized with the Data Grid range math (createVariableRowMetrics,
4
+ // computeRange from @salmonui/data-grid/engine).
5
+ import { computeRange, createVariableRowMetrics } from '@salmonui/core/virtual';
6
+ import { PAGE_GAP, PDF_TO_CSS, VIEW_PADDING } from './zoom.js';
7
+ /** Groups page indexes into spreads. */
8
+ export function spreads(count, spreadMode) {
9
+ const out = [];
10
+ let i = 0;
11
+ if (spreadMode === 'even' && count > 0)
12
+ out.push([i++]);
13
+ while (i < count) {
14
+ if (spreadMode === 'none' || i + 1 >= count)
15
+ out.push([i++]);
16
+ else {
17
+ out.push([i, i + 1]);
18
+ i += 2;
19
+ }
20
+ }
21
+ return out;
22
+ }
23
+ export function computeLayout(input) {
24
+ const { sizes, scale, scrollMode } = input;
25
+ const n = sizes.length;
26
+ const k = scale * PDF_TO_CSS;
27
+ const w = (i) => Math.round(sizes[i].width * k);
28
+ const h = (i) => Math.round(sizes[i].height * k);
29
+ let groups;
30
+ if (scrollMode === 'horizontal')
31
+ groups = Array.from({ length: n }, (_, i) => [i]);
32
+ else if (scrollMode === 'wrapped') {
33
+ groups = [];
34
+ const avail = Math.max(1, input.viewportWidth - 2 * VIEW_PADDING);
35
+ let row = [];
36
+ let width = 0;
37
+ for (let i = 0; i < n; i++) {
38
+ const next = width + (row.length ? PAGE_GAP : 0) + w(i);
39
+ if (row.length && next > avail) {
40
+ groups.push(row);
41
+ row = [];
42
+ width = 0;
43
+ }
44
+ width += (row.length ? PAGE_GAP : 0) + w(i);
45
+ row.push(i);
46
+ }
47
+ if (row.length)
48
+ groups.push(row);
49
+ }
50
+ else
51
+ groups = spreads(n, input.spreadMode);
52
+ const axis = scrollMode === 'horizontal' ? 'x' : 'y';
53
+ const rowOf = new Int32Array(n);
54
+ const rows = groups.map((pages, r) => {
55
+ for (const p of pages)
56
+ rowOf[p] = r;
57
+ const along = axis === 'x' ? Math.max(...pages.map(w)) : Math.max(...pages.map(h));
58
+ return { pages, extent: along + PAGE_GAP };
59
+ });
60
+ const metrics = createVariableRowMetrics(rows.length, (r) => rows[r].extent);
61
+ const cross = (row) => (axis === 'x' ? Math.max(...row.pages.map(h)) : row.pages.reduce((s, p, j) => s + w(p) + (j ? PAGE_GAP : 0), 0));
62
+ const maxCross = rows.reduce((m, row) => Math.max(m, cross(row)), 0);
63
+ const boxes = new Array(n);
64
+ const single = scrollMode === 'page';
65
+ if (axis === 'y') {
66
+ const inner = Math.max(input.viewportWidth, maxCross + 2 * VIEW_PADDING);
67
+ rows.forEach((row, r) => {
68
+ let x = (inner - cross(row)) / 2;
69
+ const y = VIEW_PADDING + (single ? 0 : metrics.offsetOf(r));
70
+ for (const p of row.pages) {
71
+ boxes[p] = { x: Math.round(x), y, width: w(p), height: h(p) };
72
+ x += w(p) + PAGE_GAP;
73
+ }
74
+ });
75
+ const along = single ? rows.reduce((m, row) => Math.max(m, row.extent), 0) : metrics.totalHeight;
76
+ return { axis, mode: scrollMode, boxes, rows, rowOf, metrics, width: inner, height: along - PAGE_GAP + 2 * VIEW_PADDING };
77
+ }
78
+ rows.forEach((row, r) => {
79
+ const p = row.pages[0];
80
+ boxes[p] = { x: VIEW_PADDING + metrics.offsetOf(r), y: VIEW_PADDING + (maxCross - h(p)) / 2, width: w(p), height: h(p) };
81
+ });
82
+ return { axis, mode: scrollMode, boxes, rows, rowOf, metrics, width: metrics.totalHeight - PAGE_GAP + 2 * VIEW_PADDING, height: maxCross + 2 * VIEW_PADDING };
83
+ }
84
+ /**
85
+ * Pages to render for a scroll position. `offset` and `extent` are along the
86
+ * layout axis; `pageRow` is the current row in `'page'` mode.
87
+ */
88
+ export function visiblePages(layout, offset, extent, overscan = 1, pageRow = 0) {
89
+ const n = layout.rows.length;
90
+ if (n === 0)
91
+ return { pages: [], current: 0 };
92
+ if (layout.mode === 'page') {
93
+ const r = Math.min(n - 1, Math.max(0, pageRow));
94
+ const row = layout.rows[r];
95
+ return { pages: row.pages, current: row.pages[0] };
96
+ }
97
+ const range = computeRange(layout.metrics, offset - VIEW_PADDING, Math.max(1, extent), overscan);
98
+ const pages = [];
99
+ for (let r = range.overscanStart; r < range.overscanEnd; r++)
100
+ pages.push(...layout.rows[r].pages);
101
+ // The current page: the row under the first third of the viewport, or the last row at the end.
102
+ const total = layout.axis === 'x' ? layout.width : layout.height;
103
+ const atEnd = offset + extent >= total - 1 && offset > 0;
104
+ const probe = layout.metrics.indexAt(Math.max(0, offset - VIEW_PADDING + extent / 3));
105
+ const row = layout.rows[atEnd ? n - 1 : probe];
106
+ return { pages, current: row.pages[0] };
107
+ }
108
+ /** Scroll offset (along the axis) that brings a page to the start of the viewport. */
109
+ export function pageOffset(layout, page) {
110
+ const box = layout.boxes[page];
111
+ if (!box)
112
+ return 0;
113
+ return Math.max(0, (layout.axis === 'x' ? box.x : box.y) - VIEW_PADDING / 2);
114
+ }
115
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,0EAA0E;A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M,GAAG,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAc,CAAC;IAC5D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAW,EAAE,CAAC;AACpD,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,MAAoB,EAAE,IAAY;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG;QAAE,OAAO,CAAC,CAAC;IACnB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,49 @@
1
+ export interface PdfViewerLocaleText {
2
+ readonly label: string;
3
+ readonly toolbar: string;
4
+ readonly loading: string;
5
+ readonly loadError: string;
6
+ readonly empty: string;
7
+ readonly pageLabel: string;
8
+ readonly pageNumber: string;
9
+ readonly pageOf: string;
10
+ readonly previous: string;
11
+ readonly next: string;
12
+ readonly zoomIn: string;
13
+ readonly zoomOut: string;
14
+ readonly zoom: string;
15
+ readonly zoomAuto: string;
16
+ readonly zoomPageFit: string;
17
+ readonly zoomPageWidth: string;
18
+ readonly sidebar: string;
19
+ readonly thumbnails: string;
20
+ readonly outline: string;
21
+ readonly noOutline: string;
22
+ readonly thumbnailLabel: string;
23
+ readonly search: string;
24
+ readonly findLabel: string;
25
+ readonly findPlaceholder: string;
26
+ readonly findNext: string;
27
+ readonly findPrevious: string;
28
+ readonly matchCase: string;
29
+ readonly wholeWord: string;
30
+ readonly highlightAll: string;
31
+ readonly matchCount: string;
32
+ readonly noMatches: string;
33
+ readonly closeFind: string;
34
+ readonly highlight: string;
35
+ readonly underline: string;
36
+ readonly strikethrough: string;
37
+ readonly print: string;
38
+ readonly download: string;
39
+ readonly passwordTitle: string;
40
+ readonly passwordPrompt: string;
41
+ readonly passwordIncorrect: string;
42
+ readonly passwordLabel: string;
43
+ readonly passwordSubmit: string;
44
+ readonly passwordCancel: string;
45
+ readonly more: string;
46
+ }
47
+ export declare const PDF_VIEWER_DEFAULT_LOCALE_TEXT: PdfViewerLocaleText;
48
+ export declare const fill: (text: string, values: Readonly<Record<string, string | number>>) => string;
49
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa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C,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,8BAA8B,EAAE,mBA6C3C,CAAC;AAEH,eAAO,MAAM,IAAI,SAAU,MAAM,UAAU,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,KAAG,MAAmG,CAAC"}
package/dist/locale.js ADDED
@@ -0,0 +1,50 @@
1
+ // Default strings of PdfViewer. `{page}`, `{count}`, `{current}`
2
+ // and `{total}` are replaced at render time.
3
+ export const PDF_VIEWER_DEFAULT_LOCALE_TEXT = Object.freeze({
4
+ label: 'PDF document',
5
+ toolbar: 'PDF tools',
6
+ loading: 'Loading document…',
7
+ loadError: 'The document could not be loaded.',
8
+ empty: 'No document',
9
+ pageLabel: 'Page {page} of {count}',
10
+ pageNumber: 'Page',
11
+ pageOf: 'of {count}',
12
+ previous: 'Previous page',
13
+ next: 'Next page',
14
+ zoomIn: 'Zoom in',
15
+ zoomOut: 'Zoom out',
16
+ zoom: 'Zoom',
17
+ zoomAuto: 'Automatic',
18
+ zoomPageFit: 'Page fit',
19
+ zoomPageWidth: 'Page width',
20
+ sidebar: 'Toggle sidebar',
21
+ thumbnails: 'Thumbnails',
22
+ outline: 'Bookmarks',
23
+ noOutline: 'This document has no bookmarks.',
24
+ thumbnailLabel: 'Page {page}',
25
+ search: 'Find',
26
+ findLabel: 'Find in document',
27
+ findPlaceholder: 'Find',
28
+ findNext: 'Next match',
29
+ findPrevious: 'Previous match',
30
+ matchCase: 'Match case',
31
+ wholeWord: 'Whole words',
32
+ highlightAll: 'Highlight all',
33
+ matchCount: '{current} of {total}',
34
+ noMatches: 'No matches',
35
+ closeFind: 'Close find bar',
36
+ highlight: 'Highlight',
37
+ underline: 'Underline',
38
+ strikethrough: 'Strikethrough',
39
+ print: 'Print',
40
+ download: 'Download',
41
+ passwordTitle: 'Password required',
42
+ passwordPrompt: 'Enter the password to open this PDF document.',
43
+ passwordIncorrect: 'Incorrect password. Try again.',
44
+ passwordLabel: 'Password',
45
+ passwordSubmit: 'Open',
46
+ passwordCancel: 'Cancel',
47
+ more: 'More tools',
48
+ });
49
+ export const fill = (text, values) => text.replace(/\{(\w+)\}/g, (m, key) => (key in values ? String(values[key]) : m));
50
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,6CAA6C;AAiD7C,MAAM,CAAC,MAAM,8BAA8B,GAAwB,MAAM,CAAC,MAAM,CAAC;IAC/E,KAAK,EAAE,cAAc;IACrB,OAAO,EAAE,WAAW;IACpB,OAAO,EAAE,mBAAmB;IAC5B,SAAS,EAAE,mCAAmC;IAC9C,KAAK,EAAE,aAAa;IACpB,SAAS,EAAE,wBAAwB;IACnC,UAAU,EAAE,MAAM;IAClB,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,eAAe;IACzB,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,UAAU;IACvB,aAAa,EAAE,YAAY;IAC3B,OAAO,EAAE,gBAAgB;IACzB,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,WAAW;IACpB,SAAS,EAAE,iCAAiC;IAC5C,cAAc,EAAE,aAAa;IAC7B,MAAM,EAAE,MAAM;IACd,SAAS,EAAE,kBAAkB;IAC7B,eAAe,EAAE,MAAM;IACvB,QAAQ,EAAE,YAAY;IACtB,YAAY,EAAE,gBAAgB;IAC9B,SAAS,EAAE,YAAY;IACvB,SAAS,EAAE,aAAa;IACxB,YAAY,EAAE,eAAe;IAC7B,UAAU,EAAE,sBAAsB;IAClC,SAAS,EAAE,YAAY;IACvB,SAAS,EAAE,gBAAgB;IAC3B,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,aAAa,EAAE,eAAe;IAC9B,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,mBAAmB;IAClC,cAAc,EAAE,+CAA+C;IAC/D,iBAAiB,EAAE,gCAAgC;IACnD,aAAa,EAAE,UAAU;IACzB,cAAc,EAAE,MAAM;IACtB,cAAc,EAAE,QAAQ;IACxB,IAAI,EAAE,YAAY;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAiD,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { PdfRect, PdfTextMarkupAnnotation, PdfTextMarkupKind } from './types.js';
2
+ /** A page's `/MediaBox`-derived view box `[x0, y0, x1, y1]` and `/Rotate`. */
3
+ export interface PageGeometry {
4
+ readonly view: readonly [number, number, number, number];
5
+ readonly rotate: number;
6
+ }
7
+ export interface CssRect {
8
+ readonly left: number;
9
+ readonly top: number;
10
+ readonly width: number;
11
+ readonly height: number;
12
+ }
13
+ type Matrix = readonly [number, number, number, number, number, number];
14
+ /** The pdf.js PageViewport transform for `scale` (CSS px per PDF unit). */
15
+ export declare function pageTransform(geometry: PageGeometry, scale: number): Matrix;
16
+ /** Page CSS rectangle (at `scale`) to a normalized PDF rectangle. */
17
+ export declare function cssRectToPdf(geometry: PageGeometry, scale: number, rect: CssRect): PdfRect;
18
+ /** PDF rectangle to a page CSS rectangle at `scale`. */
19
+ export declare function pdfRectToCss(geometry: PageGeometry, scale: number, rect: PdfRect): CssRect;
20
+ /**
21
+ * Merges selection client rectangles into one rectangle per line: rectangles
22
+ * that overlap vertically by at least half the smaller height and touch
23
+ * horizontally join; empty and contained rectangles drop.
24
+ */
25
+ export declare function mergeLineRects(rects: readonly CssRect[]): CssRect[];
26
+ /** Bounding rectangle of PDF rectangles. */
27
+ export declare function boundingRect(rects: readonly PdfRect[]): PdfRect;
28
+ /** `/QuadPoints` of line rectangles (upper left, upper right, lower left, lower right per line). */
29
+ export declare function quadPoints(rects: readonly PdfRect[]): number[];
30
+ /**
31
+ * The band of a line rectangle a markup kind paints, in PDF units: the whole
32
+ * line for a highlight, a thin bar near the bottom for an underline, one
33
+ * through the middle for a strikethrough.
34
+ */
35
+ export declare function markBand(kind: PdfTextMarkupKind, rect: PdfRect): PdfRect;
36
+ /** Closed polygons (`[x, y, ...]`) of the appearance stream the writer draws. */
37
+ export declare function markOutlines(kind: PdfTextMarkupKind, rects: readonly PdfRect[]): number[][];
38
+ export declare const DEFAULT_MARKUP_COLORS: Readonly<Record<PdfTextMarkupKind, string>>;
39
+ /** `#rgb` / `#rrggbb` to 0..255 components (black when unparsable). */
40
+ export declare function hexToRgb(color: string): [number, number, number];
41
+ /** Editor-storage record pdf.js `saveDocument` writes as a markup annotation (HIGHLIGHT editor type, outlines as appearance). */
42
+ export declare function toEngineRecord(annotation: PdfTextMarkupAnnotation): Record<string, unknown>;
43
+ /**
44
+ * pdf.js writes every new markup annotation as `/Highlight`. The names
45
+ * `/Highlight`, `/Underline` and `/StrikeOut` have the same byte length, so
46
+ * the subtype of each annotation appended after `from` is patched in place
47
+ * (xref offsets stay valid); the annotation is found by its `/Rect`.
48
+ * Returns the number of patched annotations.
49
+ */
50
+ export declare function patchMarkupSubtypes(bytes: Uint8Array, from: number, annotations: readonly PdfTextMarkupAnnotation[]): number;
51
+ /** A fresh annotation id (time based, unique per session). */
52
+ export declare const annotationId: () => string;
53
+ export {};
54
+ //# sourceMappingURL=markup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup.d.ts","sourceRoot":"","sources":["../src/markup.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,uBAAuB,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AE,iBAAiB,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAMxE;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,EAAE,EAAE,CAK3F;AAED,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAA2F,CAAC;AAE1K,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAKhE;AAED,iIAAiI;AACjI,wBAAgB,cAAc,CAAC,UAAU,EAAE,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkB3F;AAUD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,uBAAuB,EAAE,GAAG,MAAM,CAqB5H;AAGD,8DAA8D;AAC9D,eAAO,MAAM,YAAY,QAAO,MAAmE,CAAC"}
package/dist/markup.js ADDED
@@ -0,0 +1,175 @@
1
+ /** The pdf.js PageViewport transform for `scale` (CSS px per PDF unit). */
2
+ export function pageTransform(geometry, scale) {
3
+ const [x0, y0, x1, y1] = geometry.view;
4
+ const cx = (x0 + x1) / 2;
5
+ const cy = (y0 + y1) / 2;
6
+ const rotation = ((geometry.rotate % 360) + 360) % 360;
7
+ let a = 1;
8
+ let b = 0;
9
+ let c = 0;
10
+ let d = -1;
11
+ if (rotation === 90)
12
+ [a, b, c, d] = [0, 1, 1, 0];
13
+ else if (rotation === 180)
14
+ [a, b, c, d] = [-1, 0, 0, 1];
15
+ else if (rotation === 270)
16
+ [a, b, c, d] = [0, -1, -1, 0];
17
+ const ox = a === 0 ? Math.abs(cy - y0) * scale : Math.abs(cx - x0) * scale;
18
+ const oy = a === 0 ? Math.abs(cx - x0) * scale : Math.abs(cy - y0) * scale;
19
+ return [a * scale, b * scale, c * scale, d * scale, ox - a * scale * cx - c * scale * cy, oy - b * scale * cx - d * scale * cy];
20
+ }
21
+ const apply = (m, x, y) => [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
22
+ function invert(m) {
23
+ const det = m[0] * m[3] - m[1] * m[2];
24
+ return [m[3] / det, -m[1] / det, -m[2] / det, m[0] / det, (m[2] * m[5] - m[3] * m[4]) / det, (m[1] * m[4] - m[0] * m[5]) / det];
25
+ }
26
+ const round2 = (v) => Math.round(v * 100) / 100;
27
+ /** Page CSS rectangle (at `scale`) to a normalized PDF rectangle. */
28
+ export function cssRectToPdf(geometry, scale, rect) {
29
+ const inv = invert(pageTransform(geometry, scale));
30
+ const [ax, ay] = apply(inv, rect.left, rect.top);
31
+ const [bx, by] = apply(inv, rect.left + rect.width, rect.top + rect.height);
32
+ return [round2(Math.min(ax, bx)), round2(Math.min(ay, by)), round2(Math.max(ax, bx)), round2(Math.max(ay, by))];
33
+ }
34
+ /** PDF rectangle to a page CSS rectangle at `scale`. */
35
+ export function pdfRectToCss(geometry, scale, rect) {
36
+ const m = pageTransform(geometry, scale);
37
+ const [ax, ay] = apply(m, rect[0], rect[1]);
38
+ const [bx, by] = apply(m, rect[2], rect[3]);
39
+ return { left: Math.min(ax, bx), top: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
40
+ }
41
+ /**
42
+ * Merges selection client rectangles into one rectangle per line: rectangles
43
+ * that overlap vertically by at least half the smaller height and touch
44
+ * horizontally join; empty and contained rectangles drop.
45
+ */
46
+ export function mergeLineRects(rects) {
47
+ const list = rects.filter((r) => r.width > 0.5 && r.height > 0.5).map((r) => ({ l: r.left, t: r.top, r: r.left + r.width, b: r.top + r.height }));
48
+ list.sort((p, q) => p.t - q.t || p.l - q.l);
49
+ const out = [];
50
+ for (const cur of list) {
51
+ const line = out.find((o) => {
52
+ const overlap = Math.min(o.b, cur.b) - Math.max(o.t, cur.t);
53
+ return overlap >= Math.min(o.b - o.t, cur.b - cur.t) / 2 && cur.l <= o.r + 4 && cur.r >= o.l - 4;
54
+ });
55
+ if (line) {
56
+ line.l = Math.min(line.l, cur.l);
57
+ line.r = Math.max(line.r, cur.r);
58
+ line.t = Math.min(line.t, cur.t);
59
+ line.b = Math.max(line.b, cur.b);
60
+ }
61
+ else
62
+ out.push({ ...cur });
63
+ }
64
+ return out.map((o) => ({ left: o.l, top: o.t, width: o.r - o.l, height: o.b - o.t }));
65
+ }
66
+ /** Bounding rectangle of PDF rectangles. */
67
+ export function boundingRect(rects) {
68
+ let [x1, y1, x2, y2] = [Infinity, Infinity, -Infinity, -Infinity];
69
+ for (const r of rects) {
70
+ x1 = Math.min(x1, r[0]);
71
+ y1 = Math.min(y1, r[1]);
72
+ x2 = Math.max(x2, r[2]);
73
+ y2 = Math.max(y2, r[3]);
74
+ }
75
+ return rects.length ? [x1, y1, x2, y2] : [0, 0, 0, 0];
76
+ }
77
+ /** `/QuadPoints` of line rectangles (upper left, upper right, lower left, lower right per line). */
78
+ export function quadPoints(rects) {
79
+ return rects.flatMap((r) => [r[0], r[3], r[2], r[3], r[0], r[1], r[2], r[1]]);
80
+ }
81
+ /**
82
+ * The band of a line rectangle a markup kind paints, in PDF units: the whole
83
+ * line for a highlight, a thin bar near the bottom for an underline, one
84
+ * through the middle for a strikethrough.
85
+ */
86
+ export function markBand(kind, rect) {
87
+ if (kind === 'highlight')
88
+ return rect;
89
+ const h = rect[3] - rect[1];
90
+ const t = Math.max(0.5, h * 0.07);
91
+ const y = kind === 'underline' ? rect[1] + h * 0.08 : rect[1] + h * 0.45;
92
+ return [rect[0], round2(y), rect[2], round2(y + t)];
93
+ }
94
+ /** Closed polygons (`[x, y, ...]`) of the appearance stream the writer draws. */
95
+ export function markOutlines(kind, rects) {
96
+ return rects.map((r) => {
97
+ const [x1, y1, x2, y2] = markBand(kind, r);
98
+ return [x1, y1, x2, y1, x2, y2, x1, y2];
99
+ });
100
+ }
101
+ export const DEFAULT_MARKUP_COLORS = Object.freeze({ highlight: '#ffd400', underline: '#2563eb', strikethrough: '#dc2626' });
102
+ /** `#rgb` / `#rrggbb` to 0..255 components (black when unparsable). */
103
+ export function hexToRgb(color) {
104
+ let hex = color.trim().replace(/^#/, '');
105
+ if (hex.length === 3)
106
+ hex = hex.replace(/./g, (c) => c + c);
107
+ const n = /^[0-9a-f]{6}$/i.test(hex) ? Number.parseInt(hex, 16) : 0;
108
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
109
+ }
110
+ /** Editor-storage record pdf.js `saveDocument` writes as a markup annotation (HIGHLIGHT editor type, outlines as appearance). */
111
+ export function toEngineRecord(annotation) {
112
+ const rect = boundingRect(annotation.rects);
113
+ const record = {
114
+ annotationType: 9,
115
+ pageIndex: annotation.page - 1,
116
+ color: hexToRgb(annotation.color),
117
+ opacity: annotation.opacity ?? 1,
118
+ thickness: 1,
119
+ quadPoints: quadPoints(annotation.rects),
120
+ outlines: markOutlines(annotation.kind, annotation.rects),
121
+ rect: [...rect],
122
+ rotation: 0,
123
+ user: annotation.author,
124
+ date: annotation.createdAt,
125
+ structTreeParentId: null,
126
+ };
127
+ if (annotation.comment)
128
+ record['popup'] = { contents: annotation.comment, rect: [rect[2], rect[3] - 80, rect[2] + 160, rect[3]] };
129
+ return record;
130
+ }
131
+ const SUBTYPE = { highlight: '/Highlight', underline: '/Underline', strikethrough: '/StrikeOut' };
132
+ const latin1 = (bytes, from) => {
133
+ let s = '';
134
+ for (let i = from; i < bytes.length; i += 8192)
135
+ s += String.fromCharCode(...bytes.subarray(i, Math.min(bytes.length, i + 8192)));
136
+ return s;
137
+ };
138
+ const nums = (s) => s.trim().split(/\s+/).map(Number);
139
+ /**
140
+ * pdf.js writes every new markup annotation as `/Highlight`. The names
141
+ * `/Highlight`, `/Underline` and `/StrikeOut` have the same byte length, so
142
+ * the subtype of each annotation appended after `from` is patched in place
143
+ * (xref offsets stay valid); the annotation is found by its `/Rect`.
144
+ * Returns the number of patched annotations.
145
+ */
146
+ export function patchMarkupSubtypes(bytes, from, annotations) {
147
+ const wanted = annotations.filter((a) => a.kind !== 'highlight').map((a) => ({ a, rect: boundingRect(a.rects), done: false }));
148
+ if (!wanted.length)
149
+ return 0;
150
+ const tail = latin1(bytes, from);
151
+ const objRe = /\d+\s+\d+\s+obj\b([\s\S]*?)\bendobj\b/g;
152
+ let patched = 0;
153
+ for (let m = objRe.exec(tail); m; m = objRe.exec(tail)) {
154
+ const body = m[1];
155
+ const sub = body.indexOf('/Subtype /Highlight');
156
+ const rect = /\/Rect\s*\[([^\]]*)\]/.exec(body);
157
+ if (sub < 0 || !rect)
158
+ continue;
159
+ const r = nums(rect[1]);
160
+ const hit = wanted.find((w) => !w.done && w.rect.every((v, i) => Math.abs(v - (r[i] ?? NaN)) < 0.6));
161
+ if (!hit)
162
+ continue;
163
+ hit.done = true;
164
+ const at = from + m.index + m[0].indexOf(body) + sub + '/Subtype '.length;
165
+ const name = SUBTYPE[hit.a.kind];
166
+ for (let i = 0; i < name.length; i++)
167
+ bytes[at + i] = name.charCodeAt(i);
168
+ patched++;
169
+ }
170
+ return patched;
171
+ }
172
+ let seq = 0;
173
+ /** A fresh annotation id (time based, unique per session). */
174
+ export const annotationId = () => `pdfv-${Date.now().toString(36)}-${(seq++).toString(36)}`;
175
+ //# sourceMappingURL=markup.js.map