microboard-temp 0.14.3 → 0.14.5

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.js CHANGED
@@ -58044,13 +58044,19 @@ var init_findOrthogonalPath = __esm(() => {
58044
58044
  });
58045
58045
 
58046
58046
  // src/Items/Connector/getLine/getOrthogonalLine.ts
58047
+ function getItemWorldMbr(item) {
58048
+ if (item instanceof BaseItem && item.parent !== "Board") {
58049
+ return item.getWorldMbr();
58050
+ }
58051
+ return item.getMbr();
58052
+ }
58047
58053
  function getOrthogonalLine(start, end, middle, skipObstacles = false) {
58048
58054
  const obstacles = [];
58049
58055
  if (start.pointType !== "Board" && !skipObstacles) {
58050
- obstacles.push(start.item.getMbr());
58056
+ obstacles.push(getItemWorldMbr(start.item));
58051
58057
  }
58052
58058
  if (end.pointType !== "Board" && !skipObstacles) {
58053
- obstacles.push(end.item.getMbr());
58059
+ obstacles.push(getItemWorldMbr(end.item));
58054
58060
  }
58055
58061
  const { lines, newStart, newEnd } = findOrthogonalPath(start, end, obstacles, middle ? [middle] : undefined);
58056
58062
  if (lines.length === 0) {
@@ -58064,6 +58070,7 @@ function getOrthogonalLine(start, end, middle, skipObstacles = false) {
58064
58070
  var init_getOrthogonalLine = __esm(() => {
58065
58071
  init_Items();
58066
58072
  init_findOrthogonalPath();
58073
+ init_BaseItem();
58067
58074
  });
58068
58075
 
58069
58076
  // src/Items/Connector/getLine/getStraightLine.ts
@@ -58098,6 +58105,175 @@ var init_getLine = __esm(() => {
58098
58105
  init_getStraightLine();
58099
58106
  });
58100
58107
 
58108
+ // src/Items/Group/Group.ts
58109
+ var Group;
58110
+ var init_Group = __esm(() => {
58111
+ init_Mbr();
58112
+ init_Point();
58113
+ init_BaseItem();
58114
+ Group = class Group extends BaseItem {
58115
+ events;
58116
+ itemType = "Group";
58117
+ parent = "Board";
58118
+ subject = new Subject;
58119
+ transformationRenderBlock = undefined;
58120
+ isLockedGroup = false;
58121
+ static movingGroupId = null;
58122
+ constructor(board, events, childIds = [], id = "") {
58123
+ super(board, id, undefined, true);
58124
+ this.events = events;
58125
+ this.canBeNested = true;
58126
+ if (childIds.length > 0) {
58127
+ this.applyAddChildren(childIds);
58128
+ }
58129
+ }
58130
+ isClosed() {
58131
+ return false;
58132
+ }
58133
+ getRichText() {
58134
+ return null;
58135
+ }
58136
+ apply(op) {
58137
+ switch (op.class) {
58138
+ case "Transformation":
58139
+ super.apply(op);
58140
+ this.updateMbr();
58141
+ Group.movingGroupId = this.id;
58142
+ for (const child of this.index.listAll()) {
58143
+ child.subject.publish(child);
58144
+ }
58145
+ Group.movingGroupId = null;
58146
+ break;
58147
+ case "Group":
58148
+ if (op.method === "addChild") {
58149
+ this.applyAddChildren([op.childId]);
58150
+ } else if (op.method === "removeChild") {
58151
+ this.applyRemoveChildren([op.childId]);
58152
+ } else {
58153
+ super.apply(op);
58154
+ }
58155
+ break;
58156
+ default:
58157
+ super.apply(op);
58158
+ return;
58159
+ }
58160
+ this.subject.publish(this);
58161
+ }
58162
+ emit(operation) {
58163
+ if (this.events) {
58164
+ const command = new GroupCommand([this], operation);
58165
+ command.apply();
58166
+ this.events.emit(operation, command);
58167
+ } else {
58168
+ this.apply(operation);
58169
+ }
58170
+ }
58171
+ setId(id) {
58172
+ this.id = id;
58173
+ this.transformation.setId(id);
58174
+ return this;
58175
+ }
58176
+ getMbr() {
58177
+ const children = this.index.listAll();
58178
+ if (children.length === 0) {
58179
+ return new Mbr(this.left, this.top, this.right, this.bottom);
58180
+ }
58181
+ const groupWorldMatrix = this.getWorldMatrix();
58182
+ let left = Number.MAX_SAFE_INTEGER;
58183
+ let top = Number.MAX_SAFE_INTEGER;
58184
+ let right = Number.MIN_SAFE_INTEGER;
58185
+ let bottom = Number.MIN_SAFE_INTEGER;
58186
+ for (const child of children) {
58187
+ const childLocalMbr = child.getMbr();
58188
+ const corners = [
58189
+ new Point(childLocalMbr.left, childLocalMbr.top),
58190
+ new Point(childLocalMbr.right, childLocalMbr.top),
58191
+ new Point(childLocalMbr.right, childLocalMbr.bottom),
58192
+ new Point(childLocalMbr.left, childLocalMbr.bottom)
58193
+ ];
58194
+ for (const corner of corners) {
58195
+ groupWorldMatrix.apply(corner);
58196
+ if (corner.x < left)
58197
+ left = corner.x;
58198
+ if (corner.y < top)
58199
+ top = corner.y;
58200
+ if (corner.x > right)
58201
+ right = corner.x;
58202
+ if (corner.y > bottom)
58203
+ bottom = corner.y;
58204
+ }
58205
+ }
58206
+ const mbr = new Mbr(left, top, right, bottom);
58207
+ this.left = left;
58208
+ this.top = top;
58209
+ this.right = right;
58210
+ this.bottom = bottom;
58211
+ return mbr;
58212
+ }
58213
+ updateMbr() {
58214
+ this.getMbr();
58215
+ }
58216
+ getChildrenIds() {
58217
+ return this.index.listAll().map((item) => item.getId());
58218
+ }
58219
+ getChildren() {
58220
+ return this.index.listAll();
58221
+ }
58222
+ getLinkTo() {
58223
+ return this.linkTo.link;
58224
+ }
58225
+ serialize() {
58226
+ return {
58227
+ id: this.id,
58228
+ itemType: "Group",
58229
+ childIds: this.getChildrenIds(),
58230
+ transformation: this.transformation.serialize(),
58231
+ isLockedGroup: this.isLockedGroup
58232
+ };
58233
+ }
58234
+ deserialize(data) {
58235
+ if (data.transformation) {
58236
+ this.transformation.deserialize(data.transformation);
58237
+ }
58238
+ if (data.childIds && data.childIds.length > 0) {
58239
+ this.applyAddChildren(data.childIds);
58240
+ }
58241
+ if (data.isLockedGroup !== undefined) {
58242
+ this.isLockedGroup = data.isLockedGroup;
58243
+ }
58244
+ this.updateMbr();
58245
+ this.subject.publish(this);
58246
+ return this;
58247
+ }
58248
+ getId() {
58249
+ return this.id;
58250
+ }
58251
+ getIntersectionPoints(segment) {
58252
+ const lines = this.getMbr().getLines();
58253
+ const initPoints = [];
58254
+ return lines.reduce((acc, line) => {
58255
+ const intersections = line.getIntersectionPoints(segment);
58256
+ if (intersections.length > 0) {
58257
+ acc.push(...intersections);
58258
+ }
58259
+ return acc;
58260
+ }, initPoints);
58261
+ }
58262
+ render(context) {
58263
+ if (this.transformationRenderBlock) {
58264
+ return;
58265
+ }
58266
+ const ctx = context.ctx;
58267
+ ctx.save();
58268
+ this.transformation.applyToContext(ctx);
58269
+ for (const child of this.index.listAll()) {
58270
+ child.render(context);
58271
+ }
58272
+ ctx.restore();
58273
+ }
58274
+ };
58275
+ });
58276
+
58101
58277
  // src/Items/Connector/ConnectorTypes.ts
58102
58278
  var ConnectionLineWidths, CONNECTOR_COLOR = "rgb(20, 21, 26)", CONNECTOR_LINE_WIDTH = 1, CONNECTOR_BORDER_STYLE = "solid", DEFAULT_END_POINTER = "TriangleFilled", CONNECTOR_POINTER_TYPES;
58103
58279
  var init_ConnectorTypes = __esm(() => {
@@ -58206,6 +58382,7 @@ var init_Connector = __esm(() => {
58206
58382
  init_Settings();
58207
58383
  init_transformOps();
58208
58384
  init_BaseItem();
58385
+ init_Group();
58209
58386
  init_Color();
58210
58387
  init_ConnectorTypes();
58211
58388
  init_connectorOps();
@@ -58295,8 +58472,9 @@ var init_Connector = __esm(() => {
58295
58472
  const point5 = this.startPoint;
58296
58473
  if (point5.pointType !== "Board") {
58297
58474
  point5.recalculatePoint();
58298
- const j1 = this.smartJumpStartEdge();
58299
- const j2 = this.smartJumpEndEdge();
58475
+ const isGroupMoving = Group.movingGroupId !== null;
58476
+ const j1 = isGroupMoving ? false : this.smartJumpStartEdge();
58477
+ const j2 = isGroupMoving ? false : this.smartJumpEndEdge();
58300
58478
  if (!j1 && !j2) {
58301
58479
  this.updatePaths();
58302
58480
  this.subject.publish(this);
@@ -58307,8 +58485,9 @@ var init_Connector = __esm(() => {
58307
58485
  const point5 = this.endPoint;
58308
58486
  if (point5.pointType !== "Board") {
58309
58487
  point5.recalculatePoint();
58310
- const j1 = this.smartJumpEndEdge();
58311
- const j2 = this.smartJumpStartEdge();
58488
+ const isGroupMoving = Group.movingGroupId !== null;
58489
+ const j1 = isGroupMoving ? false : this.smartJumpEndEdge();
58490
+ const j2 = isGroupMoving ? false : this.smartJumpStartEdge();
58312
58491
  if (!j1 && !j2) {
58313
58492
  this.updatePaths();
58314
58493
  this.subject.publish(this);
@@ -63621,172 +63800,6 @@ var init_Placeholder2 = __esm(() => {
63621
63800
  init_Placeholder();
63622
63801
  });
63623
63802
 
63624
- // src/Items/Group/Group.ts
63625
- var Group;
63626
- var init_Group = __esm(() => {
63627
- init_Mbr();
63628
- init_Point();
63629
- init_BaseItem();
63630
- Group = class Group extends BaseItem {
63631
- events;
63632
- itemType = "Group";
63633
- parent = "Board";
63634
- subject = new Subject;
63635
- transformationRenderBlock = undefined;
63636
- isLockedGroup = false;
63637
- constructor(board, events, childIds = [], id = "") {
63638
- super(board, id, undefined, true);
63639
- this.events = events;
63640
- this.canBeNested = true;
63641
- if (childIds.length > 0) {
63642
- this.applyAddChildren(childIds);
63643
- }
63644
- }
63645
- isClosed() {
63646
- return false;
63647
- }
63648
- getRichText() {
63649
- return null;
63650
- }
63651
- apply(op) {
63652
- switch (op.class) {
63653
- case "Transformation":
63654
- super.apply(op);
63655
- this.updateMbr();
63656
- for (const child of this.index.listAll()) {
63657
- child.subject.publish(child);
63658
- }
63659
- break;
63660
- case "Group":
63661
- if (op.method === "addChild") {
63662
- this.applyAddChildren([op.childId]);
63663
- } else if (op.method === "removeChild") {
63664
- this.applyRemoveChildren([op.childId]);
63665
- } else {
63666
- super.apply(op);
63667
- }
63668
- break;
63669
- default:
63670
- super.apply(op);
63671
- return;
63672
- }
63673
- this.subject.publish(this);
63674
- }
63675
- emit(operation) {
63676
- if (this.events) {
63677
- const command = new GroupCommand([this], operation);
63678
- command.apply();
63679
- this.events.emit(operation, command);
63680
- } else {
63681
- this.apply(operation);
63682
- }
63683
- }
63684
- setId(id) {
63685
- this.id = id;
63686
- this.transformation.setId(id);
63687
- return this;
63688
- }
63689
- getMbr() {
63690
- const children = this.index.listAll();
63691
- if (children.length === 0) {
63692
- return new Mbr(this.left, this.top, this.right, this.bottom);
63693
- }
63694
- const groupWorldMatrix = this.getWorldMatrix();
63695
- let left = Number.MAX_SAFE_INTEGER;
63696
- let top = Number.MAX_SAFE_INTEGER;
63697
- let right = Number.MIN_SAFE_INTEGER;
63698
- let bottom = Number.MIN_SAFE_INTEGER;
63699
- for (const child of children) {
63700
- const childLocalMbr = child.getMbr();
63701
- const corners = [
63702
- new Point(childLocalMbr.left, childLocalMbr.top),
63703
- new Point(childLocalMbr.right, childLocalMbr.top),
63704
- new Point(childLocalMbr.right, childLocalMbr.bottom),
63705
- new Point(childLocalMbr.left, childLocalMbr.bottom)
63706
- ];
63707
- for (const corner of corners) {
63708
- groupWorldMatrix.apply(corner);
63709
- if (corner.x < left)
63710
- left = corner.x;
63711
- if (corner.y < top)
63712
- top = corner.y;
63713
- if (corner.x > right)
63714
- right = corner.x;
63715
- if (corner.y > bottom)
63716
- bottom = corner.y;
63717
- }
63718
- }
63719
- const mbr = new Mbr(left, top, right, bottom);
63720
- this.left = left;
63721
- this.top = top;
63722
- this.right = right;
63723
- this.bottom = bottom;
63724
- return mbr;
63725
- }
63726
- updateMbr() {
63727
- this.getMbr();
63728
- }
63729
- getChildrenIds() {
63730
- return this.index.listAll().map((item) => item.getId());
63731
- }
63732
- getChildren() {
63733
- return this.index.listAll();
63734
- }
63735
- getLinkTo() {
63736
- return this.linkTo.link;
63737
- }
63738
- serialize() {
63739
- return {
63740
- id: this.id,
63741
- itemType: "Group",
63742
- childIds: this.getChildrenIds(),
63743
- transformation: this.transformation.serialize(),
63744
- isLockedGroup: this.isLockedGroup
63745
- };
63746
- }
63747
- deserialize(data) {
63748
- if (data.transformation) {
63749
- this.transformation.deserialize(data.transformation);
63750
- }
63751
- if (data.childIds && data.childIds.length > 0) {
63752
- this.applyAddChildren(data.childIds);
63753
- }
63754
- if (data.isLockedGroup !== undefined) {
63755
- this.isLockedGroup = data.isLockedGroup;
63756
- }
63757
- this.updateMbr();
63758
- this.subject.publish(this);
63759
- return this;
63760
- }
63761
- getId() {
63762
- return this.id;
63763
- }
63764
- getIntersectionPoints(segment) {
63765
- const lines = this.getMbr().getLines();
63766
- const initPoints = [];
63767
- return lines.reduce((acc, line) => {
63768
- const intersections = line.getIntersectionPoints(segment);
63769
- if (intersections.length > 0) {
63770
- acc.push(...intersections);
63771
- }
63772
- return acc;
63773
- }, initPoints);
63774
- }
63775
- render(context) {
63776
- if (this.transformationRenderBlock) {
63777
- return;
63778
- }
63779
- const ctx = context.ctx;
63780
- ctx.save();
63781
- this.transformation.applyToContext(ctx);
63782
- for (const child of this.index.listAll()) {
63783
- child.render(context);
63784
- }
63785
- ctx.restore();
63786
- }
63787
- };
63788
- });
63789
-
63790
63803
  // src/Items/Group/index.ts
63791
63804
  var init_Group2 = __esm(() => {
63792
63805
  init_Group();
@@ -64236,26 +64249,18 @@ class ConnectorSnap {
64236
64249
  } else if (anchor) {
64237
64250
  this.controlPoint = getFixedPoint(item, anchor.getCenter());
64238
64251
  } else if (point5) {
64239
- this.controlPoint = getFixedPoint(item, point5.getCenter());
64252
+ const nearest2 = item.getNearestEdgePointTo(pointer);
64253
+ this.controlPoint = getFixedPoint(item, nearest2);
64240
64254
  } else {
64241
- this.controlPoint = getFixedPoint(item, pointer);
64255
+ if (this.hover.isTimeoutElapsed) {
64256
+ this.controlPoint = getFixedPoint(item, pointer);
64257
+ } else {
64258
+ this.controlPoint = getFixedPoint(item, pointer);
64259
+ }
64242
64260
  }
64243
64261
  }
64244
64262
  setHover() {
64245
- let hover = this.board.items.getUnderPointer(0)[0];
64246
- if (hover instanceof BaseItem && hover.index) {
64247
- const group = hover;
64248
- const inverse = group.getWorldMatrix().getInverse();
64249
- const pointer = this.board.pointer.point;
64250
- const localPointer = pointer.copy();
64251
- localPointer.transform(inverse);
64252
- for (const child of group.index.listAll()) {
64253
- if (child.getMbr().isUnderPoint(localPointer)) {
64254
- hover = child;
64255
- break;
64256
- }
64257
- }
64258
- }
64263
+ const hover = this.board.items.getUnderPointer(0)[0];
64259
64264
  if (hover) {
64260
64265
  if (hover !== this.hover.item) {
64261
64266
  this.hover = {
@@ -64312,18 +64317,8 @@ class ConnectorSnap {
64312
64317
  return nearest;
64313
64318
  }
64314
64319
  getClosestPointOnItem(item, position4) {
64315
- let worldEdgePoint;
64316
- if (item instanceof BaseItem && item.parent !== "Board") {
64317
- const parentMatrix = item.getParentWorldMatrix();
64318
- const localPos = position4.copy();
64319
- localPos.transform(parentMatrix.getInverse());
64320
- const localEdge = item.getNearestEdgePointTo(localPos);
64321
- worldEdgePoint = localEdge.copy();
64322
- parentMatrix.apply(worldEdgePoint);
64323
- } else {
64324
- worldEdgePoint = item.getNearestEdgePointTo(position4);
64325
- }
64326
- return getFixedPoint(item, worldEdgePoint);
64320
+ const nearestEdgePoint = item.getNearestEdgePointTo(position4);
64321
+ return getFixedPoint(item, nearestEdgePoint);
64327
64322
  }
64328
64323
  isNearBorder(item) {
64329
64324
  if (!item) {
@@ -64352,15 +64347,10 @@ class ConnectorSnap {
64352
64347
  }
64353
64348
  }
64354
64349
  setAnchors(item) {
64355
- const localPoints = item.getSnapAnchorPoints();
64356
- if (!localPoints) {
64350
+ const points = item.getSnapAnchorPoints();
64351
+ if (!points) {
64357
64352
  return;
64358
64353
  }
64359
- const points = item instanceof BaseItem && item.parent !== "Board" ? localPoints.map((p3) => {
64360
- const wp = p3.copy();
64361
- item.getParentWorldMatrix().apply(wp);
64362
- return wp;
64363
- }) : localPoints;
64364
64354
  const anchors = [];
64365
64355
  for (const { x, y } of points) {
64366
64356
  anchors.push(new Anchor(x, y, 5, this.color.anchorBorder, this.color.anchorBackground, 1));
@@ -64394,19 +64384,9 @@ class ConnectorSnap {
64394
64384
  const { item, anchor } = this.snap;
64395
64385
  if (item) {
64396
64386
  if (!anchor) {
64397
- let edgePoint;
64398
- if (item instanceof BaseItem && item.parent !== "Board") {
64399
- const parentMatrix = item.getParentWorldMatrix();
64400
- const localPointer = pointer.copy();
64401
- localPointer.transform(parentMatrix.getInverse());
64402
- const localEdge = item.getNearestEdgePointTo(localPointer);
64403
- edgePoint = localEdge.copy();
64404
- parentMatrix.apply(edgePoint);
64405
- } else {
64406
- edgePoint = item.getNearestEdgePointTo(pointer);
64407
- }
64408
- if (edgePoint.getDistance(pointer) < this.distance.border || !this.hover.isTimeoutElapsed) {
64409
- this.snap.point = new Anchor(edgePoint.x, edgePoint.y, 5, this.color.pointBorder, this.color.pointBackground, 1);
64387
+ const point5 = item.getNearestEdgePointTo(pointer);
64388
+ if (point5.getDistance(pointer) < this.distance.border || !this.hover.isTimeoutElapsed) {
64389
+ this.snap.point = new Anchor(point5.x, point5.y, 5, this.color.pointBorder, this.color.pointBackground, 1);
64410
64390
  } else {
64411
64391
  this.snap.point = null;
64412
64392
  }
@@ -64435,7 +64415,6 @@ class ConnectorSnap {
64435
64415
  }
64436
64416
  var init_ConnectorSnap = __esm(() => {
64437
64417
  init_ControlPoint();
64438
- init_BaseItem2();
64439
64418
  init_Anchor2();
64440
64419
  init_Connector();
64441
64420
  });