@haklex/rich-renderer-image 0.0.79 → 0.0.81
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/dist/ImageRenderer-BUTTEOl6.js +131 -0
- package/dist/index.mjs +613 -672
- package/dist/rich-renderer-image.css +2 -1
- package/dist/static.mjs +2 -4
- package/package.json +4 -4
- package/dist/ImageRenderer-DyeaT08P.js +0 -130
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { vars } from "@haklex/rich-editor";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { decodeThumbHash } from "@haklex/rich-editor/renderers";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import "react-photo-view/dist/react-photo-view.css";
|
|
6
|
+
import { PhotoProvider, PhotoView } from "react-photo-view";
|
|
7
|
+
//#region src/styles.css.ts
|
|
8
|
+
var semanticClassNames = {
|
|
9
|
+
root: "rr-image-root",
|
|
10
|
+
frame: "rr-image-frame",
|
|
11
|
+
frameLoading: "rr-image-loading",
|
|
12
|
+
frameLoaded: "rr-image-loaded",
|
|
13
|
+
frameError: "rr-image-error",
|
|
14
|
+
image: "rr-image-img",
|
|
15
|
+
loader: "rr-image-loader",
|
|
16
|
+
errorBadge: "rr-image-error",
|
|
17
|
+
caption: "rr-image-caption",
|
|
18
|
+
editTrigger: "rr-image-edit-trigger",
|
|
19
|
+
editPlaceholder: "rr-image-edit-placeholder",
|
|
20
|
+
editToolbar: "rr-image-edit-toolbar",
|
|
21
|
+
editToolbarVisible: "rr-image-edit-toolbar-visible",
|
|
22
|
+
editToolbarButton: "rr-image-edit-toolbar-button",
|
|
23
|
+
editToolbarButtonDanger: "rr-image-edit-toolbar-danger",
|
|
24
|
+
editPanel: "rr-image-edit-panel",
|
|
25
|
+
editField: "rr-image-edit-field",
|
|
26
|
+
editFieldIcon: "rr-image-edit-field-icon",
|
|
27
|
+
editInput: "rr-image-edit-input",
|
|
28
|
+
replaceUploadArea: "rr-image-replace-upload-area",
|
|
29
|
+
replacePreview: "rr-image-replace-preview",
|
|
30
|
+
panelHint: "rr-image-panel-hint"
|
|
31
|
+
};
|
|
32
|
+
var root = "_1n94osf0";
|
|
33
|
+
var image = "_1n94osf2";
|
|
34
|
+
var imageState = {
|
|
35
|
+
loading: "_1n94osf3",
|
|
36
|
+
loaded: "_1n94osf4",
|
|
37
|
+
error: "_1n94osf5"
|
|
38
|
+
};
|
|
39
|
+
var imageVisible = "_1n94osf6";
|
|
40
|
+
var frame = "_1n94osf7";
|
|
41
|
+
var frameEditMode = "_1n94osf8";
|
|
42
|
+
var loader = "_1n94osfa";
|
|
43
|
+
var errorBadge = "_1n94osfb";
|
|
44
|
+
var caption = "_1n94osfc";
|
|
45
|
+
var editTrigger = "_1n94osfk";
|
|
46
|
+
var editPlaceholder = "_1n94osfl";
|
|
47
|
+
var editToolbar = "_1n94osfm";
|
|
48
|
+
var editToolbarVisible = "_1n94osfn";
|
|
49
|
+
var editToolbarButton = "_1n94osfo";
|
|
50
|
+
var editToolbarButtonDanger = "_1n94osfp";
|
|
51
|
+
var editPanel = "_1n94osfq";
|
|
52
|
+
var editField = "_1n94osfr";
|
|
53
|
+
var editFieldIcon = "_1n94osfs";
|
|
54
|
+
var editInput = "_1n94osft";
|
|
55
|
+
var replaceUploadArea = "_1n94osfu";
|
|
56
|
+
var replacePreview = "_1n94osfv";
|
|
57
|
+
var panelHint = "_1n94osfw";
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/ImageRenderer.tsx
|
|
60
|
+
var frameStateSemanticClass = {
|
|
61
|
+
loading: semanticClassNames.frameLoading,
|
|
62
|
+
loaded: semanticClassNames.frameLoaded,
|
|
63
|
+
error: semanticClassNames.frameError
|
|
64
|
+
};
|
|
65
|
+
function getCaptionText(altText, caption) {
|
|
66
|
+
if (caption) return caption;
|
|
67
|
+
if (!altText) return void 0;
|
|
68
|
+
if (altText.startsWith("!") || altText.startsWith("¡")) return altText.slice(1);
|
|
69
|
+
}
|
|
70
|
+
var ImageRenderer = ({ src, altText, width, height, caption: caption$1, thumbhash, accent }) => {
|
|
71
|
+
const [state, setState] = useState("loading");
|
|
72
|
+
const captionText = useMemo(() => getCaptionText(altText, caption$1), [altText, caption$1]);
|
|
73
|
+
const placeholderUrl = useMemo(() => thumbhash ? decodeThumbHash(thumbhash) : void 0, [thumbhash]);
|
|
74
|
+
if (!src) return null;
|
|
75
|
+
const frameStyle = {
|
|
76
|
+
backgroundColor: state !== "loaded" && !placeholderUrl ? accent || vars.color.bgTertiary : "transparent",
|
|
77
|
+
backgroundImage: placeholderUrl && state !== "loaded" ? `url(${placeholderUrl})` : void 0,
|
|
78
|
+
backgroundSize: "cover",
|
|
79
|
+
width: width ? Math.min(width, 1200) : void 0,
|
|
80
|
+
maxWidth: "100%",
|
|
81
|
+
...width && height ? { aspectRatio: `${width} / ${height}` } : {}
|
|
82
|
+
};
|
|
83
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
84
|
+
className: `${root} ${semanticClassNames.root}`,
|
|
85
|
+
children: [/* @__PURE__ */ jsx(PhotoProvider, {
|
|
86
|
+
photoClosable: true,
|
|
87
|
+
children: /* @__PURE__ */ jsx(PhotoView, {
|
|
88
|
+
src,
|
|
89
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
90
|
+
"aria-label": `Open image: ${altText || "image"}`,
|
|
91
|
+
className: `${frame} ${semanticClassNames.frame} ${imageState[state]} ${frameStateSemanticClass[state]}`.trim(),
|
|
92
|
+
role: "button",
|
|
93
|
+
style: frameStyle,
|
|
94
|
+
tabIndex: 0,
|
|
95
|
+
onKeyDown: (e) => {
|
|
96
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
e.currentTarget.click();
|
|
99
|
+
},
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx("img", {
|
|
102
|
+
alt: altText,
|
|
103
|
+
className: `${image} ${state === "loaded" ? imageVisible : ""} ${semanticClassNames.image}`,
|
|
104
|
+
"data-state": state,
|
|
105
|
+
height,
|
|
106
|
+
loading: "lazy",
|
|
107
|
+
src,
|
|
108
|
+
style: width && height ? {
|
|
109
|
+
height: "100%",
|
|
110
|
+
objectFit: "cover"
|
|
111
|
+
} : void 0,
|
|
112
|
+
width,
|
|
113
|
+
onError: () => setState("error"),
|
|
114
|
+
onLoad: () => setState("loaded")
|
|
115
|
+
}),
|
|
116
|
+
state === "loading" && /* @__PURE__ */ jsx("span", { className: `_1n94osfa ${semanticClassNames.loader}` }),
|
|
117
|
+
state === "error" && /* @__PURE__ */ jsx("span", {
|
|
118
|
+
className: `_1n94osfb ${semanticClassNames.errorBadge}`,
|
|
119
|
+
children: "Image failed to load"
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
}), captionText && /* @__PURE__ */ jsx("figcaption", {
|
|
125
|
+
className: `_1n94osfc ${semanticClassNames.caption}`,
|
|
126
|
+
children: captionText
|
|
127
|
+
})]
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { root as C, replaceUploadArea as S, imageState as _, editInput as a, panelHint as b, editToolbar as c, editToolbarVisible as d, editTrigger as f, image as g, frameEditMode as h, editFieldIcon as i, editToolbarButton as l, frame as m, caption as n, editPanel as o, errorBadge as p, editField as r, editPlaceholder as s, ImageRenderer as t, editToolbarButtonDanger as u, imageVisible as v, semanticClassNames as w, replacePreview as x, loader as y };
|