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/node.js CHANGED
@@ -60453,13 +60453,19 @@ var init_findOrthogonalPath = __esm(() => {
60453
60453
  });
60454
60454
 
60455
60455
  // src/Items/Connector/getLine/getOrthogonalLine.ts
60456
+ function getItemWorldMbr(item) {
60457
+ if (item instanceof BaseItem && item.parent !== "Board") {
60458
+ return item.getWorldMbr();
60459
+ }
60460
+ return item.getMbr();
60461
+ }
60456
60462
  function getOrthogonalLine(start, end, middle, skipObstacles = false) {
60457
60463
  const obstacles = [];
60458
60464
  if (start.pointType !== "Board" && !skipObstacles) {
60459
- obstacles.push(start.item.getMbr());
60465
+ obstacles.push(getItemWorldMbr(start.item));
60460
60466
  }
60461
60467
  if (end.pointType !== "Board" && !skipObstacles) {
60462
- obstacles.push(end.item.getMbr());
60468
+ obstacles.push(getItemWorldMbr(end.item));
60463
60469
  }
60464
60470
  const { lines, newStart, newEnd } = findOrthogonalPath(start, end, obstacles, middle ? [middle] : undefined);
60465
60471
  if (lines.length === 0) {
@@ -60473,6 +60479,7 @@ function getOrthogonalLine(start, end, middle, skipObstacles = false) {
60473
60479
  var init_getOrthogonalLine = __esm(() => {
60474
60480
  init_Items();
60475
60481
  init_findOrthogonalPath();
60482
+ init_BaseItem();
60476
60483
  });
60477
60484
 
60478
60485
  // src/Items/Connector/getLine/getStraightLine.ts
@@ -60507,6 +60514,175 @@ var init_getLine = __esm(() => {
60507
60514
  init_getStraightLine();
60508
60515
  });
60509
60516
 
60517
+ // src/Items/Group/Group.ts
60518
+ var Group;
60519
+ var init_Group = __esm(() => {
60520
+ init_Mbr();
60521
+ init_Point();
60522
+ init_BaseItem();
60523
+ Group = class Group extends BaseItem {
60524
+ events;
60525
+ itemType = "Group";
60526
+ parent = "Board";
60527
+ subject = new Subject;
60528
+ transformationRenderBlock = undefined;
60529
+ isLockedGroup = false;
60530
+ static movingGroupId = null;
60531
+ constructor(board, events, childIds = [], id = "") {
60532
+ super(board, id, undefined, true);
60533
+ this.events = events;
60534
+ this.canBeNested = true;
60535
+ if (childIds.length > 0) {
60536
+ this.applyAddChildren(childIds);
60537
+ }
60538
+ }
60539
+ isClosed() {
60540
+ return false;
60541
+ }
60542
+ getRichText() {
60543
+ return null;
60544
+ }
60545
+ apply(op) {
60546
+ switch (op.class) {
60547
+ case "Transformation":
60548
+ super.apply(op);
60549
+ this.updateMbr();
60550
+ Group.movingGroupId = this.id;
60551
+ for (const child of this.index.listAll()) {
60552
+ child.subject.publish(child);
60553
+ }
60554
+ Group.movingGroupId = null;
60555
+ break;
60556
+ case "Group":
60557
+ if (op.method === "addChild") {
60558
+ this.applyAddChildren([op.childId]);
60559
+ } else if (op.method === "removeChild") {
60560
+ this.applyRemoveChildren([op.childId]);
60561
+ } else {
60562
+ super.apply(op);
60563
+ }
60564
+ break;
60565
+ default:
60566
+ super.apply(op);
60567
+ return;
60568
+ }
60569
+ this.subject.publish(this);
60570
+ }
60571
+ emit(operation) {
60572
+ if (this.events) {
60573
+ const command = new GroupCommand([this], operation);
60574
+ command.apply();
60575
+ this.events.emit(operation, command);
60576
+ } else {
60577
+ this.apply(operation);
60578
+ }
60579
+ }
60580
+ setId(id) {
60581
+ this.id = id;
60582
+ this.transformation.setId(id);
60583
+ return this;
60584
+ }
60585
+ getMbr() {
60586
+ const children = this.index.listAll();
60587
+ if (children.length === 0) {
60588
+ return new Mbr(this.left, this.top, this.right, this.bottom);
60589
+ }
60590
+ const groupWorldMatrix = this.getWorldMatrix();
60591
+ let left = Number.MAX_SAFE_INTEGER;
60592
+ let top = Number.MAX_SAFE_INTEGER;
60593
+ let right = Number.MIN_SAFE_INTEGER;
60594
+ let bottom = Number.MIN_SAFE_INTEGER;
60595
+ for (const child of children) {
60596
+ const childLocalMbr = child.getMbr();
60597
+ const corners = [
60598
+ new Point(childLocalMbr.left, childLocalMbr.top),
60599
+ new Point(childLocalMbr.right, childLocalMbr.top),
60600
+ new Point(childLocalMbr.right, childLocalMbr.bottom),
60601
+ new Point(childLocalMbr.left, childLocalMbr.bottom)
60602
+ ];
60603
+ for (const corner of corners) {
60604
+ groupWorldMatrix.apply(corner);
60605
+ if (corner.x < left)
60606
+ left = corner.x;
60607
+ if (corner.y < top)
60608
+ top = corner.y;
60609
+ if (corner.x > right)
60610
+ right = corner.x;
60611
+ if (corner.y > bottom)
60612
+ bottom = corner.y;
60613
+ }
60614
+ }
60615
+ const mbr = new Mbr(left, top, right, bottom);
60616
+ this.left = left;
60617
+ this.top = top;
60618
+ this.right = right;
60619
+ this.bottom = bottom;
60620
+ return mbr;
60621
+ }
60622
+ updateMbr() {
60623
+ this.getMbr();
60624
+ }
60625
+ getChildrenIds() {
60626
+ return this.index.listAll().map((item) => item.getId());
60627
+ }
60628
+ getChildren() {
60629
+ return this.index.listAll();
60630
+ }
60631
+ getLinkTo() {
60632
+ return this.linkTo.link;
60633
+ }
60634
+ serialize() {
60635
+ return {
60636
+ id: this.id,
60637
+ itemType: "Group",
60638
+ childIds: this.getChildrenIds(),
60639
+ transformation: this.transformation.serialize(),
60640
+ isLockedGroup: this.isLockedGroup
60641
+ };
60642
+ }
60643
+ deserialize(data) {
60644
+ if (data.transformation) {
60645
+ this.transformation.deserialize(data.transformation);
60646
+ }
60647
+ if (data.childIds && data.childIds.length > 0) {
60648
+ this.applyAddChildren(data.childIds);
60649
+ }
60650
+ if (data.isLockedGroup !== undefined) {
60651
+ this.isLockedGroup = data.isLockedGroup;
60652
+ }
60653
+ this.updateMbr();
60654
+ this.subject.publish(this);
60655
+ return this;
60656
+ }
60657
+ getId() {
60658
+ return this.id;
60659
+ }
60660
+ getIntersectionPoints(segment) {
60661
+ const lines = this.getMbr().getLines();
60662
+ const initPoints = [];
60663
+ return lines.reduce((acc, line) => {
60664
+ const intersections = line.getIntersectionPoints(segment);
60665
+ if (intersections.length > 0) {
60666
+ acc.push(...intersections);
60667
+ }
60668
+ return acc;
60669
+ }, initPoints);
60670
+ }
60671
+ render(context) {
60672
+ if (this.transformationRenderBlock) {
60673
+ return;
60674
+ }
60675
+ const ctx = context.ctx;
60676
+ ctx.save();
60677
+ this.transformation.applyToContext(ctx);
60678
+ for (const child of this.index.listAll()) {
60679
+ child.render(context);
60680
+ }
60681
+ ctx.restore();
60682
+ }
60683
+ };
60684
+ });
60685
+
60510
60686
  // src/Items/Connector/ConnectorTypes.ts
60511
60687
  var ConnectionLineWidths, CONNECTOR_COLOR = "rgb(20, 21, 26)", CONNECTOR_LINE_WIDTH = 1, CONNECTOR_BORDER_STYLE = "solid", DEFAULT_END_POINTER = "TriangleFilled", CONNECTOR_POINTER_TYPES;
60512
60688
  var init_ConnectorTypes = __esm(() => {
@@ -60615,6 +60791,7 @@ var init_Connector = __esm(() => {
60615
60791
  init_Settings();
60616
60792
  init_transformOps();
60617
60793
  init_BaseItem();
60794
+ init_Group();
60618
60795
  init_Color();
60619
60796
  init_ConnectorTypes();
60620
60797
  init_connectorOps();
@@ -60704,8 +60881,9 @@ var init_Connector = __esm(() => {
60704
60881
  const point5 = this.startPoint;
60705
60882
  if (point5.pointType !== "Board") {
60706
60883
  point5.recalculatePoint();
60707
- const j1 = this.smartJumpStartEdge();
60708
- const j2 = this.smartJumpEndEdge();
60884
+ const isGroupMoving = Group.movingGroupId !== null;
60885
+ const j1 = isGroupMoving ? false : this.smartJumpStartEdge();
60886
+ const j2 = isGroupMoving ? false : this.smartJumpEndEdge();
60709
60887
  if (!j1 && !j2) {
60710
60888
  this.updatePaths();
60711
60889
  this.subject.publish(this);
@@ -60716,8 +60894,9 @@ var init_Connector = __esm(() => {
60716
60894
  const point5 = this.endPoint;
60717
60895
  if (point5.pointType !== "Board") {
60718
60896
  point5.recalculatePoint();
60719
- const j1 = this.smartJumpEndEdge();
60720
- const j2 = this.smartJumpStartEdge();
60897
+ const isGroupMoving = Group.movingGroupId !== null;
60898
+ const j1 = isGroupMoving ? false : this.smartJumpEndEdge();
60899
+ const j2 = isGroupMoving ? false : this.smartJumpStartEdge();
60721
60900
  if (!j1 && !j2) {
60722
60901
  this.updatePaths();
60723
60902
  this.subject.publish(this);
@@ -66030,172 +66209,6 @@ var init_Placeholder2 = __esm(() => {
66030
66209
  init_Placeholder();
66031
66210
  });
66032
66211
 
66033
- // src/Items/Group/Group.ts
66034
- var Group;
66035
- var init_Group = __esm(() => {
66036
- init_Mbr();
66037
- init_Point();
66038
- init_BaseItem();
66039
- Group = class Group extends BaseItem {
66040
- events;
66041
- itemType = "Group";
66042
- parent = "Board";
66043
- subject = new Subject;
66044
- transformationRenderBlock = undefined;
66045
- isLockedGroup = false;
66046
- constructor(board, events, childIds = [], id = "") {
66047
- super(board, id, undefined, true);
66048
- this.events = events;
66049
- this.canBeNested = true;
66050
- if (childIds.length > 0) {
66051
- this.applyAddChildren(childIds);
66052
- }
66053
- }
66054
- isClosed() {
66055
- return false;
66056
- }
66057
- getRichText() {
66058
- return null;
66059
- }
66060
- apply(op) {
66061
- switch (op.class) {
66062
- case "Transformation":
66063
- super.apply(op);
66064
- this.updateMbr();
66065
- for (const child of this.index.listAll()) {
66066
- child.subject.publish(child);
66067
- }
66068
- break;
66069
- case "Group":
66070
- if (op.method === "addChild") {
66071
- this.applyAddChildren([op.childId]);
66072
- } else if (op.method === "removeChild") {
66073
- this.applyRemoveChildren([op.childId]);
66074
- } else {
66075
- super.apply(op);
66076
- }
66077
- break;
66078
- default:
66079
- super.apply(op);
66080
- return;
66081
- }
66082
- this.subject.publish(this);
66083
- }
66084
- emit(operation) {
66085
- if (this.events) {
66086
- const command = new GroupCommand([this], operation);
66087
- command.apply();
66088
- this.events.emit(operation, command);
66089
- } else {
66090
- this.apply(operation);
66091
- }
66092
- }
66093
- setId(id) {
66094
- this.id = id;
66095
- this.transformation.setId(id);
66096
- return this;
66097
- }
66098
- getMbr() {
66099
- const children = this.index.listAll();
66100
- if (children.length === 0) {
66101
- return new Mbr(this.left, this.top, this.right, this.bottom);
66102
- }
66103
- const groupWorldMatrix = this.getWorldMatrix();
66104
- let left = Number.MAX_SAFE_INTEGER;
66105
- let top = Number.MAX_SAFE_INTEGER;
66106
- let right = Number.MIN_SAFE_INTEGER;
66107
- let bottom = Number.MIN_SAFE_INTEGER;
66108
- for (const child of children) {
66109
- const childLocalMbr = child.getMbr();
66110
- const corners = [
66111
- new Point(childLocalMbr.left, childLocalMbr.top),
66112
- new Point(childLocalMbr.right, childLocalMbr.top),
66113
- new Point(childLocalMbr.right, childLocalMbr.bottom),
66114
- new Point(childLocalMbr.left, childLocalMbr.bottom)
66115
- ];
66116
- for (const corner of corners) {
66117
- groupWorldMatrix.apply(corner);
66118
- if (corner.x < left)
66119
- left = corner.x;
66120
- if (corner.y < top)
66121
- top = corner.y;
66122
- if (corner.x > right)
66123
- right = corner.x;
66124
- if (corner.y > bottom)
66125
- bottom = corner.y;
66126
- }
66127
- }
66128
- const mbr = new Mbr(left, top, right, bottom);
66129
- this.left = left;
66130
- this.top = top;
66131
- this.right = right;
66132
- this.bottom = bottom;
66133
- return mbr;
66134
- }
66135
- updateMbr() {
66136
- this.getMbr();
66137
- }
66138
- getChildrenIds() {
66139
- return this.index.listAll().map((item) => item.getId());
66140
- }
66141
- getChildren() {
66142
- return this.index.listAll();
66143
- }
66144
- getLinkTo() {
66145
- return this.linkTo.link;
66146
- }
66147
- serialize() {
66148
- return {
66149
- id: this.id,
66150
- itemType: "Group",
66151
- childIds: this.getChildrenIds(),
66152
- transformation: this.transformation.serialize(),
66153
- isLockedGroup: this.isLockedGroup
66154
- };
66155
- }
66156
- deserialize(data) {
66157
- if (data.transformation) {
66158
- this.transformation.deserialize(data.transformation);
66159
- }
66160
- if (data.childIds && data.childIds.length > 0) {
66161
- this.applyAddChildren(data.childIds);
66162
- }
66163
- if (data.isLockedGroup !== undefined) {
66164
- this.isLockedGroup = data.isLockedGroup;
66165
- }
66166
- this.updateMbr();
66167
- this.subject.publish(this);
66168
- return this;
66169
- }
66170
- getId() {
66171
- return this.id;
66172
- }
66173
- getIntersectionPoints(segment) {
66174
- const lines = this.getMbr().getLines();
66175
- const initPoints = [];
66176
- return lines.reduce((acc, line) => {
66177
- const intersections = line.getIntersectionPoints(segment);
66178
- if (intersections.length > 0) {
66179
- acc.push(...intersections);
66180
- }
66181
- return acc;
66182
- }, initPoints);
66183
- }
66184
- render(context) {
66185
- if (this.transformationRenderBlock) {
66186
- return;
66187
- }
66188
- const ctx = context.ctx;
66189
- ctx.save();
66190
- this.transformation.applyToContext(ctx);
66191
- for (const child of this.index.listAll()) {
66192
- child.render(context);
66193
- }
66194
- ctx.restore();
66195
- }
66196
- };
66197
- });
66198
-
66199
66212
  // src/Items/Group/index.ts
66200
66213
  var init_Group2 = __esm(() => {
66201
66214
  init_Group();
@@ -66645,26 +66658,18 @@ class ConnectorSnap {
66645
66658
  } else if (anchor) {
66646
66659
  this.controlPoint = getFixedPoint(item, anchor.getCenter());
66647
66660
  } else if (point5) {
66648
- this.controlPoint = getFixedPoint(item, point5.getCenter());
66661
+ const nearest2 = item.getNearestEdgePointTo(pointer);
66662
+ this.controlPoint = getFixedPoint(item, nearest2);
66649
66663
  } else {
66650
- this.controlPoint = getFixedPoint(item, pointer);
66664
+ if (this.hover.isTimeoutElapsed) {
66665
+ this.controlPoint = getFixedPoint(item, pointer);
66666
+ } else {
66667
+ this.controlPoint = getFixedPoint(item, pointer);
66668
+ }
66651
66669
  }
66652
66670
  }
66653
66671
  setHover() {
66654
- let hover = this.board.items.getUnderPointer(0)[0];
66655
- if (hover instanceof BaseItem && hover.index) {
66656
- const group = hover;
66657
- const inverse = group.getWorldMatrix().getInverse();
66658
- const pointer = this.board.pointer.point;
66659
- const localPointer = pointer.copy();
66660
- localPointer.transform(inverse);
66661
- for (const child of group.index.listAll()) {
66662
- if (child.getMbr().isUnderPoint(localPointer)) {
66663
- hover = child;
66664
- break;
66665
- }
66666
- }
66667
- }
66672
+ const hover = this.board.items.getUnderPointer(0)[0];
66668
66673
  if (hover) {
66669
66674
  if (hover !== this.hover.item) {
66670
66675
  this.hover = {
@@ -66721,18 +66726,8 @@ class ConnectorSnap {
66721
66726
  return nearest;
66722
66727
  }
66723
66728
  getClosestPointOnItem(item, position4) {
66724
- let worldEdgePoint;
66725
- if (item instanceof BaseItem && item.parent !== "Board") {
66726
- const parentMatrix = item.getParentWorldMatrix();
66727
- const localPos = position4.copy();
66728
- localPos.transform(parentMatrix.getInverse());
66729
- const localEdge = item.getNearestEdgePointTo(localPos);
66730
- worldEdgePoint = localEdge.copy();
66731
- parentMatrix.apply(worldEdgePoint);
66732
- } else {
66733
- worldEdgePoint = item.getNearestEdgePointTo(position4);
66734
- }
66735
- return getFixedPoint(item, worldEdgePoint);
66729
+ const nearestEdgePoint = item.getNearestEdgePointTo(position4);
66730
+ return getFixedPoint(item, nearestEdgePoint);
66736
66731
  }
66737
66732
  isNearBorder(item) {
66738
66733
  if (!item) {
@@ -66761,15 +66756,10 @@ class ConnectorSnap {
66761
66756
  }
66762
66757
  }
66763
66758
  setAnchors(item) {
66764
- const localPoints = item.getSnapAnchorPoints();
66765
- if (!localPoints) {
66759
+ const points = item.getSnapAnchorPoints();
66760
+ if (!points) {
66766
66761
  return;
66767
66762
  }
66768
- const points = item instanceof BaseItem && item.parent !== "Board" ? localPoints.map((p3) => {
66769
- const wp = p3.copy();
66770
- item.getParentWorldMatrix().apply(wp);
66771
- return wp;
66772
- }) : localPoints;
66773
66763
  const anchors = [];
66774
66764
  for (const { x, y } of points) {
66775
66765
  anchors.push(new Anchor(x, y, 5, this.color.anchorBorder, this.color.anchorBackground, 1));
@@ -66803,19 +66793,9 @@ class ConnectorSnap {
66803
66793
  const { item, anchor } = this.snap;
66804
66794
  if (item) {
66805
66795
  if (!anchor) {
66806
- let edgePoint;
66807
- if (item instanceof BaseItem && item.parent !== "Board") {
66808
- const parentMatrix = item.getParentWorldMatrix();
66809
- const localPointer = pointer.copy();
66810
- localPointer.transform(parentMatrix.getInverse());
66811
- const localEdge = item.getNearestEdgePointTo(localPointer);
66812
- edgePoint = localEdge.copy();
66813
- parentMatrix.apply(edgePoint);
66814
- } else {
66815
- edgePoint = item.getNearestEdgePointTo(pointer);
66816
- }
66817
- if (edgePoint.getDistance(pointer) < this.distance.border || !this.hover.isTimeoutElapsed) {
66818
- this.snap.point = new Anchor(edgePoint.x, edgePoint.y, 5, this.color.pointBorder, this.color.pointBackground, 1);
66796
+ const point5 = item.getNearestEdgePointTo(pointer);
66797
+ if (point5.getDistance(pointer) < this.distance.border || !this.hover.isTimeoutElapsed) {
66798
+ this.snap.point = new Anchor(point5.x, point5.y, 5, this.color.pointBorder, this.color.pointBackground, 1);
66819
66799
  } else {
66820
66800
  this.snap.point = null;
66821
66801
  }
@@ -66844,7 +66824,6 @@ class ConnectorSnap {
66844
66824
  }
66845
66825
  var init_ConnectorSnap = __esm(() => {
66846
66826
  init_ControlPoint();
66847
- init_BaseItem2();
66848
66827
  init_Anchor2();
66849
66828
  init_Connector();
66850
66829
  });
@@ -23,6 +23,12 @@ export declare class Group extends BaseItem<Group> {
23
23
  readonly subject: Subject<Group>;
24
24
  transformationRenderBlock?: boolean;
25
25
  isLockedGroup: boolean;
26
+ /**
27
+ * Set to this group's id while publishing children during a group transformation.
28
+ * Connector observers check this to skip smartJump (position is already correct
29
+ * via recalculatePoint) and avoid persisting spurious setStartPoint/setEndPoint ops.
30
+ */
31
+ static movingGroupId: string | null;
26
32
  constructor(board: Board, events?: Events | undefined, childIds?: string[], id?: string);
27
33
  isClosed(): boolean;
28
34
  getRichText(): null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.14.3",
3
+ "version": "0.14.5",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",