@univerjs/drawing-ui 0.21.1 → 0.22.0

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/lib/es/index.js CHANGED
@@ -9,18 +9,6 @@ import { useEffect, useRef, useState } from "react";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
10
 
11
11
  //#region src/commands/operations/drawing-align.operation.ts
12
- let AlignType = /* @__PURE__ */ function(AlignType) {
13
- AlignType["default"] = "0";
14
- AlignType["left"] = "1";
15
- AlignType["center"] = "2";
16
- AlignType["right"] = "3";
17
- AlignType["top"] = "4";
18
- AlignType["middle"] = "5";
19
- AlignType["bottom"] = "6";
20
- AlignType["horizon"] = "7";
21
- AlignType["vertical"] = "8";
22
- return AlignType;
23
- }({});
24
12
  /**
25
13
  * Set drawing align operation, including left, center, right, top, middle, bottom, horizon and vertical align.
26
14
  */
@@ -35,56 +23,56 @@ const SetDrawingAlignLeftOperation = {
35
23
  id: "sheet.operation.set-drawing-align-left",
36
24
  type: CommandType.OPERATION,
37
25
  handler: (accessor) => {
38
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.left });
26
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "1" });
39
27
  }
40
28
  };
41
29
  const SetDrawingAlignCenterOperation = {
42
30
  id: "sheet.operation.set-drawing-align-center",
43
31
  type: CommandType.OPERATION,
44
32
  handler: (accessor) => {
45
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.center });
33
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "2" });
46
34
  }
47
35
  };
48
36
  const SetDrawingAlignRightOperation = {
49
37
  id: "sheet.operation.set-drawing-align-right",
50
38
  type: CommandType.OPERATION,
51
39
  handler: (accessor) => {
52
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.right });
40
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "3" });
53
41
  }
54
42
  };
55
43
  const SetDrawingAlignTopOperation = {
56
44
  id: "sheet.operation.set-drawing-align-top",
57
45
  type: CommandType.OPERATION,
58
46
  handler: (accessor) => {
59
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.top });
47
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "4" });
60
48
  }
61
49
  };
62
50
  const SetDrawingAlignMiddleOperation = {
63
51
  id: "sheet.operation.set-drawing-align-middle",
64
52
  type: CommandType.OPERATION,
65
53
  handler: (accessor) => {
66
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.middle });
54
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "5" });
67
55
  }
68
56
  };
69
57
  const SetDrawingAlignBottomOperation = {
70
58
  id: "sheet.operation.set-drawing-align-bottom",
71
59
  type: CommandType.OPERATION,
72
60
  handler: (accessor) => {
73
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.bottom });
61
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "6" });
74
62
  }
75
63
  };
76
64
  const SetDrawingAlignHorizonOperation = {
77
65
  id: "sheet.operation.set-drawing-align-horizon",
78
66
  type: CommandType.OPERATION,
79
67
  handler: (accessor) => {
80
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.horizon });
68
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "7" });
81
69
  }
82
70
  };
83
71
  const SetDrawingAlignVerticalOperation = {
84
72
  id: "sheet.operation.set-drawing-align-vertical",
85
73
  type: CommandType.OPERATION,
86
74
  handler: (accessor) => {
87
- return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.vertical });
75
+ return accessor.get(ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: "8" });
88
76
  }
89
77
  };
90
78
 
@@ -260,19 +248,6 @@ const CloseImageCropOperation = {
260
248
  return true;
261
249
  }
262
250
  };
263
- let CropType = /* @__PURE__ */ function(CropType) {
264
- CropType["FREE"] = "0";
265
- CropType["R1_1"] = "1";
266
- CropType["R16_9"] = "2";
267
- CropType["R9_16"] = "3";
268
- CropType["R5_4"] = "4";
269
- CropType["R4_5"] = "5";
270
- CropType["R4_3"] = "6";
271
- CropType["R3_4"] = "7";
272
- CropType["R3_2"] = "8";
273
- CropType["R2_3"] = "9";
274
- return CropType;
275
- }({});
276
251
  const AutoImageCropOperation = {
277
252
  id: "sheet.operation.Auto-image-crop",
278
253
  type: CommandType.OPERATION,
@@ -346,7 +321,7 @@ function getCurrentUnitInfo(currentUniverService, propUnitId) {
346
321
  //#endregion
347
322
  //#region package.json
348
323
  var name = "@univerjs/drawing-ui";
349
- var version = "0.21.1";
324
+ var version = "0.22.0";
350
325
 
351
326
  //#endregion
352
327
  //#region src/config/config.ts
@@ -685,7 +660,7 @@ function ImagePopupMenu(props) {
685
660
  }
686
661
 
687
662
  //#endregion
688
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
663
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
689
664
  function __decorateParam(paramIndex, decorator) {
690
665
  return function(target, key) {
691
666
  decorator(target, key, paramIndex);
@@ -693,7 +668,7 @@ function __decorateParam(paramIndex, decorator) {
693
668
  }
694
669
 
695
670
  //#endregion
696
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
671
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
697
672
  function __decorate(decorators, target, key, desc) {
698
673
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
699
674
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -810,7 +785,7 @@ function getUpdateParams(objects, drawingManagerService) {
810
785
  }
811
786
 
812
787
  //#endregion
813
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
788
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
814
789
  function _typeof(o) {
815
790
  "@babel/helpers - typeof";
816
791
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -821,7 +796,7 @@ function _typeof(o) {
821
796
  }
822
797
 
823
798
  //#endregion
824
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
799
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
825
800
  function toPrimitive(t, r) {
826
801
  if ("object" != _typeof(t) || !t) return t;
827
802
  var e = t[Symbol.toPrimitive];
@@ -834,14 +809,14 @@ function toPrimitive(t, r) {
834
809
  }
835
810
 
836
811
  //#endregion
837
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
812
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
838
813
  function toPropertyKey(t) {
839
814
  var i = toPrimitive(t, "string");
840
815
  return "symbol" == _typeof(i) ? i : i + "";
841
816
  }
842
817
 
843
818
  //#endregion
844
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
819
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
845
820
  function _defineProperty(e, r, t) {
846
821
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
847
822
  value: t,
@@ -1011,7 +986,7 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1011
986
  _drawingAlign(params) {
1012
987
  const { alignType } = params;
1013
988
  const drawings = params.drawings || this._drawingManagerService.getFocusDrawings();
1014
- if (alignType === AlignType.default) return;
989
+ if (alignType === "0") return;
1015
990
  const drawingTransformCaches = [];
1016
991
  let minLeft = Number.POSITIVE_INFINITY;
1017
992
  let minTop = Number.POSITIVE_INFINITY;
@@ -1057,28 +1032,28 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1057
1032
  let newLeft = left;
1058
1033
  let newTop = top;
1059
1034
  switch (alignType) {
1060
- case AlignType.left:
1035
+ case "1":
1061
1036
  newLeft = minLeft;
1062
1037
  break;
1063
- case AlignType.center:
1038
+ case "2":
1064
1039
  newLeft = minLeft + (maxRight - minLeft) / 2 - width / 2;
1065
1040
  break;
1066
- case AlignType.right:
1041
+ case "3":
1067
1042
  newLeft = maxRight - width;
1068
1043
  break;
1069
- case AlignType.top:
1044
+ case "4":
1070
1045
  newTop = minTop;
1071
1046
  break;
1072
- case AlignType.middle:
1047
+ case "5":
1073
1048
  newTop = minTop + (maxBottom - minTop) / 2 - height / 2;
1074
1049
  break;
1075
- case AlignType.bottom:
1050
+ case "6":
1076
1051
  newTop = maxBottom - height;
1077
1052
  break;
1078
- case AlignType.horizon:
1053
+ case "7":
1079
1054
  newLeft = minLeft + averageHorizon * index;
1080
1055
  break;
1081
- case AlignType.vertical:
1056
+ case "8":
1082
1057
  newTop = minTop + averageVertical * index;
1083
1058
  break;
1084
1059
  default: break;
@@ -1104,14 +1079,14 @@ let DrawingUpdateController = class DrawingUpdateController extends Disposable {
1104
1079
  const { left: aLeft = 0, top: aTop = 0, width: aWidth = 0, height: aHeight = 0 } = aTransform;
1105
1080
  const { left: bLeft = 0, top: bTop = 0, width: bWidth = 0, height: bHeight = 0 } = bTransform;
1106
1081
  switch (alignType) {
1107
- case AlignType.left: return aLeft - bLeft;
1108
- case AlignType.center: return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
1109
- case AlignType.right: return aLeft + aWidth - (bLeft + bWidth);
1110
- case AlignType.top: return aTop - bTop;
1111
- case AlignType.middle: return aTop + aHeight / 2 - (bTop + bHeight / 2);
1112
- case AlignType.bottom: return aTop + aHeight - (bTop + bHeight);
1113
- case AlignType.horizon: return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
1114
- case AlignType.vertical: return aTop + aHeight / 2 - (bTop + bHeight / 2);
1082
+ case "1": return aLeft - bLeft;
1083
+ case "2": return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
1084
+ case "3": return aLeft + aWidth - (bLeft + bWidth);
1085
+ case "4": return aTop - bTop;
1086
+ case "5": return aTop + aHeight / 2 - (bTop + bHeight / 2);
1087
+ case "6": return aTop + aHeight - (bTop + bHeight);
1088
+ case "7": return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
1089
+ case "8": return aTop + aHeight / 2 - (bTop + bHeight / 2);
1115
1090
  default: return 0;
1116
1091
  }
1117
1092
  });
@@ -1343,11 +1318,6 @@ DrawingUpdateController = __decorate([
1343
1318
 
1344
1319
  //#endregion
1345
1320
  //#region src/views/crop/image-cropper-object.ts
1346
- var ImageCropperObjectType = /* @__PURE__ */ function(ImageCropperObjectType) {
1347
- ImageCropperObjectType[ImageCropperObjectType["RECT"] = 0] = "RECT";
1348
- ImageCropperObjectType[ImageCropperObjectType["PATH"] = 1] = "PATH";
1349
- return ImageCropperObjectType;
1350
- }(ImageCropperObjectType || {});
1351
1321
  var ImageCropperObject = class extends Shape {
1352
1322
  constructor(key, props) {
1353
1323
  if (props == null) props = {};
@@ -1426,11 +1396,11 @@ var ImageCropperObject = class extends Shape {
1426
1396
  cacheCtx.restore();
1427
1397
  }
1428
1398
  _clipForApplyObject(cacheCtx) {
1429
- let objectType = ImageCropperObjectType.RECT;
1430
- if (this._prstGeom != null) objectType = ImageCropperObjectType.PATH;
1399
+ let objectType = 0;
1400
+ if (this._prstGeom != null) objectType = 1;
1431
1401
  cacheCtx.globalCompositeOperation = "destination-out";
1432
1402
  cacheCtx.beginPath();
1433
- if (objectType === ImageCropperObjectType.RECT) {
1403
+ if (objectType === 0) {
1434
1404
  const m = this.transform.getMatrix();
1435
1405
  cacheCtx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
1436
1406
  cacheCtx.rect(0, 0, this.width, this.height);
@@ -1561,34 +1531,34 @@ let ImageCropperController = class ImageCropperController extends Disposable {
1561
1531
  const { left, top, width, height } = imageShape.calculateTransformWithSrcRect();
1562
1532
  let newSrcRect;
1563
1533
  switch (cropType) {
1564
- case CropType.R1_1:
1534
+ case "1":
1565
1535
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 1, 1);
1566
1536
  break;
1567
- case CropType.R16_9:
1537
+ case "2":
1568
1538
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 16, 9);
1569
1539
  break;
1570
- case CropType.R9_16:
1540
+ case "3":
1571
1541
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 9, 16);
1572
1542
  break;
1573
- case CropType.R5_4:
1543
+ case "4":
1574
1544
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 5, 4);
1575
1545
  break;
1576
- case CropType.R4_5:
1546
+ case "5":
1577
1547
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 5);
1578
1548
  break;
1579
- case CropType.R4_3:
1549
+ case "6":
1580
1550
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 3);
1581
1551
  break;
1582
- case CropType.R3_4:
1552
+ case "7":
1583
1553
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 4);
1584
1554
  break;
1585
- case CropType.R3_2:
1555
+ case "8":
1586
1556
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 2);
1587
1557
  break;
1588
- case CropType.R2_3:
1558
+ case "9":
1589
1559
  newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 2, 3);
1590
1560
  break;
1591
- case CropType.FREE:
1561
+ case "0":
1592
1562
  default: break;
1593
1563
  }
1594
1564
  if (newSrcRect == null) return;
@@ -2225,46 +2195,46 @@ const DrawingAlign = (props) => {
2225
2195
  const commandService = useDependency(ICommandService);
2226
2196
  const localeService = useDependency(LocaleService);
2227
2197
  const { drawings, alignShow } = props;
2228
- const [alignValue, setAlignValue] = useState(AlignType.default);
2198
+ const [alignValue, setAlignValue] = useState("0");
2229
2199
  const alignOptions = [
2230
2200
  {
2231
2201
  label: localeService.t("image-panel.align.default"),
2232
- value: AlignType.default
2202
+ value: "0"
2233
2203
  },
2234
2204
  { options: [
2235
2205
  {
2236
2206
  label: localeService.t("image-panel.align.left"),
2237
- value: AlignType.left
2207
+ value: "1"
2238
2208
  },
2239
2209
  {
2240
2210
  label: localeService.t("image-panel.align.center"),
2241
- value: AlignType.center
2211
+ value: "2"
2242
2212
  },
2243
2213
  {
2244
2214
  label: localeService.t("image-panel.align.right"),
2245
- value: AlignType.right
2215
+ value: "3"
2246
2216
  }
2247
2217
  ] },
2248
2218
  { options: [
2249
2219
  {
2250
2220
  label: localeService.t("image-panel.align.top"),
2251
- value: AlignType.top
2221
+ value: "4"
2252
2222
  },
2253
2223
  {
2254
2224
  label: localeService.t("image-panel.align.middle"),
2255
- value: AlignType.middle
2225
+ value: "5"
2256
2226
  },
2257
2227
  {
2258
2228
  label: localeService.t("image-panel.align.bottom"),
2259
- value: AlignType.bottom
2229
+ value: "6"
2260
2230
  }
2261
2231
  ] },
2262
2232
  { options: [{
2263
2233
  label: localeService.t("image-panel.align.horizon"),
2264
- value: AlignType.horizon
2234
+ value: "7"
2265
2235
  }, {
2266
2236
  label: localeService.t("image-panel.align.vertical"),
2267
- value: AlignType.vertical
2237
+ value: "8"
2268
2238
  }] }
2269
2239
  ];
2270
2240
  function handleAlignChange(value) {
@@ -2688,48 +2658,48 @@ const ImageCropper = (props) => {
2688
2658
  const canUseShapeClip = useObservable(clipService.canUseShapeClip$, false);
2689
2659
  const { drawings, cropperShow } = props;
2690
2660
  if (drawings[0] == null) return;
2691
- const [cropValue, setCropValue] = useState(CropType.FREE);
2661
+ const [cropValue, setCropValue] = useState("0");
2692
2662
  const cropStateRef = useRef(false);
2693
2663
  const cropOptions = [
2694
2664
  {
2695
2665
  label: localeService.t("image-panel.crop.mode"),
2696
- value: CropType.FREE
2666
+ value: "0"
2697
2667
  },
2698
2668
  {
2699
2669
  label: "1:1",
2700
- value: CropType.R1_1
2670
+ value: "1"
2701
2671
  },
2702
2672
  {
2703
2673
  label: "16:9",
2704
- value: CropType.R16_9
2674
+ value: "2"
2705
2675
  },
2706
2676
  {
2707
2677
  label: "9:16",
2708
- value: CropType.R9_16
2678
+ value: "3"
2709
2679
  },
2710
2680
  {
2711
2681
  label: "5:4",
2712
- value: CropType.R5_4
2682
+ value: "4"
2713
2683
  },
2714
2684
  {
2715
2685
  label: "4:5",
2716
- value: CropType.R4_5
2686
+ value: "5"
2717
2687
  },
2718
2688
  {
2719
2689
  label: "4:3",
2720
- value: CropType.R4_3
2690
+ value: "6"
2721
2691
  },
2722
2692
  {
2723
2693
  label: "3:4",
2724
- value: CropType.R3_4
2694
+ value: "7"
2725
2695
  },
2726
2696
  {
2727
2697
  label: "3:2",
2728
- value: CropType.R3_2
2698
+ value: "8"
2729
2699
  },
2730
2700
  {
2731
2701
  label: "2:3",
2732
- value: CropType.R2_3
2702
+ value: "9"
2733
2703
  }
2734
2704
  ];
2735
2705
  useEffect(() => {