microboard-temp 0.13.32 → 0.13.34

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
@@ -4488,11 +4488,12 @@ var conf = {
4488
4488
  DEFAULT_GAME_ITEM_DIMENSIONS: { width: 200, height: 200 },
4489
4489
  MAX_CARD_SIZE: 500,
4490
4490
  CONNECTOR_ITEM_OFFSET: 20,
4491
- FG_SPRING_K: 3,
4491
+ FG_SPRING_K: 0.2,
4492
4492
  FG_TARGET_GAP: 20,
4493
- FG_REPULSION: 400000,
4494
- FG_DAMPING: 0.9,
4495
- FG_SLEEP_THRESHOLD: 10,
4493
+ FG_REPULSION: 500,
4494
+ FG_MIN_DIST_SQ: 100,
4495
+ FG_DAMPING: 0.6,
4496
+ FG_SLEEP_THRESHOLD: 0.5,
4496
4497
  GRAVITY_G: 80,
4497
4498
  GRAVITY_G_CENTER: 120,
4498
4499
  GRAVITY_DAMPING: 0.96,
@@ -20898,14 +20899,14 @@ class SpatialIndex {
20898
20899
  if ("index" in item && item.index) {
20899
20900
  item.removeChildItems(item.index.list());
20900
20901
  }
20902
+ this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20903
+ this.itemsIndex.remove(item);
20901
20904
  if (item.parent !== "Board") {
20902
20905
  const parentFrame = this.items.getById(item.parent);
20903
20906
  parentFrame?.removeChildItems(item);
20904
20907
  this.subject.publish(this.items);
20905
20908
  return;
20906
20909
  }
20907
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20908
- this.itemsIndex.remove(item);
20909
20910
  if (this.itemsArray.length === 0) {
20910
20911
  this.Mbr = new Mbr;
20911
20912
  } else {
@@ -20926,7 +20927,8 @@ class SpatialIndex {
20926
20927
  translateX: worldMatrix.translateX,
20927
20928
  translateY: worldMatrix.translateY,
20928
20929
  scaleX: worldMatrix.scaleX,
20929
- scaleY: worldMatrix.scaleY
20930
+ scaleY: worldMatrix.scaleY,
20931
+ isLocked: false
20930
20932
  };
20931
20933
  }
20932
20934
  return serialized;
@@ -21286,7 +21288,7 @@ class Items {
21286
21288
  if (item.itemType === "Drawing" && !item.isPointNearLine(this.pointer.point)) {
21287
21289
  return acc;
21288
21290
  }
21289
- const isItemTransparent = item instanceof Shape && item?.getBackgroundColor() === "none";
21291
+ const isItemTransparent = item instanceof Shape && item.getBackgroundColor() === "none";
21290
21292
  const itemZIndex = this.getZIndex(item);
21291
21293
  const accZIndex = this.getZIndex(acc.nearest);
21292
21294
  if (itemZIndex > accZIndex && (!isItemTransparent || area === acc.area) || area < acc.area) {
@@ -21382,7 +21384,7 @@ class Items {
21382
21384
  });
21383
21385
  const childrenMap = new Map;
21384
21386
  const GroupsHTML = groups.map((group) => {
21385
- group.getChildrenIds().forEach((childId) => childrenMap.set(childId, group.getId()));
21387
+ group.getChildrenIds()?.forEach((childId) => childrenMap.set(childId, group.getId()));
21386
21388
  const html = group.renderHTML(documentFactory);
21387
21389
  translateElementBy(html, -lowestCoordinates.left, -lowestCoordinates.top);
21388
21390
  return html;
@@ -21398,7 +21400,10 @@ class Items {
21398
21400
  item.setAttribute("data-end-point-x", (endX - lowestCoordinates.left).toString());
21399
21401
  item.setAttribute("data-end-point-y", (endY - lowestCoordinates.top).toString());
21400
21402
  }
21401
- return translateElementBy(item, -lowestCoordinates.left, -lowestCoordinates.top);
21403
+ if (!childrenMap.get(item.id)) {
21404
+ return translateElementBy(item, -lowestCoordinates.left, -lowestCoordinates.top);
21405
+ }
21406
+ return item;
21402
21407
  });
21403
21408
  for (const item of restHTML) {
21404
21409
  const parentFrameId = childrenMap.get(item.id);
@@ -22056,8 +22061,8 @@ class BaseItem extends Mbr {
22056
22061
  }
22057
22062
  renderHTML(documentFactory) {
22058
22063
  const div = documentFactory.createElement("base-item");
22059
- const { translateX, translateY } = this.transformation.getMatrixData();
22060
- const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
22064
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.getMatrixData();
22065
+ const transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
22061
22066
  div.style.backgroundColor = "#b2b0c3";
22062
22067
  div.id = this.getId();
22063
22068
  div.style.width = `${this.getWidth()}px`;
@@ -40241,7 +40246,7 @@ class Shape extends BaseItem {
40241
40246
  if (Shapes[this.shapeType].useMbrUnderPointer) {
40242
40247
  return this.mbr.isUnderPoint(point5);
40243
40248
  }
40244
- if (this.text.isEmpty() && (this.backgroundOpacity === 0 || this.backgroundColor === "none" || this.backgroundColor === "")) {
40249
+ if (this.text.isEmpty() && (this.backgroundOpacity === 0 || this.backgroundColor === "none" || this.backgroundColor === "transparent" || this.backgroundColor === "")) {
40245
40250
  return this.path.isPointOverEdges(point5, tolerance);
40246
40251
  } else {
40247
40252
  return this.textContainer.isUnderPoint(point5) || this.path.isUnderPoint(point5);
@@ -40293,8 +40298,8 @@ class Shape extends BaseItem {
40293
40298
  const pathElement = Shapes[this.shapeType].path.copy().renderHTML(documentFactory);
40294
40299
  const paths = Array.isArray(pathElement) ? pathElement : [pathElement];
40295
40300
  paths.forEach((element4) => {
40296
- element4.setAttribute("fill", this.backgroundColor);
40297
- element4.setAttribute("stroke", this.borderColor);
40301
+ element4.setAttribute("fill", resolveColor(this.backgroundColor, conf.theme, "background"));
40302
+ element4.setAttribute("stroke", resolveColor(this.borderColor, conf.theme, "foreground"));
40298
40303
  element4.setAttribute("stroke-dasharray", LinePatterns[this.borderStyle].join(", "));
40299
40304
  element4.setAttribute("stroke-width", this.borderWidth.toString());
40300
40305
  element4.setAttribute("transform-origin", "0 0");
@@ -40309,8 +40314,8 @@ class Shape extends BaseItem {
40309
40314
  div.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
40310
40315
  div.style.position = "absolute";
40311
40316
  div.setAttribute("data-shape-type", this.shapeType);
40312
- div.setAttribute("fill", this.backgroundColor);
40313
- div.setAttribute("stroke", this.borderColor);
40317
+ div.setAttribute("fill", resolveColor(this.backgroundColor, conf.theme, "background"));
40318
+ div.setAttribute("stroke", resolveColor(this.borderColor, conf.theme, "foreground"));
40314
40319
  div.setAttribute("data-border-style", this.borderStyle);
40315
40320
  div.setAttribute("stroke-dasharray", LinePatterns[this.borderStyle].join(", "));
40316
40321
  div.setAttribute("stroke-width", this.borderWidth.toString());
@@ -40354,9 +40359,6 @@ class Shape extends BaseItem {
40354
40359
  this.text.updateElement();
40355
40360
  }
40356
40361
  transformPath() {
40357
- if (conf.isNode()) {
40358
- return;
40359
- }
40360
40362
  this.path = Shapes[this.shapeType].createPath(this.mbr);
40361
40363
  this.textContainer = Shapes[this.shapeType].textBounds.copy();
40362
40364
  this.text.setContainer(this.textContainer.copy());
@@ -43664,7 +43666,13 @@ class Group extends BaseItem {
43664
43666
  ctx.restore();
43665
43667
  }
43666
43668
  renderHTML(documentFactory) {
43667
- return documentFactory.createElement("div");
43669
+ const div = documentFactory.createElement("div");
43670
+ div.id = this.id;
43671
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.getMatrixData();
43672
+ div.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
43673
+ div.style.position = "absolute";
43674
+ div.style.transformOrigin = "0 0";
43675
+ return div;
43668
43676
  }
43669
43677
  }
43670
43678
  // src/itemFactories.ts
@@ -54518,7 +54526,6 @@ class ForceGraphEngine {
54518
54526
  activeComponents = new Map;
54519
54527
  TICK_MS = 33;
54520
54528
  SYNC_MS = 300;
54521
- SOFTENING_SQ = 100 * 100;
54522
54529
  MIN_MOVE_PX = 0.05;
54523
54530
  constructor(board) {
54524
54531
  this.board = board;
@@ -54667,42 +54674,27 @@ class ForceGraphEngine {
54667
54674
  return this.board.items.listAll().filter((item) => item.itemType === "Connector");
54668
54675
  }
54669
54676
  tick() {
54670
- const dt = this.TICK_MS / 1000;
54671
54677
  const activeIds = this.getActiveNodeIds();
54672
54678
  const draggedIds = this.board.getDraggedItemIds();
54673
54679
  const allNodes = this.getNodes();
54674
- const nodes = allNodes.filter((item) => {
54675
- if (!activeIds.has(item.getId()))
54676
- return false;
54677
- if (draggedIds.has(item.getId()))
54678
- return false;
54679
- if (item.parent !== "Board" && draggedIds.has(item.parent))
54680
- return false;
54681
- return true;
54682
- });
54683
- if (nodes.length < 1)
54684
- return;
54685
54680
  const snapMap = new Map;
54686
- for (const item of nodes) {
54681
+ for (const item of allNodes) {
54682
+ if (!activeIds.has(item.getId()))
54683
+ continue;
54687
54684
  const pos = item.transformation.getTranslation();
54688
54685
  const mbr = item.getMbr();
54689
54686
  const w = Math.max(mbr.getWidth(), 1);
54690
54687
  const h2 = Math.max(mbr.getHeight(), 1);
54691
- snapMap.set(item.getId(), {
54692
- id: item.getId(),
54693
- cx: pos.x + w * 0.5,
54694
- cy: pos.y + h2 * 0.5,
54695
- w,
54696
- h: h2
54697
- });
54688
+ snapMap.set(item.getId(), { id: item.getId(), cx: pos.x + w * 0.5, cy: pos.y + h2 * 0.5, w, h: h2 });
54698
54689
  }
54699
54690
  const snap = Array.from(snapMap.values());
54691
+ if (snap.length < 1)
54692
+ return;
54700
54693
  const uf = new UnionFind;
54701
54694
  for (const connector of this.getConnectors()) {
54702
54695
  const { startItem, endItem } = connector.getConnectedItems();
54703
- if (startItem && endItem) {
54696
+ if (startItem && endItem)
54704
54697
  uf.union(startItem.getId(), endItem.getId());
54705
- }
54706
54698
  }
54707
54699
  const ax = new Map;
54708
54700
  const ay = new Map;
@@ -54720,14 +54712,13 @@ class ForceGraphEngine {
54720
54712
  continue;
54721
54713
  const dx = s2.cx - s1.cx;
54722
54714
  const dy = s2.cy - s1.cy;
54723
- const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54715
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1;
54724
54716
  const compId = this.findComponentId(s1.id);
54725
54717
  const targetGap = compId ? this.activeComponents.get(compId)?.targetGap ?? conf.FG_TARGET_GAP : conf.FG_TARGET_GAP;
54726
54718
  const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + targetGap;
54727
- const stretch = dist - targetDist;
54728
- const forceMag = stretch * conf.FG_SPRING_K;
54729
- const fx = dx / dist * forceMag;
54730
- const fy = dy / dist * forceMag;
54719
+ const force = (dist - targetDist) * conf.FG_SPRING_K;
54720
+ const fx = dx / dist * force;
54721
+ const fy = dy / dist * force;
54731
54722
  ax.set(s1.id, (ax.get(s1.id) ?? 0) + fx);
54732
54723
  ay.set(s1.id, (ay.get(s1.id) ?? 0) + fy);
54733
54724
  ax.set(s2.id, (ax.get(s2.id) ?? 0) - fx);
@@ -54741,35 +54732,35 @@ class ForceGraphEngine {
54741
54732
  continue;
54742
54733
  const dx = s2.cx - s1.cx;
54743
54734
  const dy = s2.cy - s1.cy;
54744
- const centerDist = Math.sqrt(dx * dx + dy * dy) + 0.001;
54745
- const r1 = Math.max(s1.w, s1.h) * 0.5;
54746
- const r2 = Math.max(s2.w, s2.h) * 0.5;
54747
- const edgeDist = Math.max(centerDist - r1 - r2, 1);
54748
- const repMag = conf.FG_REPULSION / (edgeDist * edgeDist + this.SOFTENING_SQ);
54749
- const fx = dx / centerDist * repMag;
54750
- const fy = dy / centerDist * repMag;
54751
- ax.set(s1.id, (ax.get(s1.id) ?? 0) - fx);
54752
- ay.set(s1.id, (ay.get(s1.id) ?? 0) - fy);
54753
- ax.set(s2.id, (ax.get(s2.id) ?? 0) + fx);
54754
- ay.set(s2.id, (ay.get(s2.id) ?? 0) + fy);
54735
+ const distSq = Math.max(dx * dx + dy * dy, conf.FG_MIN_DIST_SQ);
54736
+ const force = conf.FG_REPULSION / distSq;
54737
+ ax.set(s1.id, (ax.get(s1.id) ?? 0) - dx * force);
54738
+ ay.set(s1.id, (ay.get(s1.id) ?? 0) - dy * force);
54739
+ ax.set(s2.id, (ax.get(s2.id) ?? 0) + dx * force);
54740
+ ay.set(s2.id, (ay.get(s2.id) ?? 0) + dy * force);
54755
54741
  }
54756
54742
  }
54757
54743
  let totalEnergy = 0;
54758
- for (const item of nodes) {
54744
+ for (const item of allNodes) {
54759
54745
  const id = item.getId();
54760
- if (!this.velocities.has(id)) {
54746
+ if (!activeIds.has(id))
54747
+ continue;
54748
+ if (!this.velocities.has(id))
54761
54749
  this.velocities.set(id, { vx: 0, vy: 0 });
54762
- }
54763
54750
  const vel = this.velocities.get(id);
54764
- vel.vx = (vel.vx + (ax.get(id) ?? 0) * dt) * conf.FG_DAMPING;
54765
- vel.vy = (vel.vy + (ay.get(id) ?? 0) * dt) * conf.FG_DAMPING;
54766
- totalEnergy += vel.vx * vel.vx + vel.vy * vel.vy;
54767
- const moveX = vel.vx * dt;
54768
- const moveY = vel.vy * dt;
54769
- if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
54751
+ const isDragged = draggedIds.has(id) || item.parent !== "Board" && draggedIds.has(item.parent);
54752
+ if (isDragged) {
54753
+ vel.vx = 0;
54754
+ vel.vy = 0;
54755
+ continue;
54756
+ }
54757
+ vel.vx = (vel.vx + (ax.get(id) ?? 0)) * conf.FG_DAMPING;
54758
+ vel.vy = (vel.vy + (ay.get(id) ?? 0)) * conf.FG_DAMPING;
54759
+ totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
54760
+ if (Math.abs(vel.vx) >= this.MIN_MOVE_PX || Math.abs(vel.vy) >= this.MIN_MOVE_PX) {
54770
54761
  item.transformation.applyMatrixSilent({
54771
- translateX: moveX,
54772
- translateY: moveY,
54762
+ translateX: vel.vx,
54763
+ translateY: vel.vy,
54773
54764
  scaleX: 1,
54774
54765
  scaleY: 1,
54775
54766
  shearX: 0,
package/dist/esm/node.js CHANGED
@@ -5272,11 +5272,12 @@ var conf = {
5272
5272
  DEFAULT_GAME_ITEM_DIMENSIONS: { width: 200, height: 200 },
5273
5273
  MAX_CARD_SIZE: 500,
5274
5274
  CONNECTOR_ITEM_OFFSET: 20,
5275
- FG_SPRING_K: 3,
5275
+ FG_SPRING_K: 0.2,
5276
5276
  FG_TARGET_GAP: 20,
5277
- FG_REPULSION: 400000,
5278
- FG_DAMPING: 0.9,
5279
- FG_SLEEP_THRESHOLD: 10,
5277
+ FG_REPULSION: 500,
5278
+ FG_MIN_DIST_SQ: 100,
5279
+ FG_DAMPING: 0.6,
5280
+ FG_SLEEP_THRESHOLD: 0.5,
5280
5281
  GRAVITY_G: 80,
5281
5282
  GRAVITY_G_CENTER: 120,
5282
5283
  GRAVITY_DAMPING: 0.96,
@@ -23365,14 +23366,14 @@ class SpatialIndex {
23365
23366
  if ("index" in item && item.index) {
23366
23367
  item.removeChildItems(item.index.list());
23367
23368
  }
23369
+ this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
23370
+ this.itemsIndex.remove(item);
23368
23371
  if (item.parent !== "Board") {
23369
23372
  const parentFrame = this.items.getById(item.parent);
23370
23373
  parentFrame?.removeChildItems(item);
23371
23374
  this.subject.publish(this.items);
23372
23375
  return;
23373
23376
  }
23374
- this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
23375
- this.itemsIndex.remove(item);
23376
23377
  if (this.itemsArray.length === 0) {
23377
23378
  this.Mbr = new Mbr;
23378
23379
  } else {
@@ -23393,7 +23394,8 @@ class SpatialIndex {
23393
23394
  translateX: worldMatrix.translateX,
23394
23395
  translateY: worldMatrix.translateY,
23395
23396
  scaleX: worldMatrix.scaleX,
23396
- scaleY: worldMatrix.scaleY
23397
+ scaleY: worldMatrix.scaleY,
23398
+ isLocked: false
23397
23399
  };
23398
23400
  }
23399
23401
  return serialized;
@@ -23753,7 +23755,7 @@ class Items {
23753
23755
  if (item.itemType === "Drawing" && !item.isPointNearLine(this.pointer.point)) {
23754
23756
  return acc;
23755
23757
  }
23756
- const isItemTransparent = item instanceof Shape && item?.getBackgroundColor() === "none";
23758
+ const isItemTransparent = item instanceof Shape && item.getBackgroundColor() === "none";
23757
23759
  const itemZIndex = this.getZIndex(item);
23758
23760
  const accZIndex = this.getZIndex(acc.nearest);
23759
23761
  if (itemZIndex > accZIndex && (!isItemTransparent || area === acc.area) || area < acc.area) {
@@ -23849,7 +23851,7 @@ class Items {
23849
23851
  });
23850
23852
  const childrenMap = new Map;
23851
23853
  const GroupsHTML = groups.map((group) => {
23852
- group.getChildrenIds().forEach((childId) => childrenMap.set(childId, group.getId()));
23854
+ group.getChildrenIds()?.forEach((childId) => childrenMap.set(childId, group.getId()));
23853
23855
  const html = group.renderHTML(documentFactory);
23854
23856
  translateElementBy(html, -lowestCoordinates.left, -lowestCoordinates.top);
23855
23857
  return html;
@@ -23865,7 +23867,10 @@ class Items {
23865
23867
  item.setAttribute("data-end-point-x", (endX - lowestCoordinates.left).toString());
23866
23868
  item.setAttribute("data-end-point-y", (endY - lowestCoordinates.top).toString());
23867
23869
  }
23868
- return translateElementBy(item, -lowestCoordinates.left, -lowestCoordinates.top);
23870
+ if (!childrenMap.get(item.id)) {
23871
+ return translateElementBy(item, -lowestCoordinates.left, -lowestCoordinates.top);
23872
+ }
23873
+ return item;
23869
23874
  });
23870
23875
  for (const item of restHTML) {
23871
23876
  const parentFrameId = childrenMap.get(item.id);
@@ -24523,8 +24528,8 @@ class BaseItem extends Mbr {
24523
24528
  }
24524
24529
  renderHTML(documentFactory) {
24525
24530
  const div = documentFactory.createElement("base-item");
24526
- const { translateX, translateY } = this.transformation.getMatrixData();
24527
- const transform = `translate(${translateX}px, ${translateY}px) scale(1, 1)`;
24531
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.getMatrixData();
24532
+ const transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
24528
24533
  div.style.backgroundColor = "#b2b0c3";
24529
24534
  div.id = this.getId();
24530
24535
  div.style.width = `${this.getWidth()}px`;
@@ -42709,7 +42714,7 @@ class Shape extends BaseItem {
42709
42714
  if (Shapes[this.shapeType].useMbrUnderPointer) {
42710
42715
  return this.mbr.isUnderPoint(point5);
42711
42716
  }
42712
- if (this.text.isEmpty() && (this.backgroundOpacity === 0 || this.backgroundColor === "none" || this.backgroundColor === "")) {
42717
+ if (this.text.isEmpty() && (this.backgroundOpacity === 0 || this.backgroundColor === "none" || this.backgroundColor === "transparent" || this.backgroundColor === "")) {
42713
42718
  return this.path.isPointOverEdges(point5, tolerance);
42714
42719
  } else {
42715
42720
  return this.textContainer.isUnderPoint(point5) || this.path.isUnderPoint(point5);
@@ -42761,8 +42766,8 @@ class Shape extends BaseItem {
42761
42766
  const pathElement = Shapes[this.shapeType].path.copy().renderHTML(documentFactory);
42762
42767
  const paths = Array.isArray(pathElement) ? pathElement : [pathElement];
42763
42768
  paths.forEach((element3) => {
42764
- element3.setAttribute("fill", this.backgroundColor);
42765
- element3.setAttribute("stroke", this.borderColor);
42769
+ element3.setAttribute("fill", resolveColor(this.backgroundColor, conf.theme, "background"));
42770
+ element3.setAttribute("stroke", resolveColor(this.borderColor, conf.theme, "foreground"));
42766
42771
  element3.setAttribute("stroke-dasharray", LinePatterns[this.borderStyle].join(", "));
42767
42772
  element3.setAttribute("stroke-width", this.borderWidth.toString());
42768
42773
  element3.setAttribute("transform-origin", "0 0");
@@ -42777,8 +42782,8 @@ class Shape extends BaseItem {
42777
42782
  div.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
42778
42783
  div.style.position = "absolute";
42779
42784
  div.setAttribute("data-shape-type", this.shapeType);
42780
- div.setAttribute("fill", this.backgroundColor);
42781
- div.setAttribute("stroke", this.borderColor);
42785
+ div.setAttribute("fill", resolveColor(this.backgroundColor, conf.theme, "background"));
42786
+ div.setAttribute("stroke", resolveColor(this.borderColor, conf.theme, "foreground"));
42782
42787
  div.setAttribute("data-border-style", this.borderStyle);
42783
42788
  div.setAttribute("stroke-dasharray", LinePatterns[this.borderStyle].join(", "));
42784
42789
  div.setAttribute("stroke-width", this.borderWidth.toString());
@@ -42822,9 +42827,6 @@ class Shape extends BaseItem {
42822
42827
  this.text.updateElement();
42823
42828
  }
42824
42829
  transformPath() {
42825
- if (conf.isNode()) {
42826
- return;
42827
- }
42828
42830
  this.path = Shapes[this.shapeType].createPath(this.mbr);
42829
42831
  this.textContainer = Shapes[this.shapeType].textBounds.copy();
42830
42832
  this.text.setContainer(this.textContainer.copy());
@@ -46132,7 +46134,13 @@ class Group extends BaseItem {
46132
46134
  ctx.restore();
46133
46135
  }
46134
46136
  renderHTML(documentFactory) {
46135
- return documentFactory.createElement("div");
46137
+ const div = documentFactory.createElement("div");
46138
+ div.id = this.id;
46139
+ const { translateX, translateY, scaleX, scaleY } = this.transformation.getMatrixData();
46140
+ div.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scaleX}, ${scaleY})`;
46141
+ div.style.position = "absolute";
46142
+ div.style.transformOrigin = "0 0";
46143
+ return div;
46136
46144
  }
46137
46145
  }
46138
46146
  // src/itemFactories.ts
@@ -56986,7 +56994,6 @@ class ForceGraphEngine {
56986
56994
  activeComponents = new Map;
56987
56995
  TICK_MS = 33;
56988
56996
  SYNC_MS = 300;
56989
- SOFTENING_SQ = 100 * 100;
56990
56997
  MIN_MOVE_PX = 0.05;
56991
56998
  constructor(board) {
56992
56999
  this.board = board;
@@ -57135,42 +57142,27 @@ class ForceGraphEngine {
57135
57142
  return this.board.items.listAll().filter((item) => item.itemType === "Connector");
57136
57143
  }
57137
57144
  tick() {
57138
- const dt = this.TICK_MS / 1000;
57139
57145
  const activeIds = this.getActiveNodeIds();
57140
57146
  const draggedIds = this.board.getDraggedItemIds();
57141
57147
  const allNodes = this.getNodes();
57142
- const nodes = allNodes.filter((item) => {
57143
- if (!activeIds.has(item.getId()))
57144
- return false;
57145
- if (draggedIds.has(item.getId()))
57146
- return false;
57147
- if (item.parent !== "Board" && draggedIds.has(item.parent))
57148
- return false;
57149
- return true;
57150
- });
57151
- if (nodes.length < 1)
57152
- return;
57153
57148
  const snapMap = new Map;
57154
- for (const item of nodes) {
57149
+ for (const item of allNodes) {
57150
+ if (!activeIds.has(item.getId()))
57151
+ continue;
57155
57152
  const pos = item.transformation.getTranslation();
57156
57153
  const mbr = item.getMbr();
57157
57154
  const w = Math.max(mbr.getWidth(), 1);
57158
57155
  const h2 = Math.max(mbr.getHeight(), 1);
57159
- snapMap.set(item.getId(), {
57160
- id: item.getId(),
57161
- cx: pos.x + w * 0.5,
57162
- cy: pos.y + h2 * 0.5,
57163
- w,
57164
- h: h2
57165
- });
57156
+ snapMap.set(item.getId(), { id: item.getId(), cx: pos.x + w * 0.5, cy: pos.y + h2 * 0.5, w, h: h2 });
57166
57157
  }
57167
57158
  const snap = Array.from(snapMap.values());
57159
+ if (snap.length < 1)
57160
+ return;
57168
57161
  const uf = new UnionFind;
57169
57162
  for (const connector of this.getConnectors()) {
57170
57163
  const { startItem, endItem } = connector.getConnectedItems();
57171
- if (startItem && endItem) {
57164
+ if (startItem && endItem)
57172
57165
  uf.union(startItem.getId(), endItem.getId());
57173
- }
57174
57166
  }
57175
57167
  const ax = new Map;
57176
57168
  const ay = new Map;
@@ -57188,14 +57180,13 @@ class ForceGraphEngine {
57188
57180
  continue;
57189
57181
  const dx = s2.cx - s1.cx;
57190
57182
  const dy = s2.cy - s1.cy;
57191
- const dist = Math.sqrt(dx * dx + dy * dy) + 0.001;
57183
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1;
57192
57184
  const compId = this.findComponentId(s1.id);
57193
57185
  const targetGap = compId ? this.activeComponents.get(compId)?.targetGap ?? conf.FG_TARGET_GAP : conf.FG_TARGET_GAP;
57194
57186
  const targetDist = (Math.max(s1.w, s1.h) + Math.max(s2.w, s2.h)) * 0.5 + targetGap;
57195
- const stretch = dist - targetDist;
57196
- const forceMag = stretch * conf.FG_SPRING_K;
57197
- const fx = dx / dist * forceMag;
57198
- const fy = dy / dist * forceMag;
57187
+ const force = (dist - targetDist) * conf.FG_SPRING_K;
57188
+ const fx = dx / dist * force;
57189
+ const fy = dy / dist * force;
57199
57190
  ax.set(s1.id, (ax.get(s1.id) ?? 0) + fx);
57200
57191
  ay.set(s1.id, (ay.get(s1.id) ?? 0) + fy);
57201
57192
  ax.set(s2.id, (ax.get(s2.id) ?? 0) - fx);
@@ -57209,35 +57200,35 @@ class ForceGraphEngine {
57209
57200
  continue;
57210
57201
  const dx = s2.cx - s1.cx;
57211
57202
  const dy = s2.cy - s1.cy;
57212
- const centerDist = Math.sqrt(dx * dx + dy * dy) + 0.001;
57213
- const r1 = Math.max(s1.w, s1.h) * 0.5;
57214
- const r2 = Math.max(s2.w, s2.h) * 0.5;
57215
- const edgeDist = Math.max(centerDist - r1 - r2, 1);
57216
- const repMag = conf.FG_REPULSION / (edgeDist * edgeDist + this.SOFTENING_SQ);
57217
- const fx = dx / centerDist * repMag;
57218
- const fy = dy / centerDist * repMag;
57219
- ax.set(s1.id, (ax.get(s1.id) ?? 0) - fx);
57220
- ay.set(s1.id, (ay.get(s1.id) ?? 0) - fy);
57221
- ax.set(s2.id, (ax.get(s2.id) ?? 0) + fx);
57222
- ay.set(s2.id, (ay.get(s2.id) ?? 0) + fy);
57203
+ const distSq = Math.max(dx * dx + dy * dy, conf.FG_MIN_DIST_SQ);
57204
+ const force = conf.FG_REPULSION / distSq;
57205
+ ax.set(s1.id, (ax.get(s1.id) ?? 0) - dx * force);
57206
+ ay.set(s1.id, (ay.get(s1.id) ?? 0) - dy * force);
57207
+ ax.set(s2.id, (ax.get(s2.id) ?? 0) + dx * force);
57208
+ ay.set(s2.id, (ay.get(s2.id) ?? 0) + dy * force);
57223
57209
  }
57224
57210
  }
57225
57211
  let totalEnergy = 0;
57226
- for (const item of nodes) {
57212
+ for (const item of allNodes) {
57227
57213
  const id = item.getId();
57228
- if (!this.velocities.has(id)) {
57214
+ if (!activeIds.has(id))
57215
+ continue;
57216
+ if (!this.velocities.has(id))
57229
57217
  this.velocities.set(id, { vx: 0, vy: 0 });
57230
- }
57231
57218
  const vel = this.velocities.get(id);
57232
- vel.vx = (vel.vx + (ax.get(id) ?? 0) * dt) * conf.FG_DAMPING;
57233
- vel.vy = (vel.vy + (ay.get(id) ?? 0) * dt) * conf.FG_DAMPING;
57234
- totalEnergy += vel.vx * vel.vx + vel.vy * vel.vy;
57235
- const moveX = vel.vx * dt;
57236
- const moveY = vel.vy * dt;
57237
- if (Math.abs(moveX) >= this.MIN_MOVE_PX || Math.abs(moveY) >= this.MIN_MOVE_PX) {
57219
+ const isDragged = draggedIds.has(id) || item.parent !== "Board" && draggedIds.has(item.parent);
57220
+ if (isDragged) {
57221
+ vel.vx = 0;
57222
+ vel.vy = 0;
57223
+ continue;
57224
+ }
57225
+ vel.vx = (vel.vx + (ax.get(id) ?? 0)) * conf.FG_DAMPING;
57226
+ vel.vy = (vel.vy + (ay.get(id) ?? 0)) * conf.FG_DAMPING;
57227
+ totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
57228
+ if (Math.abs(vel.vx) >= this.MIN_MOVE_PX || Math.abs(vel.vy) >= this.MIN_MOVE_PX) {
57238
57229
  item.transformation.applyMatrixSilent({
57239
- translateX: moveX,
57240
- translateY: moveY,
57230
+ translateX: vel.vx,
57231
+ translateY: vel.vy,
57241
57232
  scaleX: 1,
57242
57233
  scaleY: 1,
57243
57234
  shearX: 0,
@@ -10,7 +10,6 @@ export declare class ForceGraphEngine {
10
10
  private activeComponents;
11
11
  private readonly TICK_MS;
12
12
  private readonly SYNC_MS;
13
- private readonly SOFTENING_SQ;
14
13
  private readonly MIN_MOVE_PX;
15
14
  constructor(board: Board);
16
15
  /**
@@ -250,6 +250,7 @@ export declare const conf: {
250
250
  FG_SPRING_K: number;
251
251
  FG_TARGET_GAP: number;
252
252
  FG_REPULSION: number;
253
+ FG_MIN_DIST_SQ: number;
253
254
  FG_DAMPING: number;
254
255
  FG_SLEEP_THRESHOLD: number;
255
256
  GRAVITY_G: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.13.32",
3
+ "version": "0.13.34",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",