fangguo-component 1.2.3 → 1.2.5

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.
Files changed (52) hide show
  1. package/dist/{ErrorImage-CFVt1ht_.js → ErrorImage-Ao9kEEUg.js} +2 -2
  2. package/dist/FgCascader.css +2 -14
  3. package/dist/{FgCascader.vue_vue_type_style_index_0_lang-CstlYwHs.js → FgCascader.vue_vue_type_style_index_0_lang-CtUPO8fk.js} +20 -26
  4. package/dist/{HSelect-DgFjd08Y.js → HSelect-0w2mSrtm.js} +1 -1
  5. package/dist/{HSelectAll.vue_vue_type_script_setup_true_lang-C6qzdQT-.js → HSelectAll.vue_vue_type_script_setup_true_lang-xHFbYs59.js} +1 -1
  6. package/dist/{HSelectSJ-DOFUzTZV.js → HSelectSJ-Cm573j6B.js} +1 -1
  7. package/dist/{ImgViewerHost.vue_vue_type_script_setup_true_lang-DBs42WOq.js → ImgViewerHost.vue_vue_type_script_setup_true_lang-DO9s-b9s.js} +42 -3
  8. package/dist/{LazyPopover-7ebuh-QG.js → LazyPopover-CcvilJ6U.js} +25 -3
  9. package/dist/LazyPopover.css +1 -1
  10. package/dist/{SelectTree-DUH92Iwr.js → SelectTree-BHvvkiQi.js} +1 -1
  11. package/dist/ViewImg-CLRjYOUN.js +556 -0
  12. package/dist/ViewImg.css +60 -35
  13. package/dist/ViewImgPopover-BtFnYval.js +463 -0
  14. package/dist/ViewImgPopover.css +28 -26
  15. package/dist/components/cascader/index.js +1 -1
  16. package/dist/components/errorImage/index.js +2 -2
  17. package/dist/components/hSelect/index.js +1 -1
  18. package/dist/components/hSelectAll/index.js +1 -1
  19. package/dist/components/hSelectSJ/index.js +1 -1
  20. package/dist/components/imgViewerHost/ImgViewerHost.vue.d.ts +7 -1
  21. package/dist/components/imgViewerHost/imgViewerAutoHost.d.ts +2 -0
  22. package/dist/components/imgViewerHost/imgViewerHostRegistry.d.ts +5 -0
  23. package/dist/components/imgViewerHost/index.js +2 -2
  24. package/dist/components/index.js +22 -18
  25. package/dist/components/lazyPopover/LazyPopover.vue.d.ts +2 -0
  26. package/dist/components/lazyPopover/index.js +1 -1
  27. package/dist/components/selectTree/index.js +1 -1
  28. package/dist/components/viewImg/ViewImg.vue.d.ts +44 -19
  29. package/dist/components/viewImg/ViewImgErrorFallback.vue.d.ts +17 -0
  30. package/dist/components/viewImg/defaults.d.ts +28 -0
  31. package/dist/components/viewImg/index.d.ts +3 -0
  32. package/dist/components/viewImg/index.js +6 -2
  33. package/dist/components/viewImgPopover/ViewImgPopover.vue.d.ts +207 -99
  34. package/dist/components/viewImgPopover/index.js +1 -1
  35. package/dist/components/viewImgPreview/ViewImgPreview.vue.d.ts +6 -6
  36. package/dist/imgViewerAutoHost-BQVVGop1.js +32 -0
  37. package/dist/{imgViewerStore-DK3zvGf4.js → imgViewerStore-Ajm-L7R5.js} +7 -0
  38. package/dist/{index-Qkq7I01c.js → index-DsfY1yqo.js} +6 -1
  39. package/dist/{index-Ce_edAQB.js → index-wDrpgKQT.js} +17 -13
  40. package/dist/index.d.ts +8 -3
  41. package/dist/index.js +58 -49
  42. package/dist/montageImgUrl-B9ZmJ7TF.js +464 -0
  43. package/dist/tools/ImageParserUtils/index.d.ts +1 -1
  44. package/dist/tools/imgUrl/imageUrl.d.ts +246 -0
  45. package/dist/tools/imgUrl/index.d.ts +2 -0
  46. package/dist/tools/imgUrl/index.js +13 -8
  47. package/dist/tools/imgUrl/montageImgUrl.d.ts +11 -5
  48. package/dist/tools/index.js +19 -14
  49. package/package.json +2 -2
  50. package/dist/ViewImg-DXhF20SL.js +0 -254
  51. package/dist/ViewImgPopover-QblZG0z5.js +0 -343
  52. package/dist/montageImgUrl-CwgYnB2h.js +0 -204
@@ -0,0 +1,556 @@
1
+ import './ViewImg.css';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { defineComponent, computed, openBlock, createElementBlock, createElementVNode, Fragment, normalizeStyle, toDisplayString, reactive, useAttrs, ref, watch, nextTick, onMounted, onUnmounted, unref, normalizeClass, withDirectives, mergeProps, vShow, renderSlot, normalizeProps, guardReactiveProps, createBlock, resolveDynamicComponent, createCommentVNode } from "vue";
33
+ import { _ as _export_sfc } from "./_plugin-vue_export-helper-1tPrXgE0.js";
34
+ import { I as ImgViewerStore } from "./imgViewerStore-Ajm-L7R5.js";
35
+ import { h as DEFAULT_PREVIEW_SIDE_NAV, D as DEFAULT_ORIGINAL_TOOLBAR, l as DEFAULT_TOOLBAR_ICON_COLOR, k as DEFAULT_TOOLBAR_BG_COLOR, g as DEFAULT_PREVIEW_SHOW_PROGRESS, d as DEFAULT_PREVIEW_MAX_SCALE, e as DEFAULT_PREVIEW_MIN_SCALE, f as DEFAULT_PREVIEW_SCALE, j as DEFAULT_PREVIEW_ZOOM_RATE, a as DEFAULT_PREVIEW_CLOSE_ON_PRESS_ESCAPE, b as DEFAULT_PREVIEW_HIDE_ON_CLICK_MODAL, c as DEFAULT_PREVIEW_INFINITE, i as DEFAULT_PREVIEW_TELEPORTED } from "./types-Ccn_sb6f.js";
36
+ import { n as networkKey, i as imgUrlConfigKey, m as montageImgUrl } from "./montageImgUrl-B9ZmJ7TF.js";
37
+ const _hoisted_1$1 = { class: "fg-view-img__error-default" };
38
+ const _hoisted_2$1 = { class: "fg-view-img__error-default-body" };
39
+ const _hoisted_3$1 = {
40
+ class: "fg-view-img__error-icon",
41
+ viewBox: "0 0 1280 1024",
42
+ xmlns: "http://www.w3.org/2000/svg"
43
+ };
44
+ const _hoisted_4 = ["fill"];
45
+ const _hoisted_5 = {
46
+ class: "fg-view-img__error-icon",
47
+ viewBox: "0 0 1131 1024",
48
+ xmlns: "http://www.w3.org/2000/svg"
49
+ };
50
+ const _hoisted_6 = ["fill"];
51
+ const _hoisted_7 = ["fill"];
52
+ const _hoisted_8 = {
53
+ class: "fg-view-img__error-icon",
54
+ viewBox: "0 0 1088 1024",
55
+ xmlns: "http://www.w3.org/2000/svg"
56
+ };
57
+ const _hoisted_9 = ["fill"];
58
+ const DEFAULT_PRIMARY = "#D4DADC";
59
+ const DEFAULT_SECONDARY = "#E1E4E5";
60
+ const DEFAULT_ICON_COLOR = "#c3c6ca";
61
+ const DEFAULT_LOADING_COLOR = "#cfd2d7";
62
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
63
+ __name: "ViewImgErrorFallback",
64
+ props: {
65
+ loading: { type: Boolean, default: false },
66
+ src: { default: "" },
67
+ errorText: { default: "" },
68
+ fallbackColor: { default: "" }
69
+ },
70
+ setup(__props) {
71
+ const props = __props;
72
+ const isEmptySrc = computed(() => !props.src.trim());
73
+ const resolvedLabel = computed(() => props.errorText || "加载失败");
74
+ const customColor = computed(() => {
75
+ var _a;
76
+ return ((_a = props.fallbackColor) == null ? void 0 : _a.trim()) || "";
77
+ });
78
+ function parseHexColor(input) {
79
+ const hex = input.startsWith("#") ? input.slice(1) : input;
80
+ if (/^[0-9a-fA-F]{3}$/.test(hex)) {
81
+ return [0, 1, 2].map((i) => parseInt(hex[i] + hex[i], 16));
82
+ }
83
+ if (/^[0-9a-fA-F]{6}$/.test(hex)) {
84
+ return [0, 2, 4].map((i) => parseInt(hex.slice(i, i + 2), 16));
85
+ }
86
+ return null;
87
+ }
88
+ function parseRgbCss(input) {
89
+ const m = input.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);
90
+ if (!m) return null;
91
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
92
+ }
93
+ function resolveCssColor(input) {
94
+ const fromHex = parseHexColor(input);
95
+ if (fromHex) return fromHex;
96
+ const fromRgb = parseRgbCss(input);
97
+ if (fromRgb) return fromRgb;
98
+ if (typeof document === "undefined") return null;
99
+ const ctx = document.createElement("canvas").getContext("2d");
100
+ if (!ctx) return null;
101
+ ctx.fillStyle = "#000000";
102
+ ctx.fillStyle = input;
103
+ const afterDark = String(ctx.fillStyle);
104
+ ctx.fillStyle = "#ffffff";
105
+ ctx.fillStyle = input;
106
+ const afterLight = String(ctx.fillStyle);
107
+ if (afterDark === "#000000" && afterLight === "#ffffff") return null;
108
+ return parseHexColor(afterDark !== "#000000" ? afterDark : afterLight) || parseRgbCss(afterDark);
109
+ }
110
+ function toHex([r, g, b]) {
111
+ return `#${[r, g, b].map((n) => Math.round(n).toString(16).padStart(2, "0")).join("")}`;
112
+ }
113
+ function tint(rgb, amount) {
114
+ return toHex(rgb.map((c) => c + (255 - c) * amount));
115
+ }
116
+ const colorPalette = computed(() => {
117
+ const base = customColor.value;
118
+ const rgb = base ? resolveCssColor(base) : null;
119
+ if (!rgb) {
120
+ return {
121
+ primary: DEFAULT_PRIMARY,
122
+ secondary: DEFAULT_SECONDARY,
123
+ icon: DEFAULT_ICON_COLOR,
124
+ loading: DEFAULT_LOADING_COLOR,
125
+ label: ""
126
+ };
127
+ }
128
+ return {
129
+ primary: tint(rgb, 0.28),
130
+ secondary: tint(rgb, 0.52),
131
+ icon: tint(rgb, 0.36),
132
+ loading: tint(rgb, 0.32),
133
+ label: tint(rgb, 0.45)
134
+ };
135
+ });
136
+ const resolvedPrimary = computed(() => colorPalette.value.primary);
137
+ const resolvedSecondary = computed(() => colorPalette.value.secondary);
138
+ const resolvedIconColor = computed(() => colorPalette.value.icon);
139
+ const resolvedLoadingColor = computed(() => colorPalette.value.loading);
140
+ const labelStyle = computed(() => {
141
+ if (!colorPalette.value.label) return {};
142
+ return { color: colorPalette.value.label };
143
+ });
144
+ return (_ctx, _cache) => {
145
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
146
+ createElementVNode("div", _hoisted_2$1, [
147
+ __props.loading ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
148
+ (openBlock(), createElementBlock("svg", _hoisted_3$1, [
149
+ createElementVNode("path", {
150
+ d: "M1174.826667 0H105.216A105.258667 105.258667 0 0 0-0.042667 105.258667V918.613333a105.258667 105.258667 0 0 0 105.258667 105.258667h1069.653333A105.258667 105.258667 0 0 0 1280.085333 918.613333V105.258667A105.344 105.344 0 0 0 1174.826667 0z m-402.773334 181.461333a105.386667 105.386667 0 1 1-0.042666 210.773334 105.386667 105.386667 0 0 1 0-210.773334zM104.746667 883.882667S191.018667 381.098667 391.509333 381.098667c196.48 0 246.528 351.616 384.810667 351.616 87.210667 0 78.08-158.72 216.490667-158.72 99.242667 0 162.304 309.888 162.304 309.888H104.789333z",
151
+ fill: resolvedLoadingColor.value
152
+ }, null, 8, _hoisted_4)
153
+ ])),
154
+ createElementVNode("span", {
155
+ class: "fg-view-img__error-label",
156
+ style: normalizeStyle(labelStyle.value)
157
+ }, "加载中", 4)
158
+ ], 64)) : isEmptySrc.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
159
+ (openBlock(), createElementBlock("svg", _hoisted_5, [
160
+ createElementVNode("path", {
161
+ d: "M764.191528 125.736421a125.844211 125.844211 0 0 0 125.898106 125.763368 125.844211 125.844211 0 0 0 125.898105-125.763368A125.844211 125.844211 0 0 0 890.089634 0a125.844211 125.844211 0 0 0-125.898106 125.736421zM317.269423 317.493895L18.261423 807.909053c-50.364632 84.884211 9.431579 191.757474 107.008 191.757473h601.168842c97.549474 0 157.372632-106.873263 106.981053-191.757473L534.465213 317.493895c-50.364632-78.578526-166.804211-78.578526-217.19579 0z",
162
+ fill: resolvedPrimary.value
163
+ }, null, 8, _hoisted_6),
164
+ createElementVNode("path", {
165
+ d: "M742.148581 556.409263l-157.372632 257.778526c-50.337684 84.884211 9.458526 191.784421 107.034948 191.784422h314.745263c97.549474 0 157.372632-106.900211 107.008-191.784422l-157.372632-257.778526c-47.211789-81.731368-166.804211-81.731368-214.016 0z",
166
+ fill: resolvedSecondary.value
167
+ }, null, 8, _hoisted_7)
168
+ ])),
169
+ createElementVNode("span", {
170
+ class: "fg-view-img__error-label",
171
+ style: normalizeStyle(labelStyle.value)
172
+ }, "无图", 4)
173
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
174
+ (openBlock(), createElementBlock("svg", _hoisted_8, [
175
+ createElementVNode("path", {
176
+ d: "M640 138.688a32 32 0 0 1 27.456 48.448L613.76 276.416l31.488 47.232a32 32 0 0 1-12.288 46.336L482.944 444.928l18.112 126.592a32.064 32.064 0 0 1-22.912 35.264l-118.976 33.92 55.68 204.224a32 32 0 0 1-30.848 40.448H149.376a74.688 74.688 0 0 1-74.688-74.688V213.376c0-41.216 33.472-74.688 74.688-74.688H640z m234.624 0c41.216 0 74.688 33.472 74.688 74.688v597.312c0 41.216-33.472 74.688-74.688 74.688H512a32.064 32.064 0 0 1-30.784-23.232l-42.624-149.312a32 32 0 0 1 21.888-39.552l122.944-35.2-17.92-143.36a32 32 0 0 1 18.816-33.28l158.912-70.72-45.376-75.584a32 32 0 0 1 0.832-34.176l85.312-128a32 32 0 0 1 26.624-14.272h64z m-725.248 64a10.688 10.688 0 0 0-10.688 10.688v597.312c0 5.888 4.8 10.688 10.688 10.688h192.768l-52.992-194.24a32 32 0 0 1 22.08-39.168l122.432-35.072-17.344-121.728a32 32 0 0 1 17.344-33.088l138.24-69.12-22.528-33.856a32.064 32.064 0 0 1-0.832-34.24l34.944-58.176H149.376z m613.76 96.896l53.632 89.28a32 32 0 0 1-14.464 45.76L632 510.272l18.368 147.072a32 32 0 0 1-22.912 34.752l-118.656 33.92 27.328 95.36h338.496a10.688 10.688 0 0 0 10.688-10.688V213.376a10.688 10.688 0 0 0-10.688-10.688h-46.848l-64.64 96.896zM309.312 288a64 64 0 1 1 0 128 64 64 0 0 1 0-128z",
177
+ fill: resolvedIconColor.value
178
+ }, null, 8, _hoisted_9)
179
+ ])),
180
+ createElementVNode("span", {
181
+ class: "fg-view-img__error-label",
182
+ style: normalizeStyle(labelStyle.value)
183
+ }, toDisplayString(resolvedLabel.value), 5)
184
+ ], 64))
185
+ ])
186
+ ]);
187
+ };
188
+ }
189
+ });
190
+ const ViewImgErrorFallback = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-4588a25e"]]);
191
+ const viewImgDefaults = reactive({});
192
+ function configureViewImgDefaults(defaults) {
193
+ resetViewImgDefaults();
194
+ Object.assign(viewImgDefaults, defaults);
195
+ }
196
+ function resetViewImgDefaults() {
197
+ delete viewImgDefaults.placeholder;
198
+ delete viewImgDefaults.error;
199
+ delete viewImgDefaults.waterMarkTitle;
200
+ delete viewImgDefaults.loadingIconColor;
201
+ }
202
+ function useViewImgDefaults() {
203
+ return viewImgDefaults;
204
+ }
205
+ const _hoisted_1 = ["src"];
206
+ const _hoisted_2 = {
207
+ key: 0,
208
+ class: "fg-view-img__placeholder"
209
+ };
210
+ const _hoisted_3 = {
211
+ key: 1,
212
+ class: "fg-view-img__error"
213
+ };
214
+ const LAZY_ROOT_MARGIN = "200px";
215
+ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, {
216
+ inheritAttrs: false
217
+ }), {
218
+ __name: "ViewImg",
219
+ props: {
220
+ src: { default: "" },
221
+ fit: { default: "" },
222
+ lazy: { type: Boolean, default: false },
223
+ scrollContainer: { default: null },
224
+ loading: { type: Boolean, default: false },
225
+ preview: { type: Boolean, default: false },
226
+ previewSrcList: { default: () => [] },
227
+ initialIndex: { default: void 0 },
228
+ defImgPreviewIndex: { default: void 0 },
229
+ infinite: { type: Boolean, default: DEFAULT_PREVIEW_INFINITE },
230
+ zIndex: { default: void 0 },
231
+ hideOnClickModal: { type: Boolean, default: DEFAULT_PREVIEW_HIDE_ON_CLICK_MODAL },
232
+ closeOnPressEscape: { type: Boolean, default: DEFAULT_PREVIEW_CLOSE_ON_PRESS_ESCAPE },
233
+ previewTeleported: { type: Boolean, default: void 0 },
234
+ teleported: { type: Boolean, default: void 0 },
235
+ zoomRate: { default: DEFAULT_PREVIEW_ZOOM_RATE },
236
+ scale: { default: DEFAULT_PREVIEW_SCALE },
237
+ minScale: { default: DEFAULT_PREVIEW_MIN_SCALE },
238
+ maxScale: { default: DEFAULT_PREVIEW_MAX_SCALE },
239
+ showProgress: { type: Boolean, default: DEFAULT_PREVIEW_SHOW_PROGRESS },
240
+ toolbarBgColor: { default: DEFAULT_TOOLBAR_BG_COLOR },
241
+ backgroundColor: { default: "" },
242
+ toolbarIconColor: { default: DEFAULT_TOOLBAR_ICON_COLOR },
243
+ simpleExtraTools: { default: () => [] },
244
+ renderExtraTools: { default: null },
245
+ originalToolbar: { default: () => [...DEFAULT_ORIGINAL_TOOLBAR] },
246
+ fallbackColor: { default: "" },
247
+ errorText: { default: "" },
248
+ ossProcess: { type: Boolean, default: true },
249
+ ossLinks: { default: void 0 },
250
+ imgSize: { default: () => ({}) },
251
+ previewStripQuery: { type: Boolean, default: true },
252
+ previewSideNav: { type: [Boolean, String], default: DEFAULT_PREVIEW_SIDE_NAV }
253
+ },
254
+ emits: ["load", "error", "retry", "show", "close", "switch"],
255
+ setup(__props, { expose: __expose, emit: __emit }) {
256
+ const props = __props;
257
+ const emit = __emit;
258
+ const attrs = useAttrs();
259
+ const rootRef = ref(null);
260
+ const displaySrc = ref("");
261
+ const retried = ref(false);
262
+ const internalLoading = ref(false);
263
+ const loadError = ref(false);
264
+ const lazyActivated = ref(!props.lazy);
265
+ const viewImgDefaults2 = useViewImgDefaults();
266
+ let lazyObserver = null;
267
+ const imgAttrs = computed(() => {
268
+ const _a = attrs, { class: _, style: __ } = _a, rest = __objRest(_a, ["class", "style"]);
269
+ return rest;
270
+ });
271
+ const imgStyle = computed(() => {
272
+ if (!props.fit) return {};
273
+ return { objectFit: props.fit };
274
+ });
275
+ const showPlaceholder = computed(
276
+ () => !!props.src.trim() && (props.loading || internalLoading.value) && !loadError.value
277
+ );
278
+ const defaultSlotPayload = computed(() => ({
279
+ src: props.src,
280
+ displaySrc: displaySrc.value,
281
+ loading: props.loading || internalLoading.value,
282
+ loadError: loadError.value,
283
+ errorText: props.errorText,
284
+ fallbackColor: props.fallbackColor
285
+ }));
286
+ const globalPlaceholderComponent = computed(() => {
287
+ const renderPlaceholder = viewImgDefaults2.placeholder;
288
+ if (!renderPlaceholder) return null;
289
+ return {
290
+ render: () => renderPlaceholder(defaultSlotPayload.value)
291
+ };
292
+ });
293
+ const globalErrorComponent = computed(() => {
294
+ const renderError = viewImgDefaults2.error;
295
+ if (!renderError) return null;
296
+ return {
297
+ render: () => renderError(defaultSlotPayload.value)
298
+ };
299
+ });
300
+ const previewEnabled = computed(() => (props.preview || props.previewSrcList.length > 0) && !!displaySrc.value && !loadError.value);
301
+ const previewUrlList = computed(() => {
302
+ const rawList = props.previewSrcList.length ? props.previewSrcList : props.src.trim() ? [props.src] : [];
303
+ return rawList.map((url) => applyPreviewUrlFallback(url));
304
+ });
305
+ const previewInitialIndex = computed(() => resolvePreviewInitialIndex(previewUrlList.value));
306
+ function resolvePreviewInitialIndex(previewList) {
307
+ if (props.defImgPreviewIndex != null) return props.defImgPreviewIndex;
308
+ if (props.initialIndex != null) return props.initialIndex;
309
+ const index = previewList.indexOf(applyPreviewUrlFallback(props.src));
310
+ return index >= 0 ? index : 0;
311
+ }
312
+ const resolvedToolbarBgColor = computed(() => props.toolbarBgColor || props.backgroundColor || DEFAULT_TOOLBAR_BG_COLOR);
313
+ const resolvedPreviewTeleported = computed(
314
+ () => {
315
+ var _a, _b;
316
+ return (_b = (_a = props.previewTeleported) != null ? _a : props.teleported) != null ? _b : DEFAULT_PREVIEW_TELEPORTED;
317
+ }
318
+ );
319
+ function stripQueryParams(url) {
320
+ const index = url.indexOf("?");
321
+ return index === -1 ? url : url.slice(0, index);
322
+ }
323
+ function resolveImgUrl(url, imgSize) {
324
+ if (!props.ossProcess) return url;
325
+ return montageImgUrl(url, imgSize, props.ossLinks ? { ossLinks: props.ossLinks } : void 0);
326
+ }
327
+ function applyPreviewUrlFallback(url) {
328
+ if (!props.previewStripQuery || !url) return url;
329
+ return stripQueryParams(url);
330
+ }
331
+ function resetState(src) {
332
+ retried.value = false;
333
+ internalLoading.value = false;
334
+ if (!src.trim()) {
335
+ displaySrc.value = "";
336
+ loadError.value = true;
337
+ return;
338
+ }
339
+ loadError.value = false;
340
+ internalLoading.value = true;
341
+ displaySrc.value = resolveImgUrl(src, props.imgSize);
342
+ }
343
+ function setLazyPending(src) {
344
+ retried.value = false;
345
+ displaySrc.value = "";
346
+ if (!src.trim()) {
347
+ loadError.value = true;
348
+ internalLoading.value = false;
349
+ return;
350
+ }
351
+ loadError.value = false;
352
+ internalLoading.value = true;
353
+ }
354
+ function resolveScrollRoot() {
355
+ const container = props.scrollContainer;
356
+ if (!container) return null;
357
+ if (typeof container === "string") {
358
+ return document.querySelector(container);
359
+ }
360
+ return container;
361
+ }
362
+ function stopLazyObserver() {
363
+ if (lazyObserver) {
364
+ lazyObserver.disconnect();
365
+ lazyObserver = null;
366
+ }
367
+ }
368
+ function activateLazyLoad() {
369
+ if (lazyActivated.value) return;
370
+ lazyActivated.value = true;
371
+ stopLazyObserver();
372
+ resetState(props.src);
373
+ }
374
+ function startLazyObserver() {
375
+ stopLazyObserver();
376
+ if (!props.lazy || lazyActivated.value) return;
377
+ if (typeof window === "undefined" || !("IntersectionObserver" in window)) {
378
+ activateLazyLoad();
379
+ return;
380
+ }
381
+ const el = rootRef.value;
382
+ if (!el) return;
383
+ lazyObserver = new IntersectionObserver(
384
+ (entries) => {
385
+ if (entries.some((entry) => entry.isIntersecting)) {
386
+ activateLazyLoad();
387
+ }
388
+ },
389
+ {
390
+ root: resolveScrollRoot(),
391
+ rootMargin: LAZY_ROOT_MARGIN,
392
+ threshold: 0
393
+ }
394
+ );
395
+ lazyObserver.observe(el);
396
+ }
397
+ function applySrc(src) {
398
+ if (props.lazy && !lazyActivated.value) {
399
+ setLazyPending(src);
400
+ return;
401
+ }
402
+ resetState(src);
403
+ }
404
+ function handleLoad(event) {
405
+ internalLoading.value = false;
406
+ loadError.value = false;
407
+ emit("load", event);
408
+ }
409
+ function markLoadFailed(event) {
410
+ internalLoading.value = false;
411
+ loadError.value = true;
412
+ emit("error", event);
413
+ }
414
+ function handleError(event) {
415
+ if (retried.value) {
416
+ markLoadFailed(event);
417
+ return;
418
+ }
419
+ const stripped = stripQueryParams(displaySrc.value);
420
+ if (stripped === displaySrc.value) {
421
+ markLoadFailed(event);
422
+ return;
423
+ }
424
+ const urlBefore = displaySrc.value;
425
+ retried.value = true;
426
+ internalLoading.value = true;
427
+ displaySrc.value = stripped;
428
+ emit("retry", { from: urlBefore, to: stripped });
429
+ }
430
+ function openPreview(previewList) {
431
+ const previewImgList = previewList ? previewList.map((url) => applyPreviewUrlFallback(url)) : previewUrlList.value;
432
+ if (!previewImgList.length) return;
433
+ ImgViewerStore().showImgViewer({
434
+ previewImgList,
435
+ defImgPreviewIndex: previewList ? resolvePreviewInitialIndex(previewImgList) : previewInitialIndex.value,
436
+ toolbarBgColor: resolvedToolbarBgColor.value,
437
+ toolbarIconColor: props.toolbarIconColor,
438
+ infinite: props.infinite,
439
+ zIndex: props.zIndex,
440
+ hideOnClickModal: props.hideOnClickModal,
441
+ closeOnPressEscape: props.closeOnPressEscape,
442
+ teleported: resolvedPreviewTeleported.value,
443
+ zoomRate: props.zoomRate,
444
+ scale: props.scale,
445
+ minScale: props.minScale,
446
+ maxScale: props.maxScale,
447
+ showProgress: props.showProgress,
448
+ simpleExtraTools: props.simpleExtraTools,
449
+ renderExtraTools: props.renderExtraTools,
450
+ originalToolbar: props.originalToolbar,
451
+ previewSideNav: props.previewSideNav,
452
+ onShow: (payload) => emit("show", payload),
453
+ onClose: () => emit("close"),
454
+ onSwitch: (index) => emit("switch", index)
455
+ });
456
+ }
457
+ function handlePreviewClick() {
458
+ if (!previewEnabled.value) return;
459
+ openPreview();
460
+ }
461
+ watch(
462
+ [() => props.src, () => props.ossProcess, () => props.ossLinks, () => props.imgSize, networkKey, imgUrlConfigKey],
463
+ ([src]) => {
464
+ applySrc(src);
465
+ },
466
+ { immediate: true, deep: true }
467
+ );
468
+ watch(
469
+ () => props.lazy,
470
+ (lazy) => {
471
+ if (!lazy) {
472
+ if (!lazyActivated.value) {
473
+ activateLazyLoad();
474
+ }
475
+ return;
476
+ }
477
+ if (!lazyActivated.value) {
478
+ nextTick(() => startLazyObserver());
479
+ }
480
+ }
481
+ );
482
+ watch(
483
+ () => props.scrollContainer,
484
+ () => {
485
+ if (props.lazy && !lazyActivated.value) {
486
+ nextTick(() => startLazyObserver());
487
+ }
488
+ }
489
+ );
490
+ onMounted(() => {
491
+ if (props.lazy && !lazyActivated.value) {
492
+ startLazyObserver();
493
+ }
494
+ });
495
+ onUnmounted(() => {
496
+ stopLazyObserver();
497
+ });
498
+ __expose({
499
+ displaySrc,
500
+ retried,
501
+ openPreview
502
+ });
503
+ return (_ctx, _cache) => {
504
+ return openBlock(), createElementBlock("span", {
505
+ ref_key: "rootRef",
506
+ ref: rootRef,
507
+ class: normalizeClass(["fg-view-img", unref(attrs).class]),
508
+ style: normalizeStyle(unref(attrs).style)
509
+ }, [
510
+ withDirectives(createElementVNode("img", mergeProps({
511
+ class: ["fg-view-img__inner", {
512
+ "fg-view-img__inner--preview": previewEnabled.value,
513
+ "fg-view-img__inner--loading": showPlaceholder.value
514
+ }]
515
+ }, imgAttrs.value, {
516
+ src: displaySrc.value || void 0,
517
+ loading: "eager",
518
+ style: imgStyle.value,
519
+ onLoad: handleLoad,
520
+ onError: handleError,
521
+ onClick: handlePreviewClick
522
+ }), null, 16, _hoisted_1), [
523
+ [vShow, !loadError.value && !!displaySrc.value]
524
+ ]),
525
+ showPlaceholder.value ? (openBlock(), createElementBlock("span", _hoisted_2, [
526
+ renderSlot(_ctx.$slots, "placeholder", normalizeProps(guardReactiveProps(defaultSlotPayload.value)), () => [
527
+ globalPlaceholderComponent.value ? (openBlock(), createBlock(resolveDynamicComponent(globalPlaceholderComponent.value), { key: 0 })) : (openBlock(), createBlock(ViewImgErrorFallback, {
528
+ key: 1,
529
+ loading: "",
530
+ src: __props.src,
531
+ "fallback-color": __props.fallbackColor
532
+ }, null, 8, ["src", "fallback-color"]))
533
+ ], true)
534
+ ])) : createCommentVNode("", true),
535
+ loadError.value ? (openBlock(), createElementBlock("span", _hoisted_3, [
536
+ renderSlot(_ctx.$slots, "error", normalizeProps(guardReactiveProps(defaultSlotPayload.value)), () => [
537
+ globalErrorComponent.value ? (openBlock(), createBlock(resolveDynamicComponent(globalErrorComponent.value), { key: 0 })) : (openBlock(), createBlock(ViewImgErrorFallback, {
538
+ key: 1,
539
+ src: __props.src,
540
+ "error-text": __props.errorText,
541
+ "fallback-color": __props.fallbackColor
542
+ }, null, 8, ["src", "error-text", "fallback-color"]))
543
+ ], true)
544
+ ])) : createCommentVNode("", true)
545
+ ], 6);
546
+ };
547
+ }
548
+ }));
549
+ const FgViewImg = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-b5064f2e"]]);
550
+ export {
551
+ FgViewImg as F,
552
+ ViewImgErrorFallback as V,
553
+ configureViewImgDefaults as c,
554
+ resetViewImgDefaults as r,
555
+ useViewImgDefaults as u
556
+ };
package/dist/ViewImg.css CHANGED
@@ -1,4 +1,54 @@
1
- .fg-view-img[data-v-c6ff5d38] {
1
+ @charset "UTF-8";
2
+ /* 外层建立尺寸容器,内层用 cqmin 随格子缩放 */
3
+ .fg-view-img__error-default[data-v-4588a25e] {
4
+ container-type: size;
5
+ width: 100%;
6
+ height: 100%;
7
+ overflow: hidden;
8
+ }
9
+ .fg-view-img__error-default-body[data-v-4588a25e] {
10
+ width: 100%;
11
+ height: 100%;
12
+ display: flex;
13
+ flex-direction: column;
14
+ align-items: center;
15
+ justify-content: center;
16
+ gap: clamp(2px, 4cqmin, 6px);
17
+ box-sizing: border-box;
18
+ padding: clamp(2px, 6cqmin, 8px);
19
+ }
20
+ .fg-view-img__error-icon[data-v-4588a25e] {
21
+ display: block;
22
+ flex: none;
23
+ width: clamp(16px, 36cqmin, 56px);
24
+ height: auto;
25
+ max-width: 56px;
26
+ max-height: 48px;
27
+ aspect-ratio: 1;
28
+ }
29
+ .fg-view-img__error-label[data-v-4588a25e] {
30
+ flex: none;
31
+ color: #a8abb2;
32
+ font-size: clamp(8px, 10cqmin, 12px);
33
+ line-height: 1.2;
34
+ text-align: center;
35
+ white-space: nowrap;
36
+ max-width: 100%;
37
+ overflow: hidden;
38
+ text-overflow: ellipsis;
39
+ }
40
+
41
+ /* 极小格子隐藏文案,只留图标 */
42
+ @container (max-width: 56px) or (max-height: 48px) {
43
+ .fg-view-img__error-label[data-v-4588a25e] {
44
+ display: none;
45
+ }
46
+ .fg-view-img__error-default-body[data-v-4588a25e] {
47
+ gap: 0;
48
+ padding: 2px;
49
+ }
50
+ }
51
+ .fg-view-img[data-v-b5064f2e] {
2
52
  display: block;
3
53
  position: relative;
4
54
  overflow: hidden;
@@ -7,50 +57,25 @@
7
57
  vertical-align: top;
8
58
  line-height: 0;
9
59
  }
10
- .fg-view-img__inner[data-v-c6ff5d38] {
60
+ .fg-view-img__inner[data-v-b5064f2e] {
11
61
  display: block;
12
62
  width: 100%;
13
63
  height: 100%;
14
64
  }
15
- .fg-view-img__inner--preview[data-v-c6ff5d38] {
65
+
66
+ /* 加载中仍占位渲染,避免 display:none + 原生 lazy 导致永不请求 */
67
+ .fg-view-img__inner--loading[data-v-b5064f2e] {
68
+ opacity: 0;
69
+ }
70
+ .fg-view-img__inner--preview[data-v-b5064f2e] {
16
71
  cursor: zoom-in;
17
72
  }
18
- .fg-view-img__placeholder[data-v-c6ff5d38],
19
- .fg-view-img__error[data-v-c6ff5d38] {
73
+ .fg-view-img__placeholder[data-v-b5064f2e],
74
+ .fg-view-img__error[data-v-b5064f2e] {
20
75
  position: absolute;
21
76
  inset: 0;
22
77
  display: flex;
23
78
  align-items: center;
24
79
  justify-content: center;
25
80
  background: #f5f7fa;
26
- }
27
- .fg-view-img__error[data-v-c6ff5d38] .error-image {
28
- width: 100%;
29
- height: 100%;
30
- }
31
- .fg-view-img__error-default[data-v-c6ff5d38] {
32
- position: relative;
33
- width: 100%;
34
- height: 100%;
35
- display: flex;
36
- flex-direction: column;
37
- align-items: center;
38
- justify-content: center;
39
- gap: 8px;
40
- padding: 8px;
41
- box-sizing: border-box;
42
- }
43
- .fg-view-img__error-icon[data-v-c6ff5d38] {
44
- flex: none;
45
- width: 56%;
46
- height: 56%;
47
- max-width: 80px;
48
- max-height: 80px;
49
- }
50
- .fg-view-img__error-text[data-v-c6ff5d38] {
51
- font-size: 13px;
52
- line-height: 1.4;
53
- color: #909399;
54
- text-align: center;
55
- word-break: break-all;
56
81
  }