stimulus-pdf-viewer-rails 0.1.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +13 -0
- data/LICENSE-APACHE +177 -0
- data/LICENSE-MIT +21 -0
- data/NOTICE +27 -0
- data/README.md +221 -0
- data/app/assets/images/stimulus-pdf-viewer/cursor-editorFreeHighlight.svg +6 -0
- data/app/assets/images/stimulus-pdf-viewer/cursor-editorInk.svg +4 -0
- data/app/assets/images/stimulus-pdf-viewer/cursor-editorNote.svg +8 -0
- data/app/assets/images/stimulus-pdf-viewer/cursor-editorTextHighlight.svg +8 -0
- data/app/assets/javascripts/stimulus-pdf-viewer.esm.js +8163 -0
- data/app/assets/javascripts/stimulus-pdf-viewer.js +8191 -0
- data/app/assets/stylesheets/stimulus-pdf-viewer.scss +2843 -0
- data/config/importmap.rb +4 -0
- data/lib/generators/stimulus_pdf_viewer/install/templates/views/_toolbar.html.erb +220 -0
- data/lib/generators/stimulus_pdf_viewer/install/templates/views/_viewer.html.erb +54 -0
- data/lib/generators/stimulus_pdf_viewer/install_generator.rb +95 -0
- data/lib/stimulus-pdf-viewer-rails.rb +2 -0
- data/lib/stimulus_pdf_viewer/rails/engine.rb +26 -0
- data/lib/stimulus_pdf_viewer/rails/version.rb +7 -0
- data/lib/stimulus_pdf_viewer/rails.rb +7 -0
- data/lib/tasks/assets.rake +196 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 87748480aefcffa7ea8982698921226374c2c0045ce121007cdc1005081a09ce
|
|
4
|
+
data.tar.gz: b74be2a4e6935d8733fd8efbbb73ba7828bcdb369e54524ef7d236a4b12dd8e4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2432665c49981db9706ff1e07e79bf01a66f6d2bc30c3bf5b42f4e8f2f04c60d2a3f56ca1bfd2967ddbcfa217085d4e6ecbefa5c7bbeeee9f6e4f09487cef7e4
|
|
7
|
+
data.tar.gz: 61a3c62f6798e0497dc709adefbc815679f382e66aff40d6b5a011c95bf64a8e2395b2a64166a4cc2afa305b17cb10b8878d1ec8e4d32116b97df2d149cc88f0
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2024-01-10
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release
|
|
9
|
+
- Vendored stimulus-pdf-viewer 0.1.0
|
|
10
|
+
- Rails engine with asset pipeline integration
|
|
11
|
+
- Importmap support (automatic pin for stimulus-pdf-viewer)
|
|
12
|
+
- Install generator (`rails g stimulus_pdf_viewer:install`)
|
|
13
|
+
- Example view partials
|
data/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on behalf
|
|
53
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no theory of
|
|
154
|
+
liability, whether in contract, strict liability, or tort
|
|
155
|
+
(including negligence or otherwise) arising in any way out of
|
|
156
|
+
the use or inability to use the Work (even if such Holder or other
|
|
157
|
+
party has been advised of the possibility of such damages), shall
|
|
158
|
+
any Contributor be liable to You for damages, including any direct,
|
|
159
|
+
indirect, special, incidental, or consequential damages of any
|
|
160
|
+
character arising as a result of this License or out of the use or
|
|
161
|
+
inability to use the Work (including but not limited to damages for
|
|
162
|
+
loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
163
|
+
any and all other commercial damages or losses), even if such
|
|
164
|
+
Contributor has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jeremy Baker
|
|
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.
|
data/NOTICE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
stimulus-pdf-viewer
|
|
2
|
+
Copyright 2024 Jeremy Baker
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Mozilla Foundation
|
|
5
|
+
(https://www.mozilla.org/).
|
|
6
|
+
|
|
7
|
+
Portions of this software are derived from PDF.js, which is licensed
|
|
8
|
+
under the Apache License, Version 2.0:
|
|
9
|
+
|
|
10
|
+
PDF.js
|
|
11
|
+
Copyright Mozilla Foundation
|
|
12
|
+
https://github.com/nickmessenlehner/nickmessenlehner.github.io/pdf.js
|
|
13
|
+
Licensed under the Apache License, Version 2.0
|
|
14
|
+
|
|
15
|
+
The following files contain code derived from or inspired by PDF.js:
|
|
16
|
+
|
|
17
|
+
- src/lib/core/rendering_queue.js
|
|
18
|
+
Based on PDF.js pdf_rendering_queue.js rendering prioritization pattern
|
|
19
|
+
|
|
20
|
+
- src/lib/core/viewer.js
|
|
21
|
+
Text layer selection handling based on PDF.js text_layer_builder.js patterns
|
|
22
|
+
|
|
23
|
+
- src/lib/find_controller.js
|
|
24
|
+
Search functionality patterns inspired by PDF.js pdf_find_controller.js
|
|
25
|
+
|
|
26
|
+
For the Apache License, Version 2.0, see LICENSE-APACHE.
|
|
27
|
+
For the MIT License covering original code, see LICENSE-MIT.
|
data/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# stimulus-pdf-viewer-rails
|
|
2
|
+
|
|
3
|
+
A Rails gem that packages [stimulus-pdf-viewer](https://github.com/jhubert/stimulus-pdf-viewer) for easy integration into Rails applications. No Node.js or npm required.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full-featured PDF viewer powered by PDF.js
|
|
8
|
+
- Annotations: highlights, underlines, sticky notes, freehand drawing
|
|
9
|
+
- Text search with keyboard shortcuts
|
|
10
|
+
- Thumbnail navigation sidebar
|
|
11
|
+
- Zoom controls (fit to page, fit to width, custom levels)
|
|
12
|
+
- User-specific watermarks
|
|
13
|
+
- PDF download with embedded annotations
|
|
14
|
+
- Mobile support with touch gestures
|
|
15
|
+
- Works with Rails importmap (no Node.js required)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add the gem to your Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem "stimulus-pdf-viewer-rails"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then run the installer:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
bundle install
|
|
29
|
+
rails generate stimulus_pdf_viewer:install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The installer will:
|
|
33
|
+
1. Register the Stimulus controllers in your application
|
|
34
|
+
2. Add the stylesheet import
|
|
35
|
+
3. Add the PDF.js worker meta tag
|
|
36
|
+
4. Optionally copy example view partials
|
|
37
|
+
|
|
38
|
+
## Manual Setup
|
|
39
|
+
|
|
40
|
+
If you prefer manual setup or the generator doesn't work for your setup:
|
|
41
|
+
|
|
42
|
+
### 1. Register the Stimulus Controllers
|
|
43
|
+
|
|
44
|
+
In `app/javascript/controllers/index.js`:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { PdfViewerController, PdfDownloadController } from "stimulus-pdf-viewer"
|
|
48
|
+
application.register("pdf-viewer", PdfViewerController)
|
|
49
|
+
application.register("pdf-download", PdfDownloadController)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Import the Stylesheet
|
|
53
|
+
|
|
54
|
+
In your `application.scss`:
|
|
55
|
+
|
|
56
|
+
```scss
|
|
57
|
+
@import "stimulus-pdf-viewer";
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Add PDF.js Worker Meta Tag
|
|
61
|
+
|
|
62
|
+
In your layout `<head>`:
|
|
63
|
+
|
|
64
|
+
```erb
|
|
65
|
+
<meta name="pdf-worker-src" content="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.worker.min.js">
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or if you prefer to vendor the worker locally, copy it to your assets and reference it there.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
### Basic Viewer
|
|
73
|
+
|
|
74
|
+
```erb
|
|
75
|
+
<div class="pdf-viewer-container"
|
|
76
|
+
data-controller="pdf-viewer"
|
|
77
|
+
data-pdf-viewer-document-url-value="<%= url_for(@document.file) %>"
|
|
78
|
+
data-pdf-viewer-document-name-value="<%= @document.name %>"
|
|
79
|
+
data-pdf-viewer-annotations-url-value="<%= document_annotations_path(@document) %>"
|
|
80
|
+
data-pdf-viewer-user-name-value="<%= current_user.name %>">
|
|
81
|
+
|
|
82
|
+
<div class="pdf-viewer-toolbar">
|
|
83
|
+
<%= render "pdf_viewer/toolbar" %>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div class="pdf-viewer-body">
|
|
87
|
+
<div class="pdf-loading-overlay" data-pdf-viewer-target="loadingOverlay">
|
|
88
|
+
<div class="pdf-loading-spinner"></div>
|
|
89
|
+
<div class="pdf-loading-text">Loading document...</div>
|
|
90
|
+
</div>
|
|
91
|
+
<div class="pdf-pages-container"></div>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Configuration Options
|
|
97
|
+
|
|
98
|
+
| Data Attribute | Description |
|
|
99
|
+
|----------------|-------------|
|
|
100
|
+
| `document-url-value` | URL to the PDF file (required) |
|
|
101
|
+
| `document-name-value` | Display name for downloads (required) |
|
|
102
|
+
| `annotations-url-value` | REST API endpoint for annotations |
|
|
103
|
+
| `user-name-value` | User name for watermarks |
|
|
104
|
+
| `organization-name-value` | Organization name for watermarks |
|
|
105
|
+
| `initial-page-value` | Page to open on load |
|
|
106
|
+
| `initial-annotation-value` | Annotation ID to highlight on load |
|
|
107
|
+
| `tracking-url-value` | Endpoint for time tracking |
|
|
108
|
+
|
|
109
|
+
### Annotations API
|
|
110
|
+
|
|
111
|
+
The viewer expects a REST API at `annotations-url-value`:
|
|
112
|
+
|
|
113
|
+
| Method | Path | Description |
|
|
114
|
+
|--------|------|-------------|
|
|
115
|
+
| GET | `{url}.json` | List all annotations |
|
|
116
|
+
| POST | `{url}` | Create annotation |
|
|
117
|
+
| PATCH | `{url}/{id}` | Update annotation |
|
|
118
|
+
| DELETE | `{url}/{id}` | Delete annotation |
|
|
119
|
+
| PATCH | `{url}/{id}/restore` | Restore deleted annotation |
|
|
120
|
+
|
|
121
|
+
Example controller:
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
class AnnotationsController < ApplicationController
|
|
125
|
+
before_action :set_document
|
|
126
|
+
before_action :set_annotation, only: [:update, :destroy, :restore]
|
|
127
|
+
|
|
128
|
+
def index
|
|
129
|
+
@annotations = @document.annotations
|
|
130
|
+
render json: @annotations
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def create
|
|
134
|
+
@annotation = @document.annotations.build(annotation_params)
|
|
135
|
+
@annotation.user = current_user
|
|
136
|
+
|
|
137
|
+
if @annotation.save
|
|
138
|
+
render json: @annotation, status: :created
|
|
139
|
+
else
|
|
140
|
+
render json: @annotation.errors, status: :unprocessable_entity
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def update
|
|
145
|
+
if @annotation.update(annotation_params)
|
|
146
|
+
render json: @annotation
|
|
147
|
+
else
|
|
148
|
+
render json: @annotation.errors, status: :unprocessable_entity
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def destroy
|
|
153
|
+
@annotation.destroy
|
|
154
|
+
head :no_content
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def restore
|
|
158
|
+
@annotation.restore
|
|
159
|
+
render json: @annotation
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
def set_document
|
|
165
|
+
@document = Document.find(params[:document_id])
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def set_annotation
|
|
169
|
+
@annotation = @document.annotations.find(params[:id])
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def annotation_params
|
|
173
|
+
params.require(:annotation).permit(
|
|
174
|
+
:page, :annotation_type, :color, :opacity, :contents,
|
|
175
|
+
:thickness, :subject, :rect, quads: {}, ink_strokes: {}
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Peer Dependencies
|
|
182
|
+
|
|
183
|
+
The PDF viewer requires these JavaScript libraries. When using importmap, pin them from a CDN:
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
# config/importmap.rb
|
|
187
|
+
pin "pdfjs-dist", to: "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.0.379/pdf.min.mjs"
|
|
188
|
+
pin "pdf-lib", to: "https://cdn.jsdelivr.net/npm/pdf-lib@1.17.1/dist/pdf-lib.esm.min.js"
|
|
189
|
+
pin "@rails/request.js", to: "@rails--request.js.js" # Usually already pinned
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Updating the Vendored Assets
|
|
193
|
+
|
|
194
|
+
Check for newer versions:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
rake stimulus_pdf_viewer:check
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Update to the latest version:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
rake stimulus_pdf_viewer:update
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Update to a specific version:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
rake stimulus_pdf_viewer:update[0.2.0]
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The rake task will download the package from npm, copy the dist files, and update `STIMULUS_PDF_VIEWER_VERSION` in `lib/stimulus_pdf_viewer/rails/version.rb`.
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
This gem is dual-licensed:
|
|
217
|
+
|
|
218
|
+
- **MIT License** - for original code
|
|
219
|
+
- **Apache License 2.0** - for code derived from PDF.js
|
|
220
|
+
|
|
221
|
+
See the [stimulus-pdf-viewer](https://github.com/jhubert/stimulus-pdf-viewer) repository for full license details.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="18" height="19" viewBox="0 0 18 19" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.2 3.09C12.28 3.01 12.43 3 12.43 3C12.48 3 12.58 3.02 12.66 3.1L14.45 4.89C14.58 5.02 14.58 5.22 14.45 5.35L11.7713 8.02872L9.51628 5.77372L12.2 3.09ZM13.2658 5.12L11.7713 6.6145L10.9305 5.77372L12.425 4.27921L13.2658 5.12Z" fill="#FBFBFE"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.98 9.32L8.23 11.57L10.7106 9.08938L8.45562 6.83438L5.98 9.31V9.32ZM8.23 10.1558L9.29641 9.08938L8.45562 8.24859L7.38921 9.315L8.23 10.1558Z" fill="#FBFBFE"/>
|
|
4
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.1526 13.1816L16.2125 7.1217C16.7576 6.58919 17.05 5.8707 17.05 5.12C17.05 4.36931 16.7576 3.65084 16.2126 3.11834L14.4317 1.33747C13.8992 0.79242 13.1807 0.5 12.43 0.5C11.6643 0.5 10.9529 0.812929 10.4329 1.33289L3.68289 8.08289C3.04127 8.72452 3.00459 9.75075 3.57288 10.4363L1.29187 12.7239C1.09186 12.9245 0.990263 13.1957 1.0007 13.4685L1 14.5C0.447715 14.5 0 14.9477 0 15.5V17.5C0 18.0523 0.447715 18.5 1 18.5H16C16.5523 18.5 17 18.0523 17 17.5V15.5C17 14.9477 16.5523 14.5 16 14.5H10.2325C9.83594 14.5 9.39953 13.9347 10.1526 13.1816ZM4.39 9.85L4.9807 10.4407L2.39762 13.0312H6.63877L7.10501 12.565L7.57125 13.0312H8.88875L15.51 6.41C15.86 6.07 16.05 5.61 16.05 5.12C16.05 4.63 15.86 4.17 15.51 3.83L13.72 2.04C13.38 1.69 12.92 1.5 12.43 1.5C11.94 1.5 11.48 1.7 11.14 2.04L4.39 8.79C4.1 9.08 4.1 9.56 4.39 9.85ZM16 17.5V15.5H1V17.5H16Z" fill="#FBFBFE"/>
|
|
5
|
+
<path d="M15.1616 6.05136L15.1616 6.05132L15.1564 6.05645L8.40645 12.8064C8.35915 12.8537 8.29589 12.88 8.23 12.88C8.16411 12.88 8.10085 12.8537 8.05355 12.8064L7.45857 12.2115L7.10501 11.8579L6.75146 12.2115L6.03289 12.93H3.20465L5.33477 10.7937L5.6873 10.4402L5.33426 10.0871L4.74355 9.49645C4.64882 9.40171 4.64882 9.23829 4.74355 9.14355L11.4936 2.39355C11.7436 2.14354 12.0779 2 12.43 2C12.7883 2 13.1179 2.13776 13.3614 2.38839L13.3613 2.38843L13.3664 2.39355L15.1564 4.18355L15.1564 4.18359L15.1616 4.18864C15.4122 4.43211 15.55 4.76166 15.55 5.12C15.55 5.47834 15.4122 5.80789 15.1616 6.05136ZM7.87645 11.9236L8.23 12.2771L8.58355 11.9236L11.0642 9.44293L11.4177 9.08938L11.0642 8.73582L8.80918 6.48082L8.45562 6.12727L8.10207 6.48082L5.62645 8.95645L5.48 9.10289V9.31V9.32V9.52711L5.62645 9.67355L7.87645 11.9236ZM11.4177 8.38227L11.7713 8.73582L12.1248 8.38227L14.8036 5.70355C15.1288 5.37829 15.1288 4.86171 14.8036 4.53645L13.0136 2.74645C12.8186 2.55146 12.5792 2.5 12.43 2.5H12.4134L12.3967 2.50111L12.43 3C12.3967 2.50111 12.3966 2.50112 12.3965 2.50112L12.3963 2.50114L12.3957 2.50117L12.3947 2.50125L12.3924 2.50142L12.387 2.50184L12.3732 2.50311C12.3628 2.50416 12.3498 2.50567 12.3346 2.50784C12.3049 2.51208 12.2642 2.51925 12.2178 2.53146C12.1396 2.55202 11.9797 2.60317 11.8464 2.73645L9.16273 5.42016L8.80918 5.77372L9.16273 6.12727L11.4177 8.38227ZM1.5 16H15.5V17H1.5V16Z" stroke="#15141A"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M0.0189877 13.6645L0.612989 10.4635C0.687989 10.0545 0.884989 9.6805 1.18099 9.3825L9.98199 0.5805C10.756 -0.1925 12.015 -0.1945 12.792 0.5805L14.42 2.2085C15.194 2.9835 15.194 4.2435 14.42 5.0185L5.61599 13.8215C5.31999 14.1165 4.94599 14.3125 4.53799 14.3875L1.33599 14.9815C1.26599 14.9935 1.19799 15.0005 1.12999 15.0005C0.832989 15.0005 0.544988 14.8835 0.330988 14.6695C0.0679874 14.4055 -0.0490122 14.0305 0.0189877 13.6645Z" fill="white"/>
|
|
3
|
+
<path d="M0.0189877 13.6645L0.612989 10.4635C0.687989 10.0545 0.884989 9.6805 1.18099 9.3825L9.98199 0.5805C10.756 -0.1925 12.015 -0.1945 12.792 0.5805L14.42 2.2085C15.194 2.9835 15.194 4.2435 14.42 5.0185L5.61599 13.8215C5.31999 14.1165 4.94599 14.3125 4.53799 14.3875L1.33599 14.9815C1.26599 14.9935 1.19799 15.0005 1.12999 15.0005C0.832989 15.0005 0.544988 14.8835 0.330988 14.6695C0.0679874 14.4055 -0.0490122 14.0305 0.0189877 13.6645ZM12.472 5.1965L13.632 4.0365L13.631 3.1885L11.811 1.3675L10.963 1.3685L9.80299 2.5285L12.472 5.1965ZM4.31099 13.1585C4.47099 13.1285 4.61799 13.0515 4.73399 12.9345L11.587 6.0815L8.91899 3.4135L2.06599 10.2655C1.94899 10.3835 1.87199 10.5305 1.84099 10.6915L1.36699 13.2485L1.75199 13.6335L4.31099 13.1585Z" fill="black"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<!-- White outline/shadow -->
|
|
3
|
+
<path d="M2 1C1.44772 1 1 1.44772 1 2V11C1 11.5523 1.44772 12 2 12H5L8 15L11 12H14C14.5523 12 15 11.5523 15 11V2C15 1.44772 14.5523 1 14 1H2Z" fill="white" stroke="white" stroke-width="1"/>
|
|
4
|
+
<!-- Black icon -->
|
|
5
|
+
<path d="M2 2H14V11H10.5L8 13.5L5.5 11H2V2Z" fill="black"/>
|
|
6
|
+
<!-- Inner detail - folded corner or lines -->
|
|
7
|
+
<path d="M4 5H12M4 7.5H10" stroke="white" stroke-width="1" stroke-linecap="round"/>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg width="29" height="32" viewBox="0 0 29 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M28 16.75C28.2761 16.75 28.5 16.5261 28.5 16.25V15C28.5 14.7239 28.2761 14.5 28 14.5H26.358C25.9117 14.5 25.4773 14.6257 25.0999 14.8604L25.0989 14.8611L24 15.5484L22.9 14.861L22.8991 14.8604C22.5218 14.6257 22.0875 14.5 21.642 14.5H20C19.7239 14.5 19.5 14.7239 19.5 15V16.25C19.5 16.5261 19.7239 16.75 20 16.75H21.642C21.6648 16.75 21.6885 16.7564 21.7101 16.7697C21.7102 16.7698 21.7104 16.7699 21.7105 16.77L22.817 17.461C22.817 17.461 22.8171 17.4611 22.8171 17.4611C22.8171 17.4611 22.8171 17.4611 22.8171 17.4611C22.8552 17.4849 22.876 17.5229 22.876 17.567V22.625V27.683C22.876 27.7271 22.8552 27.765 22.8172 27.7889C22.8171 27.7889 22.8171 27.789 22.817 27.789L21.7095 28.48C21.7094 28.4801 21.7093 28.4802 21.7092 28.4803C21.6872 28.4938 21.6644 28.5 21.641 28.5H20C19.7239 28.5 19.5 28.7239 19.5 29V30.25C19.5 30.5261 19.7239 30.75 20 30.75H21.642C22.0883 30.75 22.5227 30.6243 22.9001 30.3896L22.9009 30.3891L24 29.7026L25.1 30.39L25.1009 30.3906C25.4783 30.6253 25.9127 30.751 26.359 30.751H28C28.2761 30.751 28.5 30.5271 28.5 30.251V29.001C28.5 28.7249 28.2761 28.501 28 28.501H26.358C26.3352 28.501 26.3115 28.4946 26.2899 28.4813C26.2897 28.4812 26.2896 28.4811 26.2895 28.481L25.183 27.79C25.183 27.79 25.183 27.79 25.1829 27.79C25.1829 27.7899 25.1829 27.7899 25.1829 27.7899C25.1462 27.7669 25.125 27.7297 25.125 27.684V22.625V17.567C25.125 17.5227 25.146 17.4844 25.1836 17.4606C25.1838 17.4605 25.1839 17.4604 25.184 17.4603L26.2895 16.77C26.2896 16.7699 26.2898 16.7698 26.2899 16.7697C26.3119 16.7562 26.3346 16.75 26.358 16.75H28Z" fill="black" stroke="#FBFBFE" stroke-linejoin="round"/>
|
|
3
|
+
<path d="M24.625 17.567C24.625 17.35 24.735 17.152 24.918 17.037L26.026 16.345C26.126 16.283 26.24 16.25 26.358 16.25H28V15H26.358C26.006 15 25.663 15.099 25.364 15.285L24.256 15.978C24.161 16.037 24.081 16.113 24 16.187C23.918 16.113 23.839 16.037 23.744 15.978L22.635 15.285C22.336 15.099 21.993 15 21.642 15H20V16.25H21.642C21.759 16.25 21.874 16.283 21.974 16.345L23.082 17.037C23.266 17.152 23.376 17.35 23.376 17.567V22.625V27.683C23.376 27.9 23.266 28.098 23.082 28.213L21.973 28.905C21.873 28.967 21.759 29 21.641 29H20V30.25H21.642C21.994 30.25 22.337 30.151 22.636 29.965L23.744 29.273C23.84 29.213 23.919 29.137 24 29.064C24.081 29.137 24.161 29.213 24.256 29.273L25.365 29.966C25.664 30.152 26.007 30.251 26.359 30.251H28V29.001H26.358C26.241 29.001 26.126 28.968 26.026 28.906L24.918 28.214C24.734 28.099 24.625 27.901 24.625 27.684V22.625V17.567Z" fill="black"/>
|
|
4
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.2 2.59C12.28 2.51 12.43 2.5 12.43 2.5C12.48 2.5 12.58 2.52 12.66 2.6L14.45 4.39C14.58 4.52 14.58 4.72 14.45 4.85L11.7713 7.52872L9.51628 5.27372L12.2 2.59ZM13.2658 4.62L11.7713 6.1145L10.9305 5.27372L12.425 3.77921L13.2658 4.62Z" fill="#FBFBFE"/>
|
|
5
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.98 8.82L8.23 11.07L10.7106 8.58938L8.45562 6.33438L5.98 8.81V8.82ZM8.23 9.65579L9.29641 8.58938L8.45562 7.74859L7.38921 8.815L8.23 9.65579Z" fill="#FBFBFE"/>
|
|
6
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.1526 12.6816L16.2125 6.6217C16.7576 6.08919 17.05 5.3707 17.05 4.62C17.05 3.86931 16.7576 3.15084 16.2126 2.61834L14.4317 0.837474C13.8992 0.29242 13.1807 0 12.43 0C11.6643 0 10.9529 0.312929 10.4329 0.832893L3.68289 7.58289C3.04127 8.22452 3.00459 9.25075 3.57288 9.93634L1.29187 12.2239C1.09186 12.4245 0.990263 12.6957 1.0007 12.9685L1 14C0.447715 14 0 14.4477 0 15V17C0 17.5523 0.447715 18 1 18H16C16.5523 18 17 17.5523 17 17V15C17 14.4477 16.5523 14 16 14H10.2325C9.83594 14 9.39953 13.4347 10.1526 12.6816ZM4.39 9.35L4.9807 9.9407L2.39762 12.5312H6.63877L7.10501 12.065L7.57125 12.5312H8.88875L15.51 5.91C15.86 5.57 16.05 5.11 16.05 4.62C16.05 4.13 15.86 3.67 15.51 3.33L13.72 1.54C13.38 1.19 12.92 1 12.43 1C11.94 1 11.48 1.2 11.14 1.54L4.39 8.29C4.1 8.58 4.1 9.06 4.39 9.35ZM16 17V15H1V17H16Z" fill="#FBFBFE"/>
|
|
7
|
+
<path d="M15.1616 5.55136L15.1616 5.55132L15.1564 5.55645L8.40645 12.3064C8.35915 12.3537 8.29589 12.38 8.23 12.38C8.16411 12.38 8.10085 12.3537 8.05355 12.3064L7.45857 11.7115L7.10501 11.3579L6.75146 11.7115L6.03289 12.43H3.20465L5.33477 10.2937L5.6873 9.94019L5.33426 9.58715L4.74355 8.99645C4.64882 8.90171 4.64882 8.73829 4.74355 8.64355L11.4936 1.89355C11.7436 1.64354 12.0779 1.5 12.43 1.5C12.7883 1.5 13.1179 1.63776 13.3614 1.88839L13.3613 1.88843L13.3664 1.89355L15.1564 3.68355L15.1564 3.68359L15.1616 3.68864C15.4122 3.93211 15.55 4.26166 15.55 4.62C15.55 4.97834 15.4122 5.30789 15.1616 5.55136ZM5.48 8.82V9.02711L5.62645 9.17355L7.87645 11.4236L8.23 11.7771L8.58355 11.4236L11.0642 8.94293L11.4177 8.58938L11.0642 8.23582L8.80918 5.98082L8.45562 5.62727L8.10207 5.98082L5.62645 8.45645L5.48 8.60289V8.81V8.82ZM11.4177 7.88227L11.7713 8.23582L12.1248 7.88227L14.8036 5.20355C15.1288 4.87829 15.1288 4.36171 14.8036 4.03645L13.0136 2.24645C12.8186 2.05146 12.5792 2 12.43 2H12.4134L12.3967 2.00111L12.43 2.5C12.3967 2.00111 12.3966 2.00112 12.3965 2.00112L12.3963 2.00114L12.3957 2.00117L12.3947 2.00125L12.3924 2.00142L12.387 2.00184L12.3732 2.00311C12.3628 2.00416 12.3498 2.00567 12.3346 2.00784C12.3049 2.01208 12.2642 2.01925 12.2178 2.03146C12.1396 2.05202 11.9797 2.10317 11.8464 2.23645L9.16273 4.92016L8.80918 5.27372L9.16273 5.62727L11.4177 7.88227ZM1.5 16.5V15.5H15.5V16.5H1.5Z" stroke="#15141A"/>
|
|
8
|
+
</svg>
|