tdesign-mobile-vue
Version:
tdesign-mobile-vue
84 lines (80 loc) • 3.2 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 TDesign Group
* @license MIT
*/
import { positiveAdd, positiveSubtract } from '../input-number/number.mjs';
import 'lodash-es';
import '../input-number/large-number.mjs';
import '../../../_chunks/dep-a3709177.mjs';
import '../../../_chunks/dep-8efef78c.mjs';
import '../log/log.mjs';
import '../log/index.mjs';
var DEFAULT_IMAGE_SCALE = {
max: 2,
min: 0.5,
step: 0.2,
defaultScale: 1
};
var isImageExceedsViewport = function isImageExceedsViewport(container, modalBox) {
var containerRect = container.getBoundingClientRect();
var modalRect = modalBox.getBoundingClientRect();
return modalRect.left < containerRect.left || modalRect.right > containerRect.right || modalRect.top < containerRect.top || modalRect.bottom > containerRect.bottom;
};
var MIRROR_DEFAULT = 1;
var toggleMirror = function toggleMirror(current) {
return current > 0 ? -1 : 1;
};
var ROTATE_DEG = -90;
function calcResetRotation(currentDeg) {
var degreeToRotate = currentDeg % 360;
if (degreeToRotate === 0) return 0;
return Math.abs(degreeToRotate) > 180 ? (degreeToRotate + 360) % 360 : degreeToRotate;
}
function clampScale(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function calcZoomInScale(oldScale, step, min, max) {
return clampScale(positiveAdd(oldScale, step), min, max);
}
function calcZoomOutScale(oldScale, step, min, max) {
return clampScale(positiveSubtract(oldScale, step), min, max);
}
function calculateTranslateOffset(oldScale, newScale, options) {
var _options$currentTrans;
if ((options === null || options === void 0 ? void 0 : options.mouseOffsetX) == null || (options === null || options === void 0 ? void 0 : options.mouseOffsetY) == null) {
return void 0;
}
var scaleRatio = newScale / oldScale;
var _ref = (_options$currentTrans = options === null || options === void 0 ? void 0 : options.currentTranslate) !== null && _options$currentTrans !== void 0 ? _options$currentTrans : {},
_ref$translateX = _ref.translateX,
translateX = _ref$translateX === void 0 ? 0 : _ref$translateX,
_ref$translateY = _ref.translateY,
translateY = _ref$translateY === void 0 ? 0 : _ref$translateY;
var mouseOffsetX = options.mouseOffsetX,
mouseOffsetY = options.mouseOffsetY;
return {
translateX: scaleRatio * translateX + (1 - scaleRatio) * mouseOffsetX,
translateY: scaleRatio * translateY + (1 - scaleRatio) * mouseOffsetY
};
}
function zoomIn(oldScale, step, min, max, options) {
var newScale = calcZoomInScale(oldScale, step, min, max);
return {
newScale: newScale,
zoomResult: {
newTranslate: calculateTranslateOffset(oldScale, newScale, options)
}
};
}
function zoomOut(oldScale, step, min, max, options) {
var newScale = calcZoomOutScale(oldScale, step, min, max);
return {
newScale: newScale,
zoomResult: {
newTranslate: calculateTranslateOffset(oldScale, newScale, options)
}
};
}
export { DEFAULT_IMAGE_SCALE, MIRROR_DEFAULT, ROTATE_DEG, calcResetRotation, calcZoomInScale, calcZoomOutScale, calculateTranslateOffset, clampScale, isImageExceedsViewport, toggleMirror, zoomIn, zoomOut };
//# sourceMappingURL=transform.mjs.map