linkmore-design 1.1.3 → 1.1.4
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/dist/CropImg/LmCropImg.d.ts +11 -0
- package/dist/CropImg/body/Operate.d.ts +5 -0
- package/dist/CropImg/body/index.d.ts +5 -0
- package/dist/CropImg/demos/basic.d.ts +2 -0
- package/dist/CropImg/fns/index.d.ts +14 -0
- package/dist/CropImg/index.d.ts +4 -0
- package/dist/CropImg/style/index.d.ts +1 -0
- package/dist/CropImg/style/variables.d.ts +1 -0
- package/dist/CropImg/utils.d.ts +18 -0
- package/dist/CropImg/wrapper/Container.d.ts +5 -0
- package/dist/CropImg/wrapper/Root.d.ts +3 -0
- package/dist/CropImg/wrapper/Wrapper.d.ts +5 -0
- package/dist/CropImg/wrapper/reducer.d.ts +13 -0
- package/dist/ImageViewer/wrapeer/Container.d.ts +4 -3
- package/dist/ImageViewer/wrapeer/Wrapper.d.ts +4 -3
- package/dist/LmUpload/components/Crop.d.ts +5 -0
- package/dist/LmUpload/demos/crop.d.ts +2 -0
- package/dist/LmUpload/demos/custom.d.ts +2 -0
- package/dist/LmUpload/fns/index.d.ts +2 -0
- package/dist/LmUpload/wrapper/reducer.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.umd.js +2529 -27
- package/dist/index.umd.min.js +46 -18
- package/dist/variables.css +90 -30
- package/es/CardTable/pager/TablePagination.js +1 -3
- package/es/CardTable/pager/index.js +0 -1
- package/es/CropImg/LmCropImg.d.ts +11 -0
- package/es/CropImg/LmCropImg.js +17 -0
- package/es/CropImg/body/Operate.d.ts +5 -0
- package/es/CropImg/body/Operate.js +90 -0
- package/es/CropImg/body/index.d.ts +5 -0
- package/es/CropImg/body/index.js +46 -0
- package/es/CropImg/fns/index.d.ts +14 -0
- package/es/CropImg/fns/index.js +50 -0
- package/es/CropImg/index.d.ts +4 -0
- package/es/CropImg/index.js +4 -0
- package/es/CropImg/style/index.css +17 -0
- package/es/CropImg/style/index.js +3 -0
- package/es/CropImg/style/variables.css +17 -0
- package/es/CropImg/style/variables.js +3 -0
- package/es/CropImg/utils.js +161 -0
- package/es/CropImg/wrapper/Container.d.ts +5 -0
- package/es/CropImg/wrapper/Container.js +107 -0
- package/es/CropImg/wrapper/Root.d.ts +3 -0
- package/es/CropImg/wrapper/Root.js +44 -0
- package/es/CropImg/wrapper/Wrapper.d.ts +5 -0
- package/es/CropImg/wrapper/Wrapper.js +11 -0
- package/es/CropImg/wrapper/reducer.d.ts +13 -0
- package/es/CropImg/wrapper/reducer.js +33 -0
- package/es/ImageViewer/wrapeer/Container.d.ts +4 -3
- package/es/ImageViewer/wrapeer/Container.js +1 -1
- package/es/ImageViewer/wrapeer/Wrapper.d.ts +4 -3
- package/es/ImageViewer/wrapeer/Wrapper.js +1 -1
- package/es/LmFilter/components/CheckboxFilter.js +7 -4
- package/es/LmFilter/filterFns/index.js +15 -3
- package/es/LmFilter/style/index.css +73 -30
- package/es/LmFilter/style/variables.css +73 -30
- package/es/LmTable/Table.js +3 -2
- package/es/LmUpload/LmUpload.js +1 -0
- package/es/LmUpload/components/Crop.d.ts +5 -0
- package/es/LmUpload/components/Crop.js +23 -0
- package/es/LmUpload/fns/index.d.ts +2 -0
- package/es/LmUpload/fns/index.js +90 -14
- package/es/LmUpload/wrapper/UploadWrapper.js +3 -0
- package/es/LmUpload/wrapper/reducer.d.ts +1 -0
- package/es/LmUpload/wrapper/reducer.js +9 -2
- package/es/index.d.ts +3 -0
- package/es/index.js +3 -1
- package/es/styles/variables.css +90 -30
- package/lib/CardTable/pager/TablePagination.js +1 -3
- package/lib/CardTable/pager/index.js +0 -1
- package/lib/CropImg/LmCropImg.d.ts +11 -0
- package/lib/CropImg/LmCropImg.js +31 -0
- package/lib/CropImg/body/Operate.d.ts +5 -0
- package/lib/CropImg/body/Operate.js +102 -0
- package/lib/CropImg/body/index.d.ts +5 -0
- package/lib/CropImg/body/index.js +60 -0
- package/lib/CropImg/fns/index.d.ts +14 -0
- package/lib/CropImg/fns/index.js +60 -0
- package/lib/CropImg/index.d.ts +4 -0
- package/lib/CropImg/index.js +33 -0
- package/lib/CropImg/style/index.css +17 -0
- package/lib/CropImg/style/index.js +3 -0
- package/lib/CropImg/style/variables.css +17 -0
- package/lib/CropImg/style/variables.js +3 -0
- package/lib/CropImg/utils.js +161 -0
- package/lib/CropImg/wrapper/Container.d.ts +5 -0
- package/lib/CropImg/wrapper/Container.js +124 -0
- package/lib/CropImg/wrapper/Root.d.ts +3 -0
- package/lib/CropImg/wrapper/Root.js +61 -0
- package/lib/CropImg/wrapper/Wrapper.d.ts +5 -0
- package/lib/CropImg/wrapper/Wrapper.js +23 -0
- package/lib/CropImg/wrapper/reducer.d.ts +13 -0
- package/lib/CropImg/wrapper/reducer.js +45 -0
- package/lib/ImageViewer/wrapeer/Container.d.ts +4 -3
- package/lib/ImageViewer/wrapeer/Container.js +2 -1
- package/lib/ImageViewer/wrapeer/Wrapper.d.ts +4 -3
- package/lib/ImageViewer/wrapeer/Wrapper.js +2 -1
- package/lib/LmFilter/components/CheckboxFilter.js +7 -4
- package/lib/LmFilter/filterFns/index.js +15 -3
- package/lib/LmFilter/style/index.css +73 -30
- package/lib/LmFilter/style/variables.css +73 -30
- package/lib/LmTable/Table.js +3 -2
- package/lib/LmUpload/LmUpload.js +1 -0
- package/lib/LmUpload/components/Crop.d.ts +5 -0
- package/lib/LmUpload/components/Crop.js +35 -0
- package/lib/LmUpload/fns/index.d.ts +2 -0
- package/lib/LmUpload/fns/index.js +90 -14
- package/lib/LmUpload/wrapper/UploadWrapper.js +4 -0
- package/lib/LmUpload/wrapper/reducer.d.ts +1 -0
- package/lib/LmUpload/wrapper/reducer.js +9 -2
- package/lib/index.d.ts +3 -0
- package/lib/index.js +21 -3
- package/lib/styles/variables.css +90 -30
- package/package.json +3 -1
- package/dist/LmUpload/components/card.d.ts +0 -2
- package/es/LmUpload/components/card.d.ts +0 -2
- package/es/LmUpload/components/card.js +0 -9
- package/lib/LmUpload/components/card.d.ts +0 -2
- package/lib/LmUpload/components/card.js +0 -19
package/dist/index.umd.js
CHANGED
|
@@ -90193,7 +90193,10 @@
|
|
|
90193
90193
|
return !options.some(function (v) {
|
|
90194
90194
|
return v.value === value;
|
|
90195
90195
|
});
|
|
90196
|
-
}) : uniqueFunc([].concat(_toConsumableArray$1(checkedValues), _toConsumableArray$1(options)
|
|
90196
|
+
}) : uniqueFunc([].concat(_toConsumableArray$1(checkedValues), _toConsumableArray$1(options.map(function (_ref3) {
|
|
90197
|
+
var value = _ref3.value;
|
|
90198
|
+
return value;
|
|
90199
|
+
}))), 'value');
|
|
90197
90200
|
setCheckedValues(nValue);
|
|
90198
90201
|
}; // 取消 不执行查询操作 关闭下拉框
|
|
90199
90202
|
|
|
@@ -90246,9 +90249,9 @@
|
|
|
90246
90249
|
}, /*#__PURE__*/React__default['default'].createElement(VirList, {
|
|
90247
90250
|
options: options,
|
|
90248
90251
|
className: "filter_list"
|
|
90249
|
-
}, function (
|
|
90250
|
-
var item =
|
|
90251
|
-
resetProps = _objectWithoutProperties$1(
|
|
90252
|
+
}, function (_ref4) {
|
|
90253
|
+
var item = _ref4.item,
|
|
90254
|
+
resetProps = _objectWithoutProperties$1(_ref4, _excluded$14);
|
|
90252
90255
|
|
|
90253
90256
|
return /*#__PURE__*/React__default['default'].createElement("div", _extends$2({}, resetProps, {
|
|
90254
90257
|
className: classnames('filter_item', {
|
|
@@ -93018,14 +93021,26 @@
|
|
|
93018
93021
|
filterQuery: filterQuery,
|
|
93019
93022
|
type: 'basic'
|
|
93020
93023
|
};
|
|
93021
|
-
}, [state, dataSource]);
|
|
93024
|
+
}, [state, dataSource]);
|
|
93025
|
+
/*
|
|
93026
|
+
* 设置筛选的值 itemValue => String || Array => ['', '', ...]
|
|
93027
|
+
* 后端仅接受数组包字符串形式, 不接受数值及布尔值
|
|
93028
|
+
*/
|
|
93022
93029
|
|
|
93023
93030
|
var setFilterValue = React.useCallback(function (itemValue, item) {
|
|
93024
93031
|
var field = item.field;
|
|
93025
93032
|
|
|
93026
93033
|
if (field) {
|
|
93027
93034
|
// 将结果转换为字符串
|
|
93028
|
-
var
|
|
93035
|
+
var isArray = Array.isArray(itemValue);
|
|
93036
|
+
|
|
93037
|
+
var transformString = function transformString(val) {
|
|
93038
|
+
return isArray ? val.map(function (v) {
|
|
93039
|
+
return String(v);
|
|
93040
|
+
}) : String(val);
|
|
93041
|
+
};
|
|
93042
|
+
|
|
93043
|
+
var stringValue = enableAutoString ? transformString(itemValue) : itemValue; // 基础查询数据(受控数据)
|
|
93029
93044
|
|
|
93030
93045
|
var basicFilter = _objectSpread(_objectSpread({}, state.basicFilter), {}, _defineProperty$1({}, field, stringValue)); // 外部查询数据结构
|
|
93031
93046
|
|
|
@@ -93034,7 +93049,7 @@
|
|
|
93034
93049
|
fieldName: field,
|
|
93035
93050
|
fieldType: item.valueType || 'string',
|
|
93036
93051
|
type: item.type,
|
|
93037
|
-
value:
|
|
93052
|
+
value: isArray ? stringValue : [stringValue],
|
|
93038
93053
|
operator: item.operator || 'equal'
|
|
93039
93054
|
})); // 数据清除时不返回结构体
|
|
93040
93055
|
|
|
@@ -93430,7 +93445,8 @@
|
|
|
93430
93445
|
// 状态管理操作
|
|
93431
93446
|
var reducer$1 = function reducer(state, action) {
|
|
93432
93447
|
var fileList = action.fileList,
|
|
93433
|
-
percent = action.percent
|
|
93448
|
+
percent = action.percent,
|
|
93449
|
+
cropFile = action.cropFile;
|
|
93434
93450
|
|
|
93435
93451
|
switch (action.type) {
|
|
93436
93452
|
case 'changeFileList':
|
|
@@ -93443,6 +93459,11 @@
|
|
|
93443
93459
|
percent: percent
|
|
93444
93460
|
});
|
|
93445
93461
|
|
|
93462
|
+
case 'changeCropFile':
|
|
93463
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
93464
|
+
cropFile: cropFile
|
|
93465
|
+
});
|
|
93466
|
+
|
|
93446
93467
|
default:
|
|
93447
93468
|
throw new Error();
|
|
93448
93469
|
}
|
|
@@ -93455,7 +93476,8 @@
|
|
|
93455
93476
|
upload: upload,
|
|
93456
93477
|
process: 0,
|
|
93457
93478
|
status: 'done',
|
|
93458
|
-
fileList: defaultFileList
|
|
93479
|
+
fileList: defaultFileList,
|
|
93480
|
+
cropFile: null // 需要裁剪的图片
|
|
93459
93481
|
|
|
93460
93482
|
};
|
|
93461
93483
|
};
|
|
@@ -181292,6 +181314,7 @@
|
|
|
181292
181314
|
type = props.type,
|
|
181293
181315
|
fileSize = props.fileSize,
|
|
181294
181316
|
enabledOss = props.enabledOss,
|
|
181317
|
+
enableCrop = props.enableCrop,
|
|
181295
181318
|
ossConfig = props.ossConfig; // 获取当前的文件列表
|
|
181296
181319
|
|
|
181297
181320
|
var getFileList = React.useCallback(function () {
|
|
@@ -181476,7 +181499,78 @@
|
|
|
181476
181499
|
value: getFileList(),
|
|
181477
181500
|
onChange: uploadSuccess
|
|
181478
181501
|
});
|
|
181479
|
-
}, [props.fileUpload, getFileList, uploadSuccess]); //
|
|
181502
|
+
}, [props.fileUpload, getFileList, uploadSuccess]); // 上传文件
|
|
181503
|
+
|
|
181504
|
+
var uploadFile = React.useCallback(function (file) {
|
|
181505
|
+
enabledOss && uploadOss(file);
|
|
181506
|
+
customUpload(file);
|
|
181507
|
+
}, [enabledOss, uploadOss, customUpload]); // 检测完成 file
|
|
181508
|
+
|
|
181509
|
+
var checkOver = React.useCallback( /*#__PURE__*/function () {
|
|
181510
|
+
var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(file) {
|
|
181511
|
+
var res, newFile;
|
|
181512
|
+
return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
|
|
181513
|
+
while (1) {
|
|
181514
|
+
switch (_context2.prev = _context2.next) {
|
|
181515
|
+
case 0:
|
|
181516
|
+
if (props === null || props === void 0 ? void 0 : props.beforeUpload) {
|
|
181517
|
+
_context2.next = 3;
|
|
181518
|
+
break;
|
|
181519
|
+
}
|
|
181520
|
+
|
|
181521
|
+
uploadFile(file);
|
|
181522
|
+
return _context2.abrupt("return");
|
|
181523
|
+
|
|
181524
|
+
case 3:
|
|
181525
|
+
res = props.beforeUpload(file, getFileList()); // Promise
|
|
181526
|
+
|
|
181527
|
+
if (!(res === null || res === void 0 ? void 0 : res.then)) {
|
|
181528
|
+
_context2.next = 16;
|
|
181529
|
+
break;
|
|
181530
|
+
}
|
|
181531
|
+
|
|
181532
|
+
_context2.prev = 5;
|
|
181533
|
+
_context2.next = 8;
|
|
181534
|
+
return res;
|
|
181535
|
+
|
|
181536
|
+
case 8:
|
|
181537
|
+
newFile = _context2.sent;
|
|
181538
|
+
uploadFile(newFile);
|
|
181539
|
+
_context2.next = 15;
|
|
181540
|
+
break;
|
|
181541
|
+
|
|
181542
|
+
case 12:
|
|
181543
|
+
_context2.prev = 12;
|
|
181544
|
+
_context2.t0 = _context2["catch"](5);
|
|
181545
|
+
console.log('上传失败!');
|
|
181546
|
+
|
|
181547
|
+
case 15:
|
|
181548
|
+
return _context2.abrupt("return");
|
|
181549
|
+
|
|
181550
|
+
case 16:
|
|
181551
|
+
if (res) {
|
|
181552
|
+
_context2.next = 18;
|
|
181553
|
+
break;
|
|
181554
|
+
}
|
|
181555
|
+
|
|
181556
|
+
return _context2.abrupt("return");
|
|
181557
|
+
|
|
181558
|
+
case 18:
|
|
181559
|
+
// () => true
|
|
181560
|
+
uploadFile(file);
|
|
181561
|
+
|
|
181562
|
+
case 19:
|
|
181563
|
+
case "end":
|
|
181564
|
+
return _context2.stop();
|
|
181565
|
+
}
|
|
181566
|
+
}
|
|
181567
|
+
}, _callee2, null, [[5, 12]]);
|
|
181568
|
+
}));
|
|
181569
|
+
|
|
181570
|
+
return function (_x2) {
|
|
181571
|
+
return _ref5.apply(this, arguments);
|
|
181572
|
+
};
|
|
181573
|
+
}(), [props.beforeUpload, getFileList, uploadFile]); // 上传前的检测
|
|
181480
181574
|
|
|
181481
181575
|
var beforeUpload = React.useCallback(function (e) {
|
|
181482
181576
|
var files = e.target.files; // 循环文件检查是否存在不符合要求的文件
|
|
@@ -181491,31 +181585,38 @@
|
|
|
181491
181585
|
|
|
181492
181586
|
if (item.size / 1024 / 1024 > fileSize) {
|
|
181493
181587
|
return api$2.warning("\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25\uFF01\u9644\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7".concat(fileSize, "M\uFF01"), 1.5);
|
|
181494
|
-
}
|
|
181588
|
+
} // 可剪裁时单独处理文件
|
|
181495
181589
|
|
|
181496
|
-
enabledOss && uploadOss(item); // 单个文件上传
|
|
181497
181590
|
|
|
181498
|
-
|
|
181591
|
+
if (enableCrop) {
|
|
181592
|
+
dispatch({
|
|
181593
|
+
type: 'changeCropFile',
|
|
181594
|
+
cropFile: item
|
|
181595
|
+
});
|
|
181596
|
+
} else {
|
|
181597
|
+
// 单个文件上传
|
|
181598
|
+
checkOver(item);
|
|
181599
|
+
}
|
|
181499
181600
|
}
|
|
181500
181601
|
|
|
181501
181602
|
return false;
|
|
181502
|
-
}, [type, fileSize,
|
|
181603
|
+
}, [type, fileSize, enableCrop, checkOver]); // 删除事件
|
|
181503
181604
|
|
|
181504
181605
|
var remove = React.useCallback( /*#__PURE__*/function () {
|
|
181505
|
-
var
|
|
181606
|
+
var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3(file) {
|
|
181506
181607
|
var _props$onRemove;
|
|
181507
181608
|
|
|
181508
181609
|
var res, _getFileList, fileList;
|
|
181509
181610
|
|
|
181510
|
-
return _regeneratorRuntime$1().wrap(function
|
|
181611
|
+
return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
|
|
181511
181612
|
while (1) {
|
|
181512
|
-
switch (
|
|
181613
|
+
switch (_context3.prev = _context3.next) {
|
|
181513
181614
|
case 0:
|
|
181514
|
-
|
|
181615
|
+
_context3.next = 2;
|
|
181515
181616
|
return (_props$onRemove = props.onRemove) === null || _props$onRemove === void 0 ? void 0 : _props$onRemove.call(props, file);
|
|
181516
181617
|
|
|
181517
181618
|
case 2:
|
|
181518
|
-
res =
|
|
181619
|
+
res = _context3.sent;
|
|
181519
181620
|
|
|
181520
181621
|
if (res) {
|
|
181521
181622
|
fileList = (_getFileList = getFileList()) === null || _getFileList === void 0 ? void 0 : _getFileList.filter(function (v) {
|
|
@@ -181533,14 +181634,14 @@
|
|
|
181533
181634
|
|
|
181534
181635
|
case 4:
|
|
181535
181636
|
case "end":
|
|
181536
|
-
return
|
|
181637
|
+
return _context3.stop();
|
|
181537
181638
|
}
|
|
181538
181639
|
}
|
|
181539
|
-
},
|
|
181640
|
+
}, _callee3);
|
|
181540
181641
|
}));
|
|
181541
181642
|
|
|
181542
|
-
return function (
|
|
181543
|
-
return
|
|
181643
|
+
return function (_x3) {
|
|
181644
|
+
return _ref6.apply(this, arguments);
|
|
181544
181645
|
};
|
|
181545
181646
|
}(), [props.onRemove, getFileList, onChange, dispatch, uid]); // 点击文件链接或预览图标时的回调
|
|
181546
181647
|
|
|
@@ -181559,6 +181660,7 @@
|
|
|
181559
181660
|
getIsMaxCount: getIsMaxCount,
|
|
181560
181661
|
getFileFields: getFileFields,
|
|
181561
181662
|
beforeUpload: beforeUpload,
|
|
181663
|
+
checkOver: checkOver,
|
|
181562
181664
|
getUploadStatus: getUploadStatus,
|
|
181563
181665
|
remove: remove,
|
|
181564
181666
|
preview: preview,
|
|
@@ -181568,8 +181670,8 @@
|
|
|
181568
181670
|
getState: function getState() {
|
|
181569
181671
|
return state;
|
|
181570
181672
|
},
|
|
181571
|
-
getFileList: getFileList
|
|
181572
|
-
|
|
181673
|
+
getFileList: getFileList,
|
|
181674
|
+
uploadFile: uploadFile
|
|
181573
181675
|
};
|
|
181574
181676
|
return {
|
|
181575
181677
|
CoreMethods: CoreMethods,
|
|
@@ -181986,6 +182088,29 @@
|
|
|
181986
182088
|
});
|
|
181987
182089
|
};
|
|
181988
182090
|
|
|
182091
|
+
var Crop = function Crop(_ref) {
|
|
182092
|
+
var instance = _ref.instance;
|
|
182093
|
+
var enableCrop = instance.enableCrop,
|
|
182094
|
+
state = instance.state,
|
|
182095
|
+
cropConfig = instance.cropConfig,
|
|
182096
|
+
checkOver = instance.checkOver;
|
|
182097
|
+
if (!enableCrop) return null;
|
|
182098
|
+
|
|
182099
|
+
var config = _objectSpread(_objectSpread({}, cropConfig), {}, {
|
|
182100
|
+
file: state.cropFile,
|
|
182101
|
+
onClose: function onClose(blob, oldFile) {
|
|
182102
|
+
var newFile = new File([blob], oldFile.name, {
|
|
182103
|
+
type: oldFile.type
|
|
182104
|
+
});
|
|
182105
|
+
checkOver(newFile);
|
|
182106
|
+
}
|
|
182107
|
+
});
|
|
182108
|
+
|
|
182109
|
+
return /*#__PURE__*/React__default['default'].createElement(CropImg, _objectSpread({}, config));
|
|
182110
|
+
};
|
|
182111
|
+
|
|
182112
|
+
var Crop$1 = /*#__PURE__*/React__default['default'].memo(Crop);
|
|
182113
|
+
|
|
181989
182114
|
// 包裹上传组件区域: 拓展其他结构
|
|
181990
182115
|
|
|
181991
182116
|
var LmUploadWrapper = function LmUploadWrapper(_ref) {
|
|
@@ -181996,6 +182121,8 @@
|
|
|
181996
182121
|
instance: instance
|
|
181997
182122
|
}), /*#__PURE__*/React__default['default'].createElement(LmUploadView, {
|
|
181998
182123
|
instance: instance
|
|
182124
|
+
}), /*#__PURE__*/React__default['default'].createElement(Crop$1, {
|
|
182125
|
+
instance: instance
|
|
181999
182126
|
}));
|
|
182000
182127
|
};
|
|
182001
182128
|
|
|
@@ -182112,6 +182239,7 @@
|
|
|
182112
182239
|
maxCount: null,
|
|
182113
182240
|
children: null,
|
|
182114
182241
|
itemRender: null,
|
|
182242
|
+
enabledCrop: false,
|
|
182115
182243
|
enabledOss: false,
|
|
182116
182244
|
// oss配置
|
|
182117
182245
|
ossConfig: function ossConfig() {
|
|
@@ -184524,6 +184652,7 @@
|
|
|
184524
184652
|
if (!left) {
|
|
184525
184653
|
return /*#__PURE__*/React__default['default'].createElement("div", null);
|
|
184526
184654
|
}
|
|
184655
|
+
|
|
184527
184656
|
return typeof left === 'function' ? left(table) : left;
|
|
184528
184657
|
}; // 底部工具栏右侧插槽
|
|
184529
184658
|
|
|
@@ -286554,8 +286683,9 @@
|
|
|
286554
286683
|
}
|
|
286555
286684
|
|
|
286556
286685
|
var resetHeight = React.useMemo(function () {
|
|
286557
|
-
var height = tableSize.height;
|
|
286558
|
-
|
|
286686
|
+
var height = tableSize.height; // 头部高度
|
|
286687
|
+
|
|
286688
|
+
var h = height - (props.size === 'middle' ? 47 : 40);
|
|
286559
286689
|
|
|
286560
286690
|
if (!props.hiddenPage || props.customCheck) {
|
|
286561
286691
|
h -= 48;
|
|
@@ -320687,6 +320817,2376 @@
|
|
|
320687
320817
|
}, children), document.body) : children;
|
|
320688
320818
|
};
|
|
320689
320819
|
|
|
320820
|
+
// 初始化状态值
|
|
320821
|
+
var defaultState = {
|
|
320822
|
+
// 容器盒子大小
|
|
320823
|
+
resize: {
|
|
320824
|
+
width: 0,
|
|
320825
|
+
height: 0
|
|
320826
|
+
},
|
|
320827
|
+
currentIndex: 0,
|
|
320828
|
+
currentUrl: '',
|
|
320829
|
+
// 当前选中的图片变换
|
|
320830
|
+
transform: {
|
|
320831
|
+
scale: 1,
|
|
320832
|
+
rotateZ: 0 // Z轴旋转方向
|
|
320833
|
+
|
|
320834
|
+
}
|
|
320835
|
+
}; // 状态管理操作
|
|
320836
|
+
|
|
320837
|
+
var reducer$5 = function reducer(state, action) {
|
|
320838
|
+
var resize = action.resize,
|
|
320839
|
+
transform = action.transform,
|
|
320840
|
+
current = action.current;
|
|
320841
|
+
|
|
320842
|
+
switch (action.type) {
|
|
320843
|
+
case 'changeResize':
|
|
320844
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
320845
|
+
resize: resize
|
|
320846
|
+
});
|
|
320847
|
+
|
|
320848
|
+
case 'changeTransform':
|
|
320849
|
+
// 改变转换
|
|
320850
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
320851
|
+
transform: _objectSpread(_objectSpread({}, state.transform), transform)
|
|
320852
|
+
});
|
|
320853
|
+
|
|
320854
|
+
case 'changeCurrent':
|
|
320855
|
+
// 改变当前选中的图片
|
|
320856
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), current), {}, {
|
|
320857
|
+
transform: defaultState.transform
|
|
320858
|
+
});
|
|
320859
|
+
|
|
320860
|
+
default:
|
|
320861
|
+
throw new Error();
|
|
320862
|
+
}
|
|
320863
|
+
}; // 仅在初始化时触发一次
|
|
320864
|
+
|
|
320865
|
+
var initialState$3 = function initialState(props) {
|
|
320866
|
+
var initialIndex = props.initialIndex;
|
|
320867
|
+
return _objectSpread(_objectSpread({}, defaultState), {}, {
|
|
320868
|
+
currentIndex: initialIndex
|
|
320869
|
+
});
|
|
320870
|
+
};
|
|
320871
|
+
|
|
320872
|
+
var useCoreOptions$2 = function useCoreOptions(_ref) {
|
|
320873
|
+
var state = _ref.state,
|
|
320874
|
+
dispatch = _ref.dispatch,
|
|
320875
|
+
props = _ref.props,
|
|
320876
|
+
bodyRef = _ref.bodyRef;
|
|
320877
|
+
// 获取是否为视频格式
|
|
320878
|
+
var getIsVideo = React.useCallback(function (url) {
|
|
320879
|
+
var fileExtension = url.replace(/.*\./, '').toLowerCase();
|
|
320880
|
+
return ['mp4', 'm2v', 'mkv', 'ogm', 'webm'].includes(fileExtension);
|
|
320881
|
+
}, []);
|
|
320882
|
+
var setTransform = React.useCallback(function (type) {
|
|
320883
|
+
var scale = state.transform.scale * 100;
|
|
320884
|
+
var rotateZ = state.transform.rotateZ;
|
|
320885
|
+
|
|
320886
|
+
switch (type) {
|
|
320887
|
+
case 'zoomIn':
|
|
320888
|
+
scale += 25;
|
|
320889
|
+
break;
|
|
320890
|
+
|
|
320891
|
+
case 'zoomOut':
|
|
320892
|
+
scale < 30 ? scale : scale -= 25;
|
|
320893
|
+
break;
|
|
320894
|
+
|
|
320895
|
+
case 'rotateLeft':
|
|
320896
|
+
rotateZ -= 90;
|
|
320897
|
+
break;
|
|
320898
|
+
|
|
320899
|
+
case 'rotateRight':
|
|
320900
|
+
rotateZ += 90;
|
|
320901
|
+
break;
|
|
320902
|
+
}
|
|
320903
|
+
|
|
320904
|
+
dispatch({
|
|
320905
|
+
type: 'changeTransform',
|
|
320906
|
+
transform: {
|
|
320907
|
+
rotateZ: rotateZ,
|
|
320908
|
+
scale: scale / 100
|
|
320909
|
+
}
|
|
320910
|
+
});
|
|
320911
|
+
}, [state.transform]); // 切换轮播前的回调
|
|
320912
|
+
|
|
320913
|
+
var beforeChange = React.useCallback(function (from, currentIndex) {
|
|
320914
|
+
dispatch({
|
|
320915
|
+
type: 'changeCurrent',
|
|
320916
|
+
current: {
|
|
320917
|
+
currentIndex: currentIndex
|
|
320918
|
+
}
|
|
320919
|
+
});
|
|
320920
|
+
}, []); // 切换轮播后的回调
|
|
320921
|
+
|
|
320922
|
+
var afterChange = React.useCallback(function (currentIndex) {
|
|
320923
|
+
dispatch({
|
|
320924
|
+
type: 'changeCurrent',
|
|
320925
|
+
current: {
|
|
320926
|
+
currentIndex: currentIndex
|
|
320927
|
+
}
|
|
320928
|
+
});
|
|
320929
|
+
}, []); // 转到指定的轮播图, 直接跳转, 不展示动画
|
|
320930
|
+
|
|
320931
|
+
var slickGoTo = React.useCallback(function (currentIndex) {
|
|
320932
|
+
bodyRef.current.goTo(currentIndex, true);
|
|
320933
|
+
}, []); // 转到下一张轮播图
|
|
320934
|
+
|
|
320935
|
+
var slickNext = React.useCallback(function () {
|
|
320936
|
+
bodyRef.current.next();
|
|
320937
|
+
}, []); // 转到上一张轮播图
|
|
320938
|
+
|
|
320939
|
+
var slickPrev = React.useCallback(function () {
|
|
320940
|
+
bodyRef.current.prev();
|
|
320941
|
+
}, []); // 初始化图片索引
|
|
320942
|
+
|
|
320943
|
+
React.useEffect(function () {
|
|
320944
|
+
slickGoTo(props.initialIndex);
|
|
320945
|
+
dispatch({
|
|
320946
|
+
type: 'changeCurrent',
|
|
320947
|
+
current: {
|
|
320948
|
+
currentIndex: props.initialIndex
|
|
320949
|
+
}
|
|
320950
|
+
});
|
|
320951
|
+
}, [slickGoTo]);
|
|
320952
|
+
var CoreMethods = {
|
|
320953
|
+
getIsVideo: getIsVideo,
|
|
320954
|
+
setTransform: setTransform,
|
|
320955
|
+
beforeChange: beforeChange,
|
|
320956
|
+
afterChange: afterChange
|
|
320957
|
+
};
|
|
320958
|
+
var RefMethods = {
|
|
320959
|
+
getState: function getState() {
|
|
320960
|
+
return state;
|
|
320961
|
+
},
|
|
320962
|
+
slickGoTo: slickGoTo,
|
|
320963
|
+
slickNext: slickNext,
|
|
320964
|
+
slickPrev: slickPrev
|
|
320965
|
+
};
|
|
320966
|
+
return {
|
|
320967
|
+
CoreMethods: CoreMethods,
|
|
320968
|
+
RefMethods: RefMethods
|
|
320969
|
+
};
|
|
320970
|
+
};
|
|
320971
|
+
|
|
320972
|
+
var BannerItem = /*#__PURE__*/React__default['default'].memo(function (_ref) {
|
|
320973
|
+
var key = _ref.key,
|
|
320974
|
+
index = _ref.index,
|
|
320975
|
+
item = _ref.item,
|
|
320976
|
+
instance = _ref.instance;
|
|
320977
|
+
var state = instance.state,
|
|
320978
|
+
getIsVideo = instance.getIsVideo;
|
|
320979
|
+
var transformProps = React.useMemo(function () {
|
|
320980
|
+
if (index !== state.currentIndex) return {};
|
|
320981
|
+
var _state$transform = state.transform,
|
|
320982
|
+
scale = _state$transform.scale,
|
|
320983
|
+
rotateZ = _state$transform.rotateZ;
|
|
320984
|
+
return {
|
|
320985
|
+
transform: "scale(".concat(scale, ") rotateZ(").concat(rotateZ, "deg)")
|
|
320986
|
+
};
|
|
320987
|
+
}, [state.currentIndex, state.transform]); // useEffect(() => {
|
|
320988
|
+
// // 1. 创建 IntersectionObserver对象
|
|
320989
|
+
// const ob = new IntersectionObserver(
|
|
320990
|
+
// (entry) => {
|
|
320991
|
+
// console.log('可见', entry[0].isIntersecting)
|
|
320992
|
+
// if (entry[0].isIntersecting) {
|
|
320993
|
+
// // 图片可见
|
|
320994
|
+
// if (imgRef.current) {
|
|
320995
|
+
// console.log('赋值src')
|
|
320996
|
+
// imgRef.current.src = item
|
|
320997
|
+
// setLoading(true)
|
|
320998
|
+
// }
|
|
320999
|
+
// ob.unobserve(imgRef.current!)
|
|
321000
|
+
// }
|
|
321001
|
+
// },
|
|
321002
|
+
// {
|
|
321003
|
+
// root: document.querySelector('.lm_imglist_banner'),
|
|
321004
|
+
// },
|
|
321005
|
+
// )
|
|
321006
|
+
// if (imgRef.current) {
|
|
321007
|
+
// // 2. 观察img
|
|
321008
|
+
// ob.observe(imgRef.current!)
|
|
321009
|
+
// return () => {
|
|
321010
|
+
// ob.disconnect()
|
|
321011
|
+
// }
|
|
321012
|
+
// }
|
|
321013
|
+
// }, [])
|
|
321014
|
+
|
|
321015
|
+
var renderView = React.useMemo(function () {
|
|
321016
|
+
if (getIsVideo(item)) {
|
|
321017
|
+
return (
|
|
321018
|
+
/*#__PURE__*/
|
|
321019
|
+
// @ts-ignore
|
|
321020
|
+
React__default['default'].createElement("video", {
|
|
321021
|
+
width: "100%",
|
|
321022
|
+
height: "100%",
|
|
321023
|
+
controls: "controls"
|
|
321024
|
+
}, /*#__PURE__*/React__default['default'].createElement("source", {
|
|
321025
|
+
src: item,
|
|
321026
|
+
type: "video/mp4"
|
|
321027
|
+
}), /*#__PURE__*/React__default['default'].createElement("source", {
|
|
321028
|
+
src: item,
|
|
321029
|
+
type: "video/webm"
|
|
321030
|
+
}), /*#__PURE__*/React__default['default'].createElement("source", {
|
|
321031
|
+
src: item,
|
|
321032
|
+
type: "video/ogg"
|
|
321033
|
+
}), "\u89C6\u9891\u64AD\u653E\u5931\u8D25\uFF01")
|
|
321034
|
+
);
|
|
321035
|
+
}
|
|
321036
|
+
|
|
321037
|
+
return /*#__PURE__*/React__default['default'].createElement("img", {
|
|
321038
|
+
loading: "lazy",
|
|
321039
|
+
alt: "",
|
|
321040
|
+
src: item,
|
|
321041
|
+
style: transformProps
|
|
321042
|
+
});
|
|
321043
|
+
}, [getIsVideo, item, transformProps]);
|
|
321044
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
321045
|
+
className: "banner_item"
|
|
321046
|
+
}, renderView);
|
|
321047
|
+
});
|
|
321048
|
+
|
|
321049
|
+
var BigImg = function BigImg(_ref2) {
|
|
321050
|
+
var instance = _ref2.instance;
|
|
321051
|
+
var dataSource = instance.dataSource,
|
|
321052
|
+
bodyRef = instance.bodyRef,
|
|
321053
|
+
enableWheel = instance.enableWheel,
|
|
321054
|
+
infinite = instance.infinite,
|
|
321055
|
+
setTransform = instance.setTransform,
|
|
321056
|
+
beforeChange = instance.beforeChange;
|
|
321057
|
+
var onWheel = React.useCallback(function (e) {
|
|
321058
|
+
if (!enableWheel) return;
|
|
321059
|
+
|
|
321060
|
+
if ((e === null || e === void 0 ? void 0 : e.deltaY) <= 0) {
|
|
321061
|
+
setTransform('zoomIn');
|
|
321062
|
+
} else {
|
|
321063
|
+
setTransform('zoomOut');
|
|
321064
|
+
}
|
|
321065
|
+
}, [enableWheel, setTransform]);
|
|
321066
|
+
var config = {
|
|
321067
|
+
dots: false,
|
|
321068
|
+
infinite: infinite,
|
|
321069
|
+
adaptiveHeight: false,
|
|
321070
|
+
beforeChange: beforeChange
|
|
321071
|
+
};
|
|
321072
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
321073
|
+
className: "lm_imglist_banner",
|
|
321074
|
+
onClick: function onClick(e) {
|
|
321075
|
+
return e.stopPropagation();
|
|
321076
|
+
},
|
|
321077
|
+
onWheel: onWheel
|
|
321078
|
+
}, /*#__PURE__*/React__default['default'].createElement(Carousel, _objectSpread({
|
|
321079
|
+
ref: bodyRef
|
|
321080
|
+
}, config), dataSource.map(function (v, idx) {
|
|
321081
|
+
return /*#__PURE__*/React__default['default'].createElement(BannerItem, {
|
|
321082
|
+
key: v || idx,
|
|
321083
|
+
index: idx,
|
|
321084
|
+
item: v,
|
|
321085
|
+
instance: instance
|
|
321086
|
+
});
|
|
321087
|
+
})));
|
|
321088
|
+
};
|
|
321089
|
+
|
|
321090
|
+
var Banner = /*#__PURE__*/React__default['default'].memo(BigImg);
|
|
321091
|
+
|
|
321092
|
+
var ThumbItem = /*#__PURE__*/React__default['default'].memo(function (_ref) {
|
|
321093
|
+
var index = _ref.index,
|
|
321094
|
+
item = _ref.item,
|
|
321095
|
+
instance = _ref.instance;
|
|
321096
|
+
var state = instance.state,
|
|
321097
|
+
slickGoTo = instance.slickGoTo,
|
|
321098
|
+
getIsVideo = instance.getIsVideo;
|
|
321099
|
+
|
|
321100
|
+
var handleGoTo = function handleGoTo(e, number) {
|
|
321101
|
+
e.preventDefault();
|
|
321102
|
+
slickGoTo(number);
|
|
321103
|
+
};
|
|
321104
|
+
|
|
321105
|
+
var renderView = React.useMemo(function () {
|
|
321106
|
+
if (getIsVideo(item)) {
|
|
321107
|
+
return /*#__PURE__*/React__default['default'].createElement(IconFont, {
|
|
321108
|
+
type: "lmweb-video",
|
|
321109
|
+
className: "thumb_item_icon"
|
|
321110
|
+
});
|
|
321111
|
+
}
|
|
321112
|
+
|
|
321113
|
+
return /*#__PURE__*/React__default['default'].createElement("img", {
|
|
321114
|
+
loading: "lazy",
|
|
321115
|
+
src: item,
|
|
321116
|
+
alt: ""
|
|
321117
|
+
});
|
|
321118
|
+
}, [getIsVideo, item]);
|
|
321119
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
321120
|
+
className: classnames('thumb_item', state.currentIndex === index && 'active'),
|
|
321121
|
+
onClick: function onClick(e) {
|
|
321122
|
+
return handleGoTo(e, index);
|
|
321123
|
+
}
|
|
321124
|
+
}, renderView);
|
|
321125
|
+
});
|
|
321126
|
+
|
|
321127
|
+
var Thumb = function Thumb(_ref2) {
|
|
321128
|
+
var instance = _ref2.instance;
|
|
321129
|
+
var dataSource = instance.dataSource;
|
|
321130
|
+
var thumbProps = React.useMemo(function () {
|
|
321131
|
+
return {
|
|
321132
|
+
gridTemplateColumns: "repeat(".concat(dataSource.length, ", 90px)")
|
|
321133
|
+
};
|
|
321134
|
+
}, [dataSource.length]);
|
|
321135
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
321136
|
+
className: "lm_imglist_thumb",
|
|
321137
|
+
style: thumbProps,
|
|
321138
|
+
onClick: function onClick(e) {
|
|
321139
|
+
return e.stopPropagation();
|
|
321140
|
+
}
|
|
321141
|
+
}, dataSource.map(function (v, idx) {
|
|
321142
|
+
return /*#__PURE__*/React__default['default'].createElement(ThumbItem, {
|
|
321143
|
+
key: v || idx,
|
|
321144
|
+
index: idx,
|
|
321145
|
+
item: v,
|
|
321146
|
+
instance: instance
|
|
321147
|
+
});
|
|
321148
|
+
}));
|
|
321149
|
+
};
|
|
321150
|
+
|
|
321151
|
+
var Thumb$1 = /*#__PURE__*/React__default['default'].memo(Thumb);
|
|
321152
|
+
|
|
321153
|
+
var useIsomorphicLayoutEffect$h = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
321154
|
+
var Container$1 = /*#__PURE__*/React__default['default'].memo(function (_ref) {
|
|
321155
|
+
var instance = _ref.instance;
|
|
321156
|
+
var dispatch = instance.dispatch,
|
|
321157
|
+
height = instance.height;
|
|
321158
|
+
var boxContainerRef = React.useRef(null); // 获取盒子容器的大小
|
|
321159
|
+
|
|
321160
|
+
/** TODO: 没设默认值会导致打包失败 */
|
|
321161
|
+
|
|
321162
|
+
var getResize = React.useCallback(function () {
|
|
321163
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
321164
|
+
_ref2$blockSize = _ref2.blockSize,
|
|
321165
|
+
blockSize = _ref2$blockSize === void 0 ? 0 : _ref2$blockSize,
|
|
321166
|
+
_ref2$inlineSize = _ref2.inlineSize,
|
|
321167
|
+
inlineSize = _ref2$inlineSize === void 0 ? 0 : _ref2$inlineSize;
|
|
321168
|
+
|
|
321169
|
+
dispatch({
|
|
321170
|
+
type: 'changeResize',
|
|
321171
|
+
resize: {
|
|
321172
|
+
width: inlineSize,
|
|
321173
|
+
height: blockSize
|
|
321174
|
+
}
|
|
321175
|
+
});
|
|
321176
|
+
}, []); // 获取表格高度
|
|
321177
|
+
|
|
321178
|
+
useIsomorphicLayoutEffect$h(function () {
|
|
321179
|
+
// 频繁变动可考虑增加防抖
|
|
321180
|
+
var resizeObserver = new ResizeObserver(function (entries) {
|
|
321181
|
+
var borderbox = entries[0].borderBoxSize[0];
|
|
321182
|
+
getResize(borderbox);
|
|
321183
|
+
});
|
|
321184
|
+
|
|
321185
|
+
if (boxContainerRef.current) {
|
|
321186
|
+
resizeObserver.observe(boxContainerRef.current);
|
|
321187
|
+
}
|
|
321188
|
+
|
|
321189
|
+
return function () {
|
|
321190
|
+
return resizeObserver.disconnect();
|
|
321191
|
+
};
|
|
321192
|
+
}, [getResize]);
|
|
321193
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
321194
|
+
ref: boxContainerRef,
|
|
321195
|
+
className: "lm_imglist_container",
|
|
321196
|
+
style: {
|
|
321197
|
+
height: height
|
|
321198
|
+
}
|
|
321199
|
+
}, /*#__PURE__*/React__default['default'].createElement(Banner, {
|
|
321200
|
+
instance: instance
|
|
321201
|
+
}), /*#__PURE__*/React__default['default'].createElement(Thumb$1, {
|
|
321202
|
+
instance: instance
|
|
321203
|
+
}));
|
|
321204
|
+
});
|
|
321205
|
+
|
|
321206
|
+
var LmBoxWrapper = /*#__PURE__*/React__default['default'].memo(function (_ref) {
|
|
321207
|
+
var instance = _ref.instance;
|
|
321208
|
+
return /*#__PURE__*/React__default['default'].createElement(Container$1, {
|
|
321209
|
+
instance: instance
|
|
321210
|
+
});
|
|
321211
|
+
});
|
|
321212
|
+
|
|
321213
|
+
var Root = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
321214
|
+
var bodyRef = React.useRef(null);
|
|
321215
|
+
var initialState = React.useMemo(function () {
|
|
321216
|
+
return initialState$3(props);
|
|
321217
|
+
}, []);
|
|
321218
|
+
|
|
321219
|
+
var _useReducer = React.useReducer(reducer$5, initialState),
|
|
321220
|
+
_useReducer2 = _slicedToArray$1(_useReducer, 2),
|
|
321221
|
+
state = _useReducer2[0],
|
|
321222
|
+
dispatch = _useReducer2[1]; // 获取核心Methods
|
|
321223
|
+
|
|
321224
|
+
|
|
321225
|
+
var _useCoreOptions = useCoreOptions$2({
|
|
321226
|
+
state: state,
|
|
321227
|
+
dispatch: dispatch,
|
|
321228
|
+
props: props,
|
|
321229
|
+
bodyRef: bodyRef
|
|
321230
|
+
}),
|
|
321231
|
+
CoreMethods = _useCoreOptions.CoreMethods,
|
|
321232
|
+
RefMethods = _useCoreOptions.RefMethods;
|
|
321233
|
+
|
|
321234
|
+
var instance = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props), CoreMethods), RefMethods), {}, {
|
|
321235
|
+
bodyRef: bodyRef,
|
|
321236
|
+
state: state,
|
|
321237
|
+
dispatch: dispatch
|
|
321238
|
+
}); // 向外暴露出的方法
|
|
321239
|
+
|
|
321240
|
+
|
|
321241
|
+
React.useImperativeHandle(ref, function () {
|
|
321242
|
+
return _objectSpread(_objectSpread({}, RefMethods), {}, {
|
|
321243
|
+
getState: function getState() {
|
|
321244
|
+
return state;
|
|
321245
|
+
}
|
|
321246
|
+
});
|
|
321247
|
+
});
|
|
321248
|
+
return /*#__PURE__*/React__default['default'].createElement(LmBoxWrapper, {
|
|
321249
|
+
instance: instance
|
|
321250
|
+
});
|
|
321251
|
+
});
|
|
321252
|
+
|
|
321253
|
+
var LmImgList = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
321254
|
+
var defaultRef = React.useRef(null);
|
|
321255
|
+
|
|
321256
|
+
var defaultProps = _objectSpread({
|
|
321257
|
+
type: 'default',
|
|
321258
|
+
height: null,
|
|
321259
|
+
dataSource: [],
|
|
321260
|
+
initialIndex: 1,
|
|
321261
|
+
infinite: false,
|
|
321262
|
+
enableWheel: false,
|
|
321263
|
+
enableScale: false,
|
|
321264
|
+
enableRotate: false
|
|
321265
|
+
}, props);
|
|
321266
|
+
|
|
321267
|
+
return /*#__PURE__*/React__default['default'].createElement(Root, _objectSpread({
|
|
321268
|
+
ref: ref || defaultRef
|
|
321269
|
+
}, defaultProps));
|
|
321270
|
+
});
|
|
321271
|
+
|
|
321272
|
+
var defaultState$1 = {
|
|
321273
|
+
visible: false,
|
|
321274
|
+
zoom: 1,
|
|
321275
|
+
rotation: 0,
|
|
321276
|
+
crop: {
|
|
321277
|
+
x: 0,
|
|
321278
|
+
y: 0
|
|
321279
|
+
},
|
|
321280
|
+
croppedAreaPixels: null,
|
|
321281
|
+
croppedImage: null // 裁剪后的图片File
|
|
321282
|
+
|
|
321283
|
+
}; // 状态管理操作
|
|
321284
|
+
|
|
321285
|
+
var reducer$6 = function reducer(state, action) {
|
|
321286
|
+
var result = action.result,
|
|
321287
|
+
init = action.init;
|
|
321288
|
+
|
|
321289
|
+
switch (action.type) {
|
|
321290
|
+
case 'changeInit':
|
|
321291
|
+
return _objectSpread(_objectSpread(_objectSpread({}, state), defaultState$1), init);
|
|
321292
|
+
|
|
321293
|
+
case 'changeResult':
|
|
321294
|
+
return _objectSpread(_objectSpread({}, state), result);
|
|
321295
|
+
|
|
321296
|
+
default:
|
|
321297
|
+
throw new Error();
|
|
321298
|
+
}
|
|
321299
|
+
}; // 仅在初始化时触发一次
|
|
321300
|
+
|
|
321301
|
+
var initialState$4 = function initialState() {
|
|
321302
|
+
return _objectSpread({}, defaultState$1);
|
|
321303
|
+
};
|
|
321304
|
+
|
|
321305
|
+
var createImage = function createImage(url) {
|
|
321306
|
+
return new Promise(function (resolve, reject) {
|
|
321307
|
+
var image = new Image();
|
|
321308
|
+
image.addEventListener('load', function () {
|
|
321309
|
+
return resolve(image);
|
|
321310
|
+
});
|
|
321311
|
+
image.addEventListener('error', function (error) {
|
|
321312
|
+
return reject(error);
|
|
321313
|
+
});
|
|
321314
|
+
image.setAttribute('crossOrigin', 'anonymous'); // needed to avoid cross-origin issues on CodeSandbox
|
|
321315
|
+
|
|
321316
|
+
image.src = url;
|
|
321317
|
+
});
|
|
321318
|
+
};
|
|
321319
|
+
function getRadianAngle(degreeValue) {
|
|
321320
|
+
return degreeValue * Math.PI / 180;
|
|
321321
|
+
}
|
|
321322
|
+
/**
|
|
321323
|
+
* Returns the new bounding area of a rotated rectangle.
|
|
321324
|
+
*/
|
|
321325
|
+
|
|
321326
|
+
function rotateSize(width, height, rotation) {
|
|
321327
|
+
var rotRad = getRadianAngle(rotation);
|
|
321328
|
+
return {
|
|
321329
|
+
width: Math.abs(Math.cos(rotRad) * width) + Math.abs(Math.sin(rotRad) * height),
|
|
321330
|
+
height: Math.abs(Math.sin(rotRad) * width) + Math.abs(Math.cos(rotRad) * height)
|
|
321331
|
+
};
|
|
321332
|
+
}
|
|
321333
|
+
/**
|
|
321334
|
+
* This function was adapted from the one in the ReadMe of https://github.com/DominicTobias/react-image-crop
|
|
321335
|
+
*/
|
|
321336
|
+
|
|
321337
|
+
function getCroppedImg(_x, _x2) {
|
|
321338
|
+
return _getCroppedImg.apply(this, arguments);
|
|
321339
|
+
}
|
|
321340
|
+
|
|
321341
|
+
function _getCroppedImg() {
|
|
321342
|
+
_getCroppedImg = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(imageSrc, pixelCrop) {
|
|
321343
|
+
var rotation,
|
|
321344
|
+
flip,
|
|
321345
|
+
image,
|
|
321346
|
+
canvas,
|
|
321347
|
+
ctx,
|
|
321348
|
+
rotRad,
|
|
321349
|
+
_rotateSize,
|
|
321350
|
+
bBoxWidth,
|
|
321351
|
+
bBoxHeight,
|
|
321352
|
+
data,
|
|
321353
|
+
_args = arguments;
|
|
321354
|
+
|
|
321355
|
+
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
321356
|
+
while (1) {
|
|
321357
|
+
switch (_context.prev = _context.next) {
|
|
321358
|
+
case 0:
|
|
321359
|
+
rotation = _args.length > 2 && _args[2] !== undefined ? _args[2] : 0;
|
|
321360
|
+
flip = _args.length > 3 && _args[3] !== undefined ? _args[3] : {
|
|
321361
|
+
horizontal: false,
|
|
321362
|
+
vertical: false
|
|
321363
|
+
};
|
|
321364
|
+
_context.next = 4;
|
|
321365
|
+
return createImage(imageSrc);
|
|
321366
|
+
|
|
321367
|
+
case 4:
|
|
321368
|
+
image = _context.sent;
|
|
321369
|
+
canvas = document.createElement('canvas');
|
|
321370
|
+
ctx = canvas.getContext('2d');
|
|
321371
|
+
|
|
321372
|
+
if (ctx) {
|
|
321373
|
+
_context.next = 9;
|
|
321374
|
+
break;
|
|
321375
|
+
}
|
|
321376
|
+
|
|
321377
|
+
return _context.abrupt("return", null);
|
|
321378
|
+
|
|
321379
|
+
case 9:
|
|
321380
|
+
rotRad = getRadianAngle(rotation); // calculate bounding box of the rotated image
|
|
321381
|
+
|
|
321382
|
+
_rotateSize = rotateSize(image.width, image.height, rotation), bBoxWidth = _rotateSize.width, bBoxHeight = _rotateSize.height; // set canvas size to match the bounding box
|
|
321383
|
+
|
|
321384
|
+
canvas.width = bBoxWidth;
|
|
321385
|
+
canvas.height = bBoxHeight; // translate canvas context to a central location to allow rotating and flipping around the center
|
|
321386
|
+
|
|
321387
|
+
ctx.translate(bBoxWidth / 2, bBoxHeight / 2);
|
|
321388
|
+
ctx.rotate(rotRad);
|
|
321389
|
+
ctx.scale(flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1);
|
|
321390
|
+
ctx.translate(-image.width / 2, -image.height / 2); // draw rotated image
|
|
321391
|
+
|
|
321392
|
+
ctx.drawImage(image, 0, 0); // croppedAreaPixels values are bounding box relative
|
|
321393
|
+
// extract the cropped image using these values
|
|
321394
|
+
|
|
321395
|
+
data = ctx.getImageData(pixelCrop.x, pixelCrop.y, pixelCrop.width, pixelCrop.height); // set canvas width to final desired crop size - this will clear existing context
|
|
321396
|
+
|
|
321397
|
+
canvas.width = pixelCrop.width;
|
|
321398
|
+
canvas.height = pixelCrop.height; // paste generated rotate image at the top left corner
|
|
321399
|
+
|
|
321400
|
+
ctx.putImageData(data, 0, 0); // As Base64 string
|
|
321401
|
+
// return canvas.toDataURL('image/jpeg');
|
|
321402
|
+
// As a blob
|
|
321403
|
+
|
|
321404
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
321405
|
+
canvas.toBlob(function (file) {
|
|
321406
|
+
// resolve(URL.createObjectURL(file))
|
|
321407
|
+
resolve(file);
|
|
321408
|
+
}, 'image/jpeg');
|
|
321409
|
+
}));
|
|
321410
|
+
|
|
321411
|
+
case 23:
|
|
321412
|
+
case "end":
|
|
321413
|
+
return _context.stop();
|
|
321414
|
+
}
|
|
321415
|
+
}
|
|
321416
|
+
}, _callee);
|
|
321417
|
+
}));
|
|
321418
|
+
return _getCroppedImg.apply(this, arguments);
|
|
321419
|
+
}
|
|
321420
|
+
|
|
321421
|
+
var useCoreOptions$3 = function useCoreOptions(_ref) {
|
|
321422
|
+
var state = _ref.state,
|
|
321423
|
+
dispatch = _ref.dispatch,
|
|
321424
|
+
props = _ref.props;
|
|
321425
|
+
var file = props.file; // 本地文件URL
|
|
321426
|
+
|
|
321427
|
+
var imgURL = React.useMemo(function () {
|
|
321428
|
+
return file && window.URL.createObjectURL(file);
|
|
321429
|
+
}, [file]); // 设置transform参数
|
|
321430
|
+
|
|
321431
|
+
var setTransform = React.useCallback(function (obj) {
|
|
321432
|
+
dispatch({
|
|
321433
|
+
type: 'changeResult',
|
|
321434
|
+
result: obj
|
|
321435
|
+
});
|
|
321436
|
+
}, [dispatch]); // 获取裁剪后的图片
|
|
321437
|
+
|
|
321438
|
+
var getCropImageAsync = React.useCallback(function () {
|
|
321439
|
+
try {
|
|
321440
|
+
return getCroppedImg(imgURL, state.croppedAreaPixels, state.rotation);
|
|
321441
|
+
} catch (e) {
|
|
321442
|
+
console.error('getCropImageAsync图片获取失败!', e);
|
|
321443
|
+
return null;
|
|
321444
|
+
}
|
|
321445
|
+
}, [imgURL, state.croppedAreaPixels, state.rotation]);
|
|
321446
|
+
React.useEffect(function () {
|
|
321447
|
+
dispatch({
|
|
321448
|
+
type: 'changeInit',
|
|
321449
|
+
init: {
|
|
321450
|
+
visible: !!file
|
|
321451
|
+
}
|
|
321452
|
+
});
|
|
321453
|
+
}, [file]);
|
|
321454
|
+
var CoreMethds = {
|
|
321455
|
+
setTransform: setTransform,
|
|
321456
|
+
getCropImageAsync: getCropImageAsync
|
|
321457
|
+
};
|
|
321458
|
+
var RefMethods = {
|
|
321459
|
+
imgURL: imgURL
|
|
321460
|
+
};
|
|
321461
|
+
return {
|
|
321462
|
+
CoreMethds: CoreMethds,
|
|
321463
|
+
RefMethods: RefMethods
|
|
321464
|
+
};
|
|
321465
|
+
};
|
|
321466
|
+
|
|
321467
|
+
/*! *****************************************************************************
|
|
321468
|
+
Copyright (c) Microsoft Corporation.
|
|
321469
|
+
|
|
321470
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
321471
|
+
purpose with or without fee is hereby granted.
|
|
321472
|
+
|
|
321473
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
321474
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
321475
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
321476
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
321477
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
321478
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
321479
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
321480
|
+
***************************************************************************** */
|
|
321481
|
+
/* global Reflect, Promise */
|
|
321482
|
+
|
|
321483
|
+
var extendStatics$3 = function(d, b) {
|
|
321484
|
+
extendStatics$3 = Object.setPrototypeOf ||
|
|
321485
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
321486
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
321487
|
+
return extendStatics$3(d, b);
|
|
321488
|
+
};
|
|
321489
|
+
|
|
321490
|
+
function __extends$3(d, b) {
|
|
321491
|
+
extendStatics$3(d, b);
|
|
321492
|
+
function __() { this.constructor = d; }
|
|
321493
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
321494
|
+
}
|
|
321495
|
+
|
|
321496
|
+
var __assign$2 = function() {
|
|
321497
|
+
__assign$2 = Object.assign || function __assign(t) {
|
|
321498
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
321499
|
+
s = arguments[i];
|
|
321500
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
321501
|
+
}
|
|
321502
|
+
return t;
|
|
321503
|
+
};
|
|
321504
|
+
return __assign$2.apply(this, arguments);
|
|
321505
|
+
};
|
|
321506
|
+
|
|
321507
|
+
/**
|
|
321508
|
+
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
321509
|
+
*
|
|
321510
|
+
* @providesModule UserAgent_DEPRECATED
|
|
321511
|
+
*/
|
|
321512
|
+
|
|
321513
|
+
/**
|
|
321514
|
+
* Provides entirely client-side User Agent and OS detection. You should prefer
|
|
321515
|
+
* the non-deprecated UserAgent module when possible, which exposes our
|
|
321516
|
+
* authoritative server-side PHP-based detection to the client.
|
|
321517
|
+
*
|
|
321518
|
+
* Usage is straightforward:
|
|
321519
|
+
*
|
|
321520
|
+
* if (UserAgent_DEPRECATED.ie()) {
|
|
321521
|
+
* // IE
|
|
321522
|
+
* }
|
|
321523
|
+
*
|
|
321524
|
+
* You can also do version checks:
|
|
321525
|
+
*
|
|
321526
|
+
* if (UserAgent_DEPRECATED.ie() >= 7) {
|
|
321527
|
+
* // IE7 or better
|
|
321528
|
+
* }
|
|
321529
|
+
*
|
|
321530
|
+
* The browser functions will return NaN if the browser does not match, so
|
|
321531
|
+
* you can also do version compares the other way:
|
|
321532
|
+
*
|
|
321533
|
+
* if (UserAgent_DEPRECATED.ie() < 7) {
|
|
321534
|
+
* // IE6 or worse
|
|
321535
|
+
* }
|
|
321536
|
+
*
|
|
321537
|
+
* Note that the version is a float and may include a minor version number,
|
|
321538
|
+
* so you should always use range operators to perform comparisons, not
|
|
321539
|
+
* strict equality.
|
|
321540
|
+
*
|
|
321541
|
+
* **Note:** You should **strongly** prefer capability detection to browser
|
|
321542
|
+
* version detection where it's reasonable:
|
|
321543
|
+
*
|
|
321544
|
+
* http://www.quirksmode.org/js/support.html
|
|
321545
|
+
*
|
|
321546
|
+
* Further, we have a large number of mature wrapper functions and classes
|
|
321547
|
+
* which abstract away many browser irregularities. Check the documentation,
|
|
321548
|
+
* grep for things, or ask on javascript@lists.facebook.com before writing yet
|
|
321549
|
+
* another copy of "event || window.event".
|
|
321550
|
+
*
|
|
321551
|
+
*/
|
|
321552
|
+
|
|
321553
|
+
var _populated = false;
|
|
321554
|
+
|
|
321555
|
+
// Browsers
|
|
321556
|
+
var _ie, _firefox, _opera, _webkit, _chrome;
|
|
321557
|
+
|
|
321558
|
+
// Actual IE browser for compatibility mode
|
|
321559
|
+
var _ie_real_version;
|
|
321560
|
+
|
|
321561
|
+
// Platforms
|
|
321562
|
+
var _osx, _windows, _linux, _android;
|
|
321563
|
+
|
|
321564
|
+
// Architectures
|
|
321565
|
+
var _win64;
|
|
321566
|
+
|
|
321567
|
+
// Devices
|
|
321568
|
+
var _iphone, _ipad, _native;
|
|
321569
|
+
|
|
321570
|
+
var _mobile;
|
|
321571
|
+
|
|
321572
|
+
function _populate() {
|
|
321573
|
+
if (_populated) {
|
|
321574
|
+
return;
|
|
321575
|
+
}
|
|
321576
|
+
|
|
321577
|
+
_populated = true;
|
|
321578
|
+
|
|
321579
|
+
// To work around buggy JS libraries that can't handle multi-digit
|
|
321580
|
+
// version numbers, Opera 10's user agent string claims it's Opera
|
|
321581
|
+
// 9, then later includes a Version/X.Y field:
|
|
321582
|
+
//
|
|
321583
|
+
// Opera/9.80 (foo) Presto/2.2.15 Version/10.10
|
|
321584
|
+
var uas = navigator.userAgent;
|
|
321585
|
+
var agent = /(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(uas);
|
|
321586
|
+
var os = /(Mac OS X)|(Windows)|(Linux)/.exec(uas);
|
|
321587
|
+
|
|
321588
|
+
_iphone = /\b(iPhone|iP[ao]d)/.exec(uas);
|
|
321589
|
+
_ipad = /\b(iP[ao]d)/.exec(uas);
|
|
321590
|
+
_android = /Android/i.exec(uas);
|
|
321591
|
+
_native = /FBAN\/\w+;/i.exec(uas);
|
|
321592
|
+
_mobile = /Mobile/i.exec(uas);
|
|
321593
|
+
|
|
321594
|
+
// Note that the IE team blog would have you believe you should be checking
|
|
321595
|
+
// for 'Win64; x64'. But MSDN then reveals that you can actually be coming
|
|
321596
|
+
// from either x64 or ia64; so ultimately, you should just check for Win64
|
|
321597
|
+
// as in indicator of whether you're in 64-bit IE. 32-bit IE on 64-bit
|
|
321598
|
+
// Windows will send 'WOW64' instead.
|
|
321599
|
+
_win64 = !!(/Win64/.exec(uas));
|
|
321600
|
+
|
|
321601
|
+
if (agent) {
|
|
321602
|
+
_ie = agent[1] ? parseFloat(agent[1]) : (
|
|
321603
|
+
agent[5] ? parseFloat(agent[5]) : NaN);
|
|
321604
|
+
// IE compatibility mode
|
|
321605
|
+
if (_ie && document && document.documentMode) {
|
|
321606
|
+
_ie = document.documentMode;
|
|
321607
|
+
}
|
|
321608
|
+
// grab the "true" ie version from the trident token if available
|
|
321609
|
+
var trident = /(?:Trident\/(\d+.\d+))/.exec(uas);
|
|
321610
|
+
_ie_real_version = trident ? parseFloat(trident[1]) + 4 : _ie;
|
|
321611
|
+
|
|
321612
|
+
_firefox = agent[2] ? parseFloat(agent[2]) : NaN;
|
|
321613
|
+
_opera = agent[3] ? parseFloat(agent[3]) : NaN;
|
|
321614
|
+
_webkit = agent[4] ? parseFloat(agent[4]) : NaN;
|
|
321615
|
+
if (_webkit) {
|
|
321616
|
+
// We do not add the regexp to the above test, because it will always
|
|
321617
|
+
// match 'safari' only since 'AppleWebKit' appears before 'Chrome' in
|
|
321618
|
+
// the userAgent string.
|
|
321619
|
+
agent = /(?:Chrome\/(\d+\.\d+))/.exec(uas);
|
|
321620
|
+
_chrome = agent && agent[1] ? parseFloat(agent[1]) : NaN;
|
|
321621
|
+
} else {
|
|
321622
|
+
_chrome = NaN;
|
|
321623
|
+
}
|
|
321624
|
+
} else {
|
|
321625
|
+
_ie = _firefox = _opera = _chrome = _webkit = NaN;
|
|
321626
|
+
}
|
|
321627
|
+
|
|
321628
|
+
if (os) {
|
|
321629
|
+
if (os[1]) {
|
|
321630
|
+
// Detect OS X version. If no version number matches, set _osx to true.
|
|
321631
|
+
// Version examples: 10, 10_6_1, 10.7
|
|
321632
|
+
// Parses version number as a float, taking only first two sets of
|
|
321633
|
+
// digits. If only one set of digits is found, returns just the major
|
|
321634
|
+
// version number.
|
|
321635
|
+
var ver = /(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(uas);
|
|
321636
|
+
|
|
321637
|
+
_osx = ver ? parseFloat(ver[1].replace('_', '.')) : true;
|
|
321638
|
+
} else {
|
|
321639
|
+
_osx = false;
|
|
321640
|
+
}
|
|
321641
|
+
_windows = !!os[2];
|
|
321642
|
+
_linux = !!os[3];
|
|
321643
|
+
} else {
|
|
321644
|
+
_osx = _windows = _linux = false;
|
|
321645
|
+
}
|
|
321646
|
+
}
|
|
321647
|
+
|
|
321648
|
+
var UserAgent_DEPRECATED = {
|
|
321649
|
+
|
|
321650
|
+
/**
|
|
321651
|
+
* Check if the UA is Internet Explorer.
|
|
321652
|
+
*
|
|
321653
|
+
*
|
|
321654
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
321655
|
+
*/
|
|
321656
|
+
ie: function() {
|
|
321657
|
+
return _populate() || _ie;
|
|
321658
|
+
},
|
|
321659
|
+
|
|
321660
|
+
/**
|
|
321661
|
+
* Check if we're in Internet Explorer compatibility mode.
|
|
321662
|
+
*
|
|
321663
|
+
* @return bool true if in compatibility mode, false if
|
|
321664
|
+
* not compatibility mode or not ie
|
|
321665
|
+
*/
|
|
321666
|
+
ieCompatibilityMode: function() {
|
|
321667
|
+
return _populate() || (_ie_real_version > _ie);
|
|
321668
|
+
},
|
|
321669
|
+
|
|
321670
|
+
|
|
321671
|
+
/**
|
|
321672
|
+
* Whether the browser is 64-bit IE. Really, this is kind of weak sauce; we
|
|
321673
|
+
* only need this because Skype can't handle 64-bit IE yet. We need to remove
|
|
321674
|
+
* this when we don't need it -- tracked by #601957.
|
|
321675
|
+
*/
|
|
321676
|
+
ie64: function() {
|
|
321677
|
+
return UserAgent_DEPRECATED.ie() && _win64;
|
|
321678
|
+
},
|
|
321679
|
+
|
|
321680
|
+
/**
|
|
321681
|
+
* Check if the UA is Firefox.
|
|
321682
|
+
*
|
|
321683
|
+
*
|
|
321684
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
321685
|
+
*/
|
|
321686
|
+
firefox: function() {
|
|
321687
|
+
return _populate() || _firefox;
|
|
321688
|
+
},
|
|
321689
|
+
|
|
321690
|
+
|
|
321691
|
+
/**
|
|
321692
|
+
* Check if the UA is Opera.
|
|
321693
|
+
*
|
|
321694
|
+
*
|
|
321695
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
321696
|
+
*/
|
|
321697
|
+
opera: function() {
|
|
321698
|
+
return _populate() || _opera;
|
|
321699
|
+
},
|
|
321700
|
+
|
|
321701
|
+
|
|
321702
|
+
/**
|
|
321703
|
+
* Check if the UA is WebKit.
|
|
321704
|
+
*
|
|
321705
|
+
*
|
|
321706
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
321707
|
+
*/
|
|
321708
|
+
webkit: function() {
|
|
321709
|
+
return _populate() || _webkit;
|
|
321710
|
+
},
|
|
321711
|
+
|
|
321712
|
+
/**
|
|
321713
|
+
* For Push
|
|
321714
|
+
* WILL BE REMOVED VERY SOON. Use UserAgent_DEPRECATED.webkit
|
|
321715
|
+
*/
|
|
321716
|
+
safari: function() {
|
|
321717
|
+
return UserAgent_DEPRECATED.webkit();
|
|
321718
|
+
},
|
|
321719
|
+
|
|
321720
|
+
/**
|
|
321721
|
+
* Check if the UA is a Chrome browser.
|
|
321722
|
+
*
|
|
321723
|
+
*
|
|
321724
|
+
* @return float|NaN Version number (if match) or NaN.
|
|
321725
|
+
*/
|
|
321726
|
+
chrome : function() {
|
|
321727
|
+
return _populate() || _chrome;
|
|
321728
|
+
},
|
|
321729
|
+
|
|
321730
|
+
|
|
321731
|
+
/**
|
|
321732
|
+
* Check if the user is running Windows.
|
|
321733
|
+
*
|
|
321734
|
+
* @return bool `true' if the user's OS is Windows.
|
|
321735
|
+
*/
|
|
321736
|
+
windows: function() {
|
|
321737
|
+
return _populate() || _windows;
|
|
321738
|
+
},
|
|
321739
|
+
|
|
321740
|
+
|
|
321741
|
+
/**
|
|
321742
|
+
* Check if the user is running Mac OS X.
|
|
321743
|
+
*
|
|
321744
|
+
* @return float|bool Returns a float if a version number is detected,
|
|
321745
|
+
* otherwise true/false.
|
|
321746
|
+
*/
|
|
321747
|
+
osx: function() {
|
|
321748
|
+
return _populate() || _osx;
|
|
321749
|
+
},
|
|
321750
|
+
|
|
321751
|
+
/**
|
|
321752
|
+
* Check if the user is running Linux.
|
|
321753
|
+
*
|
|
321754
|
+
* @return bool `true' if the user's OS is some flavor of Linux.
|
|
321755
|
+
*/
|
|
321756
|
+
linux: function() {
|
|
321757
|
+
return _populate() || _linux;
|
|
321758
|
+
},
|
|
321759
|
+
|
|
321760
|
+
/**
|
|
321761
|
+
* Check if the user is running on an iPhone or iPod platform.
|
|
321762
|
+
*
|
|
321763
|
+
* @return bool `true' if the user is running some flavor of the
|
|
321764
|
+
* iPhone OS.
|
|
321765
|
+
*/
|
|
321766
|
+
iphone: function() {
|
|
321767
|
+
return _populate() || _iphone;
|
|
321768
|
+
},
|
|
321769
|
+
|
|
321770
|
+
mobile: function() {
|
|
321771
|
+
return _populate() || (_iphone || _ipad || _android || _mobile);
|
|
321772
|
+
},
|
|
321773
|
+
|
|
321774
|
+
nativeApp: function() {
|
|
321775
|
+
// webviews inside of the native apps
|
|
321776
|
+
return _populate() || _native;
|
|
321777
|
+
},
|
|
321778
|
+
|
|
321779
|
+
android: function() {
|
|
321780
|
+
return _populate() || _android;
|
|
321781
|
+
},
|
|
321782
|
+
|
|
321783
|
+
ipad: function() {
|
|
321784
|
+
return _populate() || _ipad;
|
|
321785
|
+
}
|
|
321786
|
+
};
|
|
321787
|
+
|
|
321788
|
+
var UserAgent_DEPRECATED_1 = UserAgent_DEPRECATED;
|
|
321789
|
+
|
|
321790
|
+
/**
|
|
321791
|
+
* Copyright (c) 2015, Facebook, Inc.
|
|
321792
|
+
* All rights reserved.
|
|
321793
|
+
*
|
|
321794
|
+
* This source code is licensed under the BSD-style license found in the
|
|
321795
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
321796
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
321797
|
+
*
|
|
321798
|
+
* @providesModule ExecutionEnvironment
|
|
321799
|
+
*/
|
|
321800
|
+
|
|
321801
|
+
var canUseDOM$2 = !!(
|
|
321802
|
+
typeof window !== 'undefined' &&
|
|
321803
|
+
window.document &&
|
|
321804
|
+
window.document.createElement
|
|
321805
|
+
);
|
|
321806
|
+
|
|
321807
|
+
/**
|
|
321808
|
+
* Simple, lightweight module assisting with the detection and context of
|
|
321809
|
+
* Worker. Helps avoid circular dependencies and allows code to reason about
|
|
321810
|
+
* whether or not they are in a Worker, even if they never include the main
|
|
321811
|
+
* `ReactWorker` dependency.
|
|
321812
|
+
*/
|
|
321813
|
+
var ExecutionEnvironment = {
|
|
321814
|
+
|
|
321815
|
+
canUseDOM: canUseDOM$2,
|
|
321816
|
+
|
|
321817
|
+
canUseWorkers: typeof Worker !== 'undefined',
|
|
321818
|
+
|
|
321819
|
+
canUseEventListeners:
|
|
321820
|
+
canUseDOM$2 && !!(window.addEventListener || window.attachEvent),
|
|
321821
|
+
|
|
321822
|
+
canUseViewport: canUseDOM$2 && !!window.screen,
|
|
321823
|
+
|
|
321824
|
+
isInWorker: !canUseDOM$2 // For now, this is true - might change in the future.
|
|
321825
|
+
|
|
321826
|
+
};
|
|
321827
|
+
|
|
321828
|
+
var ExecutionEnvironment_1 = ExecutionEnvironment;
|
|
321829
|
+
|
|
321830
|
+
var useHasFeature;
|
|
321831
|
+
if (ExecutionEnvironment_1.canUseDOM) {
|
|
321832
|
+
useHasFeature =
|
|
321833
|
+
document.implementation &&
|
|
321834
|
+
document.implementation.hasFeature &&
|
|
321835
|
+
// always returns true in newer browsers as per the standard.
|
|
321836
|
+
// @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
|
|
321837
|
+
document.implementation.hasFeature('', '') !== true;
|
|
321838
|
+
}
|
|
321839
|
+
|
|
321840
|
+
/**
|
|
321841
|
+
* Checks if an event is supported in the current execution environment.
|
|
321842
|
+
*
|
|
321843
|
+
* NOTE: This will not work correctly for non-generic events such as `change`,
|
|
321844
|
+
* `reset`, `load`, `error`, and `select`.
|
|
321845
|
+
*
|
|
321846
|
+
* Borrows from Modernizr.
|
|
321847
|
+
*
|
|
321848
|
+
* @param {string} eventNameSuffix Event name, e.g. "click".
|
|
321849
|
+
* @param {?boolean} capture Check if the capture phase is supported.
|
|
321850
|
+
* @return {boolean} True if the event is supported.
|
|
321851
|
+
* @internal
|
|
321852
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
321853
|
+
*/
|
|
321854
|
+
function isEventSupported(eventNameSuffix, capture) {
|
|
321855
|
+
if (!ExecutionEnvironment_1.canUseDOM ||
|
|
321856
|
+
capture && !('addEventListener' in document)) {
|
|
321857
|
+
return false;
|
|
321858
|
+
}
|
|
321859
|
+
|
|
321860
|
+
var eventName = 'on' + eventNameSuffix;
|
|
321861
|
+
var isSupported = eventName in document;
|
|
321862
|
+
|
|
321863
|
+
if (!isSupported) {
|
|
321864
|
+
var element = document.createElement('div');
|
|
321865
|
+
element.setAttribute(eventName, 'return;');
|
|
321866
|
+
isSupported = typeof element[eventName] === 'function';
|
|
321867
|
+
}
|
|
321868
|
+
|
|
321869
|
+
if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
|
|
321870
|
+
// This is the only way to test support for the `wheel` event in IE9+.
|
|
321871
|
+
isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
|
|
321872
|
+
}
|
|
321873
|
+
|
|
321874
|
+
return isSupported;
|
|
321875
|
+
}
|
|
321876
|
+
|
|
321877
|
+
var isEventSupported_1 = isEventSupported;
|
|
321878
|
+
|
|
321879
|
+
// Reasonable defaults
|
|
321880
|
+
var PIXEL_STEP = 10;
|
|
321881
|
+
var LINE_HEIGHT = 40;
|
|
321882
|
+
var PAGE_HEIGHT = 800;
|
|
321883
|
+
|
|
321884
|
+
/**
|
|
321885
|
+
* Mouse wheel (and 2-finger trackpad) support on the web sucks. It is
|
|
321886
|
+
* complicated, thus this doc is long and (hopefully) detailed enough to answer
|
|
321887
|
+
* your questions.
|
|
321888
|
+
*
|
|
321889
|
+
* If you need to react to the mouse wheel in a predictable way, this code is
|
|
321890
|
+
* like your bestest friend. * hugs *
|
|
321891
|
+
*
|
|
321892
|
+
* As of today, there are 4 DOM event types you can listen to:
|
|
321893
|
+
*
|
|
321894
|
+
* 'wheel' -- Chrome(31+), FF(17+), IE(9+)
|
|
321895
|
+
* 'mousewheel' -- Chrome, IE(6+), Opera, Safari
|
|
321896
|
+
* 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!
|
|
321897
|
+
* 'DOMMouseScroll' -- FF(0.9.7+) since 2003
|
|
321898
|
+
*
|
|
321899
|
+
* So what to do? The is the best:
|
|
321900
|
+
*
|
|
321901
|
+
* normalizeWheel.getEventType();
|
|
321902
|
+
*
|
|
321903
|
+
* In your event callback, use this code to get sane interpretation of the
|
|
321904
|
+
* deltas. This code will return an object with properties:
|
|
321905
|
+
*
|
|
321906
|
+
* spinX -- normalized spin speed (use for zoom) - x plane
|
|
321907
|
+
* spinY -- " - y plane
|
|
321908
|
+
* pixelX -- normalized distance (to pixels) - x plane
|
|
321909
|
+
* pixelY -- " - y plane
|
|
321910
|
+
*
|
|
321911
|
+
* Wheel values are provided by the browser assuming you are using the wheel to
|
|
321912
|
+
* scroll a web page by a number of lines or pixels (or pages). Values can vary
|
|
321913
|
+
* significantly on different platforms and browsers, forgetting that you can
|
|
321914
|
+
* scroll at different speeds. Some devices (like trackpads) emit more events
|
|
321915
|
+
* at smaller increments with fine granularity, and some emit massive jumps with
|
|
321916
|
+
* linear speed or acceleration.
|
|
321917
|
+
*
|
|
321918
|
+
* This code does its best to normalize the deltas for you:
|
|
321919
|
+
*
|
|
321920
|
+
* - spin is trying to normalize how far the wheel was spun (or trackpad
|
|
321921
|
+
* dragged). This is super useful for zoom support where you want to
|
|
321922
|
+
* throw away the chunky scroll steps on the PC and make those equal to
|
|
321923
|
+
* the slow and smooth tiny steps on the Mac. Key data: This code tries to
|
|
321924
|
+
* resolve a single slow step on a wheel to 1.
|
|
321925
|
+
*
|
|
321926
|
+
* - pixel is normalizing the desired scroll delta in pixel units. You'll
|
|
321927
|
+
* get the crazy differences between browsers, but at least it'll be in
|
|
321928
|
+
* pixels!
|
|
321929
|
+
*
|
|
321930
|
+
* - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This
|
|
321931
|
+
* should translate to positive value zooming IN, negative zooming OUT.
|
|
321932
|
+
* This matches the newer 'wheel' event.
|
|
321933
|
+
*
|
|
321934
|
+
* Why are there spinX, spinY (or pixels)?
|
|
321935
|
+
*
|
|
321936
|
+
* - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn
|
|
321937
|
+
* with a mouse. It results in side-scrolling in the browser by default.
|
|
321938
|
+
*
|
|
321939
|
+
* - spinY is what you expect -- it's the classic axis of a mouse wheel.
|
|
321940
|
+
*
|
|
321941
|
+
* - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and
|
|
321942
|
+
* probably is by browsers in conjunction with fancy 3D controllers .. but
|
|
321943
|
+
* you know.
|
|
321944
|
+
*
|
|
321945
|
+
* Implementation info:
|
|
321946
|
+
*
|
|
321947
|
+
* Examples of 'wheel' event if you scroll slowly (down) by one step with an
|
|
321948
|
+
* average mouse:
|
|
321949
|
+
*
|
|
321950
|
+
* OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)
|
|
321951
|
+
* OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)
|
|
321952
|
+
* OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)
|
|
321953
|
+
* Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)
|
|
321954
|
+
* Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)
|
|
321955
|
+
*
|
|
321956
|
+
* On the trackpad:
|
|
321957
|
+
*
|
|
321958
|
+
* OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)
|
|
321959
|
+
* OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)
|
|
321960
|
+
*
|
|
321961
|
+
* On other/older browsers.. it's more complicated as there can be multiple and
|
|
321962
|
+
* also missing delta values.
|
|
321963
|
+
*
|
|
321964
|
+
* The 'wheel' event is more standard:
|
|
321965
|
+
*
|
|
321966
|
+
* http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
|
|
321967
|
+
*
|
|
321968
|
+
* The basics is that it includes a unit, deltaMode (pixels, lines, pages), and
|
|
321969
|
+
* deltaX, deltaY and deltaZ. Some browsers provide other values to maintain
|
|
321970
|
+
* backward compatibility with older events. Those other values help us
|
|
321971
|
+
* better normalize spin speed. Example of what the browsers provide:
|
|
321972
|
+
*
|
|
321973
|
+
* | event.wheelDelta | event.detail
|
|
321974
|
+
* ------------------+------------------+--------------
|
|
321975
|
+
* Safari v5/OS X | -120 | 0
|
|
321976
|
+
* Safari v5/Win7 | -120 | 0
|
|
321977
|
+
* Chrome v17/OS X | -120 | 0
|
|
321978
|
+
* Chrome v17/Win7 | -120 | 0
|
|
321979
|
+
* IE9/Win7 | -120 | undefined
|
|
321980
|
+
* Firefox v4/OS X | undefined | 1
|
|
321981
|
+
* Firefox v4/Win7 | undefined | 3
|
|
321982
|
+
*
|
|
321983
|
+
*/
|
|
321984
|
+
function normalizeWheel(/*object*/ event) /*object*/ {
|
|
321985
|
+
var sX = 0, sY = 0, // spinX, spinY
|
|
321986
|
+
pX = 0, pY = 0; // pixelX, pixelY
|
|
321987
|
+
|
|
321988
|
+
// Legacy
|
|
321989
|
+
if ('detail' in event) { sY = event.detail; }
|
|
321990
|
+
if ('wheelDelta' in event) { sY = -event.wheelDelta / 120; }
|
|
321991
|
+
if ('wheelDeltaY' in event) { sY = -event.wheelDeltaY / 120; }
|
|
321992
|
+
if ('wheelDeltaX' in event) { sX = -event.wheelDeltaX / 120; }
|
|
321993
|
+
|
|
321994
|
+
// side scrolling on FF with DOMMouseScroll
|
|
321995
|
+
if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
|
|
321996
|
+
sX = sY;
|
|
321997
|
+
sY = 0;
|
|
321998
|
+
}
|
|
321999
|
+
|
|
322000
|
+
pX = sX * PIXEL_STEP;
|
|
322001
|
+
pY = sY * PIXEL_STEP;
|
|
322002
|
+
|
|
322003
|
+
if ('deltaY' in event) { pY = event.deltaY; }
|
|
322004
|
+
if ('deltaX' in event) { pX = event.deltaX; }
|
|
322005
|
+
|
|
322006
|
+
if ((pX || pY) && event.deltaMode) {
|
|
322007
|
+
if (event.deltaMode == 1) { // delta in LINE units
|
|
322008
|
+
pX *= LINE_HEIGHT;
|
|
322009
|
+
pY *= LINE_HEIGHT;
|
|
322010
|
+
} else { // delta in PAGE units
|
|
322011
|
+
pX *= PAGE_HEIGHT;
|
|
322012
|
+
pY *= PAGE_HEIGHT;
|
|
322013
|
+
}
|
|
322014
|
+
}
|
|
322015
|
+
|
|
322016
|
+
// Fall-back if spin cannot be determined
|
|
322017
|
+
if (pX && !sX) { sX = (pX < 1) ? -1 : 1; }
|
|
322018
|
+
if (pY && !sY) { sY = (pY < 1) ? -1 : 1; }
|
|
322019
|
+
|
|
322020
|
+
return { spinX : sX,
|
|
322021
|
+
spinY : sY,
|
|
322022
|
+
pixelX : pX,
|
|
322023
|
+
pixelY : pY };
|
|
322024
|
+
}
|
|
322025
|
+
|
|
322026
|
+
|
|
322027
|
+
/**
|
|
322028
|
+
* The best combination if you prefer spinX + spinY normalization. It favors
|
|
322029
|
+
* the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with
|
|
322030
|
+
* 'wheel' event, making spin speed determination impossible.
|
|
322031
|
+
*/
|
|
322032
|
+
normalizeWheel.getEventType = function() /*string*/ {
|
|
322033
|
+
return (UserAgent_DEPRECATED_1.firefox())
|
|
322034
|
+
? 'DOMMouseScroll'
|
|
322035
|
+
: (isEventSupported_1('wheel'))
|
|
322036
|
+
? 'wheel'
|
|
322037
|
+
: 'mousewheel';
|
|
322038
|
+
};
|
|
322039
|
+
|
|
322040
|
+
var normalizeWheel_1 = normalizeWheel;
|
|
322041
|
+
|
|
322042
|
+
var normalizeWheel$1 = normalizeWheel_1;
|
|
322043
|
+
|
|
322044
|
+
/**
|
|
322045
|
+
* Compute the dimension of the crop area based on media size,
|
|
322046
|
+
* aspect ratio and optionally rotation
|
|
322047
|
+
*/
|
|
322048
|
+
|
|
322049
|
+
function getCropSize(mediaWidth, mediaHeight, containerWidth, containerHeight, aspect, rotation) {
|
|
322050
|
+
if (rotation === void 0) {
|
|
322051
|
+
rotation = 0;
|
|
322052
|
+
}
|
|
322053
|
+
|
|
322054
|
+
var _a = rotateSize$1(mediaWidth, mediaHeight, rotation),
|
|
322055
|
+
width = _a.width,
|
|
322056
|
+
height = _a.height;
|
|
322057
|
+
|
|
322058
|
+
var fittingWidth = Math.min(width, containerWidth);
|
|
322059
|
+
var fittingHeight = Math.min(height, containerHeight);
|
|
322060
|
+
|
|
322061
|
+
if (fittingWidth > fittingHeight * aspect) {
|
|
322062
|
+
return {
|
|
322063
|
+
width: fittingHeight * aspect,
|
|
322064
|
+
height: fittingHeight
|
|
322065
|
+
};
|
|
322066
|
+
}
|
|
322067
|
+
|
|
322068
|
+
return {
|
|
322069
|
+
width: fittingWidth,
|
|
322070
|
+
height: fittingWidth / aspect
|
|
322071
|
+
};
|
|
322072
|
+
}
|
|
322073
|
+
/**
|
|
322074
|
+
* Compute media zoom.
|
|
322075
|
+
* We fit the media into the container with "max-width: 100%; max-height: 100%;"
|
|
322076
|
+
*/
|
|
322077
|
+
|
|
322078
|
+
function getMediaZoom(mediaSize) {
|
|
322079
|
+
// Take the axis with more pixels to improve accuracy
|
|
322080
|
+
return mediaSize.width > mediaSize.height ? mediaSize.width / mediaSize.naturalWidth : mediaSize.height / mediaSize.naturalHeight;
|
|
322081
|
+
}
|
|
322082
|
+
/**
|
|
322083
|
+
* Ensure a new media position stays in the crop area.
|
|
322084
|
+
*/
|
|
322085
|
+
|
|
322086
|
+
function restrictPosition(position, mediaSize, cropSize, zoom, rotation) {
|
|
322087
|
+
if (rotation === void 0) {
|
|
322088
|
+
rotation = 0;
|
|
322089
|
+
}
|
|
322090
|
+
|
|
322091
|
+
var _a = rotateSize$1(mediaSize.width, mediaSize.height, rotation),
|
|
322092
|
+
width = _a.width,
|
|
322093
|
+
height = _a.height;
|
|
322094
|
+
|
|
322095
|
+
return {
|
|
322096
|
+
x: restrictPositionCoord(position.x, width, cropSize.width, zoom),
|
|
322097
|
+
y: restrictPositionCoord(position.y, height, cropSize.height, zoom)
|
|
322098
|
+
};
|
|
322099
|
+
}
|
|
322100
|
+
|
|
322101
|
+
function restrictPositionCoord(position, mediaSize, cropSize, zoom) {
|
|
322102
|
+
var maxPosition = mediaSize * zoom / 2 - cropSize / 2;
|
|
322103
|
+
return clamp$2(position, -maxPosition, maxPosition);
|
|
322104
|
+
}
|
|
322105
|
+
|
|
322106
|
+
function getDistanceBetweenPoints(pointA, pointB) {
|
|
322107
|
+
return Math.sqrt(Math.pow(pointA.y - pointB.y, 2) + Math.pow(pointA.x - pointB.x, 2));
|
|
322108
|
+
}
|
|
322109
|
+
function getRotationBetweenPoints(pointA, pointB) {
|
|
322110
|
+
return Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x) * 180 / Math.PI;
|
|
322111
|
+
}
|
|
322112
|
+
/**
|
|
322113
|
+
* Compute the output cropped area of the media in percentages and pixels.
|
|
322114
|
+
* x/y are the top-left coordinates on the src media
|
|
322115
|
+
*/
|
|
322116
|
+
|
|
322117
|
+
function computeCroppedArea(crop, mediaSize, cropSize, aspect, zoom, rotation, restrictPosition) {
|
|
322118
|
+
if (rotation === void 0) {
|
|
322119
|
+
rotation = 0;
|
|
322120
|
+
}
|
|
322121
|
+
|
|
322122
|
+
if (restrictPosition === void 0) {
|
|
322123
|
+
restrictPosition = true;
|
|
322124
|
+
} // if the media is rotated by the user, we cannot limit the position anymore
|
|
322125
|
+
// as it might need to be negative.
|
|
322126
|
+
|
|
322127
|
+
|
|
322128
|
+
var limitAreaFn = restrictPosition ? limitArea : noOp;
|
|
322129
|
+
var mediaBBoxSize = rotateSize$1(mediaSize.width, mediaSize.height, rotation);
|
|
322130
|
+
var mediaNaturalBBoxSize = rotateSize$1(mediaSize.naturalWidth, mediaSize.naturalHeight, rotation); // calculate the crop area in percentages
|
|
322131
|
+
// in the rotated space
|
|
322132
|
+
|
|
322133
|
+
var croppedAreaPercentages = {
|
|
322134
|
+
x: limitAreaFn(100, ((mediaBBoxSize.width - cropSize.width / zoom) / 2 - crop.x / zoom) / mediaBBoxSize.width * 100),
|
|
322135
|
+
y: limitAreaFn(100, ((mediaBBoxSize.height - cropSize.height / zoom) / 2 - crop.y / zoom) / mediaBBoxSize.height * 100),
|
|
322136
|
+
width: limitAreaFn(100, cropSize.width / mediaBBoxSize.width * 100 / zoom),
|
|
322137
|
+
height: limitAreaFn(100, cropSize.height / mediaBBoxSize.height * 100 / zoom)
|
|
322138
|
+
}; // we compute the pixels size naively
|
|
322139
|
+
|
|
322140
|
+
var widthInPixels = Math.round(limitAreaFn(mediaNaturalBBoxSize.width, croppedAreaPercentages.width * mediaNaturalBBoxSize.width / 100));
|
|
322141
|
+
var heightInPixels = Math.round(limitAreaFn(mediaNaturalBBoxSize.height, croppedAreaPercentages.height * mediaNaturalBBoxSize.height / 100));
|
|
322142
|
+
var isImgWiderThanHigh = mediaNaturalBBoxSize.width >= mediaNaturalBBoxSize.height * aspect; // then we ensure the width and height exactly match the aspect (to avoid rounding approximations)
|
|
322143
|
+
// if the media is wider than high, when zoom is 0, the crop height will be equals to image height
|
|
322144
|
+
// thus we want to compute the width from the height and aspect for accuracy.
|
|
322145
|
+
// Otherwise, we compute the height from width and aspect.
|
|
322146
|
+
|
|
322147
|
+
var sizePixels = isImgWiderThanHigh ? {
|
|
322148
|
+
width: Math.round(heightInPixels * aspect),
|
|
322149
|
+
height: heightInPixels
|
|
322150
|
+
} : {
|
|
322151
|
+
width: widthInPixels,
|
|
322152
|
+
height: Math.round(widthInPixels / aspect)
|
|
322153
|
+
};
|
|
322154
|
+
|
|
322155
|
+
var croppedAreaPixels = __assign$2(__assign$2({}, sizePixels), {
|
|
322156
|
+
x: Math.round(limitAreaFn(mediaNaturalBBoxSize.width - sizePixels.width, croppedAreaPercentages.x * mediaNaturalBBoxSize.width / 100)),
|
|
322157
|
+
y: Math.round(limitAreaFn(mediaNaturalBBoxSize.height - sizePixels.height, croppedAreaPercentages.y * mediaNaturalBBoxSize.height / 100))
|
|
322158
|
+
});
|
|
322159
|
+
|
|
322160
|
+
return {
|
|
322161
|
+
croppedAreaPercentages: croppedAreaPercentages,
|
|
322162
|
+
croppedAreaPixels: croppedAreaPixels
|
|
322163
|
+
};
|
|
322164
|
+
}
|
|
322165
|
+
/**
|
|
322166
|
+
* Ensure the returned value is between 0 and max
|
|
322167
|
+
*/
|
|
322168
|
+
|
|
322169
|
+
function limitArea(max, value) {
|
|
322170
|
+
return Math.min(max, Math.max(0, value));
|
|
322171
|
+
}
|
|
322172
|
+
|
|
322173
|
+
function noOp(_max, value) {
|
|
322174
|
+
return value;
|
|
322175
|
+
}
|
|
322176
|
+
/**
|
|
322177
|
+
* Compute crop and zoom from the croppedAreaPercentages.
|
|
322178
|
+
*/
|
|
322179
|
+
|
|
322180
|
+
|
|
322181
|
+
function getInitialCropFromCroppedAreaPercentages(croppedAreaPercentages, mediaSize, rotation, cropSize, minZoom, maxZoom) {
|
|
322182
|
+
var mediaBBoxSize = rotateSize$1(mediaSize.width, mediaSize.height, rotation); // This is the inverse process of computeCroppedArea
|
|
322183
|
+
|
|
322184
|
+
var zoom = clamp$2(cropSize.width / mediaBBoxSize.width * (100 / croppedAreaPercentages.width), minZoom, maxZoom);
|
|
322185
|
+
var crop = {
|
|
322186
|
+
x: zoom * mediaBBoxSize.width / 2 - cropSize.width / 2 - mediaBBoxSize.width * zoom * (croppedAreaPercentages.x / 100),
|
|
322187
|
+
y: zoom * mediaBBoxSize.height / 2 - cropSize.height / 2 - mediaBBoxSize.height * zoom * (croppedAreaPercentages.y / 100)
|
|
322188
|
+
};
|
|
322189
|
+
return {
|
|
322190
|
+
crop: crop,
|
|
322191
|
+
zoom: zoom
|
|
322192
|
+
};
|
|
322193
|
+
}
|
|
322194
|
+
/**
|
|
322195
|
+
* Compute zoom from the croppedAreaPixels
|
|
322196
|
+
*/
|
|
322197
|
+
|
|
322198
|
+
function getZoomFromCroppedAreaPixels(croppedAreaPixels, mediaSize, cropSize) {
|
|
322199
|
+
var mediaZoom = getMediaZoom(mediaSize);
|
|
322200
|
+
return cropSize.height > cropSize.width ? cropSize.height / (croppedAreaPixels.height * mediaZoom) : cropSize.width / (croppedAreaPixels.width * mediaZoom);
|
|
322201
|
+
}
|
|
322202
|
+
/**
|
|
322203
|
+
* Compute crop and zoom from the croppedAreaPixels
|
|
322204
|
+
*/
|
|
322205
|
+
|
|
322206
|
+
|
|
322207
|
+
function getInitialCropFromCroppedAreaPixels(croppedAreaPixels, mediaSize, rotation, cropSize, minZoom, maxZoom) {
|
|
322208
|
+
if (rotation === void 0) {
|
|
322209
|
+
rotation = 0;
|
|
322210
|
+
}
|
|
322211
|
+
|
|
322212
|
+
var mediaNaturalBBoxSize = rotateSize$1(mediaSize.naturalWidth, mediaSize.naturalHeight, rotation);
|
|
322213
|
+
var zoom = clamp$2(getZoomFromCroppedAreaPixels(croppedAreaPixels, mediaSize, cropSize), minZoom, maxZoom);
|
|
322214
|
+
var cropZoom = cropSize.height > cropSize.width ? cropSize.height / croppedAreaPixels.height : cropSize.width / croppedAreaPixels.width;
|
|
322215
|
+
var crop = {
|
|
322216
|
+
x: ((mediaNaturalBBoxSize.width - croppedAreaPixels.width) / 2 - croppedAreaPixels.x) * cropZoom,
|
|
322217
|
+
y: ((mediaNaturalBBoxSize.height - croppedAreaPixels.height) / 2 - croppedAreaPixels.y) * cropZoom
|
|
322218
|
+
};
|
|
322219
|
+
return {
|
|
322220
|
+
crop: crop,
|
|
322221
|
+
zoom: zoom
|
|
322222
|
+
};
|
|
322223
|
+
}
|
|
322224
|
+
/**
|
|
322225
|
+
* Return the point that is the center of point a and b
|
|
322226
|
+
*/
|
|
322227
|
+
|
|
322228
|
+
function getCenter(a, b) {
|
|
322229
|
+
return {
|
|
322230
|
+
x: (b.x + a.x) / 2,
|
|
322231
|
+
y: (b.y + a.y) / 2
|
|
322232
|
+
};
|
|
322233
|
+
}
|
|
322234
|
+
function getRadianAngle$1(degreeValue) {
|
|
322235
|
+
return degreeValue * Math.PI / 180;
|
|
322236
|
+
}
|
|
322237
|
+
/**
|
|
322238
|
+
* Returns the new bounding area of a rotated rectangle.
|
|
322239
|
+
*/
|
|
322240
|
+
|
|
322241
|
+
function rotateSize$1(width, height, rotation) {
|
|
322242
|
+
var rotRad = getRadianAngle$1(rotation);
|
|
322243
|
+
return {
|
|
322244
|
+
width: Math.abs(Math.cos(rotRad) * width) + Math.abs(Math.sin(rotRad) * height),
|
|
322245
|
+
height: Math.abs(Math.sin(rotRad) * width) + Math.abs(Math.cos(rotRad) * height)
|
|
322246
|
+
};
|
|
322247
|
+
}
|
|
322248
|
+
/**
|
|
322249
|
+
* Clamp value between min and max
|
|
322250
|
+
*/
|
|
322251
|
+
|
|
322252
|
+
function clamp$2(value, min, max) {
|
|
322253
|
+
return Math.min(Math.max(value, min), max);
|
|
322254
|
+
}
|
|
322255
|
+
/**
|
|
322256
|
+
* Combine multiple class names into a single string.
|
|
322257
|
+
*/
|
|
322258
|
+
|
|
322259
|
+
function classNames() {
|
|
322260
|
+
var args = [];
|
|
322261
|
+
|
|
322262
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
322263
|
+
args[_i] = arguments[_i];
|
|
322264
|
+
}
|
|
322265
|
+
|
|
322266
|
+
return args.filter(function (value) {
|
|
322267
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
322268
|
+
return true;
|
|
322269
|
+
}
|
|
322270
|
+
|
|
322271
|
+
return false;
|
|
322272
|
+
}).join(' ').trim();
|
|
322273
|
+
}
|
|
322274
|
+
|
|
322275
|
+
var css_248z = ".reactEasyCrop_Container {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n overflow: hidden;\n user-select: none;\n touch-action: none;\n cursor: move;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.reactEasyCrop_Image,\n.reactEasyCrop_Video {\n will-change: transform; /* this improves performances and prevent painting issues on iOS Chrome */\n}\n\n.reactEasyCrop_Contain {\n max-width: 100%;\n max-height: 100%;\n margin: auto;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n}\n.reactEasyCrop_Cover_Horizontal {\n width: 100%;\n height: auto;\n}\n.reactEasyCrop_Cover_Vertical {\n width: auto;\n height: 100%;\n}\n\n.reactEasyCrop_CropArea {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n border: 1px solid rgba(255, 255, 255, 0.5);\n box-sizing: border-box;\n box-shadow: 0 0 0 9999em;\n color: rgba(0, 0, 0, 0.5);\n overflow: hidden;\n}\n\n.reactEasyCrop_CropAreaRound {\n border-radius: 50%;\n}\n\n.reactEasyCrop_CropAreaGrid::before {\n content: ' ';\n box-sizing: border-box;\n position: absolute;\n border: 1px solid rgba(255, 255, 255, 0.5);\n top: 0;\n bottom: 0;\n left: 33.33%;\n right: 33.33%;\n border-top: 0;\n border-bottom: 0;\n}\n\n.reactEasyCrop_CropAreaGrid::after {\n content: ' ';\n box-sizing: border-box;\n position: absolute;\n border: 1px solid rgba(255, 255, 255, 0.5);\n top: 33.33%;\n bottom: 33.33%;\n left: 0;\n right: 0;\n border-left: 0;\n border-right: 0;\n}\n";
|
|
322276
|
+
|
|
322277
|
+
var MIN_ZOOM = 1;
|
|
322278
|
+
var MAX_ZOOM = 3;
|
|
322279
|
+
|
|
322280
|
+
var Cropper =
|
|
322281
|
+
/** @class */
|
|
322282
|
+
function (_super) {
|
|
322283
|
+
__extends$3(Cropper, _super);
|
|
322284
|
+
|
|
322285
|
+
function Cropper() {
|
|
322286
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
322287
|
+
|
|
322288
|
+
_this.imageRef = /*#__PURE__*/React__default['default'].createRef();
|
|
322289
|
+
_this.videoRef = /*#__PURE__*/React__default['default'].createRef();
|
|
322290
|
+
_this.containerRef = null;
|
|
322291
|
+
_this.styleRef = null;
|
|
322292
|
+
_this.containerRect = null;
|
|
322293
|
+
_this.mediaSize = {
|
|
322294
|
+
width: 0,
|
|
322295
|
+
height: 0,
|
|
322296
|
+
naturalWidth: 0,
|
|
322297
|
+
naturalHeight: 0
|
|
322298
|
+
};
|
|
322299
|
+
_this.dragStartPosition = {
|
|
322300
|
+
x: 0,
|
|
322301
|
+
y: 0
|
|
322302
|
+
};
|
|
322303
|
+
_this.dragStartCrop = {
|
|
322304
|
+
x: 0,
|
|
322305
|
+
y: 0
|
|
322306
|
+
};
|
|
322307
|
+
_this.lastPinchDistance = 0;
|
|
322308
|
+
_this.lastPinchRotation = 0;
|
|
322309
|
+
_this.rafDragTimeout = null;
|
|
322310
|
+
_this.rafPinchTimeout = null;
|
|
322311
|
+
_this.wheelTimer = null;
|
|
322312
|
+
_this.currentDoc = document;
|
|
322313
|
+
_this.currentWindow = window;
|
|
322314
|
+
_this.state = {
|
|
322315
|
+
cropSize: null,
|
|
322316
|
+
hasWheelJustStarted: false
|
|
322317
|
+
}; // this is to prevent Safari on iOS >= 10 to zoom the page
|
|
322318
|
+
|
|
322319
|
+
_this.preventZoomSafari = function (e) {
|
|
322320
|
+
return e.preventDefault();
|
|
322321
|
+
};
|
|
322322
|
+
|
|
322323
|
+
_this.cleanEvents = function () {
|
|
322324
|
+
_this.currentDoc.removeEventListener('mousemove', _this.onMouseMove);
|
|
322325
|
+
|
|
322326
|
+
_this.currentDoc.removeEventListener('mouseup', _this.onDragStopped);
|
|
322327
|
+
|
|
322328
|
+
_this.currentDoc.removeEventListener('touchmove', _this.onTouchMove);
|
|
322329
|
+
|
|
322330
|
+
_this.currentDoc.removeEventListener('touchend', _this.onDragStopped);
|
|
322331
|
+
};
|
|
322332
|
+
|
|
322333
|
+
_this.clearScrollEvent = function () {
|
|
322334
|
+
if (_this.containerRef) _this.containerRef.removeEventListener('wheel', _this.onWheel);
|
|
322335
|
+
|
|
322336
|
+
if (_this.wheelTimer) {
|
|
322337
|
+
clearTimeout(_this.wheelTimer);
|
|
322338
|
+
}
|
|
322339
|
+
};
|
|
322340
|
+
|
|
322341
|
+
_this.onMediaLoad = function () {
|
|
322342
|
+
var cropSize = _this.computeSizes();
|
|
322343
|
+
|
|
322344
|
+
if (cropSize) {
|
|
322345
|
+
_this.emitCropData();
|
|
322346
|
+
|
|
322347
|
+
_this.setInitialCrop(cropSize);
|
|
322348
|
+
}
|
|
322349
|
+
|
|
322350
|
+
if (_this.props.onMediaLoaded) {
|
|
322351
|
+
_this.props.onMediaLoaded(_this.mediaSize);
|
|
322352
|
+
}
|
|
322353
|
+
};
|
|
322354
|
+
|
|
322355
|
+
_this.setInitialCrop = function (cropSize) {
|
|
322356
|
+
if (_this.props.initialCroppedAreaPercentages) {
|
|
322357
|
+
var _a = getInitialCropFromCroppedAreaPercentages(_this.props.initialCroppedAreaPercentages, _this.mediaSize, _this.props.rotation, cropSize, _this.props.minZoom, _this.props.maxZoom),
|
|
322358
|
+
crop = _a.crop,
|
|
322359
|
+
zoom = _a.zoom;
|
|
322360
|
+
|
|
322361
|
+
_this.props.onCropChange(crop);
|
|
322362
|
+
|
|
322363
|
+
_this.props.onZoomChange && _this.props.onZoomChange(zoom);
|
|
322364
|
+
} else if (_this.props.initialCroppedAreaPixels) {
|
|
322365
|
+
var _b = getInitialCropFromCroppedAreaPixels(_this.props.initialCroppedAreaPixels, _this.mediaSize, _this.props.rotation, cropSize, _this.props.minZoom, _this.props.maxZoom),
|
|
322366
|
+
crop = _b.crop,
|
|
322367
|
+
zoom = _b.zoom;
|
|
322368
|
+
|
|
322369
|
+
_this.props.onCropChange(crop);
|
|
322370
|
+
|
|
322371
|
+
_this.props.onZoomChange && _this.props.onZoomChange(zoom);
|
|
322372
|
+
}
|
|
322373
|
+
};
|
|
322374
|
+
|
|
322375
|
+
_this.computeSizes = function () {
|
|
322376
|
+
var _a, _b, _c, _d, _e, _f;
|
|
322377
|
+
|
|
322378
|
+
var mediaRef = _this.imageRef.current || _this.videoRef.current;
|
|
322379
|
+
|
|
322380
|
+
if (mediaRef && _this.containerRef) {
|
|
322381
|
+
_this.containerRect = _this.containerRef.getBoundingClientRect();
|
|
322382
|
+
var containerAspect = _this.containerRect.width / _this.containerRect.height;
|
|
322383
|
+
var naturalWidth = ((_a = _this.imageRef.current) === null || _a === void 0 ? void 0 : _a.naturalWidth) || ((_b = _this.videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) || 0;
|
|
322384
|
+
var naturalHeight = ((_c = _this.imageRef.current) === null || _c === void 0 ? void 0 : _c.naturalHeight) || ((_d = _this.videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) || 0;
|
|
322385
|
+
var isMediaScaledDown = mediaRef.offsetWidth < naturalWidth || mediaRef.offsetHeight < naturalHeight;
|
|
322386
|
+
var mediaAspect = naturalWidth / naturalHeight; // We do not rely on the offsetWidth/offsetHeight if the media is scaled down
|
|
322387
|
+
// as the values they report are rounded. That will result in precision losses
|
|
322388
|
+
// when calculating zoom. We use the fact that the media is positionned relative
|
|
322389
|
+
// to the container. That allows us to use the container's dimensions
|
|
322390
|
+
// and natural aspect ratio of the media to calculate accurate media size.
|
|
322391
|
+
// However, for this to work, the container should not be rotated
|
|
322392
|
+
|
|
322393
|
+
var renderedMediaSize = void 0;
|
|
322394
|
+
|
|
322395
|
+
if (isMediaScaledDown) {
|
|
322396
|
+
switch (_this.props.objectFit) {
|
|
322397
|
+
default:
|
|
322398
|
+
case 'contain':
|
|
322399
|
+
renderedMediaSize = containerAspect > mediaAspect ? {
|
|
322400
|
+
width: _this.containerRect.height * mediaAspect,
|
|
322401
|
+
height: _this.containerRect.height
|
|
322402
|
+
} : {
|
|
322403
|
+
width: _this.containerRect.width,
|
|
322404
|
+
height: _this.containerRect.width / mediaAspect
|
|
322405
|
+
};
|
|
322406
|
+
break;
|
|
322407
|
+
|
|
322408
|
+
case 'horizontal-cover':
|
|
322409
|
+
renderedMediaSize = {
|
|
322410
|
+
width: _this.containerRect.width,
|
|
322411
|
+
height: _this.containerRect.width / mediaAspect
|
|
322412
|
+
};
|
|
322413
|
+
break;
|
|
322414
|
+
|
|
322415
|
+
case 'vertical-cover':
|
|
322416
|
+
renderedMediaSize = {
|
|
322417
|
+
width: _this.containerRect.height * mediaAspect,
|
|
322418
|
+
height: _this.containerRect.height
|
|
322419
|
+
};
|
|
322420
|
+
break;
|
|
322421
|
+
|
|
322422
|
+
case 'auto-cover':
|
|
322423
|
+
renderedMediaSize = naturalWidth > naturalHeight ? {
|
|
322424
|
+
width: _this.containerRect.width,
|
|
322425
|
+
height: _this.containerRect.width / mediaAspect
|
|
322426
|
+
} : {
|
|
322427
|
+
width: _this.containerRect.height * mediaAspect,
|
|
322428
|
+
height: _this.containerRect.height
|
|
322429
|
+
};
|
|
322430
|
+
break;
|
|
322431
|
+
}
|
|
322432
|
+
} else {
|
|
322433
|
+
renderedMediaSize = {
|
|
322434
|
+
width: mediaRef.offsetWidth,
|
|
322435
|
+
height: mediaRef.offsetHeight
|
|
322436
|
+
};
|
|
322437
|
+
}
|
|
322438
|
+
|
|
322439
|
+
_this.mediaSize = __assign$2(__assign$2({}, renderedMediaSize), {
|
|
322440
|
+
naturalWidth: naturalWidth,
|
|
322441
|
+
naturalHeight: naturalHeight
|
|
322442
|
+
}); // set media size in the parent
|
|
322443
|
+
|
|
322444
|
+
if (_this.props.setMediaSize) {
|
|
322445
|
+
_this.props.setMediaSize(_this.mediaSize);
|
|
322446
|
+
}
|
|
322447
|
+
|
|
322448
|
+
var cropSize = _this.props.cropSize ? _this.props.cropSize : getCropSize(_this.mediaSize.width, _this.mediaSize.height, _this.containerRect.width, _this.containerRect.height, _this.props.aspect, _this.props.rotation);
|
|
322449
|
+
|
|
322450
|
+
if (((_e = _this.state.cropSize) === null || _e === void 0 ? void 0 : _e.height) !== cropSize.height || ((_f = _this.state.cropSize) === null || _f === void 0 ? void 0 : _f.width) !== cropSize.width) {
|
|
322451
|
+
_this.props.onCropSizeChange && _this.props.onCropSizeChange(cropSize);
|
|
322452
|
+
}
|
|
322453
|
+
|
|
322454
|
+
_this.setState({
|
|
322455
|
+
cropSize: cropSize
|
|
322456
|
+
}, _this.recomputeCropPosition); // pass crop size to parent
|
|
322457
|
+
|
|
322458
|
+
|
|
322459
|
+
if (_this.props.setCropSize) {
|
|
322460
|
+
_this.props.setCropSize(cropSize);
|
|
322461
|
+
}
|
|
322462
|
+
|
|
322463
|
+
return cropSize;
|
|
322464
|
+
}
|
|
322465
|
+
};
|
|
322466
|
+
|
|
322467
|
+
_this.onMouseDown = function (e) {
|
|
322468
|
+
e.preventDefault();
|
|
322469
|
+
|
|
322470
|
+
_this.currentDoc.addEventListener('mousemove', _this.onMouseMove);
|
|
322471
|
+
|
|
322472
|
+
_this.currentDoc.addEventListener('mouseup', _this.onDragStopped);
|
|
322473
|
+
|
|
322474
|
+
_this.onDragStart(Cropper.getMousePoint(e));
|
|
322475
|
+
};
|
|
322476
|
+
|
|
322477
|
+
_this.onMouseMove = function (e) {
|
|
322478
|
+
return _this.onDrag(Cropper.getMousePoint(e));
|
|
322479
|
+
};
|
|
322480
|
+
|
|
322481
|
+
_this.onTouchStart = function (e) {
|
|
322482
|
+
if (_this.props.onTouchRequest && !_this.props.onTouchRequest(e)) {
|
|
322483
|
+
return;
|
|
322484
|
+
}
|
|
322485
|
+
|
|
322486
|
+
_this.currentDoc.addEventListener('touchmove', _this.onTouchMove, {
|
|
322487
|
+
passive: false
|
|
322488
|
+
}); // iOS 11 now defaults to passive: true
|
|
322489
|
+
|
|
322490
|
+
|
|
322491
|
+
_this.currentDoc.addEventListener('touchend', _this.onDragStopped);
|
|
322492
|
+
|
|
322493
|
+
if (e.touches.length === 2) {
|
|
322494
|
+
_this.onPinchStart(e);
|
|
322495
|
+
} else if (e.touches.length === 1) {
|
|
322496
|
+
_this.onDragStart(Cropper.getTouchPoint(e.touches[0]));
|
|
322497
|
+
}
|
|
322498
|
+
};
|
|
322499
|
+
|
|
322500
|
+
_this.onTouchMove = function (e) {
|
|
322501
|
+
// Prevent whole page from scrolling on iOS.
|
|
322502
|
+
e.preventDefault();
|
|
322503
|
+
|
|
322504
|
+
if (e.touches.length === 2) {
|
|
322505
|
+
_this.onPinchMove(e);
|
|
322506
|
+
} else if (e.touches.length === 1) {
|
|
322507
|
+
_this.onDrag(Cropper.getTouchPoint(e.touches[0]));
|
|
322508
|
+
}
|
|
322509
|
+
};
|
|
322510
|
+
|
|
322511
|
+
_this.onDragStart = function (_a) {
|
|
322512
|
+
var _b, _c;
|
|
322513
|
+
|
|
322514
|
+
var x = _a.x,
|
|
322515
|
+
y = _a.y;
|
|
322516
|
+
_this.dragStartPosition = {
|
|
322517
|
+
x: x,
|
|
322518
|
+
y: y
|
|
322519
|
+
};
|
|
322520
|
+
_this.dragStartCrop = __assign$2({}, _this.props.crop);
|
|
322521
|
+
(_c = (_b = _this.props).onInteractionStart) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
322522
|
+
};
|
|
322523
|
+
|
|
322524
|
+
_this.onDrag = function (_a) {
|
|
322525
|
+
var x = _a.x,
|
|
322526
|
+
y = _a.y;
|
|
322527
|
+
if (_this.rafDragTimeout) _this.currentWindow.cancelAnimationFrame(_this.rafDragTimeout);
|
|
322528
|
+
_this.rafDragTimeout = _this.currentWindow.requestAnimationFrame(function () {
|
|
322529
|
+
if (!_this.state.cropSize) return;
|
|
322530
|
+
if (x === undefined || y === undefined) return;
|
|
322531
|
+
var offsetX = x - _this.dragStartPosition.x;
|
|
322532
|
+
var offsetY = y - _this.dragStartPosition.y;
|
|
322533
|
+
var requestedPosition = {
|
|
322534
|
+
x: _this.dragStartCrop.x + offsetX,
|
|
322535
|
+
y: _this.dragStartCrop.y + offsetY
|
|
322536
|
+
};
|
|
322537
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(requestedPosition, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : requestedPosition;
|
|
322538
|
+
|
|
322539
|
+
_this.props.onCropChange(newPosition);
|
|
322540
|
+
});
|
|
322541
|
+
};
|
|
322542
|
+
|
|
322543
|
+
_this.onDragStopped = function () {
|
|
322544
|
+
var _a, _b;
|
|
322545
|
+
|
|
322546
|
+
_this.cleanEvents();
|
|
322547
|
+
|
|
322548
|
+
_this.emitCropData();
|
|
322549
|
+
|
|
322550
|
+
(_b = (_a = _this.props).onInteractionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
322551
|
+
};
|
|
322552
|
+
|
|
322553
|
+
_this.onWheel = function (e) {
|
|
322554
|
+
if (_this.props.onWheelRequest && !_this.props.onWheelRequest(e)) {
|
|
322555
|
+
return;
|
|
322556
|
+
}
|
|
322557
|
+
|
|
322558
|
+
e.preventDefault();
|
|
322559
|
+
var point = Cropper.getMousePoint(e);
|
|
322560
|
+
var pixelY = normalizeWheel$1(e).pixelY;
|
|
322561
|
+
var newZoom = _this.props.zoom - pixelY * _this.props.zoomSpeed / 200;
|
|
322562
|
+
|
|
322563
|
+
_this.setNewZoom(newZoom, point, {
|
|
322564
|
+
shouldUpdatePosition: true
|
|
322565
|
+
});
|
|
322566
|
+
|
|
322567
|
+
if (!_this.state.hasWheelJustStarted) {
|
|
322568
|
+
_this.setState({
|
|
322569
|
+
hasWheelJustStarted: true
|
|
322570
|
+
}, function () {
|
|
322571
|
+
var _a, _b;
|
|
322572
|
+
|
|
322573
|
+
return (_b = (_a = _this.props).onInteractionStart) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
322574
|
+
});
|
|
322575
|
+
}
|
|
322576
|
+
|
|
322577
|
+
if (_this.wheelTimer) {
|
|
322578
|
+
clearTimeout(_this.wheelTimer);
|
|
322579
|
+
}
|
|
322580
|
+
|
|
322581
|
+
_this.wheelTimer = _this.currentWindow.setTimeout(function () {
|
|
322582
|
+
return _this.setState({
|
|
322583
|
+
hasWheelJustStarted: false
|
|
322584
|
+
}, function () {
|
|
322585
|
+
var _a, _b;
|
|
322586
|
+
|
|
322587
|
+
return (_b = (_a = _this.props).onInteractionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
322588
|
+
});
|
|
322589
|
+
}, 250);
|
|
322590
|
+
};
|
|
322591
|
+
|
|
322592
|
+
_this.getPointOnContainer = function (_a) {
|
|
322593
|
+
var x = _a.x,
|
|
322594
|
+
y = _a.y;
|
|
322595
|
+
|
|
322596
|
+
if (!_this.containerRect) {
|
|
322597
|
+
throw new Error('The Cropper is not mounted');
|
|
322598
|
+
}
|
|
322599
|
+
|
|
322600
|
+
return {
|
|
322601
|
+
x: _this.containerRect.width / 2 - (x - _this.containerRect.left),
|
|
322602
|
+
y: _this.containerRect.height / 2 - (y - _this.containerRect.top)
|
|
322603
|
+
};
|
|
322604
|
+
};
|
|
322605
|
+
|
|
322606
|
+
_this.getPointOnMedia = function (_a) {
|
|
322607
|
+
var x = _a.x,
|
|
322608
|
+
y = _a.y;
|
|
322609
|
+
var _b = _this.props,
|
|
322610
|
+
crop = _b.crop,
|
|
322611
|
+
zoom = _b.zoom;
|
|
322612
|
+
return {
|
|
322613
|
+
x: (x + crop.x) / zoom,
|
|
322614
|
+
y: (y + crop.y) / zoom
|
|
322615
|
+
};
|
|
322616
|
+
};
|
|
322617
|
+
|
|
322618
|
+
_this.setNewZoom = function (zoom, point, _a) {
|
|
322619
|
+
var _b = (_a === void 0 ? {} : _a).shouldUpdatePosition,
|
|
322620
|
+
shouldUpdatePosition = _b === void 0 ? true : _b;
|
|
322621
|
+
if (!_this.state.cropSize || !_this.props.onZoomChange) return;
|
|
322622
|
+
|
|
322623
|
+
var zoomPoint = _this.getPointOnContainer(point);
|
|
322624
|
+
|
|
322625
|
+
var zoomTarget = _this.getPointOnMedia(zoomPoint);
|
|
322626
|
+
|
|
322627
|
+
var newZoom = clamp$2(zoom, _this.props.minZoom, _this.props.maxZoom);
|
|
322628
|
+
var requestedPosition = {
|
|
322629
|
+
x: zoomTarget.x * newZoom - zoomPoint.x,
|
|
322630
|
+
y: zoomTarget.y * newZoom - zoomPoint.y
|
|
322631
|
+
};
|
|
322632
|
+
|
|
322633
|
+
if (shouldUpdatePosition) {
|
|
322634
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(requestedPosition, _this.mediaSize, _this.state.cropSize, newZoom, _this.props.rotation) : requestedPosition;
|
|
322635
|
+
|
|
322636
|
+
_this.props.onCropChange(newPosition);
|
|
322637
|
+
}
|
|
322638
|
+
|
|
322639
|
+
_this.props.onZoomChange(newZoom);
|
|
322640
|
+
};
|
|
322641
|
+
|
|
322642
|
+
_this.getCropData = function () {
|
|
322643
|
+
if (!_this.state.cropSize) {
|
|
322644
|
+
return null;
|
|
322645
|
+
} // this is to ensure the crop is correctly restricted after a zoom back (https://github.com/ValentinH/react-easy-crop/issues/6)
|
|
322646
|
+
|
|
322647
|
+
|
|
322648
|
+
var restrictedPosition = _this.props.restrictPosition ? restrictPosition(_this.props.crop, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : _this.props.crop;
|
|
322649
|
+
return computeCroppedArea(restrictedPosition, _this.mediaSize, _this.state.cropSize, _this.getAspect(), _this.props.zoom, _this.props.rotation, _this.props.restrictPosition);
|
|
322650
|
+
};
|
|
322651
|
+
|
|
322652
|
+
_this.emitCropData = function () {
|
|
322653
|
+
var cropData = _this.getCropData();
|
|
322654
|
+
|
|
322655
|
+
if (!cropData) return;
|
|
322656
|
+
var croppedAreaPercentages = cropData.croppedAreaPercentages,
|
|
322657
|
+
croppedAreaPixels = cropData.croppedAreaPixels;
|
|
322658
|
+
|
|
322659
|
+
if (_this.props.onCropComplete) {
|
|
322660
|
+
_this.props.onCropComplete(croppedAreaPercentages, croppedAreaPixels);
|
|
322661
|
+
}
|
|
322662
|
+
|
|
322663
|
+
if (_this.props.onCropAreaChange) {
|
|
322664
|
+
_this.props.onCropAreaChange(croppedAreaPercentages, croppedAreaPixels);
|
|
322665
|
+
}
|
|
322666
|
+
};
|
|
322667
|
+
|
|
322668
|
+
_this.emitCropAreaChange = function () {
|
|
322669
|
+
var cropData = _this.getCropData();
|
|
322670
|
+
|
|
322671
|
+
if (!cropData) return;
|
|
322672
|
+
var croppedAreaPercentages = cropData.croppedAreaPercentages,
|
|
322673
|
+
croppedAreaPixels = cropData.croppedAreaPixels;
|
|
322674
|
+
|
|
322675
|
+
if (_this.props.onCropAreaChange) {
|
|
322676
|
+
_this.props.onCropAreaChange(croppedAreaPercentages, croppedAreaPixels);
|
|
322677
|
+
}
|
|
322678
|
+
};
|
|
322679
|
+
|
|
322680
|
+
_this.recomputeCropPosition = function () {
|
|
322681
|
+
if (!_this.state.cropSize) return;
|
|
322682
|
+
var newPosition = _this.props.restrictPosition ? restrictPosition(_this.props.crop, _this.mediaSize, _this.state.cropSize, _this.props.zoom, _this.props.rotation) : _this.props.crop;
|
|
322683
|
+
|
|
322684
|
+
_this.props.onCropChange(newPosition);
|
|
322685
|
+
|
|
322686
|
+
_this.emitCropData();
|
|
322687
|
+
};
|
|
322688
|
+
|
|
322689
|
+
return _this;
|
|
322690
|
+
}
|
|
322691
|
+
|
|
322692
|
+
Cropper.prototype.componentDidMount = function () {
|
|
322693
|
+
if (this.containerRef) {
|
|
322694
|
+
if (this.containerRef.ownerDocument) {
|
|
322695
|
+
this.currentDoc = this.containerRef.ownerDocument;
|
|
322696
|
+
}
|
|
322697
|
+
|
|
322698
|
+
if (this.currentDoc.defaultView) {
|
|
322699
|
+
this.currentWindow = this.currentDoc.defaultView;
|
|
322700
|
+
}
|
|
322701
|
+
|
|
322702
|
+
this.currentWindow.addEventListener('resize', this.computeSizes);
|
|
322703
|
+
this.props.zoomWithScroll && this.containerRef.addEventListener('wheel', this.onWheel, {
|
|
322704
|
+
passive: false
|
|
322705
|
+
});
|
|
322706
|
+
this.containerRef.addEventListener('gesturestart', this.preventZoomSafari);
|
|
322707
|
+
this.containerRef.addEventListener('gesturechange', this.preventZoomSafari);
|
|
322708
|
+
}
|
|
322709
|
+
|
|
322710
|
+
if (!this.props.disableAutomaticStylesInjection) {
|
|
322711
|
+
this.styleRef = this.currentDoc.createElement('style');
|
|
322712
|
+
this.styleRef.setAttribute('type', 'text/css');
|
|
322713
|
+
|
|
322714
|
+
if (this.props.nonce) {
|
|
322715
|
+
this.styleRef.setAttribute('nonce', this.props.nonce);
|
|
322716
|
+
}
|
|
322717
|
+
|
|
322718
|
+
this.styleRef.innerHTML = css_248z;
|
|
322719
|
+
this.currentDoc.head.appendChild(this.styleRef);
|
|
322720
|
+
} // when rendered via SSR, the image can already be loaded and its onLoad callback will never be called
|
|
322721
|
+
|
|
322722
|
+
|
|
322723
|
+
if (this.imageRef.current && this.imageRef.current.complete) {
|
|
322724
|
+
this.onMediaLoad();
|
|
322725
|
+
} // set image and video refs in the parent if the callbacks exist
|
|
322726
|
+
|
|
322727
|
+
|
|
322728
|
+
if (this.props.setImageRef) {
|
|
322729
|
+
this.props.setImageRef(this.imageRef);
|
|
322730
|
+
}
|
|
322731
|
+
|
|
322732
|
+
if (this.props.setVideoRef) {
|
|
322733
|
+
this.props.setVideoRef(this.videoRef);
|
|
322734
|
+
}
|
|
322735
|
+
};
|
|
322736
|
+
|
|
322737
|
+
Cropper.prototype.componentWillUnmount = function () {
|
|
322738
|
+
var _a;
|
|
322739
|
+
|
|
322740
|
+
this.currentWindow.removeEventListener('resize', this.computeSizes);
|
|
322741
|
+
|
|
322742
|
+
if (this.containerRef) {
|
|
322743
|
+
this.containerRef.removeEventListener('gesturestart', this.preventZoomSafari);
|
|
322744
|
+
this.containerRef.removeEventListener('gesturechange', this.preventZoomSafari);
|
|
322745
|
+
}
|
|
322746
|
+
|
|
322747
|
+
if (this.styleRef) {
|
|
322748
|
+
(_a = this.styleRef.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.styleRef);
|
|
322749
|
+
}
|
|
322750
|
+
|
|
322751
|
+
this.cleanEvents();
|
|
322752
|
+
this.props.zoomWithScroll && this.clearScrollEvent();
|
|
322753
|
+
};
|
|
322754
|
+
|
|
322755
|
+
Cropper.prototype.componentDidUpdate = function (prevProps) {
|
|
322756
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
322757
|
+
|
|
322758
|
+
if (prevProps.rotation !== this.props.rotation) {
|
|
322759
|
+
this.computeSizes();
|
|
322760
|
+
this.recomputeCropPosition();
|
|
322761
|
+
} else if (prevProps.aspect !== this.props.aspect) {
|
|
322762
|
+
this.computeSizes();
|
|
322763
|
+
} else if (prevProps.zoom !== this.props.zoom) {
|
|
322764
|
+
this.recomputeCropPosition();
|
|
322765
|
+
} else if (((_a = prevProps.cropSize) === null || _a === void 0 ? void 0 : _a.height) !== ((_b = this.props.cropSize) === null || _b === void 0 ? void 0 : _b.height) || ((_c = prevProps.cropSize) === null || _c === void 0 ? void 0 : _c.width) !== ((_d = this.props.cropSize) === null || _d === void 0 ? void 0 : _d.width)) {
|
|
322766
|
+
this.computeSizes();
|
|
322767
|
+
} else if (((_e = prevProps.crop) === null || _e === void 0 ? void 0 : _e.x) !== ((_f = this.props.crop) === null || _f === void 0 ? void 0 : _f.x) || ((_g = prevProps.crop) === null || _g === void 0 ? void 0 : _g.y) !== ((_h = this.props.crop) === null || _h === void 0 ? void 0 : _h.y)) {
|
|
322768
|
+
this.emitCropAreaChange();
|
|
322769
|
+
}
|
|
322770
|
+
|
|
322771
|
+
if (prevProps.zoomWithScroll !== this.props.zoomWithScroll && this.containerRef) {
|
|
322772
|
+
this.props.zoomWithScroll ? this.containerRef.addEventListener('wheel', this.onWheel, {
|
|
322773
|
+
passive: false
|
|
322774
|
+
}) : this.clearScrollEvent();
|
|
322775
|
+
}
|
|
322776
|
+
|
|
322777
|
+
if (prevProps.video !== this.props.video) {
|
|
322778
|
+
(_j = this.videoRef.current) === null || _j === void 0 ? void 0 : _j.load();
|
|
322779
|
+
}
|
|
322780
|
+
};
|
|
322781
|
+
|
|
322782
|
+
Cropper.prototype.getAspect = function () {
|
|
322783
|
+
var _a = this.props,
|
|
322784
|
+
cropSize = _a.cropSize,
|
|
322785
|
+
aspect = _a.aspect;
|
|
322786
|
+
|
|
322787
|
+
if (cropSize) {
|
|
322788
|
+
return cropSize.width / cropSize.height;
|
|
322789
|
+
}
|
|
322790
|
+
|
|
322791
|
+
return aspect;
|
|
322792
|
+
};
|
|
322793
|
+
|
|
322794
|
+
Cropper.prototype.onPinchStart = function (e) {
|
|
322795
|
+
var pointA = Cropper.getTouchPoint(e.touches[0]);
|
|
322796
|
+
var pointB = Cropper.getTouchPoint(e.touches[1]);
|
|
322797
|
+
this.lastPinchDistance = getDistanceBetweenPoints(pointA, pointB);
|
|
322798
|
+
this.lastPinchRotation = getRotationBetweenPoints(pointA, pointB);
|
|
322799
|
+
this.onDragStart(getCenter(pointA, pointB));
|
|
322800
|
+
};
|
|
322801
|
+
|
|
322802
|
+
Cropper.prototype.onPinchMove = function (e) {
|
|
322803
|
+
var _this = this;
|
|
322804
|
+
|
|
322805
|
+
var pointA = Cropper.getTouchPoint(e.touches[0]);
|
|
322806
|
+
var pointB = Cropper.getTouchPoint(e.touches[1]);
|
|
322807
|
+
var center = getCenter(pointA, pointB);
|
|
322808
|
+
this.onDrag(center);
|
|
322809
|
+
if (this.rafPinchTimeout) this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout);
|
|
322810
|
+
this.rafPinchTimeout = this.currentWindow.requestAnimationFrame(function () {
|
|
322811
|
+
var distance = getDistanceBetweenPoints(pointA, pointB);
|
|
322812
|
+
var newZoom = _this.props.zoom * (distance / _this.lastPinchDistance);
|
|
322813
|
+
|
|
322814
|
+
_this.setNewZoom(newZoom, center, {
|
|
322815
|
+
shouldUpdatePosition: false
|
|
322816
|
+
});
|
|
322817
|
+
|
|
322818
|
+
_this.lastPinchDistance = distance;
|
|
322819
|
+
var rotation = getRotationBetweenPoints(pointA, pointB);
|
|
322820
|
+
var newRotation = _this.props.rotation + (rotation - _this.lastPinchRotation);
|
|
322821
|
+
_this.props.onRotationChange && _this.props.onRotationChange(newRotation);
|
|
322822
|
+
_this.lastPinchRotation = rotation;
|
|
322823
|
+
});
|
|
322824
|
+
};
|
|
322825
|
+
|
|
322826
|
+
Cropper.prototype.render = function () {
|
|
322827
|
+
var _this = this;
|
|
322828
|
+
|
|
322829
|
+
var _a = this.props,
|
|
322830
|
+
image = _a.image,
|
|
322831
|
+
video = _a.video,
|
|
322832
|
+
mediaProps = _a.mediaProps,
|
|
322833
|
+
transform = _a.transform,
|
|
322834
|
+
_b = _a.crop,
|
|
322835
|
+
x = _b.x,
|
|
322836
|
+
y = _b.y,
|
|
322837
|
+
rotation = _a.rotation,
|
|
322838
|
+
zoom = _a.zoom,
|
|
322839
|
+
cropShape = _a.cropShape,
|
|
322840
|
+
showGrid = _a.showGrid,
|
|
322841
|
+
_c = _a.style,
|
|
322842
|
+
containerStyle = _c.containerStyle,
|
|
322843
|
+
cropAreaStyle = _c.cropAreaStyle,
|
|
322844
|
+
mediaStyle = _c.mediaStyle,
|
|
322845
|
+
_d = _a.classes,
|
|
322846
|
+
containerClassName = _d.containerClassName,
|
|
322847
|
+
cropAreaClassName = _d.cropAreaClassName,
|
|
322848
|
+
mediaClassName = _d.mediaClassName,
|
|
322849
|
+
objectFit = _a.objectFit;
|
|
322850
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
322851
|
+
onMouseDown: this.onMouseDown,
|
|
322852
|
+
onTouchStart: this.onTouchStart,
|
|
322853
|
+
ref: function ref(el) {
|
|
322854
|
+
return _this.containerRef = el;
|
|
322855
|
+
},
|
|
322856
|
+
"data-testid": "container",
|
|
322857
|
+
style: containerStyle,
|
|
322858
|
+
className: classNames('reactEasyCrop_Container', containerClassName)
|
|
322859
|
+
}, image ? /*#__PURE__*/React__default['default'].createElement("img", __assign$2({
|
|
322860
|
+
alt: "",
|
|
322861
|
+
className: classNames('reactEasyCrop_Image', objectFit === 'contain' && 'reactEasyCrop_Contain', objectFit === 'horizontal-cover' && 'reactEasyCrop_Cover_Horizontal', objectFit === 'vertical-cover' && 'reactEasyCrop_Cover_Vertical', objectFit === 'auto-cover' && (this.mediaSize.naturalWidth > this.mediaSize.naturalHeight ? 'reactEasyCrop_Cover_Horizontal' : 'reactEasyCrop_Cover_Vertical'), mediaClassName)
|
|
322862
|
+
}, mediaProps, {
|
|
322863
|
+
src: image,
|
|
322864
|
+
ref: this.imageRef,
|
|
322865
|
+
style: __assign$2(__assign$2({}, mediaStyle), {
|
|
322866
|
+
transform: transform || "translate(" + x + "px, " + y + "px) rotate(" + rotation + "deg) scale(" + zoom + ")"
|
|
322867
|
+
}),
|
|
322868
|
+
onLoad: this.onMediaLoad
|
|
322869
|
+
})) : video && /*#__PURE__*/React__default['default'].createElement("video", __assign$2({
|
|
322870
|
+
autoPlay: true,
|
|
322871
|
+
loop: true,
|
|
322872
|
+
muted: true,
|
|
322873
|
+
className: classNames('reactEasyCrop_Video', objectFit === 'contain' && 'reactEasyCrop_Contain', objectFit === 'horizontal-cover' && 'reactEasyCrop_Cover_Horizontal', objectFit === 'vertical-cover' && 'reactEasyCrop_Cover_Vertical', objectFit === 'auto-cover' && (this.mediaSize.naturalWidth > this.mediaSize.naturalHeight ? 'reactEasyCrop_Cover_Horizontal' : 'reactEasyCrop_Cover_Vertical'), mediaClassName)
|
|
322874
|
+
}, mediaProps, {
|
|
322875
|
+
ref: this.videoRef,
|
|
322876
|
+
onLoadedMetadata: this.onMediaLoad,
|
|
322877
|
+
style: __assign$2(__assign$2({}, mediaStyle), {
|
|
322878
|
+
transform: transform || "translate(" + x + "px, " + y + "px) rotate(" + rotation + "deg) scale(" + zoom + ")"
|
|
322879
|
+
}),
|
|
322880
|
+
controls: false
|
|
322881
|
+
}), (Array.isArray(video) ? video : [{
|
|
322882
|
+
src: video
|
|
322883
|
+
}]).map(function (item) {
|
|
322884
|
+
return /*#__PURE__*/React__default['default'].createElement("source", __assign$2({
|
|
322885
|
+
key: item.src
|
|
322886
|
+
}, item));
|
|
322887
|
+
})), this.state.cropSize && /*#__PURE__*/React__default['default'].createElement("div", {
|
|
322888
|
+
style: __assign$2(__assign$2({}, cropAreaStyle), {
|
|
322889
|
+
width: this.state.cropSize.width,
|
|
322890
|
+
height: this.state.cropSize.height
|
|
322891
|
+
}),
|
|
322892
|
+
"data-testid": "cropper",
|
|
322893
|
+
className: classNames('reactEasyCrop_CropArea', cropShape === 'round' && 'reactEasyCrop_CropAreaRound', showGrid && 'reactEasyCrop_CropAreaGrid', cropAreaClassName)
|
|
322894
|
+
}));
|
|
322895
|
+
};
|
|
322896
|
+
|
|
322897
|
+
Cropper.defaultProps = {
|
|
322898
|
+
zoom: 1,
|
|
322899
|
+
rotation: 0,
|
|
322900
|
+
aspect: 4 / 3,
|
|
322901
|
+
maxZoom: MAX_ZOOM,
|
|
322902
|
+
minZoom: MIN_ZOOM,
|
|
322903
|
+
cropShape: 'rect',
|
|
322904
|
+
objectFit: 'contain',
|
|
322905
|
+
showGrid: true,
|
|
322906
|
+
style: {},
|
|
322907
|
+
classes: {},
|
|
322908
|
+
mediaProps: {},
|
|
322909
|
+
zoomSpeed: 1,
|
|
322910
|
+
restrictPosition: true,
|
|
322911
|
+
zoomWithScroll: true
|
|
322912
|
+
};
|
|
322913
|
+
|
|
322914
|
+
Cropper.getMousePoint = function (e) {
|
|
322915
|
+
return {
|
|
322916
|
+
x: Number(e.clientX),
|
|
322917
|
+
y: Number(e.clientY)
|
|
322918
|
+
};
|
|
322919
|
+
};
|
|
322920
|
+
|
|
322921
|
+
Cropper.getTouchPoint = function (touch) {
|
|
322922
|
+
return {
|
|
322923
|
+
x: Number(touch.clientX),
|
|
322924
|
+
y: Number(touch.clientY)
|
|
322925
|
+
};
|
|
322926
|
+
};
|
|
322927
|
+
|
|
322928
|
+
return Cropper;
|
|
322929
|
+
}(React__default['default'].Component);
|
|
322930
|
+
|
|
322931
|
+
var Index$b = function Index(_ref) {
|
|
322932
|
+
var instance = _ref.instance;
|
|
322933
|
+
var state = instance.state,
|
|
322934
|
+
imgURL = instance.imgURL,
|
|
322935
|
+
setTransform = instance.setTransform,
|
|
322936
|
+
minZoom = instance.minZoom,
|
|
322937
|
+
zoomSpeed = instance.zoomSpeed,
|
|
322938
|
+
aspect = instance.aspect,
|
|
322939
|
+
cropSize = instance.cropSize;
|
|
322940
|
+
var onCropComplete = React.useCallback(function (croppedArea, croppedAreaPixels) {
|
|
322941
|
+
// console.log('croppedArea:', croppedArea, 'croppedAreaPixels:', croppedAreaPixels)
|
|
322942
|
+
setTransform({
|
|
322943
|
+
croppedAreaPixels: croppedAreaPixels
|
|
322944
|
+
});
|
|
322945
|
+
}, [setTransform]);
|
|
322946
|
+
var cropConfig = {
|
|
322947
|
+
minZoom: minZoom,
|
|
322948
|
+
zoomSpeed: zoomSpeed,
|
|
322949
|
+
aspect: aspect,
|
|
322950
|
+
cropSize: cropSize
|
|
322951
|
+
};
|
|
322952
|
+
return /*#__PURE__*/React__default['default'].createElement("div", {
|
|
322953
|
+
className: "lm_cutimg_crop"
|
|
322954
|
+
}, /*#__PURE__*/React__default['default'].createElement(Cropper, _objectSpread(_objectSpread({}, cropConfig), {}, {
|
|
322955
|
+
image: imgURL,
|
|
322956
|
+
crop: state.crop,
|
|
322957
|
+
zoom: state.zoom,
|
|
322958
|
+
rotation: state.rotation,
|
|
322959
|
+
onCropChange: function onCropChange(crop) {
|
|
322960
|
+
return setTransform({
|
|
322961
|
+
crop: crop
|
|
322962
|
+
});
|
|
322963
|
+
},
|
|
322964
|
+
onCropComplete: onCropComplete,
|
|
322965
|
+
onZoomChange: function onZoomChange(zoom) {
|
|
322966
|
+
return setTransform({
|
|
322967
|
+
zoom: zoom
|
|
322968
|
+
});
|
|
322969
|
+
}
|
|
322970
|
+
})));
|
|
322971
|
+
};
|
|
322972
|
+
|
|
322973
|
+
var Body$1 = /*#__PURE__*/React__default['default'].memo(Index$b);
|
|
322974
|
+
|
|
322975
|
+
var _excluded$37 = ["value", "onChange", "leftIcon", "rightIcon"];
|
|
322976
|
+
|
|
322977
|
+
var ResetSlider = function ResetSlider(_ref) {
|
|
322978
|
+
var value = _ref.value,
|
|
322979
|
+
_onChange = _ref.onChange,
|
|
322980
|
+
leftIcon = _ref.leftIcon,
|
|
322981
|
+
rightIcon = _ref.rightIcon,
|
|
322982
|
+
props = _objectWithoutProperties$1(_ref, _excluded$37);
|
|
322983
|
+
|
|
322984
|
+
// 减
|
|
322985
|
+
var decrement = function decrement() {
|
|
322986
|
+
if (!(value > props.min)) return;
|
|
322987
|
+
var nValue = Math.round(value * 100 - props.step * 100) / 100;
|
|
322988
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(nValue);
|
|
322989
|
+
}; // 增
|
|
322990
|
+
|
|
322991
|
+
|
|
322992
|
+
var increment = function increment() {
|
|
322993
|
+
if (!(value < props.max)) return;
|
|
322994
|
+
var nValue = Math.round(value * 100 + props.step * 100) / 100;
|
|
322995
|
+
_onChange === null || _onChange === void 0 ? void 0 : _onChange(nValue);
|
|
322996
|
+
};
|
|
322997
|
+
|
|
322998
|
+
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(IconFont, {
|
|
322999
|
+
type: leftIcon,
|
|
323000
|
+
onClick: decrement
|
|
323001
|
+
}), /*#__PURE__*/React__default['default'].createElement(Slider$1, _objectSpread(_objectSpread({}, props), {}, {
|
|
323002
|
+
value: value,
|
|
323003
|
+
onChange: function onChange(val) {
|
|
323004
|
+
return _onChange(val);
|
|
323005
|
+
}
|
|
323006
|
+
})), /*#__PURE__*/React__default['default'].createElement(IconFont, {
|
|
323007
|
+
type: rightIcon,
|
|
323008
|
+
onClick: increment
|
|
323009
|
+
}));
|
|
323010
|
+
}; // 图片调整
|
|
323011
|
+
|
|
323012
|
+
|
|
323013
|
+
var Operate = function Operate(_ref2) {
|
|
323014
|
+
var instance = _ref2.instance;
|
|
323015
|
+
var state = instance.state,
|
|
323016
|
+
setTransform = instance.setTransform;
|
|
323017
|
+
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("div", {
|
|
323018
|
+
className: "img_crop_control"
|
|
323019
|
+
}, /*#__PURE__*/React__default['default'].createElement(ResetSlider, {
|
|
323020
|
+
value: state.zoom,
|
|
323021
|
+
onChange: function onChange(zoom) {
|
|
323022
|
+
return setTransform({
|
|
323023
|
+
zoom: zoom
|
|
323024
|
+
});
|
|
323025
|
+
},
|
|
323026
|
+
defaultValue: 1,
|
|
323027
|
+
leftIcon: "lmweb-minus",
|
|
323028
|
+
rightIcon: "lmweb-plus",
|
|
323029
|
+
step: 0.1,
|
|
323030
|
+
min: 0.1,
|
|
323031
|
+
max: 3
|
|
323032
|
+
})), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
323033
|
+
className: "img_crop_control"
|
|
323034
|
+
}, /*#__PURE__*/React__default['default'].createElement(ResetSlider, {
|
|
323035
|
+
value: state.rotation,
|
|
323036
|
+
onChange: function onChange(rotation) {
|
|
323037
|
+
return setTransform({
|
|
323038
|
+
rotation: rotation
|
|
323039
|
+
});
|
|
323040
|
+
},
|
|
323041
|
+
defaultValue: 0,
|
|
323042
|
+
leftIcon: "lmweb-rotate-left",
|
|
323043
|
+
rightIcon: "lmweb-rotate-right",
|
|
323044
|
+
step: 1,
|
|
323045
|
+
min: -180,
|
|
323046
|
+
max: 180
|
|
323047
|
+
})));
|
|
323048
|
+
};
|
|
323049
|
+
|
|
323050
|
+
var Operate$1 = /*#__PURE__*/React__default['default'].memo(Operate);
|
|
323051
|
+
|
|
323052
|
+
var LmBoxContainer = function LmBoxContainer(_ref) {
|
|
323053
|
+
var instance = _ref.instance;
|
|
323054
|
+
var visible = instance.visible,
|
|
323055
|
+
onClose = instance.onClose,
|
|
323056
|
+
state = instance.state,
|
|
323057
|
+
dispatch = instance.dispatch,
|
|
323058
|
+
getCropImageAsync = instance.getCropImageAsync,
|
|
323059
|
+
file = instance.file;
|
|
323060
|
+
var boxContainerRef = React.useRef(null); // 关闭时初始化
|
|
323061
|
+
|
|
323062
|
+
var handleClose = function handleClose(blobFile) {
|
|
323063
|
+
dispatch({
|
|
323064
|
+
type: 'changeResult',
|
|
323065
|
+
result: {
|
|
323066
|
+
visible: false
|
|
323067
|
+
}
|
|
323068
|
+
});
|
|
323069
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(blobFile, file);
|
|
323070
|
+
};
|
|
323071
|
+
|
|
323072
|
+
var handleOk = /*#__PURE__*/function () {
|
|
323073
|
+
var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
|
|
323074
|
+
var croppedImage;
|
|
323075
|
+
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
323076
|
+
while (1) {
|
|
323077
|
+
switch (_context.prev = _context.next) {
|
|
323078
|
+
case 0:
|
|
323079
|
+
_context.next = 2;
|
|
323080
|
+
return getCropImageAsync();
|
|
323081
|
+
|
|
323082
|
+
case 2:
|
|
323083
|
+
croppedImage = _context.sent;
|
|
323084
|
+
dispatch({
|
|
323085
|
+
type: 'changeResult',
|
|
323086
|
+
result: {
|
|
323087
|
+
croppedImage: croppedImage
|
|
323088
|
+
}
|
|
323089
|
+
});
|
|
323090
|
+
handleClose(croppedImage);
|
|
323091
|
+
|
|
323092
|
+
case 5:
|
|
323093
|
+
case "end":
|
|
323094
|
+
return _context.stop();
|
|
323095
|
+
}
|
|
323096
|
+
}
|
|
323097
|
+
}, _callee);
|
|
323098
|
+
}));
|
|
323099
|
+
|
|
323100
|
+
return function handleOk() {
|
|
323101
|
+
return _ref2.apply(this, arguments);
|
|
323102
|
+
};
|
|
323103
|
+
}();
|
|
323104
|
+
|
|
323105
|
+
var config = {
|
|
323106
|
+
title: '编辑图片',
|
|
323107
|
+
open: visible !== null && visible !== void 0 ? visible : state.visible,
|
|
323108
|
+
onCancel: function onCancel() {
|
|
323109
|
+
return handleClose(false);
|
|
323110
|
+
},
|
|
323111
|
+
onOk: handleOk
|
|
323112
|
+
};
|
|
323113
|
+
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(LMModal, _objectSpread({}, config), /*#__PURE__*/React__default['default'].createElement("div", {
|
|
323114
|
+
ref: boxContainerRef,
|
|
323115
|
+
className: "lm_cutimg_container"
|
|
323116
|
+
}, /*#__PURE__*/React__default['default'].createElement(Body$1, {
|
|
323117
|
+
instance: instance
|
|
323118
|
+
}), /*#__PURE__*/React__default['default'].createElement(Operate$1, {
|
|
323119
|
+
instance: instance
|
|
323120
|
+
}))));
|
|
323121
|
+
};
|
|
323122
|
+
|
|
323123
|
+
var Container$2 = /*#__PURE__*/React__default['default'].memo(LmBoxContainer);
|
|
323124
|
+
|
|
323125
|
+
var Wrapper = function Wrapper(_ref) {
|
|
323126
|
+
var instance = _ref.instance;
|
|
323127
|
+
return /*#__PURE__*/React__default['default'].createElement(Container$2, {
|
|
323128
|
+
instance: instance
|
|
323129
|
+
});
|
|
323130
|
+
};
|
|
323131
|
+
|
|
323132
|
+
var Wrapper$1 = /*#__PURE__*/React__default['default'].memo(Wrapper);
|
|
323133
|
+
|
|
323134
|
+
var LmBox = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
323135
|
+
var initialState = React.useMemo(function () {
|
|
323136
|
+
return initialState$4();
|
|
323137
|
+
}, []);
|
|
323138
|
+
|
|
323139
|
+
var _useReducer = React.useReducer(reducer$6, initialState),
|
|
323140
|
+
_useReducer2 = _slicedToArray$1(_useReducer, 2),
|
|
323141
|
+
state = _useReducer2[0],
|
|
323142
|
+
dispatch = _useReducer2[1]; // 获取核心Methods
|
|
323143
|
+
|
|
323144
|
+
|
|
323145
|
+
var _useCoreOptions = useCoreOptions$3({
|
|
323146
|
+
state: state,
|
|
323147
|
+
dispatch: dispatch,
|
|
323148
|
+
props: props
|
|
323149
|
+
}),
|
|
323150
|
+
CoreMethds = _useCoreOptions.CoreMethds,
|
|
323151
|
+
RefMethods = _useCoreOptions.RefMethods; // 组件实例
|
|
323152
|
+
|
|
323153
|
+
|
|
323154
|
+
var instance = React.useMemo(function () {
|
|
323155
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props), CoreMethds), RefMethods), {}, {
|
|
323156
|
+
state: state,
|
|
323157
|
+
dispatch: dispatch
|
|
323158
|
+
});
|
|
323159
|
+
}, [props, RefMethods, state, dispatch]); // 向外暴露出的方法
|
|
323160
|
+
|
|
323161
|
+
React.useImperativeHandle(ref, function () {
|
|
323162
|
+
return _objectSpread({
|
|
323163
|
+
getState: function getState() {
|
|
323164
|
+
return state;
|
|
323165
|
+
}
|
|
323166
|
+
}, RefMethods);
|
|
323167
|
+
});
|
|
323168
|
+
return /*#__PURE__*/React__default['default'].createElement(Wrapper$1, {
|
|
323169
|
+
instance: instance
|
|
323170
|
+
});
|
|
323171
|
+
});
|
|
323172
|
+
|
|
323173
|
+
var CropImg = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
323174
|
+
var defaultRef = React.useRef(null);
|
|
323175
|
+
|
|
323176
|
+
var defaultProps = _objectSpread({
|
|
323177
|
+
visible: null,
|
|
323178
|
+
file: null,
|
|
323179
|
+
minZoom: 0.1,
|
|
323180
|
+
zoomSpeed: 0.2,
|
|
323181
|
+
aspect: 4 / 3,
|
|
323182
|
+
cropSize: null
|
|
323183
|
+
}, props);
|
|
323184
|
+
|
|
323185
|
+
return /*#__PURE__*/React__default['default'].createElement(LmBox, _objectSpread({
|
|
323186
|
+
ref: ref || defaultRef
|
|
323187
|
+
}, defaultProps));
|
|
323188
|
+
});
|
|
323189
|
+
|
|
320690
323190
|
exports.Alert = Alert$1;
|
|
320691
323191
|
exports.Approval = LMApproval;
|
|
320692
323192
|
exports.AutoComplete = RefAutoComplete$1;
|
|
@@ -320704,6 +323204,7 @@
|
|
|
320704
323204
|
exports.Collapse = Collapse$1;
|
|
320705
323205
|
exports.Comment = Comment;
|
|
320706
323206
|
exports.ConfigProvider = ConfigProvider$1;
|
|
323207
|
+
exports.CropImg = CropImg;
|
|
320707
323208
|
exports.CustomTableOption = LMCustomTableOption;
|
|
320708
323209
|
exports.CustomerService = CustomerService;
|
|
320709
323210
|
exports.DatePicker = DatePicker$1;
|
|
@@ -320729,6 +323230,7 @@
|
|
|
320729
323230
|
exports.List = List$2;
|
|
320730
323231
|
exports.LmEditTable = LmEditTable;
|
|
320731
323232
|
exports.LmFilter = LmFilter$2;
|
|
323233
|
+
exports.LmImgList = LmImgList;
|
|
320732
323234
|
exports.LmSelect = LMSelect;
|
|
320733
323235
|
exports.LmTable = Table$2;
|
|
320734
323236
|
exports.LmUpload = LmUpload$2;
|