@krizaka/ui 3.15.0 → 3.16.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/README.md +1 -0
- package/dist/document-viewer.d.ts +200 -0
- package/dist/document-viewer.js +248 -0
- package/dist/document-viewer.js.map +1 -0
- package/package.json +25 -6
- package/registry/achievement.json +1 -1
- package/registry/action-bar.json +1 -1
- package/registry/activity-feed.json +1 -1
- package/registry/alert.json +1 -1
- package/registry/app-shell.json +1 -1
- package/registry/argument-card.json +1 -1
- package/registry/audio-player.json +1 -1
- package/registry/auth-layout.json +1 -1
- package/registry/avatar.json +1 -1
- package/registry/badge.json +1 -1
- package/registry/button.json +1 -1
- package/registry/card-grid.json +1 -1
- package/registry/card.json +1 -1
- package/registry/catalogue-page.json +1 -1
- package/registry/changelog-page.json +1 -1
- package/registry/chat.json +1 -1
- package/registry/checkbox.json +1 -1
- package/registry/chip-link.json +1 -1
- package/registry/chip.json +1 -1
- package/registry/choice-grid.json +1 -1
- package/registry/code-block.json +1 -1
- package/registry/combobox.json +1 -1
- package/registry/command.json +1 -1
- package/registry/component-page.json +1 -1
- package/registry/confirm-button.json +1 -1
- package/registry/contact-page.json +1 -1
- package/registry/continue-prompt.json +1 -1
- package/registry/countdown.json +1 -1
- package/registry/cta-panel.json +1 -1
- package/registry/dashboard-layout.json +1 -1
- package/registry/data-table.json +1 -1
- package/registry/date-picker.json +1 -1
- package/registry/decision-list.json +1 -1
- package/registry/description-list.json +1 -1
- package/registry/detail-layout.json +1 -1
- package/registry/dialog.json +1 -1
- package/registry/docs-article-page.json +1 -1
- package/registry/docs-hub-page.json +1 -1
- package/registry/docs-layout.json +1 -1
- package/registry/document-viewer.json +232 -0
- package/registry/dropdown-menu.json +1 -1
- package/registry/empty-state.json +1 -1
- package/registry/error-page.json +1 -1
- package/registry/examples/document-viewer/highlights.d.ts +4 -0
- package/registry/examples/document-viewer/highlights.js +27 -0
- package/registry/examples/document-viewer/highlights.tsx +30 -0
- package/registry/field.json +1 -1
- package/registry/file-upload.json +1 -1
- package/registry/filter-bar.json +1 -1
- package/registry/form.json +1 -1
- package/registry/gallery-page.json +1 -1
- package/registry/glow-card.json +1 -1
- package/registry/goal-gauge.json +1 -1
- package/registry/how-it-works-page.json +1 -1
- package/registry/image-cropper.json +1 -1
- package/registry/index.json +22 -4
- package/registry/iso.json +1 -1
- package/registry/kanban.json +1 -1
- package/registry/kbd.json +1 -1
- package/registry/landing-page.json +1 -1
- package/registry/landscape.json +1 -1
- package/registry/legal-page.json +1 -1
- package/registry/link-card.json +1 -1
- package/registry/list.json +1 -1
- package/registry/loader.json +1 -1
- package/registry/longform-page.json +1 -1
- package/registry/map.json +2 -2
- package/registry/markdown.json +1 -1
- package/registry/marketing-layout.json +1 -1
- package/registry/marquee.json +1 -1
- package/registry/mascot-quote.json +1 -1
- package/registry/mascot-state.json +1 -1
- package/registry/mascots.json +1 -1
- package/registry/match-dialog.json +1 -1
- package/registry/media-capture.json +1 -1
- package/registry/meter.json +1 -1
- package/registry/nav-bar.json +2 -2
- package/registry/number-ticker.json +1 -1
- package/registry/page-header.json +1 -1
- package/registry/page-hero.json +1 -1
- package/registry/page.json +1 -1
- package/registry/pagination.json +1 -1
- package/registry/photo-grid.json +1 -1
- package/registry/pointer-light.json +1 -1
- package/registry/popover.json +1 -1
- package/registry/pricing-page.json +1 -1
- package/registry/product-page.json +1 -1
- package/registry/profile-card.json +1 -1
- package/registry/progress.json +1 -1
- package/registry/promise-card.json +1 -1
- package/registry/radio-group.json +1 -1
- package/registry/recipes.json +1 -1
- package/registry/scroll-stage.json +1 -1
- package/registry/search-field.json +1 -1
- package/registry/section-backdrop.json +1 -1
- package/registry/separator.json +1 -1
- package/registry/settings-layout.json +1 -1
- package/registry/showcase.json +1 -1
- package/registry/site-footer.json +2 -2
- package/registry/sites.json +1 -1
- package/registry/skeleton.json +1 -1
- package/registry/skip-link.json +1 -1
- package/registry/slider.json +1 -1
- package/registry/slot.json +1 -1
- package/registry/spinner.json +1 -1
- package/registry/split-view.json +1 -1
- package/registry/stage-banner.json +1 -1
- package/registry/stat.json +1 -1
- package/registry/status-page.json +1 -1
- package/registry/step-progress.json +1 -1
- package/registry/stepper.json +1 -1
- package/registry/swipe-deck.json +1 -1
- package/registry/switch.json +1 -1
- package/registry/tabs.json +1 -1
- package/registry/tag-input.json +1 -1
- package/registry/tag-selector.json +1 -1
- package/registry/terminal-replay.json +1 -1
- package/registry/theme.json +1 -1
- package/registry/toast.json +1 -1
- package/registry/toc.json +1 -1
- package/registry/tooltip.json +1 -1
- package/registry/tree-view.json +1 -1
- package/registry/verified-badge.json +1 -1
- package/registry/vertical-video.json +1 -1
- package/registry/video-player.json +1 -1
- package/registry/video-trimmer.json +1 -1
- package/registry/virtual.json +1 -1
package/README.md
CHANGED
|
@@ -192,6 +192,7 @@ light or a product's — is a set of tokens.
|
|
|
192
192
|
| `@krizaka/ui/video-trimmer` | `VideoTrimmer` (`duration`, `value` [start, end], `minLength`, `step`/`largeStep`, `frames` or children, `time` + `onSeek`, `classNames` per part, `renderHandle`) | client |
|
|
193
193
|
| `@krizaka/ui/audio-player` | `AudioPlayer` (a seekable waveform: `peaks` or `computePeaks`, `bars`, `playbackRates`, `duration`), `resamplePeaks`, `computeAudioPeaks` | client |
|
|
194
194
|
| `@krizaka/ui/image-cropper` | `ImageCropper` (`aspect`, `round`, an image or a `<video>`, a focus point + zoom out, keyboard and zoom slider), `cropRect` | client |
|
|
195
|
+
| `@krizaka/ui/document-viewer` | `DocumentViewer` (a PDF drawn by pdf.js — `loadPdfjs={() => import("pdfjs-dist")}`, an optional peer — with `highlights` lit where their quotes sit, `activeId` / `onActiveChange`, `onLocate`; page + quote when the text layer cannot place one), `locateQuote` | client |
|
|
195
196
|
| `@krizaka/ui/page` | the page frame: `Page` (`size` narrow·default·wide·full, `as`), `Section` (`id`, `eyebrow`, `title`, `lead`, `actions`, `divider`, `spacing` sm·md·lg, `backdrop`, `size`, `reveal`), `SectionHeading`, `Facts` (`items`: `label`, `tone` ok·wip·neutral, `href`), `Ticks` (backticks read as code) — see [Page blocks](#page-blocks) | server |
|
|
196
197
|
| `@krizaka/ui/page-hero` | `PageHero` (`title` → the h1, `eyebrow`, `lead`, `back`, `aside`, `backdrop` grid·plain·none, `align`, `size`, `linkAs`; facts or actions as children) | server |
|
|
197
198
|
| `@krizaka/ui/card-grid` | `CardGrid` (`min`, `fit` fill·fit, `align`, `reveal` staggered by `columns`, `light`, `as` div·ul·ol) | client |
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import * as tailwind_variants from 'tailwind-variants';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
/** A text item as pdf.js returns it (`TextItem`): the string, its matrix (`[a, b, c, d, x, baseline]`) and its size. */
|
|
5
|
+
type TextItem = {
|
|
6
|
+
str: string;
|
|
7
|
+
transform: number[];
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
/** A rectangle in fractions of the page (0–1), origin top-left — independent of the zoom the page is drawn at. */
|
|
12
|
+
type Box = {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
/** The text layer of one page: its size in PDF units (rotation 0) and its items in reading order. */
|
|
19
|
+
type PageText = {
|
|
20
|
+
page: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
items: readonly TextItem[];
|
|
24
|
+
};
|
|
25
|
+
type Located = {
|
|
26
|
+
/** 1-based page where the passage starts. */
|
|
27
|
+
page: number;
|
|
28
|
+
/** One box per line of the passage (merged along a line); empty when only the page is known. */
|
|
29
|
+
boxes: Box[];
|
|
30
|
+
/** `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */
|
|
31
|
+
match: "exact" | "start" | "page";
|
|
32
|
+
};
|
|
33
|
+
/** The comparable form of a text: no whitespace, no soft hyphen, straight quotes, case and accents folded. */
|
|
34
|
+
declare function fold(text: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Where `quote` sits in the pages: the first page (starting with `hintPage`, if any) whose text contains it, and the
|
|
37
|
+
* boxes of its lines. A quote that a different layout cut (a column break, a hyphen) is looked for by its opening
|
|
38
|
+
* words (`match: "start"`); one that is nowhere gives `null`, or the hinted page alone (`match: "page"`). Never a guess:
|
|
39
|
+
* a rotated page has no boxes, only its page.
|
|
40
|
+
*/
|
|
41
|
+
declare function locateQuote(pages: readonly PageText[], quote: string, hintPage?: number): Located | null;
|
|
42
|
+
|
|
43
|
+
declare const documentViewer: tailwind_variants.TVReturnType<{
|
|
44
|
+
[key: string]: {
|
|
45
|
+
[key: string]: tailwind_variants.ClassValue | {
|
|
46
|
+
page?: tailwind_variants.ClassValue;
|
|
47
|
+
root?: tailwind_variants.ClassValue;
|
|
48
|
+
pages?: tailwind_variants.ClassValue;
|
|
49
|
+
canvas?: tailwind_variants.ClassValue;
|
|
50
|
+
caption?: tailwind_variants.ClassValue;
|
|
51
|
+
box?: tailwind_variants.ClassValue;
|
|
52
|
+
bar?: tailwind_variants.ClassValue;
|
|
53
|
+
status?: tailwind_variants.ClassValue;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
[x: string]: {
|
|
58
|
+
[x: string]: tailwind_variants.ClassValue | {
|
|
59
|
+
page?: tailwind_variants.ClassValue;
|
|
60
|
+
root?: tailwind_variants.ClassValue;
|
|
61
|
+
pages?: tailwind_variants.ClassValue;
|
|
62
|
+
canvas?: tailwind_variants.ClassValue;
|
|
63
|
+
caption?: tailwind_variants.ClassValue;
|
|
64
|
+
box?: tailwind_variants.ClassValue;
|
|
65
|
+
bar?: tailwind_variants.ClassValue;
|
|
66
|
+
status?: tailwind_variants.ClassValue;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
} | {}, {
|
|
70
|
+
root: string;
|
|
71
|
+
pages: string;
|
|
72
|
+
page: string;
|
|
73
|
+
canvas: string;
|
|
74
|
+
caption: string;
|
|
75
|
+
box: string;
|
|
76
|
+
bar: string;
|
|
77
|
+
status: string;
|
|
78
|
+
}, undefined, {
|
|
79
|
+
[key: string]: {
|
|
80
|
+
[key: string]: tailwind_variants.ClassValue | {
|
|
81
|
+
page?: tailwind_variants.ClassValue;
|
|
82
|
+
root?: tailwind_variants.ClassValue;
|
|
83
|
+
pages?: tailwind_variants.ClassValue;
|
|
84
|
+
canvas?: tailwind_variants.ClassValue;
|
|
85
|
+
caption?: tailwind_variants.ClassValue;
|
|
86
|
+
box?: tailwind_variants.ClassValue;
|
|
87
|
+
bar?: tailwind_variants.ClassValue;
|
|
88
|
+
status?: tailwind_variants.ClassValue;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
} | {}, {
|
|
92
|
+
root: string;
|
|
93
|
+
pages: string;
|
|
94
|
+
page: string;
|
|
95
|
+
canvas: string;
|
|
96
|
+
caption: string;
|
|
97
|
+
box: string;
|
|
98
|
+
bar: string;
|
|
99
|
+
status: string;
|
|
100
|
+
}, tailwind_variants.TVReturnTypeLike<unknown, {
|
|
101
|
+
root: string;
|
|
102
|
+
pages: string;
|
|
103
|
+
page: string;
|
|
104
|
+
canvas: string;
|
|
105
|
+
caption: string;
|
|
106
|
+
box: string;
|
|
107
|
+
bar: string;
|
|
108
|
+
status: string;
|
|
109
|
+
}>>;
|
|
110
|
+
/** The words of the viewer, passed translated. `{page}` and `{total}` are replaced. */
|
|
111
|
+
type DocumentViewerLabels = {
|
|
112
|
+
/** The accessible name of the pages' region. */
|
|
113
|
+
region: string;
|
|
114
|
+
loading: string;
|
|
115
|
+
failed: string;
|
|
116
|
+
/** A page's caption and accessible name: "Page {page} of {total}". */
|
|
117
|
+
page: string;
|
|
118
|
+
/** The bar above the pages when the active passage could only be placed on a page: "Passage on page {page}:". */
|
|
119
|
+
onPage: string;
|
|
120
|
+
/** The bar when the active passage is not in the text layer. */
|
|
121
|
+
notFound: string;
|
|
122
|
+
};
|
|
123
|
+
declare const documentViewerLabels: DocumentViewerLabels;
|
|
124
|
+
/** A passage to light: its quote (as the text layer reads it), the page if the app knows it, a name for screen readers. */
|
|
125
|
+
type DocumentHighlight = {
|
|
126
|
+
id: string;
|
|
127
|
+
quote: string;
|
|
128
|
+
page?: number;
|
|
129
|
+
label?: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** The members of pdf.js the viewer uses (`pdfjs-dist` ≥ 5), typed here so the package does not depend on it. */
|
|
133
|
+
type PdfjsModule = {
|
|
134
|
+
GlobalWorkerOptions: {
|
|
135
|
+
workerSrc: string;
|
|
136
|
+
};
|
|
137
|
+
getDocument(source: {
|
|
138
|
+
url?: string;
|
|
139
|
+
data?: Uint8Array;
|
|
140
|
+
}): {
|
|
141
|
+
promise: Promise<PdfDocument>;
|
|
142
|
+
destroy?: () => Promise<void> | void;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
type PdfDocument = {
|
|
146
|
+
numPages: number;
|
|
147
|
+
getPage(n: number): Promise<PdfPage>;
|
|
148
|
+
destroy?: () => Promise<void> | void;
|
|
149
|
+
};
|
|
150
|
+
type PdfPage = {
|
|
151
|
+
rotate: number;
|
|
152
|
+
view: number[];
|
|
153
|
+
getViewport(options: {
|
|
154
|
+
scale: number;
|
|
155
|
+
}): {
|
|
156
|
+
width: number;
|
|
157
|
+
height: number;
|
|
158
|
+
};
|
|
159
|
+
getTextContent(): Promise<{
|
|
160
|
+
items: readonly unknown[];
|
|
161
|
+
}>;
|
|
162
|
+
render(options: {
|
|
163
|
+
canvas: HTMLCanvasElement;
|
|
164
|
+
canvasContext: CanvasRenderingContext2D;
|
|
165
|
+
viewport: {
|
|
166
|
+
width: number;
|
|
167
|
+
height: number;
|
|
168
|
+
};
|
|
169
|
+
}): {
|
|
170
|
+
promise: Promise<void>;
|
|
171
|
+
cancel?: () => void;
|
|
172
|
+
};
|
|
173
|
+
cleanup?: () => void;
|
|
174
|
+
};
|
|
175
|
+
type DocumentViewerProps = Omit<React.ComponentProps<"div">, "children" | "onChange"> & {
|
|
176
|
+
/** The PDF: an address (same origin or CORS) or its bytes. */
|
|
177
|
+
src: string | Uint8Array;
|
|
178
|
+
/** Loads pdf.js: `() => import("pdfjs-dist")`. An optional peer, never in a bundle without a document. */
|
|
179
|
+
loadPdfjs: () => Promise<PdfjsModule>;
|
|
180
|
+
/** The address of pdf.js's worker (`new URL("pdfjs-dist/build/pdf.worker.min.mjs", import.meta.url).toString()`). */
|
|
181
|
+
workerSrc: string;
|
|
182
|
+
/** The passages to light. */
|
|
183
|
+
highlights?: readonly DocumentHighlight[];
|
|
184
|
+
/** The passage in focus: the viewer scrolls to it. */
|
|
185
|
+
activeId?: string | null;
|
|
186
|
+
/** A box was clicked (the id) or the focus was released (`null`). */
|
|
187
|
+
onActiveChange?: (id: string | null) => void;
|
|
188
|
+
/** Where each passage was found (`null`: nowhere) — once the text layer is read, and again if `highlights` change. */
|
|
189
|
+
onLocate?: (found: Record<string, Located | null>) => void;
|
|
190
|
+
/** Called when the document is open, with its page count. */
|
|
191
|
+
onLoad?: (info: {
|
|
192
|
+
pages: number;
|
|
193
|
+
}) => void;
|
|
194
|
+
/** The words of the viewer, translated (English by default). */
|
|
195
|
+
labels?: Partial<DocumentViewerLabels>;
|
|
196
|
+
};
|
|
197
|
+
/** A PDF with its passages lit — see the file's header. Client. */
|
|
198
|
+
declare function DocumentViewer({ src, loadPdfjs, workerSrc, highlights, activeId, onActiveChange, onLocate, onLoad, labels, className, ...props }: DocumentViewerProps): React.JSX.Element;
|
|
199
|
+
|
|
200
|
+
export { type Box, type DocumentHighlight, DocumentViewer, type DocumentViewerLabels, type DocumentViewerProps, type Located, type PageText, type PdfDocument, type PdfPage, type PdfjsModule, type TextItem, documentViewer, documentViewerLabels, fold, locateQuote };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useLatest,
|
|
4
|
+
usePrefersReducedMotion
|
|
5
|
+
} from "./chunk-FZBWEDQI.js";
|
|
6
|
+
|
|
7
|
+
// src/document-viewer/document-viewer.tsx
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { tv } from "tailwind-variants";
|
|
10
|
+
|
|
11
|
+
// src/document-viewer/locate.ts
|
|
12
|
+
var FOLD = { "\u2019": "'", "\u2018": "'", "\u201C": '"', "\u201D": '"', "\xAB": '"', "\xBB": '"', "\u2013": "-", "\u2014": "-", "\xA0": " ", "\u202F": " ", "\uFB01": "fi", "\uFB02": "fl" };
|
|
13
|
+
function fold(text) {
|
|
14
|
+
let out = "";
|
|
15
|
+
for (const ch of text.normalize("NFKD")) {
|
|
16
|
+
if (/\p{M}/u.test(ch) || /\s/u.test(ch) || ch === "\xAD" || ch === "\u200B") continue;
|
|
17
|
+
out += (FOLD[ch] ?? ch).toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
function indexPage(items) {
|
|
22
|
+
let text = "";
|
|
23
|
+
const at = [];
|
|
24
|
+
items.forEach((item, i) => {
|
|
25
|
+
for (let c = 0; c < item.str.length; c++) {
|
|
26
|
+
const piece = fold(item.str[c]);
|
|
27
|
+
for (let k = 0; k < piece.length; k++) {
|
|
28
|
+
text += piece[k];
|
|
29
|
+
at.push({ item: i, char: c });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return { text, at };
|
|
34
|
+
}
|
|
35
|
+
function boxesOf(page, index, from, to) {
|
|
36
|
+
const spans = /* @__PURE__ */ new Map();
|
|
37
|
+
for (let k = from; k < to; k++) {
|
|
38
|
+
const { item, char } = index.at[k];
|
|
39
|
+
const s = spans.get(item);
|
|
40
|
+
spans.set(item, s ? [Math.min(s[0], char), Math.max(s[1], char + 1)] : [char, char + 1]);
|
|
41
|
+
}
|
|
42
|
+
const raw = [];
|
|
43
|
+
for (const [i, [c0, c1]] of [...spans].sort((a, b) => a[0] - b[0])) {
|
|
44
|
+
const item = page.items[i];
|
|
45
|
+
const len = Math.max(1, item.str.length);
|
|
46
|
+
const size = item.height || Math.abs(item.transform[3] ?? 0) || 10;
|
|
47
|
+
const x = (item.transform[4] ?? 0) + item.width * c0 / len;
|
|
48
|
+
const w = item.width * (c1 - c0) / len;
|
|
49
|
+
const top = page.height - ((item.transform[5] ?? 0) + size * 0.9);
|
|
50
|
+
raw.push({ x: x / page.width, y: top / page.height, width: w / page.width, height: size * 1.15 / page.height });
|
|
51
|
+
}
|
|
52
|
+
const merged = [];
|
|
53
|
+
for (const b of raw) {
|
|
54
|
+
const last = merged[merged.length - 1];
|
|
55
|
+
const sameLine = last && Math.abs(last.y - b.y) < last.height * 0.5 && b.x - (last.x + last.width) < last.height * 1.5 && b.x >= last.x - 1e-9;
|
|
56
|
+
if (last && sameLine) {
|
|
57
|
+
const right = Math.max(last.x + last.width, b.x + b.width);
|
|
58
|
+
last.y = Math.min(last.y, b.y);
|
|
59
|
+
last.height = Math.max(last.height, b.height);
|
|
60
|
+
last.width = right - last.x;
|
|
61
|
+
} else merged.push({ ...b });
|
|
62
|
+
}
|
|
63
|
+
return merged.map((b) => ({ x: clamp01(b.x), y: clamp01(b.y), width: Math.min(b.width, 1 - clamp01(b.x)), height: Math.min(b.height, 1 - clamp01(b.y)) }));
|
|
64
|
+
}
|
|
65
|
+
var clamp01 = (n) => Math.min(1, Math.max(0, n));
|
|
66
|
+
var MIN_START = 24;
|
|
67
|
+
function locateQuote(pages, quote, hintPage) {
|
|
68
|
+
const needle = fold(quote);
|
|
69
|
+
const ordered = hintPage ? [...pages].sort((a, b) => Number(b.page === hintPage) - Number(a.page === hintPage)) : pages;
|
|
70
|
+
if (needle.length > 0) {
|
|
71
|
+
for (const mode of ["exact", "start"]) {
|
|
72
|
+
const wanted = mode === "exact" ? needle : needle.slice(0, Math.max(MIN_START, Math.min(40, Math.floor(needle.length * 0.6))));
|
|
73
|
+
if (mode === "start" && (needle.length <= wanted.length || wanted.length < MIN_START)) break;
|
|
74
|
+
for (const page of ordered) {
|
|
75
|
+
const index = indexPage(page.items);
|
|
76
|
+
const found = index.text.indexOf(wanted);
|
|
77
|
+
if (found < 0) continue;
|
|
78
|
+
return { page: page.page, boxes: boxesOf(page, index, found, found + wanted.length), match: mode };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return hintPage && pages.some((p) => p.page === hintPage) ? { page: hintPage, boxes: [], match: "page" } : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/document-viewer/document-viewer.tsx
|
|
86
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
87
|
+
var documentViewer = tv({
|
|
88
|
+
slots: {
|
|
89
|
+
root: "relative flex min-w-0 flex-col gap-3",
|
|
90
|
+
pages: "flex max-h-(--kz-document-viewer-height,70vh) flex-col gap-3 overflow-auto rounded-lg border border-border-default bg-surface-2 p-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent",
|
|
91
|
+
page: "relative mx-auto w-full max-w-(--kz-document-viewer-page,56rem) shrink-0 overflow-hidden rounded-sm bg-white shadow-sm",
|
|
92
|
+
canvas: "block h-auto w-full",
|
|
93
|
+
caption: "absolute top-1 left-1 rounded-sm bg-surface-1/90 px-1.5 py-0.5 text-xs text-fg-secondary",
|
|
94
|
+
box: "absolute cursor-pointer rounded-xs border border-warning/70 bg-warning/25 mix-blend-multiply transition-colors data-[active=true]:border-2 data-[active=true]:border-danger data-[active=true]:bg-danger/25 motion-reduce:transition-none",
|
|
95
|
+
bar: "rounded-lg border border-border-default bg-surface-1 px-3 py-2 text-sm text-fg-secondary",
|
|
96
|
+
status: "p-6 text-center text-sm text-fg-secondary"
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
var documentViewerLabels = {
|
|
100
|
+
region: "Document pages",
|
|
101
|
+
loading: "Loading the document\u2026",
|
|
102
|
+
failed: "The document could not be displayed.",
|
|
103
|
+
page: "Page {page} of {total}",
|
|
104
|
+
onPage: "Passage on page {page}:",
|
|
105
|
+
notFound: "This passage is not in the document's text layer:"
|
|
106
|
+
};
|
|
107
|
+
var fill = (template, vars) => template.replace(/\{(\w+)\}/g, (m, k) => k in vars ? String(vars[k]) : m);
|
|
108
|
+
var isItem = (x) => typeof x === "object" && x !== null && typeof x.str === "string" && Array.isArray(x.transform);
|
|
109
|
+
function PageCanvas({ page, doc, caption, onReady, className }) {
|
|
110
|
+
const ref = React.useRef(null);
|
|
111
|
+
const wrapper = React.useRef(null);
|
|
112
|
+
const [visible, setVisible] = React.useState(() => typeof IntersectionObserver === "undefined");
|
|
113
|
+
const ready = useLatest(onReady);
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
const node = wrapper.current?.parentElement;
|
|
116
|
+
if (!node) return;
|
|
117
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
118
|
+
const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setVisible(true), { rootMargin: "600px 0px" });
|
|
119
|
+
observer.observe(node);
|
|
120
|
+
return () => observer.disconnect();
|
|
121
|
+
}, []);
|
|
122
|
+
React.useEffect(() => {
|
|
123
|
+
if (!visible) return;
|
|
124
|
+
let task;
|
|
125
|
+
let cancelled = false;
|
|
126
|
+
void (async () => {
|
|
127
|
+
const p = await doc.getPage(page);
|
|
128
|
+
const canvas = ref.current;
|
|
129
|
+
const ctx = canvas?.getContext("2d");
|
|
130
|
+
if (cancelled || !canvas || !ctx) return;
|
|
131
|
+
const base = p.getViewport({ scale: 1 });
|
|
132
|
+
const dpr = typeof window === "undefined" ? 1 : Math.min(2, window.devicePixelRatio || 1);
|
|
133
|
+
const scale = Math.min(2.5, Math.max(1, (canvas.parentElement?.clientWidth || base.width) / base.width)) * dpr;
|
|
134
|
+
const viewport = p.getViewport({ scale });
|
|
135
|
+
canvas.width = Math.floor(viewport.width);
|
|
136
|
+
canvas.height = Math.floor(viewport.height);
|
|
137
|
+
task = p.render({ canvas, canvasContext: ctx, viewport });
|
|
138
|
+
await task.promise.catch(() => void 0);
|
|
139
|
+
if (!cancelled) ready.current?.();
|
|
140
|
+
})().catch(() => void 0);
|
|
141
|
+
return () => {
|
|
142
|
+
cancelled = true;
|
|
143
|
+
task?.cancel?.();
|
|
144
|
+
};
|
|
145
|
+
}, [visible, doc, page, ready]);
|
|
146
|
+
return /* @__PURE__ */ jsxs("div", { ref: wrapper, className: "contents", children: [
|
|
147
|
+
/* @__PURE__ */ jsx("canvas", { ref, "aria-hidden": "true", className }),
|
|
148
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: caption })
|
|
149
|
+
] });
|
|
150
|
+
}
|
|
151
|
+
function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId = null, onActiveChange, onLocate, onLoad, labels, className, ...props }) {
|
|
152
|
+
const words = { ...documentViewerLabels, ...labels };
|
|
153
|
+
const s = documentViewer();
|
|
154
|
+
const reduce = usePrefersReducedMotion();
|
|
155
|
+
const [loaded, setPhase] = React.useState({ state: "loading" });
|
|
156
|
+
const callbacks = useLatest({ onLoad, onLocate });
|
|
157
|
+
const containerRef = React.useRef(null);
|
|
158
|
+
const bytes = typeof src === "string" ? src : src.byteLength + ":" + src[0] + ":" + src[src.length - 1];
|
|
159
|
+
const phase = loaded.state !== "loading" && loaded.key !== bytes ? { state: "loading" } : loaded;
|
|
160
|
+
React.useEffect(() => {
|
|
161
|
+
let cancelled = false;
|
|
162
|
+
let opened;
|
|
163
|
+
void (async () => {
|
|
164
|
+
const pdfjs = await loadPdfjs();
|
|
165
|
+
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
|
|
166
|
+
const loading = pdfjs.getDocument(typeof src === "string" ? { url: src } : { data: src.slice() });
|
|
167
|
+
opened = loading;
|
|
168
|
+
const doc = await loading.promise;
|
|
169
|
+
const texts = [];
|
|
170
|
+
const sizes = [];
|
|
171
|
+
for (let n = 1; n <= doc.numPages; n++) {
|
|
172
|
+
const page = await doc.getPage(n);
|
|
173
|
+
const vp = page.getViewport({ scale: 1 });
|
|
174
|
+
sizes.push({ width: vp.width, height: vp.height });
|
|
175
|
+
const content = await page.getTextContent();
|
|
176
|
+
texts.push({ page: n, width: vp.width, height: vp.height, items: page.rotate % 360 === 0 ? content.items.filter(isItem) : [] });
|
|
177
|
+
page.cleanup?.();
|
|
178
|
+
}
|
|
179
|
+
if (cancelled) return;
|
|
180
|
+
setPhase({ state: "ready", key: bytes, doc, texts, sizes });
|
|
181
|
+
callbacks.current.onLoad?.({ pages: doc.numPages });
|
|
182
|
+
})().catch(() => !cancelled && setPhase({ state: "error", key: bytes }));
|
|
183
|
+
return () => {
|
|
184
|
+
cancelled = true;
|
|
185
|
+
void opened?.destroy?.();
|
|
186
|
+
};
|
|
187
|
+
}, [bytes, loadPdfjs, workerSrc, callbacks]);
|
|
188
|
+
const key = highlights.map((h) => `${h.id}\0${h.page ?? ""}\0${h.quote}`).join("");
|
|
189
|
+
const found = React.useMemo(() => {
|
|
190
|
+
const out = {};
|
|
191
|
+
if (phase.state === "ready") for (const h of highlights) out[h.id] = locateQuote(phase.texts, h.quote, h.page);
|
|
192
|
+
return out;
|
|
193
|
+
}, [phase, key]);
|
|
194
|
+
React.useEffect(() => {
|
|
195
|
+
if (phase.state === "ready") callbacks.current.onLocate?.(found);
|
|
196
|
+
}, [found, phase.state, callbacks]);
|
|
197
|
+
const active = activeId ? highlights.find((h) => h.id === activeId) : void 0;
|
|
198
|
+
const where = activeId ? found[activeId] : void 0;
|
|
199
|
+
React.useEffect(() => {
|
|
200
|
+
if (phase.state !== "ready" || !where) return;
|
|
201
|
+
const root = containerRef.current;
|
|
202
|
+
const target = root?.querySelector(where.boxes.length > 0 ? `[data-highlight="${CSS.escape(activeId)}"]` : `[data-page="${where.page}"]`) ?? null;
|
|
203
|
+
target?.scrollIntoView?.({ block: where.boxes.length > 0 ? "center" : "start", behavior: reduce ? "auto" : "smooth" });
|
|
204
|
+
}, [activeId, where, phase.state]);
|
|
205
|
+
return /* @__PURE__ */ jsxs("div", { className: s.root({ className }), ...props, children: [
|
|
206
|
+
active && where !== void 0 && where?.match !== "exact" && where?.match !== "start" ? /* @__PURE__ */ jsxs("p", { className: s.bar(), "data-testid": "document-viewer-bar", children: [
|
|
207
|
+
where?.match === "page" ? fill(words.onPage, { page: where.page }) : words.notFound,
|
|
208
|
+
" ",
|
|
209
|
+
/* @__PURE__ */ jsx("q", { children: active.quote })
|
|
210
|
+
] }) : null,
|
|
211
|
+
/* @__PURE__ */ jsxs("div", { ref: containerRef, className: s.pages(), role: "region", "aria-label": words.region, tabIndex: 0, children: [
|
|
212
|
+
phase.state === "loading" ? /* @__PURE__ */ jsx("p", { className: s.status(), children: words.loading }) : null,
|
|
213
|
+
phase.state === "error" ? /* @__PURE__ */ jsx("p", { role: "alert", className: s.status(), children: words.failed }) : null,
|
|
214
|
+
phase.state === "ready" ? phase.texts.map((t, i) => {
|
|
215
|
+
const size = phase.sizes[i];
|
|
216
|
+
const caption = fill(words.page, { page: t.page, total: phase.doc.numPages });
|
|
217
|
+
return /* @__PURE__ */ jsxs("div", { className: s.page(), "data-page": t.page, style: { aspectRatio: `${size.width} / ${size.height}` }, children: [
|
|
218
|
+
/* @__PURE__ */ jsx(PageCanvas, { page: t.page, doc: phase.doc, caption, className: s.canvas() }),
|
|
219
|
+
/* @__PURE__ */ jsx("span", { className: s.caption(), "aria-hidden": "true", children: caption }),
|
|
220
|
+
highlights.flatMap((h) => {
|
|
221
|
+
const f = found[h.id];
|
|
222
|
+
if (!f || f.page !== t.page) return [];
|
|
223
|
+
return f.boxes.map((b, k) => /* @__PURE__ */ jsx(
|
|
224
|
+
"div",
|
|
225
|
+
{
|
|
226
|
+
"aria-hidden": "true",
|
|
227
|
+
"data-highlight": h.id,
|
|
228
|
+
"data-active": h.id === activeId,
|
|
229
|
+
className: s.box(),
|
|
230
|
+
style: { left: `${b.x * 100}%`, top: `${b.y * 100}%`, width: `${b.width * 100}%`, height: `${b.height * 100}%` },
|
|
231
|
+
onClick: () => onActiveChange?.(h.id === activeId ? null : h.id)
|
|
232
|
+
},
|
|
233
|
+
`${h.id}:${k}`
|
|
234
|
+
));
|
|
235
|
+
})
|
|
236
|
+
] }, t.page);
|
|
237
|
+
}) : null
|
|
238
|
+
] })
|
|
239
|
+
] });
|
|
240
|
+
}
|
|
241
|
+
export {
|
|
242
|
+
DocumentViewer,
|
|
243
|
+
documentViewer,
|
|
244
|
+
documentViewerLabels,
|
|
245
|
+
fold,
|
|
246
|
+
locateQuote
|
|
247
|
+
};
|
|
248
|
+
//# sourceMappingURL=document-viewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/document-viewer/document-viewer.tsx","../src/document-viewer/locate.ts"],"sourcesContent":["// Client. A PDF drawn page by page (pdf.js), and passages of it lit where they sit. The app hands over the engine\n// (`loadPdfjs={() => import(\"pdfjs-dist\")}` — an optional peer, loaded only on a page that shows a document) and the\n// worker's address; it hands over the passages as quotes (`highlights`), and the viewer finds their place from the\n// PDF's own text positions (`locateQuote`): one box per line, in fractions of the page, so they follow any zoom.\n// `activeId` (controlled) scrolls to a passage and strengthens it; a click on a box calls `onActiveChange`. A passage\n// the text layer cannot place is never drawn at a guessed place: the viewer goes to its page when it is known and shows\n// the quote in a bar — and tells the app (`onLocate`) so its list can say \"page 3\" or \"not found\".\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { useLatest, usePrefersReducedMotion } from \"../media\";\nimport { type Located, locateQuote, type PageText } from \"./locate\";\n\nexport const documentViewer = tv({\n slots: {\n root: \"relative flex min-w-0 flex-col gap-3\",\n pages: \"flex max-h-(--kz-document-viewer-height,70vh) flex-col gap-3 overflow-auto rounded-lg border border-border-default bg-surface-2 p-3 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent\",\n page: \"relative mx-auto w-full max-w-(--kz-document-viewer-page,56rem) shrink-0 overflow-hidden rounded-sm bg-white shadow-sm\",\n canvas: \"block h-auto w-full\",\n caption: \"absolute top-1 left-1 rounded-sm bg-surface-1/90 px-1.5 py-0.5 text-xs text-fg-secondary\",\n box: \"absolute cursor-pointer rounded-xs border border-warning/70 bg-warning/25 mix-blend-multiply transition-colors data-[active=true]:border-2 data-[active=true]:border-danger data-[active=true]:bg-danger/25 motion-reduce:transition-none\",\n bar: \"rounded-lg border border-border-default bg-surface-1 px-3 py-2 text-sm text-fg-secondary\",\n status: \"p-6 text-center text-sm text-fg-secondary\",\n },\n});\n\n/** The words of the viewer, passed translated. `{page}` and `{total}` are replaced. */\nexport type DocumentViewerLabels = {\n /** The accessible name of the pages' region. */\n region: string;\n loading: string;\n failed: string;\n /** A page's caption and accessible name: \"Page {page} of {total}\". */\n page: string;\n /** The bar above the pages when the active passage could only be placed on a page: \"Passage on page {page}:\". */\n onPage: string;\n /** The bar when the active passage is not in the text layer. */\n notFound: string;\n};\n\nexport const documentViewerLabels: DocumentViewerLabels = {\n region: \"Document pages\",\n loading: \"Loading the document…\",\n failed: \"The document could not be displayed.\",\n page: \"Page {page} of {total}\",\n onPage: \"Passage on page {page}:\",\n notFound: \"This passage is not in the document's text layer:\",\n};\n\n/** A passage to light: its quote (as the text layer reads it), the page if the app knows it, a name for screen readers. */\nexport type DocumentHighlight = { id: string; quote: string; page?: number; label?: string };\n\n/** What the viewer found for a passage. */\nexport type { Located };\n\n/** The members of pdf.js the viewer uses (`pdfjs-dist` ≥ 5), typed here so the package does not depend on it. */\nexport type PdfjsModule = {\n GlobalWorkerOptions: { workerSrc: string };\n getDocument(source: { url?: string; data?: Uint8Array }): { promise: Promise<PdfDocument>; destroy?: () => Promise<void> | void };\n};\nexport type PdfDocument = { numPages: number; getPage(n: number): Promise<PdfPage>; destroy?: () => Promise<void> | void };\nexport type PdfPage = {\n rotate: number;\n view: number[];\n getViewport(options: { scale: number }): { width: number; height: number };\n getTextContent(): Promise<{ items: readonly unknown[] }>;\n render(options: { canvas: HTMLCanvasElement; canvasContext: CanvasRenderingContext2D; viewport: { width: number; height: number } }): { promise: Promise<void>; cancel?: () => void };\n cleanup?: () => void;\n};\n\nexport type DocumentViewerProps = Omit<React.ComponentProps<\"div\">, \"children\" | \"onChange\"> & {\n /** The PDF: an address (same origin or CORS) or its bytes. */\n src: string | Uint8Array;\n /** Loads pdf.js: `() => import(\"pdfjs-dist\")`. An optional peer, never in a bundle without a document. */\n loadPdfjs: () => Promise<PdfjsModule>;\n /** The address of pdf.js's worker (`new URL(\"pdfjs-dist/build/pdf.worker.min.mjs\", import.meta.url).toString()`). */\n workerSrc: string;\n /** The passages to light. */\n highlights?: readonly DocumentHighlight[];\n /** The passage in focus: the viewer scrolls to it. */\n activeId?: string | null;\n /** A box was clicked (the id) or the focus was released (`null`). */\n onActiveChange?: (id: string | null) => void;\n /** Where each passage was found (`null`: nowhere) — once the text layer is read, and again if `highlights` change. */\n onLocate?: (found: Record<string, Located | null>) => void;\n /** Called when the document is open, with its page count. */\n onLoad?: (info: { pages: number }) => void;\n /** The words of the viewer, translated (English by default). */\n labels?: Partial<DocumentViewerLabels>;\n};\n\nconst fill = (template: string, vars: Record<string, string | number>) => template.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));\n\ntype Loaded = { doc: PdfDocument; texts: PageText[]; sizes: { width: number; height: number }[] };\ntype Phase = { state: \"loading\" } | { state: \"error\"; key: string } | ({ state: \"ready\"; key: string } & Loaded);\n\nconst isItem = (x: unknown): x is PageText[\"items\"][number] => typeof x === \"object\" && x !== null && typeof (x as { str?: unknown }).str === \"string\" && Array.isArray((x as { transform?: unknown }).transform);\n\nfunction PageCanvas({ page, doc, caption, onReady, className }: { page: number; doc: PdfDocument; caption: string; onReady?: () => void; className: string }) {\n const ref = React.useRef<HTMLCanvasElement>(null);\n const wrapper = React.useRef<HTMLDivElement>(null);\n const [visible, setVisible] = React.useState(() => typeof IntersectionObserver === \"undefined\");\n const ready = useLatest(onReady);\n React.useEffect(() => {\n const node = wrapper.current?.parentElement;\n if (!node) return;\n if (typeof IntersectionObserver === \"undefined\") return;\n const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setVisible(true), { rootMargin: \"600px 0px\" });\n observer.observe(node);\n return () => observer.disconnect();\n }, []);\n React.useEffect(() => {\n if (!visible) return;\n let task: { promise: Promise<void>; cancel?: () => void } | undefined;\n let cancelled = false;\n void (async () => {\n const p = await doc.getPage(page);\n const canvas = ref.current;\n const ctx = canvas?.getContext(\"2d\");\n if (cancelled || !canvas || !ctx) return;\n const base = p.getViewport({ scale: 1 });\n const dpr = typeof window === \"undefined\" ? 1 : Math.min(2, window.devicePixelRatio || 1);\n const scale = Math.min(2.5, Math.max(1, (canvas.parentElement?.clientWidth || base.width) / base.width)) * dpr;\n const viewport = p.getViewport({ scale });\n canvas.width = Math.floor(viewport.width);\n canvas.height = Math.floor(viewport.height);\n task = p.render({ canvas, canvasContext: ctx, viewport });\n await task.promise.catch(() => undefined);\n if (!cancelled) ready.current?.();\n })().catch(() => undefined);\n return () => {\n cancelled = true;\n task?.cancel?.();\n };\n }, [visible, doc, page, ready]);\n return (\n <div ref={wrapper} className=\"contents\">\n <canvas ref={ref} aria-hidden=\"true\" className={className} />\n <span className=\"sr-only\">{caption}</span>\n </div>\n );\n}\n\n/** A PDF with its passages lit — see the file's header. Client. */\nexport function DocumentViewer({ src, loadPdfjs, workerSrc, highlights = [], activeId = null, onActiveChange, onLocate, onLoad, labels, className, ...props }: DocumentViewerProps) {\n const words = { ...documentViewerLabels, ...labels };\n const s = documentViewer();\n const reduce = usePrefersReducedMotion();\n const [loaded, setPhase] = React.useState<Phase>({ state: \"loading\" });\n const callbacks = useLatest({ onLoad, onLocate });\n const containerRef = React.useRef<HTMLDivElement>(null);\n const bytes = typeof src === \"string\" ? src : src.byteLength + \":\" + src[0] + \":\" + src[src.length - 1];\n // A result belongs to the document it was read from: another `src` is loading again, with no reset inside the effect.\n const phase: Phase = loaded.state !== \"loading\" && loaded.key !== bytes ? { state: \"loading\" } : loaded;\n\n // Open the document and read every page's text layer (positions only; nothing is sent anywhere).\n React.useEffect(() => {\n let cancelled = false;\n let opened: { destroy?: () => Promise<void> | void } | undefined;\n void (async () => {\n const pdfjs = await loadPdfjs();\n pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;\n const loading = pdfjs.getDocument(typeof src === \"string\" ? { url: src } : { data: src.slice() });\n opened = loading;\n const doc = await loading.promise;\n const texts: PageText[] = [];\n const sizes: Loaded[\"sizes\"] = [];\n for (let n = 1; n <= doc.numPages; n++) {\n const page = await doc.getPage(n);\n const vp = page.getViewport({ scale: 1 });\n sizes.push({ width: vp.width, height: vp.height });\n const content = await page.getTextContent();\n // A rotated page has no reliable boxes: it keeps its size and an empty text layer (the app's page hint still works).\n texts.push({ page: n, width: vp.width, height: vp.height, items: page.rotate % 360 === 0 ? content.items.filter(isItem) : [] });\n page.cleanup?.();\n }\n if (cancelled) return;\n setPhase({ state: \"ready\", key: bytes, doc, texts, sizes });\n callbacks.current.onLoad?.({ pages: doc.numPages });\n })().catch(() => !cancelled && setPhase({ state: \"error\", key: bytes }));\n return () => {\n cancelled = true;\n void opened?.destroy?.();\n };\n // `src` is compared by content (`bytes`) so a re-render with the same bytes does not reopen the file.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [bytes, loadPdfjs, workerSrc, callbacks]);\n\n const key = highlights.map((h) => `${h.id}\\u0000${h.page ?? \"\"}\\u0000${h.quote}`).join(\"\\u0001\");\n const found = React.useMemo(() => {\n const out: Record<string, Located | null> = {};\n if (phase.state === \"ready\") for (const h of highlights) out[h.id] = locateQuote(phase.texts, h.quote, h.page);\n return out;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [phase, key]);\n React.useEffect(() => {\n if (phase.state === \"ready\") callbacks.current.onLocate?.(found);\n }, [found, phase.state, callbacks]);\n\n // Go to the active passage.\n const active = activeId ? highlights.find((h) => h.id === activeId) : undefined;\n const where = activeId ? found[activeId] : undefined;\n React.useEffect(() => {\n if (phase.state !== \"ready\" || !where) return;\n const root = containerRef.current;\n const target = root?.querySelector<HTMLElement>(where.boxes.length > 0 ? `[data-highlight=\"${CSS.escape(activeId!)}\"]` : `[data-page=\"${where.page}\"]`) ?? null;\n target?.scrollIntoView?.({ block: where.boxes.length > 0 ? \"center\" : \"start\", behavior: reduce ? \"auto\" : \"smooth\" });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeId, where, phase.state]);\n\n return (\n <div className={s.root({ className })} {...props}>\n {active && where !== undefined && where?.match !== \"exact\" && where?.match !== \"start\" ? (\n <p className={s.bar()} data-testid=\"document-viewer-bar\">\n {where?.match === \"page\" ? fill(words.onPage, { page: where.page }) : words.notFound} <q>{active.quote}</q>\n </p>\n ) : null}\n <div ref={containerRef} className={s.pages()} role=\"region\" aria-label={words.region} tabIndex={0}>\n {phase.state === \"loading\" ? <p className={s.status()}>{words.loading}</p> : null}\n {phase.state === \"error\" ? <p role=\"alert\" className={s.status()}>{words.failed}</p> : null}\n {phase.state === \"ready\"\n ? phase.texts.map((t, i) => {\n const size = phase.sizes[i]!;\n const caption = fill(words.page, { page: t.page, total: phase.doc.numPages });\n return (\n <div key={t.page} className={s.page()} data-page={t.page} style={{ aspectRatio: `${size.width} / ${size.height}` }}>\n <PageCanvas page={t.page} doc={phase.doc} caption={caption} className={s.canvas()} />\n <span className={s.caption()} aria-hidden=\"true\">{caption}</span>\n {highlights.flatMap((h) => {\n const f = found[h.id];\n if (!f || f.page !== t.page) return [];\n return f.boxes.map((b, k) => (\n <div\n key={`${h.id}:${k}`}\n aria-hidden=\"true\"\n data-highlight={h.id}\n data-active={h.id === activeId}\n className={s.box()}\n style={{ left: `${b.x * 100}%`, top: `${b.y * 100}%`, width: `${b.width * 100}%`, height: `${b.height * 100}%` }}\n onClick={() => onActiveChange?.(h.id === activeId ? null : h.id)}\n />\n ));\n })}\n </div>\n );\n })\n : null}\n </div>\n </div>\n );\n}\n","// Pure: where a quoted passage sits on the pages of a PDF, from pdf.js's text positions. No DOM, no pdf.js import —\n// the viewer feeds it what `page.getTextContent()` returned, a test feeds it a fixture.\n\n/** A text item as pdf.js returns it (`TextItem`): the string, its matrix (`[a, b, c, d, x, baseline]`) and its size. */\nexport type TextItem = { str: string; transform: number[]; width: number; height: number };\n\n/** A rectangle in fractions of the page (0–1), origin top-left — independent of the zoom the page is drawn at. */\nexport type Box = { x: number; y: number; width: number; height: number };\n\n/** The text layer of one page: its size in PDF units (rotation 0) and its items in reading order. */\nexport type PageText = { page: number; width: number; height: number; items: readonly TextItem[] };\n\nexport type Located = {\n /** 1-based page where the passage starts. */\n page: number;\n /** One box per line of the passage (merged along a line); empty when only the page is known. */\n boxes: Box[];\n /** `exact`: the whole quote was found; `start`: only its opening words were (a quote cut by a different layout). */\n match: \"exact\" | \"start\" | \"page\";\n};\n\nconst FOLD: Record<string, string> = { \"’\": \"'\", \"‘\": \"'\", \"“\": '\"', \"”\": '\"', \"«\": '\"', \"»\": '\"', \"–\": \"-\", \"—\": \"-\", \" \": \" \", \" \": \" \", \"fi\": \"fi\", \"fl\": \"fl\" };\n\n/** The comparable form of a text: no whitespace, no soft hyphen, straight quotes, case and accents folded. */\nexport function fold(text: string): string {\n let out = \"\";\n for (const ch of text.normalize(\"NFKD\")) {\n if (/\\p{M}/u.test(ch) || /\\s/u.test(ch) || ch === \"\" || ch === \"\") continue;\n out += (FOLD[ch] ?? ch).toLowerCase();\n }\n return out;\n}\n\ntype Index = { text: string; at: { item: number; char: number }[] };\n\nfunction indexPage(items: readonly TextItem[]): Index {\n let text = \"\";\n const at: Index[\"at\"] = [];\n items.forEach((item, i) => {\n for (let c = 0; c < item.str.length; c++) {\n const piece = fold(item.str[c]!);\n for (let k = 0; k < piece.length; k++) {\n text += piece[k];\n at.push({ item: i, char: c });\n }\n }\n });\n return { text, at };\n}\n\nfunction boxesOf(page: PageText, index: Index, from: number, to: number): Box[] {\n const spans = new Map<number, [number, number]>();\n for (let k = from; k < to; k++) {\n const { item, char } = index.at[k]!;\n const s = spans.get(item);\n spans.set(item, s ? [Math.min(s[0], char), Math.max(s[1], char + 1)] : [char, char + 1]);\n }\n const raw: Box[] = [];\n for (const [i, [c0, c1]] of [...spans].sort((a, b) => a[0] - b[0])) {\n const item = page.items[i]!;\n const len = Math.max(1, item.str.length);\n const size = item.height || Math.abs(item.transform[3] ?? 0) || 10;\n const x = (item.transform[4] ?? 0) + (item.width * c0) / len;\n const w = (item.width * (c1 - c0)) / len;\n const top = page.height - ((item.transform[5] ?? 0) + size * 0.9);\n raw.push({ x: x / page.width, y: top / page.height, width: w / page.width, height: (size * 1.15) / page.height });\n }\n // Merge the pieces that sit on one line and touch (several items of one sentence) into one rectangle.\n const merged: Box[] = [];\n for (const b of raw) {\n const last = merged[merged.length - 1];\n const sameLine = last && Math.abs(last.y - b.y) < last.height * 0.5 && b.x - (last.x + last.width) < last.height * 1.5 && b.x >= last.x - 1e-9;\n if (last && sameLine) {\n const right = Math.max(last.x + last.width, b.x + b.width);\n last.y = Math.min(last.y, b.y);\n last.height = Math.max(last.height, b.height);\n last.width = right - last.x;\n } else merged.push({ ...b });\n }\n return merged.map((b) => ({ x: clamp01(b.x), y: clamp01(b.y), width: Math.min(b.width, 1 - clamp01(b.x)), height: Math.min(b.height, 1 - clamp01(b.y)) }));\n}\n\nconst clamp01 = (n: number) => Math.min(1, Math.max(0, n));\n\n/** The shortest opening worth highlighting alone: a few words, not a stray letter. */\nconst MIN_START = 24;\n\n/**\n * Where `quote` sits in the pages: the first page (starting with `hintPage`, if any) whose text contains it, and the\n * boxes of its lines. A quote that a different layout cut (a column break, a hyphen) is looked for by its opening\n * words (`match: \"start\"`); one that is nowhere gives `null`, or the hinted page alone (`match: \"page\"`). Never a guess:\n * a rotated page has no boxes, only its page.\n */\nexport function locateQuote(pages: readonly PageText[], quote: string, hintPage?: number): Located | null {\n const needle = fold(quote);\n const ordered = hintPage ? [...pages].sort((a, b) => Number(b.page === hintPage) - Number(a.page === hintPage)) : pages;\n if (needle.length > 0) {\n for (const mode of [\"exact\", \"start\"] as const) {\n const wanted = mode === \"exact\" ? needle : needle.slice(0, Math.max(MIN_START, Math.min(40, Math.floor(needle.length * 0.6))));\n if (mode === \"start\" && (needle.length <= wanted.length || wanted.length < MIN_START)) break;\n for (const page of ordered) {\n const index = indexPage(page.items);\n const found = index.text.indexOf(wanted);\n if (found < 0) continue;\n return { page: page.page, boxes: boxesOf(page, index, found, found + wanted.length), match: mode };\n }\n }\n }\n return hintPage && pages.some((p) => p.page === hintPage) ? { page: hintPage, boxes: [], match: \"page\" } : null;\n}\n"],"mappings":";;;;;;;AAOA,YAAY,WAAW;AACvB,SAAS,UAAU;;;ACanB,IAAM,OAA+B,EAAE,UAAK,KAAK,UAAK,KAAK,UAAK,KAAK,UAAK,KAAK,QAAK,KAAK,QAAK,KAAK,UAAK,KAAK,UAAK,KAAK,QAAK,KAAK,UAAK,KAAK,UAAK,MAAM,UAAK,KAAK;AAGzJ,SAAS,KAAK,MAAsB;AACzC,MAAI,MAAM;AACV,aAAW,MAAM,KAAK,UAAU,MAAM,GAAG;AACvC,QAAI,SAAS,KAAK,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,OAAO,UAAO,OAAO,SAAK;AACrE,YAAQ,KAAK,EAAE,KAAK,IAAI,YAAY;AAAA,EACtC;AACA,SAAO;AACT;AAIA,SAAS,UAAU,OAAmC;AACpD,MAAI,OAAO;AACX,QAAM,KAAkB,CAAC;AACzB,QAAM,QAAQ,CAAC,MAAM,MAAM;AACzB,aAAS,IAAI,GAAG,IAAI,KAAK,IAAI,QAAQ,KAAK;AACxC,YAAM,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAE;AAC/B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,gBAAQ,MAAM,CAAC;AACf,WAAG,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAAA,MAC9B;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAO,EAAE,MAAM,GAAG;AACpB;AAEA,SAAS,QAAQ,MAAgB,OAAc,MAAc,IAAmB;AAC9E,QAAM,QAAQ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AO,EAAE,aAAa,GAAG,KAAK,KAAK,MAAM,KAAK,MAAM,GAAG,GAC/G;AAAA,8BAAC,cAAW,MAAM,EAAE,MAAM,KAAK,MAAM,KAAK,SAAkB,WAAW,EAAE,OAAO,GAAG;AAAA,UACnF,oBAAC,UAAK,WAAW,EAAE,QAAQ,GAAG,eAAY,QAAQ,mBAAQ;AAAA,UACzD,WAAW,QAAQ,CAAC,MAAM;AACzB,kBAAM,IAAI,MAAM,EAAE,EAAE;AACpB,gBAAI,CAAC,KAAK,EAAE,SAAS,EAAE,KAAM,QAAO,CAAC;AACrC,mBAAO,EAAE,MAAM,IAAI,CAAC,GAAG,MACrB;AAAA,cAAC;AAAA;AAAA,gBAEC,eAAY;AAAA,gBACZ,kBAAgB,EAAE;AAAA,gBAClB,eAAa,EAAE,OAAO;AAAA,gBACtB,WAAW,EAAE,IAAI;AAAA,gBACjB,OAAO,EAAE,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,KAAK,GAAG,EAAE,IAAI,GAAG,KAAK,OAAO,GAAG,EAAE,QAAQ,GAAG,KAAK,QAAQ,GAAG,EAAE,SAAS,GAAG,IAAI;AAAA,gBAC/G,SAAS,MAAM,iBAAiB,EAAE,OAAO,WAAW,OAAO,EAAE,EAAE;AAAA;AAAA,cAN1D,GAAG,EAAE,EAAE,IAAI,CAAC;AAAA,YAOnB,CACD;AAAA,UACH,CAAC;AAAA,aAjBO,EAAE,IAkBZ;AAAA,MAEJ,CAAC,IACD;AAAA,OACN;AAAA,KACF;AAEJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "The Krizaka front-end platform's components: the primitives (button, card, dialog, toast, menu, field, tabs, chip, switch, slider, command palette, theme, countdown…) on the semantic --kz-* tokens, the animated marks (Krizaka, Orazaka, Orochia, Yasakia, Yororis) and the motion signature — web and /native.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"krizaka",
|
|
@@ -333,6 +333,10 @@
|
|
|
333
333
|
"types": "./dist/image-cropper.d.ts",
|
|
334
334
|
"import": "./dist/image-cropper.js"
|
|
335
335
|
},
|
|
336
|
+
"./document-viewer": {
|
|
337
|
+
"types": "./dist/document-viewer.d.ts",
|
|
338
|
+
"import": "./dist/document-viewer.js"
|
|
339
|
+
},
|
|
336
340
|
"./list": {
|
|
337
341
|
"types": "./dist/list.d.ts",
|
|
338
342
|
"import": "./dist/list.js"
|
|
@@ -621,7 +625,7 @@
|
|
|
621
625
|
],
|
|
622
626
|
"peerDependencies": {
|
|
623
627
|
"@krizaka/query": ">=0.2.1",
|
|
624
|
-
"@krizaka/tailwind": ">=3.
|
|
628
|
+
"@krizaka/tailwind": ">=3.16.0",
|
|
625
629
|
"@maplibre/maplibre-react-native": ">=11",
|
|
626
630
|
"@shopify/flash-list": ">=2",
|
|
627
631
|
"expo-camera": ">=16",
|
|
@@ -629,6 +633,7 @@
|
|
|
629
633
|
"expo-video": ">=2",
|
|
630
634
|
"hls.js": ">=1.5",
|
|
631
635
|
"maplibre-gl": ">=6",
|
|
636
|
+
"pdfjs-dist": ">=5",
|
|
632
637
|
"react": ">=18",
|
|
633
638
|
"react-dom": ">=18",
|
|
634
639
|
"react-native": ">=0.76",
|
|
@@ -664,6 +669,7 @@
|
|
|
664
669
|
"jest": "30.4.2",
|
|
665
670
|
"jest-environment-node": "30.4.1",
|
|
666
671
|
"maplibre-gl": "6.11.2",
|
|
672
|
+
"pdfjs-dist": "6.4.299",
|
|
667
673
|
"publint": "^0.3.25",
|
|
668
674
|
"react": "^19.2.0",
|
|
669
675
|
"react-docgen-typescript": "^2.4.0",
|
|
@@ -679,8 +685,8 @@
|
|
|
679
685
|
"typescript": "^5.9.0",
|
|
680
686
|
"vitest": "^4.1.11",
|
|
681
687
|
"zod": "^4.6.5",
|
|
682
|
-
"@krizaka/
|
|
683
|
-
"@krizaka/
|
|
688
|
+
"@krizaka/query": "0.2.1",
|
|
689
|
+
"@krizaka/config": "0.4.1"
|
|
684
690
|
},
|
|
685
691
|
"engines": {
|
|
686
692
|
"node": ">=22"
|
|
@@ -716,6 +722,9 @@
|
|
|
716
722
|
"maplibre-gl": {
|
|
717
723
|
"optional": true
|
|
718
724
|
},
|
|
725
|
+
"pdfjs-dist": {
|
|
726
|
+
"optional": true
|
|
727
|
+
},
|
|
719
728
|
"react-dom": {
|
|
720
729
|
"optional": true
|
|
721
730
|
},
|
|
@@ -1402,6 +1411,16 @@
|
|
|
1402
1411
|
"clsx"
|
|
1403
1412
|
]
|
|
1404
1413
|
},
|
|
1414
|
+
{
|
|
1415
|
+
"name": "./document-viewer",
|
|
1416
|
+
"path": "dist/document-viewer.js",
|
|
1417
|
+
"limit": "5 kB",
|
|
1418
|
+
"gzip": true,
|
|
1419
|
+
"ignore": [
|
|
1420
|
+
"tailwind-variants",
|
|
1421
|
+
"clsx"
|
|
1422
|
+
]
|
|
1423
|
+
},
|
|
1405
1424
|
{
|
|
1406
1425
|
"name": "./list",
|
|
1407
1426
|
"path": "dist/list.js",
|
|
@@ -2105,8 +2124,8 @@
|
|
|
2105
2124
|
"sonner": "^2.0.8",
|
|
2106
2125
|
"tailwind-variants": "^3.3.1",
|
|
2107
2126
|
"@krizaka/intl": "^0.2.1",
|
|
2108
|
-
"@krizaka/
|
|
2109
|
-
"@krizaka/
|
|
2127
|
+
"@krizaka/pacer": "^0.1.0",
|
|
2128
|
+
"@krizaka/tokens": "^3.16.0"
|
|
2110
2129
|
},
|
|
2111
2130
|
"scripts": {
|
|
2112
2131
|
"build": "node -e \"const fs=require('node:fs');fs.rmSync('dist',{recursive:true,force:true});for(const f of fs.readdirSync('registry/examples',{recursive:true}))if(/\\.(js|d\\.ts)$/.test(f))fs.rmSync('registry/examples/'+f)\" && tsup && node -e \"require('node:fs').copyFileSync('src/motion.css','dist/motion.css');require('node:fs').copyFileSync('src/blocks.css','dist/blocks.css');require('node:fs').copyFileSync('src/story.css','dist/story.css')\" && node scripts/build-registry.mjs",
|