@pdfslick/react 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +94 -0
  2. package/package.json +2 -2
  3. package/dist/README.md +0 -119
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ <br><br>
2
+
3
+ ![readme-header](https://pdfslick.dev/pdfslick_logo.svg)
4
+
5
+ <br><br>
6
+ <div align="center">
7
+ View and Interact with PDF documents in React apps
8
+ <br><br>
9
+
10
+ [Getting Started](https://pdfslick.dev/docs) | [Examples](https://pdfslick.dev/examples)
11
+
12
+ <br><br>
13
+ </div>
14
+
15
+ ---
16
+ <br>
17
+
18
+ PDFSlick for React is a library which enables viewing of and interaction with PDF documents in React apps.
19
+ It's build on top of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js), and utilises [Zustand](https://github.com/pmndrs/zustand) to provide a reactive store for the loaded documents.
20
+
21
+ ## Getting started with PDFSlick for React
22
+
23
+ To get started with React run:
24
+ ```shell
25
+ npm install @pdfslick/react
26
+ # yarn add @pdfslick/react
27
+ # pnpm add @pdfslick/react
28
+ ```
29
+
30
+ You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
31
+ ```jsx
32
+ import { usePDFSlick } from "@pdfslick/react";
33
+ import PDFNavigation from "./yourcomponents/PDFNavigation";
34
+
35
+ //
36
+ // It is required to include PDFSlick's CSS styles once
37
+ // you can do it in your main `App.tsx` for example
38
+ //
39
+ import "@pdfslick/react/dist/pdf_viewer.css";
40
+
41
+ type PDFViewerComponentProps = {
42
+ pdfFilePath: string;
43
+ };
44
+
45
+ const PDFViewerComponent = ({ pdfFilePath }: PDFViewerComponent) => {
46
+ const { viewerRef, usePDFSlickStore, PDFSlickViewer } = usePDFSlick(pdfFilePath, {
47
+ scaleValue: "page-fit"
48
+ });
49
+
50
+ /*
51
+ Access the store with `usePDFSlickStore()` hook — you can pass is
52
+ as a prop to other components (like with `<PDFNavigation />` below)
53
+ Toolbars, Sidebars, components which render thumbnails etc.
54
+ and use it as here to get and react on
55
+ PDF document's and viewer's properties and changes
56
+ */
57
+ const scale = usePDFSlickStore((s) => s.scale);
58
+ const numPages = usePDFSlickStore((s) => s.numPages);
59
+ const pageNumber = usePDFSlickStore((s) => s.pageNumber);
60
+
61
+ return (
62
+ <div className="absolute inset-0 pdfSlick">
63
+ <div className="relative h-full">
64
+ <PDFSlickViewer {...{ viewerRef, usePDFSlickStore }} />
65
+
66
+ {/*
67
+ Pass PDFSlick's store to your custom components
68
+ */}
69
+ <PDFNavigation {...{ usePDFSlickStore }} />
70
+
71
+ {/*
72
+ PDFSlick's store values automatically update
73
+ */}
74
+ <div className="absolute w-full top-0 left-0">
75
+ <p>Current scale: {scale}</p>
76
+ <p>Current page number: {pageNumber}</p>
77
+ <p>Total number of pages: {numPages}</p>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ );
82
+ };
83
+
84
+ export default PDFViewerComponent;
85
+ ```
86
+
87
+ Provided with the PDF Document path and PDFSlick options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
88
+ - `PDFSlickViewer` is the PDF Viewer component used for viewing the PDF document
89
+ - `viewerRef` is the `ref` callback that is provided as a prop to the `<PDFSlickViewer />` component
90
+ - `usePDFSlickStore` enables using PDFSlick store within your React components
91
+
92
+ <br>
93
+
94
+ [More on using PDFSlick with React](https://pdfslick.dev/docs/react) | [Checkout the React Examples](./apps/web/examples)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfslick/react",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "source": "./index.tsx",
5
5
  "main": "dist/umd/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -27,7 +27,7 @@
27
27
  "scripts": {
28
28
  "lint": "eslint \"**/*.ts*\"",
29
29
  "dev": "concurrently \"rollup --config node:@pdfslick/rollup-config --watch\" \"wait-on ./dist && cp ../core/dist/pdf_viewer.css ./dist\"",
30
- "build": "rollup --config node:@pdfslick/rollup-config --environment NODE_ENV:production && cp ../core/dist/pdf_viewer.css ./dist && cp ../core/dist/pdf_viewer.css ./dist && cp ../../README.md ./dist"
30
+ "build": "rollup --config node:@pdfslick/rollup-config --environment NODE_ENV:production && cp ../core/dist/pdf_viewer.css ./dist"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^18.0.22",
package/dist/README.md DELETED
@@ -1,119 +0,0 @@
1
- <br><br>
2
-
3
- ![readme-header](https://pdfslick.dev/pdfslick_logo.svg)
4
-
5
- <br><br>
6
- <div align="center">
7
- View and Interact with PDFs in React and SolidJS apps
8
- <br><br>
9
-
10
- [Getting Started](https://pdfslick.dev/docs) | [Examples](https://pdfslick.dev/examples)
11
-
12
- <br><br>
13
- </div>
14
-
15
- ---
16
- <br>
17
-
18
- PDFSlick is a library that enables viewing of and interaction with PDF documents in React and SolidJS apps.
19
- It's build on top of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js), and utilises [Zustand](https://github.com/pmndrs/zustand) to provide a reactive store for the loaded documents.
20
-
21
- ## Motivation
22
-
23
- [PDF.js](https://github.com/mozilla/pdf.js) is an amazing piece of software. It is also a very stable and mature one — it powers the PDF viewer in Mozilla Firefox and it's been around since 2011. However, it's all Vanilla JavaScript, and when it comes to using it with libraries like React and SolidJS (although possible) it's a litte bit hard in terms of integrating it in these Component- and reactive-like environments. PDFSlick attempts to wrap all of that fascinating functionality into one that is easier to fit in React and SolidJS worlds — as components and a reactive store.
24
-
25
- ## Core Concepts
26
-
27
- The core of PDFSlick is within the `@pdfslick/core` package. It wraps `PDF.js`'s functionality and links it to the store. This `@pdfslick/core` package is the basis for the React and SolidJS packages, which additionally transform the store and make it suitable for the adequate library, as well as providing components for the PDF viewer and thumbnails.
28
-
29
- Depending on your needs, at this you might find it useful to continue with learning more about using PDFSlick with React and SolidJS respsectivelly. However, if really interested you can learn more about using PDFSlick's `@pdfslick/core` package with Vanilla JS apps and with libraries other than React and SolidJS in the sections below.
30
-
31
- ## Getting Started with React
32
-
33
- To get started with React run:
34
- ```shell
35
- npm install @pdfslick/react
36
- # yarn add @pdfslick/react
37
- # pnpm add @pdfslick/react
38
- ```
39
-
40
- You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
41
- ```jsx
42
- import { usePDFSlick } from "@pdfslick/react";
43
- import PDFNavigation from "./PDFNavigation";
44
-
45
- import "@pdfslick/react/dist/pdf_viewer.css";
46
-
47
- type PDFViewerAppProps = {
48
- pdfFilePath: string;
49
- };
50
-
51
- const SimplePDFViewer = ({ pdfFilePath }: PDFViewerAppProps) => {
52
- const { viewerRef, usePDFSlickStore, PDFSlickViewer } = usePDFSlick(pdfFilePath, {
53
- singlePageViewer: true,
54
- scaleValue: "page-fit"
55
- });
56
-
57
- return (
58
- <div className="absolute inset-0 bg-slate-200/70 pdfSlick">
59
- <div className="flex-1 relative h-full">
60
- <PDFSlickViewer {...{ viewerRef, usePDFSlickStore }} />
61
- <PDFNavigation {...{ usePDFSlickStore }} />
62
- </div>
63
- </div>
64
- );
65
- };
66
-
67
- export default SimplePDFViewer;
68
- ```
69
-
70
- Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
71
- - `PDFSlickViewer` — the PDF Viewer component used for viewing the PDF document
72
- - `viewerRef` — a `RefCallback` that is provided as a prop to the `<PDFSlickViewer />` component
73
- - `usePDFSlickStore` — a hook to the PDFSlick store
74
-
75
- <br><br>
76
- [Read more about using PDFSlick with React](https://pdfslick.dev/docs/react) | [Checkout the React Examples](./apps/web/examples)
77
-
78
- ## SolidJS
79
-
80
- To get started with PDFSlick for SolidJS React run:
81
- ```shell
82
- npm install @pdfslick/solid
83
- # yarn add @pdfslick/solid
84
- # pnpm add @pdfslick/solid
85
- ```
86
-
87
- You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
88
- ```jsx
89
- import { Component, createSignal } from "solid-js";
90
- import { usePDFSlick } from "@pdfslick/solid";
91
-
92
- type PDFViewerAppProps = {
93
- pdfFilePath: string;
94
- };
95
-
96
- const PDFViewerApp: Component<PDFViewerAppProps> = ({ pdfFilePath }) => {
97
- const { viewerRef, pdfSlickStore: store, PDFSlickViewer } =
98
- usePDFSlick(pdfFilePath);
99
-
100
- return (
101
- <div class="absolute inset-0 bg-slate-200/70 flex flex-col pdfSlick">
102
- <div class="flex-1 relative h-full">
103
- <PDFSlickViewer {...{ store, viewerRef }} />
104
- </div>
105
- </div>
106
- );
107
- };
108
-
109
- export default PDFViewerApp;
110
- ```
111
-
112
- Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
113
- - `PDFSlickViewer` — the PDF Viewer component used for viewing the PDF document
114
- - `viewerRef` — a `RefCallback` that is provided as a prop to the `<PDFSlickViewer />` component
115
- - `pdfSlickStore` — the PDFSlick store
116
-
117
- <br><br>
118
- [Read more about using PDFSlick with SolidJS](https://pdfslick.dev/docs/solid) | [Checkout the SolidJS Examples](./apps/solidweb/src/examples)
119
-