@edgepdf/viewer-js 0.0.29 → 0.0.30

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
@@ -10,7 +10,9 @@ npm install @edgepdf/viewer-js
10
10
  pnpm add @edgepdf/viewer-js
11
11
  ```
12
12
 
13
- **Note:** Leaflet is bundled with this library, so you don't need to install it separately. **CSS styles are automatically injected** when you import the library - no manual CSS import needed!
13
+ **Note:** Leaflet is bundled with this library, so you don't need to install it separately.
14
+
15
+ **For SSR frameworks (Next.js, Remix, etc.):** This library requires a browser environment. Use dynamic imports or the React component (`@edgepdf/viewer-react`) which handles SSR automatically. See [SSR Support](#ssr-support) section below.
14
16
 
15
17
  ## Usage
16
18
 
@@ -78,6 +80,93 @@ const viewer = new EdgePdfViewer({
78
80
  viewer.initialize();
79
81
  ```
80
82
 
83
+ ## SSR Support
84
+
85
+ This library uses Leaflet, which requires a browser environment. For SSR frameworks like Next.js, Remix, or other React frameworks, you have two options:
86
+
87
+ ### Option 1: Use the React Component (Recommended)
88
+
89
+ The `@edgepdf/viewer-react` package handles SSR automatically with dynamic imports:
90
+
91
+ ```tsx
92
+ import { EdgePDFViewer } from '@edgepdf/viewer-react';
93
+ import { ViewerProvider } from '@edgepdf/viewer-react';
94
+
95
+ // In your component
96
+ <ViewerProvider>
97
+ <EdgePDFViewer config={config} />
98
+ </ViewerProvider>;
99
+ ```
100
+
101
+ ### Option 2: Use Dynamic Imports (Next.js)
102
+
103
+ If you need to use `@edgepdf/viewer-js` directly in Next.js, use dynamic imports with `ssr: false`:
104
+
105
+ ```tsx
106
+ import dynamic from 'next/dynamic';
107
+
108
+ const EdgePdfViewer = dynamic(
109
+ () => import('@edgepdf/viewer-js').then((mod) => mod.EdgePdfViewer),
110
+ { ssr: false }
111
+ );
112
+
113
+ // Or use it in a client component
114
+ ('use client');
115
+
116
+ import { useEffect, useRef } from 'react';
117
+ import dynamic from 'next/dynamic';
118
+
119
+ const EdgePdfViewer = dynamic(
120
+ () => import('@edgepdf/viewer-js').then((mod) => mod.EdgePdfViewer),
121
+ { ssr: false }
122
+ );
123
+
124
+ export default function MyComponent() {
125
+ const containerRef = useRef<HTMLDivElement>(null);
126
+
127
+ useEffect(() => {
128
+ if (!containerRef.current) return;
129
+
130
+ const { EdgePdfViewer } = require('@edgepdf/viewer-js');
131
+ const viewer = new EdgePdfViewer({
132
+ container: containerRef.current,
133
+ config: yourConfig,
134
+ });
135
+ viewer.initialize();
136
+
137
+ return () => viewer.dispose();
138
+ }, []);
139
+
140
+ return <div ref={containerRef} style={{ width: '100%', height: '100%' }} />;
141
+ }
142
+ ```
143
+
144
+ ### Next.js Configuration
145
+
146
+ If you're still getting build errors, add this to your `next.config.js`:
147
+
148
+ ```javascript
149
+ /** @type {import('next').NextConfig} */
150
+ const nextConfig = {
151
+ webpack: (config, { isServer }) => {
152
+ if (isServer) {
153
+ // Exclude @edgepdf/viewer-js from server-side bundle
154
+ config.externals = config.externals || [];
155
+ config.externals.push('@edgepdf/viewer-js');
156
+ }
157
+ return config;
158
+ },
159
+ };
160
+
161
+ module.exports = nextConfig;
162
+ ```
163
+
164
+ **Note:** You'll also need to import the CSS manually when using dynamic imports:
165
+
166
+ ```tsx
167
+ import '@edgepdf/viewer-js/dist/styles.css';
168
+ ```
169
+
81
170
  ## API Reference
82
171
 
83
172
  ### EdgePdfViewer
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import './styles.css';
1
+ import './lib/inject-styles.js';
2
2
  export * from './lib/viewer.js';
3
3
  export { EdgePdfViewer } from './lib/viewer.js';
4
4
  export { TileLayerManager } from './lib/tile-layer-manager.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,CAAC;AAEtB,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE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,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,YAAY,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,MAAM,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Injects CSS styles into the document head
3
+ * This function is safe to call in SSR environments (no-op if window/document not available)
4
+ *
5
+ * The CSS file is bundled separately and injected via a link tag.
6
+ * This ensures styles are included in the build while remaining SSR-safe.
7
+ */
8
+ /**
9
+ * Injects the EdgePDF viewer styles into the document head
10
+ * Safe to call in SSR environments (will be a no-op)
11
+ *
12
+ * Note: For best results, import the CSS directly in your app:
13
+ * import '@edgepdf/viewer-js/dist/styles.css'
14
+ * This function is a convenience fallback.
15
+ */
16
+ export declare function injectStyles(): void;
17
+ //# sourceMappingURL=inject-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-styles.d.ts","sourceRoot":"","sources":["../../src/lib/inject-styles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAyCnC"}