@idraw/core 0.4.0-beta.13 → 0.4.0-beta.15

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.
@@ -378,12 +378,16 @@ var __privateMethod = (obj, member, method) => {
378
378
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
379
379
  };
380
380
  var _Context2D_ctx, _Context2D_opts;
381
+ const defaultFontSize = 12;
382
+ const defaultFontWeight = "400";
383
+ const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'`;
381
384
  class Context2D {
382
385
  constructor(ctx, opts) {
383
386
  _Context2D_ctx.set(this, void 0);
384
387
  _Context2D_opts.set(this, void 0);
385
388
  __classPrivateFieldSet$9(this, _Context2D_ctx, ctx, "f");
386
389
  __classPrivateFieldSet$9(this, _Context2D_opts, Object.assign({ devicePixelRatio: 1, offscreenCanvas: null }, opts), "f");
390
+ this.$resetFont();
387
391
  }
388
392
  $undoPixelRatio(num) {
389
393
  return num / __classPrivateFieldGet$9(this, _Context2D_opts, "f").devicePixelRatio;
@@ -406,6 +410,13 @@ var __privateMethod = (obj, member, method) => {
406
410
  strList.push(`${opts.fontFamily || "sans-serif"}`);
407
411
  __classPrivateFieldGet$9(this, _Context2D_ctx, "f").font = `${strList.join(" ")}`;
408
412
  }
413
+ $resetFont() {
414
+ this.$setFont({
415
+ fontSize: defaultFontSize,
416
+ fontFamily: defaultFontFamily,
417
+ fontWeight: defaultFontWeight
418
+ });
419
+ }
409
420
  $getOffscreenCanvas() {
410
421
  return __classPrivateFieldGet$9(this, _Context2D_opts, "f").offscreenCanvas;
411
422
  }
@@ -1215,6 +1226,32 @@ var __privateMethod = (obj, member, method) => {
1215
1226
  }
1216
1227
  return result;
1217
1228
  }
1229
+ function getElementPositionFromList(uuid, elements) {
1230
+ const result = [];
1231
+ let over = false;
1232
+ const _loop = (list) => {
1233
+ var _a;
1234
+ for (let i = 0; i < list.length; i++) {
1235
+ if (over === true) {
1236
+ break;
1237
+ }
1238
+ result.push(i);
1239
+ const elem = list[i];
1240
+ if (elem.uuid === uuid) {
1241
+ over = true;
1242
+ break;
1243
+ } else if (elem.type === "group") {
1244
+ _loop(((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.children) || []);
1245
+ }
1246
+ if (over) {
1247
+ break;
1248
+ }
1249
+ result.pop();
1250
+ }
1251
+ };
1252
+ _loop(elements);
1253
+ return result;
1254
+ }
1218
1255
  function checkRectIntersect(rect1, rect2) {
1219
1256
  const react1MinX = rect1.x;
1220
1257
  const react1MinY = rect1.y;
@@ -2107,11 +2144,18 @@ var __privateMethod = (obj, member, method) => {
2107
2144
  renderContent();
2108
2145
  ctx.restore();
2109
2146
  } else {
2147
+ ctx.save();
2148
+ ctx.shadowColor = "transparent";
2149
+ ctx.shadowOffsetX = 0;
2150
+ ctx.shadowOffsetY = 0;
2151
+ ctx.shadowBlur = 0;
2110
2152
  renderContent();
2153
+ ctx.restore();
2111
2154
  }
2112
2155
  }
2113
2156
  function drawCircle(ctx, elem, opts) {
2114
2157
  const { detail, angle: angle2 } = elem;
2158
+ const { calculator, viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2115
2159
  const { background: background2 = "#000000", borderColor: borderColor2 = "#000000", boxSizing, borderWidth: borderWidth2 = 0 } = detail;
2116
2160
  let bw = 0;
2117
2161
  if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
@@ -2119,7 +2163,7 @@ var __privateMethod = (obj, member, method) => {
2119
2163
  } else if (Array.isArray(borderWidth2) && typeof borderWidth2[0] === "number" && borderWidth2[0] > 0) {
2120
2164
  bw = borderWidth2[0];
2121
2165
  }
2122
- const { calculator, viewScaleInfo, viewSizeInfo, parentOpacity } = opts;
2166
+ bw = bw * viewScaleInfo.scale;
2123
2167
  const { x: x2, y: y2, w: w2, h: h2 } = (calculator === null || calculator === void 0 ? void 0 : calculator.elementSize({ x: elem.x, y: elem.y, w: elem.w, h: elem.h }, viewScaleInfo, viewSizeInfo)) || elem;
2124
2168
  const viewElem = Object.assign(Object.assign({}, elem), { x: x2, y: y2, w: w2, h: h2, angle: angle2 });
2125
2169
  rotateElement$1(ctx, { x: x2, y: y2, w: w2, h: h2, angle: angle2 }, () => {
@@ -2146,12 +2190,12 @@ var __privateMethod = (obj, member, method) => {
2146
2190
  if (a >= 0 && b >= 0) {
2147
2191
  const opacity = getOpacity(viewElem) * parentOpacity;
2148
2192
  ctx.globalAlpha = opacity;
2149
- if (typeof borderWidth2 === "number" && borderWidth2 > 0) {
2150
- const ba = borderWidth2 / 2 + a;
2151
- const bb = borderWidth2 / 2 + b;
2193
+ if (typeof bw === "number" && bw > 0) {
2194
+ const ba = bw / 2 + a;
2195
+ const bb = bw / 2 + b;
2152
2196
  ctx.beginPath();
2153
2197
  ctx.strokeStyle = borderColor2;
2154
- ctx.lineWidth = borderWidth2;
2198
+ ctx.lineWidth = bw;
2155
2199
  ctx.circle(centerX, centerY, ba, bb, 0, 0, 2 * Math.PI);
2156
2200
  ctx.closePath();
2157
2201
  ctx.stroke();
@@ -2786,6 +2830,9 @@ var __privateMethod = (obj, member, method) => {
2786
2830
  }, _Loader_loadResource = function _Loader_loadResource2(element, assets) {
2787
2831
  const item = __classPrivateFieldGet$6(this, _Loader_instances, "m", _Loader_createLoadItem).call(this, element);
2788
2832
  const assetId = getAssetIdFromElement(element);
2833
+ if (__classPrivateFieldGet$6(this, _Loader_currentLoadItemMap, "f")[assetId]) {
2834
+ return;
2835
+ }
2789
2836
  __classPrivateFieldGet$6(this, _Loader_currentLoadItemMap, "f")[assetId] = item;
2790
2837
  const loadFunc = __classPrivateFieldGet$6(this, _Loader_loadFuncMap, "f")[element.type];
2791
2838
  if (typeof loadFunc === "function" && !__classPrivateFieldGet$6(this, _Loader_hasDestroyed, "f")) {
@@ -2921,7 +2968,8 @@ var __privateMethod = (obj, member, method) => {
2921
2968
  loader.on("load", (e) => {
2922
2969
  this.trigger("load", e);
2923
2970
  });
2924
- loader.on("error", () => {
2971
+ loader.on("error", (e) => {
2972
+ console.error(e);
2925
2973
  });
2926
2974
  };
2927
2975
  var __classPrivateFieldSet$4 = function(receiver, state, value, kind, f) {
@@ -3598,6 +3646,9 @@ var __privateMethod = (obj, member, method) => {
3598
3646
  __classPrivateFieldGet(this, _Board_watcher, "f").on("scrollY", __classPrivateFieldGet(this, _Board_instances, "m", _Board_handleScrollY).bind(this));
3599
3647
  __classPrivateFieldGet(this, _Board_watcher, "f").on("resize", __classPrivateFieldGet(this, _Board_instances, "m", _Board_handleResize).bind(this));
3600
3648
  __classPrivateFieldGet(this, _Board_watcher, "f").on("doubleClick", __classPrivateFieldGet(this, _Board_instances, "m", _Board_handleDoubleClick).bind(this));
3649
+ __classPrivateFieldGet(this, _Board_renderer, "f").on("load", () => {
3650
+ __classPrivateFieldGet(this, _Board_eventHub, "f").trigger("loadResource");
3651
+ });
3601
3652
  }, _Board_handlePointStart = function _Board_handlePointStart2(e) {
3602
3653
  var _a;
3603
3654
  for (let i = 0; i < __classPrivateFieldGet(this, _Board_activeMiddlewareObjs, "f").length; i++) {
@@ -3884,6 +3935,7 @@ var __privateMethod = (obj, member, method) => {
3884
3935
  const keySelectedElementController = Symbol(`${key$2}_selectedElementController`);
3885
3936
  const keyGroupQueue = Symbol(`${key$2}_groupQueue`);
3886
3937
  const keyGroupQueueVertexesList = Symbol(`${key$2}_groupQueueVertexesList`);
3938
+ const keyIsMoving = Symbol(`${key$2}_isMoving`);
3887
3939
  const selectWrapperBorderWidth = 2;
3888
3940
  const resizeControllerBorderWidth = 4;
3889
3941
  const areaBorderWidth = 1;
@@ -3943,13 +3995,6 @@ var __privateMethod = (obj, member, method) => {
3943
3995
  ctx.fill();
3944
3996
  }
3945
3997
  }
3946
- function drawHoverVertexesWrapper(ctx, vertexes, opts) {
3947
- if (!vertexes) {
3948
- return;
3949
- }
3950
- const wrapperOpts = { borderColor: wrapperColor, borderWidth: 1, background: "transparent", lineDash: [] };
3951
- drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
3952
- }
3953
3998
  function drawCrossVertexes(ctx, vertexes, opts) {
3954
3999
  const { borderColor: borderColor2, borderWidth: borderWidth2, background: background2, lineDash } = opts;
3955
4000
  ctx.setLineDash([]);
@@ -3968,6 +4013,13 @@ var __privateMethod = (obj, member, method) => {
3968
4013
  ctx.closePath();
3969
4014
  ctx.stroke();
3970
4015
  }
4016
+ function drawHoverVertexesWrapper(ctx, vertexes, opts) {
4017
+ if (!vertexes) {
4018
+ return;
4019
+ }
4020
+ const wrapperOpts = { borderColor: wrapperColor, borderWidth: 1, background: "transparent", lineDash: [] };
4021
+ drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
4022
+ }
3971
4023
  function drawLockVertexesWrapper(ctx, vertexes, opts) {
3972
4024
  if (!vertexes) {
3973
4025
  return;
@@ -3992,16 +4044,19 @@ var __privateMethod = (obj, member, method) => {
3992
4044
  if (!controller) {
3993
4045
  return;
3994
4046
  }
4047
+ const { hideControllers } = opts;
3995
4048
  const { elementWrapper, topLeft, topRight, bottomLeft, bottomRight, top, rotate } = controller;
3996
4049
  const wrapperOpts = { borderColor: wrapperColor, borderWidth: selectWrapperBorderWidth, background: "transparent", lineDash: [] };
3997
4050
  const ctrlOpts = { ...wrapperOpts, borderWidth: resizeControllerBorderWidth, background: "#FFFFFF" };
3998
- drawLine(ctx, calcViewPointSize(top.center, opts), calcViewPointSize(rotate.center, opts), { ...ctrlOpts, borderWidth: 2 });
3999
4051
  drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
4000
- drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
4001
- drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
4002
- drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
4003
- drawVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
4004
- drawCircleController(ctx, calcViewPointSize(rotate.center, opts), { ...ctrlOpts, size: controllerSize, borderWidth: 2 });
4052
+ if (!hideControllers) {
4053
+ drawLine(ctx, calcViewPointSize(top.center, opts), calcViewPointSize(rotate.center, opts), { ...ctrlOpts, borderWidth: 2 });
4054
+ drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
4055
+ drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
4056
+ drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
4057
+ drawVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
4058
+ drawCircleController(ctx, calcViewPointSize(rotate.center, opts), { ...ctrlOpts, size: controllerSize, borderWidth: 2 });
4059
+ }
4005
4060
  }
4006
4061
  function drawArea(ctx, opts) {
4007
4062
  const { start, end } = opts;
@@ -4811,15 +4866,18 @@ var __privateMethod = (obj, member, method) => {
4811
4866
  };
4812
4867
  }
4813
4868
  const middlewareEventTextEdit = "@middleware/text-edit";
4869
+ const middlewareEventTextChange = "@middleware/text-change";
4814
4870
  const defaultElementDetail = getDefaultElementDetailConfig();
4815
4871
  const MiddlewareTextEditor = (opts) => {
4816
4872
  const { eventHub, boardContent, viewer } = opts;
4817
4873
  const canvas = boardContent.boardContext.canvas;
4818
- const textarea = document.createElement("textarea");
4874
+ const textarea = document.createElement("div");
4875
+ textarea.setAttribute("contenteditable", "true");
4819
4876
  const canvasWrapper = document.createElement("div");
4820
4877
  const container = opts.container || document.body;
4821
4878
  const mask = document.createElement("div");
4822
4879
  let activeElem = null;
4880
+ let activePosition = [];
4823
4881
  canvasWrapper.appendChild(textarea);
4824
4882
  canvasWrapper.style.position = "absolute";
4825
4883
  mask.appendChild(canvasWrapper);
@@ -4838,6 +4896,7 @@ var __privateMethod = (obj, member, method) => {
4838
4896
  const hideTextArea = () => {
4839
4897
  mask.style.display = "none";
4840
4898
  activeElem = null;
4899
+ activePosition = [];
4841
4900
  };
4842
4901
  const getCanvasRect = () => {
4843
4902
  const clientRect = canvas.getBoundingClientRect();
@@ -4898,6 +4957,21 @@ var __privateMethod = (obj, member, method) => {
4898
4957
  elemW = element.w * scale;
4899
4958
  elemH = element.h * scale;
4900
4959
  }
4960
+ let justifyContent = "center";
4961
+ let alignItems = "center";
4962
+ if (detail.textAlign === "left") {
4963
+ justifyContent = "start";
4964
+ } else if (detail.textAlign === "right") {
4965
+ justifyContent = "end";
4966
+ }
4967
+ if (detail.verticalAlign === "top") {
4968
+ alignItems = "start";
4969
+ } else if (detail.verticalAlign === "bottom") {
4970
+ alignItems = "end";
4971
+ }
4972
+ textarea.style.display = "inline-flex";
4973
+ textarea.style.justifyContent = justifyContent;
4974
+ textarea.style.alignItems = alignItems;
4901
4975
  textarea.style.position = "absolute";
4902
4976
  textarea.style.left = `${elemX - 1}px`;
4903
4977
  textarea.style.top = `${elemY - 1}px`;
@@ -4918,7 +4992,7 @@ var __privateMethod = (obj, member, method) => {
4918
4992
  textarea.style.padding = "0";
4919
4993
  textarea.style.margin = "0";
4920
4994
  textarea.style.outline = "none";
4921
- textarea.value = detail.text || "";
4995
+ textarea.innerText = detail.text || "";
4922
4996
  parent.appendChild(textarea);
4923
4997
  };
4924
4998
  const resetCanvasWrapper = () => {
@@ -4936,19 +5010,40 @@ var __privateMethod = (obj, member, method) => {
4936
5010
  textarea.addEventListener("click", (e) => {
4937
5011
  e.stopPropagation();
4938
5012
  });
4939
- textarea.addEventListener("input", (e) => {
4940
- if (activeElem) {
4941
- activeElem.detail.text = e.target.value || "";
5013
+ textarea.addEventListener("input", () => {
5014
+ if (activeElem && activePosition) {
5015
+ activeElem.detail.text = textarea.innerText || "";
5016
+ eventHub.trigger(middlewareEventTextChange, {
5017
+ element: {
5018
+ uuid: activeElem.uuid,
5019
+ detail: {
5020
+ text: activeElem.detail.text
5021
+ }
5022
+ },
5023
+ position: [...activePosition || []]
5024
+ });
4942
5025
  viewer.drawFrame();
4943
5026
  }
4944
5027
  });
4945
5028
  textarea.addEventListener("blur", () => {
5029
+ if (activeElem && activePosition) {
5030
+ eventHub.trigger(middlewareEventTextChange, {
5031
+ element: {
5032
+ uuid: activeElem.uuid,
5033
+ detail: {
5034
+ text: activeElem.detail.text
5035
+ }
5036
+ },
5037
+ position: [...activePosition]
5038
+ });
5039
+ }
4946
5040
  hideTextArea();
4947
5041
  });
4948
5042
  const textEditCallback = (e) => {
4949
5043
  var _a;
4950
- if ((e == null ? void 0 : e.element) && ((_a = e == null ? void 0 : e.element) == null ? void 0 : _a.type) === "text") {
5044
+ if ((e == null ? void 0 : e.position) && (e == null ? void 0 : e.element) && ((_a = e == null ? void 0 : e.element) == null ? void 0 : _a.type) === "text") {
4951
5045
  activeElem = e.element;
5046
+ activePosition = e.position;
4952
5047
  }
4953
5048
  showTextArea(e);
4954
5049
  };
@@ -5043,6 +5138,7 @@ var __privateMethod = (obj, member, method) => {
5043
5138
  sharer.setSharedStorage(keySelectedElementList, []);
5044
5139
  sharer.setSharedStorage(keySelectedElementListVertexes, null);
5045
5140
  sharer.setSharedStorage(keySelectedElementController, null);
5141
+ sharer.setSharedStorage(keyIsMoving, null);
5046
5142
  };
5047
5143
  clear();
5048
5144
  const selectCallback = ({ uuids, positions }) => {
@@ -5231,6 +5327,7 @@ var __privateMethod = (obj, member, method) => {
5231
5327
  },
5232
5328
  pointMove: (e) => {
5233
5329
  var _a, _b, _c;
5330
+ sharer.setSharedStorage(keyIsMoving, true);
5234
5331
  const data = sharer.getActiveStorage("data");
5235
5332
  const elems = getActiveElements();
5236
5333
  const scale = sharer.getActiveStorage("scale") || 1;
@@ -5330,6 +5427,7 @@ var __privateMethod = (obj, member, method) => {
5330
5427
  },
5331
5428
  pointEnd(e) {
5332
5429
  inBusyMode = null;
5430
+ sharer.setSharedStorage(keyIsMoving, false);
5333
5431
  const data = sharer.getActiveStorage("data");
5334
5432
  const resizeType = sharer.getSharedStorage(keyResizeType);
5335
5433
  const actionType = sharer.getSharedStorage(keyActionType);
@@ -5402,7 +5500,7 @@ var __privateMethod = (obj, member, method) => {
5402
5500
  viewer.drawFrame();
5403
5501
  },
5404
5502
  doubleClick(e) {
5405
- var _a, _b, _c, _d;
5503
+ var _a, _b, _c, _d, _e, _f;
5406
5504
  const target = getPointTarget(e.point, pointTargetBaseOptions());
5407
5505
  sharer.setSharedStorage(keySelectedElementController, null);
5408
5506
  sharer.setSharedStorage(keySelectedElementList, []);
@@ -5420,6 +5518,7 @@ var __privateMethod = (obj, member, method) => {
5420
5518
  eventHub.trigger(middlewareEventTextEdit, {
5421
5519
  element: target.elements[0],
5422
5520
  groupQueue: sharer.getSharedStorage(keyGroupQueue) || [],
5521
+ position: getElementPositionFromList((_e = target.elements[0]) == null ? void 0 : _e.uuid, ((_f = sharer.getActiveStorage("data")) == null ? void 0 : _f.elements) || []),
5423
5522
  viewScaleInfo: sharer.getActiveViewScaleInfo()
5424
5523
  });
5425
5524
  }
@@ -5441,6 +5540,7 @@ var __privateMethod = (obj, member, method) => {
5441
5540
  const areaEnd = sharedStore[keyAreaEnd];
5442
5541
  const groupQueue = sharedStore[keyGroupQueue];
5443
5542
  const groupQueueVertexesList = sharedStore[keyGroupQueueVertexesList];
5543
+ const isMoving = sharedStore[keyIsMoving];
5444
5544
  const drawBaseOpts = { calculator, viewScaleInfo, viewSizeInfo };
5445
5545
  const selectedElementController = elem ? calcElementSizeController(elem, {
5446
5546
  groupQueue,
@@ -5465,7 +5565,12 @@ var __privateMethod = (obj, member, method) => {
5465
5565
  }
5466
5566
  }
5467
5567
  if (!isLock && elem && ["select", "drag", "resize"].includes(actionType)) {
5468
- drawSelectedElementControllersVertexes(helperContext, selectedElementController, { ...drawBaseOpts });
5568
+ drawSelectedElementControllersVertexes(helperContext, selectedElementController, {
5569
+ ...drawBaseOpts,
5570
+ element: elem,
5571
+ groupQueue,
5572
+ hideControllers: !!isMoving && actionType === "drag"
5573
+ });
5469
5574
  }
5470
5575
  } else {
5471
5576
  if (hoverElement && actionType !== "drag") {
@@ -5483,7 +5588,12 @@ var __privateMethod = (obj, member, method) => {
5483
5588
  }
5484
5589
  }
5485
5590
  if (!isLock && elem && ["select", "drag", "resize"].includes(actionType)) {
5486
- drawSelectedElementControllersVertexes(helperContext, selectedElementController, { ...drawBaseOpts });
5591
+ drawSelectedElementControllersVertexes(helperContext, selectedElementController, {
5592
+ ...drawBaseOpts,
5593
+ element: elem,
5594
+ groupQueue,
5595
+ hideControllers: !!isMoving && actionType === "drag"
5596
+ });
5487
5597
  } else if (actionType === "area" && areaStart && areaEnd) {
5488
5598
  drawArea(helperContext, { start: areaStart, end: areaEnd });
5489
5599
  } else if (["drag-list", "drag-list-end"].includes(actionType)) {
@@ -6210,6 +6320,7 @@ var __privateMethod = (obj, member, method) => {
6210
6320
  exports.middlewareEventScale = middlewareEventScale;
6211
6321
  exports.middlewareEventSelect = middlewareEventSelect;
6212
6322
  exports.middlewareEventSelectClear = middlewareEventSelectClear;
6323
+ exports.middlewareEventTextChange = middlewareEventTextChange;
6213
6324
  exports.middlewareEventTextEdit = middlewareEventTextEdit;
6214
6325
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6215
6326
  return exports;