@embedpdf/react-pdf-viewer 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CloudPDF
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @embedpdf/react-pdf-viewer
2
+
3
+ React component for embedding PDF documents with full-featured viewing capabilities.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @embedpdf/react-pdf-viewer
9
+ # or
10
+ pnpm add @embedpdf/react-pdf-viewer
11
+ # or
12
+ yarn add @embedpdf/react-pdf-viewer
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { PDFViewer } from '@embedpdf/react-pdf-viewer';
19
+
20
+ function App() {
21
+ return (
22
+ <PDFViewer
23
+ config={{
24
+ src: '/document.pdf',
25
+ theme: { preference: 'system' },
26
+ zoom: { defaultLevel: 'fit-width' },
27
+ }}
28
+ style={{ width: '100%', height: '100vh' }}
29
+ onReady={(registry) => {
30
+ console.log('PDF viewer ready', registry);
31
+ }}
32
+ />
33
+ );
34
+ }
35
+ ```
36
+
37
+ ## Props
38
+
39
+ | Prop | Type | Description |
40
+ | ----------- | --------------------- | ---------------------------------------- |
41
+ | `config` | `PDFViewerConfig` | Full configuration object for the viewer |
42
+ | `className` | `string` | CSS class name for the container |
43
+ | `style` | `CSSProperties` | Inline styles for the container |
44
+ | `onInit` | `(container) => void` | Callback when viewer is initialized |
45
+ | `onReady` | `(registry) => void` | Callback when registry is ready |
46
+
47
+ The `config` prop accepts all configuration options from `@embedpdf/snippet`, including:
48
+
49
+ - `src` - URL or path to the PDF document
50
+ - `theme` - Theme configuration
51
+ - `zoom` - Zoom configuration
52
+ - `scroll` - Scroll configuration
53
+ - `annotations` - Annotation configuration
54
+ - And more...
55
+
56
+ ## Accessing the Registry
57
+
58
+ Use a ref to access the viewer container and registry:
59
+
60
+ ```tsx
61
+ import { useRef } from 'react';
62
+ import { PDFViewer, PDFViewerRef } from '@embedpdf/react-pdf-viewer';
63
+
64
+ function App() {
65
+ const viewerRef = useRef<PDFViewerRef>(null);
66
+
67
+ const handleClick = async () => {
68
+ const registry = await viewerRef.current?.registry;
69
+ // Use registry to access plugins
70
+ };
71
+
72
+ return (
73
+ <>
74
+ <PDFViewer
75
+ ref={viewerRef}
76
+ config={{ src: '/document.pdf' }}
77
+ style={{ width: '100%', height: '100vh' }}
78
+ />
79
+ <button onClick={handleClick}>Get Registry</button>
80
+ </>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ## Re-exports
86
+
87
+ This package re-exports everything from `@embedpdf/snippet`, so you can import types and utilities directly:
88
+
89
+ ```tsx
90
+ import {
91
+ PDFViewer,
92
+ ZoomPlugin,
93
+ ScrollPlugin,
94
+ type PDFViewerConfig,
95
+ type PluginRegistry,
96
+ } from '@embedpdf/react-pdf-viewer';
97
+ ```
98
+
99
+ ## License
100
+
101
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),r=require("react"),t=require("@embedpdf/snippet"),n=r.forwardRef(function(n,u){const{config:s={},className:c,style:l,onInit:i,onReady:o}=n,a=r.useRef(null),f=r.useRef(null);return r.useImperativeHandle(u,()=>({get container(){return f.current},get registry(){var e;return(null==(e=f.current)?void 0:e.registry)??null}})),r.useEffect(()=>{if(!a.current)return;const e=t.init({type:"container",target:a.current,...s});return e&&(f.current=e,null==i||i(e),o&&e.registry.then(o)),()=>{f.current&&a.current&&(a.current.innerHTML="",f.current=null)}},[]),e.jsx("div",{ref:a,className:c,style:l})});exports.PDFViewer=n,exports.default=n,Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.tsx"],"sourcesContent":["import {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n type ForwardedRef,\n type CSSProperties,\n} from 'react';\nimport EmbedPDF, {\n type EmbedPdfContainer,\n type PDFViewerConfig,\n type PluginRegistry,\n} from '@embedpdf/snippet';\n\n// Re-export everything from snippet for convenience\nexport * from '@embedpdf/snippet';\n\nexport interface PDFViewerProps {\n /** Full configuration for the PDF viewer */\n config?: PDFViewerConfig;\n /** CSS class name for the container div */\n className?: string;\n /** Inline styles for the container div */\n style?: CSSProperties;\n /** Callback when the viewer is initialized */\n onInit?: (container: EmbedPdfContainer) => void;\n /** Callback when the registry is ready */\n onReady?: (registry: PluginRegistry) => void;\n}\n\nexport interface PDFViewerRef {\n /** The EmbedPdfContainer element */\n container: EmbedPdfContainer | null;\n /** Promise that resolves to the PluginRegistry */\n registry: Promise<PluginRegistry> | null;\n}\n\n/**\n * React component for embedding PDF documents\n *\n * @example\n * ```tsx\n * import { PDFViewer } from '@embedpdf/react-pdf-viewer';\n *\n * function App() {\n * return (\n * <PDFViewer\n * config={{\n * src: '/document.pdf',\n * theme: { preference: 'system' },\n * }}\n * style={{ width: '100%', height: '100vh' }}\n * onReady={(registry) => {\n * console.log('PDF viewer ready', registry);\n * }}\n * />\n * );\n * }\n * ```\n */\nexport const PDFViewer = forwardRef(function PDFViewer(\n props: PDFViewerProps,\n ref: ForwardedRef<PDFViewerRef>,\n) {\n const { config = {}, className, style, onInit, onReady } = props;\n const containerRef = useRef<HTMLDivElement>(null);\n const viewerRef = useRef<EmbedPdfContainer | null>(null);\n\n useImperativeHandle(ref, () => ({\n get container() {\n return viewerRef.current;\n },\n get registry() {\n return viewerRef.current?.registry ?? null;\n },\n }));\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n // Initialize the viewer with the config prop\n const viewer = EmbedPDF.init({\n type: 'container',\n target: containerRef.current,\n ...config,\n });\n\n if (viewer) {\n viewerRef.current = viewer;\n onInit?.(viewer);\n\n // Call onReady when registry is available\n if (onReady) {\n viewer.registry.then(onReady);\n }\n }\n\n return () => {\n // Cleanup: remove the viewer element\n if (viewerRef.current && containerRef.current) {\n containerRef.current.innerHTML = '';\n viewerRef.current = null;\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return <div ref={containerRef} className={className} style={style} />;\n});\n\nexport default PDFViewer;\n"],"names":["PDFViewer","forwardRef","props","ref","config","className","style","onInit","onReady","containerRef","useRef","viewerRef","useImperativeHandle","container","current","registry","_a","useEffect","viewer","EmbedPDF","init","type","target","then","innerHTML","jsx"],"mappings":"mMA4DaA,EAAYC,EAAAA,WAAW,SAClCC,EACAC,GAEA,MAAMC,OAAEA,EAAS,aAAIC,QAAWC,EAAAC,OAAOA,EAAAC,QAAQA,GAAYN,EACrDO,EAAeC,EAAAA,OAAuB,MACtCC,EAAYD,EAAAA,OAAiC,MAyCnD,OAvCAE,EAAAA,oBAAoBT,EAAK,KAAA,CACvB,aAAIU,GACF,OAAOF,EAAUG,OACnB,EACA,YAAIC,SACF,OAAO,OAAAC,EAAAL,EAAUG,cAAV,EAAAE,EAAmBD,WAAY,IACxC,KAGFE,EAAAA,UAAU,KACR,IAAKR,EAAaK,QAAS,OAG3B,MAAMI,EAASC,EAASC,KAAK,CAC3BC,KAAM,YACNC,OAAQb,EAAaK,WAClBV,IAaL,OAVIc,IACFP,EAAUG,QAAUI,EACpB,MAAAX,GAAAA,EAASW,GAGLV,GACFU,EAAOH,SAASQ,KAAKf,IAIlB,KAEDG,EAAUG,SAAWL,EAAaK,UACpCL,EAAaK,QAAQU,UAAY,GACjCb,EAAUG,QAAU,QAIvB,IAEIW,EAAAA,IAAC,MAAA,CAAItB,IAAKM,EAAcJ,YAAsBC,SACvD"}
@@ -0,0 +1,47 @@
1
+ import { CSSProperties } from 'react';
2
+ import { EmbedPdfContainer, PDFViewerConfig, PluginRegistry } from '@embedpdf/snippet';
3
+ export * from '@embedpdf/snippet';
4
+ export interface PDFViewerProps {
5
+ /** Full configuration for the PDF viewer */
6
+ config?: PDFViewerConfig;
7
+ /** CSS class name for the container div */
8
+ className?: string;
9
+ /** Inline styles for the container div */
10
+ style?: CSSProperties;
11
+ /** Callback when the viewer is initialized */
12
+ onInit?: (container: EmbedPdfContainer) => void;
13
+ /** Callback when the registry is ready */
14
+ onReady?: (registry: PluginRegistry) => void;
15
+ }
16
+ export interface PDFViewerRef {
17
+ /** The EmbedPdfContainer element */
18
+ container: EmbedPdfContainer | null;
19
+ /** Promise that resolves to the PluginRegistry */
20
+ registry: Promise<PluginRegistry> | null;
21
+ }
22
+ /**
23
+ * React component for embedding PDF documents
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * import { PDFViewer } from '@embedpdf/react-pdf-viewer';
28
+ *
29
+ * function App() {
30
+ * return (
31
+ * <PDFViewer
32
+ * config={{
33
+ * src: '/document.pdf',
34
+ * theme: { preference: 'system' },
35
+ * }}
36
+ * style={{ width: '100%', height: '100vh' }}
37
+ * onReady={(registry) => {
38
+ * console.log('PDF viewer ready', registry);
39
+ * }}
40
+ * />
41
+ * );
42
+ * }
43
+ * ```
44
+ */
45
+ export declare const PDFViewer: import('react').ForwardRefExoticComponent<PDFViewerProps & import('react').RefAttributes<PDFViewerRef>>;
46
+ export default PDFViewer;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAiB,EACf,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,cAAc,mBAAmB,CAAC;AAElC,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAChD,0CAA0C;IAC1C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,SAAS,yGAgDpB,CAAC;AAEH,eAAe,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
3
+ import EmbedPDF__default from "@embedpdf/snippet";
4
+ export * from "@embedpdf/snippet";
5
+ const PDFViewer = forwardRef(function PDFViewer2(props, ref) {
6
+ const { config = {}, className, style, onInit, onReady } = props;
7
+ const containerRef = useRef(null);
8
+ const viewerRef = useRef(null);
9
+ useImperativeHandle(ref, () => ({
10
+ get container() {
11
+ return viewerRef.current;
12
+ },
13
+ get registry() {
14
+ var _a;
15
+ return ((_a = viewerRef.current) == null ? void 0 : _a.registry) ?? null;
16
+ }
17
+ }));
18
+ useEffect(() => {
19
+ if (!containerRef.current) return;
20
+ const viewer = EmbedPDF__default.init({
21
+ type: "container",
22
+ target: containerRef.current,
23
+ ...config
24
+ });
25
+ if (viewer) {
26
+ viewerRef.current = viewer;
27
+ onInit == null ? void 0 : onInit(viewer);
28
+ if (onReady) {
29
+ viewer.registry.then(onReady);
30
+ }
31
+ }
32
+ return () => {
33
+ if (viewerRef.current && containerRef.current) {
34
+ containerRef.current.innerHTML = "";
35
+ viewerRef.current = null;
36
+ }
37
+ };
38
+ }, []);
39
+ return /* @__PURE__ */ jsx("div", { ref: containerRef, className, style });
40
+ });
41
+ export {
42
+ PDFViewer,
43
+ PDFViewer as default
44
+ };
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import {\n useRef,\n useEffect,\n useImperativeHandle,\n forwardRef,\n type ForwardedRef,\n type CSSProperties,\n} from 'react';\nimport EmbedPDF, {\n type EmbedPdfContainer,\n type PDFViewerConfig,\n type PluginRegistry,\n} from '@embedpdf/snippet';\n\n// Re-export everything from snippet for convenience\nexport * from '@embedpdf/snippet';\n\nexport interface PDFViewerProps {\n /** Full configuration for the PDF viewer */\n config?: PDFViewerConfig;\n /** CSS class name for the container div */\n className?: string;\n /** Inline styles for the container div */\n style?: CSSProperties;\n /** Callback when the viewer is initialized */\n onInit?: (container: EmbedPdfContainer) => void;\n /** Callback when the registry is ready */\n onReady?: (registry: PluginRegistry) => void;\n}\n\nexport interface PDFViewerRef {\n /** The EmbedPdfContainer element */\n container: EmbedPdfContainer | null;\n /** Promise that resolves to the PluginRegistry */\n registry: Promise<PluginRegistry> | null;\n}\n\n/**\n * React component for embedding PDF documents\n *\n * @example\n * ```tsx\n * import { PDFViewer } from '@embedpdf/react-pdf-viewer';\n *\n * function App() {\n * return (\n * <PDFViewer\n * config={{\n * src: '/document.pdf',\n * theme: { preference: 'system' },\n * }}\n * style={{ width: '100%', height: '100vh' }}\n * onReady={(registry) => {\n * console.log('PDF viewer ready', registry);\n * }}\n * />\n * );\n * }\n * ```\n */\nexport const PDFViewer = forwardRef(function PDFViewer(\n props: PDFViewerProps,\n ref: ForwardedRef<PDFViewerRef>,\n) {\n const { config = {}, className, style, onInit, onReady } = props;\n const containerRef = useRef<HTMLDivElement>(null);\n const viewerRef = useRef<EmbedPdfContainer | null>(null);\n\n useImperativeHandle(ref, () => ({\n get container() {\n return viewerRef.current;\n },\n get registry() {\n return viewerRef.current?.registry ?? null;\n },\n }));\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n // Initialize the viewer with the config prop\n const viewer = EmbedPDF.init({\n type: 'container',\n target: containerRef.current,\n ...config,\n });\n\n if (viewer) {\n viewerRef.current = viewer;\n onInit?.(viewer);\n\n // Call onReady when registry is available\n if (onReady) {\n viewer.registry.then(onReady);\n }\n }\n\n return () => {\n // Cleanup: remove the viewer element\n if (viewerRef.current && containerRef.current) {\n containerRef.current.innerHTML = '';\n viewerRef.current = null;\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return <div ref={containerRef} className={className} style={style} />;\n});\n\nexport default PDFViewer;\n"],"names":["PDFViewer","EmbedPDF"],"mappings":";;;;AA4DO,MAAM,YAAY,WAAW,SAASA,WAC3C,OACA,KACA;AACA,QAAM,EAAE,SAAS,IAAI,WAAW,OAAO,QAAQ,YAAY;AAC3D,QAAM,eAAe,OAAuB,IAAI;AAChD,QAAM,YAAY,OAAiC,IAAI;AAEvD,sBAAoB,KAAK,OAAO;AAAA,IAC9B,IAAI,YAAY;AACd,aAAO,UAAU;AAAA,IACnB;AAAA,IACA,IAAI,WAAW;;AACb,eAAO,eAAU,YAAV,mBAAmB,aAAY;AAAA,IACxC;AAAA,EAAA,EACA;AAEF,YAAU,MAAM;AACd,QAAI,CAAC,aAAa,QAAS;AAG3B,UAAM,SAASC,kBAAS,KAAK;AAAA,MAC3B,MAAM;AAAA,MACN,QAAQ,aAAa;AAAA,MACrB,GAAG;AAAA,IAAA,CACJ;AAED,QAAI,QAAQ;AACV,gBAAU,UAAU;AACpB,uCAAS;AAGT,UAAI,SAAS;AACX,eAAO,SAAS,KAAK,OAAO;AAAA,MAC9B;AAAA,IACF;AAEA,WAAO,MAAM;AAEX,UAAI,UAAU,WAAW,aAAa,SAAS;AAC7C,qBAAa,QAAQ,YAAY;AACjC,kBAAU,UAAU;AAAA,MACtB;AAAA,IACF;AAAA,EAEF,GAAG,CAAA,CAAE;AAEL,SAAO,oBAAC,OAAA,EAAI,KAAK,cAAc,WAAsB,OAAc;AACrE,CAAC;"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@embedpdf/react-pdf-viewer",
3
+ "version": "1.0.0",
4
+ "description": "React component for embedding PDF documents",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "dependencies": {
23
+ "@embedpdf/snippet": "1.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "^18.2.0",
27
+ "@types/react-dom": "^18.2.0",
28
+ "rimraf": "^5.0.5",
29
+ "typescript": "^5.1.6",
30
+ "unplugin-dts": "1.0.0-beta.6",
31
+ "vite": "^6.3.5"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=17.0.0",
35
+ "react-dom": ">=17.0.0"
36
+ },
37
+ "keywords": [
38
+ "react",
39
+ "pdf",
40
+ "viewer",
41
+ "embed",
42
+ "document"
43
+ ],
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/embedpdf/embed-pdf-viewer.git",
47
+ "directory": "viewers/react"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "clean": "rimraf dist",
54
+ "build": "pnpm run clean && vite build"
55
+ }
56
+ }