@react-pdf-kit/viewer 0.0.0-experimental.4 → 0.0.0-experimental.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.
Files changed (138) hide show
  1. package/dist/RPLayout.module-b4b23e29.js +14 -0
  2. package/dist/assets/style.css +1 -1
  3. package/dist/assets/style.js +15 -15
  4. package/dist/components/RPConfig.js +18 -6
  5. package/dist/components/RPController.js +21 -26
  6. package/dist/components/RPDropFileZone.js +34 -28
  7. package/dist/components/RPPages.js +352 -361
  8. package/dist/components/RPProvider.js +20 -24
  9. package/dist/components/layout/LayoutContainer.js +1 -1
  10. package/dist/components/layout/LayoutWrapper.js +1 -1
  11. package/dist/components/layout/RPDefaultLayout.js +6 -7
  12. package/dist/components/layout/RPLayout.js +22 -22
  13. package/dist/components/layout/WrapperLayout.js +10 -11
  14. package/dist/components/layout/sidebar/RPSidebar.js +3 -4
  15. package/dist/components/layout/sidebar/Thumbnail.js +3 -4
  16. package/dist/components/layout/sidebar/Thumbnails.js +3 -4
  17. package/dist/components/layout/toolbar/DocumentDialog.js +5 -6
  18. package/dist/components/layout/toolbar/FileDownloadTool.js +3 -4
  19. package/dist/components/layout/toolbar/FileUploadTool.js +3 -4
  20. package/dist/components/layout/toolbar/MostPageTool.js +3 -4
  21. package/dist/components/layout/toolbar/OtherTool.js +3 -4
  22. package/dist/components/layout/toolbar/Paginate.js +3 -4
  23. package/dist/components/layout/toolbar/PrintTool.js +3 -4
  24. package/dist/components/layout/toolbar/RPMoreOptions.js +3 -4
  25. package/dist/components/layout/toolbar/RPToolbar.js +3 -6
  26. package/dist/components/layout/toolbar/RPToolbarEnd.js +3 -4
  27. package/dist/components/layout/toolbar/RotateTool.js +3 -4
  28. package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -6
  29. package/dist/components/layout/toolbar/SearchTool.js +5 -8
  30. package/dist/components/layout/toolbar/ThumbnailTool.js +3 -4
  31. package/dist/components/layout/toolbar/ToolbarCustom.js +3 -4
  32. package/dist/components/layout/toolbar/ToolbarDefault.js +3 -6
  33. package/dist/components/layout/toolbar/ToolbarLayout.js +3 -6
  34. package/dist/components/layout/toolbar/ZoomTool.js +3 -4
  35. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +3 -4
  36. package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +7 -9
  37. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +3 -4
  38. package/dist/components/layout/toolbar/tools/FileUploadTool.js +3 -4
  39. package/dist/components/layout/toolbar/tools/FirstPageTool.js +7 -9
  40. package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -4
  41. package/dist/components/layout/toolbar/tools/LastPageTool.js +7 -9
  42. package/dist/components/layout/toolbar/tools/NextPageTool.js +3 -4
  43. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +3 -4
  44. package/dist/components/layout/toolbar/tools/PrintTool.js +3 -4
  45. package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +3 -4
  46. package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -4
  47. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +3 -4
  48. package/dist/components/layout/toolbar/tools/ZoomInTool.js +3 -4
  49. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +13 -14
  50. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +3 -4
  51. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +3 -6
  52. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +3 -4
  53. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +3 -4
  54. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +3 -4
  55. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +3 -4
  56. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +3 -4
  57. package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +3 -4
  58. package/dist/components/page/AnnotationLayer.js +65 -66
  59. package/dist/components/page/CanvasLayer.js +3 -4
  60. package/dist/components/page/CustomElement.js +3 -4
  61. package/dist/components/page/DualPage.js +5 -11
  62. package/dist/components/page/DualPageWithCover.js +5 -11
  63. package/dist/components/page/RPPage.js +6 -12
  64. package/dist/components/page/SinglePage.js +5 -11
  65. package/dist/components/page/TextHighlightLayer.js +178 -86
  66. package/dist/components/page/TextLayer.js +170 -125
  67. package/dist/components/ui/LoadingIndicator.js +7 -8
  68. package/dist/contexts/ConfigContext.js +5 -4
  69. package/dist/contexts/DimensionPagesContext.js +5 -6
  70. package/dist/contexts/DropFileZoneContext.js +4 -5
  71. package/dist/contexts/ElementPageContext.js +5 -6
  72. package/dist/contexts/FileInputContext.js +5 -6
  73. package/dist/contexts/HighlightContext.js +7 -10
  74. package/dist/contexts/LayoutDropFileZoneContext.js +11 -0
  75. package/dist/contexts/LicenseContext.js +8 -6
  76. package/dist/contexts/PagesRotateContext.js +5 -6
  77. package/dist/contexts/PaginationContext.js +5 -6
  78. package/dist/contexts/PrintContext.js +16 -17
  79. package/dist/contexts/RPDocumentContext.js +13 -14
  80. package/dist/contexts/RenderQueueProvider.js +5 -6
  81. package/dist/contexts/RotationContext.js +8 -9
  82. package/dist/contexts/SearchContext.js +5 -8
  83. package/dist/contexts/ThumbnailsContext.js +4 -5
  84. package/dist/contexts/ZoomContext.js +5 -6
  85. package/dist/main.js +9 -9
  86. package/dist/types/components/layout/sidebar/Thumbnail.d.ts +2 -2
  87. package/dist/types/contexts/LayoutDropFileZoneContext.d.ts +9 -0
  88. package/dist/types/contexts/RPDocumentContext.d.ts +1 -1
  89. package/dist/types/contexts/RenderQueueProvider.d.ts +1 -1
  90. package/dist/types/contexts/RenderedPagesCache.d.ts +2 -2
  91. package/dist/types/main.d.ts +1 -1
  92. package/dist/types/utils/annotations.d.ts +2 -2
  93. package/dist/types/utils/getThumbnailViewport.d.ts +2 -2
  94. package/dist/types/utils/highlight.d.ts +5 -5
  95. package/dist/types/utils/hooks/useDropFileZone.d.ts +5 -0
  96. package/dist/types/utils/hooks/useFlickerSelectText.d.ts +1 -0
  97. package/dist/types/utils/hooks/useHighlight.d.ts +1 -1
  98. package/dist/types/utils/hooks/useLoadPdf.d.ts +2 -2
  99. package/dist/types/utils/hooks/useLoadWorker.d.ts +1 -5
  100. package/dist/types/utils/hooks/usePdfProperties.d.ts +1 -1
  101. package/dist/types/utils/hooks/useTextSelection.d.ts +3 -12
  102. package/dist/types/utils/link_service.d.ts +3 -2
  103. package/dist/types/utils/renderPage.d.ts +2 -2
  104. package/dist/types/utils/types.d.ts +10 -6
  105. package/dist/utils/highlight.js +158 -184
  106. package/dist/utils/hooks/useCopyText.js +22 -60
  107. package/dist/utils/hooks/useDropFileZone.js +12 -0
  108. package/dist/utils/hooks/useFileDownload.js +5 -6
  109. package/dist/utils/hooks/useFlickerSelectText.js +25 -0
  110. package/dist/utils/hooks/useHighlight.js +33 -35
  111. package/dist/utils/hooks/useLicense.js +22 -28
  112. package/dist/utils/hooks/useLoadPdf.js +70 -95
  113. package/dist/utils/hooks/useLoadWorker.js +14 -4
  114. package/dist/utils/hooks/usePageRotateContext.js +7 -8
  115. package/dist/utils/hooks/usePaginate.js +3 -4
  116. package/dist/utils/hooks/usePinch.js +10 -11
  117. package/dist/utils/hooks/usePresentPage.js +3 -4
  118. package/dist/utils/hooks/usePrint.js +55 -54
  119. package/dist/utils/hooks/useRotate.js +3 -4
  120. package/dist/utils/hooks/useScrollToPage.js +3 -4
  121. package/dist/utils/hooks/useSearch.js +15 -18
  122. package/dist/utils/hooks/useTextSelection.js +73 -2
  123. package/dist/utils/hooks/useThumbnail.js +17 -18
  124. package/dist/utils/hooks/useVirtualReactWindow.js +3 -4
  125. package/dist/utils/hooks/useWatermark.js +8 -6
  126. package/dist/utils/link_service.js +19 -18
  127. package/dist/utils/renderPage.js +1 -1
  128. package/dist/utils/types.js +3 -3
  129. package/package.json +6 -7
  130. package/dist/RPLayout.module-7766e0b4.js +0 -14
  131. package/dist/contexts/TextSelectionContext.js +0 -191
  132. package/dist/types/contexts/TextSelectionContext.d.ts +0 -14
  133. package/dist/types/utils/geometryCache.d.ts +0 -15
  134. package/dist/types/utils/glyphHitTest.d.ts +0 -12
  135. package/dist/types/utils/selectionUtils.d.ts +0 -30
  136. package/dist/utils/geometryCache.js +0 -32
  137. package/dist/utils/glyphHitTest.js +0 -29
  138. package/dist/utils/selectionUtils.js +0 -96
@@ -1,191 +0,0 @@
1
- import { jsx as J } from "react/jsx-runtime";
2
- import { createContext as K, useContext as O, useRef as l, useState as Q, useCallback as f, useEffect as _, useMemo as B } from "react";
3
- import { glyphAt as q } from "../utils/glyphHitTest.js";
4
- import { rectsForRange as A, textForRange as E, expandToWordBoundary as L, expandToLineBoundary as $ } from "../utils/selectionUtils.js";
5
- import { geometryCache as k } from "../utils/geometryCache.js";
6
- import { useEventCallbackContext as ee } from "./EventCallbackContext.js";
7
- import { useZoomContext as te } from "./ZoomContext.js";
8
- import "../utils/types.js";
9
- import "../de_DE-a553b162.js";
10
- import "../utils/appConsole.js";
11
- import "./InitialStateContext.js";
12
- import "./RPDocumentContext.js";
13
- import "../utils/hooks/useLoadPdf.js";
14
- import "@pdf-viewer/pdfium";
15
- import "@pdf-viewer/pdfium/compat";
16
- import "../utils/getThumbnailViewport.js";
17
- import "./ConfigContext.js";
18
- import "./DocumentPasswordContext.js";
19
- import "../utils/hooks/usePdfProperties.js";
20
- import "../utils/convertPdfDate.js";
21
- import "../utils/formatFileSize.js";
22
- import "../utils/constants.js";
23
- import "../utils/getZoomLevel.js";
24
- import "./LayoutContainerContext.js";
25
- import "./ViewModeContext.js";
26
- import "./RotationContext.js";
27
- import "./GlobalCurrentPage.js";
28
- import "../utils/hooks/useDebounce.js";
29
- const ne = {
30
- handlePointerDown: () => {
31
- },
32
- handlePointerMove: () => {
33
- },
34
- handlePointerUp: () => {
35
- },
36
- getPageSelectionRects: () => [],
37
- isSelecting: !1,
38
- selectedText: "",
39
- selectionVersion: 0,
40
- clearSelection: () => {
41
- }
42
- }, z = K(ne), Ve = () => O(z), Fe = ({ children: G }) => {
43
- const { onTextSelect: C } = ee(), { currentZoom: P } = te(), h = l(null), R = l(null), g = l(!1), y = l(/* @__PURE__ */ new Map()), S = l(""), m = l(0), F = l(0), D = l({ x: 0, y: 0 }), I = l(0), w = l(0), M = l(-1), [N, V] = Q(0), T = f(
44
- (e, n) => {
45
- const o = n.getBoundingClientRect();
46
- return { x: e.clientX - o.left, y: e.clientY - o.top };
47
- },
48
- []
49
- ), b = f(
50
- (e, n) => {
51
- const o = /* @__PURE__ */ new Map();
52
- let a = "";
53
- if (e.pageIndex === n.pageIndex) {
54
- const i = k.get(e.pageIndex);
55
- if (i) {
56
- const c = A(i, e.charIndex, n.charIndex);
57
- c.length > 0 && o.set(e.pageIndex, c), a = E(i, e.charIndex, n.charIndex);
58
- }
59
- } else {
60
- const i = e.pageIndex < n.pageIndex, c = Math.min(e.pageIndex, n.pageIndex), t = Math.max(e.pageIndex, n.pageIndex);
61
- for (let r = c; r <= t; r++) {
62
- const u = k.get(r);
63
- if (!u || u.totalCharCount === 0)
64
- continue;
65
- const d = u.totalCharCount - 1;
66
- let x, p;
67
- r === e.pageIndex ? (x = e.charIndex, p = i ? d : 0) : r === n.pageIndex ? (x = i ? 0 : d, p = n.charIndex) : (x = 0, p = d);
68
- const s = A(u, x, p);
69
- s.length > 0 && o.set(r, s);
70
- const j = E(u, x, p);
71
- a && j && (a += `
72
- `), a += j;
73
- }
74
- }
75
- y.current = o, S.current = a, V((i) => i + 1);
76
- },
77
- []
78
- ), X = f(
79
- (e, n, o) => {
80
- const { x: a, y: i } = T(n, o), c = k.get(e);
81
- if (!c)
82
- return;
83
- const t = q(c, a, i);
84
- if (!t) {
85
- h.current = null, R.current = null, y.current = /* @__PURE__ */ new Map(), S.current = "", V((s) => s + 1);
86
- return;
87
- }
88
- const r = Date.now(), u = Math.abs(n.clientX - D.current.x), d = Math.abs(n.clientY - D.current.y);
89
- r - F.current < 500 && u < 5 && d < 5 ? m.current = m.current % 3 + 1 : m.current = 1, F.current = r, D.current = { x: n.clientX, y: n.clientY };
90
- let x, p;
91
- if (m.current === 2) {
92
- const s = L(c, t.charIndex);
93
- x = { pageIndex: e, charIndex: s.start }, p = { pageIndex: e, charIndex: s.end }, I.current = s.start, w.current = s.end, M.current = e;
94
- } else if (m.current === 3) {
95
- const s = $(c, t.charIndex);
96
- x = { pageIndex: e, charIndex: s.start }, p = { pageIndex: e, charIndex: s.end }, I.current = s.start, w.current = s.end, M.current = e;
97
- } else
98
- x = { pageIndex: e, charIndex: t.charIndex }, p = { pageIndex: e, charIndex: t.charIndex };
99
- h.current = x, R.current = p, g.current = !0, o.setPointerCapture(n.pointerId), b(x, p);
100
- },
101
- [T, b]
102
- ), Y = f(
103
- (e, n, o) => {
104
- if (!g.current || !h.current)
105
- return;
106
- const { x: a, y: i } = T(n, o), c = k.get(e);
107
- if (!c)
108
- return;
109
- const t = q(c, a, i);
110
- if (!t)
111
- return;
112
- let r = t.charIndex;
113
- const u = h.current;
114
- if (m.current === 2 && e === M.current) {
115
- const d = L(c, t.charIndex);
116
- t.charIndex < I.current ? (r = d.start, h.current = { pageIndex: u.pageIndex, charIndex: w.current }) : (r = d.end, h.current = { pageIndex: u.pageIndex, charIndex: I.current });
117
- } else if (m.current === 3 && e === M.current) {
118
- const d = $(c, t.charIndex);
119
- t.charIndex < I.current ? (r = d.start, h.current = { pageIndex: u.pageIndex, charIndex: w.current }) : (r = d.end, h.current = { pageIndex: u.pageIndex, charIndex: I.current });
120
- }
121
- R.current = { pageIndex: e, charIndex: r }, b(h.current, R.current);
122
- },
123
- [T, b]
124
- ), Z = f(() => {
125
- if (!g.current)
126
- return;
127
- g.current = !1;
128
- const e = S.current;
129
- if (e && C) {
130
- const n = [];
131
- for (const [o, a] of y.current.entries()) {
132
- const i = o + 1, c = document.querySelector(`[data-rp="page-${i}"]`), t = c == null ? void 0 : c.getBoundingClientRect();
133
- n.push({
134
- pageNumber: i,
135
- pageBasedBoundingRects: a.map((r) => ({
136
- left: r.x,
137
- bottom: r.y + r.height,
138
- width: r.width,
139
- height: r.height
140
- })),
141
- pageDimension: {
142
- width: (t == null ? void 0 : t.width) ?? 0,
143
- height: (t == null ? void 0 : t.height) ?? 0
144
- },
145
- pagePositionInWindow: {
146
- x: (t == null ? void 0 : t.left) ?? 0,
147
- y: (t == null ? void 0 : t.top) ?? 0
148
- }
149
- });
150
- }
151
- n.sort((o, a) => o.pageNumber - a.pageNumber), C({
152
- text: e,
153
- pageSelections: n
154
- });
155
- } else
156
- C && !e && C(null);
157
- }, [C]), v = f(() => {
158
- h.current = null, R.current = null, g.current = !1, y.current = /* @__PURE__ */ new Map(), S.current = "", V((e) => e + 1);
159
- }, []), U = l(P);
160
- _(() => {
161
- P !== U.current && (U.current = P, v());
162
- }, [P, v]);
163
- const W = f(
164
- (e) => y.current.get(e) ?? [],
165
- []
166
- ), H = B(
167
- () => ({
168
- handlePointerDown: X,
169
- handlePointerMove: Y,
170
- handlePointerUp: Z,
171
- getPageSelectionRects: W,
172
- isSelecting: g.current,
173
- selectedText: S.current,
174
- selectionVersion: N,
175
- clearSelection: v
176
- }),
177
- [
178
- X,
179
- Y,
180
- Z,
181
- W,
182
- N,
183
- v
184
- ]
185
- );
186
- return /* @__PURE__ */ J(z.Provider, { value: H, children: G });
187
- };
188
- export {
189
- Fe as TextSelectionProvider,
190
- Ve as useTextSelectionContext
191
- };
@@ -1,14 +0,0 @@
1
- import { FC, PropsWithChildren } from 'react';
2
- import { HighlightRect } from '../utils/selectionUtils';
3
- export interface TextSelectionContextType {
4
- handlePointerDown: (pageIndex: number, e: React.PointerEvent, overlayEl: HTMLElement) => void;
5
- handlePointerMove: (pageIndex: number, e: React.PointerEvent, overlayEl: HTMLElement) => void;
6
- handlePointerUp: () => void;
7
- getPageSelectionRects: (pageIndex: number) => HighlightRect[];
8
- isSelecting: boolean;
9
- selectedText: string;
10
- selectionVersion: number;
11
- clearSelection: () => void;
12
- }
13
- export declare const useTextSelectionContext: () => TextSelectionContextType;
14
- export declare const TextSelectionProvider: FC<PropsWithChildren>;
@@ -1,15 +0,0 @@
1
- import { PageGeometry } from '@pdf-viewer/pdfium';
2
- /**
3
- * LRU cache for PageGeometry objects keyed by page index.
4
- */
5
- export declare class GeometryCache {
6
- private cache;
7
- private readonly maxSize;
8
- constructor(maxSize?: number);
9
- get(pageIndex: number): PageGeometry | undefined;
10
- set(pageIndex: number, geometry: PageGeometry): void;
11
- clear(): void;
12
- get size(): number;
13
- }
14
- /** Shared singleton instance */
15
- export declare const geometryCache: GeometryCache;
@@ -1,12 +0,0 @@
1
- import { PageGeometry } from '@pdf-viewer/pdfium';
2
- export interface HitResult {
3
- runIndex: number;
4
- glyphIndex: number;
5
- charIndex: number;
6
- }
7
- /**
8
- * Two-pass glyph hit-testing:
9
- * 1. Exact match against tight bounds
10
- * 2. Tolerance-expanded match using Manhattan distance
11
- */
12
- export declare function glyphAt(geometry: PageGeometry, x: number, y: number, tolerance?: number): HitResult | null;
@@ -1,30 +0,0 @@
1
- import { PageGeometry } from '@pdf-viewer/pdfium';
2
- export interface CharRange {
3
- start: number;
4
- end: number;
5
- }
6
- export interface HighlightRect {
7
- x: number;
8
- y: number;
9
- width: number;
10
- height: number;
11
- }
12
- /**
13
- * Expand selection to word boundaries.
14
- * Walk backward/forward from charIndex until hitting a space (flags=1) or empty (flags=2) glyph.
15
- */
16
- export declare function expandToWordBoundary(geometry: PageGeometry, charIndex: number): CharRange;
17
- /**
18
- * Expand selection to line boundaries.
19
- * Find all runs that vertically overlap >= 50% with the run containing charIndex.
20
- */
21
- export declare function expandToLineBoundary(geometry: PageGeometry, charIndex: number): CharRange;
22
- /**
23
- * Compute merged highlight rectangles for a character range.
24
- * Adjacent glyphs on the same visual line are merged into single rectangles.
25
- */
26
- export declare function rectsForRange(geometry: PageGeometry, startChar: number, endChar: number): HighlightRect[];
27
- /**
28
- * Extract text from a character range across all runs.
29
- */
30
- export declare function textForRange(geometry: PageGeometry, startChar: number, endChar: number): string;
@@ -1,32 +0,0 @@
1
- var i = Object.defineProperty;
2
- var a = (t, e, c) => e in t ? i(t, e, { enumerable: !0, configurable: !0, writable: !0, value: c }) : t[e] = c;
3
- var h = (t, e, c) => (a(t, typeof e != "symbol" ? e + "" : e, c), c);
4
- class o {
5
- constructor(e = 50) {
6
- h(this, "cache", /* @__PURE__ */ new Map());
7
- h(this, "maxSize");
8
- this.maxSize = e;
9
- }
10
- get(e) {
11
- const c = this.cache.get(e);
12
- return c !== void 0 && (this.cache.delete(e), this.cache.set(e, c)), c;
13
- }
14
- set(e, c) {
15
- if (this.cache.has(e) && this.cache.delete(e), this.cache.size >= this.maxSize) {
16
- const s = this.cache.keys().next().value;
17
- s !== void 0 && this.cache.delete(s);
18
- }
19
- this.cache.set(e, c);
20
- }
21
- clear() {
22
- this.cache.clear();
23
- }
24
- get size() {
25
- return this.cache.size;
26
- }
27
- }
28
- const l = new o();
29
- export {
30
- o as GeometryCache,
31
- l as geometryCache
32
- };
@@ -1,29 +0,0 @@
1
- function x(g, s, i, u = 4) {
2
- let e = 0;
3
- for (let h = 0; h < g.runs.length; h++) {
4
- const l = g.runs[h];
5
- for (let n = 0; n < l.glyphs.length; n++) {
6
- const t = l.glyphs[n];
7
- if (s >= t.tightX && s <= t.tightX + t.tightWidth && i >= t.tightY && i <= t.tightY + t.tightHeight)
8
- return { runIndex: h, glyphIndex: n, charIndex: e + n };
9
- }
10
- e += l.glyphs.length;
11
- }
12
- let c = 1 / 0, o = null;
13
- e = 0;
14
- for (let h = 0; h < g.runs.length; h++) {
15
- const l = g.runs[h];
16
- for (let n = 0; n < l.glyphs.length; n++) {
17
- const t = l.glyphs[n];
18
- if (t.flags === 2)
19
- continue;
20
- const f = t.x + t.width / 2, p = t.y + t.height / 2, d = Math.abs(s - f) + Math.abs(i - p), r = u / 2;
21
- s >= t.x - r && s <= t.x + t.width + r && i >= t.y - r && i <= t.y + t.height + r && d < c && (c = d, o = { runIndex: h, glyphIndex: n, charIndex: e + n });
22
- }
23
- e += l.glyphs.length;
24
- }
25
- return o;
26
- }
27
- export {
28
- x as glyphAt
29
- };
@@ -1,96 +0,0 @@
1
- function M(l) {
2
- const e = [];
3
- for (const h of l.runs)
4
- for (const i of h.glyphs)
5
- e.push(i);
6
- return e;
7
- }
8
- function w(l, e) {
9
- const h = M(l);
10
- if (h.length === 0)
11
- return { start: e, end: e };
12
- const i = Math.max(0, Math.min(e, h.length - 1));
13
- let o = i;
14
- for (; o > 0 && h[o - 1].flags === 0; )
15
- o--;
16
- let r = i;
17
- for (; r < h.length - 1 && h[r + 1].flags === 0; )
18
- r++;
19
- return { start: o, end: r };
20
- }
21
- function R(l, e) {
22
- let h = -1, i = 0;
23
- for (let t = 0; t < l.runs.length; t++) {
24
- const a = l.runs[t].glyphs.length;
25
- if (e < i + a) {
26
- h = t;
27
- break;
28
- }
29
- i += a;
30
- }
31
- if (h === -1)
32
- return { start: e, end: e };
33
- const o = l.runs[h].rect, r = o.height;
34
- let s = 1 / 0, n = -1 / 0, c = 0;
35
- for (let t = 0; t < l.runs.length; t++) {
36
- const a = l.runs[t], g = a.rect, x = Math.max(g.y, o.y), y = Math.min(g.y + g.height, o.y + o.height), p = Math.max(0, y - x), u = Math.min(g.height, r);
37
- if (u > 0 && p / u >= 0.5) {
38
- const f = c, m = c + a.glyphs.length - 1;
39
- f < s && (s = f), m > n && (n = m);
40
- }
41
- c += a.glyphs.length;
42
- }
43
- return s === 1 / 0 ? { start: e, end: e } : { start: s, end: n };
44
- }
45
- function v(l, e, h) {
46
- const i = M(l);
47
- if (i.length === 0)
48
- return [];
49
- const o = Math.max(0, Math.min(e, h)), r = Math.min(i.length - 1, Math.max(e, h)), s = [];
50
- let n = null;
51
- for (let c = o; c <= r; c++) {
52
- const t = i[c];
53
- if (t.flags === 2)
54
- continue;
55
- if (!n) {
56
- n = { x: t.x, y: t.y, width: t.width, height: t.height };
57
- continue;
58
- }
59
- const a = Math.max(n.y, t.y), g = Math.min(
60
- n.y + n.height,
61
- t.y + t.height
62
- ), x = Math.max(0, g - a), y = Math.min(n.height, t.height);
63
- if (y > 0 && x / y >= 0.5) {
64
- const u = Math.min(n.x, t.x), f = Math.min(n.y, t.y), m = Math.max(n.x + n.width, t.x + t.width), d = Math.max(
65
- n.y + n.height,
66
- t.y + t.height
67
- );
68
- n = {
69
- x: u,
70
- y: f,
71
- width: m - u,
72
- height: d - f
73
- };
74
- } else
75
- s.push(n), n = { x: t.x, y: t.y, width: t.width, height: t.height };
76
- }
77
- return n && s.push(n), s;
78
- }
79
- function B(l, e, h) {
80
- const i = Math.min(e, h), o = Math.max(e, h);
81
- let r = "", s = 0;
82
- for (const n of l.runs) {
83
- if (s + n.text.length - 1 >= i && s <= o) {
84
- const t = Math.max(0, i - s), a = Math.min(n.text.length, o - s + 1);
85
- r += n.text.slice(t, a);
86
- }
87
- s += n.glyphs.length;
88
- }
89
- return r;
90
- }
91
- export {
92
- R as expandToLineBoundary,
93
- w as expandToWordBoundary,
94
- v as rectsForRange,
95
- B as textForRange
96
- };