@rasterex/viewer 1.1.0 → 1.1.1

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
@@ -1,43 +1,73 @@
1
1
  # Rasterex Viewer SDK
2
2
 
3
- Embed Rasterex Canvas in your web application with the Rasterex Viewer SDK: a
4
- small, framework-independent TypeScript SDK that uses an iframe and
5
- PostMessage.
3
+ Embed Rasterex Canvas in a web application with a small, framework-independent
4
+ TypeScript SDK. The SDK mounts Canvas in an iframe, communicates through
5
+ PostMessage, and provides typed APIs for files, tools, events, and viewer
6
+ features.
6
7
 
7
- Customer production deployments are self-hosted. Rasterex provides hosted
8
- Canvas for evaluation and proof-of-concept testing.
9
-
10
- The SDK mounts the viewer, opens files, controls tools, listens for viewer events, and provides TypeScript types for the public API.
8
+ Customer production deployments are self-hosted. Rasterex provides a hosted
9
+ Canvas Sandbox for evaluation and proof-of-concept testing.
11
10
 
12
11
  Full [documentation](https://docs.rasterex.com/) ·
13
12
  [source](https://github.com/Rasterex-Software/rasterex-viewer) ·
14
13
  [runnable examples](https://github.com/Rasterex-Software/rasterex-viewer-examples) ·
15
14
  [issues and support](https://github.com/Rasterex-Software/rasterex-viewer/issues)
16
15
 
17
- ## Install
16
+ ## Choose A Viewer Environment
18
17
 
19
- ```sh
20
- npm install @rasterex/viewer
18
+ ### Hosted Sandbox
19
+
20
+ The SDK defaults to `https://sandbox.rasterex.com`, Rasterex's hosted Canvas
21
+ environment for evaluation and proof-of-concept testing. The SDK embeds it in
22
+ an iframe and sends Canvas broker messages to that origin.
23
+
24
+ Documents opened in Sandbox must be reachable from the hosted viewer
25
+ environment. The public PDF used in the examples is intentionally suitable for
26
+ this purpose.
27
+
28
+ ### Self-Hosted Production
29
+
30
+ Do not treat the hosted Sandbox as a customer production deployment. For
31
+ production, private files, or network-restricted content, deploy Rasterex
32
+ Canvas in your own environment and provide its URL:
33
+
34
+ ```ts
35
+ import { createViewer } from "@rasterex/viewer";
36
+
37
+ const viewer = createViewer({
38
+ container: "#rx-viewer",
39
+ viewerUrl: "https://viewer.example.com",
40
+ targetOrigin: "https://viewer.example.com"
41
+ });
42
+
43
+ await viewer.mount();
44
+ await viewer.ready();
21
45
  ```
22
46
 
23
- ## Requirements
47
+ If `targetOrigin` is omitted, the SDK derives it from `viewerUrl` with
48
+ `new URL(viewerUrl).origin`.
24
49
 
25
- Use the package from a bundled application such as Vite, Next.js, Angular, React, Vue, Webpack, or Rollup.
50
+ ## Install And Requirements
26
51
 
27
- Use Node.js `^20.19.0 || >=22.12.0` when developing, building, or releasing
28
- this package.
52
+ ```sh
53
+ npm install @rasterex/viewer
54
+ ```
29
55
 
30
- Browsers cannot resolve npm package names directly from a plain `<script type="module">` file without a bundler or import map.
56
+ Use the package from a bundled application such as Vite, Next.js, Angular,
57
+ React, Vue, Webpack, or Rollup. Use Node.js `^20.19.0 || >=22.12.0` when
58
+ developing, building, or releasing this package.
31
59
 
32
- The viewer container must have a real width and height before mounting.
60
+ The viewer container must have a real width and height before mounting:
33
61
 
34
62
  ```html
35
63
  <div id="rx-viewer" style="width: 100%; height: 640px"></div>
36
64
  ```
37
65
 
38
- ## No Framework
66
+ ### Plain HTML Without A Bundler
39
67
 
40
- For a plain HTML page without a framework or bundler, install the package and add an import map before your module script.
68
+ Browsers cannot resolve npm package names directly from a plain
69
+ `<script type="module">` without a bundler or import map. Install the package
70
+ and add an import map before your module script:
41
71
 
42
72
  ```html
43
73
  <div id="rx-viewer" style="width: 100%; height: 640px"></div>
@@ -54,9 +84,7 @@ For a plain HTML page without a framework or bundler, install the package and ad
54
84
  <script type="module">
55
85
  import { createViewer } from "@rasterex/viewer";
56
86
 
57
- const viewer = createViewer({
58
- container: "#rx-viewer"
59
- });
87
+ const viewer = createViewer({ container: "#rx-viewer" });
60
88
 
61
89
  await viewer.mount();
62
90
  await viewer.ready();
@@ -65,6 +93,8 @@ For a plain HTML page without a framework or bundler, install the package and ad
65
93
 
66
94
  ## Quick Start
67
95
 
96
+ Create a viewer, mount its iframe, then wait for Canvas to become ready:
97
+
68
98
  ```ts
69
99
  import { createViewer } from "@rasterex/viewer";
70
100
 
@@ -76,39 +106,34 @@ await viewer.mount();
76
106
  await viewer.ready();
77
107
  ```
78
108
 
79
- By default, the SDK loads Rasterex's hosted Canvas environment for evaluation
80
- and proof-of-concept testing:
109
+ Without `viewerUrl`, this uses the hosted Sandbox. `targetOrigin` is derived
110
+ from the viewer URL when it is not provided.
81
111
 
82
- ```txt
83
- https://sandbox.rasterex.com
84
- ```
112
+ ## Open A Document
85
113
 
86
- `targetOrigin` is derived from the viewer URL when it is not provided.
87
-
88
- For customer production deployments, set `viewerUrl` to your self-hosted
89
- Rasterex Canvas URL.
90
-
91
- ## Open A File URL
114
+ After the viewer is ready, open a document URL:
92
115
 
93
116
  ```ts
94
117
  await viewer.documents.open({
95
- url: "https://pdfobject.com/pdf/sample.pdf",
118
+ url: "https://res.cloudinary.com/dvgeew3bj/image/upload/v1779169700/Main_version_1.pdf_1_ifrgjq.pdf",
96
119
  displayName: "sample.pdf",
97
120
  cacheId: "file_7f3a9c2_sample_pdf",
98
121
  mime: "application/pdf"
99
122
  });
100
123
  ```
101
124
 
102
- The file URL must be reachable by the viewer environment.
125
+ The file URL must be reachable by the viewer environment. This example uses a
126
+ public PDF for Sandbox demonstration only; production URLs must be reachable
127
+ by your self-hosted Rasterex Canvas deployment.
103
128
 
104
- This example uses a public PDF for demonstration only. In production, provide
105
- a file URL that is reachable by your self-hosted Rasterex Canvas deployment.
129
+ `displayName` should include the file extension, such as `sample.pdf`.
130
+ `cacheId` should be a stable file or content ID from your application or server,
131
+ not the display name. It lets the server reuse already processed content for the
132
+ same file, which can make repeat opens faster.
106
133
 
107
- `displayName` should include the file extension, for example `sample.pdf`.
134
+ ### Create, Mount, And Open In One Call
108
135
 
109
- `cacheId` should be a stable file/content ID from your application or server, not the display file name. It lets the server reuse already processed content for the same file, which can make repeat opens faster.
110
-
111
- ## Mount And Open In One Call
136
+ Use `createDocumentViewer` when the first action should be opening a document:
112
137
 
113
138
  ```ts
114
139
  import { createDocumentViewer } from "@rasterex/viewer";
@@ -116,56 +141,13 @@ import { createDocumentViewer } from "@rasterex/viewer";
116
141
  const viewer = await createDocumentViewer({
117
142
  container: "#rx-viewer",
118
143
  document: {
119
- url: "https://pdfobject.com/pdf/sample.pdf",
144
+ url: "https://res.cloudinary.com/dvgeew3bj/image/upload/v1779169700/Main_version_1.pdf_1_ifrgjq.pdf",
120
145
  displayName: "sample.pdf"
121
146
  }
122
147
  });
123
148
  ```
124
149
 
125
- ## Custom Viewer URL
126
-
127
- For customer production deployments, use `viewerUrl` for your self-hosted
128
- Rasterex Canvas URL. The default hosted Canvas environment is intended for
129
- evaluation and proof-of-concept testing.
130
-
131
- ```ts
132
- import { createViewer } from "@rasterex/viewer";
133
-
134
- const viewer = createViewer({
135
- container: "#rx-viewer",
136
- viewerUrl: "https://viewer.example.com",
137
- targetOrigin: "https://viewer.example.com"
138
- });
139
-
140
- await viewer.mount();
141
- await viewer.ready();
142
- ```
143
-
144
- If `targetOrigin` is omitted, the SDK uses `new URL(viewerUrl).origin`.
145
-
146
- ## Tools
147
-
148
- ```ts
149
- await viewer.tools.set({
150
- group: "measurement",
151
- action: "MEASURE_LENGTH",
152
- enabled: true
153
- });
154
-
155
- viewer.tools.clear();
156
- ```
157
-
158
- ## Annotation Events
159
-
160
- ```ts
161
- const unsubscribe = viewer.annotations.on("created", (event) => {
162
- console.log(event.guid, event.data);
163
- });
164
-
165
- unsubscribe();
166
- ```
167
-
168
- ## Options
150
+ ## Configuration
169
151
 
170
152
  ```ts
171
153
  interface RasterexViewerOptions {
@@ -195,38 +177,6 @@ interface RasterexViewerOptions {
195
177
  | `iframeClassName` | CSS class applied to the iframe. |
196
178
  | `iframeAttributes` | Extra iframe attributes, for example `{ allow: "fullscreen" }`. |
197
179
 
198
- ## Presets
199
-
200
- Presets are optional and are exported from a separate entrypoint.
201
-
202
- ```ts
203
- import { createViewer } from "@rasterex/viewer";
204
- import { sandboxCanvas, takeoffDemo } from "@rasterex/viewer/demo-presets";
205
-
206
- const viewer = createViewer({
207
- container: "#rx-viewer",
208
- viewerUrl: sandboxCanvas.viewerUrl,
209
- targetOrigin: sandboxCanvas.targetOrigin
210
- });
211
- ```
212
-
213
- Takeoff is not loaded by default. Use `takeoffDemo` only when your app explicitly chooses that preset.
214
-
215
- ## TypeScript
216
-
217
- Types are included.
218
-
219
- ```ts
220
- import type {
221
- DocumentOpenOptions,
222
- RasterexViewerOptions,
223
- ToolAction,
224
- ToolGroup
225
- } from "@rasterex/viewer";
226
- ```
227
-
228
- TypeScript will report invalid option names, unsupported tool actions, and wrong payload shapes at compile time.
229
-
230
180
  ## Common APIs
231
181
 
232
182
  ```ts
@@ -234,35 +184,88 @@ await viewer.documents.open({ url: "/files/sample.pdf", displayName: "sample.pdf
234
184
  await viewer.tools.set({ group: "measurement", action: "MEASURE_LENGTH", enabled: true });
235
185
  viewer.tools.clear();
236
186
  viewer.annotations.select({ guid: "annotation-guid" });
187
+
237
188
  const snapshot = await viewer.layers.getLayers();
238
189
  const firstLayer = snapshot.layers[0];
239
190
  if (firstLayer?.index !== undefined) {
240
191
  await viewer.layers.setLayerVisibility({ index: firstLayer.index, visible: false });
241
192
  }
193
+
242
194
  const blocks = await viewer.blocks.getBlocks();
243
195
  const firstBlock = blocks.blocks[0];
244
196
  if (firstBlock?.index !== undefined) {
245
197
  await viewer.blocks.getBlockDetails({ index: firstBlock.index });
246
198
  viewer.blocks.setBlockVisibility({ index: firstBlock.index, visible: false });
247
199
  }
200
+
248
201
  viewer.compare.compare({ backgroundUrl: "old.pdf", overlayUrl: "new.pdf" });
249
202
  viewer.styles.setGlobalAppearance({ strokeColor: "#164863" });
250
203
  viewer.diagnostics.on("transport.error", (event) => console.error(event.error));
251
204
  ```
252
205
 
253
- ## Cleanup
206
+ ### Tool Control
207
+
208
+ ```ts
209
+ await viewer.tools.set({
210
+ group: "measurement",
211
+ action: "MEASURE_LENGTH",
212
+ enabled: true
213
+ });
214
+
215
+ viewer.tools.clear();
216
+ ```
254
217
 
255
- Destroy the viewer when the page, route, or component no longer needs it.
218
+ ### Annotation Events
256
219
 
257
220
  ```ts
258
- viewer.destroy();
221
+ const unsubscribe = viewer.annotations.on("created", (event) => {
222
+ console.log(event.guid, event.data);
223
+ });
224
+
225
+ unsubscribe();
259
226
  ```
260
227
 
261
- ## License
228
+ ## TypeScript
262
229
 
263
- This npm SDK is licensed under the MIT License.
230
+ Types are included with the package:
231
+
232
+ ```ts
233
+ import type {
234
+ DocumentOpenOptions,
235
+ RasterexViewerOptions,
236
+ ToolAction,
237
+ ToolGroup
238
+ } from "@rasterex/viewer";
239
+ ```
240
+
241
+ TypeScript reports invalid option names, unsupported tool actions, and invalid
242
+ payload shapes at compile time.
243
+
244
+ ## Optional Demo Presets
245
+
246
+ Hosted presets are exported from a separate entrypoint:
247
+
248
+ ```ts
249
+ import { createViewer } from "@rasterex/viewer";
250
+ import { sandboxCanvas, takeoffDemo } from "@rasterex/viewer/demo-presets";
264
251
 
265
- The SDK embeds Rasterex Canvas/viewer deployments through an iframe. The Rasterex Canvas application, hosted services, server components, viewer assets, and customer deployments are not licensed by this SDK package and remain subject to their own licenses and agreements.
252
+ const viewer = createViewer({
253
+ container: "#rx-viewer",
254
+ viewerUrl: sandboxCanvas.viewerUrl,
255
+ targetOrigin: sandboxCanvas.targetOrigin
256
+ });
257
+ ```
258
+
259
+ Takeoff is not loaded by default. Use `takeoffDemo` only when your application
260
+ explicitly selects that preset.
261
+
262
+ ## Cleanup
263
+
264
+ Destroy the viewer when the page, route, or component no longer needs it:
265
+
266
+ ```ts
267
+ viewer.destroy();
268
+ ```
266
269
 
267
270
  ## Supply Chain Security
268
271
 
@@ -283,6 +286,14 @@ npm pack --json
283
286
  ```
284
287
 
285
288
  Install the generated tarball in a clean project and verify the public package
286
- imports before publishing.
289
+ imports before publishing. See `SECURITY.md` for the vulnerability reporting
290
+ policy and package security scope.
291
+
292
+ ## License
293
+
294
+ This npm SDK is licensed under the MIT License.
287
295
 
288
- See `SECURITY.md` for the vulnerability reporting policy and package security scope.
296
+ The SDK embeds Rasterex Canvas/viewer deployments through an iframe. The
297
+ Rasterex Canvas application, hosted services, server components, viewer assets,
298
+ and customer deployments are not licensed by this SDK package and remain
299
+ subject to their own licenses and agreements.
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "1.1.0";
1
+ export declare const SDK_VERSION = "1.1.1";
2
2
  export declare const DEFAULT_VIEWER_URL = "https://sandbox.rasterex.com";
3
3
  export declare const DEFAULT_TARGET_ORIGIN = "https://sandbox.rasterex.com";
4
4
  export declare const DEFAULT_IFRAME_TITLE = "Rasterex Viewer";
package/dist/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "1.1.0";
1
+ export const SDK_VERSION = "1.1.1";
2
2
  export const DEFAULT_VIEWER_URL = "https://sandbox.rasterex.com";
3
3
  export const DEFAULT_TARGET_ORIGIN = "https://sandbox.rasterex.com";
4
4
  export const DEFAULT_IFRAME_TITLE = "Rasterex Viewer";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasterex/viewer",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "TypeScript SDK for embedding Rasterex Canvas in web applications via iframe and PostMessage. Built for customer self-hosted deployments; hosted Canvas is available for evaluation and proof-of-concept testing.",
5
5
  "author": {
6
6
  "name": "Rasterex Software AS",