@rightkit/document-core 0.1.1 → 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 (136) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +31 -7
  3. package/dist/app/chrome.js +1 -1
  4. package/dist/app/documentPrinting.d.ts +0 -6
  5. package/dist/app/documentPrinting.js +0 -18
  6. package/dist/app/shell/nativeMenu.d.ts +3 -2
  7. package/dist/app/shell/nativeMenu.js +8 -5
  8. package/dist/documents/perfEventCounters.d.ts +0 -8
  9. package/dist/documents/perfEventCounters.js +2 -1
  10. package/dist/documents/preview/previewFrame.d.ts +2 -1
  11. package/dist/documents/preview/previewFrame.js +9 -7
  12. package/dist/documents/searchUtils.js +1 -1
  13. package/dist/host.d.ts +36 -0
  14. package/dist/host.js +54 -0
  15. package/dist/index.d.ts +1 -50
  16. package/dist/index.js +1 -50
  17. package/dist/settings/themes.js +1 -1
  18. package/dist/state/bridgeEvents.d.ts +1 -1
  19. package/dist/state/bridgeEvents.js +7 -4
  20. package/dist/state/recentUrls.js +4 -3
  21. package/dist/state/tauriBridge.d.ts +3 -61
  22. package/dist/state/tauriBridge.js +8 -297
  23. package/dist/styles.css +2 -2
  24. package/package.json +25 -98
  25. package/dist/app/shortcutChords.d.ts +0 -6
  26. package/dist/app/shortcutChords.js +0 -14
  27. package/dist/app/useCloseFindOnSurfaceChange.d.ts +0 -14
  28. package/dist/app/useCloseFindOnSurfaceChange.js +0 -23
  29. package/dist/app/useEditText.d.ts +0 -6
  30. package/dist/app/useEditText.js +0 -10
  31. package/dist/appName.d.ts +0 -2
  32. package/dist/appName.js +0 -8
  33. package/dist/documents/FullscreenIcon.d.ts +0 -4
  34. package/dist/documents/FullscreenIcon.js +0 -7
  35. package/dist/documents/mdx/mdxRuntimeScript.d.ts +0 -2
  36. package/dist/documents/mdx/mdxRuntimeScript.js +0 -3
  37. package/dist/documents/mdx/mdxRuntimeScript.txt +0 -584
  38. package/dist/documents/pdf/MacPdfReadPane.d.ts +0 -23
  39. package/dist/documents/pdf/MacPdfReadPane.js +0 -708
  40. package/dist/documents/pdf/NativePdfDocument.d.ts +0 -9
  41. package/dist/documents/pdf/NativePdfDocument.js +0 -41
  42. package/dist/documents/pdf/PdfInlineTextEditor.d.ts +0 -53
  43. package/dist/documents/pdf/PdfInlineTextEditor.js +0 -225
  44. package/dist/documents/pdf/PdfOcrLayer.d.ts +0 -4
  45. package/dist/documents/pdf/PdfOcrLayer.js +0 -30
  46. package/dist/documents/pdf/PdfOutline.d.ts +0 -6
  47. package/dist/documents/pdf/PdfOutline.js +0 -12
  48. package/dist/documents/pdf/PdfPasswordPrompt.d.ts +0 -5
  49. package/dist/documents/pdf/PdfPasswordPrompt.js +0 -24
  50. package/dist/documents/pdf/PdfThumbnails.d.ts +0 -8
  51. package/dist/documents/pdf/PdfThumbnails.js +0 -201
  52. package/dist/documents/pdf/PdfToolbar.d.ts +0 -47
  53. package/dist/documents/pdf/PdfToolbar.js +0 -76
  54. package/dist/documents/pdf/PdfViewer.d.ts +0 -36
  55. package/dist/documents/pdf/PdfViewer.js +0 -1522
  56. package/dist/documents/pdf/PdfViewerBody.d.ts +0 -22
  57. package/dist/documents/pdf/PdfViewerBody.js +0 -42
  58. package/dist/documents/pdf/macPdfNativeBridge.d.ts +0 -118
  59. package/dist/documents/pdf/macPdfNativeBridge.js +0 -134
  60. package/dist/documents/pdf/nearestVisiblePdfPage.d.ts +0 -2
  61. package/dist/documents/pdf/nearestVisiblePdfPage.js +0 -22
  62. package/dist/documents/pdf/pdfBench.d.ts +0 -88
  63. package/dist/documents/pdf/pdfBench.js +0 -535
  64. package/dist/documents/pdf/pdfBenchAutopilot.d.ts +0 -48
  65. package/dist/documents/pdf/pdfBenchAutopilot.js +0 -154
  66. package/dist/documents/pdf/pdfBenchTransport.d.ts +0 -21
  67. package/dist/documents/pdf/pdfBenchTransport.js +0 -233
  68. package/dist/documents/pdf/pdfEditModel.d.ts +0 -294
  69. package/dist/documents/pdf/pdfEditModel.js +0 -105
  70. package/dist/documents/pdf/pdfEditor.d.ts +0 -100
  71. package/dist/documents/pdf/pdfEditor.js +0 -68
  72. package/dist/documents/pdf/pdfOcr.d.ts +0 -36
  73. package/dist/documents/pdf/pdfOcr.js +0 -88
  74. package/dist/documents/pdf/pdfOcrEdit.d.ts +0 -32
  75. package/dist/documents/pdf/pdfOcrEdit.js +0 -138
  76. package/dist/documents/pdf/pdfPrinting.d.ts +0 -28
  77. package/dist/documents/pdf/pdfPrinting.js +0 -110
  78. package/dist/documents/pdf/pdfSave.d.ts +0 -87
  79. package/dist/documents/pdf/pdfSave.js +0 -250
  80. package/dist/documents/pdf/pdfShared.d.ts +0 -16
  81. package/dist/documents/pdf/pdfShared.js +0 -20
  82. package/dist/documents/pdf/pdfToMarkdown.d.ts +0 -11
  83. package/dist/documents/pdf/pdfToMarkdown.js +0 -67
  84. package/dist/documents/pdf/pdfjsLibGlobal.d.ts +0 -1
  85. package/dist/documents/pdf/pdfjsLibGlobal.js +0 -12
  86. package/dist/documents/pdf/toolbarIcons.d.ts +0 -18
  87. package/dist/documents/pdf/toolbarIcons.js +0 -31
  88. package/dist/documents/pdf/usePdfDocumentLoader.d.ts +0 -40
  89. package/dist/documents/pdf/usePdfDocumentLoader.js +0 -243
  90. package/dist/documents/pdf/usePdfEditSession.d.ts +0 -88
  91. package/dist/documents/pdf/usePdfEditSession.js +0 -341
  92. package/dist/documents/pdf/usePdfEditor.d.ts +0 -59
  93. package/dist/documents/pdf/usePdfEditor.js +0 -317
  94. package/dist/documents/pdf/usePdfFit.d.ts +0 -19
  95. package/dist/documents/pdf/usePdfFit.js +0 -55
  96. package/dist/documents/pdf/usePdfOcr.d.ts +0 -38
  97. package/dist/documents/pdf/usePdfOcr.js +0 -337
  98. package/dist/documents/pdf/usePdfPreviewRecompose.d.ts +0 -28
  99. package/dist/documents/pdf/usePdfPreviewRecompose.js +0 -256
  100. package/dist/documents/pdf/usePdfSavePlan.d.ts +0 -61
  101. package/dist/documents/pdf/usePdfSavePlan.js +0 -303
  102. package/dist/documents/pdf/usePdfSearch.d.ts +0 -31
  103. package/dist/documents/pdf/usePdfSearch.js +0 -367
  104. package/dist/documents/pdf/usePdfViewControls.d.ts +0 -72
  105. package/dist/documents/pdf/usePdfViewControls.js +0 -152
  106. package/dist/documents/scopedSelectAll.d.ts +0 -5
  107. package/dist/documents/scopedSelectAll.js +0 -77
  108. package/dist/documents/txt/cmScroll.d.ts +0 -11
  109. package/dist/documents/txt/cmScroll.js +0 -52
  110. package/dist/documents/useMirroredEditText.d.ts +0 -15
  111. package/dist/documents/useMirroredEditText.js +0 -29
  112. package/dist/documents/useSplitResize.d.ts +0 -7
  113. package/dist/documents/useSplitResize.js +0 -37
  114. package/dist/settings/rk-settings.css +0 -38
  115. package/dist/settings/sections/EditorSection.d.ts +0 -1
  116. package/dist/settings/sections/EditorSection.js +0 -18
  117. package/dist/settings/sections/FileAssociationsSection.d.ts +0 -1
  118. package/dist/settings/sections/FileAssociationsSection.js +0 -5
  119. package/dist/settings/sections/MacFileAssociationsBlock.d.ts +0 -33
  120. package/dist/settings/sections/MacFileAssociationsBlock.js +0 -151
  121. package/dist/settings/sections/ThemeSection.d.ts +0 -1
  122. package/dist/settings/sections/ThemeSection.js +0 -31
  123. package/dist/settings/sections/TypographySection.d.ts +0 -1
  124. package/dist/settings/sections/TypographySection.js +0 -19
  125. package/dist/settings/sections/onOff.d.ts +0 -11
  126. package/dist/settings/sections/onOff.js +0 -8
  127. package/dist/state/browserQa.d.ts +0 -21
  128. package/dist/state/browserQa.js +0 -303
  129. package/dist/state/browserQaDocx.d.ts +0 -3
  130. package/dist/state/browserQaDocx.js +0 -35
  131. package/dist/state/browserQaLicense.d.ts +0 -8
  132. package/dist/state/browserQaLicense.js +0 -7
  133. package/dist/state/browserQaPdf.d.ts +0 -60
  134. package/dist/state/browserQaPdf.js +0 -302
  135. package/dist/state/browserQaText.d.ts +0 -6
  136. package/dist/state/browserQaText.js +0 -48
@@ -1,584 +0,0 @@
1
- (() => {
2
- const sessionId = "__VR_SESSION_ID__";
3
- const parentTarget = "*";
4
- const compiledType = "__VR_MDX_COMPILED__";
5
- const linkType = "__VR_MDX_LINK__";
6
- const runtimeErrorType = "__VR_MDX_RUNTIME_ERROR__";
7
- const heightType = "__VR_MDX_HEIGHT__";
8
- const findOpenType = "__VR_MDX_FIND_OPEN__";
9
- const findType = "__VR_MDX_FIND__";
10
- const stepType = "__VR_MDX_FIND_STEP__";
11
- const clearType = "__VR_MDX_FIND_CLEAR__";
12
- const resultType = "__VR_MDX_FIND_RESULT__";
13
- const printType = "__VR_MDX_PRINT__";
14
- const printContentType = "__VR_MDX_PRINT_CONTENT__";
15
- const themeType = "__VR_MDX_THEME__";
16
-
17
- const MARK_CLASS = "__vr_find";
18
- const ACTIVE_CLASS = "__vr_find_active";
19
- const Fragment = Symbol("vr-mdx-fragment");
20
- let rootEl = null;
21
- let entryId = null;
22
- let moduleGraph = {};
23
- const moduleCache = new Map();
24
-
25
- function jsx(type, props, key) {
26
- const nextProps = props ? {...props} : {};
27
- if (key !== undefined) nextProps.key = key;
28
- return {__vrVNode: true, type, props: nextProps};
29
- }
30
-
31
- const jsxs = jsx;
32
- const jsxDEV = jsx;
33
-
34
- function createElement(type, props, ...children) {
35
- const nextProps = props ? {...props} : {};
36
- if (children.length === 1) nextProps.children = children[0];
37
- else if (children.length > 1) nextProps.children = children;
38
- return {__vrVNode: true, type, props: nextProps};
39
- }
40
-
41
- function postRuntimeError(err, fallbackName) {
42
- parent.postMessage(
43
- {
44
- type: runtimeErrorType,
45
- sessionId,
46
- name: err && err.name ? err.name : fallbackName,
47
- message: err && err.message ? err.message : String(err),
48
- stack: err && err.stack ? err.stack : undefined,
49
- },
50
- parentTarget,
51
- );
52
- }
53
-
54
- function normalizeChildren(value) {
55
- if (value == null || value === false || value === true) return [];
56
- return Array.isArray(value) ? value.flatMap(normalizeChildren) : [value];
57
- }
58
-
59
- function appendChildren(target, children) {
60
- for (const child of normalizeChildren(children)) {
61
- target.appendChild(renderNode(child));
62
- }
63
- }
64
-
65
- function styleObjectToCssText(style) {
66
- return Object.entries(style)
67
- .map(([key, value]) => {
68
- const cssKey = key.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
69
- return value == null ? "" : cssKey + ":" + String(value);
70
- })
71
- .filter(Boolean)
72
- .join(";");
73
- }
74
-
75
- function applyProps(el, props) {
76
- for (const [name, value] of Object.entries(props || {})) {
77
- if (name === "children" || name === "key" || value == null || value === false) continue;
78
- if (name === "className") {
79
- el.setAttribute("class", String(value));
80
- continue;
81
- }
82
- if (name === "htmlFor") {
83
- el.setAttribute("for", String(value));
84
- continue;
85
- }
86
- if (name === "style" && typeof value === "object") {
87
- el.setAttribute("style", styleObjectToCssText(value));
88
- continue;
89
- }
90
- if (name === "dangerouslySetInnerHTML" && value && typeof value === "object" && "__html" in value) {
91
- el.innerHTML = String(value.__html || "");
92
- continue;
93
- }
94
- if (name.startsWith("on") && typeof value === "function") {
95
- el.addEventListener(name.slice(2).toLowerCase(), (event) => {
96
- try {
97
- value(event);
98
- } catch (err) {
99
- postRuntimeError(err, "EventHandlerError");
100
- }
101
- });
102
- continue;
103
- }
104
- if (value === true) {
105
- el.setAttribute(name, "");
106
- continue;
107
- }
108
- el.setAttribute(name, String(value));
109
- }
110
- }
111
-
112
- function renderNode(node) {
113
- if (node == null || node === false || node === true) return document.createComment("");
114
- if (Array.isArray(node)) {
115
- const frag = document.createDocumentFragment();
116
- appendChildren(frag, node);
117
- return frag;
118
- }
119
- if (typeof node === "string" || typeof node === "number") {
120
- return document.createTextNode(String(node));
121
- }
122
- if (!node || typeof node !== "object" || !node.__vrVNode) {
123
- return document.createTextNode(String(node));
124
- }
125
-
126
- const props = node.props || {};
127
- if (node.type === Fragment) {
128
- const frag = document.createDocumentFragment();
129
- appendChildren(frag, props.children);
130
- return frag;
131
- }
132
-
133
- if (typeof node.type === "function") {
134
- return renderNode(node.type(props));
135
- }
136
-
137
- if (typeof node.type !== "string") {
138
- throw new Error("Unknown component type in MDX preview.");
139
- }
140
-
141
- const el = document.createElement(node.type);
142
- applyProps(el, props);
143
- if (!(props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML === "object")) {
144
- appendChildren(el, props.children);
145
- }
146
- return el;
147
- }
148
-
149
- function calloutTone(type) {
150
- switch (String(type || "NOTE").toUpperCase()) {
151
- case "TIP":
152
- case "IMPORTANT":
153
- return "#0c6aa5";
154
- case "WARNING":
155
- return "#d97706";
156
- case "CAUTION":
157
- return "#dc2626";
158
- default:
159
- return "#64748b";
160
- }
161
- }
162
-
163
- function builtins() {
164
- return {
165
- Callout(props) {
166
- const kind = String(props.type || "NOTE").toUpperCase();
167
- const title = props.title || kind;
168
- const tone = calloutTone(kind);
169
- return jsxs("aside", {
170
- className: "vr-mdx-callout",
171
- style: {borderLeft: "4px solid " + tone},
172
- children: [
173
- jsx("div", {className: "vr-mdx-label", children: title}),
174
- jsx("div", {children: props.children}),
175
- ],
176
- });
177
- },
178
- Stepper(props) {
179
- return jsx("ol", {className: "vr-mdx-stepper", children: props.children});
180
- },
181
- Comparison(props) {
182
- return jsx("div", {className: "vr-mdx-grid", children: props.children});
183
- },
184
- Faq(props) {
185
- return jsx("div", {className: "vr-mdx-faq", children: props.children});
186
- },
187
- RichTable(props) {
188
- return jsx("div", {className: "vr-mdx-table-wrap", children: props.children});
189
- },
190
- Frontmatter(props) {
191
- if (props.data && typeof props.data === "object") {
192
- const rows = Object.entries(props.data);
193
- return jsx("dl", {
194
- className: "vr-mdx-frontmatter",
195
- children: rows.map(([key, value]) =>
196
- jsxs(Fragment, {
197
- children: [
198
- jsx("dt", {children: key}),
199
- jsx("dd", {children: typeof value === "string" ? value : JSON.stringify(value)}),
200
- ],
201
- }),
202
- ),
203
- });
204
- }
205
- return jsx("div", {className: "vr-mdx-frontmatter", children: props.children});
206
- },
207
- CodeBlock(props) {
208
- const lang = props.lang || props.language || "text";
209
- const code = props.code || props.children || "";
210
- return jsxs("div", {
211
- className: "vr-mdx-code",
212
- children: [
213
- jsx("div", {className: "vr-mdx-code-label", children: lang}),
214
- jsx("pre", {children: jsx("code", {children: typeof code === "string" ? code : String(code)})}),
215
- ],
216
- });
217
- },
218
- MermaidBlock(props) {
219
- const code = props.code || props.children || "";
220
- return jsxs("pre", {
221
- className: "vr-mdx-code",
222
- children: [
223
- jsx("div", {className: "vr-mdx-code-label", children: "mermaid"}),
224
- jsx("code", {children: typeof code === "string" ? code : String(code)}),
225
- ],
226
- });
227
- },
228
- Math(props) {
229
- const value = props.value || props.children || "";
230
- return props.display
231
- ? jsx("pre", {className: "vr-mdx-math-block", children: String(value)})
232
- : jsx("code", {className: "vr-mdx-math-inline", children: String(value)});
233
- },
234
- };
235
- }
236
-
237
- function resolveModuleId(spec, parentId) {
238
- if (typeof spec !== "string") throw new Error("MDX import specifier must be a string.");
239
- if (/^https:\/\/viewright\.invalid\//i.test(spec)) return spec;
240
- if (/^[a-z][a-z0-9+.-]*:/i.test(spec)) {
241
- throw new Error("Blocked external module import: " + spec);
242
- }
243
- return new URL(spec, parentId).href;
244
- }
245
-
246
- function loadModule(spec, parentId) {
247
- const moduleId = parentId ? resolveModuleId(spec, parentId) : spec;
248
- const cached = moduleCache.get(moduleId);
249
- if (cached) return cached.exports;
250
- const record = moduleGraph[moduleId];
251
- if (!record) throw new Error("Missing contained MDX module: " + moduleId);
252
-
253
- if (record.kind === "cjs") {
254
- const module = {exports: {}};
255
- moduleCache.set(moduleId, module);
256
- try {
257
- const require = (childSpec) => loadModule(childSpec, moduleId);
258
- const factory = new Function(
259
- "exports",
260
- "module",
261
- "require",
262
- "createElement",
263
- "Fragment",
264
- "jsx",
265
- "jsxs",
266
- "jsxDEV",
267
- record.code,
268
- );
269
- factory(
270
- module.exports,
271
- module,
272
- require,
273
- createElement,
274
- Fragment,
275
- jsx,
276
- jsxs,
277
- jsxDEV,
278
- );
279
- return module.exports;
280
- } catch (err) {
281
- moduleCache.delete(moduleId);
282
- throw err;
283
- }
284
- }
285
-
286
- const module = {exports: {}};
287
- moduleCache.set(moduleId, module);
288
- try {
289
- const require = (childSpec) => loadModule(childSpec, moduleId);
290
- const factory = new Function(record.code);
291
- module.exports = factory(
292
- {Fragment, jsx, jsxs, jsxDEV},
293
- require,
294
- );
295
- return module.exports;
296
- } catch (err) {
297
- moduleCache.delete(moduleId);
298
- throw err;
299
- }
300
- }
301
-
302
- function renderEntry() {
303
- if (!rootEl) rootEl = document.getElementById("root");
304
- if (!rootEl || !entryId) return;
305
- const mod = loadModule(entryId, null);
306
- const Content = mod && (mod.default || mod.MDXContent);
307
- if (typeof Content !== "function") {
308
- throw new Error("Compiled MDX did not export a default component.");
309
- }
310
- const tree = jsx(Content, {components: builtins()});
311
- rootEl.replaceChildren(renderNode(tree));
312
- reportHeight();
313
- }
314
-
315
- function injectMarkStyle() {
316
- if (document.getElementById("__vr_find_style__")) return;
317
- const s = document.createElement("style");
318
- s.id = "__vr_find_style__";
319
- s.textContent =
320
- "." + MARK_CLASS + "{background-color:rgba(12,106,165,.40);border-radius:2px;}" +
321
- "." + ACTIVE_CLASS + "{background-color:#0c6aa5;color:#fff;border-radius:2px;}";
322
- document.head.appendChild(s);
323
- }
324
-
325
- let matches = [];
326
- let markGroups = [];
327
- let nodeIndex = [];
328
- let active = -1;
329
-
330
- const isWordChar = (ch) => !!ch && /[\p{L}\p{N}_]/u.test(ch);
331
-
332
- function buildIndex() {
333
- nodeIndex = [];
334
- const root = document.body || document.documentElement;
335
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
336
- acceptNode(n) {
337
- const p = n.parentNode;
338
- if (!p) return NodeFilter.FILTER_REJECT;
339
- const tag = p.nodeName;
340
- if (tag === "SCRIPT" || tag === "STYLE" || tag === "NOSCRIPT" || tag === "TITLE") return NodeFilter.FILTER_REJECT;
341
- if (!n.nodeValue || n.nodeValue.length === 0) return NodeFilter.FILTER_REJECT;
342
- return NodeFilter.FILTER_ACCEPT;
343
- },
344
- });
345
- let offset = 0;
346
- let text = "";
347
- let n;
348
- while ((n = walker.nextNode())) {
349
- const value = n.nodeValue || "";
350
- const len = value.length;
351
- nodeIndex.push({node: n, start: offset, end: offset + len});
352
- offset += len;
353
- text += value;
354
- }
355
- return text;
356
- }
357
-
358
- function compute(text, q, opts) {
359
- if (!q) return [];
360
- const matchCase = !!opts.matchCase;
361
- const wholeWord = !!opts.wholeWord;
362
- const haystack = matchCase ? text : text.toLocaleLowerCase();
363
- const needle = matchCase ? q : q.toLocaleLowerCase();
364
- const out = [];
365
- let pos = haystack.indexOf(needle);
366
- while (pos !== -1) {
367
- const end = pos + q.length;
368
- const before = text[pos - 1];
369
- const after = text[end];
370
- if (!wholeWord || (!isWordChar(before) && !isWordChar(after))) out.push({start: pos, end});
371
- pos = haystack.indexOf(needle, pos + Math.max(1, needle.length));
372
- }
373
- return out;
374
- }
375
-
376
- function clearMarks() {
377
- for (const grp of markGroups) {
378
- for (const span of grp) {
379
- const parent = span.parentNode;
380
- if (!parent) continue;
381
- while (span.firstChild) parent.insertBefore(span.firstChild, span);
382
- parent.removeChild(span);
383
- parent.normalize();
384
- }
385
- }
386
- markGroups = [];
387
- }
388
-
389
- function wrapRange(start, end) {
390
- const groups = [];
391
- for (let i = nodeIndex.length - 1; i >= 0; i--) {
392
- const seg = nodeIndex[i];
393
- if (seg.end <= start || seg.start >= end) continue;
394
- const ls = Math.max(0, start - seg.start);
395
- const le = Math.min(seg.node.nodeValue.length, end - seg.start);
396
- let node = seg.node;
397
- if (seg.node.nodeValue.length > le) node.splitText(le);
398
- if (ls > 0) node = node.splitText(ls);
399
- const span = document.createElement("span");
400
- span.className = MARK_CLASS;
401
- const parent = node.parentNode;
402
- parent.insertBefore(span, node);
403
- span.appendChild(node);
404
- groups.unshift(span);
405
- }
406
- return groups;
407
- }
408
-
409
- function setActive(idx) {
410
- for (let g = 0; g < markGroups.length; g++) {
411
- for (const span of markGroups[g]) {
412
- span.className = g === idx ? MARK_CLASS + " " + ACTIVE_CLASS : MARK_CLASS;
413
- }
414
- }
415
- if (idx >= 0 && markGroups[idx] && markGroups[idx][0] && markGroups[idx][0].scrollIntoView) {
416
- markGroups[idx][0].scrollIntoView({block: "center"});
417
- }
418
- }
419
-
420
- function applyMatches() {
421
- injectMarkStyle();
422
- markGroups = matches.map((m) => wrapRange(m.start, m.end));
423
- if (active >= 0) setActive(active);
424
- }
425
-
426
- function respond(requestId) {
427
- parent.postMessage(
428
- {type: resultType, sessionId, requestId, count: matches.length, activeIndex: active},
429
- parentTarget,
430
- );
431
- }
432
-
433
- function anchorFrom(event) {
434
- return event.target && event.target.closest ? event.target.closest("a[href]") : null;
435
- }
436
-
437
- document.addEventListener(
438
- "click",
439
- (event) => {
440
- if (event.defaultPrevented || event.button !== 0) return;
441
- const anchor = anchorFrom(event);
442
- if (!anchor) return;
443
- const href = anchor.getAttribute("href") || "";
444
- if (!href) return;
445
- if (href.charAt(0) === "#") {
446
- event.preventDefault();
447
- const id = decodeURIComponent(href.slice(1));
448
- if (!id) {
449
- window.scrollTo({top: 0});
450
- return;
451
- }
452
- let target = document.getElementById(id);
453
- if (!target) {
454
- try {
455
- target = document.querySelector('[name="' + (window.CSS && CSS.escape ? CSS.escape(id) : id) + '"]');
456
- } catch (_) {
457
- target = null;
458
- }
459
- }
460
- if (target && target.scrollIntoView) target.scrollIntoView();
461
- return;
462
- }
463
- event.preventDefault();
464
- parent.postMessage({type: linkType, sessionId, href, newTab: !!(event.metaKey || event.ctrlKey)}, parentTarget);
465
- },
466
- true,
467
- );
468
-
469
- window.addEventListener(
470
- "keydown",
471
- (e) => {
472
- if ((e.ctrlKey || e.metaKey) && !e.altKey && (e.key || "").toLowerCase() === "f") {
473
- e.preventDefault();
474
- parent.postMessage({type: findOpenType, sessionId}, parentTarget);
475
- }
476
- },
477
- true,
478
- );
479
-
480
- let lastReportedHeight = -1;
481
- function reportHeight() {
482
- const h = Math.max(
483
- document.documentElement.scrollHeight,
484
- document.body ? document.body.scrollHeight : 0,
485
- );
486
- if (h === lastReportedHeight) return; // unchanged — don't wake the parent for nothing
487
- lastReportedHeight = h;
488
- parent.postMessage({type: heightType, sessionId, height: h}, parentTarget);
489
- }
490
-
491
- if (typeof ResizeObserver !== "undefined" && document.documentElement) {
492
- const observer = new ResizeObserver(reportHeight);
493
- observer.observe(document.documentElement);
494
- window.addEventListener("pagehide", () => observer.disconnect());
495
- } else {
496
- // Fallback for engines without ResizeObserver. Poll once a second until the height has been
497
- // unchanged for three ticks, then stop; pagehide clears it too. Never a forever-interval.
498
- window.addEventListener("load", reportHeight);
499
- let stableTicks = 0;
500
- const poll = setInterval(() => {
501
- const before = lastReportedHeight;
502
- reportHeight();
503
- stableTicks = lastReportedHeight === before ? stableTicks + 1 : 0;
504
- if (stableTicks >= 3) clearInterval(poll);
505
- }, 1000);
506
- window.addEventListener("pagehide", () => clearInterval(poll));
507
- }
508
-
509
- // Parent-resolved app theme colors arrive as --vr-* custom properties. Only well-formed names
510
- // are applied, so a malformed message cannot inject arbitrary CSS.
511
- function applyTheme(vars) {
512
- const root = document.documentElement;
513
- for (const name of Object.keys(vars)) {
514
- if (/^--vr-[a-z-]+$/.test(name) && typeof vars[name] === "string") {
515
- root.style.setProperty(name, vars[name]);
516
- }
517
- }
518
- }
519
-
520
- window.addEventListener("message", (event) => {
521
- if (event.source !== parent) return;
522
- const data = event.data;
523
- if (!data || data.sessionId !== sessionId) return;
524
- switch (data.type) {
525
- case compiledType:
526
- if (typeof data.entryId === "string" && data.modules && typeof data.modules === "object") {
527
- try {
528
- entryId = data.entryId;
529
- moduleGraph = data.modules;
530
- moduleCache.clear();
531
- renderEntry();
532
- } catch (err) {
533
- if (!rootEl) rootEl = document.getElementById("root");
534
- if (rootEl) {
535
- rootEl.replaceChildren(
536
- renderNode(
537
- jsx("pre", {
538
- className: "vr-mdx-runtime-error",
539
- "data-vr-runtime-error": "1",
540
- children: err && err.message ? err.message : String(err),
541
- }),
542
- ),
543
- );
544
- }
545
- postRuntimeError(err, "MdxRuntimeError");
546
- }
547
- }
548
- break;
549
- case themeType:
550
- if (data.vars && typeof data.vars === "object") applyTheme(data.vars);
551
- break;
552
- case findType: {
553
- clearMarks();
554
- const text = buildIndex();
555
- matches = compute(text, data.query || "", {matchCase: !!data.matchCase, wholeWord: !!data.wholeWord});
556
- active = matches.length ? 0 : -1;
557
- applyMatches();
558
- respond(data.requestId);
559
- break;
560
- }
561
- case stepType: {
562
- const n = matches.length;
563
- const next = n ? (((active + (data.delta | 0)) % n) + n) % n : -1;
564
- active = next;
565
- setActive(active);
566
- respond(data.requestId);
567
- break;
568
- }
569
- case clearType:
570
- clearMarks();
571
- matches = [];
572
- active = -1;
573
- break;
574
- case printType:
575
- // Don't print this frame directly: it's pinned to the on-screen content-pane box, so
576
- // window.print() here would paginate against that fixed viewport, not the document's full
577
- // height. Send the rendered markup back to the parent, which prints it in-flow.
578
- try {
579
- parent.postMessage({ type: printContentType, sessionId: sessionId, html: document.documentElement.outerHTML }, parentTarget);
580
- } catch (e) {}
581
- break;
582
- }
583
- });
584
- })();
@@ -1,23 +0,0 @@
1
- import { type ReactNode } from "react";
2
- import type { SearchProvider, ViewMeta } from "../types.js";
3
- import { type NativePdfEditingAction } from "./macPdfNativeBridge.js";
4
- export type { NativePdfEditingAction } from "./macPdfNativeBridge.js";
5
- export interface MacPdfReadPaneProps {
6
- documentPath: string;
7
- url?: string;
8
- active?: boolean;
9
- initialView?: ViewMeta;
10
- onViewState?: (view: ViewMeta) => void;
11
- registerPrint?: (fn: (() => Promise<boolean>) | null) => void;
12
- registerSearchProvider?: (provider: SearchProvider | null) => void;
13
- findBar?: ReactNode;
14
- findMode?: "find" | "replace";
15
- onRequestFind?: () => void;
16
- onRequestReplace?: () => void;
17
- onRequestEditing: (action: NativePdfEditingAction, view: ViewMeta) => void;
18
- onRequestFallback: (error: Error) => void;
19
- /** Wave 2 Read mode — hides every markup affordance in the shared PdfToolbar. */
20
- readOnly?: boolean;
21
- }
22
- export declare function MacPdfReadPane({ documentPath, active, initialView, onViewState, registerPrint, registerSearchProvider, findBar, findMode, onRequestFind, onRequestReplace, onRequestEditing, onRequestFallback, readOnly, }: MacPdfReadPaneProps): import("react").JSX.Element;
23
- export default MacPdfReadPane;