zkit-ui 2.0.5 → 2.0.7

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 (80) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryLayoutSupport.java → NativeImagePreviewLayoutSupport.java} +12 -12
  3. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryMediaItem.java → NativeImagePreviewMediaItem.java} +2 -2
  4. package/android/src/main/java/cn/fontree/zkit/ui/preview/NativeImagePreviewModule.kt +43 -0
  5. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryPagerAdapter.java → NativeImagePreviewPagerAdapter.java} +18 -18
  6. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySharedElementGeometry.java → NativeImagePreviewSharedElementGeometry.java} +2 -2
  7. package/android/src/main/java/cn/fontree/zkit/ui/preview/NativeImagePreviewSharedElementNames.java +39 -0
  8. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySharedElementState.java → NativeImagePreviewSharedElementState.java} +4 -4
  9. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GallerySourceViewRegistry.java → NativeImagePreviewSourceViewRegistry.java} +2 -2
  10. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryTransitionSnapshotView.java → NativeImagePreviewTransitionSnapshotView.java} +3 -3
  11. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryVideoPlayerView.java → NativeImagePreviewVideoPlayerView.java} +7 -7
  12. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GaleriaView.kt → NativeImagePreviewView.kt} +18 -18
  13. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerOverlayView.java → NativeImagePreviewViewerOverlayView.java} +49 -49
  14. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerPageView.java → NativeImagePreviewViewerPageView.java} +27 -27
  15. package/android/src/main/java/cn/fontree/zkit/ui/preview/{GalleryViewerTransitionController.java → NativeImagePreviewViewerTransitionController.java} +22 -22
  16. package/dist/ui/Button/index.d.ts +1 -1
  17. package/dist/ui/Button/index.d.ts.map +1 -1
  18. package/dist/ui/Button/index.js +18 -3
  19. package/dist/ui/NativeImagePreview/NativeImagePreview.js +6 -6
  20. package/dist/ui/NativeImagePreview/NativeImagePreview.web.d.ts +1 -0
  21. package/dist/ui/NativeImagePreview/NativeImagePreview.web.d.ts.map +1 -1
  22. package/dist/ui/NativeImagePreview/NativeImagePreview.web.js +105 -11
  23. package/dist/ui/NativeImagePreview/context.d.ts +1 -1
  24. package/dist/ui/NativeImagePreview/context.d.ts.map +1 -1
  25. package/dist/ui/NativeImagePreview/types.d.ts +3 -1
  26. package/dist/ui/NativeImagePreview/types.d.ts.map +1 -1
  27. package/dist/ui/NativeImagePreview/utils.d.ts.map +1 -1
  28. package/dist/ui/NativeImagePreview/utils.js +1 -0
  29. package/dist/ui/NativeImagePreview/web/geometry.d.ts +20 -0
  30. package/dist/ui/NativeImagePreview/web/geometry.d.ts.map +1 -0
  31. package/dist/ui/NativeImagePreview/web/geometry.js +121 -0
  32. package/dist/ui/NativeImagePreview/web/media.d.ts +6 -0
  33. package/dist/ui/NativeImagePreview/web/media.d.ts.map +1 -0
  34. package/dist/ui/NativeImagePreview/web/media.js +90 -0
  35. package/dist/ui/NativeImagePreview/web/styles.css +137 -0
  36. package/dist/ui/NativeImagePreview/web/transition.d.ts +15 -0
  37. package/dist/ui/NativeImagePreview/web/transition.d.ts.map +1 -0
  38. package/dist/ui/NativeImagePreview/web/transition.js +77 -0
  39. package/dist/ui/NativeImagePreview/web/types.d.ts +74 -0
  40. package/dist/ui/NativeImagePreview/web/types.d.ts.map +1 -0
  41. package/dist/ui/NativeImagePreview/web/types.js +3 -0
  42. package/dist/ui/NativeImagePreview/web/viewer.d.ts +104 -0
  43. package/dist/ui/NativeImagePreview/web/viewer.d.ts.map +1 -0
  44. package/dist/ui/NativeImagePreview/web/viewer.js +894 -0
  45. package/expo-module.config.json +2 -2
  46. package/ios/{GalleryViewer/GaleriaImageLoader.swift → NativeImagePreview/NativeImagePreviewImageLoader.swift} +7 -7
  47. package/ios/NativeImagePreview/NativeImagePreviewImageViewInteraction.swift +245 -0
  48. package/ios/{GalleryViewer/GaleriaLayoutSupport.swift → NativeImagePreview/NativeImagePreviewLayoutSupport.swift} +19 -19
  49. package/ios/NativeImagePreview/NativeImagePreviewMedia.swift +28 -0
  50. package/ios/NativeImagePreview/NativeImagePreviewSourceViewRegistry.swift +80 -0
  51. package/ios/{GalleryViewer/GaleriaVideoPlayerView.swift → NativeImagePreview/NativeImagePreviewVideoPlayerView.swift} +1 -1
  52. package/ios/{GalleryViewer/GaleriaViewerConfiguration.swift → NativeImagePreview/NativeImagePreviewViewerConfiguration.swift} +7 -7
  53. package/ios/{GalleryViewer/GaleriaViewerController.swift → NativeImagePreview/NativeImagePreviewViewerController.swift} +36 -36
  54. package/ios/{GalleryViewer/GaleriaViewerPageView.swift → NativeImagePreview/NativeImagePreviewViewerPageView.swift} +33 -33
  55. package/ios/{GalleryViewer/GaleriaViewerTransitionCoordinator.swift → NativeImagePreview/NativeImagePreviewViewerTransitionCoordinator.swift} +16 -16
  56. package/ios/{GaleriaModule.swift → NativeImagePreviewModule.swift} +4 -4
  57. package/ios/{GaleriaView.swift → NativeImagePreviewView.swift} +26 -27
  58. package/package.json +18 -12
  59. package/src/services/ImagePreviewService/README.md +1 -1
  60. package/src/types.d.ts +1 -0
  61. package/src/ui/Button/README.md +1 -1
  62. package/src/ui/Button/index.tsx +27 -7
  63. package/src/ui/NativeImagePreview/NativeImagePreview.tsx +7 -7
  64. package/src/ui/NativeImagePreview/NativeImagePreview.web.tsx +175 -11
  65. package/src/ui/NativeImagePreview/README.md +3 -3
  66. package/src/ui/NativeImagePreview/context.tsx +1 -1
  67. package/src/ui/NativeImagePreview/types.ts +3 -1
  68. package/src/ui/NativeImagePreview/utils.ts +1 -0
  69. package/src/ui/NativeImagePreview/web/geometry.ts +134 -0
  70. package/src/ui/NativeImagePreview/web/media.ts +91 -0
  71. package/src/ui/NativeImagePreview/web/styles.css +137 -0
  72. package/src/ui/NativeImagePreview/web/transition.ts +111 -0
  73. package/src/ui/NativeImagePreview/web/types.ts +88 -0
  74. package/src/ui/NativeImagePreview/web/viewer.ts +1024 -0
  75. package/android/src/main/java/cn/fontree/zkit/ui/preview/GaleriaModule.kt +0 -43
  76. package/android/src/main/java/cn/fontree/zkit/ui/preview/GallerySharedElementNames.java +0 -39
  77. package/ios/GalleryViewer/GaleriaImageViewInteraction.swift +0 -245
  78. package/ios/GalleryViewer/GaleriaMedia.swift +0 -28
  79. package/ios/GalleryViewer/GaleriaSourceViewRegistry.swift +0 -80
  80. /package/android/src/main/res/layout/{galeria_player_view.xml → native_image_preview_player_view.xml} +0 -0
@@ -539,6 +539,15 @@ function resolveWebCursorStyle(disabled) {
539
539
  return undefined;
540
540
  return { cursor: disabled ? 'not-allowed' : 'pointer' };
541
541
  }
542
+ function resolveRootAccessibilityRole() {
543
+ return react_native_1.Platform.OS === 'web' ? undefined : 'button';
544
+ }
545
+ function resolveRootPressableProps(props) {
546
+ if (react_native_1.Platform.OS !== 'web')
547
+ return props;
548
+ const { accessibilityRole: _accessibilityRole, role: _role, ...rest } = props;
549
+ return rest;
550
+ }
542
551
  function requiresAnimatedPressEffect(effect) {
543
552
  return (effect === 'scale' ||
544
553
  effect === 'scale-opacity' ||
@@ -707,6 +716,8 @@ function ButtonStaticImpl({ variant = 'solid', tone = 'primary', size = 'md', sh
707
716
  return;
708
717
  onPress === null || onPress === void 0 ? void 0 : onPress(event);
709
718
  }, [interactionDisabled, onPress]);
719
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
720
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
710
721
  const pressOpacityEnabled = !interactionDisabled && (pressEffect === 'auto' || pressEffect === 'opacity');
711
722
  const rootStyle = React.useCallback(({ pressed }) => [
712
723
  styles.root,
@@ -726,7 +737,7 @@ function ButtonStaticImpl({ variant = 'solid', tone = 'primary', size = 'md', sh
726
737
  visualDisabled,
727
738
  webCursorStyle,
728
739
  ]);
729
- return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
740
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
730
741
  ...accessibilityState,
731
742
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
732
743
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
@@ -816,7 +827,9 @@ function ButtonPressAnimatedImpl({ variant = 'solid', tone = 'primary', size = '
816
827
  }
817
828
  onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
818
829
  }, [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]);
819
- return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
830
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
831
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
832
+ return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
820
833
  ...accessibilityState,
821
834
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
822
835
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
@@ -997,7 +1010,9 @@ function ButtonAnimatedImpl({ variant = 'solid', tone = 'primary', size = 'md',
997
1010
  }
998
1011
  onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
999
1012
  }, [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]);
1000
- return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
1013
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
1014
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
1015
+ return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
1001
1016
  ...accessibilityState,
1002
1017
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
1003
1018
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
@@ -43,22 +43,22 @@ const context_1 = require("./context");
43
43
  const utils_1 = require("./utils");
44
44
  const NativePreviewView = (0, expo_1.requireNativeView)('ZKitNativeImagePreview');
45
45
  const ANDROID_EDGE_TO_EDGE = react_native_1.Platform.OS === 'android' ? (0, react_native_is_edge_to_edge_1.isEdgeToEdge)() : false;
46
- function createGalleryId() {
46
+ function createPreviewGroupId() {
47
47
  return `zkit-native-image-preview-${Date.now().toString(36)}-${Math.random()
48
48
  .toString(36)
49
49
  .slice(2, 10)}`;
50
50
  }
51
51
  const NativeImagePreviewRoot = React.memo(function NativeImagePreview({ children, colorScheme = 'dark', disabled = false, edgeToEdge = false, items, nativeProps, onChange, }) {
52
52
  const systemColorScheme = (0, react_native_1.useColorScheme)();
53
- const galleryIdRef = React.useRef(null);
54
- if (galleryIdRef.current == null) {
55
- galleryIdRef.current = createGalleryId();
53
+ const previewGroupIdRef = React.useRef(null);
54
+ if (previewGroupIdRef.current == null) {
55
+ previewGroupIdRef.current = createPreviewGroupId();
56
56
  }
57
57
  const resolvedItems = React.useMemo(() => (0, utils_1.normalizeNativeImagePreviewItems)(items), [items]);
58
58
  const nativeItems = React.useMemo(() => (0, utils_1.toNativePreviewItems)(resolvedItems), [resolvedItems]);
59
59
  const resolvedColorScheme = (0, utils_1.resolveNativeImagePreviewColorScheme)(colorScheme, systemColorScheme);
60
60
  const contextValue = React.useMemo(() => ({
61
- galleryId: galleryIdRef.current,
61
+ previewGroupId: previewGroupIdRef.current,
62
62
  items: resolvedItems,
63
63
  nativeItems,
64
64
  colorScheme: resolvedColorScheme,
@@ -92,7 +92,7 @@ const NativeImagePreviewItem = React.memo(function NativeImagePreviewItem({ chil
92
92
  if (__DEV__ && react_native_1.Platform.OS === 'android') {
93
93
  (0, react_native_is_edge_to_edge_1.controlEdgeToEdgeValues)({ edgeToEdge: resolvedEdgeToEdge });
94
94
  }
95
- return ((0, jsx_runtime_1.jsx)(NativePreviewView, { closeIconName: (_a = context.nativeProps) === null || _a === void 0 ? void 0 : _a.iosCloseIconName, edgeToEdge: resolvedEdgeToEdge, galleryId: context.galleryId, index: (0, utils_1.clampPreviewIndex)(index, context.nativeItems.length), items: context.nativeItems, onIndexChange: handleIndexChange, style: style, theme: context.colorScheme, children: children }));
95
+ return ((0, jsx_runtime_1.jsx)(NativePreviewView, { closeIconName: (_a = context.nativeProps) === null || _a === void 0 ? void 0 : _a.iosCloseIconName, edgeToEdge: resolvedEdgeToEdge, previewGroupId: context.previewGroupId, index: (0, utils_1.clampPreviewIndex)(index, context.nativeItems.length), items: context.nativeItems, onIndexChange: handleIndexChange, style: style, theme: context.colorScheme, children: children }));
96
96
  });
97
97
  exports.NativeImagePreview = Object.assign(NativeImagePreviewRoot, {
98
98
  Item: NativeImagePreviewItem,
@@ -1,3 +1,4 @@
1
+ import './web/styles.css';
1
2
  import type { NativeImagePreviewComponent } from './types';
2
3
  export declare const NativeImagePreview: NativeImagePreviewComponent;
3
4
  //# sourceMappingURL=NativeImagePreview.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeImagePreview.web.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/NativeImagePreview.web.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAG5B,MAAM,SAAS,CAAC;AA4BjB,eAAO,MAAM,kBAAkB,EAEzB,2BAA2B,CAAC"}
1
+ {"version":3,"file":"NativeImagePreview.web.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/NativeImagePreview.web.tsx"],"names":[],"mappings":"AAEA,OAAO,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAEV,2BAA2B,EAI5B,MAAM,SAAS,CAAC;AAyLjB,eAAO,MAAM,kBAAkB,EAEzB,2BAA2B,CAAC"}
@@ -35,21 +35,115 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.NativeImagePreview = void 0;
37
37
  const jsx_runtime_1 = require("react/jsx-runtime");
38
+ /// <reference lib="dom" />
39
+ require("./web/styles.css");
38
40
  const React = __importStar(require("react"));
39
41
  const react_native_1 = require("react-native");
40
- let didWarnUnsupportedWeb = false;
41
- function warnUnsupportedWeb() {
42
- if (!__DEV__ || didWarnUnsupportedWeb)
43
- return;
44
- didWarnUnsupportedWeb = true;
45
- console.warn('[zkit-ui][NativeImagePreview] Native shared-transition preview is only available in iOS and Android native builds.');
42
+ const utils_1 = require("./utils");
43
+ const viewer_1 = require("./web/viewer");
44
+ const NativeImagePreviewWebContext = React.createContext(null);
45
+ const WebView = react_native_1.View;
46
+ function toWebPreviewItems(items) {
47
+ return items.map(({ alt, height, id, poster, type, url, width }) => ({
48
+ alt: alt !== null && alt !== void 0 ? alt : id,
49
+ height,
50
+ id,
51
+ poster,
52
+ type,
53
+ url,
54
+ width,
55
+ }));
46
56
  }
47
- const NativeImagePreviewRoot = React.memo(function NativeImagePreview({ children, }) {
48
- React.useEffect(warnUnsupportedWeb, []);
49
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
57
+ function findPreviewSourceElement(element) {
58
+ var _a;
59
+ if (!element)
60
+ return null;
61
+ if (element instanceof HTMLImageElement || element instanceof HTMLVideoElement) {
62
+ return element;
63
+ }
64
+ return (_a = element.querySelector('img, video')) !== null && _a !== void 0 ? _a : element;
65
+ }
66
+ function toChangeMeta(meta, items) {
67
+ var _a;
68
+ return {
69
+ reason: meta.reason,
70
+ item: (_a = items[meta.index]) !== null && _a !== void 0 ? _a : null,
71
+ };
72
+ }
73
+ const NativeImagePreviewRoot = React.memo(function NativeImagePreview({ children, colorScheme = 'dark', disabled = false, items, onChange, }) {
74
+ const systemColorScheme = (0, react_native_1.useColorScheme)();
75
+ const controllerRef = React.useRef(null);
76
+ const sourceElementsRef = React.useRef([]);
77
+ const resolvedItems = React.useMemo(() => (0, utils_1.normalizeNativeImagePreviewItems)(items), [items]);
78
+ const webItems = React.useMemo(() => toWebPreviewItems(resolvedItems), [resolvedItems]);
79
+ const resolvedColorScheme = (0, utils_1.resolveNativeImagePreviewColorScheme)(colorScheme, systemColorScheme);
80
+ React.useEffect(() => {
81
+ const controller = (0, viewer_1.createNativeImagePreviewWeb)();
82
+ controllerRef.current = controller;
83
+ return () => {
84
+ controller.destroy();
85
+ controllerRef.current = null;
86
+ };
87
+ }, []);
88
+ const open = React.useCallback((index, onItemChange) => {
89
+ var _a, _b;
90
+ const controller = controllerRef.current;
91
+ if (disabled || !controller || webItems.length === 0)
92
+ return;
93
+ const value = (0, utils_1.clampPreviewIndex)(index, webItems.length);
94
+ const getSourceElement = (nextIndex) => { var _a; return findPreviewSourceElement((_a = sourceElementsRef.current[nextIndex]) !== null && _a !== void 0 ? _a : null); };
95
+ void controller.open({
96
+ getSourceElement,
97
+ index: value,
98
+ items: webItems,
99
+ objectFit: 'cover',
100
+ sourceElement: getSourceElement(value),
101
+ sourceImageSize: resolvedItems[value]
102
+ ? {
103
+ width: (_a = resolvedItems[value].width) !== null && _a !== void 0 ? _a : 0,
104
+ height: (_b = resolvedItems[value].height) !== null && _b !== void 0 ? _b : 0,
105
+ }
106
+ : null,
107
+ sourceObjectFit: 'cover',
108
+ sourceVisibility: 'hidden',
109
+ theme: resolvedColorScheme,
110
+ onChange: (nextValue, meta) => {
111
+ const changeMeta = toChangeMeta(meta, resolvedItems);
112
+ onChange === null || onChange === void 0 ? void 0 : onChange(nextValue, changeMeta);
113
+ onItemChange === null || onItemChange === void 0 ? void 0 : onItemChange(nextValue, changeMeta);
114
+ },
115
+ });
116
+ }, [disabled, onChange, resolvedColorScheme, resolvedItems, webItems]);
117
+ const contextValue = React.useMemo(() => ({
118
+ disabled,
119
+ items: resolvedItems,
120
+ open,
121
+ sourceElementsRef,
122
+ }), [disabled, open, resolvedItems]);
123
+ return ((0, jsx_runtime_1.jsx)(NativeImagePreviewWebContext.Provider, { value: contextValue, children: children }));
50
124
  });
51
- const NativeImagePreviewItem = React.memo(function NativeImagePreviewItem({ children, style, }) {
52
- return (0, jsx_runtime_1.jsx)(react_native_1.View, { style: style, children: children });
125
+ const NativeImagePreviewItem = React.memo(function NativeImagePreviewItem({ children, disabled = false, index, onChange, style, }) {
126
+ const context = React.useContext(NativeImagePreviewWebContext);
127
+ const sourceRef = React.useCallback((node) => {
128
+ if (!context)
129
+ return;
130
+ context.sourceElementsRef.current[index] = node;
131
+ }, [context, index]);
132
+ const itemDisabled = !context || context.disabled || disabled || context.items.length === 0;
133
+ const open = React.useCallback(() => {
134
+ if (itemDisabled)
135
+ return;
136
+ context.open(index, onChange);
137
+ }, [context, index, itemDisabled, onChange]);
138
+ const handleKeyDown = React.useCallback((event) => {
139
+ if (itemDisabled)
140
+ return;
141
+ if (event.key !== 'Enter' && event.key !== ' ')
142
+ return;
143
+ event.preventDefault();
144
+ open();
145
+ }, [itemDisabled, open]);
146
+ return ((0, jsx_runtime_1.jsx)(WebView, { ref: sourceRef, "aria-label": itemDisabled ? undefined : 'Open image preview', onClick: itemDisabled ? undefined : open, onKeyDown: itemDisabled ? undefined : handleKeyDown, role: itemDisabled ? undefined : 'button', style: style, tabIndex: itemDisabled ? undefined : 0, children: children }));
53
147
  });
54
148
  exports.NativeImagePreview = Object.assign(NativeImagePreviewRoot, {
55
149
  Item: NativeImagePreviewItem,
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import type { NativeImagePreviewChangeMeta, NativeImagePreviewNativeItem, NativeImagePreviewNativeProps, NativeImagePreviewResolvedItem, NativeImagePreviewResolvedColorScheme } from './types';
3
3
  export type NativeImagePreviewContextValue = {
4
- galleryId: string;
4
+ previewGroupId: string;
5
5
  items: readonly NativeImagePreviewResolvedItem[];
6
6
  nativeItems: readonly NativeImagePreviewNativeItem[];
7
7
  colorScheme: NativeImagePreviewResolvedColorScheme;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,8BAA8B,EAC9B,qCAAqC,EACtC,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,8BAA8B,EAAE,CAAC;IACjD,WAAW,EAAE,SAAS,4BAA4B,EAAE,CAAC;IACrD,WAAW,EAAE,qCAAqC,CAAC;IACnD,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,6BAA6B,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,4BAA4B,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF,eAAO,MAAM,yBAAyB,sDAC4B,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,8BAA8B,EAC9B,qCAAqC,EACtC,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,8BAA8B,GAAG;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,SAAS,8BAA8B,EAAE,CAAC;IACjD,WAAW,EAAE,SAAS,4BAA4B,EAAE,CAAC;IACrD,WAAW,EAAE,qCAAqC,CAAC;IACnD,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,6BAA6B,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,4BAA4B,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF,eAAO,MAAM,yBAAyB,sDAC4B,CAAC"}
@@ -6,6 +6,7 @@ export type NativeImagePreviewMediaType = 'image' | 'video';
6
6
  export type NativeImagePreviewSource = ImageSourcePropType | string;
7
7
  export type NativeImagePreviewItemDescriptor = {
8
8
  id?: string;
9
+ alt?: string;
9
10
  type?: NativeImagePreviewMediaType;
10
11
  url?: string;
11
12
  source?: NativeImagePreviewSource;
@@ -21,6 +22,7 @@ export type NativeImagePreviewResolvedItem = {
21
22
  poster?: string;
22
23
  width?: number;
23
24
  height?: number;
25
+ alt?: string;
24
26
  raw: NativeImagePreviewItem;
25
27
  };
26
28
  export type NativeImagePreviewNativeItem = {
@@ -31,7 +33,7 @@ export type NativeImagePreviewNativeItem = {
31
33
  width?: number;
32
34
  height?: number;
33
35
  };
34
- export type NativeImagePreviewChangeReason = 'swipe';
36
+ export type NativeImagePreviewChangeReason = 'api' | 'swipe';
35
37
  export type NativeImagePreviewChangeEventPayload = {
36
38
  currentIndex: number;
37
39
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK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,CAAC,YAAY,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,4BAA4B,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC,mBAAmB,CACjE,CAAC,KAAK,EAAE,uBAAuB,KAAK,KAAK,CAAC,YAAY,CACvD,GAAG;IACF,IAAI,EAAE,KAAK,CAAC,mBAAmB,CAC7B,CAAC,KAAK,EAAE,2BAA2B,KAAK,KAAK,CAAC,YAAY,CAC3D,CAAC;CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,6BAA6B,EAC7B,sBAAsB,EAEtB,4BAA4B,EAC5B,8BAA8B,EAC9B,qCAAqC,EACrC,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAejB,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,wBAAwB,GAAG,SAAS,sBAQ7C;AAoCD,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,SAAS,sBAAsB,EAAE,oCAKzC;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,8BAA8B,EAAE,GAC/C,4BAA4B,EAAE,CAShC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAG9D;AAED,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,6BAA6B,GAAG,SAAS,EACtD,iBAAiB,EAAE,eAAe,GACjC,qCAAqC,CAIvC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/ui/NativeImagePreview/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,6BAA6B,EAC7B,sBAAsB,EAEtB,4BAA4B,EAC5B,8BAA8B,EAC9B,qCAAqC,EACrC,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAejB,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,wBAAwB,GAAG,SAAS,sBAQ7C;AAqCD,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,SAAS,sBAAsB,EAAE,oCAKzC;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,8BAA8B,EAAE,GAC/C,4BAA4B,EAAE,CAShC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAG9D;AAED,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,6BAA6B,GAAG,SAAS,EACtD,iBAAiB,EAAE,eAAe,GACjC,qCAAqC,CAIvC"}
@@ -40,6 +40,7 @@ function normalizePreviewItem(item, index) {
40
40
  poster,
41
41
  width: item.width,
42
42
  height: item.height,
43
+ alt: item.alt,
43
44
  raw: item,
44
45
  };
45
46
  }
@@ -0,0 +1,20 @@
1
+ import type { NativeImagePreviewWebImageSize, NativeImagePreviewWebObjectFit, NativeImagePreviewWebRect } from './types';
2
+ export type SharedElementGeometry = {
3
+ visibleFrame: NativeImagePreviewWebRect;
4
+ contentFrame: NativeImagePreviewWebRect;
5
+ };
6
+ export declare function rectFromDOMRect(rect: DOMRectReadOnly | NativeImagePreviewWebRect): NativeImagePreviewWebRect;
7
+ export declare function rectFromElement(element: Element): NativeImagePreviewWebRect;
8
+ export declare function viewportRect(): NativeImagePreviewWebRect;
9
+ export declare function normalizeRect(input: Pick<NativeImagePreviewWebRect, 'left' | 'top' | 'width' | 'height'>): NativeImagePreviewWebRect;
10
+ export declare function isUsableRect(rect: NativeImagePreviewWebRect | null | undefined): rect is NativeImagePreviewWebRect;
11
+ export declare function clamp(value: number, min: number, max: number): number;
12
+ export declare function fitRect(mediaSize: NativeImagePreviewWebImageSize, container: NativeImagePreviewWebRect, objectFit: NativeImagePreviewWebObjectFit): NativeImagePreviewWebRect;
13
+ export declare function sharedGeometryFor(container: NativeImagePreviewWebRect, mediaSize: NativeImagePreviewWebImageSize, objectFit: NativeImagePreviewWebObjectFit): SharedElementGeometry;
14
+ export declare function targetGeometryFor(mediaSize: NativeImagePreviewWebImageSize, container: NativeImagePreviewWebRect): SharedElementGeometry;
15
+ export declare function intersectRects(first: NativeImagePreviewWebRect, second: NativeImagePreviewWebRect): NativeImagePreviewWebRect | null;
16
+ export declare function lerp(start: number, end: number, progress: number): number;
17
+ export declare function lerpRect(start: NativeImagePreviewWebRect, end: NativeImagePreviewWebRect, progress: number): NativeImagePreviewWebRect;
18
+ export declare function easeOutCubic(t: number): number;
19
+ export declare function easeOutQuart(t: number): number;
20
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/ui/NativeImagePreview/web/geometry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEzH,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,yBAAyB,CAAC;IACxC,YAAY,EAAE,yBAAyB,CAAC;CACzC,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,yBAAyB,GAAG,yBAAyB,CAO5G;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,yBAAyB,CAE3E;AAED,wBAAgB,YAAY,IAAI,yBAAyB,CAOxD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,yBAAyB,CASpI;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,IAAI,yBAAyB,CAElH;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,OAAO,CACrB,SAAS,EAAE,8BAA8B,EACzC,SAAS,EAAE,yBAAyB,EACpC,SAAS,EAAE,8BAA8B,GACxC,yBAAyB,CAkB3B;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,yBAAyB,EACpC,SAAS,EAAE,8BAA8B,EACzC,SAAS,EAAE,8BAA8B,GACxC,qBAAqB,CAUvB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,8BAA8B,EAAE,SAAS,EAAE,yBAAyB,GAAG,qBAAqB,CAWxI;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,yBAAyB,EAAE,MAAM,EAAE,yBAAyB,GAAG,yBAAyB,GAAG,IAAI,CASpI;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,GAAG,yBAAyB,CAOtI;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /// <reference lib="dom" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.rectFromDOMRect = rectFromDOMRect;
5
+ exports.rectFromElement = rectFromElement;
6
+ exports.viewportRect = viewportRect;
7
+ exports.normalizeRect = normalizeRect;
8
+ exports.isUsableRect = isUsableRect;
9
+ exports.clamp = clamp;
10
+ exports.fitRect = fitRect;
11
+ exports.sharedGeometryFor = sharedGeometryFor;
12
+ exports.targetGeometryFor = targetGeometryFor;
13
+ exports.intersectRects = intersectRects;
14
+ exports.lerp = lerp;
15
+ exports.lerpRect = lerpRect;
16
+ exports.easeOutCubic = easeOutCubic;
17
+ exports.easeOutQuart = easeOutQuart;
18
+ function rectFromDOMRect(rect) {
19
+ return normalizeRect({
20
+ left: rect.left,
21
+ top: rect.top,
22
+ width: rect.width,
23
+ height: rect.height,
24
+ });
25
+ }
26
+ function rectFromElement(element) {
27
+ return rectFromDOMRect(element.getBoundingClientRect());
28
+ }
29
+ function viewportRect() {
30
+ return normalizeRect({
31
+ left: 0,
32
+ top: 0,
33
+ width: window.innerWidth,
34
+ height: window.innerHeight,
35
+ });
36
+ }
37
+ function normalizeRect(input) {
38
+ return {
39
+ left: input.left,
40
+ top: input.top,
41
+ width: input.width,
42
+ height: input.height,
43
+ right: input.left + input.width,
44
+ bottom: input.top + input.height,
45
+ };
46
+ }
47
+ function isUsableRect(rect) {
48
+ return !!rect && rect.width > 1 && rect.height > 1;
49
+ }
50
+ function clamp(value, min, max) {
51
+ return Math.max(min, Math.min(max, value));
52
+ }
53
+ function fitRect(mediaSize, container, objectFit) {
54
+ if (objectFit === 'fill') {
55
+ return normalizeRect(container);
56
+ }
57
+ const widthScale = container.width / Math.max(1, mediaSize.width);
58
+ const heightScale = container.height / Math.max(1, mediaSize.height);
59
+ const scale = objectFit === 'cover'
60
+ ? Math.max(widthScale, heightScale)
61
+ : Math.min(widthScale, heightScale);
62
+ const width = mediaSize.width * scale;
63
+ const height = mediaSize.height * scale;
64
+ return normalizeRect({
65
+ left: container.left + (container.width - width) / 2,
66
+ top: container.top + (container.height - height) / 2,
67
+ width,
68
+ height,
69
+ });
70
+ }
71
+ function sharedGeometryFor(container, mediaSize, objectFit) {
72
+ var _a;
73
+ const contentFrameInWindow = fitRect(mediaSize, container, objectFit);
74
+ const visibleFrame = (_a = intersectRects(container, contentFrameInWindow)) !== null && _a !== void 0 ? _a : normalizeRect(container);
75
+ const contentFrame = normalizeRect({
76
+ left: contentFrameInWindow.left - visibleFrame.left,
77
+ top: contentFrameInWindow.top - visibleFrame.top,
78
+ width: contentFrameInWindow.width,
79
+ height: contentFrameInWindow.height,
80
+ });
81
+ return { visibleFrame, contentFrame };
82
+ }
83
+ function targetGeometryFor(mediaSize, container) {
84
+ const visibleFrame = fitRect(mediaSize, container, 'contain');
85
+ return {
86
+ visibleFrame,
87
+ contentFrame: normalizeRect({
88
+ left: 0,
89
+ top: 0,
90
+ width: visibleFrame.width,
91
+ height: visibleFrame.height,
92
+ }),
93
+ };
94
+ }
95
+ function intersectRects(first, second) {
96
+ const left = Math.max(first.left, second.left);
97
+ const top = Math.max(first.top, second.top);
98
+ const right = Math.min(first.right, second.right);
99
+ const bottom = Math.min(first.bottom, second.bottom);
100
+ if (right <= left || bottom <= top) {
101
+ return null;
102
+ }
103
+ return normalizeRect({ left, top, width: right - left, height: bottom - top });
104
+ }
105
+ function lerp(start, end, progress) {
106
+ return start + (end - start) * progress;
107
+ }
108
+ function lerpRect(start, end, progress) {
109
+ return normalizeRect({
110
+ left: lerp(start.left, end.left, progress),
111
+ top: lerp(start.top, end.top, progress),
112
+ width: lerp(start.width, end.width, progress),
113
+ height: lerp(start.height, end.height, progress),
114
+ });
115
+ }
116
+ function easeOutCubic(t) {
117
+ return 1 - Math.pow(1 - t, 3);
118
+ }
119
+ function easeOutQuart(t) {
120
+ return 1 - Math.pow(1 - t, 4);
121
+ }
@@ -0,0 +1,6 @@
1
+ import type { NativeImagePreviewWebImageSize, NativeImagePreviewWebMediaItem, NativeImagePreviewWebResolvedItem } from './types';
2
+ export declare function normalizeItems(items: readonly NativeImagePreviewWebMediaItem[]): NativeImagePreviewWebResolvedItem[];
3
+ export declare function previewSourceFor(item: NativeImagePreviewWebResolvedItem): string;
4
+ export declare function resolveMediaSize(item: NativeImagePreviewWebResolvedItem, fallback?: NativeImagePreviewWebImageSize | null): Promise<NativeImagePreviewWebImageSize>;
5
+ export declare function waitForElementImage(element: Element | null | undefined): Promise<void>;
6
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../../src/ui/NativeImagePreview/web/media.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,8BAA8B,EAAkC,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAEjK,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,8BAA8B,EAAE,GAAG,iCAAiC,EAAE,CAoBpH;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iCAAiC,GAAG,MAAM,CAEhF;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,iCAAiC,EACvC,QAAQ,CAAC,EAAE,8BAA8B,GAAG,IAAI,GAC/C,OAAO,CAAC,8BAA8B,CAAC,CAgBzC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /// <reference lib="dom" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.normalizeItems = normalizeItems;
5
+ exports.previewSourceFor = previewSourceFor;
6
+ exports.resolveMediaSize = resolveMediaSize;
7
+ exports.waitForElementImage = waitForElementImage;
8
+ function normalizeItems(items) {
9
+ return items
10
+ .map((item, index) => {
11
+ var _a, _b, _c, _d;
12
+ const src = (_b = (_a = item.src) !== null && _a !== void 0 ? _a : item.url) !== null && _b !== void 0 ? _b : '';
13
+ if (!src.trim()) {
14
+ return null;
15
+ }
16
+ const type = resolveType(item);
17
+ return {
18
+ id: (_c = item.id) !== null && _c !== void 0 ? _c : String(index),
19
+ type,
20
+ src,
21
+ poster: item.poster,
22
+ width: item.width,
23
+ height: item.height,
24
+ alt: (_d = item.alt) !== null && _d !== void 0 ? _d : `Image ${index + 1}`,
25
+ raw: item,
26
+ };
27
+ })
28
+ .filter((item) => item !== null);
29
+ }
30
+ function previewSourceFor(item) {
31
+ var _a;
32
+ return item.type === 'video' ? (_a = item.poster) !== null && _a !== void 0 ? _a : item.src : item.src;
33
+ }
34
+ async function resolveMediaSize(item, fallback) {
35
+ if (fallback && fallback.width > 0 && fallback.height > 0) {
36
+ return fallback;
37
+ }
38
+ if (item.width && item.height) {
39
+ return { width: item.width, height: item.height };
40
+ }
41
+ const previewSource = previewSourceFor(item);
42
+ if (!previewSource) {
43
+ return { width: 1, height: 1 };
44
+ }
45
+ try {
46
+ return await loadImageSize(previewSource);
47
+ }
48
+ catch {
49
+ return { width: 1, height: 1 };
50
+ }
51
+ }
52
+ function waitForElementImage(element) {
53
+ if (!(element instanceof HTMLImageElement)) {
54
+ return Promise.resolve();
55
+ }
56
+ if (element.complete && element.naturalWidth > 0) {
57
+ return Promise.resolve();
58
+ }
59
+ return new Promise((resolve) => {
60
+ const done = () => {
61
+ element.removeEventListener('load', done);
62
+ element.removeEventListener('error', done);
63
+ resolve();
64
+ };
65
+ element.addEventListener('load', done, { once: true });
66
+ element.addEventListener('error', done, { once: true });
67
+ });
68
+ }
69
+ function resolveType(item) {
70
+ var _a, _b;
71
+ if (item.type === 'video') {
72
+ return 'video';
73
+ }
74
+ const src = (_b = (_a = item.src) !== null && _a !== void 0 ? _a : item.url) !== null && _b !== void 0 ? _b : '';
75
+ return /\.(mp4|webm|ogg)(\?.*)?$/i.test(src) ? 'video' : 'image';
76
+ }
77
+ function loadImageSize(src) {
78
+ return new Promise((resolve, reject) => {
79
+ const image = new Image();
80
+ image.decoding = 'async';
81
+ image.onload = () => {
82
+ resolve({
83
+ width: image.naturalWidth || image.width || 1,
84
+ height: image.naturalHeight || image.height || 1,
85
+ });
86
+ };
87
+ image.onerror = () => reject(new Error(`Unable to load image: ${src}`));
88
+ image.src = src;
89
+ });
90
+ }