@lm_fe/components 0.2.2
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/README.md +47 -0
- package/dist/keep-alive/common.d.ts +46 -0
- package/dist/keep-alive/components/AsyncComponent.d.ts +27 -0
- package/dist/keep-alive/components/Comment.d.ts +18 -0
- package/dist/keep-alive/components/Consumer.d.ts +20 -0
- package/dist/keep-alive/components/keepAlive.d.ts +4 -0
- package/dist/keep-alive/components/provider.d.ts +31 -0
- package/dist/keep-alive/contexts/IdentificationContext.d.ts +12 -0
- package/dist/keep-alive/contexts/KeepAliveContext.d.ts +5 -0
- package/dist/keep-alive/index.d.ts +7 -0
- package/dist/keep-alive/index.js +1901 -0
- package/dist/keep-alive/utils/bindLifecycle.d.ts +3 -0
- package/dist/keep-alive/utils/changePositionByComment.d.ts +1 -0
- package/dist/keep-alive/utils/createEventEmitter.d.ts +11 -0
- package/dist/keep-alive/utils/createStoreElement.d.ts +1 -0
- package/dist/keep-alive/utils/createUniqueIdentification.d.ts +8 -0
- package/dist/keep-alive/utils/debug.d.ts +3 -0
- package/dist/keep-alive/utils/getDisplayName.d.ts +2 -0
- package/dist/keep-alive/utils/getKeepAlive.d.ts +3 -0
- package/dist/keep-alive/utils/getKeyByFiberNode.d.ts +1 -0
- package/dist/keep-alive/utils/isRegExp.d.ts +1 -0
- package/dist/keep-alive/utils/keepAliveDecorator.d.ts +17 -0
- package/dist/keep-alive/utils/md5.d.ts +1 -0
- package/dist/keep-alive/utils/noop.d.ts +2 -0
- package/dist/keep-alive/utils/shallowEqual.d.ts +2 -0
- package/dist/keep-alive/utils/useKeepAliveEffect.d.ts +2 -0
- package/dist/keep-alive/utils/withIdentificationContextConsumer.d.ts +10 -0
- package/dist/keep-alive/utils/withKeepAliveContextConsumer.d.ts +10 -0
- package/dist/src/ArraySingle/Inner.d.ts +3 -0
- package/dist/src/ArraySingle/index.d.ts +2 -0
- package/dist/src/CaseTempleteEdit/Inner.d.ts +4 -0
- package/dist/src/CaseTempleteEdit/config.d.ts +20 -0
- package/dist/src/CaseTempleteEdit/index.d.ts +4 -0
- package/dist/src/CaseTempleteEdit/types.d.ts +19 -0
- package/dist/src/CaseTempleteEdit/utils.d.ts +2 -0
- package/dist/src/CaseTempleteEditEmr/Inner.d.ts +3 -0
- package/dist/src/CaseTempleteEditEmr/demo_text.d.ts +1 -0
- package/dist/src/CaseTempleteEditEmr/index.d.ts +2 -0
- package/dist/src/CaseTempleteEditEmr/types.d.ts +6 -0
- package/dist/src/CaseTempleteEditEmr/utils.d.ts +3 -0
- package/dist/src/ContainerDimensions/index.d.ts +10 -0
- package/dist/src/GlobalModal/index.d.ts +8 -0
- package/dist/src/GlobalModal/utils.d.ts +65 -0
- package/dist/src/Monaco/Inner.d.ts +12 -0
- package/dist/src/Monaco/index.d.ts +1 -0
- package/dist/src/MyAddress/Inner.d.ts +3 -0
- package/dist/src/MyAddress/Old/InnerOld.d.ts +3 -0
- package/dist/src/MyAddress/Old/index.d.ts +3 -0
- package/dist/src/MyAddress/Old/options.d.ts +25 -0
- package/dist/src/MyAddress/index.d.ts +6 -0
- package/dist/src/MyAddress/type.d.ts +16 -0
- package/dist/src/MyAddress/utils.d.ts +6 -0
- package/dist/src/MyImageEditor/Inner.d.ts +4 -0
- package/dist/src/MyImageEditor/index.d.ts +16 -0
- package/dist/src/MyImageEditor/init_delete_control.d.ts +1 -0
- package/dist/src/MyImageEditor/utils.d.ts +36 -0
- package/dist/src/MyInput/index.d.ts +5 -0
- package/dist/src/MyInput/types.d.ts +9 -0
- package/dist/src/MyLazyComponent/index.d.ts +6 -0
- package/dist/src/PDF_Frame_View/Inner.d.ts +3 -0
- package/dist/src/PDF_Frame_View/index.d.ts +5 -0
- package/dist/src/PDF_Frame_View/types.d.ts +32 -0
- package/dist/src/PDF_Frame_View/utils.d.ts +9 -0
- package/dist/src/PatientSelect/Inner.d.ts +16 -0
- package/dist/src/PatientSelect/index.d.ts +3 -0
- package/dist/src/SimpleForm/Inner.d.ts +5 -0
- package/dist/src/SimpleForm/components/TabForm/index.d.ts +15 -0
- package/dist/src/SimpleForm/components/extra/Custom.d.ts +8 -0
- package/dist/src/SimpleForm/components/extra/MultiInput.d.ts +6 -0
- package/dist/src/SimpleForm/components/extra/SimpleSelect.d.ts +6 -0
- package/dist/src/SimpleForm/components/extra/SwitchSelect.d.ts +4 -0
- package/dist/src/SimpleForm/components/index.d.ts +34 -0
- package/dist/src/SimpleForm/index.d.ts +17 -0
- package/dist/src/SimpleForm/types/help.d.ts +3 -0
- package/dist/src/SimpleForm/types/metaTypes.d.ts +29 -0
- package/dist/src/SimpleForm/types.d.ts +24 -0
- package/dist/src/a_chunks/index.js +550 -0
- package/dist/src/a_chunks/root..js +187 -0
- package/dist/src/a_chunks/root.2.js +318 -0
- package/dist/src/a_chunks/root.3.js +622 -0
- package/dist/src/a_chunks/root.4.js +235 -0
- package/dist/src/a_chunks/root.5.js +156 -0
- package/dist/src/a_chunks/root.6.js +310 -0
- package/dist/src/a_chunks/root.7.js +867 -0
- package/dist/src/a_chunks/root.8.js +281 -0
- package/dist/src/a_chunks/root.9.js +19 -0
- package/dist/src/a_chunks/style-inject.es.js +25 -0
- package/dist/src/config.d.ts +1 -0
- package/dist/src/hooks/index.d.ts +3 -0
- package/dist/src/hooks/useMchcDriverStatus.d.ts +3 -0
- package/dist/src/hooks/useMyEffect.d.ts +4 -0
- package/dist/src/hooks/use_fuck.d.ts +5 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +10 -0
- package/dist/src/pack_components.d.ts +213 -0
- package/dist/src/style/index.d.ts +1 -0
- package/dist/src/utils/getInputStyle.d.ts +1 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/other.d.ts +3 -0
- package/package.json +67 -0
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { mchcEnv, mchcLogger, mchcEvent } from '@lm_fe/env';
|
|
8
|
+
import { safe_json_parse, base64_to_image } from '@lm_fe/utils';
|
|
9
|
+
import { MyIcon, MyColor } from '@noah-libjs/components';
|
|
10
|
+
import { Switch, Layout, Popover, Button, Slider } from 'antd';
|
|
11
|
+
import classnames from 'classnames';
|
|
12
|
+
import { isString, get } from 'lodash';
|
|
13
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
14
|
+
import { s as styleInject } from './style-inject.es.js';
|
|
15
|
+
import { r as real_fabric, M as MyImageEditorEvents, e as event_process, f as default_legends } from './index.js';
|
|
16
|
+
import '@lm_fe/static';
|
|
17
|
+
import '@lm_fe/service';
|
|
18
|
+
import '@lm_fe/provoke';
|
|
19
|
+
var css_248z = ".index-module_custom-image-editor__RK-wE {\n width: 100%;\n overflow: hidden;\n margin-top: -460px;\n position: relative;\n border: 1px solid #eee;\n}\n.index-module_custom-image-editor__RK-wE .index-module_react-img-editor-container__RYAxl,\n.index-module_custom-image-editor__RK-wE .index-module_konvajs-content__6WYGJ,\n.index-module_custom-image-editor__RK-wE .index-module_react-img-editor__8luIM {\n width: 100% !important;\n}\n.index-module_custom-image-editor__RK-wE .index-module_react-img-editor-palette__Xvk4K {\n background: #fff;\n}\n.index-module_custom-image-editor-save__eA0OC {\n position: absolute;\n right: 20px;\n bottom: 30px;\n}\n.index-module_custom-image-editor__RK-wE .index-module_custom-image-editor-null__52KxO {\n width: 100%;\n height: 460px;\n}\n.index-module_custom-image-editor__RK-wE .index-module_react-img-editor-toolbar__ps2nI {\n margin-left: -200px;\n position: absolute;\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n height: auto;\n width: 36px !important;\n display: block;\n}\n.index-module_custom-image-editor__RK-wE .index-module_react-img-editor-toolbar-separator__GTqg8 {\n display: none;\n}\n.index-module_gy-image-editor__2PgAg {\n margin: 4px;\n background-color: #fff;\n}\n.index-module_gy-image-editor__2PgAg .index-module_box-img__f2Nx9 {\n width: 90px;\n height: 90px;\n border: 1px solid #d7dce7;\n position: relative;\n margin-top: 8px;\n margin-left: 7px;\n cursor: move;\n}\n.index-module_gy-image-editor__2PgAg .index-module_box-img__f2Nx9 img {\n width: auto;\n max-width: 100%;\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n}\n.index-module_gy-image-editor__2PgAg .index-module_box-text__valN7 {\n font-size: 12px;\n font-weight: 400;\n color: #828c99;\n line-height: 17px;\n text-align: center;\n}\n.index-module_gy-image-editor__2PgAg .ant-layout-sider {\n background: #fff;\n}\n.index-module_gy-image-editor__2PgAg .ant-layout {\n background: #fff;\n}\n.index-module_gy-image-editor__2PgAg #index-module_images__pRZ9O {\n overflow: hidden;\n clear: both;\n display: flex;\n flex-wrap: wrap;\n}\n.index-module_gy-image-editor__2PgAg #index-module_canvas-container__PuYZw {\n position: relative;\n}\n.index-module_gy-image-editor__2PgAg #index-module_canvas-container__PuYZw .index-module_tool-bar__kAiyj {\n position: absolute;\n right: 0;\n top: 50%;\n transform: translateY(-50%);\n width: 32px;\n height: auto;\n}\n.index-module_gy-image-editor__2PgAg #index-module_canvas-container__PuYZw .index-module_tool-bar__kAiyj .ant-btn {\n width: 24px;\n height: 24px;\n padding: 14px 0;\n border: none;\n}\n.index-module_gy-image-editor__2PgAg .index-module_button-icon__463Ga {\n display: inline-block;\n width: 18px;\n height: 18px;\n background-size: contain;\n background-repeat: no-repeat;\n background-position: center;\n}\n.index-module_gy-image-editor__2PgAg .index-module_back__MY6Kt {\n background-image: url(/lm_imgs/mie/back.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_forward__IDKoN {\n background-image: url(/lm_imgs/mie/forward.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_pen__GyJzG {\n background-image: url(/lm_imgs/mie/pen.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_text__LVtw7 {\n background-image: url(/lm_imgs/mie/text.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_rect__K6T6d {\n background-image: url(/lm_imgs/mie/rect.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_circle-icon2__XjPuI {\n background-image: url(/lm_imgs/mie/circle.svg);\n background-color: none;\n}\n.index-module_gy-image-editor__2PgAg .index-module_triangle__-PP0Y {\n background-image: url(/lm_imgs/mie/triangle.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_line__9-WZE {\n background-image: url(/lm_imgs/mie/line.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_clear__mXP-m {\n background-image: url(/lm_imgs/mie/clear.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_export__h9hhf {\n background-image: url(/lm_imgs/mie/export.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_selected__eAmsn {\n background-image: url(/lm_imgs/mie/selected.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_noselected__xuC3A {\n background-image: url(/lm_imgs/mie/no.svg);\n}\n.index-module_gy-image-editor__2PgAg .index-module_save__rtkNk {\n background-image: url(/lm_imgs/mie/save.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_back__MY6Kt {\n background-image: url(/lm_imgs/mie/back-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_forward__IDKoN {\n background-image: url(/lm_imgs/mie/forward-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_pen__GyJzG {\n background-image: url(/lm_imgs/mie/pen-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_text__LVtw7 {\n background-image: url(/lm_imgs/mie/text-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_rect__K6T6d {\n background-image: url(/lm_imgs/mie/rect-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_circle-icon2__XjPuI {\n background-image: url(/lm_imgs/mie/circle-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_triangle__-PP0Y {\n background-image: url(/lm_imgs/mie/triangle-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_line__9-WZE {\n background-image: url(/lm_imgs/mie/line-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_clear__mXP-m {\n background-image: url(/lm_imgs/mie/clear-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_export__h9hhf {\n background-image: url(/lm_imgs/mie/export-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_selected__eAmsn {\n background-image: url(/lm_imgs/mie/selected-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_noselected__xuC3A {\n background-image: url(/lm_imgs/mie/no-hover.svg);\n}\n.ant-btn:hover .ant-btn:focus .index-module_save__rtkNk {\n background-image: url(/lm_imgs/mie/save-hover.svg);\n}\n";
|
|
20
|
+
var styles = {
|
|
21
|
+
"custom-image-editor": "index-module_custom-image-editor__RK-wE",
|
|
22
|
+
"react-img-editor-container": "index-module_react-img-editor-container__RYAxl",
|
|
23
|
+
"konvajs-content": "index-module_konvajs-content__6WYGJ",
|
|
24
|
+
"react-img-editor": "index-module_react-img-editor__8luIM",
|
|
25
|
+
"react-img-editor-palette": "index-module_react-img-editor-palette__Xvk4K",
|
|
26
|
+
"custom-image-editor-save": "index-module_custom-image-editor-save__eA0OC",
|
|
27
|
+
"custom-image-editor-null": "index-module_custom-image-editor-null__52KxO",
|
|
28
|
+
"react-img-editor-toolbar": "index-module_react-img-editor-toolbar__ps2nI",
|
|
29
|
+
"react-img-editor-toolbar-separator": "index-module_react-img-editor-toolbar-separator__GTqg8",
|
|
30
|
+
"gy-image-editor": "index-module_gy-image-editor__2PgAg",
|
|
31
|
+
"box-img": "index-module_box-img__f2Nx9",
|
|
32
|
+
"box-text": "index-module_box-text__valN7",
|
|
33
|
+
"images": "index-module_images__pRZ9O",
|
|
34
|
+
"canvas-container": "index-module_canvas-container__PuYZw",
|
|
35
|
+
"tool-bar": "index-module_tool-bar__kAiyj",
|
|
36
|
+
"button-icon": "index-module_button-icon__463Ga",
|
|
37
|
+
"back": "index-module_back__MY6Kt",
|
|
38
|
+
"forward": "index-module_forward__IDKoN",
|
|
39
|
+
"pen": "index-module_pen__GyJzG",
|
|
40
|
+
"text": "index-module_text__LVtw7",
|
|
41
|
+
"rect": "index-module_rect__K6T6d",
|
|
42
|
+
"circle-icon2": "index-module_circle-icon2__XjPuI",
|
|
43
|
+
"triangle": "index-module_triangle__-PP0Y",
|
|
44
|
+
"line": "index-module_line__9-WZE",
|
|
45
|
+
"clear": "index-module_clear__mXP-m",
|
|
46
|
+
"export": "index-module_export__h9hhf",
|
|
47
|
+
"selected": "index-module_selected__eAmsn",
|
|
48
|
+
"noselected": "index-module_noselected__xuC3A",
|
|
49
|
+
"save": "index-module_save__rtkNk"
|
|
50
|
+
};
|
|
51
|
+
styleInject(css_248z);
|
|
52
|
+
function init_delete_control() {
|
|
53
|
+
// create a rect object
|
|
54
|
+
var deleteIcon = "data:image/svg+xml,%3C%3Fxml version='1.0' encoding='utf-8'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3E%3Csvg version='1.1' id='Ebene_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='595.275px' height='595.275px' viewBox='200 215 230 470' xml:space='preserve'%3E%3Ccircle style='fill:%23F44336;' cx='299.76' cy='439.067' r='218.516'/%3E%3Cg%3E%3Crect x='267.162' y='307.978' transform='matrix(0.7071 -0.7071 0.7071 0.7071 -222.6202 340.6915)' style='fill:white;' width='65.545' height='262.18'/%3E%3Crect x='266.988' y='308.153' transform='matrix(0.7071 0.7071 -0.7071 0.7071 398.3889 -83.3116)' style='fill:white;' width='65.544' height='262.179'/%3E%3C/g%3E%3C/svg%3E";
|
|
55
|
+
var img = document.createElement('img');
|
|
56
|
+
img.src = deleteIcon;
|
|
57
|
+
// real_fabric().Object.prototype.transparentCorners = false;
|
|
58
|
+
// real_fabric().Object.prototype.cornerColor = 'blue';
|
|
59
|
+
// real_fabric().Object.prototype.cornerStyle = 'circle';
|
|
60
|
+
real_fabric().Object.prototype.controls.deleteControl = new (real_fabric().Control)({
|
|
61
|
+
x: 0.5,
|
|
62
|
+
y: -0.5,
|
|
63
|
+
offsetY: 16,
|
|
64
|
+
offsetX: -16,
|
|
65
|
+
cursorStyle: 'pointer',
|
|
66
|
+
mouseUpHandler: function deleteObject(eventData, transform) {
|
|
67
|
+
var target = transform.target;
|
|
68
|
+
var canvas = target.canvas;
|
|
69
|
+
canvas === null || canvas === void 0 || canvas.remove(target);
|
|
70
|
+
canvas === null || canvas === void 0 || canvas.requestRenderAll();
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
render: function renderIcon(ctx, left, top, styleOverride, fabricObject) {
|
|
74
|
+
var size = 16;
|
|
75
|
+
ctx.save();
|
|
76
|
+
ctx.translate(left, top);
|
|
77
|
+
ctx.rotate(real_fabric().util.degreesToRadians(fabricObject.angle));
|
|
78
|
+
ctx.drawImage(img, -size / 2, -size / 2, size, size);
|
|
79
|
+
ctx.restore();
|
|
80
|
+
}
|
|
81
|
+
// cornerSize: 24
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
var Sider = Layout.Sider,
|
|
85
|
+
Content = Layout.Content;
|
|
86
|
+
function MyImageEditor_Inner(props) {
|
|
87
|
+
var _real_fabric;
|
|
88
|
+
var value = props.value,
|
|
89
|
+
onChange = props.onChange,
|
|
90
|
+
canvasOptions = props.canvasOptions,
|
|
91
|
+
_props$legends = props.legends,
|
|
92
|
+
legends = _props$legends === void 0 ? default_legends : _props$legends;
|
|
93
|
+
var gyImageEditorRef = useRef(null);
|
|
94
|
+
//strokeWidth: number = 1;
|
|
95
|
+
//fontSize: number = 18;
|
|
96
|
+
//colors: any = "#fe547b";
|
|
97
|
+
var containner = useRef();
|
|
98
|
+
var currentType = useRef('free');
|
|
99
|
+
var textObject = useRef(null);
|
|
100
|
+
var drawingObject = useRef(null);
|
|
101
|
+
var mouseFrom = useRef({});
|
|
102
|
+
var idDrawing = useRef(false);
|
|
103
|
+
var isRedoing = useRef(false);
|
|
104
|
+
var mouseTo = useRef({});
|
|
105
|
+
var stateArr = useRef([]);
|
|
106
|
+
useRef(null);
|
|
107
|
+
var isTagging = useRef(true);
|
|
108
|
+
var freeDrawFlag = useRef(false);
|
|
109
|
+
var freeErase = useRef(false);
|
|
110
|
+
var textFlag = useRef(false);
|
|
111
|
+
var rectFlag = useRef(false);
|
|
112
|
+
var circleFlag = useRef(false);
|
|
113
|
+
var triangleFlag = useRef(false);
|
|
114
|
+
var lineFlag = useRef(false);
|
|
115
|
+
var legend_item = useRef({});
|
|
116
|
+
// const [legend_item, set_legend_item] = useState<Partial<(typeof default_legends)[number]>>({})
|
|
117
|
+
var _useState = useState('#fe547b'),
|
|
118
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
119
|
+
colors = _useState2[0],
|
|
120
|
+
set_colors = _useState2[1];
|
|
121
|
+
var _useState3 = useState(1),
|
|
122
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
123
|
+
strokeWidth = _useState4[0],
|
|
124
|
+
set_strokeWidth = _useState4[1];
|
|
125
|
+
var _useState5 = useState(18),
|
|
126
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
127
|
+
fontSize = _useState6[0],
|
|
128
|
+
set_fontSize = _useState6[1];
|
|
129
|
+
var _useState7 = useState(!!value),
|
|
130
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
131
|
+
__checked = _useState8[0],
|
|
132
|
+
set_checked = _useState8[1];
|
|
133
|
+
var _useState9 = useState(false),
|
|
134
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
135
|
+
loaded = _useState10[0],
|
|
136
|
+
set_loaded = _useState10[1];
|
|
137
|
+
useEffect(function () {
|
|
138
|
+
mchcEnv.ds([function (s) {
|
|
139
|
+
return s.lm_libs.fabric_5_2_0['fabric.min.js'];
|
|
140
|
+
}]).then(function () {
|
|
141
|
+
return set_loaded(true);
|
|
142
|
+
});
|
|
143
|
+
}, []);
|
|
144
|
+
useEffect(function () {
|
|
145
|
+
loaded && initCanvas();
|
|
146
|
+
}, [value, loaded]);
|
|
147
|
+
useEffect(function () {
|
|
148
|
+
if (loaded) {
|
|
149
|
+
init_delete_control();
|
|
150
|
+
createContainner();
|
|
151
|
+
}
|
|
152
|
+
}, [loaded]);
|
|
153
|
+
useEffect(function () {
|
|
154
|
+
return initEvent();
|
|
155
|
+
}, [colors, strokeWidth, fontSize, value]);
|
|
156
|
+
function broadcast_event(type) {
|
|
157
|
+
mchcEvent.emit('custom_msg', {
|
|
158
|
+
type: type,
|
|
159
|
+
data: {
|
|
160
|
+
ins: containner.current
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function createContainner() {
|
|
165
|
+
var _gyImageEditorRef$cur;
|
|
166
|
+
gyImageEditorRef === null || gyImageEditorRef === void 0 || (_gyImageEditorRef$cur = gyImageEditorRef.current) === null || _gyImageEditorRef$cur === void 0 || _gyImageEditorRef$cur.clientWidth;
|
|
167
|
+
if (!containner.current) {
|
|
168
|
+
var _legends$length, _gyImageEditorRef$cur2;
|
|
169
|
+
var count = (_legends$length = legends.length) !== null && _legends$length !== void 0 ? _legends$length : 0;
|
|
170
|
+
var len = count ? 200 : 0;
|
|
171
|
+
containner.current = new (real_fabric().Canvas)('c', _objectSpread({
|
|
172
|
+
backgroundColor: '#fff',
|
|
173
|
+
width: (gyImageEditorRef === null || gyImageEditorRef === void 0 || (_gyImageEditorRef$cur2 = gyImageEditorRef.current) === null || _gyImageEditorRef$cur2 === void 0 ? void 0 : _gyImageEditorRef$cur2.clientWidth) - len,
|
|
174
|
+
height: 460
|
|
175
|
+
}, canvasOptions));
|
|
176
|
+
broadcast_event(MyImageEditorEvents.create);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function initCanvas() {
|
|
180
|
+
return _initCanvas.apply(this, arguments);
|
|
181
|
+
}
|
|
182
|
+
function _initCanvas() {
|
|
183
|
+
_initCanvas = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
184
|
+
var _containner$current19, img_el, _containner$current20, img;
|
|
185
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
186
|
+
while (1) switch (_context.prev = _context.next) {
|
|
187
|
+
case 0:
|
|
188
|
+
mchcLogger.log('initCanvas', {
|
|
189
|
+
value: value
|
|
190
|
+
});
|
|
191
|
+
if (!(value && isString(value))) {
|
|
192
|
+
_context.next = 12;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (!safe_json_parse(value)) {
|
|
196
|
+
_context.next = 7;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
mchcLogger.log('initCanvas safe_json_parse', {
|
|
200
|
+
value: value
|
|
201
|
+
});
|
|
202
|
+
(_containner$current19 = containner.current) === null || _containner$current19 === void 0 || _containner$current19.loadFromJSON(value, function () {});
|
|
203
|
+
_context.next = 12;
|
|
204
|
+
break;
|
|
205
|
+
case 7:
|
|
206
|
+
mchcLogger.log('initCanvas base64_to_image', {
|
|
207
|
+
value: value
|
|
208
|
+
});
|
|
209
|
+
// 兼容base64 图片
|
|
210
|
+
_context.next = 10;
|
|
211
|
+
return base64_to_image(value);
|
|
212
|
+
case 10:
|
|
213
|
+
img_el = _context.sent;
|
|
214
|
+
if (img_el) {
|
|
215
|
+
img = new (real_fabric().Image)(img_el);
|
|
216
|
+
(_containner$current20 = containner.current) === null || _containner$current20 === void 0 || _containner$current20.add(img);
|
|
217
|
+
}
|
|
218
|
+
case 12:
|
|
219
|
+
if (!legends.length) {
|
|
220
|
+
initfreeDraw();
|
|
221
|
+
}
|
|
222
|
+
case 13:
|
|
223
|
+
case "end":
|
|
224
|
+
return _context.stop();
|
|
225
|
+
}
|
|
226
|
+
}, _callee);
|
|
227
|
+
}));
|
|
228
|
+
return _initCanvas.apply(this, arguments);
|
|
229
|
+
}
|
|
230
|
+
function initEvent() {
|
|
231
|
+
var eventType = ['line', 'circle', 'rect', 'triangle', 'text'];
|
|
232
|
+
var con = containner.current;
|
|
233
|
+
if (!con) return function () {};
|
|
234
|
+
var __events = {
|
|
235
|
+
drop: function drop(options) {
|
|
236
|
+
var item = legend_item.current;
|
|
237
|
+
real_fabric().util.loadImage(get(item, 'img'), function (img) {
|
|
238
|
+
var legimg = new (real_fabric().Image)(img, {
|
|
239
|
+
left: options.e.offsetX,
|
|
240
|
+
top: options.e.offsetY,
|
|
241
|
+
width: get(item, 'width'),
|
|
242
|
+
height: get(item, 'height'),
|
|
243
|
+
// @ts-ignore
|
|
244
|
+
id: get(item, 'id')
|
|
245
|
+
});
|
|
246
|
+
con.add(legimg);
|
|
247
|
+
handleSelectDraw();
|
|
248
|
+
}, {
|
|
249
|
+
crossOrigin: 'anonymous'
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
'mouse:down': function mouseDown(options) {
|
|
253
|
+
if (eventType.indexOf(currentType.current) != -1) {
|
|
254
|
+
mouseFrom.current.x = options.e.offsetX;
|
|
255
|
+
mouseFrom.current.y = options.e.offsetY;
|
|
256
|
+
idDrawing.current = true;
|
|
257
|
+
switch (currentType.current) {
|
|
258
|
+
case 'text':
|
|
259
|
+
initText();
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
"mouse:move": function mouseMove(options) {
|
|
265
|
+
if (idDrawing.current && eventType.indexOf(currentType.current) != -1) {
|
|
266
|
+
mouseTo.current.x = options.e.offsetX;
|
|
267
|
+
mouseTo.current.y = options.e.offsetY;
|
|
268
|
+
switch (currentType.current) {
|
|
269
|
+
case 'line':
|
|
270
|
+
ininLine();
|
|
271
|
+
break;
|
|
272
|
+
case 'circle':
|
|
273
|
+
initCircle();
|
|
274
|
+
break;
|
|
275
|
+
case 'rect':
|
|
276
|
+
initRect();
|
|
277
|
+
break;
|
|
278
|
+
case 'triangle':
|
|
279
|
+
initTriangle();
|
|
280
|
+
break;
|
|
281
|
+
case 'free':
|
|
282
|
+
initfreeDraw();
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
'mouse:up': function mouseUp(options) {
|
|
288
|
+
if (eventType.indexOf(currentType.current) != -1) {
|
|
289
|
+
mouseTo.current.x = options.e.offsetX;
|
|
290
|
+
mouseTo.current.y = options.e.offsetY;
|
|
291
|
+
drawingObject.current = null;
|
|
292
|
+
idDrawing.current = false;
|
|
293
|
+
resetMove();
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
'mouse:over': function mouseOver(options) {},
|
|
297
|
+
'mouse:out': function mouseOut(options) {},
|
|
298
|
+
'object:added': function objectAdded() {
|
|
299
|
+
if (isRedoing.current == false) {
|
|
300
|
+
stateArr.current = [];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
return event_process(con, __events);
|
|
305
|
+
}
|
|
306
|
+
function initText() {
|
|
307
|
+
var _containner$current;
|
|
308
|
+
createContainner();
|
|
309
|
+
containner.current.isDrawingMode = false;
|
|
310
|
+
containner.current.selection = false;
|
|
311
|
+
textObject.current = new (real_fabric().Textbox)('', {
|
|
312
|
+
left: mouseFrom.current.x,
|
|
313
|
+
top: mouseFrom.current.y,
|
|
314
|
+
fontSize: fontSize,
|
|
315
|
+
fill: colors,
|
|
316
|
+
hasControls: false
|
|
317
|
+
});
|
|
318
|
+
(_containner$current = containner.current) === null || _containner$current === void 0 || _containner$current.add(textObject.current);
|
|
319
|
+
textObject.current.enterEditing();
|
|
320
|
+
textObject.current.hiddenTextarea.focus();
|
|
321
|
+
}
|
|
322
|
+
function initRect() {
|
|
323
|
+
createContainner();
|
|
324
|
+
var left = mouseFrom.current.x;
|
|
325
|
+
var top = mouseFrom.current.y;
|
|
326
|
+
var width = mouseTo.current.x - mouseFrom.current.x;
|
|
327
|
+
var height = mouseTo.current.y - mouseFrom.current.y;
|
|
328
|
+
var canvasObject = new (real_fabric().Rect)({
|
|
329
|
+
left: left,
|
|
330
|
+
top: top,
|
|
331
|
+
width: width,
|
|
332
|
+
height: height,
|
|
333
|
+
stroke: colors,
|
|
334
|
+
fill: 'rgba(255, 255, 255, 0)',
|
|
335
|
+
strokeWidth: strokeWidth
|
|
336
|
+
});
|
|
337
|
+
toggleDrawingObject(canvasObject);
|
|
338
|
+
}
|
|
339
|
+
function initCircle() {
|
|
340
|
+
createContainner();
|
|
341
|
+
var left = mouseFrom.current.x;
|
|
342
|
+
var top = mouseFrom.current.y;
|
|
343
|
+
var radius = Math.sqrt((mouseTo.current.x - left) * (mouseTo.current.x - left) + (mouseTo.current.y - top) * (mouseTo.current.y - top)) / 2;
|
|
344
|
+
var canvasObject = new (real_fabric().Circle)({
|
|
345
|
+
left: left,
|
|
346
|
+
top: top,
|
|
347
|
+
stroke: colors,
|
|
348
|
+
fill: 'rgba(255, 255, 255, 0)',
|
|
349
|
+
radius: radius,
|
|
350
|
+
strokeWidth: strokeWidth
|
|
351
|
+
});
|
|
352
|
+
toggleDrawingObject(canvasObject);
|
|
353
|
+
}
|
|
354
|
+
function initTriangle() {
|
|
355
|
+
createContainner();
|
|
356
|
+
var left = mouseFrom.current.x;
|
|
357
|
+
var top = mouseFrom.current.y;
|
|
358
|
+
var height = mouseTo.current.y - mouseFrom.current.y;
|
|
359
|
+
var width = Math.sqrt(Math.pow(height, 2) + Math.pow(height / 2.0, 2));
|
|
360
|
+
var canvasObject = new (real_fabric().Triangle)({
|
|
361
|
+
left: left,
|
|
362
|
+
top: top,
|
|
363
|
+
width: width,
|
|
364
|
+
height: height,
|
|
365
|
+
stroke: colors,
|
|
366
|
+
fill: 'rgba(255, 255, 255, 0)',
|
|
367
|
+
strokeWidth: strokeWidth
|
|
368
|
+
});
|
|
369
|
+
toggleDrawingObject(canvasObject);
|
|
370
|
+
}
|
|
371
|
+
function ininLine() {
|
|
372
|
+
createContainner();
|
|
373
|
+
var canvasObject = new (real_fabric().Line)([mouseFrom.current.x, mouseFrom.current.y, mouseTo.current.x, mouseTo.current.y], {
|
|
374
|
+
fill: colors,
|
|
375
|
+
stroke: colors,
|
|
376
|
+
strokeWidth: strokeWidth
|
|
377
|
+
});
|
|
378
|
+
toggleDrawingObject(canvasObject);
|
|
379
|
+
}
|
|
380
|
+
function initfreeDraw() {
|
|
381
|
+
createContainner();
|
|
382
|
+
containner.current.isDrawingMode = true;
|
|
383
|
+
containner.current.freeDrawingBrush.color = colors;
|
|
384
|
+
containner.current.freeDrawingBrush.width = strokeWidth;
|
|
385
|
+
containner.current.renderAll();
|
|
386
|
+
}
|
|
387
|
+
function toggleDrawingObject(canvasObject) {
|
|
388
|
+
var _containner$current3;
|
|
389
|
+
containner.current.isDrawingMode = false;
|
|
390
|
+
containner.current.selection = false;
|
|
391
|
+
canvasObject.selectable = false;
|
|
392
|
+
if (drawingObject.current) {
|
|
393
|
+
var _containner$current2;
|
|
394
|
+
(_containner$current2 = containner.current) === null || _containner$current2 === void 0 || _containner$current2.remove(drawingObject.current);
|
|
395
|
+
}
|
|
396
|
+
(_containner$current3 = containner.current) === null || _containner$current3 === void 0 || _containner$current3.add(canvasObject);
|
|
397
|
+
drawingObject.current = canvasObject;
|
|
398
|
+
if (textObject.current) {
|
|
399
|
+
textObject.current.exitEditing();
|
|
400
|
+
textObject.current = null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function resetMove() {
|
|
404
|
+
mouseFrom.current = {};
|
|
405
|
+
mouseTo.current = {};
|
|
406
|
+
}
|
|
407
|
+
//开始拖拽图片
|
|
408
|
+
function handleDragStart(e, item) {
|
|
409
|
+
legend_item.current = item;
|
|
410
|
+
}
|
|
411
|
+
//后退
|
|
412
|
+
function handleRevoke() {
|
|
413
|
+
var _containner$current4;
|
|
414
|
+
if (((_containner$current4 = containner.current) === null || _containner$current4 === void 0 ? void 0 : _containner$current4._objects.length) > 0) {
|
|
415
|
+
var _containner$current5, _containner$current6;
|
|
416
|
+
stateArr.current.push((_containner$current5 = containner.current) === null || _containner$current5 === void 0 ? void 0 : _containner$current5._objects.pop());
|
|
417
|
+
(_containner$current6 = containner.current) === null || _containner$current6 === void 0 || _containner$current6.renderAll();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//前进
|
|
421
|
+
function handleRedo() {
|
|
422
|
+
if (stateArr.current.length > 0) {
|
|
423
|
+
var _containner$current7, _containner$current8;
|
|
424
|
+
isRedoing.current = true;
|
|
425
|
+
(_containner$current7 = containner.current) === null || _containner$current7 === void 0 || _containner$current7.add(stateArr.current.pop());
|
|
426
|
+
(_containner$current8 = containner.current) === null || _containner$current8 === void 0 || _containner$current8.renderAll();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
//清除
|
|
430
|
+
function handleClear() {
|
|
431
|
+
var _containner$current9;
|
|
432
|
+
(_containner$current9 = containner.current) === null || _containner$current9 === void 0 || _containner$current9.clear();
|
|
433
|
+
containner.current.backgroundColor = '#fff';
|
|
434
|
+
resetMove();
|
|
435
|
+
isRedoing.current = false;
|
|
436
|
+
stateArr.current = [];
|
|
437
|
+
}
|
|
438
|
+
//擦除
|
|
439
|
+
function handleFreeErase() {
|
|
440
|
+
if (!real_fabric().EraserBrush) return;
|
|
441
|
+
if (freeErase.current) {
|
|
442
|
+
freeErase.current = false;
|
|
443
|
+
containner.current.isDrawingMode = false;
|
|
444
|
+
} else {
|
|
445
|
+
freeErase.current = true;
|
|
446
|
+
freeDrawFlag.current = false;
|
|
447
|
+
textFlag.current = false;
|
|
448
|
+
rectFlag.current = false;
|
|
449
|
+
circleFlag.current = false;
|
|
450
|
+
triangleFlag.current = false;
|
|
451
|
+
lineFlag.current = false;
|
|
452
|
+
removeTextObject();
|
|
453
|
+
// 开启画布自由绘画模式
|
|
454
|
+
containner.current.isDrawingMode = true;
|
|
455
|
+
// 设置自由绘画模式 画笔颜色与画笔线条大小
|
|
456
|
+
containner.current.freeDrawingBrush = new (real_fabric().EraserBrush)(containner.current);
|
|
457
|
+
containner.current.freeDrawingBrush.width = 20;
|
|
458
|
+
currentType.current = 'free';
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
//自由绘画
|
|
462
|
+
function handleFreeDraw() {
|
|
463
|
+
if (freeDrawFlag.current) {
|
|
464
|
+
freeDrawFlag.current = false;
|
|
465
|
+
containner.current.isDrawingMode = false;
|
|
466
|
+
} else {
|
|
467
|
+
freeDrawFlag.current = true;
|
|
468
|
+
freeErase.current = false;
|
|
469
|
+
textFlag.current = false;
|
|
470
|
+
rectFlag.current = false;
|
|
471
|
+
circleFlag.current = false;
|
|
472
|
+
triangleFlag.current = false;
|
|
473
|
+
lineFlag.current = false;
|
|
474
|
+
if (real_fabric().PencilBrush) {
|
|
475
|
+
containner.current.freeDrawingBrush = new (real_fabric().PencilBrush)(containner.current);
|
|
476
|
+
}
|
|
477
|
+
removeTextObject();
|
|
478
|
+
// 开启画布自由绘画模式
|
|
479
|
+
containner.current.isDrawingMode = true;
|
|
480
|
+
// 设置自由绘画模式 画笔颜色与画笔线条大小
|
|
481
|
+
containner.current.freeDrawingBrush.color = colors;
|
|
482
|
+
containner.current.freeDrawingBrush.width = strokeWidth;
|
|
483
|
+
currentType.current = 'free';
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
//文本
|
|
487
|
+
function handleTextDraw() {
|
|
488
|
+
if (textFlag.current) {
|
|
489
|
+
textFlag.current = false;
|
|
490
|
+
removeTextObject();
|
|
491
|
+
} else {
|
|
492
|
+
textFlag.current = true;
|
|
493
|
+
freeDrawFlag.current = false;
|
|
494
|
+
freeErase.current = false;
|
|
495
|
+
rectFlag.current = false;
|
|
496
|
+
circleFlag.current = false;
|
|
497
|
+
triangleFlag.current = false;
|
|
498
|
+
lineFlag.current = false;
|
|
499
|
+
currentType.current = 'text';
|
|
500
|
+
containner.current.isDrawingMode = false;
|
|
501
|
+
containner.current.selection = false;
|
|
502
|
+
clearSelectable();
|
|
503
|
+
if (drawingObject.current) {
|
|
504
|
+
var _containner$current10;
|
|
505
|
+
(_containner$current10 = containner.current) === null || _containner$current10 === void 0 || _containner$current10.remove(drawingObject.current);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
//矩形
|
|
510
|
+
function handleRectDraw() {
|
|
511
|
+
if (rectFlag.current) {
|
|
512
|
+
rectFlag.current = false;
|
|
513
|
+
currentType.current = '';
|
|
514
|
+
} else {
|
|
515
|
+
rectFlag.current = true;
|
|
516
|
+
textFlag.current = false;
|
|
517
|
+
freeDrawFlag.current = false;
|
|
518
|
+
freeErase.current = false;
|
|
519
|
+
circleFlag.current = false;
|
|
520
|
+
triangleFlag.current = false;
|
|
521
|
+
lineFlag.current = false;
|
|
522
|
+
isTagging.current = false;
|
|
523
|
+
currentType.current = 'rect';
|
|
524
|
+
clearSelectable();
|
|
525
|
+
initRect();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
//圆形
|
|
529
|
+
function handleCircleDraw() {
|
|
530
|
+
if (circleFlag.current) {
|
|
531
|
+
circleFlag.current = false;
|
|
532
|
+
currentType.current = '';
|
|
533
|
+
} else {
|
|
534
|
+
rectFlag.current = false;
|
|
535
|
+
textFlag.current = false;
|
|
536
|
+
freeDrawFlag.current = false;
|
|
537
|
+
freeErase.current = false;
|
|
538
|
+
circleFlag.current = true;
|
|
539
|
+
triangleFlag.current = false;
|
|
540
|
+
lineFlag.current = false;
|
|
541
|
+
currentType.current = 'circle';
|
|
542
|
+
clearSelectable();
|
|
543
|
+
initCircle();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
//三角形
|
|
547
|
+
function handleTriangleDraw() {
|
|
548
|
+
if (triangleFlag.current) {
|
|
549
|
+
triangleFlag.current = false;
|
|
550
|
+
currentType.current = '';
|
|
551
|
+
} else {
|
|
552
|
+
rectFlag.current = false;
|
|
553
|
+
textFlag.current = false;
|
|
554
|
+
freeDrawFlag.current = false;
|
|
555
|
+
freeErase.current = false;
|
|
556
|
+
circleFlag.current = false;
|
|
557
|
+
triangleFlag.current = true;
|
|
558
|
+
lineFlag.current = false;
|
|
559
|
+
currentType.current = 'triangle';
|
|
560
|
+
clearSelectable();
|
|
561
|
+
initTriangle();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
//直线
|
|
565
|
+
function handleLineDraw() {
|
|
566
|
+
if (lineFlag.current) {
|
|
567
|
+
lineFlag.current = false;
|
|
568
|
+
currentType.current = '';
|
|
569
|
+
} else {
|
|
570
|
+
rectFlag.current = false;
|
|
571
|
+
textFlag.current = false;
|
|
572
|
+
freeDrawFlag.current = false;
|
|
573
|
+
freeErase.current = false;
|
|
574
|
+
circleFlag.current = false;
|
|
575
|
+
triangleFlag.current = false;
|
|
576
|
+
lineFlag.current = true;
|
|
577
|
+
currentType.current = 'line';
|
|
578
|
+
clearSelectable();
|
|
579
|
+
ininLine();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
//下载图片
|
|
583
|
+
function handleExport() {
|
|
584
|
+
var _containner$current11, _containner$current12, _containner$current13;
|
|
585
|
+
var dataURL = (_containner$current11 = containner.current) === null || _containner$current11 === void 0 ? void 0 : _containner$current11.toDataURL({
|
|
586
|
+
width: (_containner$current12 = containner.current) === null || _containner$current12 === void 0 ? void 0 : _containner$current12.width,
|
|
587
|
+
height: (_containner$current13 = containner.current) === null || _containner$current13 === void 0 ? void 0 : _containner$current13.height,
|
|
588
|
+
left: 0,
|
|
589
|
+
top: 0,
|
|
590
|
+
format: 'png'
|
|
591
|
+
});
|
|
592
|
+
var link = document.createElement('a');
|
|
593
|
+
link.download = 'canvas.current?.png';
|
|
594
|
+
link.href = dataURL;
|
|
595
|
+
document.body.appendChild(link);
|
|
596
|
+
link.click();
|
|
597
|
+
document.body.removeChild(link);
|
|
598
|
+
}
|
|
599
|
+
function removeTextObject() {
|
|
600
|
+
currentType.current = '';
|
|
601
|
+
if (textObject.current) {
|
|
602
|
+
textObject.current.exitEditing();
|
|
603
|
+
textObject.current = null;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
//颜色设置
|
|
607
|
+
function handleGradePicker(css) {
|
|
608
|
+
containner.current.freeDrawingBrush.color = css;
|
|
609
|
+
set_colors(css);
|
|
610
|
+
}
|
|
611
|
+
//粗细设置
|
|
612
|
+
function handleSlider(value) {
|
|
613
|
+
console.log('value', value);
|
|
614
|
+
set_strokeWidth(value);
|
|
615
|
+
}
|
|
616
|
+
//字体设置
|
|
617
|
+
function handleTextSlider(value) {
|
|
618
|
+
set_fontSize(value);
|
|
619
|
+
}
|
|
620
|
+
//清除选中
|
|
621
|
+
function clearSelectable() {
|
|
622
|
+
var _containner$current14;
|
|
623
|
+
(_containner$current14 = containner.current) === null || _containner$current14 === void 0 || _containner$current14.getObjects().map(function (item) {
|
|
624
|
+
item.set('selectable', false);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
//不可选中
|
|
628
|
+
function handleUnselectDraw() {
|
|
629
|
+
var _containner$current15;
|
|
630
|
+
containner.current.isDrawingMode = false;
|
|
631
|
+
removeTextObject();
|
|
632
|
+
clearSelectable();
|
|
633
|
+
(_containner$current15 = containner.current) === null || _containner$current15 === void 0 || _containner$current15.renderAll();
|
|
634
|
+
}
|
|
635
|
+
//可选中
|
|
636
|
+
function handleSelectDraw() {
|
|
637
|
+
var _containner$current16, _containner$current17;
|
|
638
|
+
containner.current.isDrawingMode = false;
|
|
639
|
+
removeTextObject();
|
|
640
|
+
(_containner$current16 = containner.current) === null || _containner$current16 === void 0 || _containner$current16.getObjects().map(function (item) {
|
|
641
|
+
item.set('selectable', true);
|
|
642
|
+
});
|
|
643
|
+
(_containner$current17 = containner.current) === null || _containner$current17 === void 0 || _containner$current17.renderAll();
|
|
644
|
+
}
|
|
645
|
+
//保存图片到后台
|
|
646
|
+
function handleImgSave() {
|
|
647
|
+
var _containner$current18;
|
|
648
|
+
var value = JSON.stringify(containner.current);
|
|
649
|
+
(_containner$current18 = containner.current) === null || _containner$current18 === void 0 || _containner$current18.requestRenderAll();
|
|
650
|
+
onChange === null || onChange === void 0 || onChange(value);
|
|
651
|
+
broadcast_event(MyImageEditorEvents.save);
|
|
652
|
+
// 反序列化
|
|
653
|
+
// canvas.current?.loadFromJSON(value)
|
|
654
|
+
}
|
|
655
|
+
function handleSwitch(checked) {
|
|
656
|
+
set_checked(checked);
|
|
657
|
+
}
|
|
658
|
+
function renderSetUp() {
|
|
659
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
660
|
+
className: styles["slider"],
|
|
661
|
+
style: {
|
|
662
|
+
width: 300
|
|
663
|
+
}
|
|
664
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u7C97\u7EC6"), /*#__PURE__*/React.createElement(Slider, {
|
|
665
|
+
onChange: handleSlider,
|
|
666
|
+
value: strokeWidth
|
|
667
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
668
|
+
className: styles["picker"],
|
|
669
|
+
style: {
|
|
670
|
+
width: 300
|
|
671
|
+
}
|
|
672
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u989C\u8272"), /*#__PURE__*/React.createElement(MyColor, {
|
|
673
|
+
width: '300',
|
|
674
|
+
color: colors,
|
|
675
|
+
onChange: handleGradePicker
|
|
676
|
+
})));
|
|
677
|
+
}
|
|
678
|
+
function renderTextSetUp() {
|
|
679
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
680
|
+
className: styles["slider"],
|
|
681
|
+
style: {
|
|
682
|
+
width: 300
|
|
683
|
+
}
|
|
684
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u5927\u5C0F"), /*#__PURE__*/React.createElement(Slider, {
|
|
685
|
+
onChange: handleTextSlider,
|
|
686
|
+
value: fontSize
|
|
687
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
688
|
+
className: styles["picker"],
|
|
689
|
+
style: {
|
|
690
|
+
width: 300
|
|
691
|
+
}
|
|
692
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u989C\u8272"), /*#__PURE__*/React.createElement(MyColor, {
|
|
693
|
+
width: '300',
|
|
694
|
+
color: colors,
|
|
695
|
+
onChange: handleGradePicker
|
|
696
|
+
})));
|
|
697
|
+
}
|
|
698
|
+
if (!loaded) return '加载中...';
|
|
699
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
700
|
+
className: styles["switch"],
|
|
701
|
+
style: {
|
|
702
|
+
margin: '13px 0 16px 58px'
|
|
703
|
+
}
|
|
704
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u7535\u5B50\u753B\u677F\uFF1A"), /*#__PURE__*/React.createElement(Switch, {
|
|
705
|
+
checkedChildren: "\u5F00\u542F",
|
|
706
|
+
unCheckedChildren: "\u5173\u95ED",
|
|
707
|
+
checked: __checked,
|
|
708
|
+
onChange: handleSwitch
|
|
709
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
710
|
+
className: styles["gy-image-editor"],
|
|
711
|
+
ref: gyImageEditorRef
|
|
712
|
+
}, /*#__PURE__*/React.createElement(Layout, {
|
|
713
|
+
hidden: !__checked
|
|
714
|
+
}, legends.length ? /*#__PURE__*/React.createElement(Sider, {
|
|
715
|
+
style: {
|
|
716
|
+
borderTop: '1px solid #d7dce7'
|
|
717
|
+
}
|
|
718
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
719
|
+
id: styles["images"]
|
|
720
|
+
}, legends.map(function (l, idx) {
|
|
721
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
722
|
+
className: styles["box-img"]
|
|
723
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
724
|
+
draggable: "true",
|
|
725
|
+
onDragStart: function onDragStart(e) {
|
|
726
|
+
return handleDragStart(e, _objectSpread(_objectSpread({}, l), {}, {
|
|
727
|
+
id: idx
|
|
728
|
+
}));
|
|
729
|
+
},
|
|
730
|
+
src: l.img
|
|
731
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
732
|
+
className: styles["box-text"]
|
|
733
|
+
}, l.label));
|
|
734
|
+
}))) : null, /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement("div", {
|
|
735
|
+
id: styles['canvas-container']
|
|
736
|
+
}, /*#__PURE__*/React.createElement("canvas", {
|
|
737
|
+
// width={canvasWidth}
|
|
738
|
+
// height="460"
|
|
739
|
+
id: "c",
|
|
740
|
+
style: {
|
|
741
|
+
border: '1px solid #d7dce7'
|
|
742
|
+
}
|
|
743
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
744
|
+
className: styles["tool-bar"]
|
|
745
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
746
|
+
className: styles["tool-bar-container"]
|
|
747
|
+
}, /*#__PURE__*/React.createElement(Popover, {
|
|
748
|
+
placement: "left",
|
|
749
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u540E\u9000")
|
|
750
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
751
|
+
onClick: handleRevoke,
|
|
752
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
753
|
+
className: classnames(styles["button-icon"], styles["back"])
|
|
754
|
+
})
|
|
755
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
756
|
+
placement: "left",
|
|
757
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u524D\u8FDB")
|
|
758
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
759
|
+
onClick: handleRedo,
|
|
760
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
761
|
+
className: classnames(styles["button-icon"], styles["forward"])
|
|
762
|
+
})
|
|
763
|
+
})), (_real_fabric = real_fabric()) !== null && _real_fabric !== void 0 && _real_fabric.EraserBrush ? /*#__PURE__*/React.createElement(Popover, {
|
|
764
|
+
placement: "left",
|
|
765
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u64E6\u9664")
|
|
766
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
767
|
+
onClick: handleFreeErase,
|
|
768
|
+
icon: /*#__PURE__*/React.createElement(MyIcon, {
|
|
769
|
+
value: 'ClearOutlined'
|
|
770
|
+
})
|
|
771
|
+
})) : null, /*#__PURE__*/React.createElement(Popover, {
|
|
772
|
+
placement: "left",
|
|
773
|
+
content: renderSetUp(),
|
|
774
|
+
title: "\u8BBE\u7F6E"
|
|
775
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
776
|
+
onClick: handleFreeDraw,
|
|
777
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
778
|
+
className: classnames(styles["button-icon"], styles["pen"])
|
|
779
|
+
})
|
|
780
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
781
|
+
placement: "left",
|
|
782
|
+
content: renderTextSetUp(),
|
|
783
|
+
title: "\u8BBE\u7F6E"
|
|
784
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
785
|
+
onClick: handleTextDraw,
|
|
786
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
787
|
+
className: classnames(styles["button-icon"], styles["text"])
|
|
788
|
+
})
|
|
789
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
790
|
+
placement: "left",
|
|
791
|
+
content: renderSetUp(),
|
|
792
|
+
title: "\u8BBE\u7F6E"
|
|
793
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
794
|
+
onClick: handleRectDraw,
|
|
795
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
796
|
+
className: classnames(styles["button-icon"], styles["rect"])
|
|
797
|
+
})
|
|
798
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
799
|
+
placement: "left",
|
|
800
|
+
content: renderSetUp(),
|
|
801
|
+
title: "\u8BBE\u7F6E"
|
|
802
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
803
|
+
onClick: handleCircleDraw,
|
|
804
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
805
|
+
className: classnames(styles["button-icon"], styles["circle-icon2"])
|
|
806
|
+
})
|
|
807
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
808
|
+
placement: "left",
|
|
809
|
+
content: renderSetUp(),
|
|
810
|
+
title: "\u8BBE\u7F6E"
|
|
811
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
812
|
+
onClick: handleTriangleDraw,
|
|
813
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
814
|
+
className: classnames(styles["button-icon"], styles["triangle"])
|
|
815
|
+
})
|
|
816
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
817
|
+
placement: "left",
|
|
818
|
+
content: renderSetUp(),
|
|
819
|
+
title: "\u8BBE\u7F6E"
|
|
820
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
821
|
+
onClick: handleLineDraw,
|
|
822
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
823
|
+
className: classnames(styles["button-icon"], styles["line"])
|
|
824
|
+
})
|
|
825
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
826
|
+
placement: "left",
|
|
827
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u6E05\u9664")
|
|
828
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
829
|
+
onClick: handleClear,
|
|
830
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
831
|
+
className: classnames(styles["button-icon"], styles["clear"])
|
|
832
|
+
})
|
|
833
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
834
|
+
placement: "left",
|
|
835
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u5BFC\u51FA")
|
|
836
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
837
|
+
onClick: handleExport,
|
|
838
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
839
|
+
className: classnames(styles["button-icon"], styles["export"])
|
|
840
|
+
})
|
|
841
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
842
|
+
placement: "left",
|
|
843
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u53EF\u9009\u4E2D")
|
|
844
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
845
|
+
onClick: handleSelectDraw,
|
|
846
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
847
|
+
className: classnames(styles["button-icon"], styles["selected"])
|
|
848
|
+
})
|
|
849
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
850
|
+
placement: "left",
|
|
851
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u4E0D\u53EF\u9009\u4E2D")
|
|
852
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
853
|
+
onClick: handleUnselectDraw,
|
|
854
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
855
|
+
className: classnames(styles["button-icon"], styles["noselected"])
|
|
856
|
+
})
|
|
857
|
+
})), /*#__PURE__*/React.createElement(Popover, {
|
|
858
|
+
placement: "left",
|
|
859
|
+
content: /*#__PURE__*/React.createElement("span", null, "\u4FDD\u5B58")
|
|
860
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
861
|
+
onClick: handleImgSave,
|
|
862
|
+
icon: /*#__PURE__*/React.createElement("span", {
|
|
863
|
+
className: classnames(styles["button-icon"], styles["save"])
|
|
864
|
+
})
|
|
865
|
+
})))))))));
|
|
866
|
+
}
|
|
867
|
+
export { MyImageEditor_Inner as default };
|