UNPKG

tdesign-vue

Version:
180 lines (176 loc) 7.13 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, toRefs, ref, computed, watch } from '@vue/composition-api'; import { ImageErrorIcon } from 'tdesign-icons-vue'; import '../../hooks/useConfig.js'; import { useDrag } from '../hooks.js'; import { setTransform } from '../../utils/helper.js'; import '../../hooks/index.js'; import { useConfig } from '../../config-provider/useConfig.js'; import { useImagePreviewUrl } from '../../hooks/useImagePreviewUrl.js'; import '../../config-provider/context.js'; import 'lodash-es'; import '../../_common/js/global-config/default-config.js'; import '../../_common/js/global-config/locale/zh_CN.js'; import '../../_chunks/dep-d2f11e9e.js'; import '@babel/runtime/helpers/typeof'; import '../../_chunks/dep-05dc6583.js'; import 'dayjs'; import '../../_chunks/dep-62386ed0.js'; import '../../config-provider/type.js'; import '../../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; import '../const.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import 'vue'; import '../../hooks/slots.js'; import '../../hooks/useCommonClassName.js'; import '../../hooks/useDefaultValue.js'; import '../../hooks/useDestroyOnClose.js'; import '../../hooks/useElementLazyRender.js'; import '../../_common/js/utils/observe.js'; import '../../hooks/useFormDisabled.js'; import '../../hooks/useGlobalIcon.js'; import '../../hooks/useLazyLoad.js'; import '../../hooks/useResizeObserver.js'; import '../../hooks/useVirtualScrollNew.js'; import '@babel/runtime/helpers/toConsumableArray'; import '../../hooks/useVModel.js'; import '../../hooks/useMutationObservable.js'; import '../../hooks/useVariables.js'; import '../../_common/js/utils/getColorTokenColor.js'; import '../../_common/js/common.js'; import '../../_common/js/upload/utils.js'; import '../../_common/js/log/log.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var TImageItem = defineComponent({ name: "TImageItem", props: { rotate: Number, scale: Number, mirror: Number, src: [String, Object], placementSrc: [String, Object], imageReferrerpolicy: String }, setup: function setup(props) { var _toRefs = toRefs(props), src = _toRefs.src, placementSrc = _toRefs.placementSrc; var _useConfig = useConfig("imageViewer"), classPrefix = _useConfig.classPrefix, globalConfig = _useConfig.global; var error = ref(false); var loaded = ref(false); var _useDrag = useDrag({ translateX: 0, translateY: 0 }), transform = _useDrag.transform, mouseDownHandler = _useDrag.mouseDownHandler; var _useImagePreviewUrl = useImagePreviewUrl(src), mainImagePreviewUrl = _useImagePreviewUrl.previewUrl; var _useImagePreviewUrl2 = useImagePreviewUrl(placementSrc), placementImagePreviewUrl = _useImagePreviewUrl2.previewUrl; var imgStyle = computed(function () { return _objectSpread(_objectSpread({}, setTransform("rotate(".concat(props.rotate, "deg) scale(").concat(props.scale, ")"))), {}, { display: !props.placementSrc || loaded.value ? "block" : "none" }); }); var placementImgStyle = computed(function () { return _objectSpread(_objectSpread({}, setTransform("rotate(".concat(props.rotate, "deg) scale(").concat(props.scale, ")"))), {}, { display: !loaded.value ? "block" : "none" }); }); var boxStyle = computed(function () { var _transform$value = transform.value, translateX = _transform$value.translateX, translateY = _transform$value.translateY; return setTransform("translate(".concat(translateX, "px, ").concat(translateY, "px) scale(").concat(props.mirror, ", 1)")); }); var resetStatus = function resetStatus() { error.value = false; loaded.value = false; }; watch([mainImagePreviewUrl, placementImagePreviewUrl], function () { resetStatus(); }); return { globalConfig: globalConfig, classPrefix: classPrefix, boxStyle: boxStyle, loaded: loaded, error: error, mouseDownHandler: mouseDownHandler, placementImgStyle: placementImgStyle, imgStyle: imgStyle, mainImagePreviewUrl: mainImagePreviewUrl, placementImagePreviewUrl: placementImagePreviewUrl }; }, render: function render() { var _this = this; var h = arguments[0]; return h("div", { "class": "".concat(this.classPrefix, "-image-viewer__modal-pic") }, [h("div", { "class": "".concat(this.classPrefix, "-image-viewer__modal-box"), "style": this.boxStyle }, [this.error && h("div", { "class": "".concat(this.classPrefix, "-image-viewer__img-error") }, [h("div", { "class": "".concat(this.classPrefix, "-image-viewer__img-error-content") }, [h(ImageErrorIcon, { "attrs": { "size": "4em" } }), h("div", { "class": "".concat(this.classPrefix, "-image-viewer__img-error-text") }, [this.globalConfig.errorText])])]), !this.error && !!this.placementSrc && this.placementImagePreviewUrl && h("img", { "class": "".concat(this.classPrefix, "-image-viewer__modal-image"), "on": { "mousedown": function mousedown(event) { event.stopPropagation(); _this.mouseDownHandler(event); } }, "attrs": { "src": this.placementImagePreviewUrl, "alt": "image", "draggable": "false", "referrerpolicy": this.imageReferrerpolicy }, "style": this.placementImgStyle }), !this.error && this.mainImagePreviewUrl && h("img", { "class": "".concat(this.classPrefix, "-image-viewer__modal-image"), "on": { "mousedown": function mousedown(event) { event.stopPropagation(); _this.mouseDownHandler(event); }, "load": function load() { return _this.loaded = true; }, "error": function error() { return _this.error = true; } }, "attrs": { "src": this.mainImagePreviewUrl, "alt": "image", "draggable": "false", "referrerpolicy": this.imageReferrerpolicy }, "style": this.imgStyle })])]); } }); export { TImageItem as default }; //# sourceMappingURL=ImageItem.js.map