@file-viewer/renderer-image 2.0.11
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 +35 -0
- package/README.md +35 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +178 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
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, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work by
|
|
47
|
+
the copyright owner or by an individual or Legal Entity authorized to submit on
|
|
48
|
+
behalf of the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent to the
|
|
50
|
+
Licensor or its representatives, including but not limited to communication on
|
|
51
|
+
electronic mailing lists, source code control systems, and issue tracking systems
|
|
52
|
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
53
|
+
and improving the Work, but excluding communication that is conspicuously marked
|
|
54
|
+
or otherwise designated in writing by the copyright owner as "Not a
|
|
55
|
+
Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
62
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
63
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
64
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
65
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
66
|
+
Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
69
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
70
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
71
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
72
|
+
transfer the Work, where such license applies only to those patent claims
|
|
73
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
74
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
75
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
76
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
77
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
78
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
79
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
80
|
+
such litigation is filed.
|
|
81
|
+
|
|
82
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
83
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
84
|
+
Source or Object form, provided that You meet the following conditions:
|
|
85
|
+
|
|
86
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
87
|
+
this License; and
|
|
88
|
+
|
|
89
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
90
|
+
You changed the files; and
|
|
91
|
+
|
|
92
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
93
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
94
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
95
|
+
of the Derivative Works; and
|
|
96
|
+
|
|
97
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
98
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
99
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
100
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
101
|
+
following places: within a NOTICE text file distributed as part of the Derivative
|
|
102
|
+
Works; within the Source form or documentation, if provided along with the
|
|
103
|
+
Derivative Works; or, within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents of the NOTICE
|
|
105
|
+
file are for informational purposes only and do not modify the License. You may
|
|
106
|
+
add Your own attribution notices within Derivative Works that You distribute,
|
|
107
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that such
|
|
108
|
+
additional attribution notices cannot be construed as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
111
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
112
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
113
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
114
|
+
with the conditions stated in this License.
|
|
115
|
+
|
|
116
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
117
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
118
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
119
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
120
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
121
|
+
executed with Licensor regarding such Contributions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
124
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
125
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
126
|
+
reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
129
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
130
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
131
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
132
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
135
|
+
associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
138
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
139
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
140
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
141
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
142
|
+
arising as a result of this License or out of the use or inability to use the
|
|
143
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
144
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
145
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
146
|
+
damages.
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
150
|
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
|
151
|
+
rights consistent with this License. However, in accepting such obligations, You
|
|
152
|
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
|
153
|
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
|
154
|
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
|
155
|
+
such Contributor by reason of your accepting any such warranty or additional
|
|
156
|
+
liability.
|
|
157
|
+
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
Copyright 2026 Flyfish Viewer
|
package/README.en.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @file-viewer/renderer-image
|
|
2
|
+
|
|
3
|
+
Standalone image renderer package for Flyfish File Viewer. It handles browser-side preview, lightbox viewing, and unified zoom for `png`, `jpg`, `webp`, `avif`, `gif`, `svg`, `tiff`, `ico`, `heic`, `heif`, `jxl`, and related image files.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { imageRenderer } from '@file-viewer/renderer-image'
|
|
9
|
+
|
|
10
|
+
const options = {
|
|
11
|
+
builtinRenderers: 'none',
|
|
12
|
+
renderers: [imageRenderer],
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or compose it through the full preset:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { allRenderers } from '@file-viewer/preset-all'
|
|
20
|
+
|
|
21
|
+
const options = {
|
|
22
|
+
builtinRenderers: 'none',
|
|
23
|
+
renderers: allRenderers,
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Common image formats use native browser decoding without extra runtime work.
|
|
30
|
+
- HEIC / HEIF dynamically imports `heic2any` only when those formats are opened.
|
|
31
|
+
- Includes lightbox viewing, a unified zoom provider, theme-aware background, and unmount cleanup.
|
|
32
|
+
|
|
33
|
+
## Migration Note
|
|
34
|
+
|
|
35
|
+
`@file-viewer/core` still keeps lightweight native image preview for browser-supported PNG / JPEG / SVG / WebP formats, but it no longer installs `heic2any` by default. Install this package explicitly, or use `@file-viewer/preset-all`, when HEIC / HEIF conversion or the full standalone image renderer is required.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @file-viewer/renderer-image
|
|
2
|
+
|
|
3
|
+
Flyfish File Viewer 的独立图片 renderer 包。它负责 `png`、`jpg`、`webp`、`avif`、`gif`、`svg`、`tiff`、`ico`、`heic`、`heif`、`jxl` 等图片类文件的浏览器端预览、灯箱查看和统一缩放。
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { imageRenderer } from '@file-viewer/renderer-image'
|
|
9
|
+
|
|
10
|
+
const options = {
|
|
11
|
+
builtinRenderers: 'none',
|
|
12
|
+
renderers: [imageRenderer],
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
也可以通过全量 preset 自动装配:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { allRenderers } from '@file-viewer/preset-all'
|
|
20
|
+
|
|
21
|
+
const options = {
|
|
22
|
+
builtinRenderers: 'none',
|
|
23
|
+
renderers: allRenderers,
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 能力
|
|
28
|
+
|
|
29
|
+
- 普通图片使用浏览器原生解码,不引入额外运行时。
|
|
30
|
+
- HEIC / HEIF 只在命中格式时动态加载 `heic2any` 并转换为 PNG Data URL。
|
|
31
|
+
- 支持图片灯箱、统一缩放 provider、明暗主题背景和组件卸载清理。
|
|
32
|
+
|
|
33
|
+
## 迁移说明
|
|
34
|
+
|
|
35
|
+
`@file-viewer/core` 仍保留 PNG / JPEG / SVG / WebP 等浏览器原生图片的轻量预览,但已不再默认安装 `heic2any`。需要 HEIC / HEIF 转换预览、或希望完全由独立图片 renderer 接管图片链路时,请显式安装本包,或直接使用 `@file-viewer/preset-all` 聚合能力。
|
package/dist/image.d.ts
ADDED
package/dist/image.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createFileViewerZoomChangeEmitter as createZoomChangeEmitter, registerFileViewerZoomProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
|
+
const imageMimeMap = {
|
|
3
|
+
avif: 'image/avif',
|
|
4
|
+
bmp: 'image/bmp',
|
|
5
|
+
gif: 'image/gif',
|
|
6
|
+
heic: 'image/heic',
|
|
7
|
+
heif: 'image/heif',
|
|
8
|
+
ico: 'image/x-icon',
|
|
9
|
+
jxl: 'image/jxl',
|
|
10
|
+
jpg: 'image/jpeg',
|
|
11
|
+
jpeg: 'image/jpeg',
|
|
12
|
+
png: 'image/png',
|
|
13
|
+
svg: 'image/svg+xml',
|
|
14
|
+
tif: 'image/tiff',
|
|
15
|
+
tiff: 'image/tiff',
|
|
16
|
+
webp: 'image/webp',
|
|
17
|
+
};
|
|
18
|
+
const imageStyle = `
|
|
19
|
+
.image-viewer{position:relative;width:100%;height:100%;overflow:auto;background:#eef1f4;box-sizing:border-box}
|
|
20
|
+
.image-stage{min-width:100%;min-height:100%;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box}
|
|
21
|
+
.image-stage img{display:block;width:auto;max-width:none;margin:0 auto;border:0;box-shadow:0 18px 48px rgba(15,23,42,.16);background:#fff;cursor:zoom-in}
|
|
22
|
+
.image-lightbox{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:40px;background:rgba(15,23,42,.88);box-sizing:border-box}
|
|
23
|
+
.image-lightbox[hidden]{display:none}
|
|
24
|
+
.image-lightbox img{display:block;max-width:100%;max-height:100%;object-fit:contain;background:#fff;box-shadow:0 30px 80px rgba(0,0,0,.4);cursor:zoom-out}
|
|
25
|
+
.image-lightbox button{position:absolute;top:20px;right:20px;width:40px;height:40px;border:0;border-radius:999px;background:rgba(255,255,255,.92);color:#172033;font-size:24px;line-height:40px;cursor:pointer;box-shadow:0 12px 28px rgba(0,0,0,.18)}
|
|
26
|
+
.file-viewer[data-viewer-theme='dark'] .image-viewer{background:#101820}
|
|
27
|
+
@media (prefers-color-scheme:dark){.file-viewer[data-viewer-theme='system'] .image-viewer{background:#101820}}
|
|
28
|
+
@media (max-width:767px){.image-stage{padding:12px}.image-lightbox{padding:16px}.image-lightbox button{top:12px;right:12px}}
|
|
29
|
+
`;
|
|
30
|
+
const createStyle = () => {
|
|
31
|
+
const style = document.createElement('style');
|
|
32
|
+
style.textContent = imageStyle;
|
|
33
|
+
return style;
|
|
34
|
+
};
|
|
35
|
+
const getImageBlobType = (type) => {
|
|
36
|
+
const normalized = (type || '').trim().toLowerCase();
|
|
37
|
+
return imageMimeMap[normalized] || 'image/*';
|
|
38
|
+
};
|
|
39
|
+
const readBlobDataUrl = async (blob) => {
|
|
40
|
+
return await new Promise((resolve, reject) => {
|
|
41
|
+
const reader = new FileReader();
|
|
42
|
+
reader.onload = event => {
|
|
43
|
+
var _a;
|
|
44
|
+
const result = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
45
|
+
if (typeof result === 'string') {
|
|
46
|
+
resolve(result);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
reject(new Error('Unable to read image data URL.'));
|
|
50
|
+
};
|
|
51
|
+
reader.onerror = () => reject(reader.error || new Error('Unable to read image data URL.'));
|
|
52
|
+
reader.readAsDataURL(blob);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const renderHeic = async (buffer, type) => {
|
|
56
|
+
const { default: heic2any } = await import('heic2any');
|
|
57
|
+
const result = await heic2any({
|
|
58
|
+
blob: new Blob([buffer], { type: getImageBlobType(type) }),
|
|
59
|
+
toType: 'image/png',
|
|
60
|
+
});
|
|
61
|
+
const blob = Array.isArray(result) ? result[0] : result;
|
|
62
|
+
return readBlobDataUrl(blob);
|
|
63
|
+
};
|
|
64
|
+
const resolveImageUrl = async (buffer, type) => {
|
|
65
|
+
const normalizedType = (type || '').trim().toLowerCase();
|
|
66
|
+
if (normalizedType === 'heic' || normalizedType === 'heif') {
|
|
67
|
+
return renderHeic(buffer, normalizedType);
|
|
68
|
+
}
|
|
69
|
+
return readBlobDataUrl(new Blob([buffer], { type: getImageBlobType(normalizedType) }));
|
|
70
|
+
};
|
|
71
|
+
const clampZoom = (value) => {
|
|
72
|
+
return Math.min(5, Math.max(0.1, Number(value.toFixed(2))));
|
|
73
|
+
};
|
|
74
|
+
const applyImageZoom = (image, viewportHeight, zoom) => {
|
|
75
|
+
if (viewportHeight > 0) {
|
|
76
|
+
image.style.height = `${Math.max(1, Math.round(viewportHeight * zoom))}px`;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
image.style.height = `${zoom * 100}%`;
|
|
80
|
+
};
|
|
81
|
+
const createLightbox = (src) => {
|
|
82
|
+
const lightbox = document.createElement('div');
|
|
83
|
+
lightbox.className = 'image-lightbox';
|
|
84
|
+
lightbox.hidden = true;
|
|
85
|
+
lightbox.setAttribute('role', 'dialog');
|
|
86
|
+
lightbox.setAttribute('aria-modal', 'true');
|
|
87
|
+
const image = document.createElement('img');
|
|
88
|
+
image.alt = 'Preview image';
|
|
89
|
+
image.src = src;
|
|
90
|
+
const closeButton = document.createElement('button');
|
|
91
|
+
closeButton.type = 'button';
|
|
92
|
+
closeButton.setAttribute('aria-label', 'Close image preview');
|
|
93
|
+
closeButton.textContent = 'x';
|
|
94
|
+
const close = () => {
|
|
95
|
+
lightbox.hidden = true;
|
|
96
|
+
};
|
|
97
|
+
closeButton.addEventListener('click', close);
|
|
98
|
+
image.addEventListener('click', close);
|
|
99
|
+
lightbox.addEventListener('click', event => {
|
|
100
|
+
if (event.target === lightbox) {
|
|
101
|
+
close();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
lightbox.append(image, closeButton);
|
|
105
|
+
return {
|
|
106
|
+
element: lightbox,
|
|
107
|
+
open() {
|
|
108
|
+
lightbox.hidden = false;
|
|
109
|
+
},
|
|
110
|
+
destroy() {
|
|
111
|
+
closeButton.removeEventListener('click', close);
|
|
112
|
+
image.removeEventListener('click', close);
|
|
113
|
+
lightbox.remove();
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export default async function renderImage(buffer, target, type) {
|
|
118
|
+
const src = await resolveImageUrl(buffer, type);
|
|
119
|
+
let zoom = 1;
|
|
120
|
+
let viewportHeight = 0;
|
|
121
|
+
const zoomEmitter = createZoomChangeEmitter();
|
|
122
|
+
const root = document.createElement('div');
|
|
123
|
+
root.className = 'image-viewer';
|
|
124
|
+
root.dataset.viewerZoomProvider = 'image';
|
|
125
|
+
const stage = document.createElement('div');
|
|
126
|
+
stage.className = 'image-stage';
|
|
127
|
+
const image = document.createElement('img');
|
|
128
|
+
image.alt = '图片';
|
|
129
|
+
image.src = src;
|
|
130
|
+
stage.append(image);
|
|
131
|
+
root.append(stage);
|
|
132
|
+
const lightbox = createLightbox(src);
|
|
133
|
+
const openLightbox = () => lightbox.open();
|
|
134
|
+
image.addEventListener('click', openLightbox);
|
|
135
|
+
document.body.append(lightbox.element);
|
|
136
|
+
const updateViewportSize = () => {
|
|
137
|
+
viewportHeight = root.clientHeight || 0;
|
|
138
|
+
applyImageZoom(image, viewportHeight, zoom);
|
|
139
|
+
zoomEmitter.emit();
|
|
140
|
+
};
|
|
141
|
+
const resizeObserver = new ResizeObserver(updateViewportSize);
|
|
142
|
+
resizeObserver.observe(root);
|
|
143
|
+
const getZoomState = () => ({
|
|
144
|
+
scale: zoom,
|
|
145
|
+
label: `${Math.round(zoom * 100)}%`,
|
|
146
|
+
canZoomIn: zoom < 5,
|
|
147
|
+
canZoomOut: zoom > 0.1,
|
|
148
|
+
canReset: zoom !== 1,
|
|
149
|
+
minScale: 0.1,
|
|
150
|
+
maxScale: 5,
|
|
151
|
+
});
|
|
152
|
+
const setZoom = (scale) => {
|
|
153
|
+
zoom = clampZoom(scale);
|
|
154
|
+
applyImageZoom(image, viewportHeight, zoom);
|
|
155
|
+
zoomEmitter.emit();
|
|
156
|
+
return getZoomState();
|
|
157
|
+
};
|
|
158
|
+
registerFileViewerZoomProvider(root, {
|
|
159
|
+
zoomIn: () => setZoom(zoom + 0.15),
|
|
160
|
+
zoomOut: () => setZoom(zoom - 0.15),
|
|
161
|
+
resetZoom: () => setZoom(1),
|
|
162
|
+
setZoom,
|
|
163
|
+
getState: getZoomState,
|
|
164
|
+
subscribe: zoomEmitter.subscribe,
|
|
165
|
+
});
|
|
166
|
+
target.replaceChildren(createStyle(), root);
|
|
167
|
+
updateViewportSize();
|
|
168
|
+
return {
|
|
169
|
+
$el: target,
|
|
170
|
+
unmount() {
|
|
171
|
+
unregisterFileViewerZoomProvider(root);
|
|
172
|
+
resizeObserver.disconnect();
|
|
173
|
+
image.removeEventListener('click', openLightbox);
|
|
174
|
+
lightbox.destroy();
|
|
175
|
+
target.replaceChildren();
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FileRenderHandler, type FileViewerRenderedInstance, type FileViewerRendererPlugin, type RendererDefinition } from '@file-viewer/core';
|
|
2
|
+
export declare const imageRendererDefinition: RendererDefinition;
|
|
3
|
+
export declare const renderFileViewerImage: FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
|
|
4
|
+
export declare const imageRenderer: FileViewerRendererPlugin<FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>>;
|
|
5
|
+
export default imageRenderer;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DEFAULT_RENDERER_DEFINITIONS, } from '@file-viewer/core';
|
|
2
|
+
const imageDefinition = DEFAULT_RENDERER_DEFINITIONS.find(definition => definition.id === 'image');
|
|
3
|
+
if (!imageDefinition) {
|
|
4
|
+
throw new Error('@file-viewer/renderer-image could not locate the core image renderer definition.');
|
|
5
|
+
}
|
|
6
|
+
export const imageRendererDefinition = imageDefinition;
|
|
7
|
+
export const renderFileViewerImage = (buffer, target, type) => import('./image.js').then(({ default: renderImage }) => renderImage(buffer, target, type));
|
|
8
|
+
export const imageRenderer = {
|
|
9
|
+
id: 'file-viewer-renderer-image',
|
|
10
|
+
label: 'Flyfish File Viewer image renderer',
|
|
11
|
+
definitions: [imageRendererDefinition],
|
|
12
|
+
handlers: [{
|
|
13
|
+
rendererId: imageRendererDefinition.id,
|
|
14
|
+
handler: renderFileViewerImage,
|
|
15
|
+
}],
|
|
16
|
+
};
|
|
17
|
+
export default imageRenderer;
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@file-viewer/renderer-image",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Standalone image renderer plugin for Flyfish File Viewer with native image preview, HEIC/HEIF conversion, lightbox, and unified zoom support.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"file-viewer",
|
|
9
|
+
"renderer",
|
|
10
|
+
"image",
|
|
11
|
+
"heic",
|
|
12
|
+
"heif",
|
|
13
|
+
"document-preview",
|
|
14
|
+
"document-viewer",
|
|
15
|
+
"file-preview",
|
|
16
|
+
"self-hosted"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Wangyu",
|
|
24
|
+
"email": "wybaby168@gmail.com"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/flyfish-dev/file-viewer-renderer-image.git",
|
|
29
|
+
"directory": "packages/renderers/image"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://doc.file-viewer.app/guide/on-demand-renderers",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/flyfish-dev/file-viewer-renderer-image/issues"
|
|
34
|
+
},
|
|
35
|
+
"funding": {
|
|
36
|
+
"type": "individual",
|
|
37
|
+
"url": "https://dev.flyfish.group/shop"
|
|
38
|
+
},
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"module": "./dist/index.js",
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"import": "./dist/index.js",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"README.md",
|
|
53
|
+
"README.en.md",
|
|
54
|
+
"LICENSE"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@file-viewer/core": "^2.0.11",
|
|
58
|
+
"heic2any": "^0.0.4"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"typescript": "^6.0.3"
|
|
62
|
+
},
|
|
63
|
+
"license": "Apache-2.0",
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc -b tsconfig.json",
|
|
66
|
+
"type-check": "tsc -b tsconfig.json"
|
|
67
|
+
}
|
|
68
|
+
}
|