@cloud-app-dev/vidc 3.2.37 → 3.2.38
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/es/Picture/component/Tools/index.d.ts +1 -2
- package/es/Picture/component/Tools/index.js +1 -7
- package/es/Picture/demo.js +6 -16
- package/es/Picture/index.d.ts +1 -1
- package/es/Picture/index.js +55 -96
- package/es/Picture/index.less +7 -2
- package/es/Picture/utils.d.ts +6 -0
- package/es/Picture/utils.js +58 -2
- package/package.json +2 -2
- package/es/Picture/dragBound.d.ts +0 -5
- package/es/Picture/dragBound.js +0 -77
|
@@ -7,7 +7,6 @@ interface IToolsProps {
|
|
|
7
7
|
setRotate: (rotate: number) => void;
|
|
8
8
|
containerEle: HTMLDivElement;
|
|
9
9
|
resetPicture: (event: React.MouseEvent) => void;
|
|
10
|
-
fullScreenChange: () => void;
|
|
11
10
|
}
|
|
12
|
-
declare function Tools({ scale, imgDownload, setScale, setRotate, containerEle, resetPicture
|
|
11
|
+
declare function Tools({ scale, imgDownload, setScale, setRotate, containerEle, resetPicture }: IToolsProps): JSX.Element;
|
|
13
12
|
export default Tools;
|
|
@@ -14,8 +14,7 @@ function Tools(_ref) {
|
|
|
14
14
|
setScale = _ref.setScale,
|
|
15
15
|
setRotate = _ref.setRotate,
|
|
16
16
|
containerEle = _ref.containerEle,
|
|
17
|
-
resetPicture = _ref.resetPicture
|
|
18
|
-
_fullScreenChange = _ref.fullScreenChange;
|
|
17
|
+
resetPicture = _ref.resetPicture;
|
|
19
18
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
20
19
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
21
20
|
className: "picture-tools",
|
|
@@ -87,11 +86,6 @@ function Tools(_ref) {
|
|
|
87
86
|
className: "footer_window",
|
|
88
87
|
getContainer: function getContainer() {
|
|
89
88
|
return containerEle;
|
|
90
|
-
},
|
|
91
|
-
fullScreenChange: function fullScreenChange() {
|
|
92
|
-
return setTimeout(function () {
|
|
93
|
-
return _fullScreenChange();
|
|
94
|
-
}, 200);
|
|
95
89
|
}
|
|
96
90
|
})
|
|
97
91
|
})]
|
package/es/Picture/demo.js
CHANGED
|
@@ -44,24 +44,13 @@ export default function App() {
|
|
|
44
44
|
title: '菜单1',
|
|
45
45
|
pathname: '/',
|
|
46
46
|
icon: ''
|
|
47
|
-
}]
|
|
48
|
-
|
|
47
|
+
}] // imagePath="http://192.168.100.246:5463/oss/v1/100004008/objects/638da35805f5f0a8101021f9?client_token=100004008_0_1670313176_9a47a8459c120d977904c9feb2354a7e"
|
|
48
|
+
,
|
|
49
49
|
isOpenSelect: state.open,
|
|
50
|
+
imagePath: "https://img0.baidu.com/it/u=1439439032,129098198&fm=253&fmt=auto?w=120&h=80",
|
|
50
51
|
rects: [{
|
|
51
52
|
type: 'face',
|
|
52
|
-
rect: [
|
|
53
|
-
needExpand: true
|
|
54
|
-
}, {
|
|
55
|
-
type: 'face',
|
|
56
|
-
rect: [20, 25, 23.0, 23.0],
|
|
57
|
-
needExpand: true
|
|
58
|
-
}, {
|
|
59
|
-
type: 'face',
|
|
60
|
-
rect: [40, 20.0, 49.0, 49.0],
|
|
61
|
-
needExpand: true
|
|
62
|
-
}, {
|
|
63
|
-
type: 'face',
|
|
64
|
-
rect: [35.0, 70.0, 41.0, 36.0],
|
|
53
|
+
rect: [920.0, 843.0, 96.0, 94.0],
|
|
65
54
|
needExpand: true
|
|
66
55
|
}],
|
|
67
56
|
children: function children() {
|
|
@@ -101,7 +90,8 @@ export default function App() {
|
|
|
101
90
|
children: /*#__PURE__*/_jsx("div", {
|
|
102
91
|
style: {
|
|
103
92
|
width: 800,
|
|
104
|
-
height: 600
|
|
93
|
+
height: 600,
|
|
94
|
+
backgroundColor: '#000'
|
|
105
95
|
},
|
|
106
96
|
children: /*#__PURE__*/_jsx(Picture, {
|
|
107
97
|
imagePath: "http://192.168.100.246:5463/oss/v1/100004008/objects/638da35805f5f0a8101021f9?client_token=100004008_0_1670313176_9a47a8459c120d977904c9feb2354a7e",
|
package/es/Picture/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import './index.less';
|
|
3
2
|
import type { IPictureProps } from './interface';
|
|
3
|
+
import './index.less';
|
|
4
4
|
declare function Picture({ className, width, height, minHeight, disabledDrag, imagePath, rects, isOpenSelect, disabledDrawMenu, menus, hasTool, fullScreenEle, ...props }: IPictureProps): JSX.Element;
|
|
5
5
|
declare namespace Picture {
|
|
6
6
|
var defaultProps: {
|
package/es/Picture/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import _useUpdateEffect from "ahooks/es/useUpdateEffect";
|
|
4
|
+
import _nextTick from "@cloud-app-dev/utils/es/nextTick";
|
|
4
5
|
import _useMemoizedFn from "ahooks/es/useMemoizedFn";
|
|
6
|
+
import _useSize from "ahooks/es/useSize";
|
|
5
7
|
var _excluded = ["className", "width", "height", "minHeight", "disabledDrag", "imagePath", "rects", "isOpenSelect", "disabledDrawMenu", "menus", "hasTool", "fullScreenEle"];
|
|
6
8
|
|
|
7
9
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
@@ -32,18 +34,17 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
32
34
|
|
|
33
35
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
34
36
|
|
|
35
|
-
import React, {
|
|
37
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
36
38
|
import DomMove from "../DomMove";
|
|
37
39
|
import useSimpleState from "../useSimpleState";
|
|
38
40
|
import DefaultRects from "./component/DefaultRects";
|
|
39
41
|
import DrawRect from "./component/DrawRect";
|
|
40
42
|
import Tools from "./component/Tools";
|
|
41
43
|
import WheelScale from "./component/WheelScale";
|
|
42
|
-
import { computedBound } from "./dragBound";
|
|
43
|
-
import "./index.less";
|
|
44
44
|
import { getRectImagePath } from "./loadCaptureRectImage";
|
|
45
45
|
import useDraw from "./useDraw";
|
|
46
|
-
import { computedRectScale, customContextMenu } from "./utils";
|
|
46
|
+
import { computedRectScale, customContextMenu, getImgSize } from "./utils";
|
|
47
|
+
import "./index.less";
|
|
47
48
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
48
49
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
50
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -93,6 +94,9 @@ function Picture(_ref) {
|
|
|
93
94
|
var layoutRef = useRef(null);
|
|
94
95
|
var moveActionRef = useRef(null);
|
|
95
96
|
var domImgRef = useRef(null);
|
|
97
|
+
|
|
98
|
+
var size = _useSize(layoutRef);
|
|
99
|
+
|
|
96
100
|
useEffect(function () {
|
|
97
101
|
if (!imagePath) {
|
|
98
102
|
return undefined;
|
|
@@ -121,15 +125,13 @@ function Picture(_ref) {
|
|
|
121
125
|
|
|
122
126
|
|
|
123
127
|
var loadImageSuccess = _useMemoizedFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
var img, naturalWidth, naturalHeight, layoutRect, w, h, baseXOrY, x, y, size, imagescale, imgHeight, _imagescale, imgWidth, moveObj;
|
|
128
|
+
var _getImgSize, x, y, size, baseXOrY, moveObj;
|
|
127
129
|
|
|
128
130
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
129
131
|
while (1) {
|
|
130
132
|
switch (_context.prev = _context.next) {
|
|
131
133
|
case 0:
|
|
132
|
-
if (state.localUrl) {
|
|
134
|
+
if (!(!state.localUrl || !layoutRef.current || !domImgRef.current)) {
|
|
133
135
|
_context.next = 2;
|
|
134
136
|
break;
|
|
135
137
|
}
|
|
@@ -137,48 +139,7 @@ function Picture(_ref) {
|
|
|
137
139
|
return _context.abrupt("return");
|
|
138
140
|
|
|
139
141
|
case 2:
|
|
140
|
-
|
|
141
|
-
naturalWidth = img.naturalWidth, naturalHeight = img.naturalHeight;
|
|
142
|
-
layoutRect = (_layoutRef$current2 = layoutRef.current) === null || _layoutRef$current2 === void 0 ? void 0 : _layoutRef$current2.getBoundingClientRect();
|
|
143
|
-
w = (_layoutRect$width = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.width) !== null && _layoutRect$width !== void 0 ? _layoutRect$width : 0;
|
|
144
|
-
h = (_layoutRect$height = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.height) !== null && _layoutRect$height !== void 0 ? _layoutRect$height : 0;
|
|
145
|
-
baseXOrY = naturalWidth > naturalHeight ? 'x' : 'y';
|
|
146
|
-
x = 0;
|
|
147
|
-
y = 0;
|
|
148
|
-
size = []; // 横图
|
|
149
|
-
|
|
150
|
-
if (baseXOrY === 'x') {
|
|
151
|
-
if (naturalWidth < w) {
|
|
152
|
-
// 图片小于容器
|
|
153
|
-
size[0] = naturalWidth;
|
|
154
|
-
size[1] = naturalHeight;
|
|
155
|
-
x = (w - naturalWidth) / 2;
|
|
156
|
-
y = Math.abs((h - naturalHeight) / 2);
|
|
157
|
-
} else {
|
|
158
|
-
// 图片大于容器
|
|
159
|
-
imagescale = w / naturalWidth;
|
|
160
|
-
imgHeight = imagescale * naturalHeight;
|
|
161
|
-
y = Math.abs((imgHeight - h) / 2);
|
|
162
|
-
size[0] = w;
|
|
163
|
-
size[1] = imgHeight;
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
if (naturalHeight < h) {
|
|
167
|
-
// 图片小于容器
|
|
168
|
-
size[0] = naturalWidth;
|
|
169
|
-
size[1] = naturalHeight;
|
|
170
|
-
x = Math.abs(w - naturalWidth) / 2;
|
|
171
|
-
y = (h - naturalHeight) / 2;
|
|
172
|
-
} else {
|
|
173
|
-
// 图片大于容器
|
|
174
|
-
_imagescale = h / naturalHeight;
|
|
175
|
-
imgWidth = _imagescale * naturalWidth;
|
|
176
|
-
x = Math.abs((imgWidth - w) / 2);
|
|
177
|
-
size[0] = imgWidth;
|
|
178
|
-
size[1] = h;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
142
|
+
_getImgSize = getImgSize(layoutRef.current, domImgRef.current), x = _getImgSize.x, y = _getImgSize.y, size = _getImgSize.size, baseXOrY = _getImgSize.baseXOrY;
|
|
182
143
|
moveObj = moveActionRef.current;
|
|
183
144
|
moveObj.updatePosition({
|
|
184
145
|
x: x,
|
|
@@ -189,19 +150,29 @@ function Picture(_ref) {
|
|
|
189
150
|
x: x,
|
|
190
151
|
y: y,
|
|
191
152
|
offset: [x, y],
|
|
192
|
-
forceUpdateKey: Date.now(),
|
|
193
153
|
baseXOrY: baseXOrY,
|
|
194
154
|
size: size
|
|
195
155
|
});
|
|
196
|
-
});
|
|
156
|
+
}); // 异步触发rects重新计算
|
|
197
157
|
|
|
198
|
-
|
|
158
|
+
_nextTick(function () {
|
|
159
|
+
return updateState({
|
|
160
|
+
forceUpdateKey: Date.now()
|
|
161
|
+
});
|
|
162
|
+
}, 'setTimeout');
|
|
163
|
+
|
|
164
|
+
case 7:
|
|
199
165
|
case "end":
|
|
200
166
|
return _context.stop();
|
|
201
167
|
}
|
|
202
168
|
}
|
|
203
169
|
}, _callee);
|
|
204
|
-
})));
|
|
170
|
+
}))); // 更新重绘
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
_useUpdateEffect(function () {
|
|
174
|
+
loadImageSuccess();
|
|
175
|
+
}, [size]);
|
|
205
176
|
/**
|
|
206
177
|
* 设置图片缩放
|
|
207
178
|
*/
|
|
@@ -271,7 +242,7 @@ function Picture(_ref) {
|
|
|
271
242
|
*/
|
|
272
243
|
|
|
273
244
|
|
|
274
|
-
var onDragChange =
|
|
245
|
+
var onDragChange = _useMemoizedFn(function (_ref3) {
|
|
275
246
|
var x = _ref3.x,
|
|
276
247
|
y = _ref3.y;
|
|
277
248
|
return setState(function (old) {
|
|
@@ -280,29 +251,40 @@ function Picture(_ref) {
|
|
|
280
251
|
y: y
|
|
281
252
|
});
|
|
282
253
|
});
|
|
283
|
-
}
|
|
254
|
+
});
|
|
284
255
|
/**
|
|
285
256
|
* 拖拽结束更新位置,计算边界
|
|
286
257
|
*/
|
|
287
258
|
|
|
288
|
-
var onDragEnd = _useMemoizedFn(function (_, currrentPosition) {
|
|
289
|
-
var scale = state.scale,
|
|
290
|
-
rotate = state.rotate;
|
|
291
259
|
|
|
292
|
-
|
|
260
|
+
var onDragEnd = _useMemoizedFn(function (_, currrentPosition) {
|
|
261
|
+
if (!layoutRef.current || !domImgRef.current) {
|
|
293
262
|
return undefined;
|
|
294
263
|
}
|
|
295
264
|
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
265
|
+
var _ref4 = size || {
|
|
266
|
+
width: 0,
|
|
267
|
+
height: 0
|
|
268
|
+
},
|
|
269
|
+
width = _ref4.width,
|
|
270
|
+
height = _ref4.height;
|
|
271
|
+
|
|
272
|
+
var imgw = domImgRef.current.width * state.scale;
|
|
273
|
+
var imgh = domImgRef.current.height * state.scale;
|
|
274
|
+
var scaleW = imgw - domImgRef.current.width;
|
|
275
|
+
var scaleH = imgh - domImgRef.current.height; // 校验x,y范围,超出回弹
|
|
276
|
+
|
|
277
|
+
var maxX = imgw < width ? width - imgw + scaleW / 2 : scaleW / 2;
|
|
278
|
+
var maxY = imgh < height ? height - imgh + scaleH / 2 : scaleH / 2;
|
|
279
|
+
var minX = imgw < width ? scaleW / 2 : -(imgw - width) / 2 + state.offset[0];
|
|
280
|
+
var minY = imgh < height ? scaleH / 2 : -(imgh - height) / 2 + state.offset[1];
|
|
281
|
+
var x = currrentPosition.x > maxX ? maxX : currrentPosition.x < minX ? minX : currrentPosition.x;
|
|
282
|
+
var y = currrentPosition.y > maxY ? maxY : currrentPosition.y < minY ? minY : currrentPosition.y;
|
|
283
|
+
var moveObj = moveActionRef.current;
|
|
284
|
+
moveObj.updatePosition({
|
|
285
|
+
x: x,
|
|
286
|
+
y: y
|
|
287
|
+
});
|
|
306
288
|
});
|
|
307
289
|
/**
|
|
308
290
|
* 获取结构化的小图(base64)
|
|
@@ -311,30 +293,8 @@ function Picture(_ref) {
|
|
|
311
293
|
|
|
312
294
|
var getRectImage = _useMemoizedFn(function (rect) {
|
|
313
295
|
return getRectImagePath(domImgRef.current, rect);
|
|
314
|
-
});
|
|
296
|
+
}); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
315
297
|
|
|
316
|
-
useEffect(function () {
|
|
317
|
-
var timer;
|
|
318
|
-
|
|
319
|
-
var fn = function fn() {
|
|
320
|
-
clearTimeout(timer);
|
|
321
|
-
timer = setTimeout(function () {
|
|
322
|
-
setState(function (old) {
|
|
323
|
-
return _objectSpread(_objectSpread({}, old), {}, {
|
|
324
|
-
forceUpdateKey: Date.now()
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
}, 200);
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
var dom = layoutRef.current;
|
|
331
|
-
|
|
332
|
-
_resizeObserver.createResizeObserver(dom, fn);
|
|
333
|
-
|
|
334
|
-
return function () {
|
|
335
|
-
_resizeObserver.unResizeObserver(dom, fn);
|
|
336
|
-
};
|
|
337
|
-
}, []); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
338
298
|
|
|
339
299
|
var scaleRects = useMemo(function () {
|
|
340
300
|
return computedRectScale({
|
|
@@ -413,8 +373,7 @@ function Picture(_ref) {
|
|
|
413
373
|
scale: state.scale,
|
|
414
374
|
containerEle: fullScreenEle !== null && fullScreenEle !== void 0 ? fullScreenEle : layoutRef.current,
|
|
415
375
|
resetPicture: resetPicture,
|
|
416
|
-
imgDownload: imgDownload
|
|
417
|
-
fullScreenChange: loadImageSuccess
|
|
376
|
+
imgDownload: imgDownload
|
|
418
377
|
}), /*#__PURE__*/_jsx(WheelScale, {
|
|
419
378
|
setScale: setScale,
|
|
420
379
|
dom: layoutRef.current
|
package/es/Picture/index.less
CHANGED
package/es/Picture/utils.d.ts
CHANGED
|
@@ -18,3 +18,9 @@ export declare function computedRectScale({ domImg, rects }: {
|
|
|
18
18
|
lowQuality?: boolean | undefined;
|
|
19
19
|
base64?: string | undefined;
|
|
20
20
|
}[];
|
|
21
|
+
export declare function getImgSize(dom: HTMLDivElement, img: HTMLImageElement): {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
size: (string | number)[];
|
|
25
|
+
baseXOrY: string;
|
|
26
|
+
};
|
package/es/Picture/utils.js
CHANGED
|
@@ -77,8 +77,11 @@ export function computedRectScale(_ref) {
|
|
|
77
77
|
return [];
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
var
|
|
81
|
-
|
|
80
|
+
var _domImg$getBoundingCl = domImg.getBoundingClientRect(),
|
|
81
|
+
width = _domImg$getBoundingCl.width,
|
|
82
|
+
height = _domImg$getBoundingCl.height;
|
|
83
|
+
|
|
84
|
+
console.log(width, height, domImg.naturalWidth, domImg.naturalHeight);
|
|
82
85
|
var scaleOptions = {
|
|
83
86
|
scaleX: (_ref2 = width / domImg.naturalWidth) !== null && _ref2 !== void 0 ? _ref2 : 1,
|
|
84
87
|
scaleY: (_ref3 = height / domImg.naturalHeight) !== null && _ref3 !== void 0 ? _ref3 : 1
|
|
@@ -99,4 +102,57 @@ export function computedRectScale(_ref) {
|
|
|
99
102
|
rect: rect
|
|
100
103
|
});
|
|
101
104
|
});
|
|
105
|
+
}
|
|
106
|
+
export function getImgSize(dom, img) {
|
|
107
|
+
var _layoutRect$width, _layoutRect$height;
|
|
108
|
+
|
|
109
|
+
var naturalWidth = img.naturalWidth,
|
|
110
|
+
naturalHeight = img.naturalHeight;
|
|
111
|
+
var layoutRect = dom.getBoundingClientRect();
|
|
112
|
+
var w = (_layoutRect$width = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.width) !== null && _layoutRect$width !== void 0 ? _layoutRect$width : 0;
|
|
113
|
+
var h = (_layoutRect$height = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.height) !== null && _layoutRect$height !== void 0 ? _layoutRect$height : 0;
|
|
114
|
+
var baseXOrY = naturalWidth > naturalHeight ? 'x' : 'y';
|
|
115
|
+
var x = 0;
|
|
116
|
+
var y = 0;
|
|
117
|
+
var size = []; // 横图
|
|
118
|
+
|
|
119
|
+
if (baseXOrY === 'x') {
|
|
120
|
+
if (naturalWidth < w) {
|
|
121
|
+
// 图片小于容器
|
|
122
|
+
size[0] = naturalWidth;
|
|
123
|
+
size[1] = naturalHeight;
|
|
124
|
+
x = (w - naturalWidth) / 2;
|
|
125
|
+
y = Math.abs((h - naturalHeight) / 2);
|
|
126
|
+
} else {
|
|
127
|
+
// 图片大于容器
|
|
128
|
+
var imagescale = w / naturalWidth;
|
|
129
|
+
var imgHeight = imagescale * naturalHeight;
|
|
130
|
+
y = Math.abs((imgHeight - h) / 2);
|
|
131
|
+
size[0] = w;
|
|
132
|
+
size[1] = imgHeight;
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
if (naturalHeight < h) {
|
|
136
|
+
// 图片小于容器
|
|
137
|
+
size[0] = naturalWidth;
|
|
138
|
+
size[1] = naturalHeight;
|
|
139
|
+
x = Math.abs(w - naturalWidth) / 2;
|
|
140
|
+
y = (h - naturalHeight) / 2;
|
|
141
|
+
} else {
|
|
142
|
+
// 图片大于容器
|
|
143
|
+
var _imagescale = h / naturalHeight;
|
|
144
|
+
|
|
145
|
+
var imgWidth = _imagescale * naturalWidth;
|
|
146
|
+
x = Math.abs((imgWidth - w) / 2);
|
|
147
|
+
size[0] = imgWidth;
|
|
148
|
+
size[1] = h;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
x: x,
|
|
154
|
+
y: y,
|
|
155
|
+
size: size,
|
|
156
|
+
baseXOrY: baseXOrY
|
|
157
|
+
};
|
|
102
158
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@cloud-app-dev/vidc",
|
|
4
4
|
"description": "Video Image Data Componennts",
|
|
5
|
-
"version": "3.2.
|
|
5
|
+
"version": "3.2.38",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"docs:deploy": "gh-pages -d docs-dist",
|
|
8
8
|
"build": "npm run entry && father build",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/react-dom": "^18.0.6",
|
|
67
67
|
"antd": "^4.22.6",
|
|
68
68
|
"babel-plugin-import": "^1.13.5",
|
|
69
|
-
"dumi": "^2.0.
|
|
69
|
+
"dumi": "^2.0.13",
|
|
70
70
|
"gh-pages": "^4.0.0",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-dom": "^18.2.0",
|
package/es/Picture/dragBound.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export function computedBound(ele, currentPosition, scale, rotate) {
|
|
2
|
-
var data = currentPosition;
|
|
3
|
-
var eleRect = ele.getBoundingClientRect();
|
|
4
|
-
var isHorizontal = Math.abs(rotate) % 180 === 0;
|
|
5
|
-
var w = eleRect.width;
|
|
6
|
-
var h = eleRect.height;
|
|
7
|
-
var lx = 0,
|
|
8
|
-
ly = 0;
|
|
9
|
-
|
|
10
|
-
if (scale === 1 && isHorizontal) {
|
|
11
|
-
return {
|
|
12
|
-
x: 0,
|
|
13
|
-
y: 0
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (scale === 1 && !isHorizontal) {
|
|
18
|
-
lx = 0;
|
|
19
|
-
ly = (w - h) / 2;
|
|
20
|
-
} else {
|
|
21
|
-
//TODO 这是限制x区域,应该是使用原来高度的缩放大小来计算,
|
|
22
|
-
if (h * scale < w && !isHorizontal) {
|
|
23
|
-
//TODO 放大后竖向是 h*scale<w是 x = 0,
|
|
24
|
-
lx = 0;
|
|
25
|
-
} else {
|
|
26
|
-
//TODO 得到缩放后可移动区域 在减去误差 (w - h) / 2
|
|
27
|
-
lx = !isHorizontal ? Math.round(h * (scale - 1) / 2 - (w - h) / 2) : Math.round(w * (scale - 1) / 2);
|
|
28
|
-
} //TODO y的限制区域应该是原来宽度的限制区域计算后还要加上原始的(w-h)/2
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ly = !isHorizontal ? Math.round(w * (scale - 1) / 2 + (w - h) / 2) : Math.round(h * (scale - 1) / 2);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var x = 0,
|
|
35
|
-
y = 0;
|
|
36
|
-
|
|
37
|
-
if (data.x >= 0 && data.x > lx) {
|
|
38
|
-
x = lx;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (data.x >= 0 && data.x < lx) {
|
|
42
|
-
x = data.x;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (data.x < 0 && data.x < -lx) {
|
|
46
|
-
x = -lx;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (data.x < 0 && data.x > -lx) {
|
|
50
|
-
x = data.x;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (data.y >= 0 && data.y > ly) {
|
|
54
|
-
y = ly;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (data.y >= 0 && data.y < ly) {
|
|
58
|
-
y = data.y;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (data.y < 0 && data.y < -ly) {
|
|
62
|
-
y = -ly;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (data.y < 0 && data.y > -ly) {
|
|
66
|
-
y = data.y;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (x !== data.x || y !== data.y) {
|
|
70
|
-
return {
|
|
71
|
-
x: x,
|
|
72
|
-
y: y
|
|
73
|
-
};
|
|
74
|
-
} else {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
}
|