@idraw/util 0.4.0-alpha.5 → 0.4.0-alpha.7
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/esm/index.d.ts +5 -4
- package/dist/esm/index.js +5 -4
- package/dist/esm/lib/canvas.d.ts +6 -2
- package/dist/esm/lib/canvas.js +61 -18
- package/dist/esm/lib/config.d.ts +13 -1
- package/dist/esm/lib/config.js +52 -2
- package/dist/esm/lib/context2d.d.ts +9 -3
- package/dist/esm/lib/context2d.js +101 -70
- package/dist/esm/lib/element.d.ts +4 -2
- package/dist/esm/lib/element.js +55 -49
- package/dist/esm/lib/handle-element.d.ts +14 -0
- package/dist/esm/lib/handle-element.js +226 -0
- package/dist/esm/lib/view-box.js +6 -1
- package/dist/esm/lib/view-calc.d.ts +7 -0
- package/dist/esm/lib/view-calc.js +19 -0
- package/dist/index.global.js +526 -138
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
var iDrawUtil = function(exports) {
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";var __accessCheck = (obj, member, msg) => {
|
|
3
|
+
if (!member.has(obj))
|
|
4
|
+
throw TypeError("Cannot " + msg);
|
|
5
|
+
};
|
|
6
|
+
var __privateGet = (obj, member, getter) => {
|
|
7
|
+
__accessCheck(obj, member, "read from private field");
|
|
8
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
9
|
+
};
|
|
10
|
+
var __privateAdd = (obj, member, value) => {
|
|
11
|
+
if (member.has(obj))
|
|
12
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
13
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
14
|
+
};
|
|
15
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
16
|
+
__accessCheck(obj, member, "write to private field");
|
|
17
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var _ctx, _opts;
|
|
3
22
|
function compose(middleware) {
|
|
4
23
|
return function(context, next) {
|
|
5
24
|
return dispatch(0);
|
|
@@ -775,19 +794,19 @@ var iDrawUtil = function(exports) {
|
|
|
775
794
|
// private _width: number = 0;
|
|
776
795
|
// private _height: number = 0;
|
|
777
796
|
constructor(ctx, opts) {
|
|
778
|
-
this
|
|
779
|
-
|
|
780
|
-
this
|
|
781
|
-
this
|
|
797
|
+
__privateAdd(this, _ctx, void 0);
|
|
798
|
+
__privateAdd(this, _opts, void 0);
|
|
799
|
+
__privateSet(this, _ctx, ctx);
|
|
800
|
+
__privateSet(this, _opts, { ...{ devicePixelRatio: 1, offscreenCanvas: null }, ...opts });
|
|
782
801
|
}
|
|
783
802
|
$undoPixelRatio(num) {
|
|
784
|
-
return num / this.
|
|
803
|
+
return num / __privateGet(this, _opts).devicePixelRatio;
|
|
785
804
|
}
|
|
786
805
|
$doPixelRatio(num) {
|
|
787
|
-
return this.
|
|
806
|
+
return __privateGet(this, _opts).devicePixelRatio * num;
|
|
788
807
|
}
|
|
789
808
|
$getContext() {
|
|
790
|
-
return this
|
|
809
|
+
return __privateGet(this, _ctx);
|
|
791
810
|
}
|
|
792
811
|
$setFont(opts) {
|
|
793
812
|
const strList = [];
|
|
@@ -796,135 +815,156 @@ var iDrawUtil = function(exports) {
|
|
|
796
815
|
}
|
|
797
816
|
strList.push(`${this.$doPixelRatio(opts.fontSize || 12)}px`);
|
|
798
817
|
strList.push(`${opts.fontFamily || "sans-serif"}`);
|
|
799
|
-
this
|
|
818
|
+
__privateGet(this, _ctx).font = `${strList.join(" ")}`;
|
|
819
|
+
}
|
|
820
|
+
$getOffscreenCanvas() {
|
|
821
|
+
return __privateGet(this, _opts).offscreenCanvas;
|
|
800
822
|
}
|
|
801
823
|
$resize(opts) {
|
|
802
|
-
const { width, height, devicePixelRatio } = opts;
|
|
803
|
-
const { canvas } = this
|
|
824
|
+
const { width, height, devicePixelRatio, resetStyle } = opts;
|
|
825
|
+
const { canvas } = __privateGet(this, _ctx);
|
|
804
826
|
canvas.width = width * devicePixelRatio;
|
|
805
827
|
canvas.height = height * devicePixelRatio;
|
|
806
|
-
this
|
|
828
|
+
__privateSet(this, _opts, {
|
|
829
|
+
...__privateGet(this, _opts),
|
|
830
|
+
...{
|
|
831
|
+
devicePixelRatio
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
if (resetStyle === true) {
|
|
835
|
+
canvas.style.width = `${width}px`;
|
|
836
|
+
canvas.style.height = `${height}px`;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
$getSize() {
|
|
840
|
+
const { devicePixelRatio } = __privateGet(this, _opts);
|
|
841
|
+
const { width, height } = __privateGet(this, _ctx).canvas;
|
|
842
|
+
return {
|
|
843
|
+
width: width / devicePixelRatio,
|
|
844
|
+
height: height / devicePixelRatio,
|
|
845
|
+
devicePixelRatio
|
|
846
|
+
};
|
|
807
847
|
}
|
|
808
848
|
get canvas() {
|
|
809
|
-
return this
|
|
849
|
+
return __privateGet(this, _ctx).canvas;
|
|
810
850
|
}
|
|
811
851
|
get fillStyle() {
|
|
812
|
-
return this
|
|
852
|
+
return __privateGet(this, _ctx).fillStyle;
|
|
813
853
|
}
|
|
814
854
|
set fillStyle(value) {
|
|
815
|
-
this
|
|
855
|
+
__privateGet(this, _ctx).fillStyle = value;
|
|
816
856
|
}
|
|
817
857
|
get strokeStyle() {
|
|
818
|
-
return this
|
|
858
|
+
return __privateGet(this, _ctx).strokeStyle;
|
|
819
859
|
}
|
|
820
860
|
set strokeStyle(color2) {
|
|
821
|
-
this
|
|
861
|
+
__privateGet(this, _ctx).strokeStyle = color2;
|
|
822
862
|
}
|
|
823
863
|
get lineWidth() {
|
|
824
|
-
return this.$undoPixelRatio(this
|
|
864
|
+
return this.$undoPixelRatio(__privateGet(this, _ctx).lineWidth);
|
|
825
865
|
}
|
|
826
866
|
set lineWidth(w2) {
|
|
827
|
-
this
|
|
867
|
+
__privateGet(this, _ctx).lineWidth = this.$doPixelRatio(w2);
|
|
828
868
|
}
|
|
829
869
|
get textAlign() {
|
|
830
|
-
return this
|
|
870
|
+
return __privateGet(this, _ctx).textAlign;
|
|
831
871
|
}
|
|
832
872
|
set textAlign(align) {
|
|
833
|
-
this
|
|
873
|
+
__privateGet(this, _ctx).textAlign = align;
|
|
834
874
|
}
|
|
835
875
|
get textBaseline() {
|
|
836
|
-
return this
|
|
876
|
+
return __privateGet(this, _ctx).textBaseline;
|
|
837
877
|
}
|
|
838
878
|
set textBaseline(baseline) {
|
|
839
|
-
this
|
|
879
|
+
__privateGet(this, _ctx).textBaseline = baseline;
|
|
840
880
|
}
|
|
841
881
|
get globalAlpha() {
|
|
842
|
-
return this
|
|
882
|
+
return __privateGet(this, _ctx).globalAlpha;
|
|
843
883
|
}
|
|
844
884
|
set globalAlpha(alpha) {
|
|
845
|
-
this
|
|
885
|
+
__privateGet(this, _ctx).globalAlpha = alpha;
|
|
846
886
|
}
|
|
847
887
|
get shadowColor() {
|
|
848
|
-
return this
|
|
888
|
+
return __privateGet(this, _ctx).shadowColor;
|
|
849
889
|
}
|
|
850
890
|
set shadowColor(color2) {
|
|
851
|
-
this
|
|
891
|
+
__privateGet(this, _ctx).shadowColor = color2;
|
|
852
892
|
}
|
|
853
893
|
get shadowOffsetX() {
|
|
854
|
-
return this.$undoPixelRatio(this
|
|
894
|
+
return this.$undoPixelRatio(__privateGet(this, _ctx).shadowOffsetX);
|
|
855
895
|
}
|
|
856
896
|
set shadowOffsetX(offsetX) {
|
|
857
|
-
this
|
|
897
|
+
__privateGet(this, _ctx).shadowOffsetX = this.$doPixelRatio(offsetX);
|
|
858
898
|
}
|
|
859
899
|
get shadowOffsetY() {
|
|
860
|
-
return this.$undoPixelRatio(this
|
|
900
|
+
return this.$undoPixelRatio(__privateGet(this, _ctx).shadowOffsetY);
|
|
861
901
|
}
|
|
862
902
|
set shadowOffsetY(offsetY) {
|
|
863
|
-
this
|
|
903
|
+
__privateGet(this, _ctx).shadowOffsetY = this.$doPixelRatio(offsetY);
|
|
864
904
|
}
|
|
865
905
|
get shadowBlur() {
|
|
866
|
-
return this.$undoPixelRatio(this
|
|
906
|
+
return this.$undoPixelRatio(__privateGet(this, _ctx).shadowBlur);
|
|
867
907
|
}
|
|
868
908
|
set shadowBlur(blur) {
|
|
869
|
-
this
|
|
909
|
+
__privateGet(this, _ctx).shadowBlur = this.$doPixelRatio(blur);
|
|
870
910
|
}
|
|
871
911
|
get lineCap() {
|
|
872
|
-
return this
|
|
912
|
+
return __privateGet(this, _ctx).lineCap;
|
|
873
913
|
}
|
|
874
914
|
set lineCap(lineCap) {
|
|
875
|
-
this
|
|
915
|
+
__privateGet(this, _ctx).lineCap = lineCap;
|
|
876
916
|
}
|
|
877
917
|
get globalCompositeOperation() {
|
|
878
|
-
return this
|
|
918
|
+
return __privateGet(this, _ctx).globalCompositeOperation;
|
|
879
919
|
}
|
|
880
920
|
set globalCompositeOperation(operations) {
|
|
881
|
-
this
|
|
921
|
+
__privateGet(this, _ctx).globalCompositeOperation = operations;
|
|
882
922
|
}
|
|
883
923
|
fill(...args) {
|
|
884
|
-
return this
|
|
924
|
+
return __privateGet(this, _ctx).fill(...args);
|
|
885
925
|
}
|
|
886
926
|
arc(x2, y2, radius, startAngle, endAngle, anticlockwise) {
|
|
887
|
-
return this
|
|
927
|
+
return __privateGet(this, _ctx).arc(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius), startAngle, endAngle, anticlockwise);
|
|
888
928
|
}
|
|
889
929
|
rect(x2, y2, w2, h2) {
|
|
890
|
-
return this
|
|
930
|
+
return __privateGet(this, _ctx).rect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
|
|
891
931
|
}
|
|
892
932
|
fillRect(x2, y2, w2, h2) {
|
|
893
|
-
return this
|
|
933
|
+
return __privateGet(this, _ctx).fillRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
|
|
894
934
|
}
|
|
895
935
|
clearRect(x2, y2, w2, h2) {
|
|
896
|
-
return this
|
|
936
|
+
return __privateGet(this, _ctx).clearRect(this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(w2), this.$doPixelRatio(h2));
|
|
897
937
|
}
|
|
898
938
|
beginPath() {
|
|
899
|
-
return this
|
|
939
|
+
return __privateGet(this, _ctx).beginPath();
|
|
900
940
|
}
|
|
901
941
|
closePath() {
|
|
902
|
-
return this
|
|
942
|
+
return __privateGet(this, _ctx).closePath();
|
|
903
943
|
}
|
|
904
944
|
lineTo(x2, y2) {
|
|
905
|
-
return this
|
|
945
|
+
return __privateGet(this, _ctx).lineTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
906
946
|
}
|
|
907
947
|
moveTo(x2, y2) {
|
|
908
|
-
return this
|
|
948
|
+
return __privateGet(this, _ctx).moveTo(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
909
949
|
}
|
|
910
950
|
arcTo(x1, y1, x2, y2, radius) {
|
|
911
|
-
return this
|
|
951
|
+
return __privateGet(this, _ctx).arcTo(this.$doPixelRatio(x1), this.$doPixelRatio(y1), this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(radius));
|
|
912
952
|
}
|
|
913
953
|
getLineDash() {
|
|
914
|
-
return this
|
|
954
|
+
return __privateGet(this, _ctx).getLineDash();
|
|
915
955
|
}
|
|
916
956
|
setLineDash(nums) {
|
|
917
957
|
const dash = nums.map((n) => this.$doPixelRatio(n));
|
|
918
|
-
return this
|
|
958
|
+
return __privateGet(this, _ctx).setLineDash(dash);
|
|
919
959
|
}
|
|
920
960
|
stroke(path) {
|
|
921
|
-
return path ? this
|
|
961
|
+
return path ? __privateGet(this, _ctx).stroke(path) : __privateGet(this, _ctx).stroke();
|
|
922
962
|
}
|
|
923
963
|
translate(x2, y2) {
|
|
924
|
-
return this
|
|
964
|
+
return __privateGet(this, _ctx).translate(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
925
965
|
}
|
|
926
966
|
rotate(angle2) {
|
|
927
|
-
return this
|
|
967
|
+
return __privateGet(this, _ctx).rotate(angle2);
|
|
928
968
|
}
|
|
929
969
|
drawImage(...args) {
|
|
930
970
|
const image = args[0];
|
|
@@ -937,7 +977,7 @@ var iDrawUtil = function(exports) {
|
|
|
937
977
|
const dw = args[args.length - 2];
|
|
938
978
|
const dh = args[args.length - 1];
|
|
939
979
|
if (args.length === 9) {
|
|
940
|
-
return this
|
|
980
|
+
return __privateGet(this, _ctx).drawImage(
|
|
941
981
|
image,
|
|
942
982
|
this.$doPixelRatio(sx),
|
|
943
983
|
this.$doPixelRatio(sy),
|
|
@@ -949,41 +989,41 @@ var iDrawUtil = function(exports) {
|
|
|
949
989
|
this.$doPixelRatio(dh)
|
|
950
990
|
);
|
|
951
991
|
} else {
|
|
952
|
-
return this
|
|
992
|
+
return __privateGet(this, _ctx).drawImage(image, this.$doPixelRatio(dx), this.$doPixelRatio(dy), this.$doPixelRatio(dw), this.$doPixelRatio(dh));
|
|
953
993
|
}
|
|
954
994
|
}
|
|
955
995
|
createPattern(image, repetition) {
|
|
956
|
-
return this
|
|
996
|
+
return __privateGet(this, _ctx).createPattern(image, repetition);
|
|
957
997
|
}
|
|
958
998
|
measureText(text2) {
|
|
959
|
-
const textMetrics = this
|
|
999
|
+
const textMetrics = __privateGet(this, _ctx).measureText(text2);
|
|
960
1000
|
return textMetrics;
|
|
961
1001
|
}
|
|
962
1002
|
fillText(text2, x2, y2, maxWidth) {
|
|
963
1003
|
if (maxWidth !== void 0) {
|
|
964
|
-
return this
|
|
1004
|
+
return __privateGet(this, _ctx).fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
|
|
965
1005
|
} else {
|
|
966
|
-
return this
|
|
1006
|
+
return __privateGet(this, _ctx).fillText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
967
1007
|
}
|
|
968
1008
|
}
|
|
969
1009
|
strokeText(text2, x2, y2, maxWidth) {
|
|
970
1010
|
if (maxWidth !== void 0) {
|
|
971
|
-
return this
|
|
1011
|
+
return __privateGet(this, _ctx).strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2), this.$doPixelRatio(maxWidth));
|
|
972
1012
|
} else {
|
|
973
|
-
return this
|
|
1013
|
+
return __privateGet(this, _ctx).strokeText(text2, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
974
1014
|
}
|
|
975
1015
|
}
|
|
976
1016
|
save() {
|
|
977
|
-
this
|
|
1017
|
+
__privateGet(this, _ctx).save();
|
|
978
1018
|
}
|
|
979
1019
|
restore() {
|
|
980
|
-
this
|
|
1020
|
+
__privateGet(this, _ctx).restore();
|
|
981
1021
|
}
|
|
982
1022
|
scale(ratioX, ratioY) {
|
|
983
|
-
this
|
|
1023
|
+
__privateGet(this, _ctx).scale(ratioX, ratioY);
|
|
984
1024
|
}
|
|
985
1025
|
circle(x2, y2, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise) {
|
|
986
|
-
this
|
|
1026
|
+
__privateGet(this, _ctx).ellipse(
|
|
987
1027
|
this.$doPixelRatio(x2),
|
|
988
1028
|
this.$doPixelRatio(y2),
|
|
989
1029
|
this.$doPixelRatio(radiusX),
|
|
@@ -995,24 +1035,24 @@ var iDrawUtil = function(exports) {
|
|
|
995
1035
|
);
|
|
996
1036
|
}
|
|
997
1037
|
isPointInPath(x2, y2) {
|
|
998
|
-
return this
|
|
1038
|
+
return __privateGet(this, _ctx).isPointInPath(this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
999
1039
|
}
|
|
1000
1040
|
// clip(fillRule?: CanvasFillRule): void;
|
|
1001
1041
|
// clip(path: Path2D, fillRule?: CanvasFillRule): void;
|
|
1002
1042
|
clip(...args) {
|
|
1003
|
-
return this
|
|
1043
|
+
return __privateGet(this, _ctx).clip(...args);
|
|
1004
1044
|
}
|
|
1005
1045
|
setTransform(a, b, c, d, e, f) {
|
|
1006
|
-
return this
|
|
1046
|
+
return __privateGet(this, _ctx).setTransform(a, b, c, d, e, f);
|
|
1007
1047
|
}
|
|
1008
1048
|
getTransform() {
|
|
1009
|
-
return this
|
|
1049
|
+
return __privateGet(this, _ctx).getTransform();
|
|
1010
1050
|
}
|
|
1011
1051
|
createLinearGradient(x0, y0, x1, y1) {
|
|
1012
|
-
return this
|
|
1052
|
+
return __privateGet(this, _ctx).createLinearGradient(this.$doPixelRatio(x0), this.$doPixelRatio(y0), this.$doPixelRatio(x1), this.$doPixelRatio(y1));
|
|
1013
1053
|
}
|
|
1014
1054
|
createRadialGradient(x0, y0, r0, x1, y1, r1) {
|
|
1015
|
-
return this
|
|
1055
|
+
return __privateGet(this, _ctx).createRadialGradient(
|
|
1016
1056
|
this.$doPixelRatio(x0),
|
|
1017
1057
|
this.$doPixelRatio(y0),
|
|
1018
1058
|
this.$doPixelRatio(r0),
|
|
@@ -1022,9 +1062,11 @@ var iDrawUtil = function(exports) {
|
|
|
1022
1062
|
);
|
|
1023
1063
|
}
|
|
1024
1064
|
createConicGradient(startAngle, x2, y2) {
|
|
1025
|
-
return this
|
|
1065
|
+
return __privateGet(this, _ctx).createConicGradient(startAngle, this.$doPixelRatio(x2), this.$doPixelRatio(y2));
|
|
1026
1066
|
}
|
|
1027
1067
|
}
|
|
1068
|
+
_ctx = new WeakMap();
|
|
1069
|
+
_opts = new WeakMap();
|
|
1028
1070
|
function createContext2D(opts) {
|
|
1029
1071
|
const { width, height, ctx, devicePixelRatio } = opts;
|
|
1030
1072
|
let context = ctx;
|
|
@@ -1038,29 +1080,71 @@ var iDrawUtil = function(exports) {
|
|
|
1038
1080
|
return context2d;
|
|
1039
1081
|
}
|
|
1040
1082
|
function createOffscreenContext2D(opts) {
|
|
1041
|
-
const { width, height } = opts;
|
|
1042
|
-
const offCanvas = new OffscreenCanvas(width, height);
|
|
1083
|
+
const { width, height, devicePixelRatio } = opts;
|
|
1084
|
+
const offCanvas = new OffscreenCanvas(width * devicePixelRatio, height * devicePixelRatio);
|
|
1043
1085
|
const offRenderCtx = offCanvas.getContext("2d");
|
|
1044
1086
|
const offCtx = offRenderCtx.canvas.getContext("2d");
|
|
1045
|
-
|
|
1087
|
+
const context2d = new Context2D(offCtx, {
|
|
1088
|
+
devicePixelRatio,
|
|
1089
|
+
offscreenCanvas: offCanvas
|
|
1090
|
+
});
|
|
1091
|
+
return context2d;
|
|
1046
1092
|
}
|
|
1047
|
-
function
|
|
1093
|
+
function createViewContent(canvas, opts) {
|
|
1094
|
+
const { width, height, devicePixelRatio, offscreen } = opts;
|
|
1048
1095
|
const ctxOpts = {
|
|
1049
|
-
width
|
|
1050
|
-
height
|
|
1051
|
-
devicePixelRatio
|
|
1096
|
+
width,
|
|
1097
|
+
height,
|
|
1098
|
+
devicePixelRatio
|
|
1052
1099
|
};
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1100
|
+
if (offscreen === true) {
|
|
1101
|
+
const ctx = canvas.getContext("2d");
|
|
1102
|
+
const viewContext = createOffscreenContext2D(ctxOpts);
|
|
1103
|
+
const helperContext = createOffscreenContext2D(ctxOpts);
|
|
1104
|
+
const underContext = createOffscreenContext2D(ctxOpts);
|
|
1105
|
+
const boardContext = createContext2D({ ctx, ...ctxOpts });
|
|
1106
|
+
const drawView = () => {
|
|
1107
|
+
const { width: w2, height: h2 } = viewContext.$getSize();
|
|
1108
|
+
boardContext.clearRect(0, 0, w2, h2);
|
|
1109
|
+
boardContext.drawImage(underContext.canvas, 0, 0, w2, h2);
|
|
1110
|
+
boardContext.drawImage(viewContext.canvas, 0, 0, w2, h2);
|
|
1111
|
+
boardContext.drawImage(helperContext.canvas, 0, 0, w2, h2);
|
|
1112
|
+
underContext.clearRect(0, 0, w2, h2);
|
|
1113
|
+
viewContext.clearRect(0, 0, w2, h2);
|
|
1114
|
+
helperContext.clearRect(0, 0, w2, h2);
|
|
1115
|
+
};
|
|
1116
|
+
const content = {
|
|
1117
|
+
underContext,
|
|
1118
|
+
viewContext,
|
|
1119
|
+
helperContext,
|
|
1120
|
+
boardContext,
|
|
1121
|
+
drawView
|
|
1122
|
+
};
|
|
1123
|
+
return content;
|
|
1124
|
+
} else {
|
|
1125
|
+
const ctx = canvas.getContext("2d");
|
|
1126
|
+
const viewContext = createContext2D(ctxOpts);
|
|
1127
|
+
const helperContext = createContext2D(ctxOpts);
|
|
1128
|
+
const underContext = createContext2D(ctxOpts);
|
|
1129
|
+
const boardContext = createContext2D({ ctx, ...ctxOpts });
|
|
1130
|
+
const drawView = () => {
|
|
1131
|
+
boardContext.clearRect(0, 0, width, height);
|
|
1132
|
+
boardContext.drawImage(underContext.canvas, 0, 0, width, height);
|
|
1133
|
+
boardContext.drawImage(viewContext.canvas, 0, 0, width, height);
|
|
1134
|
+
boardContext.drawImage(helperContext.canvas, 0, 0, width, height);
|
|
1135
|
+
underContext.clearRect(0, 0, width, height);
|
|
1136
|
+
viewContext.clearRect(0, 0, width, height);
|
|
1137
|
+
helperContext.clearRect(0, 0, width, height);
|
|
1138
|
+
};
|
|
1139
|
+
const content = {
|
|
1140
|
+
underContext,
|
|
1141
|
+
viewContext,
|
|
1142
|
+
helperContext,
|
|
1143
|
+
boardContext,
|
|
1144
|
+
drawView
|
|
1145
|
+
};
|
|
1146
|
+
return content;
|
|
1147
|
+
}
|
|
1064
1148
|
}
|
|
1065
1149
|
class EventEmitter {
|
|
1066
1150
|
constructor() {
|
|
@@ -1556,51 +1640,6 @@ var iDrawUtil = function(exports) {
|
|
|
1556
1640
|
_scan(uuid, elements);
|
|
1557
1641
|
return groupQueue;
|
|
1558
1642
|
}
|
|
1559
|
-
function mergeElement(originElem, updateContent) {
|
|
1560
|
-
var _a;
|
|
1561
|
-
const commonKeys = Object.keys(updateContent);
|
|
1562
|
-
for (let i = 0; i < commonKeys.length; i++) {
|
|
1563
|
-
const commonKey = commonKeys[i];
|
|
1564
|
-
if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
|
|
1565
|
-
originElem[commonKey] = updateContent[commonKey];
|
|
1566
|
-
} else if (["detail", "operations"].includes(commonKey)) {
|
|
1567
|
-
if (istype.json(updateContent[commonKey])) {
|
|
1568
|
-
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
1569
|
-
originElem[commonKey] = {};
|
|
1570
|
-
}
|
|
1571
|
-
if (istype.json(originElem[commonKey])) {
|
|
1572
|
-
originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
|
|
1573
|
-
}
|
|
1574
|
-
} else if (istype.array(updateContent[commonKey])) {
|
|
1575
|
-
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
1576
|
-
originElem[commonKey] = [];
|
|
1577
|
-
}
|
|
1578
|
-
if (istype.array(originElem[commonKey])) {
|
|
1579
|
-
(_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
|
|
1580
|
-
originElem[commonKey][i2] = item;
|
|
1581
|
-
});
|
|
1582
|
-
originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
return originElem;
|
|
1588
|
-
}
|
|
1589
|
-
function updateElementInList(uuid, updateContent, elements) {
|
|
1590
|
-
var _a;
|
|
1591
|
-
let targetElement = null;
|
|
1592
|
-
for (let i = 0; i < elements.length; i++) {
|
|
1593
|
-
const elem = elements[i];
|
|
1594
|
-
if (elem.uuid === uuid) {
|
|
1595
|
-
mergeElement(elem, updateContent);
|
|
1596
|
-
targetElement = elem;
|
|
1597
|
-
break;
|
|
1598
|
-
} else if (elem.type === "group") {
|
|
1599
|
-
targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
return targetElement;
|
|
1603
|
-
}
|
|
1604
1643
|
function getElementSize(elem) {
|
|
1605
1644
|
const { x: x2, y: y2, w: w2, h: h2, angle: angle2 } = elem;
|
|
1606
1645
|
const size = { x: x2, y: y2, w: w2, h: h2, angle: angle2 };
|
|
@@ -1665,6 +1704,58 @@ var iDrawUtil = function(exports) {
|
|
|
1665
1704
|
function isResourceElement(elem) {
|
|
1666
1705
|
return ["image", "svg", "html"].includes(elem == null ? void 0 : elem.type);
|
|
1667
1706
|
}
|
|
1707
|
+
function findElementsFromListByPositions(positions, list) {
|
|
1708
|
+
const elements = [];
|
|
1709
|
+
positions.forEach((pos) => {
|
|
1710
|
+
const elem = findElementFromListByPosition(pos, list);
|
|
1711
|
+
if (elem) {
|
|
1712
|
+
elements.push(elem);
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
return elements;
|
|
1716
|
+
}
|
|
1717
|
+
function findElementFromListByPosition(position, list) {
|
|
1718
|
+
let result = null;
|
|
1719
|
+
let tempList = list;
|
|
1720
|
+
for (let i = 0; i < position.length; i++) {
|
|
1721
|
+
const pos = position[i];
|
|
1722
|
+
const item = tempList[pos];
|
|
1723
|
+
if (i < position.length - 1 && item.type === "group") {
|
|
1724
|
+
tempList = item.detail.children;
|
|
1725
|
+
} else if (i === position.length - 1) {
|
|
1726
|
+
result = item;
|
|
1727
|
+
} else {
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
return result;
|
|
1732
|
+
}
|
|
1733
|
+
function getElementPositionFromList(uuid, elements) {
|
|
1734
|
+
let result = [];
|
|
1735
|
+
let over = false;
|
|
1736
|
+
const _loop = (list) => {
|
|
1737
|
+
var _a;
|
|
1738
|
+
for (let i = 0; i < list.length; i++) {
|
|
1739
|
+
if (over === true) {
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
result.push(i);
|
|
1743
|
+
const elem = list[i];
|
|
1744
|
+
if (elem.uuid === uuid) {
|
|
1745
|
+
over = true;
|
|
1746
|
+
break;
|
|
1747
|
+
} else if (elem.type === "group") {
|
|
1748
|
+
_loop(((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
|
|
1749
|
+
}
|
|
1750
|
+
if (over) {
|
|
1751
|
+
break;
|
|
1752
|
+
}
|
|
1753
|
+
result.pop();
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
_loop(elements);
|
|
1757
|
+
return result;
|
|
1758
|
+
}
|
|
1668
1759
|
function checkRectIntersect(rect1, rect2) {
|
|
1669
1760
|
const react1MinX = rect1.x;
|
|
1670
1761
|
const react1MinY = rect1.y;
|
|
@@ -1676,6 +1767,25 @@ var iDrawUtil = function(exports) {
|
|
|
1676
1767
|
const react2MaxY = rect2.y + rect2.h;
|
|
1677
1768
|
return react1MinX <= react2MaxX && react1MaxX >= react2MinX && react1MinY <= react2MaxY && react1MaxY >= react2MinY;
|
|
1678
1769
|
}
|
|
1770
|
+
function calcViewScaleInfo(info, opts) {
|
|
1771
|
+
const { scale, offsetX, offsetY } = info;
|
|
1772
|
+
const { viewSizeInfo } = opts;
|
|
1773
|
+
const { width, height, contextWidth, contextHeight } = viewSizeInfo;
|
|
1774
|
+
const w2 = contextWidth * scale;
|
|
1775
|
+
const h2 = contextHeight * scale;
|
|
1776
|
+
const offsetLeft = 0 - offsetX * scale;
|
|
1777
|
+
const offsetTop = 0 - offsetY * scale;
|
|
1778
|
+
const offsetRight = width - (w2 + offsetLeft / scale);
|
|
1779
|
+
const offsetBottom = height - (h2 + offsetTop / scale);
|
|
1780
|
+
const newScaleInfo = {
|
|
1781
|
+
scale,
|
|
1782
|
+
offsetLeft,
|
|
1783
|
+
offsetTop,
|
|
1784
|
+
offsetRight,
|
|
1785
|
+
offsetBottom
|
|
1786
|
+
};
|
|
1787
|
+
return newScaleInfo;
|
|
1788
|
+
}
|
|
1679
1789
|
function viewScale(opts) {
|
|
1680
1790
|
const { scale, point, viewScaleInfo: prevViewScaleInfo } = opts;
|
|
1681
1791
|
const { offsetLeft, offsetTop } = prevViewScaleInfo;
|
|
@@ -2246,7 +2356,7 @@ var iDrawUtil = function(exports) {
|
|
|
2246
2356
|
}
|
|
2247
2357
|
function getDefaultElementDetailConfig() {
|
|
2248
2358
|
const config = {
|
|
2249
|
-
boxSizing: "
|
|
2359
|
+
boxSizing: "border-box",
|
|
2250
2360
|
borderWidth: 0,
|
|
2251
2361
|
borderColor: "#000000",
|
|
2252
2362
|
shadowColor: "#000000",
|
|
@@ -2262,10 +2372,60 @@ var iDrawUtil = function(exports) {
|
|
|
2262
2372
|
fontSize: 16,
|
|
2263
2373
|
lineHeight: 20,
|
|
2264
2374
|
fontFamily: "sans-serif",
|
|
2265
|
-
fontWeight: 400
|
|
2375
|
+
fontWeight: 400,
|
|
2376
|
+
overflow: "hidden"
|
|
2266
2377
|
};
|
|
2267
2378
|
return config;
|
|
2268
2379
|
}
|
|
2380
|
+
function getDefaultElementRectDetail() {
|
|
2381
|
+
const detail = {
|
|
2382
|
+
background: "#D9D9D9"
|
|
2383
|
+
};
|
|
2384
|
+
return detail;
|
|
2385
|
+
}
|
|
2386
|
+
function getDefaultElementCircleDetail(opts) {
|
|
2387
|
+
const detail = {
|
|
2388
|
+
background: "#D9D9D9",
|
|
2389
|
+
radius: 0
|
|
2390
|
+
};
|
|
2391
|
+
return detail;
|
|
2392
|
+
}
|
|
2393
|
+
function getDefaultElementTextDetail(opts) {
|
|
2394
|
+
var _a;
|
|
2395
|
+
const detailConfig = getDefaultElementDetailConfig();
|
|
2396
|
+
const scale = ((_a = opts == null ? void 0 : opts.viewScaleInfo) == null ? void 0 : _a.scale) || 1;
|
|
2397
|
+
const detail = {
|
|
2398
|
+
text: "Text Element",
|
|
2399
|
+
color: detailConfig.color,
|
|
2400
|
+
fontFamily: detailConfig.fontFamily,
|
|
2401
|
+
fontWeight: detailConfig.fontWeight,
|
|
2402
|
+
lineHeight: detailConfig.fontSize * scale,
|
|
2403
|
+
fontSize: detailConfig.fontSize * scale,
|
|
2404
|
+
textAlign: "center",
|
|
2405
|
+
verticalAlign: "middle"
|
|
2406
|
+
};
|
|
2407
|
+
return detail;
|
|
2408
|
+
}
|
|
2409
|
+
function getDefaultElementSVGDetail() {
|
|
2410
|
+
const detail = {
|
|
2411
|
+
svg: '<svg t="1701004189871" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200"><path d="M908.1 353.1l-253.9-36.9L540.7 86.1c-3.1-6.3-8.2-11.4-14.5-14.5-15.8-7.8-35-1.3-42.9 14.5L369.8 316.2l-253.9 36.9c-7 1-13.4 4.3-18.3 9.3-12.3 12.7-12.1 32.9 0.6 45.3l183.7 179.1-43.4 252.9c-1.2 6.9-0.1 14.1 3.2 20.3 8.2 15.6 27.6 21.7 43.2 13.4L512 754l227.1 119.4c6.2 3.3 13.4 4.4 20.3 3.2 17.4-3 29.1-19.5 26.1-36.9l-43.4-252.9 183.7-179.1c5-4.9 8.3-11.3 9.3-18.3 2.7-17.5-9.5-33.7-27-36.3zM664.8 561.6l36.1 210.3L512 672.7 323.1 772l36.1-210.3-152.8-149L417.6 382 512 190.7 606.4 382l211.2 30.7-152.8 148.9z" fill="#2c2c2c"></path></svg>'
|
|
2412
|
+
};
|
|
2413
|
+
return detail;
|
|
2414
|
+
}
|
|
2415
|
+
function getDefaultElementImageDetail() {
|
|
2416
|
+
const detail = {
|
|
2417
|
+
src: "data:image/svg+xml;base64,PHN2ZyAgIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiPjxwYXRoIGQ9Ik05MjggMTYwSDk2Yy0xNy43IDAtMzIgMTQuMy0zMiAzMnY2NDBjMCAxNy43IDE0LjMgMzIgMzIgMzJoODMyYzE3LjcgMCAzMi0xNC4zIDMyLTMyVjE5MmMwLTE3LjctMTQuMy0zMi0zMi0zMnogbS00MCA2MzJIMTM2di0zOS45bDEzOC41LTE2NC4zIDE1MC4xIDE3OEw2NTguMSA0ODkgODg4IDc2MS42Vjc5MnogbTAtMTI5LjhMNjY0LjIgMzk2LjhjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDQyNC42IDY2Ni40bC0xNDQtMTcwLjdjLTMuMi0zLjgtOS0zLjgtMTIuMiAwTDEzNiA2NTIuN1YyMzJoNzUydjQzMC4yeiIgIGZpbGw9IiM1MTUxNTEiPjwvcGF0aD48cGF0aCBkPSJNMzA0IDQ1NmM0OC42IDAgODgtMzkuNCA4OC04OHMtMzkuNC04OC04OC04OC04OCAzOS40LTg4IDg4IDM5LjQgODggODggODh6IG0wLTExNmMxNS41IDAgMjggMTIuNSAyOCAyOHMtMTIuNSAyOC0yOCAyOC0yOC0xMi41LTI4LTI4IDEyLjUtMjggMjgtMjh6IiAgZmlsbD0iIzUxNTE1MSI+PC9wYXRoPjwvc3ZnPg=="
|
|
2418
|
+
};
|
|
2419
|
+
return detail;
|
|
2420
|
+
}
|
|
2421
|
+
function getDefaultElementGroupDetail(opts) {
|
|
2422
|
+
const detail = {
|
|
2423
|
+
children: [],
|
|
2424
|
+
background: "#D9D9D9",
|
|
2425
|
+
overflow: "hidden"
|
|
2426
|
+
};
|
|
2427
|
+
return detail;
|
|
2428
|
+
}
|
|
2269
2429
|
const defaultElemConfig = getDefaultElementDetailConfig();
|
|
2270
2430
|
function calcViewBoxSize(viewElem, opts) {
|
|
2271
2431
|
const { viewScaleInfo } = opts;
|
|
@@ -2284,7 +2444,7 @@ var iDrawUtil = function(exports) {
|
|
|
2284
2444
|
}
|
|
2285
2445
|
let bw = 0;
|
|
2286
2446
|
if (typeof borderWidth2 === "number") {
|
|
2287
|
-
bw = (borderWidth2 ||
|
|
2447
|
+
bw = (borderWidth2 || 0) * scale;
|
|
2288
2448
|
}
|
|
2289
2449
|
if (boxSizing === "border-box") {
|
|
2290
2450
|
x2 = viewElem.x + bw / 2;
|
|
@@ -2302,6 +2462,11 @@ var iDrawUtil = function(exports) {
|
|
|
2302
2462
|
w2 = viewElem.w;
|
|
2303
2463
|
h2 = viewElem.h;
|
|
2304
2464
|
}
|
|
2465
|
+
w2 = Math.max(w2, 1);
|
|
2466
|
+
h2 = Math.max(h2, 1);
|
|
2467
|
+
radiusList = radiusList.map((r) => {
|
|
2468
|
+
return Math.min(r, w2 / 2, h2 / 2);
|
|
2469
|
+
});
|
|
2305
2470
|
return {
|
|
2306
2471
|
x: x2,
|
|
2307
2472
|
y: y2,
|
|
@@ -2310,6 +2475,219 @@ var iDrawUtil = function(exports) {
|
|
|
2310
2475
|
radiusList
|
|
2311
2476
|
};
|
|
2312
2477
|
}
|
|
2478
|
+
const defaultViewWidth = 200;
|
|
2479
|
+
const defaultViewHeight = 200;
|
|
2480
|
+
const defaultDetail = getDefaultElementDetailConfig();
|
|
2481
|
+
function createElementSize(type, opts) {
|
|
2482
|
+
let x2 = 0;
|
|
2483
|
+
let y2 = 0;
|
|
2484
|
+
let w2 = defaultViewWidth;
|
|
2485
|
+
let h2 = defaultViewHeight;
|
|
2486
|
+
if (opts) {
|
|
2487
|
+
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
2488
|
+
const { scale, offsetLeft, offsetTop } = viewScaleInfo;
|
|
2489
|
+
const { width, height } = viewSizeInfo;
|
|
2490
|
+
if (type === "text") {
|
|
2491
|
+
const textDetail = getDefaultElementTextDetail();
|
|
2492
|
+
w2 = defaultDetail.fontSize * scale * textDetail.text.length;
|
|
2493
|
+
h2 = defaultDetail.fontSize * scale * 2;
|
|
2494
|
+
} else {
|
|
2495
|
+
const limitViewWidth = width / 4;
|
|
2496
|
+
const limitViewHeight = height / 4;
|
|
2497
|
+
if (defaultViewWidth >= limitViewWidth) {
|
|
2498
|
+
w2 = limitViewWidth / scale;
|
|
2499
|
+
} else {
|
|
2500
|
+
w2 = defaultViewWidth / scale;
|
|
2501
|
+
}
|
|
2502
|
+
if (defaultViewHeight >= limitViewHeight) {
|
|
2503
|
+
h2 = limitViewHeight / scale;
|
|
2504
|
+
} else {
|
|
2505
|
+
h2 = defaultViewHeight / scale;
|
|
2506
|
+
}
|
|
2507
|
+
if (["circle", "svg", "image"].includes(type)) {
|
|
2508
|
+
w2 = h2 = Math.max(w2, h2);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
x2 = (0 - offsetLeft + width / 2 - w2 * scale / 2) / scale;
|
|
2512
|
+
y2 = (0 - offsetTop + height / 2 - h2 * scale / 2) / scale;
|
|
2513
|
+
}
|
|
2514
|
+
const elemSize = {
|
|
2515
|
+
x: x2,
|
|
2516
|
+
y: y2,
|
|
2517
|
+
w: w2,
|
|
2518
|
+
h: h2
|
|
2519
|
+
};
|
|
2520
|
+
return elemSize;
|
|
2521
|
+
}
|
|
2522
|
+
function createElement(type, baseElem, opts) {
|
|
2523
|
+
const elemSize = createElementSize(type, opts);
|
|
2524
|
+
let detail = {};
|
|
2525
|
+
if (type === "rect") {
|
|
2526
|
+
detail = getDefaultElementRectDetail();
|
|
2527
|
+
} else if (type === "circle") {
|
|
2528
|
+
detail = getDefaultElementCircleDetail({
|
|
2529
|
+
radius: elemSize.w
|
|
2530
|
+
});
|
|
2531
|
+
} else if (type === "text") {
|
|
2532
|
+
detail = getDefaultElementTextDetail(opts);
|
|
2533
|
+
} else if (type === "svg") {
|
|
2534
|
+
detail = getDefaultElementSVGDetail();
|
|
2535
|
+
} else if (type === "image") {
|
|
2536
|
+
detail = getDefaultElementImageDetail();
|
|
2537
|
+
} else if (type === "group") {
|
|
2538
|
+
detail = getDefaultElementGroupDetail();
|
|
2539
|
+
}
|
|
2540
|
+
const elem = {
|
|
2541
|
+
...elemSize,
|
|
2542
|
+
...baseElem,
|
|
2543
|
+
uuid: createUUID(),
|
|
2544
|
+
type,
|
|
2545
|
+
detail: {
|
|
2546
|
+
...detail,
|
|
2547
|
+
...baseElem.detail || {}
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
return elem;
|
|
2551
|
+
}
|
|
2552
|
+
function insertElementToListByPosition(element, position, list) {
|
|
2553
|
+
let result = false;
|
|
2554
|
+
if (position.length === 1) {
|
|
2555
|
+
const pos = position[0];
|
|
2556
|
+
list.splice(pos, 0, element);
|
|
2557
|
+
result = true;
|
|
2558
|
+
} else if (position.length > 1) {
|
|
2559
|
+
let tempList = list;
|
|
2560
|
+
for (let i = 0; i < position.length; i++) {
|
|
2561
|
+
const pos = position[i];
|
|
2562
|
+
const item = tempList[pos];
|
|
2563
|
+
if (i === position.length - 1) {
|
|
2564
|
+
const pos2 = position[i];
|
|
2565
|
+
tempList.splice(pos2, 0, element);
|
|
2566
|
+
result = true;
|
|
2567
|
+
} else if (i < position.length - 1 && item.type === "group") {
|
|
2568
|
+
tempList = item.detail.children;
|
|
2569
|
+
} else {
|
|
2570
|
+
break;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
return result;
|
|
2575
|
+
}
|
|
2576
|
+
function deleteElementInListByPosition(position, list) {
|
|
2577
|
+
let result = false;
|
|
2578
|
+
if (position.length === 1) {
|
|
2579
|
+
const pos = position[0];
|
|
2580
|
+
list.splice(pos, 1);
|
|
2581
|
+
result = true;
|
|
2582
|
+
} else if (position.length > 1) {
|
|
2583
|
+
let tempList = list;
|
|
2584
|
+
for (let i = 0; i < position.length; i++) {
|
|
2585
|
+
const pos = position[i];
|
|
2586
|
+
const item = tempList[pos];
|
|
2587
|
+
if (i === position.length - 1) {
|
|
2588
|
+
const pos2 = position[i];
|
|
2589
|
+
tempList.splice(pos2, 1);
|
|
2590
|
+
result = true;
|
|
2591
|
+
} else if (i < position.length - 1 && item.type === "group") {
|
|
2592
|
+
tempList = item.detail.children;
|
|
2593
|
+
} else {
|
|
2594
|
+
break;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
return result;
|
|
2599
|
+
}
|
|
2600
|
+
function deleteElementInList(uuid, list) {
|
|
2601
|
+
const position = getElementPositionFromList(uuid, list);
|
|
2602
|
+
return deleteElementInListByPosition(position, list);
|
|
2603
|
+
}
|
|
2604
|
+
function moveElementPosition(elements, opts) {
|
|
2605
|
+
const { from, to } = opts;
|
|
2606
|
+
if (from.length === 0 || to.length === 0) {
|
|
2607
|
+
return elements;
|
|
2608
|
+
}
|
|
2609
|
+
if (from.length <= to.length) {
|
|
2610
|
+
for (let i = 0; i < from.length; i++) {
|
|
2611
|
+
if (to[i] === from[i]) {
|
|
2612
|
+
if (i === from.length - 1) {
|
|
2613
|
+
return elements;
|
|
2614
|
+
}
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
const target = findElementFromListByPosition(from, elements);
|
|
2620
|
+
if (target) {
|
|
2621
|
+
const insterResult = insertElementToListByPosition(target, to, elements);
|
|
2622
|
+
if (!insterResult) {
|
|
2623
|
+
return elements;
|
|
2624
|
+
}
|
|
2625
|
+
let trimDeletePosIndex = -1;
|
|
2626
|
+
for (let i = 0; i < from.length; i++) {
|
|
2627
|
+
if (!(to[i] >= 0)) {
|
|
2628
|
+
break;
|
|
2629
|
+
}
|
|
2630
|
+
if (to[i] === from[i]) {
|
|
2631
|
+
continue;
|
|
2632
|
+
}
|
|
2633
|
+
if (to[i] < from[i] && i == to.length - 1) {
|
|
2634
|
+
trimDeletePosIndex = i;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
if (trimDeletePosIndex >= 0) {
|
|
2638
|
+
{
|
|
2639
|
+
from[trimDeletePosIndex] = from[trimDeletePosIndex] + 1;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
deleteElementInListByPosition(from, elements);
|
|
2643
|
+
}
|
|
2644
|
+
return elements;
|
|
2645
|
+
}
|
|
2646
|
+
function mergeElement(originElem, updateContent) {
|
|
2647
|
+
var _a;
|
|
2648
|
+
const commonKeys = Object.keys(updateContent);
|
|
2649
|
+
for (let i = 0; i < commonKeys.length; i++) {
|
|
2650
|
+
const commonKey = commonKeys[i];
|
|
2651
|
+
if (["x", "y", "w", "h", "angle", "name"].includes(commonKey)) {
|
|
2652
|
+
originElem[commonKey] = updateContent[commonKey];
|
|
2653
|
+
} else if (["detail", "operations"].includes(commonKey)) {
|
|
2654
|
+
if (istype.json(updateContent[commonKey])) {
|
|
2655
|
+
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
2656
|
+
originElem[commonKey] = {};
|
|
2657
|
+
}
|
|
2658
|
+
if (istype.json(originElem[commonKey])) {
|
|
2659
|
+
originElem[commonKey] = { ...originElem[commonKey], ...updateContent[commonKey] };
|
|
2660
|
+
}
|
|
2661
|
+
} else if (istype.array(updateContent[commonKey])) {
|
|
2662
|
+
if (!(originElem == null ? void 0 : originElem.hasOwnProperty(commonKey))) {
|
|
2663
|
+
originElem[commonKey] = [];
|
|
2664
|
+
}
|
|
2665
|
+
if (istype.array(originElem[commonKey])) {
|
|
2666
|
+
(_a = updateContent == null ? void 0 : updateContent[commonKey]) == null ? void 0 : _a.forEach((item, i2) => {
|
|
2667
|
+
originElem[commonKey][i2] = item;
|
|
2668
|
+
});
|
|
2669
|
+
originElem[commonKey] = [...originElem[commonKey], ...updateContent[commonKey]];
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
return originElem;
|
|
2675
|
+
}
|
|
2676
|
+
function updateElementInList(uuid, updateContent, elements) {
|
|
2677
|
+
var _a;
|
|
2678
|
+
let targetElement = null;
|
|
2679
|
+
for (let i = 0; i < elements.length; i++) {
|
|
2680
|
+
const elem = elements[i];
|
|
2681
|
+
if (elem.uuid === uuid) {
|
|
2682
|
+
mergeElement(elem, updateContent);
|
|
2683
|
+
targetElement = elem;
|
|
2684
|
+
break;
|
|
2685
|
+
} else if (elem.type === "group") {
|
|
2686
|
+
targetElement = updateElementInList(uuid, updateContent, ((_a = elem == null ? void 0 : elem.detail) == null ? void 0 : _a.children) || []);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
return targetElement;
|
|
2690
|
+
}
|
|
2313
2691
|
exports.Context2D = Context2D;
|
|
2314
2692
|
exports.EventEmitter = EventEmitter;
|
|
2315
2693
|
exports.Store = Store;
|
|
@@ -2326,6 +2704,7 @@ var iDrawUtil = function(exports) {
|
|
|
2326
2704
|
exports.calcViewBoxSize = calcViewBoxSize;
|
|
2327
2705
|
exports.calcViewElementSize = calcViewElementSize;
|
|
2328
2706
|
exports.calcViewPointSize = calcViewPointSize;
|
|
2707
|
+
exports.calcViewScaleInfo = calcViewScaleInfo;
|
|
2329
2708
|
exports.calcViewVertexes = calcViewVertexes;
|
|
2330
2709
|
exports.check = check;
|
|
2331
2710
|
exports.checkRectIntersect = checkRectIntersect;
|
|
@@ -2335,24 +2714,31 @@ var iDrawUtil = function(exports) {
|
|
|
2335
2714
|
exports.compose = compose;
|
|
2336
2715
|
exports.compressImage = compressImage;
|
|
2337
2716
|
exports.createAssetId = createAssetId;
|
|
2338
|
-
exports.createBoardContexts = createBoardContexts;
|
|
2339
2717
|
exports.createContext2D = createContext2D;
|
|
2718
|
+
exports.createElement = createElement;
|
|
2340
2719
|
exports.createOffscreenContext2D = createOffscreenContext2D;
|
|
2341
2720
|
exports.createUUID = createUUID;
|
|
2721
|
+
exports.createViewContent = createViewContent;
|
|
2342
2722
|
exports.deepClone = deepClone;
|
|
2343
2723
|
exports.delay = delay;
|
|
2724
|
+
exports.deleteElementInList = deleteElementInList;
|
|
2725
|
+
exports.deleteElementInListByPosition = deleteElementInListByPosition;
|
|
2344
2726
|
exports.downloadImageFromCanvas = downloadImageFromCanvas;
|
|
2345
2727
|
exports.equalPoint = equalPoint;
|
|
2346
2728
|
exports.equalTouchPoint = equalTouchPoint;
|
|
2347
2729
|
exports.filterElementAsset = filterElementAsset;
|
|
2348
2730
|
exports.findElementFromList = findElementFromList;
|
|
2731
|
+
exports.findElementFromListByPosition = findElementFromListByPosition;
|
|
2349
2732
|
exports.findElementsFromList = findElementsFromList;
|
|
2733
|
+
exports.findElementsFromListByPositions = findElementsFromListByPositions;
|
|
2350
2734
|
exports.formatNumber = formatNumber;
|
|
2351
2735
|
exports.generateHTML = generateHTML;
|
|
2352
2736
|
exports.generateSVGPath = generateSVGPath;
|
|
2353
2737
|
exports.getCenterFromTwoPoints = getCenterFromTwoPoints;
|
|
2354
2738
|
exports.getDefaultElementDetailConfig = getDefaultElementDetailConfig;
|
|
2739
|
+
exports.getDefaultElementRectDetail = getDefaultElementRectDetail;
|
|
2355
2740
|
exports.getElemenetsAssetIds = getElemenetsAssetIds;
|
|
2741
|
+
exports.getElementPositionFromList = getElementPositionFromList;
|
|
2356
2742
|
exports.getElementRotateVertexes = getElementRotateVertexes;
|
|
2357
2743
|
exports.getElementSize = getElementSize;
|
|
2358
2744
|
exports.getElementVertexes = getElementVertexes;
|
|
@@ -2361,6 +2747,7 @@ var iDrawUtil = function(exports) {
|
|
|
2361
2747
|
exports.getViewPointAtElement = getViewPointAtElement;
|
|
2362
2748
|
exports.getViewScaleInfoFromSnapshot = getViewScaleInfoFromSnapshot;
|
|
2363
2749
|
exports.getViewSizeInfoFromSnapshot = getViewSizeInfoFromSnapshot;
|
|
2750
|
+
exports.insertElementToListByPosition = insertElementToListByPosition;
|
|
2364
2751
|
exports.is = is;
|
|
2365
2752
|
exports.isAssetId = isAssetId;
|
|
2366
2753
|
exports.isColorStr = isColorStr;
|
|
@@ -2376,6 +2763,7 @@ var iDrawUtil = function(exports) {
|
|
|
2376
2763
|
exports.matrixToRadian = matrixToRadian;
|
|
2377
2764
|
exports.mergeElementAsset = mergeElementAsset;
|
|
2378
2765
|
exports.mergeHexColorAlpha = mergeHexColorAlpha;
|
|
2766
|
+
exports.moveElementPosition = moveElementPosition;
|
|
2379
2767
|
exports.parseAngleToRadian = parseAngleToRadian;
|
|
2380
2768
|
exports.parseFileToBase64 = parseFileToBase64;
|
|
2381
2769
|
exports.parseFileToText = parseFileToText;
|