@kyrven/react-pdf-viewer 0.4.0-beta.2 → 0.4.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 CHANGED
@@ -4,10 +4,10 @@ A React component for viewing PDFs in the browser. Hayro parses and rasterizes p
4
4
 
5
5
  ## Install and render a PDF
6
6
 
7
- In a React application using Vite, install the beta from npm:
7
+ In a React application using Vite, install the viewer from npm:
8
8
 
9
9
  ```sh
10
- npm install @kyrven/react-pdf-viewer@beta
10
+ npm install @kyrven/react-pdf-viewer
11
11
  ```
12
12
 
13
13
  Place a PDF at `public/invoice.pdf`, then render the component:
@@ -31,11 +31,14 @@ Vite packages the worker and WASM automatically. Use a modern browser with modul
31
31
  | `layout` | Initial reading mode, either `continuous` (default) or `single`. |
32
32
  | `initialZoom` | Initial zoom factor, from 0.25 to 3. |
33
33
  | `height` | Viewport height as a CSS length or a number of pixels. |
34
- | `toolbar` | Visible controls. Choose from `page`, `zoom` and `settings`. |
34
+ | `toolbar` | Visible controls. The default includes `page`, `zoom`, `settings` and `download`. |
35
35
  | `maxCachedPages` | Maximum number of cached canvases, from 1 to 6. |
36
36
  | `maxFileBytes`, `maxPages` | Reduce the default limits of 64 MiB and 2,000 pages per document. |
37
+ | `theme` | Use `light` (default), `dark`, `system` or `custom`. A saved reader preference takes precedence unless the application sets `custom`. |
38
+ | `accentColor` | Initial custom accent in hexadecimal, for example `#7464D8`. Accepts three or six digits. |
39
+ | `downloadName` | Optional filename for the downloaded PDF. Defaults to the source filename or `documento.pdf`. |
37
40
 
38
- Pass these fields in the `options` prop. The component also accepts `onLoad(pageCount)`, `onPageChange(page)` and `onError(error)`. It displays rasterized pages with zoom and navigation. Text selection, search and interactive forms are outside the current feature set.
41
+ Pass these fields in the `options` prop. Readers can change the layout from the Options button and choose light, dark or system appearance when the application allows it. The viewer remembers the preference for the current site in the browser. System appearance follows the browser color scheme and updates when it changes. Set `theme: "custom"` and `accentColor` in code to use your own palette. The download button saves the original PDF bytes. The component also accepts `onLoad(pageCount)`, `onPageChange(page)` and `onError(error)`. It displays rasterized pages with zoom and navigation. Text selection, search and interactive forms are outside the current feature set.
39
42
 
40
43
  ## Other bundlers
41
44
 
@@ -65,21 +68,12 @@ Commit the regenerated binary alongside its source changes. Review the dependenc
65
68
 
66
69
  ## License
67
70
 
68
- The project is distributed under the [MIT License](LICENSE). Third-party licenses and attributions are included in [THIRD-PARTY](THIRD-PARTY/).
71
+ The project is distributed under the [MIT License](LICENSE). Third-party licenses and attributions are included in [THIRD-PARTY](THIRD-PARTY/).
69
72
 
70
73
  ## Publish a release to npm
71
74
 
72
- Run the following commands from a clean, up-to-date main branch after committing and testing your changes. If the Rust engine changed, first rebuild it with `npm run build:engine` and include the updated WASM in your commit.
75
+ Prepare the release from an up-to-date main branch. Choose a patch, minor or major version according to the changes. If the Rust engine changed, rebuild it and include the updated WASM.
73
76
 
74
- ```sh
75
- npm ci
76
- npm run build
77
- npm version prerelease --preid=beta
78
- npm publish --access public --tag beta
79
- git push origin main --follow-tags
80
- npm view @kyrven/react-pdf-viewer@beta version
81
- ```
82
-
83
- From 0.4.0-beta.1, this creates version 0.4.0-beta.2 and its Git tag. Complete the npm authentication prompt when publishing. The registry can take a few minutes to make the new version available. Verify it in a separate React application with `npm install @kyrven/react-pdf-viewer@beta`.
77
+ Install the dependencies, update the version and run `npm pack`. Install the resulting tarball in a separate React application and check the viewer in Vite development and production.
84
78
 
85
- For the first stable release in this series, use `npm version 0.4.0` and `npm publish --access public --tag latest`, then push the release commit and tag. Choose patch, minor or major for subsequent stable releases according to the changes.
79
+ Commit the version and source changes, then create and push the matching Git tag. Publish the tested tarball with `npm publish <tarball> --access public --tag latest` and confirm the public version with `npm view @kyrven/react-pdf-viewer@latest version`.
@@ -1,9 +1,14 @@
1
+ import { type PdfViewerTheme } from './theme.js';
1
2
  import { type EngineAssets, type PdfSource } from './document.js';
2
3
  import './viewer.css';
4
+ export type { PdfViewerTheme } from './theme.js';
3
5
  export interface PdfViewerOptions {
6
+ theme?: PdfViewerTheme;
7
+ accentColor?: string;
8
+ downloadName?: string;
4
9
  layout?: 'single' | 'continuous';
5
10
  initialZoom?: number;
6
- toolbar?: readonly ('page' | 'zoom' | 'settings')[];
11
+ toolbar?: readonly ('page' | 'zoom' | 'settings' | 'download')[];
7
12
  maxCachedPages?: number;
8
13
  maxFileBytes?: number;
9
14
  maxPages?: number;
@@ -1,26 +1,47 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from 'react';
4
+ import { saveThemePreference, useViewerTheme } from './theme.js';
4
5
  import { mountPages } from './pages.js';
5
6
  import { openPdf } from './document.js';
6
7
  import './viewer.css';
8
+ const defaultAccent = '#5262e8';
9
+ const themes = [
10
+ ['light', 'Claro'],
11
+ ['dark', 'Oscuro'],
12
+ ['system', 'Sistema'],
13
+ ];
14
+ function normalizeColor(value) {
15
+ const color = value?.trim().toLowerCase().replace(/^#/, '');
16
+ if (!color || !/^(?:[0-9a-f]{3}|[0-9a-f]{6})$/.test(color))
17
+ return undefined;
18
+ return '#' + (color.length === 3 ? color.replace(/./g, digit => digit.repeat(2)) : color);
19
+ }
7
20
  const boundedZoom = (value) => Number.isFinite(value) ? Math.max(0.25, Math.min(3, value)) : 1;
8
21
  export function PdfViewer({ src, assetsUrl, engine, options, onLoad, onPageChange, onError, }) {
9
22
  const [page, setPage] = useState(1);
10
23
  const [count, setCount] = useState(0);
11
24
  const [zoom, setZoom] = useState(1);
12
25
  const [error, setError] = useState('');
26
+ const [download, setDownload] = useState(null);
13
27
  const viewport = useRef(null);
14
28
  const view = useRef(null);
15
29
  const callbacks = useRef({ onLoad, onPageChange, onError });
16
30
  const pageInputId = useId();
31
+ const settingsId = useId();
32
+ const themeName = useId();
33
+ const settingsButton = useRef(null);
34
+ const [settingsOpen, setSettingsOpen] = useState(false);
35
+ const initialTheme = options?.theme ?? 'light';
36
+ const accentColor = normalizeColor(options?.accentColor) ?? defaultAccent;
37
+ const { selectedTheme, theme } = useViewerTheme(initialTheme);
17
38
  const initialZoom = boundedZoom(options?.initialZoom ?? 1);
18
39
  const initialLayout = options?.layout ?? 'continuous';
19
40
  const [layout, setLayout] = useState(initialLayout);
20
41
  useEffect(() => setLayout(initialLayout), [initialLayout]);
21
42
  const continuous = layout === 'continuous';
22
43
  const { maxFileBytes, maxPages } = options ?? {};
23
- const toolbar = options?.toolbar ?? ['page', 'zoom', 'settings'];
44
+ const toolbar = options?.toolbar ?? ['page', 'zoom', 'settings', 'download'];
24
45
  const requestedCache = options?.maxCachedPages ?? 6;
25
46
  const cacheLimit = Number.isFinite(requestedCache)
26
47
  ? Math.min(6, Math.max(1, Math.floor(requestedCache)))
@@ -42,6 +63,7 @@ export function PdfViewer({ src, assetsUrl, engine, options, onLoad, onPageChang
42
63
  setError('');
43
64
  setPage(1);
44
65
  setCount(0);
66
+ setDownload(null);
45
67
  setZoom(initialZoom);
46
68
  const fail = (reason) => {
47
69
  if (abort.signal.aborted)
@@ -64,6 +86,7 @@ export function PdfViewer({ src, assetsUrl, engine, options, onLoad, onPageChang
64
86
  callbacks.current.onPageChange?.(number);
65
87
  }, fail);
66
88
  setCount(document.pageCount);
89
+ setDownload({ source: src, save: document.save });
67
90
  callbacks.current.onLoad?.(document.pageCount);
68
91
  callbacks.current.onPageChange?.(1);
69
92
  })
@@ -80,10 +103,17 @@ export function PdfViewer({ src, assetsUrl, engine, options, onLoad, onPageChang
80
103
  setZoom(updated);
81
104
  view.current?.setZoom(updated);
82
105
  }
83
- return (_jsxs("section", { className: "krpdf", "aria-label": "Visor PDF", children: [toolbar.length > 0 && (_jsxs("div", { className: "krpdf-controls", children: [toolbar.includes('page') && (_jsxs("form", { onSubmit: (event) => {
84
- event.preventDefault();
85
- const number = Number(new FormData(event.currentTarget).get('page'));
86
- if (Number.isInteger(number) && number > 0)
87
- view.current?.goTo(number);
88
- }, children: [_jsx("button", { type: "button", disabled: page <= 1 || !count, onClick: () => view.current?.goTo(page - 1), "aria-label": "P\u00E1gina anterior", children: "\u2039" }), _jsx("label", { htmlFor: pageInputId, children: "P\u00E1gina" }), _jsx("input", { id: pageInputId, disabled: !count, name: "page", type: "number", min: 1, max: count || 1, defaultValue: page }, page), _jsxs("span", { children: ["/ ", count || '—'] }), _jsx("button", { type: "button", disabled: page >= count, onClick: () => view.current?.goTo(page + 1), "aria-label": "P\u00E1gina siguiente", children: "\u203A" })] })), toolbar.includes('zoom') && (_jsxs("div", { role: "group", "aria-label": "Zoom", children: [_jsx("button", { type: "button", disabled: !count || zoom <= 0.25, onClick: () => changeZoom(-0.25), "aria-label": "Reducir zoom", children: "\u2212" }), _jsxs("span", { children: [Math.round(zoom * 100), " %"] }), _jsx("button", { type: "button", disabled: !count || zoom >= 3, onClick: () => changeZoom(0.25), "aria-label": "Aumentar zoom", children: "+" })] })), toolbar.includes('settings') && (_jsxs("details", { className: "krpdf-settings", children: [_jsx("summary", { children: "Opciones" }), _jsxs("label", { children: ["Vista", _jsxs("select", { value: layout, onChange: event => setLayout(event.currentTarget.value === 'single' ? 'single' : 'continuous'), children: [_jsx("option", { value: "continuous", children: "Scroll continuo" }), _jsx("option", { value: "single", children: "Una p\u00E1gina" })] })] })] }))] })), error && (_jsx("p", { className: "krpdf-message", role: "alert", children: error })), !error && !count && (_jsx("p", { className: "krpdf-message", role: "status", children: "Abriendo PDF\u2026" })), _jsx("div", { ref: viewport, className: "krpdf-viewport", style: { height: options?.height }, tabIndex: 0, "aria-label": "P\u00E1ginas del PDF" })] }));
106
+ const style = theme === 'custom' ? { '--krpdf-accent': accentColor } : undefined;
107
+ return (_jsxs("section", { className: "krpdf", "data-theme": theme, style: style, "aria-label": "Visor PDF", children: [toolbar.length > 0 && (_jsxs("div", { className: "krpdf-toolbar", onKeyDown: event => {
108
+ if (event.key !== 'Escape' || !settingsOpen)
109
+ return;
110
+ event.stopPropagation();
111
+ setSettingsOpen(false);
112
+ settingsButton.current?.focus();
113
+ }, children: [_jsxs("div", { className: "krpdf-controls", children: [toolbar.includes('page') && (_jsxs("form", { className: "krpdf-control-group", onSubmit: (event) => {
114
+ event.preventDefault();
115
+ const number = Number(new FormData(event.currentTarget).get('page'));
116
+ if (Number.isInteger(number) && number > 0)
117
+ view.current?.goTo(number);
118
+ }, children: [_jsx("button", { type: "button", disabled: page <= 1 || !count, onClick: () => view.current?.goTo(page - 1), "aria-label": "P\u00E1gina anterior", children: _jsx("span", { className: "krpdf-chevron krpdf-chevron-prev", "aria-hidden": "true" }) }), _jsx("label", { htmlFor: pageInputId, children: "P\u00E1gina" }), _jsx("input", { id: pageInputId, disabled: !count, name: "page", type: "number", min: 1, max: count || 1, defaultValue: page }, page), _jsxs("span", { className: "krpdf-page-count", children: ["/ ", count || '—'] }), _jsx("button", { type: "button", disabled: page >= count, onClick: () => view.current?.goTo(page + 1), "aria-label": "P\u00E1gina siguiente", children: _jsx("span", { className: "krpdf-chevron", "aria-hidden": "true" }) })] })), toolbar.includes('zoom') && (_jsxs("div", { className: "krpdf-control-group", role: "group", "aria-label": "Zoom", children: [_jsx("button", { type: "button", disabled: !count || zoom <= 0.25, onClick: () => changeZoom(-0.25), "aria-label": "Reducir zoom", children: "\u2212" }), _jsxs("span", { className: "krpdf-zoom", children: [Math.round(zoom * 100), " %"] }), _jsx("button", { type: "button", disabled: !count || zoom >= 3, onClick: () => changeZoom(0.25), "aria-label": "Aumentar zoom", children: "+" })] })), (toolbar.includes('settings') || toolbar.includes('download')) && (_jsxs("div", { className: "krpdf-actions", children: [toolbar.includes('download') && (_jsxs("button", { className: "krpdf-download-button", type: "button", disabled: download?.source !== src, onClick: () => download?.save(options?.downloadName), children: [_jsx("span", { className: "krpdf-download-icon", "aria-hidden": "true" }), "Descargar PDF"] })), toolbar.includes('settings') && (_jsxs("button", { className: "krpdf-settings-button", type: "button", ref: settingsButton, "aria-expanded": settingsOpen, "aria-controls": settingsId, onClick: () => setSettingsOpen(open => !open), children: [_jsx("span", { className: "krpdf-gear", "aria-hidden": "true", children: "\u2699\uFE0E" }), "Opciones"] }))] }))] }), toolbar.includes('settings') && (_jsxs("div", { className: "krpdf-settings", id: settingsId, hidden: !settingsOpen, children: [_jsxs("label", { className: "krpdf-field", children: ["Vista", _jsxs("select", { value: layout, onChange: event => setLayout(event.currentTarget.value === 'single' ? 'single' : 'continuous'), children: [_jsx("option", { value: "continuous", children: "Scroll continuo" }), _jsx("option", { value: "single", children: "Una p\u00E1gina" })] })] }), initialTheme !== 'custom' && (_jsxs("fieldset", { className: "krpdf-field", children: [_jsx("legend", { children: "Apariencia" }), _jsx("div", { className: "krpdf-theme-options", children: themes.map(([value, label]) => (_jsxs("label", { children: [_jsx("input", { type: "radio", name: themeName, value: value, checked: selectedTheme === value, onChange: () => saveThemePreference(value) }), _jsx("span", { children: label })] }, value))) })] }))] }))] })), error && (_jsx("p", { className: "krpdf-message", role: "alert", children: error })), !error && !count && (_jsx("p", { className: "krpdf-message", role: "status", children: "Abriendo PDF\u2026" })), _jsx("div", { ref: viewport, className: "krpdf-viewport", style: { height: options?.height }, tabIndex: 0, "aria-label": "P\u00E1ginas del PDF" })] }));
89
119
  }
@@ -11,5 +11,6 @@ export declare function openPdf(source: PdfSource, assetsUrl: string, signal: Ab
11
11
  width: number;
12
12
  height: number;
13
13
  }>;
14
+ save: (name?: string) => void;
14
15
  close: () => void;
15
16
  }>;
@@ -1,4 +1,4 @@
1
- import { readPdf } from './source.js';
1
+ import { pdfDownloadName, readPdf } from './source.js';
2
2
  const MiB = 1024 * 1024;
3
3
  const deadline = 30_000;
4
4
  function bounded(value, maximum) {
@@ -121,7 +121,23 @@ export async function openPdf(source, assetsUrl, signal, maxFileBytes, maxPages,
121
121
  rendering = false;
122
122
  }
123
123
  }
124
- return { pageCount, render, close };
124
+ function save(name) {
125
+ if (!file)
126
+ return;
127
+ const link = document.createElement('a');
128
+ link.download = pdfDownloadName(source, name);
129
+ const downloadUrl = URL.createObjectURL(file);
130
+ link.href = downloadUrl;
131
+ try {
132
+ document.body.append(link);
133
+ link.click();
134
+ }
135
+ finally {
136
+ link.remove();
137
+ setTimeout(() => URL.revokeObjectURL(downloadUrl), 30_000);
138
+ }
139
+ }
140
+ return { pageCount, render, save, close };
125
141
  }
126
142
  catch (error) {
127
143
  close();
@@ -1,4 +1,4 @@
1
1
  import { type PdfViewerProps } from './PdfViewer.js';
2
2
  export declare function PdfViewer(props: PdfViewerProps): import("react").JSX.Element;
3
- export type { PdfViewerProps, PdfViewerOptions } from './PdfViewer.js';
3
+ export type { PdfViewerProps, PdfViewerOptions, PdfViewerTheme } from './PdfViewer.js';
4
4
  export type { PdfSource } from './source.js';
package/dist-lib/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { PdfViewer as Viewer } from './PdfViewer.js';
4
- const workerUrl = new URL('@kyrven/react-pdf-viewer/pdf.worker.mjs?no-inline', import.meta.url).href;
5
- const wasmUrl = new URL('@kyrven/react-pdf-viewer/hayro.wasm', import.meta.url).href;
4
+ // The private alias lets Vite externalize the worker during dependency optimization.
5
+ import workerUrl from '#hayro-worker.txt?url&no-inline';
6
+ import wasmUrl from './engine/hayro.wasm?url&no-inline';
6
7
  const engine = { workerUrl, wasmUrl };
7
8
  export function PdfViewer(props) {
8
9
  return _jsx(Viewer, { ...props, engine: engine });
@@ -1,2 +1,3 @@
1
1
  export type PdfSource = Blob | Uint8Array | string | URL;
2
+ export declare function pdfDownloadName(source: PdfSource, preferred?: string): string;
2
3
  export declare function readPdf(source: PdfSource, maximum: number, signal: AbortSignal): Promise<Blob>;
@@ -1,3 +1,22 @@
1
+ export function pdfDownloadName(source, preferred) {
2
+ let name = preferred?.trim();
3
+ if (!name && source instanceof File)
4
+ name = source.name;
5
+ if (!name && (typeof source === 'string' || source instanceof URL)) {
6
+ const url = new URL(source, document.baseURI);
7
+ if (url.protocol !== 'blob:') {
8
+ const segment = url.pathname.split('/').pop() ?? '';
9
+ try {
10
+ name = decodeURIComponent(segment);
11
+ }
12
+ catch {
13
+ name = segment;
14
+ }
15
+ }
16
+ }
17
+ const safeName = name?.replace(/[<>:"/\\|?*\u0000-\u001f\u007f]/g, '_').trim().replace(/[. ]+$/, '') || 'documento';
18
+ return /\.pdf$/i.test(safeName) ? safeName : safeName + '.pdf';
19
+ }
1
20
  export async function readPdf(source, maximum, signal) {
2
21
  function check(size) {
3
22
  if (size > maximum)
@@ -1,2 +1,2 @@
1
- export { PdfViewer, type PdfViewerProps, type PdfViewerOptions } from './PdfViewer.js';
1
+ export { PdfViewer, type PdfViewerProps, type PdfViewerOptions, type PdfViewerTheme } from './PdfViewer.js';
2
2
  export type { PdfSource } from './document.js';
@@ -0,0 +1,8 @@
1
+ type ThemePreference = 'light' | 'dark' | 'system';
2
+ export type PdfViewerTheme = ThemePreference | 'custom';
3
+ export declare function saveThemePreference(value: ThemePreference): void;
4
+ export declare function useViewerTheme(initialTheme: PdfViewerTheme): {
5
+ selectedTheme: string;
6
+ theme: string;
7
+ };
8
+ export {};
@@ -0,0 +1,56 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ const storageKey = '@kyrven/react-pdf-viewer:theme';
3
+ const changeEvent = storageKey + ':change';
4
+ const systemDarkQuery = '(prefers-color-scheme: dark)';
5
+ let temporaryPreference = null;
6
+ function readPreference() {
7
+ if (temporaryPreference)
8
+ return temporaryPreference;
9
+ try {
10
+ const value = window.localStorage.getItem(storageKey);
11
+ if (value === 'light' || value === 'dark' || value === 'system')
12
+ return value;
13
+ }
14
+ catch {
15
+ // An embedded viewer may run with browser storage disabled.
16
+ }
17
+ return null;
18
+ }
19
+ export function saveThemePreference(value) {
20
+ try {
21
+ window.localStorage.setItem(storageKey, value);
22
+ temporaryPreference = null;
23
+ }
24
+ catch {
25
+ temporaryPreference = value;
26
+ }
27
+ window.dispatchEvent(new Event(changeEvent));
28
+ }
29
+ function subscribePreference(onChange) {
30
+ function handleStorage(event) {
31
+ if (event.key === storageKey || event.key === null)
32
+ onChange();
33
+ }
34
+ window.addEventListener('storage', handleStorage);
35
+ window.addEventListener(changeEvent, onChange);
36
+ return () => {
37
+ window.removeEventListener('storage', handleStorage);
38
+ window.removeEventListener(changeEvent, onChange);
39
+ };
40
+ }
41
+ function subscribeSystemTheme(onChange) {
42
+ const query = window.matchMedia(systemDarkQuery);
43
+ query.addEventListener('change', onChange);
44
+ return () => query.removeEventListener('change', onChange);
45
+ }
46
+ const getSystemDark = () => window.matchMedia(systemDarkQuery).matches;
47
+ const noPreference = () => null;
48
+ const defaultSystemDark = () => false;
49
+ export function useViewerTheme(initialTheme) {
50
+ const preference = useSyncExternalStore(subscribePreference, readPreference, noPreference);
51
+ const systemDark = useSyncExternalStore(subscribeSystemTheme, getSystemDark, defaultSystemDark);
52
+ const selectedTheme = initialTheme === 'custom' ? 'custom' : preference ?? initialTheme;
53
+ const systemTheme = systemDark ? 'dark' : 'light';
54
+ const theme = selectedTheme === 'system' ? systemTheme : selectedTheme;
55
+ return { selectedTheme, theme };
56
+ }
@@ -1,59 +1,356 @@
1
1
  .krpdf {
2
- --krpdf-surface: #fff;
3
- --krpdf-border: #a9b7ca;
4
- --krpdf-text: #202b42;
5
- --krpdf-backdrop: #e4ebf4;
6
- border: 1px solid var(--krpdf-border);
7
- border-radius: 0.65rem;
2
+ --krpdf-accent: #5262e8;
3
+ --krpdf-surface: #ffffff;
4
+ --krpdf-panel: #f7f8fc;
5
+ --krpdf-control: #ffffff;
6
+ --krpdf-control-hover: #edf0f8;
7
+ --krpdf-line: #dce1ed;
8
+ --krpdf-text: #182238;
9
+ --krpdf-muted: #4e5b73;
10
+ --krpdf-backdrop: #e8ecf5;
11
+ --krpdf-dot: #6479a32d;
12
+ --krpdf-danger: #a32243;
13
+ --krpdf-paper-shadow: 0 3px 8px #21345114, 0 14px 35px #21345124;
14
+ --krpdf-accent-soft: color-mix(in srgb, var(--krpdf-accent) 12%, var(--krpdf-surface));
15
+ --krpdf-accent-edge: color-mix(in srgb, var(--krpdf-accent) 37%, var(--krpdf-line));
16
+ --krpdf-accent-text: color-mix(in srgb, var(--krpdf-accent) 48%, var(--krpdf-text));
17
+ color-scheme: light;
18
+ min-width: 0;
8
19
  overflow: hidden;
20
+ isolation: isolate;
21
+ border: 1px solid var(--krpdf-line);
22
+ border-radius: 1rem;
23
+ background: var(--krpdf-surface);
24
+ color: var(--krpdf-text);
25
+ box-shadow: 0 1px 2px #1524400a, 0 12px 36px #15244012;
26
+ font-family: "Segoe UI Variable Text", "Aptos", "Segoe UI", system-ui, sans-serif;
27
+ font-size: 0.875rem;
28
+ line-height: 1.45;
29
+ }
30
+
31
+ .krpdf[data-theme="dark"] {
32
+ --krpdf-accent: #a8b2ff;
33
+ --krpdf-surface: #151a26;
34
+ --krpdf-panel: #1a2130;
35
+ --krpdf-control: #222a3b;
36
+ --krpdf-control-hover: #2b354a;
37
+ --krpdf-line: #39455c;
38
+ --krpdf-text: #f2f4fc;
39
+ --krpdf-muted: #b3bed4;
40
+ --krpdf-backdrop: #0e1320;
41
+ --krpdf-dot: #a3b1e125;
42
+ --krpdf-danger: #ff96ad;
43
+ --krpdf-paper-shadow: 0 3px 8px #0005, 0 14px 36px #0008;
44
+ color-scheme: dark;
45
+ }
46
+
47
+ .krpdf[data-theme="custom"] {
48
+ --krpdf-panel: color-mix(in srgb, var(--krpdf-accent) 6%, #f9fafc);
49
+ --krpdf-control-hover: color-mix(in srgb, var(--krpdf-accent) 12%, #f9fafc);
50
+ --krpdf-line: color-mix(in srgb, var(--krpdf-accent) 18%, #dce1ed);
51
+ --krpdf-backdrop: color-mix(in srgb, var(--krpdf-accent) 13%, #edf0f6);
52
+ --krpdf-dot: color-mix(in srgb, var(--krpdf-accent) 24%, transparent);
53
+ }
54
+
55
+ .krpdf-toolbar {
56
+ position: relative;
57
+ z-index: 1;
58
+ border-bottom: 1px solid var(--krpdf-line);
59
+ }
60
+
61
+ .krpdf-controls {
62
+ display: flex;
63
+ align-items: center;
64
+ flex-wrap: wrap;
65
+ gap: 0.5rem 0.75rem;
66
+ padding: 0.6875rem 0.875rem;
67
+ }
68
+
69
+ .krpdf-control-group,
70
+ .krpdf-theme-options {
71
+ display: flex;
72
+ align-items: center;
73
+ gap: 0.25rem;
9
74
  min-width: 0;
75
+ margin: 0;
76
+ padding: 0.1875rem;
77
+ border: 1px solid var(--krpdf-line);
78
+ border-radius: 0.75rem;
79
+ background: var(--krpdf-panel);
80
+ }
81
+
82
+ .krpdf-control-group label,
83
+ .krpdf-page-count {
84
+ color: var(--krpdf-muted);
85
+ font-size: 0.8125rem;
86
+ font-weight: 600;
87
+ }
88
+
89
+ .krpdf-page-count {
90
+ white-space: nowrap;
91
+ padding-inline: 0.15rem;
92
+ }
93
+
94
+ .krpdf-control-group button,
95
+ .krpdf-control-group input,
96
+ .krpdf-settings-button,
97
+ .krpdf-download-button,
98
+ .krpdf-settings select {
99
+ box-sizing: border-box;
100
+ min-height: 2.125rem;
10
101
  color: var(--krpdf-text);
11
- background: var(--krpdf-surface);
102
+ font: inherit;
103
+ border: 1px solid var(--krpdf-line);
104
+ border-radius: 0.5rem;
105
+ background: var(--krpdf-control);
12
106
  }
13
107
 
14
- .krpdf-controls,
15
- .krpdf-controls form,
16
- .krpdf-controls [role='group'] {
108
+ .krpdf-control-group button,
109
+ .krpdf-settings-button,
110
+ .krpdf-download-button {
111
+ display: inline-grid;
112
+ place-items: center;
113
+ cursor: pointer;
114
+ transition: background-color 120ms ease, border-color 120ms ease;
115
+ }
116
+
117
+ .krpdf-control-group button {
118
+ min-width: 2.125rem;
119
+ padding: 0.25rem;
120
+ border-color: transparent;
121
+ background: transparent;
122
+ font-size: 1.125rem;
123
+ line-height: 1;
124
+ }
125
+
126
+ .krpdf-control-group button:enabled:hover {
127
+ border-color: var(--krpdf-line);
128
+ background: var(--krpdf-control-hover);
129
+ }
130
+
131
+ .krpdf-control-group button:disabled,
132
+ .krpdf-control-group input:disabled,
133
+ .krpdf-download-button:disabled {
134
+ opacity: 0.48;
135
+ cursor: default;
136
+ }
137
+
138
+ .krpdf-control-group input {
139
+ width: 3.5rem;
140
+ padding: 0.25rem;
141
+ text-align: center;
142
+ appearance: textfield;
143
+ font-weight: 650;
144
+ font-variant-numeric: tabular-nums;
145
+ }
146
+
147
+ .krpdf-control-group input::-webkit-inner-spin-button,
148
+ .krpdf-control-group input::-webkit-outer-spin-button {
149
+ margin: 0;
150
+ -webkit-appearance: none;
151
+ }
152
+
153
+ .krpdf-chevron {
154
+ width: 0.42rem;
155
+ height: 0.42rem;
156
+ border-right: 1.75px solid currentColor;
157
+ border-top: 1.75px solid currentColor;
158
+ transform: translateX(-0.06rem) rotate(45deg);
159
+ }
160
+
161
+ .krpdf-chevron-prev {
162
+ transform: translateX(0.06rem) rotate(-135deg);
163
+ }
164
+
165
+ .krpdf-zoom {
166
+ min-width: 3.25rem;
167
+ color: var(--krpdf-text);
168
+ text-align: center;
169
+ font-weight: 650;
170
+ font-variant-numeric: tabular-nums;
171
+ white-space: nowrap;
172
+ }
173
+
174
+ .krpdf-actions {
17
175
  display: flex;
176
+ flex-wrap: wrap;
177
+ gap: 0.5rem;
178
+ min-width: 0;
179
+ margin-inline-start: auto;
180
+ }
181
+
182
+ .krpdf-settings-button,
183
+ .krpdf-download-button {
184
+ display: inline-flex;
18
185
  align-items: center;
19
- gap: 0.35rem;
186
+ gap: 0.5rem;
187
+ min-height: 2.625rem;
188
+ padding: 0.35rem 0.85rem;
189
+ border-radius: 0.75rem;
190
+ font-weight: 700;
20
191
  }
21
- .krpdf-controls {
192
+
193
+ .krpdf-settings-button {
194
+ border-color: var(--krpdf-accent-edge);
195
+ background: var(--krpdf-accent-soft);
196
+ color: var(--krpdf-accent-text);
197
+ }
198
+
199
+ .krpdf-settings-button:hover,
200
+ .krpdf-settings-button[aria-expanded="true"] {
201
+ border-color: var(--krpdf-accent-text);
202
+ background: color-mix(in srgb, var(--krpdf-accent) 19%, var(--krpdf-surface));
203
+ }
204
+
205
+ .krpdf-download-button:enabled:hover {
206
+ border-color: var(--krpdf-accent-edge);
207
+ background: var(--krpdf-control-hover);
208
+ }
209
+
210
+ .krpdf-download-icon {
211
+ position: relative;
212
+ width: 0.875rem;
213
+ height: 0.75rem;
214
+ border-bottom: 1.5px solid currentColor;
215
+ }
216
+
217
+ .krpdf-download-icon::before,
218
+ .krpdf-download-icon::after {
219
+ position: absolute;
220
+ left: 50%;
221
+ content: "";
222
+ }
223
+
224
+ .krpdf-download-icon::before {
225
+ top: -0.1rem;
226
+ height: 0.56rem;
227
+ border-left: 1.5px solid currentColor;
228
+ transform: translateX(-50%);
229
+ }
230
+
231
+ .krpdf-download-icon::after {
232
+ top: 0.12rem;
233
+ width: 0.35rem;
234
+ height: 0.35rem;
235
+ border-right: 1.5px solid currentColor;
236
+ border-bottom: 1.5px solid currentColor;
237
+ transform: translateX(-50%) rotate(45deg);
238
+ }
239
+
240
+ .krpdf-gear {
241
+ font-family: "Segoe UI Symbol", system-ui, sans-serif;
242
+ font-size: 1.15rem;
243
+ line-height: 1;
244
+ }
245
+
246
+ .krpdf-settings:not([hidden]) {
247
+ display: flex;
248
+ align-items: flex-start;
22
249
  flex-wrap: wrap;
23
- padding: 0.55rem 0.7rem;
24
- column-gap: 0.85rem;
250
+ gap: 0.75rem 1.25rem;
251
+ padding: 0.75rem 0.875rem 0.875rem;
252
+ border-top: 1px solid var(--krpdf-line);
253
+ background: var(--krpdf-panel);
25
254
  }
26
- .krpdf-controls button,
27
- .krpdf-controls input {
28
- font: inherit;
29
- color: inherit;
30
- border: 1px solid var(--krpdf-border);
31
- border-radius: 0.35rem;
255
+
256
+ .krpdf-field {
257
+ display: flex;
258
+ flex-direction: column;
259
+ gap: 0.375rem;
260
+ min-width: 0;
261
+ margin: 0;
262
+ padding: 0;
263
+ border: 0;
264
+ color: var(--krpdf-muted);
265
+ font-size: 0.8125rem;
266
+ font-weight: 650;
267
+ }
268
+
269
+ .krpdf-field legend {
270
+ margin-bottom: 0.375rem;
271
+ padding: 0;
272
+ }
273
+
274
+ .krpdf-settings select {
275
+ min-height: 2.375rem;
276
+ padding: 0.375rem 0.625rem;
277
+ cursor: pointer;
278
+ }
279
+
280
+ .krpdf-theme-options {
281
+ width: fit-content;
282
+ flex-wrap: wrap;
283
+ gap: 0.125rem;
284
+ padding: 0.125rem;
285
+ border-radius: 0.625rem;
32
286
  background: var(--krpdf-surface);
33
- min-height: 2.1rem;
34
- padding: 0.2rem 0.4rem;
35
287
  }
36
- .krpdf-controls button {
37
- min-width: 2.1rem;
288
+
289
+ .krpdf-theme-options label {
290
+ position: relative;
38
291
  cursor: pointer;
39
292
  }
40
- .krpdf-controls button:disabled {
41
- opacity: 0.5;
42
- cursor: default;
293
+
294
+ .krpdf-theme-options input {
295
+ position: absolute;
296
+ width: 1px;
297
+ height: 1px;
298
+ opacity: 0;
299
+ }
300
+
301
+ .krpdf-theme-options span {
302
+ display: flex;
303
+ align-items: center;
304
+ min-height: 2rem;
305
+ padding-inline: 0.6rem;
306
+ border-radius: 0.4375rem;
307
+ white-space: nowrap;
43
308
  }
44
- .krpdf-controls input {
45
- width: 3.4rem;
309
+
310
+ .krpdf-theme-options label:hover span {
311
+ background: var(--krpdf-control-hover);
312
+ }
313
+
314
+ .krpdf-theme-options input:checked + span {
315
+ color: var(--krpdf-accent-text);
316
+ background: var(--krpdf-accent-soft);
317
+ box-shadow: inset 0 0 0 1px var(--krpdf-accent-edge);
318
+ }
319
+
320
+ .krpdf :is(button, input, select, .krpdf-viewport):focus-visible,
321
+ .krpdf-theme-options input:focus-visible + span {
322
+ outline: 2px solid var(--krpdf-accent-text);
323
+ outline-offset: 2px;
324
+ }
325
+
326
+ .krpdf-theme-options input:focus-visible {
327
+ outline: none;
46
328
  }
329
+
47
330
  .krpdf-message {
48
- padding: 0.45rem 0.7rem;
49
331
  margin: 0;
332
+ padding: 0.75rem 0.875rem;
333
+ background: var(--krpdf-panel);
334
+ color: var(--krpdf-muted);
335
+ }
336
+
337
+ .krpdf-message[role="alert"] {
338
+ color: var(--krpdf-danger);
50
339
  }
340
+
51
341
  .krpdf-viewport {
52
342
  position: relative;
53
343
  overflow: auto;
54
344
  height: min(65vh, 46rem);
55
- background: var(--krpdf-backdrop);
345
+ scrollbar-color: var(--krpdf-muted) var(--krpdf-backdrop);
346
+ background: radial-gradient(circle, var(--krpdf-dot) 1px, transparent 1.1px) 0 0 / 18px 18px,
347
+ var(--krpdf-backdrop);
56
348
  }
349
+
350
+ .krpdf .krpdf-viewport:focus-visible {
351
+ outline-offset: -2px;
352
+ }
353
+
57
354
  .krpdf-strip {
58
355
  position: relative;
59
356
  box-sizing: border-box;
@@ -62,15 +359,17 @@
62
359
  display: flex;
63
360
  flex-direction: column;
64
361
  align-items: center;
65
- gap: 0.8rem;
66
- padding: 0.8rem;
362
+ gap: 1rem;
363
+ padding: clamp(0.75rem, 2vw, 1.5rem);
67
364
  }
365
+
68
366
  .krpdf-sheet {
69
367
  position: relative;
70
- background: #fff;
71
368
  flex: none;
72
- box-shadow: 0 1px 8px #23365435;
369
+ background: #fff;
370
+ box-shadow: var(--krpdf-paper-shadow);
73
371
  }
372
+
74
373
  .krpdf-sheet canvas {
75
374
  position: absolute;
76
375
  inset: 0;
@@ -78,7 +377,17 @@
78
377
  width: 100%;
79
378
  height: 100%;
80
379
  }
81
- .krpdf-settings { margin-inline-start: auto; }
82
- .krpdf-settings summary { cursor: pointer; padding: .4rem; }
83
- .krpdf-settings label { display: flex; align-items: center; gap: .5rem; padding: .4rem; }
84
- .krpdf-settings select { font: inherit; color: inherit; background: var(--krpdf-surface); }
380
+
381
+ @media (prefers-reduced-motion: reduce) {
382
+ .krpdf-control-group button,
383
+ .krpdf-settings-button,
384
+ .krpdf-download-button {
385
+ transition: none;
386
+ }
387
+ }
388
+
389
+ @media (forced-colors: active) {
390
+ .krpdf-theme-options input:checked + span {
391
+ border: 1px solid Highlight;
392
+ }
393
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@kyrven/react-pdf-viewer",
3
- "version": "0.4.0-beta.2",
3
+ "version": "0.4.0",
4
4
  "description": "React PDF viewer powered by Hayro, a Rust rendering engine compiled to WebAssembly.",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=22.13.0"
8
8
  },
9
+ "imports": {
10
+ "#hayro-worker.txt": "./dist-lib/engine/pdf.worker.mjs"
11
+ },
9
12
  "exports": {
10
13
  ".": {
11
14
  "types": "./dist-lib/index.d.ts",
@@ -36,7 +39,7 @@
36
39
  },
37
40
  "publishConfig": {
38
41
  "access": "public",
39
- "tag": "beta",
42
+ "tag": "latest",
40
43
  "registry": "https://registry.npmjs.org/"
41
44
  },
42
45
  "peerDependencies": {