@file-viewer/svelte 2.0.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.
- package/LICENSE +160 -0
- package/README.en.md +175 -0
- package/README.md +175 -0
- package/dist/controller.d.ts +121 -0
- package/dist/controller.js +417 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +78 -0
- package/package.json +78 -0
- package/src/FileViewer.svelte +163 -0
- package/src/FileViewer.svelte.d.ts +51 -0
- package/src/controller.ts +593 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
|
3
|
+
import { createViewerControllerHandle, mountViewer as mountCoreViewer } from './controller.js'
|
|
4
|
+
import { fileViewerCoreRendererRegistry } from '@file-viewer/core'
|
|
5
|
+
|
|
6
|
+
export let url = undefined
|
|
7
|
+
export let file = undefined
|
|
8
|
+
export let buffer = undefined
|
|
9
|
+
export let name = undefined
|
|
10
|
+
export let filename = undefined
|
|
11
|
+
export let type = undefined
|
|
12
|
+
export let size = undefined
|
|
13
|
+
export let options = undefined
|
|
14
|
+
export let onEvent = undefined
|
|
15
|
+
export let className = ''
|
|
16
|
+
export let containerStyle = ''
|
|
17
|
+
|
|
18
|
+
const dispatch = createEventDispatcher()
|
|
19
|
+
let container
|
|
20
|
+
let controller = null
|
|
21
|
+
const viewerCoreOptions = {
|
|
22
|
+
registry: fileViewerCoreRendererRegistry
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$: viewerOptions = {
|
|
26
|
+
url,
|
|
27
|
+
file,
|
|
28
|
+
buffer,
|
|
29
|
+
name,
|
|
30
|
+
filename,
|
|
31
|
+
type,
|
|
32
|
+
size,
|
|
33
|
+
options,
|
|
34
|
+
onEvent(event) {
|
|
35
|
+
onEvent?.(event)
|
|
36
|
+
dispatch('viewerEvent', event)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const dispose = () => {
|
|
41
|
+
controller?.destroy()
|
|
42
|
+
controller = null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const handle = createViewerControllerHandle(() => controller, dispose)
|
|
46
|
+
|
|
47
|
+
onMount(() => {
|
|
48
|
+
controller = mountCoreViewer(container, viewerOptions, viewerCoreOptions)
|
|
49
|
+
return dispose
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
onDestroy(dispose)
|
|
53
|
+
|
|
54
|
+
$: if (controller) {
|
|
55
|
+
controller.update(viewerOptions)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getController() {
|
|
59
|
+
return handle.getController()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getApi() {
|
|
63
|
+
return handle.getApi()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function load(nextOptions) {
|
|
67
|
+
return handle.load(nextOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function update(nextOptions) {
|
|
71
|
+
return handle.update(nextOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function reload() {
|
|
75
|
+
return handle.reload()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function downloadOriginalFile() {
|
|
79
|
+
return handle.downloadOriginalFile()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function printRenderedHtml() {
|
|
83
|
+
return handle.printRenderedHtml()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function exportRenderedHtml() {
|
|
87
|
+
return handle.exportRenderedHtml()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function zoomIn() {
|
|
91
|
+
return handle.zoomIn()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function zoomOut() {
|
|
95
|
+
return handle.zoomOut()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function resetZoom() {
|
|
99
|
+
return handle.resetZoom()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function searchDocument(query) {
|
|
103
|
+
return handle.searchDocument(query)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function clearDocumentSearch() {
|
|
107
|
+
return handle.clearDocumentSearch()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function nextSearchResult() {
|
|
111
|
+
return handle.nextSearchResult()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function previousSearchResult() {
|
|
115
|
+
return handle.previousSearchResult()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function collectDocumentAnchors() {
|
|
119
|
+
return handle.collectDocumentAnchors()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function scrollToAnchor(anchor) {
|
|
123
|
+
return handle.scrollToAnchor(anchor)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function scrollToLine(line) {
|
|
127
|
+
return handle.scrollToLine(line)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getDocumentTextChunks() {
|
|
131
|
+
return handle.getDocumentTextChunks()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function getOperationAvailability() {
|
|
135
|
+
return handle.getOperationAvailability()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getZoomState() {
|
|
139
|
+
return handle.getZoomState()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function getSearchState() {
|
|
143
|
+
return handle.getSearchState()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function getState() {
|
|
147
|
+
return handle.getState()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function subscribe(listener) {
|
|
151
|
+
return handle.subscribe(listener)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function destroy() {
|
|
155
|
+
handle.destroy()
|
|
156
|
+
}
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<div
|
|
160
|
+
bind:this={container}
|
|
161
|
+
class={className}
|
|
162
|
+
style={`width: 100%; height: 100%; min-height: 0; ${containerStyle}`}
|
|
163
|
+
/>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SvelteComponentTyped } from 'svelte'
|
|
2
|
+
import type {
|
|
3
|
+
ViewerController,
|
|
4
|
+
ViewerControllerHandle,
|
|
5
|
+
ViewerEvent,
|
|
6
|
+
ViewerMountOptions,
|
|
7
|
+
ViewerStateListener,
|
|
8
|
+
} from './controller.js'
|
|
9
|
+
|
|
10
|
+
export interface FileViewerSvelteProps extends ViewerMountOptions {
|
|
11
|
+
className?: string
|
|
12
|
+
containerStyle?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface FileViewerSvelteEvents {
|
|
16
|
+
viewerEvent: CustomEvent<ViewerEvent>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FileViewerSvelteHandle extends ViewerControllerHandle {}
|
|
20
|
+
|
|
21
|
+
export default class FileViewer extends SvelteComponentTyped<
|
|
22
|
+
FileViewerSvelteProps,
|
|
23
|
+
FileViewerSvelteEvents,
|
|
24
|
+
Record<string, never>
|
|
25
|
+
> implements FileViewerSvelteHandle {
|
|
26
|
+
getController(): ViewerController | null
|
|
27
|
+
getApi(): ReturnType<ViewerController['getApi']>
|
|
28
|
+
load(options: ViewerMountOptions): Promise<void>
|
|
29
|
+
update(options?: ViewerMountOptions): Promise<void>
|
|
30
|
+
reload(): Promise<void>
|
|
31
|
+
downloadOriginalFile(): ReturnType<ViewerControllerHandle['downloadOriginalFile']>
|
|
32
|
+
printRenderedHtml(): ReturnType<ViewerControllerHandle['printRenderedHtml']>
|
|
33
|
+
exportRenderedHtml(): ReturnType<ViewerControllerHandle['exportRenderedHtml']>
|
|
34
|
+
zoomIn(): ReturnType<ViewerControllerHandle['zoomIn']>
|
|
35
|
+
zoomOut(): ReturnType<ViewerControllerHandle['zoomOut']>
|
|
36
|
+
resetZoom(): ReturnType<ViewerControllerHandle['resetZoom']>
|
|
37
|
+
searchDocument(query: string): ReturnType<ViewerControllerHandle['searchDocument']>
|
|
38
|
+
clearDocumentSearch(): ReturnType<ViewerControllerHandle['clearDocumentSearch']>
|
|
39
|
+
nextSearchResult(): ReturnType<ViewerControllerHandle['nextSearchResult']>
|
|
40
|
+
previousSearchResult(): ReturnType<ViewerControllerHandle['previousSearchResult']>
|
|
41
|
+
collectDocumentAnchors(): ReturnType<ViewerControllerHandle['collectDocumentAnchors']>
|
|
42
|
+
scrollToAnchor(anchor: Parameters<ViewerControllerHandle['scrollToAnchor']>[0]): ReturnType<ViewerControllerHandle['scrollToAnchor']>
|
|
43
|
+
scrollToLine(line: number): ReturnType<ViewerControllerHandle['scrollToLine']>
|
|
44
|
+
getDocumentTextChunks(): ReturnType<ViewerControllerHandle['getDocumentTextChunks']>
|
|
45
|
+
getOperationAvailability(): ReturnType<ViewerControllerHandle['getOperationAvailability']>
|
|
46
|
+
getZoomState(): ReturnType<ViewerControllerHandle['getZoomState']>
|
|
47
|
+
getSearchState(): ReturnType<ViewerControllerHandle['getSearchState']>
|
|
48
|
+
getState(): ReturnType<ViewerControllerHandle['getState']>
|
|
49
|
+
subscribe(listener: ViewerStateListener): ReturnType<ViewerControllerHandle['subscribe']>
|
|
50
|
+
destroy(): void
|
|
51
|
+
}
|