@cloud-app-dev/vidc 3.2.36 → 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/Drawer/{demo.d.ts → Demo.d.ts} +0 -0
- package/es/Drawer/{demo.js → Demo.js} +0 -0
- package/es/Picture/component/Tools/index.d.ts +1 -2
- package/es/Picture/component/Tools/index.js +1 -7
- package/es/Picture/demo.js +24 -17
- package/es/Picture/index.d.ts +1 -1
- package/es/Picture/index.js +61 -79
- package/es/Picture/index.less +7 -2
- package/es/Picture/utils.d.ts +6 -0
- package/es/Picture/utils.js +61 -5
- package/package.json +2 -2
- package/es/Picture/dragBound.d.ts +0 -5
- package/es/Picture/dragBound.js +0 -77
|
File without changes
|
|
File without changes
|
|
@@ -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: [754.0, 268.0, 23.0, 23.0],
|
|
57
|
-
needExpand: true
|
|
58
|
-
}, {
|
|
59
|
-
type: 'face',
|
|
60
|
-
rect: [430.0, 421.0, 49.0, 49.0],
|
|
61
|
-
needExpand: true
|
|
62
|
-
}, {
|
|
63
|
-
type: 'face',
|
|
64
|
-
rect: [240.0, 468.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,11 +90,29 @@ 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",
|
|
108
|
-
isOpenSelect: false
|
|
98
|
+
isOpenSelect: false,
|
|
99
|
+
rects: [{
|
|
100
|
+
type: 'face',
|
|
101
|
+
rect: [698, 274, 23, 23],
|
|
102
|
+
needExpand: true
|
|
103
|
+
}, {
|
|
104
|
+
type: 'face',
|
|
105
|
+
rect: [754.0, 268.0, 23.0, 23.0],
|
|
106
|
+
needExpand: true
|
|
107
|
+
}, {
|
|
108
|
+
type: 'face',
|
|
109
|
+
rect: [430.0, 421.0, 49.0, 49.0],
|
|
110
|
+
needExpand: true
|
|
111
|
+
}, {
|
|
112
|
+
type: 'face',
|
|
113
|
+
rect: [240.0, 468.0, 41.0, 36.0],
|
|
114
|
+
needExpand: true
|
|
115
|
+
}]
|
|
109
116
|
})
|
|
110
117
|
})
|
|
111
118
|
})]
|
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";
|
|
@@ -82,7 +83,8 @@ function Picture(_ref) {
|
|
|
82
83
|
forceUpdateKey: Date.now(),
|
|
83
84
|
fullScreenStatus: false,
|
|
84
85
|
localUrl: '',
|
|
85
|
-
offset: [0, 0]
|
|
86
|
+
offset: [0, 0],
|
|
87
|
+
size: ['auto', 'auto']
|
|
86
88
|
}),
|
|
87
89
|
_useSimpleState2 = _slicedToArray(_useSimpleState, 3),
|
|
88
90
|
state = _useSimpleState2[0],
|
|
@@ -92,6 +94,9 @@ function Picture(_ref) {
|
|
|
92
94
|
var layoutRef = useRef(null);
|
|
93
95
|
var moveActionRef = useRef(null);
|
|
94
96
|
var domImgRef = useRef(null);
|
|
97
|
+
|
|
98
|
+
var size = _useSize(layoutRef);
|
|
99
|
+
|
|
95
100
|
useEffect(function () {
|
|
96
101
|
if (!imagePath) {
|
|
97
102
|
return undefined;
|
|
@@ -120,15 +125,13 @@ function Picture(_ref) {
|
|
|
120
125
|
|
|
121
126
|
|
|
122
127
|
var loadImageSuccess = _useMemoizedFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
var img, naturalWidth, naturalHeight, layoutRect, w, h, baseXOrY, x, y, imagescale, imgHeight, _imagescale, imgWidth, moveObj;
|
|
128
|
+
var _getImgSize, x, y, size, baseXOrY, moveObj;
|
|
126
129
|
|
|
127
130
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
128
131
|
while (1) {
|
|
129
132
|
switch (_context.prev = _context.next) {
|
|
130
133
|
case 0:
|
|
131
|
-
if (state.localUrl) {
|
|
134
|
+
if (!(!state.localUrl || !layoutRef.current || !domImgRef.current)) {
|
|
132
135
|
_context.next = 2;
|
|
133
136
|
break;
|
|
134
137
|
}
|
|
@@ -136,27 +139,7 @@ function Picture(_ref) {
|
|
|
136
139
|
return _context.abrupt("return");
|
|
137
140
|
|
|
138
141
|
case 2:
|
|
139
|
-
|
|
140
|
-
naturalWidth = img.naturalWidth, naturalHeight = img.naturalHeight;
|
|
141
|
-
layoutRect = (_layoutRef$current2 = layoutRef.current) === null || _layoutRef$current2 === void 0 ? void 0 : _layoutRef$current2.getBoundingClientRect();
|
|
142
|
-
w = (_layoutRect$width = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.width) !== null && _layoutRect$width !== void 0 ? _layoutRect$width : 0;
|
|
143
|
-
h = (_layoutRect$height = layoutRect === null || layoutRect === void 0 ? void 0 : layoutRect.height) !== null && _layoutRect$height !== void 0 ? _layoutRect$height : 0;
|
|
144
|
-
baseXOrY = naturalWidth > naturalHeight ? 'x' : 'y';
|
|
145
|
-
x = 0;
|
|
146
|
-
y = 0;
|
|
147
|
-
|
|
148
|
-
if (baseXOrY === 'x') {
|
|
149
|
-
imagescale = w / naturalWidth;
|
|
150
|
-
imgHeight = imagescale * naturalHeight;
|
|
151
|
-
y = Math.abs((imgHeight - h) / 2);
|
|
152
|
-
img.width = w;
|
|
153
|
-
} else {
|
|
154
|
-
_imagescale = h / naturalHeight;
|
|
155
|
-
imgWidth = _imagescale * naturalWidth;
|
|
156
|
-
x = Math.abs((imgWidth - w) / 2);
|
|
157
|
-
img.height = h;
|
|
158
|
-
}
|
|
159
|
-
|
|
142
|
+
_getImgSize = getImgSize(layoutRef.current, domImgRef.current), x = _getImgSize.x, y = _getImgSize.y, size = _getImgSize.size, baseXOrY = _getImgSize.baseXOrY;
|
|
160
143
|
moveObj = moveActionRef.current;
|
|
161
144
|
moveObj.updatePosition({
|
|
162
145
|
x: x,
|
|
@@ -167,18 +150,29 @@ function Picture(_ref) {
|
|
|
167
150
|
x: x,
|
|
168
151
|
y: y,
|
|
169
152
|
offset: [x, y],
|
|
170
|
-
|
|
171
|
-
|
|
153
|
+
baseXOrY: baseXOrY,
|
|
154
|
+
size: size
|
|
172
155
|
});
|
|
173
|
-
});
|
|
156
|
+
}); // 异步触发rects重新计算
|
|
174
157
|
|
|
175
|
-
|
|
158
|
+
_nextTick(function () {
|
|
159
|
+
return updateState({
|
|
160
|
+
forceUpdateKey: Date.now()
|
|
161
|
+
});
|
|
162
|
+
}, 'setTimeout');
|
|
163
|
+
|
|
164
|
+
case 7:
|
|
176
165
|
case "end":
|
|
177
166
|
return _context.stop();
|
|
178
167
|
}
|
|
179
168
|
}
|
|
180
169
|
}, _callee);
|
|
181
|
-
})));
|
|
170
|
+
}))); // 更新重绘
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
_useUpdateEffect(function () {
|
|
174
|
+
loadImageSuccess();
|
|
175
|
+
}, [size]);
|
|
182
176
|
/**
|
|
183
177
|
* 设置图片缩放
|
|
184
178
|
*/
|
|
@@ -248,7 +242,7 @@ function Picture(_ref) {
|
|
|
248
242
|
*/
|
|
249
243
|
|
|
250
244
|
|
|
251
|
-
var onDragChange =
|
|
245
|
+
var onDragChange = _useMemoizedFn(function (_ref3) {
|
|
252
246
|
var x = _ref3.x,
|
|
253
247
|
y = _ref3.y;
|
|
254
248
|
return setState(function (old) {
|
|
@@ -257,29 +251,40 @@ function Picture(_ref) {
|
|
|
257
251
|
y: y
|
|
258
252
|
});
|
|
259
253
|
});
|
|
260
|
-
}
|
|
254
|
+
});
|
|
261
255
|
/**
|
|
262
256
|
* 拖拽结束更新位置,计算边界
|
|
263
257
|
*/
|
|
264
258
|
|
|
265
|
-
var onDragEnd = _useMemoizedFn(function (_, currrentPosition) {
|
|
266
|
-
var scale = state.scale,
|
|
267
|
-
rotate = state.rotate;
|
|
268
259
|
|
|
269
|
-
|
|
260
|
+
var onDragEnd = _useMemoizedFn(function (_, currrentPosition) {
|
|
261
|
+
if (!layoutRef.current || !domImgRef.current) {
|
|
270
262
|
return undefined;
|
|
271
263
|
}
|
|
272
264
|
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
});
|
|
283
288
|
});
|
|
284
289
|
/**
|
|
285
290
|
* 获取结构化的小图(base64)
|
|
@@ -288,30 +293,8 @@ function Picture(_ref) {
|
|
|
288
293
|
|
|
289
294
|
var getRectImage = _useMemoizedFn(function (rect) {
|
|
290
295
|
return getRectImagePath(domImgRef.current, rect);
|
|
291
|
-
});
|
|
296
|
+
}); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
292
297
|
|
|
293
|
-
useEffect(function () {
|
|
294
|
-
var timer;
|
|
295
|
-
|
|
296
|
-
var fn = function fn() {
|
|
297
|
-
clearTimeout(timer);
|
|
298
|
-
timer = setTimeout(function () {
|
|
299
|
-
setState(function (old) {
|
|
300
|
-
return _objectSpread(_objectSpread({}, old), {}, {
|
|
301
|
-
forceUpdateKey: Date.now()
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
}, 200);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
var dom = layoutRef.current;
|
|
308
|
-
|
|
309
|
-
_resizeObserver.createResizeObserver(dom, fn);
|
|
310
|
-
|
|
311
|
-
return function () {
|
|
312
|
-
_resizeObserver.unResizeObserver(dom, fn);
|
|
313
|
-
};
|
|
314
|
-
}, []); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
315
298
|
|
|
316
299
|
var scaleRects = useMemo(function () {
|
|
317
300
|
return computedRectScale({
|
|
@@ -365,8 +348,8 @@ function Picture(_ref) {
|
|
|
365
348
|
draggable: false,
|
|
366
349
|
src: state.localUrl,
|
|
367
350
|
style: {
|
|
368
|
-
width: state.
|
|
369
|
-
height: state.
|
|
351
|
+
width: state.size[0],
|
|
352
|
+
height: state.size[1]
|
|
370
353
|
},
|
|
371
354
|
"data-src": imagePath,
|
|
372
355
|
onLoad: loadImageSuccess
|
|
@@ -390,8 +373,7 @@ function Picture(_ref) {
|
|
|
390
373
|
scale: state.scale,
|
|
391
374
|
containerEle: fullScreenEle !== null && fullScreenEle !== void 0 ? fullScreenEle : layoutRef.current,
|
|
392
375
|
resetPicture: resetPicture,
|
|
393
|
-
imgDownload: imgDownload
|
|
394
|
-
fullScreenChange: loadImageSuccess
|
|
376
|
+
imgDownload: imgDownload
|
|
395
377
|
}), /*#__PURE__*/_jsx(WheelScale, {
|
|
396
378
|
setScale: setScale,
|
|
397
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
|
|
@@ -87,16 +90,69 @@ export function computedRectScale(_ref) {
|
|
|
87
90
|
var rect = item.needExpand ? getCaptureRect(cloneDeep(item.rect), item.type) : cloneDeep(item.rect);
|
|
88
91
|
rect[0] = Math.round(rect[0] * scaleOptions.scaleX);
|
|
89
92
|
rect[0] < 0 && (rect[0] = 0);
|
|
90
|
-
rect[2] = Math.round(rect[2] * scaleOptions.scaleX);
|
|
91
|
-
rect[2] < 0 && (rect[2] = 0);
|
|
92
93
|
rect[1] = Math.round(rect[1] * scaleOptions.scaleY);
|
|
93
94
|
rect[1] < 0 && (rect[1] = 0);
|
|
95
|
+
rect[2] = Math.round(rect[2] * scaleOptions.scaleX);
|
|
96
|
+
rect[2] < 0 && (rect[2] = 0);
|
|
97
|
+
rect[2] > width - rect[0] && (rect[2] = width - rect[0]);
|
|
94
98
|
rect[3] = Math.round(rect[3] * scaleOptions.scaleY);
|
|
95
99
|
rect[3] < 0 && (rect[3] = 0);
|
|
96
|
-
rect[2] > width - rect[0] && (rect[2] = width - rect[0]);
|
|
97
100
|
rect[3] > height - rect[1] && (rect[3] = height - rect[1]);
|
|
98
101
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
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
|
-
}
|