@haklex/rich-renderer-image 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/LICENSE +28 -0
- package/README.md +48 -0
- package/dist/ImageEditRenderer.d.ts +3 -0
- package/dist/ImageEditRenderer.d.ts.map +1 -0
- package/dist/ImageRenderer.d.ts +4 -0
- package/dist/ImageRenderer.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +335 -0
- package/dist/rich-renderer-image.css +211 -0
- package/dist/styles.css.d.ts +2 -0
- package/dist/styles.css.d.ts.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Innei
|
|
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.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Additional Terms and Conditions
|
|
25
|
+
|
|
26
|
+
----------------
|
|
27
|
+
|
|
28
|
+
Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @haklex/rich-renderer-image
|
|
2
|
+
|
|
3
|
+
图片渲染器,支持 Thumbhash 模糊占位和灯箱。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @haklex/rich-renderer-image @haklex/rich-editor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 导出
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
export { ImageRenderer } from './ImageRenderer'
|
|
15
|
+
export { ImageEditRenderer } from './ImageEditRenderer'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 功能
|
|
19
|
+
|
|
20
|
+
- Thumbhash 模糊占位
|
|
21
|
+
- 图片灯箱(react-photo-view)
|
|
22
|
+
- 图片说明
|
|
23
|
+
- 加载状态
|
|
24
|
+
|
|
25
|
+
## 使用
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { ImageRenderer } from '@haklex/rich-renderer-image'
|
|
29
|
+
import type { RendererConfig } from '@haklex/rich-editor'
|
|
30
|
+
|
|
31
|
+
const config: RendererConfig = {
|
|
32
|
+
Image: ImageRenderer,
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 依赖
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"@haklex/rich-editor": "workspace:*",
|
|
41
|
+
"react-photo-view": "^1.2.0",
|
|
42
|
+
"thumbhash": "^0.1.0"
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageEditRenderer.d.ts","sourceRoot":"","sources":["../src/ImageEditRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AAErB,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,qBAAqB,CAAA;AAqB5B,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,2CAQ1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageRenderer.d.ts","sourceRoot":"","sources":["../src/ImageRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,4CAA4C,CAAA;AACnD,OAAO,cAAc,CAAA;AAErB,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,OAAO,CAAA;AAezD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,kBAAkB,CA4E3D,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { decodeThumbHash, useRendererMode } from "@haklex/rich-editor";
|
|
3
|
+
import { Popover, PopoverTrigger, PopoverPanel } from "@haklex/rich-editor-ui";
|
|
4
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
5
|
+
import { $getNearestNodeFromDOMNode } from "lexical";
|
|
6
|
+
import { ImageIcon, Type, ExternalLink, Trash2 } from "lucide-react";
|
|
7
|
+
import { useState, useMemo, useRef, useEffect, useCallback } from "react";
|
|
8
|
+
import { PhotoProvider, PhotoView } from "react-photo-view";
|
|
9
|
+
function getCaptionText$1(altText, caption) {
|
|
10
|
+
if (caption) return caption;
|
|
11
|
+
if (!altText) return void 0;
|
|
12
|
+
if (altText.startsWith("!") || altText.startsWith("¡")) {
|
|
13
|
+
return altText.slice(1);
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const ImageRenderer = ({
|
|
18
|
+
src,
|
|
19
|
+
altText,
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
caption,
|
|
23
|
+
thumbhash,
|
|
24
|
+
accent
|
|
25
|
+
}) => {
|
|
26
|
+
const [state, setState] = useState("loading");
|
|
27
|
+
const captionText = useMemo(
|
|
28
|
+
() => getCaptionText$1(altText, caption),
|
|
29
|
+
[altText, caption]
|
|
30
|
+
);
|
|
31
|
+
const placeholderUrl = useMemo(
|
|
32
|
+
() => thumbhash ? decodeThumbHash(thumbhash) : void 0,
|
|
33
|
+
[thumbhash]
|
|
34
|
+
);
|
|
35
|
+
if (!src) return null;
|
|
36
|
+
const frameStyle = {
|
|
37
|
+
backgroundColor: !placeholderUrl ? accent || "#f5f5f5" : void 0,
|
|
38
|
+
backgroundImage: placeholderUrl && state !== "loaded" ? `url(${placeholderUrl})` : void 0,
|
|
39
|
+
backgroundSize: "cover",
|
|
40
|
+
width: width ? Math.min(width, 1200) : void 0,
|
|
41
|
+
maxWidth: "100%",
|
|
42
|
+
...width && height ? { aspectRatio: `${width} / ${height}` } : {}
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs("figure", { className: "rr-image-root", children: [
|
|
45
|
+
/* @__PURE__ */ jsx(PhotoProvider, { photoClosable: true, children: /* @__PURE__ */ jsx(PhotoView, { src, children: /* @__PURE__ */ jsxs(
|
|
46
|
+
"div",
|
|
47
|
+
{
|
|
48
|
+
className: `rr-image-frame rr-image-${state}`,
|
|
49
|
+
style: frameStyle,
|
|
50
|
+
role: "button",
|
|
51
|
+
tabIndex: 0,
|
|
52
|
+
"aria-label": `Open image: ${altText || "image"}`,
|
|
53
|
+
onKeyDown: (e) => {
|
|
54
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.currentTarget.click();
|
|
57
|
+
},
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
"img",
|
|
61
|
+
{
|
|
62
|
+
src,
|
|
63
|
+
alt: altText,
|
|
64
|
+
width,
|
|
65
|
+
height,
|
|
66
|
+
loading: "lazy",
|
|
67
|
+
className: "rr-image-img",
|
|
68
|
+
onLoad: () => setState("loaded"),
|
|
69
|
+
onError: () => setState("error")
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
state === "loading" && /* @__PURE__ */ jsx("span", { className: "rr-image-loader" }),
|
|
73
|
+
state === "error" && /* @__PURE__ */ jsx("span", { className: "rr-image-error", children: "Image failed to load" })
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
) }) }),
|
|
77
|
+
captionText && /* @__PURE__ */ jsx("figcaption", { className: "rr-image-caption", children: captionText })
|
|
78
|
+
] });
|
|
79
|
+
};
|
|
80
|
+
function getCaptionText(altText, caption) {
|
|
81
|
+
if (caption) return caption;
|
|
82
|
+
if (!altText) return void 0;
|
|
83
|
+
if (altText.startsWith("!") || altText.startsWith("¡")) {
|
|
84
|
+
return altText.slice(1);
|
|
85
|
+
}
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
88
|
+
function ImageEditRenderer(props) {
|
|
89
|
+
const mode = useRendererMode();
|
|
90
|
+
if (mode !== "editor") {
|
|
91
|
+
return /* @__PURE__ */ jsx(ImageRenderer, { ...props });
|
|
92
|
+
}
|
|
93
|
+
return /* @__PURE__ */ jsx(ImageEditRendererInner, { ...props });
|
|
94
|
+
}
|
|
95
|
+
function ImageEditRendererInner({
|
|
96
|
+
src,
|
|
97
|
+
altText,
|
|
98
|
+
width,
|
|
99
|
+
height,
|
|
100
|
+
caption,
|
|
101
|
+
thumbhash,
|
|
102
|
+
accent
|
|
103
|
+
}) {
|
|
104
|
+
const [editor] = useLexicalComposerContext();
|
|
105
|
+
const editable = editor.isEditable();
|
|
106
|
+
const wrapperRef = useRef(null);
|
|
107
|
+
const srcInputRef = useRef(null);
|
|
108
|
+
const [open, setOpen] = useState(!src);
|
|
109
|
+
const [editSrc, setEditSrc] = useState(src);
|
|
110
|
+
const [editAltText, setEditAltText] = useState(altText);
|
|
111
|
+
const [editCaption, setEditCaption] = useState(caption || "");
|
|
112
|
+
const [state, setState] = useState("loading");
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
setEditSrc(src);
|
|
115
|
+
setEditAltText(altText);
|
|
116
|
+
setEditCaption(caption || "");
|
|
117
|
+
}, [src, altText, caption]);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!src) setOpen(true);
|
|
120
|
+
}, [src]);
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (open) {
|
|
123
|
+
requestAnimationFrame(() => srcInputRef.current?.focus());
|
|
124
|
+
}
|
|
125
|
+
}, [open]);
|
|
126
|
+
const placeholderUrl = useMemo(
|
|
127
|
+
() => thumbhash ? decodeThumbHash(thumbhash) : void 0,
|
|
128
|
+
[thumbhash]
|
|
129
|
+
);
|
|
130
|
+
const captionText = useMemo(
|
|
131
|
+
() => getCaptionText(altText, caption),
|
|
132
|
+
[altText, caption]
|
|
133
|
+
);
|
|
134
|
+
const commitChanges = useCallback(() => {
|
|
135
|
+
const trimmedSrc = editSrc.trim();
|
|
136
|
+
if (!trimmedSrc) return;
|
|
137
|
+
if (/^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i.test(trimmedSrc))
|
|
138
|
+
return;
|
|
139
|
+
if (!wrapperRef.current) return;
|
|
140
|
+
editor.update(() => {
|
|
141
|
+
const node = $getNearestNodeFromDOMNode(wrapperRef.current);
|
|
142
|
+
if (!node) return;
|
|
143
|
+
const writable = node.getWritable();
|
|
144
|
+
writable.__src = trimmedSrc;
|
|
145
|
+
writable.__altText = editAltText.trim();
|
|
146
|
+
writable.__caption = editCaption.trim() || void 0;
|
|
147
|
+
});
|
|
148
|
+
setOpen(false);
|
|
149
|
+
}, [editor, editSrc, editAltText, editCaption]);
|
|
150
|
+
const handleDelete = useCallback(() => {
|
|
151
|
+
if (!wrapperRef.current) return;
|
|
152
|
+
editor.update(() => {
|
|
153
|
+
const node = $getNearestNodeFromDOMNode(wrapperRef.current);
|
|
154
|
+
if (node) node.remove();
|
|
155
|
+
});
|
|
156
|
+
setOpen(false);
|
|
157
|
+
}, [editor]);
|
|
158
|
+
const handleOpen = useCallback(() => {
|
|
159
|
+
if (src) window.open(src, "_blank", "noopener,noreferrer");
|
|
160
|
+
}, [src]);
|
|
161
|
+
const handleKeyDown = useCallback(
|
|
162
|
+
(e) => {
|
|
163
|
+
if (e.key === "Enter") {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
commitChanges();
|
|
166
|
+
} else if (e.key === "Escape") {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
setEditSrc(src);
|
|
169
|
+
setEditAltText(altText);
|
|
170
|
+
setEditCaption(caption || "");
|
|
171
|
+
setOpen(false);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
[commitChanges, src, altText, caption]
|
|
175
|
+
);
|
|
176
|
+
if (!editable) {
|
|
177
|
+
return /* @__PURE__ */ jsx(
|
|
178
|
+
ImageRenderer,
|
|
179
|
+
{
|
|
180
|
+
src,
|
|
181
|
+
altText,
|
|
182
|
+
width,
|
|
183
|
+
height,
|
|
184
|
+
caption,
|
|
185
|
+
thumbhash,
|
|
186
|
+
accent
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const frameStyle = {
|
|
191
|
+
backgroundColor: !placeholderUrl ? accent || "#f5f5f5" : void 0,
|
|
192
|
+
backgroundImage: placeholderUrl && state !== "loaded" ? `url(${placeholderUrl})` : void 0,
|
|
193
|
+
backgroundSize: "cover",
|
|
194
|
+
width: width ? Math.min(width, 1200) : void 0,
|
|
195
|
+
maxWidth: "100%",
|
|
196
|
+
...width && height ? { aspectRatio: `${width} / ${height}` } : {}
|
|
197
|
+
};
|
|
198
|
+
return /* @__PURE__ */ jsxs(
|
|
199
|
+
Popover,
|
|
200
|
+
{
|
|
201
|
+
open,
|
|
202
|
+
onOpenChange: (nextOpen) => {
|
|
203
|
+
setOpen(nextOpen);
|
|
204
|
+
if (!nextOpen) {
|
|
205
|
+
setEditSrc(src);
|
|
206
|
+
setEditAltText(altText);
|
|
207
|
+
setEditCaption(caption || "");
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
children: [
|
|
211
|
+
/* @__PURE__ */ jsx(
|
|
212
|
+
PopoverTrigger,
|
|
213
|
+
{
|
|
214
|
+
render: /* @__PURE__ */ jsx("div", { ref: wrapperRef, className: "rr-image-edit-trigger" }),
|
|
215
|
+
children: src ? /* @__PURE__ */ jsxs("figure", { className: "rr-image-root", children: [
|
|
216
|
+
/* @__PURE__ */ jsxs(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
className: `rr-image-frame rr-image-${state}`,
|
|
220
|
+
style: frameStyle,
|
|
221
|
+
children: [
|
|
222
|
+
/* @__PURE__ */ jsx(
|
|
223
|
+
"img",
|
|
224
|
+
{
|
|
225
|
+
src,
|
|
226
|
+
alt: altText,
|
|
227
|
+
width,
|
|
228
|
+
height,
|
|
229
|
+
loading: "lazy",
|
|
230
|
+
className: "rr-image-img",
|
|
231
|
+
onLoad: () => setState("loaded"),
|
|
232
|
+
onError: () => setState("error")
|
|
233
|
+
}
|
|
234
|
+
),
|
|
235
|
+
state === "loading" && /* @__PURE__ */ jsx("span", { className: "rr-image-loader" }),
|
|
236
|
+
state === "error" && /* @__PURE__ */ jsx("span", { className: "rr-image-error", children: "Image failed to load" })
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
),
|
|
240
|
+
captionText && /* @__PURE__ */ jsx("figcaption", { className: "rr-image-caption", children: captionText })
|
|
241
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "rr-image-edit-placeholder", children: [
|
|
242
|
+
/* @__PURE__ */ jsx(ImageIcon, { size: 24 }),
|
|
243
|
+
/* @__PURE__ */ jsx("span", { children: "Click to add image" })
|
|
244
|
+
] })
|
|
245
|
+
}
|
|
246
|
+
),
|
|
247
|
+
/* @__PURE__ */ jsxs(
|
|
248
|
+
PopoverPanel,
|
|
249
|
+
{
|
|
250
|
+
side: "bottom",
|
|
251
|
+
sideOffset: 8,
|
|
252
|
+
className: "rr-image-edit-panel",
|
|
253
|
+
children: [
|
|
254
|
+
/* @__PURE__ */ jsxs("div", { className: "rr-image-edit-field", children: [
|
|
255
|
+
/* @__PURE__ */ jsx(ImageIcon, { className: "rr-image-edit-field-icon", size: 14 }),
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
"input",
|
|
258
|
+
{
|
|
259
|
+
ref: srcInputRef,
|
|
260
|
+
className: "rr-image-edit-input",
|
|
261
|
+
type: "url",
|
|
262
|
+
value: editSrc,
|
|
263
|
+
onChange: (e) => setEditSrc(e.target.value),
|
|
264
|
+
onKeyDown: handleKeyDown,
|
|
265
|
+
placeholder: "Image URL"
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
] }),
|
|
269
|
+
/* @__PURE__ */ jsxs("div", { className: "rr-image-edit-field", children: [
|
|
270
|
+
/* @__PURE__ */ jsx(Type, { className: "rr-image-edit-field-icon", size: 14 }),
|
|
271
|
+
/* @__PURE__ */ jsx(
|
|
272
|
+
"input",
|
|
273
|
+
{
|
|
274
|
+
className: "rr-image-edit-input",
|
|
275
|
+
type: "text",
|
|
276
|
+
value: editAltText,
|
|
277
|
+
onChange: (e) => setEditAltText(e.target.value),
|
|
278
|
+
onKeyDown: handleKeyDown,
|
|
279
|
+
placeholder: "Alt text"
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
] }),
|
|
283
|
+
/* @__PURE__ */ jsxs("div", { className: "rr-image-edit-field", children: [
|
|
284
|
+
/* @__PURE__ */ jsx(Type, { className: "rr-image-edit-field-icon", size: 14 }),
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
"input",
|
|
287
|
+
{
|
|
288
|
+
className: "rr-image-edit-input",
|
|
289
|
+
type: "text",
|
|
290
|
+
value: editCaption,
|
|
291
|
+
onChange: (e) => setEditCaption(e.target.value),
|
|
292
|
+
onBlur: commitChanges,
|
|
293
|
+
onKeyDown: handleKeyDown,
|
|
294
|
+
placeholder: "Caption (optional)"
|
|
295
|
+
}
|
|
296
|
+
)
|
|
297
|
+
] }),
|
|
298
|
+
/* @__PURE__ */ jsxs("div", { className: "rr-image-edit-actions", children: [
|
|
299
|
+
/* @__PURE__ */ jsxs(
|
|
300
|
+
"button",
|
|
301
|
+
{
|
|
302
|
+
className: "rr-image-edit-action-btn",
|
|
303
|
+
type: "button",
|
|
304
|
+
onClick: handleOpen,
|
|
305
|
+
children: [
|
|
306
|
+
/* @__PURE__ */ jsx(ExternalLink, { size: 14 }),
|
|
307
|
+
"Open"
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ jsxs(
|
|
312
|
+
"button",
|
|
313
|
+
{
|
|
314
|
+
className: "rr-image-edit-action-btn rr-image-edit-action-btn--end",
|
|
315
|
+
type: "button",
|
|
316
|
+
onClick: handleDelete,
|
|
317
|
+
children: [
|
|
318
|
+
/* @__PURE__ */ jsx(Trash2, { size: 14 }),
|
|
319
|
+
"Remove"
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
] })
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
export {
|
|
332
|
+
ImageEditRenderer,
|
|
333
|
+
ImageRenderer,
|
|
334
|
+
ImageRenderer as default
|
|
335
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
@keyframes _1n94osf0 {
|
|
2
|
+
0% {
|
|
3
|
+
mask: linear-gradient(90deg, #000 25%, #000000e6 50%, #00000000) 150% 0 / 400% no-repeat;
|
|
4
|
+
opacity: 0.16;
|
|
5
|
+
}
|
|
6
|
+
100% {
|
|
7
|
+
mask: linear-gradient(90deg, #000 25%, #000000e6 50%, #00000000) 0 / 400% no-repeat;
|
|
8
|
+
opacity: 1;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
@keyframes _1n94osf1 {
|
|
12
|
+
to {
|
|
13
|
+
transform: rotate(360deg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
@keyframes _1n94osf2 {
|
|
17
|
+
from {
|
|
18
|
+
opacity: 0;
|
|
19
|
+
}
|
|
20
|
+
to {
|
|
21
|
+
opacity: 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
.rr-image-root {
|
|
25
|
+
margin: 1.25rem 0;
|
|
26
|
+
text-align: center;
|
|
27
|
+
}
|
|
28
|
+
.rr-image-frame {
|
|
29
|
+
position: relative;
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
border-radius: var(--rc-radius-md);
|
|
35
|
+
cursor: zoom-in;
|
|
36
|
+
min-height: 3rem;
|
|
37
|
+
transition: transform 0.25s ease;
|
|
38
|
+
}
|
|
39
|
+
.rr-image-frame:hover {
|
|
40
|
+
transform: translateY(-1px);
|
|
41
|
+
}
|
|
42
|
+
.rr-image-img {
|
|
43
|
+
display: block;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: auto;
|
|
46
|
+
max-width: 100%;
|
|
47
|
+
opacity: 0;
|
|
48
|
+
transition: opacity 280ms ease;
|
|
49
|
+
border-radius: 0px !important;
|
|
50
|
+
}
|
|
51
|
+
.rr-image-loaded .rr-image-img {
|
|
52
|
+
opacity: 1;
|
|
53
|
+
animation: _1n94osf0 420ms ease;
|
|
54
|
+
}
|
|
55
|
+
.rr-image-error .rr-image-img {
|
|
56
|
+
display: none;
|
|
57
|
+
}
|
|
58
|
+
.rr-image-loader {
|
|
59
|
+
position: absolute;
|
|
60
|
+
width: 1.65rem;
|
|
61
|
+
height: 1.65rem;
|
|
62
|
+
border: 2px solid color-mix(in srgb, var(--rc-text-secondary) 45%, transparent);
|
|
63
|
+
border-top-color: color-mix(in srgb, var(--rc-text) 65%, transparent);
|
|
64
|
+
border-radius: 50%;
|
|
65
|
+
animation: _1n94osf1 0.75s linear infinite;
|
|
66
|
+
}
|
|
67
|
+
.rr-image-error {
|
|
68
|
+
font-size: 0.8rem;
|
|
69
|
+
color: var(--rc-alert-caution);
|
|
70
|
+
background: color-mix(in srgb, var(--rc-bg) 86%, transparent);
|
|
71
|
+
border-radius: 999px;
|
|
72
|
+
padding: 0.15rem 0.6rem;
|
|
73
|
+
}
|
|
74
|
+
.rr-image-caption {
|
|
75
|
+
margin-top: 0.5rem;
|
|
76
|
+
color: var(--rc-text-secondary);
|
|
77
|
+
font-size: 0.86rem;
|
|
78
|
+
line-height: 1.5;
|
|
79
|
+
}
|
|
80
|
+
.rich-image {
|
|
81
|
+
margin: var(--rc-space-md) 0;
|
|
82
|
+
text-align: center;
|
|
83
|
+
}
|
|
84
|
+
.rich-image figcaption {
|
|
85
|
+
font-size: var(--rc-font-size-small);
|
|
86
|
+
color: var(--rc-text-secondary);
|
|
87
|
+
margin-top: var(--rc-space-sm);
|
|
88
|
+
line-height: var(--rc-line-height-tight);
|
|
89
|
+
}
|
|
90
|
+
.rich-image-container {
|
|
91
|
+
position: relative;
|
|
92
|
+
display: inline-block;
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
border-radius: var(--rc-radius-md);
|
|
95
|
+
transition: background-color 0.3s ease;
|
|
96
|
+
}
|
|
97
|
+
.rich-image-hidden {
|
|
98
|
+
opacity: 0;
|
|
99
|
+
transition: opacity 0.3s ease;
|
|
100
|
+
}
|
|
101
|
+
.rich-image-visible {
|
|
102
|
+
opacity: 1;
|
|
103
|
+
transition: opacity 0.3s ease;
|
|
104
|
+
}
|
|
105
|
+
.rich-image-zoom-overlay {
|
|
106
|
+
position: fixed;
|
|
107
|
+
inset: 0;
|
|
108
|
+
z-index: 9999;
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
justify-content: center;
|
|
112
|
+
background-color: rgba(0, 0, 0, 0.85);
|
|
113
|
+
cursor: zoom-out;
|
|
114
|
+
animation: _1n94osf2 0.2s ease;
|
|
115
|
+
}
|
|
116
|
+
.rich-image-zoom-img {
|
|
117
|
+
max-width: 90vw;
|
|
118
|
+
max-height: 90vh;
|
|
119
|
+
object-fit: contain;
|
|
120
|
+
border-radius: 0;
|
|
121
|
+
}
|
|
122
|
+
.rr-image-edit-trigger {
|
|
123
|
+
display: block;
|
|
124
|
+
cursor: pointer;
|
|
125
|
+
}
|
|
126
|
+
.rr-image-edit-trigger .rr-image-frame {
|
|
127
|
+
cursor: pointer;
|
|
128
|
+
}
|
|
129
|
+
.rr-image-edit-trigger .rr-image-frame:hover {
|
|
130
|
+
transform: none;
|
|
131
|
+
}
|
|
132
|
+
.rr-image-edit-placeholder {
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
justify-content: center;
|
|
136
|
+
gap: 8px;
|
|
137
|
+
padding: 2rem;
|
|
138
|
+
border: 2px dashed var(--rc-border);
|
|
139
|
+
border-radius: var(--rc-radius-md);
|
|
140
|
+
color: var(--rc-text-secondary);
|
|
141
|
+
font-size: 0.875rem;
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
transition: border-color 0.2s, color 0.2s;
|
|
144
|
+
}
|
|
145
|
+
.rr-image-edit-placeholder:hover {
|
|
146
|
+
border-color: var(--rc-accent);
|
|
147
|
+
color: var(--rc-text);
|
|
148
|
+
}
|
|
149
|
+
.rr-image-edit-panel {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
gap: 8px;
|
|
153
|
+
width: 340px;
|
|
154
|
+
padding: 12px;
|
|
155
|
+
font-size: 13px;
|
|
156
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
157
|
+
}
|
|
158
|
+
.rr-image-edit-field {
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
gap: 8px;
|
|
162
|
+
padding: 6px 10px;
|
|
163
|
+
background-color: var(--rc-bg-secondary);
|
|
164
|
+
border-radius: 6px;
|
|
165
|
+
min-width: 0;
|
|
166
|
+
}
|
|
167
|
+
.rr-image-edit-field-icon {
|
|
168
|
+
flex-shrink: 0;
|
|
169
|
+
color: var(--rc-text-secondary);
|
|
170
|
+
}
|
|
171
|
+
.rr-image-edit-input {
|
|
172
|
+
flex: 1;
|
|
173
|
+
appearance: none;
|
|
174
|
+
border: none;
|
|
175
|
+
background-color: transparent;
|
|
176
|
+
color: inherit;
|
|
177
|
+
font-size: 13px;
|
|
178
|
+
padding: 0;
|
|
179
|
+
outline: none;
|
|
180
|
+
min-width: 0;
|
|
181
|
+
}
|
|
182
|
+
.rr-image-edit-input::placeholder {
|
|
183
|
+
color: var(--rc-text-secondary);
|
|
184
|
+
}
|
|
185
|
+
.rr-image-edit-actions {
|
|
186
|
+
display: flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
gap: 4px;
|
|
189
|
+
}
|
|
190
|
+
.rr-image-edit-action-btn {
|
|
191
|
+
display: inline-flex;
|
|
192
|
+
align-items: center;
|
|
193
|
+
gap: 6px;
|
|
194
|
+
appearance: none;
|
|
195
|
+
border: none;
|
|
196
|
+
background: none;
|
|
197
|
+
color: inherit;
|
|
198
|
+
font-size: 13px;
|
|
199
|
+
font-weight: 500;
|
|
200
|
+
cursor: pointer;
|
|
201
|
+
padding: 4px 8px;
|
|
202
|
+
border-radius: 4px;
|
|
203
|
+
transition: color 0.15s ease, background-color 0.15s ease;
|
|
204
|
+
white-space: nowrap;
|
|
205
|
+
}
|
|
206
|
+
.rr-image-edit-action-btn:hover {
|
|
207
|
+
background-color: var(--rc-bg-secondary);
|
|
208
|
+
}
|
|
209
|
+
.rr-image-edit-action-btn--end {
|
|
210
|
+
margin-left: auto;
|
|
211
|
+
}.PhotoView-Portal{direction:ltr;height:100%;left:0;overflow:hidden;position:fixed;top:0;touch-action:none;width:100%;z-index:2000}@keyframes PhotoView__rotate{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}@keyframes PhotoView__delayIn{0%,50%{opacity:0}to{opacity:1}}.PhotoView__Spinner{animation:PhotoView__delayIn .4s linear both}.PhotoView__Spinner svg{animation:PhotoView__rotate .6s linear infinite}.PhotoView__Photo{cursor:grab;max-width:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.PhotoView__Photo:active{cursor:grabbing}.PhotoView__icon{display:inline-block;left:0;position:absolute;top:0;transform:translate(-50%,-50%)}.PhotoView__PhotoBox,.PhotoView__PhotoWrap{bottom:0;direction:ltr;left:0;position:absolute;right:0;top:0;touch-action:none;width:100%}.PhotoView__PhotoWrap{overflow:hidden;z-index:10}.PhotoView__PhotoBox{transform-origin:left top}@keyframes PhotoView__fade{0%{opacity:0}to{opacity:1}}.PhotoView-Slider__clean .PhotoView-Slider__ArrowLeft,.PhotoView-Slider__clean .PhotoView-Slider__ArrowRight,.PhotoView-Slider__clean .PhotoView-Slider__BannerWrap,.PhotoView-Slider__clean .PhotoView-Slider__Overlay,.PhotoView-Slider__willClose .PhotoView-Slider__BannerWrap:hover{opacity:0}.PhotoView-Slider__Backdrop{background:#000;height:100%;left:0;position:absolute;top:0;transition-property:background-color;width:100%;z-index:-1}.PhotoView-Slider__fadeIn{animation:PhotoView__fade linear both;opacity:0}.PhotoView-Slider__fadeOut{animation:PhotoView__fade linear reverse both;opacity:0}.PhotoView-Slider__BannerWrap{align-items:center;background-color:rgba(0,0,0,.5);color:#fff;display:flex;height:44px;justify-content:space-between;left:0;position:absolute;top:0;transition:opacity .2s ease-out;width:100%;z-index:20}.PhotoView-Slider__BannerWrap:hover{opacity:1}.PhotoView-Slider__Counter{font-size:14px;opacity:.75;padding:0 10px}.PhotoView-Slider__BannerRight{align-items:center;display:flex;height:100%}.PhotoView-Slider__toolbarIcon{fill:#fff;box-sizing:border-box;cursor:pointer;opacity:.75;padding:10px;transition:opacity .2s linear}.PhotoView-Slider__toolbarIcon:hover{opacity:1}.PhotoView-Slider__ArrowLeft,.PhotoView-Slider__ArrowRight{align-items:center;bottom:0;cursor:pointer;display:flex;height:100px;justify-content:center;margin:auto;opacity:.75;position:absolute;top:0;transition:opacity .2s linear;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:70px;z-index:20}.PhotoView-Slider__ArrowLeft:hover,.PhotoView-Slider__ArrowRight:hover{opacity:1}.PhotoView-Slider__ArrowLeft svg,.PhotoView-Slider__ArrowRight svg{fill:#fff;background:rgba(0,0,0,.3);box-sizing:content-box;height:24px;padding:10px;width:24px}.PhotoView-Slider__ArrowLeft{left:0}.PhotoView-Slider__ArrowRight{right:0}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.css.d.ts","sourceRoot":"","sources":["../src/styles.css.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@haklex/rich-renderer-image",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Image renderer with blurhash and lightbox",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./style.css": "./dist/rich-renderer-image.css"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.mjs",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"lucide-react": "^0.574.0",
|
|
20
|
+
"react-photo-view": "^1.2.6",
|
|
21
|
+
"thumbhash": "^0.1.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@lexical/react": "^0.39.0",
|
|
25
|
+
"@types/react": "^19.0.0",
|
|
26
|
+
"@types/react-dom": "^19.0.0",
|
|
27
|
+
"@vanilla-extract/css": "^1.17.1",
|
|
28
|
+
"@vanilla-extract/vite-plugin": "^4.0.20",
|
|
29
|
+
"lexical": "^0.39.0",
|
|
30
|
+
"react": "19.2.4",
|
|
31
|
+
"react-dom": "19.2.4",
|
|
32
|
+
"typescript": "^5.9.0",
|
|
33
|
+
"vite": "^7.3.1",
|
|
34
|
+
"vite-plugin-dts": "^4.5.0",
|
|
35
|
+
"@haklex/rich-editor": "0.0.1",
|
|
36
|
+
"@haklex/rich-editor-ui": "0.0.1",
|
|
37
|
+
"@haklex/rich-style-token": "0.0.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@lexical/react": "^0.39.0",
|
|
41
|
+
"lexical": "^0.39.0",
|
|
42
|
+
"react": ">=19",
|
|
43
|
+
"react-dom": ">=19",
|
|
44
|
+
"@haklex/rich-editor": "0.0.1",
|
|
45
|
+
"@haklex/rich-editor-ui": "0.0.1",
|
|
46
|
+
"@haklex/rich-style-token": "0.0.1"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"dev:build": "vite build --watch"
|
|
54
|
+
},
|
|
55
|
+
"types": "./dist/index.d.ts"
|
|
56
|
+
}
|