@edgepdf/viewer-js 0.0.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 +197 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11802 -0
- package/dist/lib/coordinate-mapper.d.ts +229 -0
- package/dist/lib/coordinate-mapper.d.ts.map +1 -0
- package/dist/lib/marker-delete-popup.d.ts +20 -0
- package/dist/lib/marker-delete-popup.d.ts.map +1 -0
- package/dist/lib/marker-edit-popup.d.ts +23 -0
- package/dist/lib/marker-edit-popup.d.ts.map +1 -0
- package/dist/lib/marker-manager.d.ts +408 -0
- package/dist/lib/marker-manager.d.ts.map +1 -0
- package/dist/lib/tile-layer-manager.d.ts +108 -0
- package/dist/lib/tile-layer-manager.d.ts.map +1 -0
- package/dist/lib/viewer.d.ts +135 -0
- package/dist/lib/viewer.d.ts.map +1 -0
- package/dist/lib/zoom-controller.d.ts +182 -0
- package/dist/lib/zoom-controller.d.ts.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @edgepdf/viewer-js
|
|
2
|
+
|
|
3
|
+
Core JavaScript library for the EdgePDF viewer, providing Leaflet map integration for displaying and interacting with PDF/image tiles.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @edgepdf/viewer-js
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @edgepdf/viewer-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Note:** Leaflet is bundled with this library, so you don't need to install it separately. However, you do need to import the CSS:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import '@edgepdf/viewer-js/styles.css';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Basic Example
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { EdgePdfViewer } from '@edgepdf/viewer-js';
|
|
25
|
+
import '@edgepdf/viewer-js/styles.css'; // Required: Leaflet CSS
|
|
26
|
+
import type { ViewerConfig } from '@edgepdf/types';
|
|
27
|
+
|
|
28
|
+
// Get container element
|
|
29
|
+
const container = document.getElementById('map-container');
|
|
30
|
+
|
|
31
|
+
// Configure viewer
|
|
32
|
+
const config: ViewerConfig = {
|
|
33
|
+
tileUrl: 'https://example.com/tiles/{z}/{x}/{y}.png',
|
|
34
|
+
imageInfo: {
|
|
35
|
+
width: 2000,
|
|
36
|
+
height: 3000,
|
|
37
|
+
tileSize: 256,
|
|
38
|
+
maxZoom: 5,
|
|
39
|
+
minZoom: 0
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Create and initialize viewer
|
|
44
|
+
const viewer = new EdgePdfViewer({ container, config });
|
|
45
|
+
viewer.initialize();
|
|
46
|
+
|
|
47
|
+
// Cleanup when done
|
|
48
|
+
viewer.dispose();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With Custom Map Options
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { EdgePdfViewer } from '@edgepdf/viewer-js';
|
|
55
|
+
import '@edgepdf/viewer-js/styles.css'; // Required: Leaflet CSS
|
|
56
|
+
import type { ViewerConfig, MapOptions } from '@edgepdf/types';
|
|
57
|
+
|
|
58
|
+
const config: ViewerConfig = {
|
|
59
|
+
tileUrl: 'https://example.com/tiles/{z}/{x}/{y}.png',
|
|
60
|
+
imageInfo: {
|
|
61
|
+
width: 2000,
|
|
62
|
+
height: 3000,
|
|
63
|
+
tileSize: 256,
|
|
64
|
+
maxZoom: 5,
|
|
65
|
+
minZoom: 0
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const mapOptions: MapOptions = {
|
|
70
|
+
center: [1500, 1000], // [y, x] in pixel coordinates
|
|
71
|
+
zoom: 2,
|
|
72
|
+
minZoom: 0,
|
|
73
|
+
maxZoom: 5
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const viewer = new EdgePdfViewer({
|
|
77
|
+
container: document.getElementById('map-container'),
|
|
78
|
+
config,
|
|
79
|
+
mapOptions
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
viewer.initialize();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### EdgePdfViewer
|
|
88
|
+
|
|
89
|
+
Main class for initializing and managing Leaflet map instances.
|
|
90
|
+
|
|
91
|
+
#### Constructor
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
new EdgePdfViewer(options: {
|
|
95
|
+
container: HTMLElement;
|
|
96
|
+
config: ViewerConfig;
|
|
97
|
+
mapOptions?: MapOptions;
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Parameters:**
|
|
102
|
+
- `container` - HTML element that will contain the map
|
|
103
|
+
- `config` - Viewer configuration with tile URL and image info
|
|
104
|
+
- `mapOptions` - Optional Leaflet map options (center, zoom, etc.)
|
|
105
|
+
|
|
106
|
+
**Throws:**
|
|
107
|
+
- `Error` if container is not provided or invalid
|
|
108
|
+
- `Error` if config is not provided or invalid
|
|
109
|
+
- `Error` if tileUrl is missing
|
|
110
|
+
- `Error` if imageInfo is missing
|
|
111
|
+
|
|
112
|
+
#### Methods
|
|
113
|
+
|
|
114
|
+
##### `initialize(): void`
|
|
115
|
+
|
|
116
|
+
Initializes the Leaflet map with custom CRS (Coordinate Reference System). Sets up a custom CRS.Simple coordinate system suitable for displaying image tiles without geographic coordinates.
|
|
117
|
+
|
|
118
|
+
**Throws:**
|
|
119
|
+
- `Error` if map initialization fails
|
|
120
|
+
|
|
121
|
+
##### `getMap(): L.Map | null`
|
|
122
|
+
|
|
123
|
+
Gets the Leaflet map instance.
|
|
124
|
+
|
|
125
|
+
**Returns:** The Leaflet map instance, or `null` if not initialized
|
|
126
|
+
|
|
127
|
+
##### `isInitialized(): boolean`
|
|
128
|
+
|
|
129
|
+
Checks if the map is initialized.
|
|
130
|
+
|
|
131
|
+
**Returns:** `true` if map is initialized, `false` otherwise
|
|
132
|
+
|
|
133
|
+
##### `dispose(): void`
|
|
134
|
+
|
|
135
|
+
Disposes of the map instance and cleans up resources. This should be called when the viewer is no longer needed to prevent memory leaks and event listener issues.
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
### ViewerConfig
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
interface ViewerConfig {
|
|
143
|
+
tileUrl: string; // Tile URL template with {z}, {x}, {y} placeholders
|
|
144
|
+
imageInfo: ImageInfo; // Image metadata
|
|
145
|
+
onPinsUpdate?: (pins: Marker[]) => void; // Optional callback for marker updates
|
|
146
|
+
originalImagePath?: string; // Optional original image path
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### ImageInfo
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
interface ImageInfo {
|
|
154
|
+
width: number; // Original image width in pixels
|
|
155
|
+
height: number; // Original image height in pixels
|
|
156
|
+
tileSize: number; // Tile size in pixels (default: 256)
|
|
157
|
+
maxZoom: number; // Maximum zoom level
|
|
158
|
+
minZoom: number; // Minimum zoom level
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### MapOptions
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
interface MapOptions {
|
|
166
|
+
center?: [number, number]; // Initial center coordinates [y, x]
|
|
167
|
+
zoom?: number; // Initial zoom level
|
|
168
|
+
minZoom?: number; // Minimum zoom level
|
|
169
|
+
maxZoom?: number; // Maximum zoom level
|
|
170
|
+
bounds?: {
|
|
171
|
+
southwest: [number, number];
|
|
172
|
+
northeast: [number, number];
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Coordinate System
|
|
178
|
+
|
|
179
|
+
The viewer uses Leaflet's `CRS.Simple` coordinate system, which treats coordinates as pixel positions rather than geographic lat/lng. This is ideal for displaying image tiles:
|
|
180
|
+
|
|
181
|
+
- X-axis: horizontal pixel position (0 to image width)
|
|
182
|
+
- Y-axis: vertical pixel position (0 to image height)
|
|
183
|
+
- Origin: top-left corner (0, 0)
|
|
184
|
+
|
|
185
|
+
## Building
|
|
186
|
+
|
|
187
|
+
Run `nx build viewer-js` to build the library.
|
|
188
|
+
|
|
189
|
+
## Running Tests
|
|
190
|
+
|
|
191
|
+
Run `nx test viewer-js` to execute the unit tests via [Jest](https://jestjs.io).
|
|
192
|
+
|
|
193
|
+
Run `nx test viewer-js --coverage` to generate coverage reports.
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './lib/viewer.js';
|
|
2
|
+
export { EdgePdfViewer } from './lib/viewer.js';
|
|
3
|
+
export { TileLayerManager } from './lib/tile-layer-manager.js';
|
|
4
|
+
export { CoordinateMapper } from './lib/coordinate-mapper.js';
|
|
5
|
+
export { ZoomController } from './lib/zoom-controller.js';
|
|
6
|
+
export { MarkerManager } from './lib/marker-manager.js';
|
|
7
|
+
export type { CreateMarkerOptions } from './lib/marker-manager.js';
|
|
8
|
+
export type { ImageInfo, TileConfig, ViewerConfig, LeafletCoords, ImageCoords, Marker, MarkerData, MapOptions, ZoomConfig, ZoomState, CoordinateBounds, MarkerEventType, MarkerEvent, MarkerEditHandler, MarkerDeleteHandler, MarkerInteractionConfig, MarkerSelectionState, } from '@edgepdf/types';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGnE,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"}
|