@inditextech/weave-sdk 3.9.2 → 3.10.1

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/types.js CHANGED
@@ -4,6 +4,7 @@ import { WEAVE_ASYNC_STATUS, WEAVE_AWARENESS_LAYER_ID, WEAVE_EXPORT_BACKGROUND_C
4
4
  import { getYjsDoc, getYjsValue, observeDeep, syncedStore } from "@syncedstore/core";
5
5
  import * as Y$1 from "yjs";
6
6
  import * as Y from "yjs";
7
+ import simplify from "simplify-js";
7
8
  import "konva/lib/types";
8
9
 
9
10
  //#region rolldown:runtime
@@ -17697,7 +17698,8 @@ function moveNodeToContainerNT(instance, node, containerToMove, originalNode, or
17697
17698
  const actualContainerAttrs = nodeActualContainer.getAttrs();
17698
17699
  let layerToMove = void 0;
17699
17700
  if (actualContainerAttrs.id !== containerToMove.getAttrs().id && !invalidOriginsTypes.includes(node.getAttrs().nodeType)) layerToMove = containerToMove;
17700
- if (layerToMove && actualContainerAttrs.id !== layerToMove.getAttrs().id && actualContainerAttrs.id !== layerToMove.getAttrs().containerId) {
17701
+ const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
17702
+ if (layerToMove && actualContainerAttrs.id !== layerToMove.getAttrs().id && actualContainerAttrs.id !== layerToMove.getAttrs().containerId && nodeHandler) {
17701
17703
  const layerToMoveAttrs = layerToMove.getAttrs();
17702
17704
  const nodePos = node.getAbsolutePosition();
17703
17705
  const nodeRotation = node.getAbsoluteRotation();
@@ -17706,7 +17708,6 @@ function moveNodeToContainerNT(instance, node, containerToMove, originalNode, or
17706
17708
  node.rotation(nodeRotation);
17707
17709
  node.x(node.x() - (layerToMoveAttrs.containerOffsetX ?? 0));
17708
17710
  node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
17709
- node.destroy();
17710
17711
  const newNode = node.clone();
17711
17712
  instance.emitEvent("onNodeMovedToContainer", {
17712
17713
  node: newNode,
@@ -17714,17 +17715,15 @@ function moveNodeToContainerNT(instance, node, containerToMove, originalNode, or
17714
17715
  originalNode,
17715
17716
  originalContainer
17716
17717
  });
17717
- const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
17718
- if (nodeHandler) {
17719
- const actualNodeState = nodeHandler.serialize(node);
17720
- const newNodeState = nodeHandler.serialize(newNode);
17721
- instance.removeNodeNT(actualNodeState, { emitUserChangeEvent: false });
17722
- instance.addNodeNT(newNodeState, layerToMoveAttrs.id, {
17723
- emitUserChangeEvent: false,
17724
- overrideUserChangeType: WEAVE_NODE_CHANGE_TYPE.UPDATE
17725
- });
17726
- return true;
17727
- }
17718
+ const actualNodeState = nodeHandler.serialize(node);
17719
+ const newNodeState = nodeHandler.serialize(newNode);
17720
+ node.destroy();
17721
+ instance.removeNodeNT(actualNodeState, { emitUserChangeEvent: false });
17722
+ instance.addNodeNT(newNodeState, layerToMoveAttrs.id, {
17723
+ emitUserChangeEvent: false,
17724
+ overrideUserChangeType: WEAVE_NODE_CHANGE_TYPE.UPDATE
17725
+ });
17726
+ return true;
17728
17727
  }
17729
17728
  return false;
17730
17729
  }
@@ -19287,10 +19286,10 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19287
19286
  }
19288
19287
  const isStage = e.target instanceof Konva.Stage;
19289
19288
  const isTransformer = e.target?.getParent() instanceof Konva.Transformer;
19290
- const isTargetable = e.target.getAttrs().isTargetable !== false;
19289
+ const canBeTargeted = e.target.getAttrs().canBeTargeted !== false;
19291
19290
  const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
19292
19291
  if (isTransformer) return;
19293
- if (!isStage && !isContainerEmptyArea && isTargetable) {
19292
+ if (!isStage && !isContainerEmptyArea && canBeTargeted) {
19294
19293
  this.selecting = false;
19295
19294
  this.stopPanLoop();
19296
19295
  this.hideSelectorArea();
@@ -20402,6 +20401,9 @@ var WeaveNode = class {
20402
20401
  mutexUserId: void 0
20403
20402
  });
20404
20403
  };
20404
+ const isLocked = node.getAttrs().locked ?? false;
20405
+ if (isLocked) node.listening(false);
20406
+ else node.listening(true);
20405
20407
  }
20406
20408
  isNodeSelected(ele) {
20407
20409
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -20786,27 +20788,27 @@ var WeaveNode = class {
20786
20788
  const activeAction = this.instance.getActiveAction();
20787
20789
  const isNodeSelectionEnabled = this.getSelectionPlugin()?.isEnabled();
20788
20790
  const realNode = this.instance.getInstanceRecursive(node);
20789
- const isTargetable = node.getAttrs().isTargetable !== false;
20790
- const isLocked = node.getAttrs().locked ?? false;
20791
+ const canBeTargeted = realNode.getAttrs().canBeTargeted !== false;
20792
+ const isLocked = realNode.getAttrs().locked ?? false;
20791
20793
  const isMutexLocked = realNode.getAttrs().mutexLocked && realNode.getAttrs().mutexUserId !== user.id;
20792
20794
  if ([MOVE_TOOL_ACTION_NAME].includes(activeAction ?? "")) return false;
20793
20795
  let showHover = false;
20794
20796
  let cancelBubble = false;
20795
- if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && (isLocked || isMutexLocked)) {
20797
+ if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && realNode.hasName("node") && (isLocked || isMutexLocked)) {
20796
20798
  stage.container().style.cursor = "default";
20797
20799
  cancelBubble = true;
20798
20800
  }
20799
- if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20801
+ if (isNodeSelectionEnabled && this.isSelecting() && !this.isNodeSelected(realNode) && !this.isPasting() && canBeTargeted && realNode.hasName("node") && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20800
20802
  showHover = true;
20801
- stage.container().style.cursor = (typeof node?.defineMousePointer === "function" ? node.defineMousePointer() : null) ?? "pointer";
20803
+ stage.container().style.cursor = (typeof realNode?.defineMousePointer === "function" ? realNode.defineMousePointer() : null) ?? "pointer";
20802
20804
  cancelBubble = true;
20803
20805
  }
20804
- if (isNodeSelectionEnabled && this.isSelecting() && this.isNodeSelected(realNode) && !this.isPasting() && isTargetable && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20806
+ if (isNodeSelectionEnabled && this.isSelecting() && this.isNodeSelected(realNode) && !this.isPasting() && realNode.hasName("node") && canBeTargeted && !(isLocked || isMutexLocked) && stage.mode() === WEAVE_STAGE_DEFAULT_MODE) {
20805
20807
  showHover = true;
20806
- stage.container().style.cursor = (typeof node?.defineMousePointer === "function" ? node.defineMousePointer() : null) ?? "grab";
20808
+ stage.container().style.cursor = (typeof realNode?.defineMousePointer === "function" ? realNode.defineMousePointer() : null) ?? "grab";
20807
20809
  cancelBubble = true;
20808
20810
  }
20809
- if (!isTargetable) cancelBubble = true;
20811
+ if (!canBeTargeted) cancelBubble = true;
20810
20812
  if (this.isPasting()) {
20811
20813
  stage.container().style.cursor = "crosshair";
20812
20814
  cancelBubble = true;
@@ -20894,7 +20896,12 @@ var WeaveNode = class {
20894
20896
  }
20895
20897
  lock(instance) {
20896
20898
  if (instance.getAttrs().nodeType !== this.getNodeType()) return;
20897
- instance.setAttrs({ locked: true });
20899
+ const isListening = instance.listening();
20900
+ instance.setAttrs({
20901
+ locked: true,
20902
+ listening: false,
20903
+ previousListening: isListening
20904
+ });
20898
20905
  this.instance.updateNode(this.serialize(instance));
20899
20906
  const selectionPlugin = this.getSelectionPlugin();
20900
20907
  if (selectionPlugin) {
@@ -20912,7 +20919,12 @@ var WeaveNode = class {
20912
20919
  let realInstance = instance;
20913
20920
  if (instance.getAttrs().nodeId) realInstance = this.instance.getStage().findOne(`#${instance.getAttrs().nodeId}`);
20914
20921
  if (!realInstance) return;
20915
- realInstance.setAttrs({ locked: false });
20922
+ const previousListening = realInstance.getAttrs().previousListening ?? true;
20923
+ realInstance.setAttrs({
20924
+ locked: false,
20925
+ listening: previousListening,
20926
+ previousListening: void 0
20927
+ });
20916
20928
  this.instance.updateNode(this.serialize(realInstance));
20917
20929
  this.setupDefaultNodeEvents(realInstance);
20918
20930
  const stage = this.instance.getStage();
@@ -22086,7 +22098,7 @@ var WeaveRegisterManager = class {
22086
22098
 
22087
22099
  //#endregion
22088
22100
  //#region package.json
22089
- var version = "3.9.2";
22101
+ var version = "3.10.1";
22090
22102
 
22091
22103
  //#endregion
22092
22104
  //#region src/managers/setup.ts
@@ -24274,6 +24286,7 @@ async function downscaleImageFile(file, ratio) {
24274
24286
  ctx.drawImage(bitmap, 0, 0, width, height);
24275
24287
  return new Promise((resolve) => {
24276
24288
  canvas.toBlob((blob) => resolve(blob), file.type, .9);
24289
+ canvas.remove();
24277
24290
  });
24278
24291
  }
24279
24292
  function getImageSizeFromFile(file) {
@@ -24329,7 +24342,9 @@ const downscaleImageFromURL = (url, options) => {
24329
24342
  canvas.height = height;
24330
24343
  const ctx = canvas.getContext("2d");
24331
24344
  ctx.drawImage(img, 0, 0, width, height);
24332
- resolve(canvas.toDataURL(type));
24345
+ const dataURL = canvas.toDataURL(type);
24346
+ canvas.remove();
24347
+ resolve(dataURL);
24333
24348
  };
24334
24349
  img.onerror = () => {
24335
24350
  reject(new Error("Invalid image", { cause: "InvalidImage" }));
@@ -24391,7 +24406,8 @@ var WeaveStageNode = class extends WeaveNode {
24391
24406
  globalEventsInitialized = false;
24392
24407
  initialize = void 0;
24393
24408
  onRender(props) {
24394
- const stage = new Konva.Stage({
24409
+ let stage = this.instance.getStage();
24410
+ if (!stage) stage = new Konva.Stage({
24395
24411
  ...props,
24396
24412
  mode: "default"
24397
24413
  });
@@ -26441,6 +26457,7 @@ const doPreloadCursors = async (cursorsToPreload, setCursor, getFallbackCursor,
26441
26457
  const ctx = canvas.getContext("2d");
26442
26458
  ctx?.drawImage(img, 0, 0);
26443
26459
  const dataURL = canvas.toDataURL("image/png");
26460
+ canvas.remove();
26444
26461
  const tokens = value.split(" ");
26445
26462
  tokens[0] = `url(${dataURL})`;
26446
26463
  setCursor(state, tokens.join(" "));
@@ -27801,7 +27818,7 @@ var WeaveFrameNode = class extends WeaveNode {
27801
27818
  strokeScaleEnabled: true,
27802
27819
  listening: true,
27803
27820
  draggable: false,
27804
- isTargetable: false
27821
+ canBeTargeted: false
27805
27822
  });
27806
27823
  frameInternal.clip({
27807
27824
  x: -(borderWidth / 2) * frameInternal.scaleX(),
@@ -28062,8 +28079,8 @@ var WeaveStrokeNode = class extends WeaveNode {
28062
28079
  const segLen = Math.hypot(dx, dy) || 1;
28063
28080
  const nx = -dy / segLen;
28064
28081
  const ny = dx / segLen;
28065
- const w0 = baseW * p0.pressure / 2;
28066
- const w1 = baseW * p1.pressure / 2;
28082
+ const w0 = Math.max(baseW * p0.pressure / 2, .5);
28083
+ const w1 = Math.max(baseW * p1.pressure / 2, .5);
28067
28084
  let traveled = 0;
28068
28085
  while (traveled < segLen) {
28069
28086
  const step = Math.min(dashRemaining, segLen - traveled);
@@ -29131,7 +29148,7 @@ var WeaveCommentNode = class extends WeaveNode {
29131
29148
  const commentNode = new Konva.Group({
29132
29149
  ...commentParams,
29133
29150
  name: "comment",
29134
- isTargetable: false,
29151
+ canBeTargeted: false,
29135
29152
  isExpanded: false,
29136
29153
  commentAction: null,
29137
29154
  listening: true,
@@ -29142,7 +29159,7 @@ var WeaveCommentNode = class extends WeaveNode {
29142
29159
  id: `${id}-bg`,
29143
29160
  x: 0,
29144
29161
  y: -heightContracted,
29145
- isTargetable: false,
29162
+ canBeTargeted: false,
29146
29163
  fill: commentParams.userBackgroundColor ?? "#0000FF",
29147
29164
  stroke: this.config.style.stroke,
29148
29165
  strokeWidth: this.config.style.strokeWidth,
@@ -34140,6 +34157,11 @@ const BRUSH_TOOL_DEFAULT_CONFIG = { interpolationSteps: 10 };
34140
34157
  var WeaveBrushToolAction = class extends WeaveAction {
34141
34158
  initialized = false;
34142
34159
  isSpacePressed = false;
34160
+ penActive = false;
34161
+ lastSmoothedPressure = .5;
34162
+ lastPointerPos = null;
34163
+ lastPointerTime = 0;
34164
+ predictedCount = 0;
34143
34165
  onPropsChange = void 0;
34144
34166
  onInit = void 0;
34145
34167
  constructor(params) {
@@ -34169,11 +34191,29 @@ var WeaveBrushToolAction = class extends WeaveAction {
34169
34191
  };
34170
34192
  }
34171
34193
  getEventPressure(e) {
34172
- if (e.evt.pointerType && e.evt.pointerType === "pen") return e.evt.pressure || .5;
34173
- return .5;
34194
+ const now$2 = performance.now();
34195
+ let velocity = 0;
34196
+ if (this.lastPointerPos && now$2 - this.lastPointerTime > 0) {
34197
+ const dx = e.evt.clientX - this.lastPointerPos.x;
34198
+ const dy = e.evt.clientY - this.lastPointerPos.y;
34199
+ velocity = Math.hypot(dx, dy) / (now$2 - this.lastPointerTime) * 1e3;
34200
+ }
34201
+ this.lastPointerPos = {
34202
+ x: e.evt.clientX,
34203
+ y: e.evt.clientY
34204
+ };
34205
+ this.lastPointerTime = now$2;
34206
+ const alpha = Math.min(Math.max(velocity / 1500, .15), .6);
34207
+ let raw;
34208
+ if (e.evt.pointerType === "pen") raw = e.evt.pressure || .5;
34209
+ else raw = .5;
34210
+ this.lastSmoothedPressure = alpha * raw + (1 - alpha) * this.lastSmoothedPressure;
34211
+ return Math.max(this.lastSmoothedPressure, .15);
34174
34212
  }
34175
34213
  setupEvents() {
34176
34214
  const stage = this.instance.getStage();
34215
+ this.prevTouchAction = stage.container().style.touchAction;
34216
+ stage.container().style.touchAction = "none";
34177
34217
  window.addEventListener("keyup", (e) => {
34178
34218
  if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.isSpacePressed = false;
34179
34219
  }, { signal: this.instance.getEventsController()?.signal });
@@ -34199,6 +34239,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
34199
34239
  if (this.getZoomPlugin()?.isPinching()) return;
34200
34240
  if (this.isSpacePressed) return;
34201
34241
  if (e?.evt?.button !== 0) return;
34242
+ if (e.evt.pointerType === "touch" && this.penActive) return;
34243
+ if (e.evt.pointerType === "pen") this.penActive = true;
34202
34244
  const pointPressure = this.getEventPressure(e);
34203
34245
  this.handleStartStroke(pointPressure);
34204
34246
  e.evt.stopPropagation();
@@ -34209,12 +34251,27 @@ var WeaveBrushToolAction = class extends WeaveAction {
34209
34251
  this.setCursor();
34210
34252
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34211
34253
  if (this.getZoomPlugin()?.isPinching()) return;
34212
- const pointPressure = this.getEventPressure(e);
34213
- this.handleMovement(pointPressure);
34254
+ const coalescedEvents = e.evt.getCoalescedEvents ? e.evt.getCoalescedEvents() : [];
34255
+ if (coalescedEvents.length > 1) {
34256
+ for (const ce of coalescedEvents) {
34257
+ const pointPressure = ce.pointerType === "pen" && typeof ce.pressure === "number" ? ce.pressure : .5;
34258
+ this.handleMovement(pointPressure, void 0, false);
34259
+ }
34260
+ const predictedEvents = e.evt.getPredictedEvents ? e.evt.getPredictedEvents() : [];
34261
+ if (predictedEvents.length > 0) {
34262
+ const last = predictedEvents[predictedEvents.length - 1];
34263
+ const predPressure = last.pointerType === "pen" && typeof last.pressure === "number" ? last.pressure : .5;
34264
+ this.handleMovement(predPressure, last, true);
34265
+ }
34266
+ } else {
34267
+ const pointPressure = this.getEventPressure(e);
34268
+ this.handleMovement(pointPressure, void 0, false);
34269
+ }
34214
34270
  e.evt.stopPropagation();
34215
34271
  };
34216
34272
  stage.on("pointermove", handlePointerMove);
34217
34273
  const handlePointerUp = (e) => {
34274
+ this.penActive = false;
34218
34275
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34219
34276
  if (this.getZoomPlugin()?.isPinching()) return;
34220
34277
  this.handleEndStroke();
@@ -34251,6 +34308,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
34251
34308
  };
34252
34309
  }
34253
34310
  handleStartStroke(pressure) {
34311
+ this.lastSmoothedPressure = .5;
34312
+ this.lastPointerPos = null;
34313
+ this.lastPointerTime = 0;
34314
+ this.predictedCount = 0;
34254
34315
  const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
34255
34316
  this.clickPoint = mousePoint;
34256
34317
  this.container = container;
@@ -34279,17 +34340,25 @@ var WeaveBrushToolAction = class extends WeaveAction {
34279
34340
  }
34280
34341
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
34281
34342
  }
34282
- handleMovement(pressure) {
34343
+ handleMovement(pressure, predictedEvent, isPredicted = false) {
34283
34344
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34345
+ const stage = this.instance.getStage();
34284
34346
  const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
34285
34347
  if (this.measureContainer && tempStroke) {
34348
+ if (predictedEvent) stage.setPointersPositions(predictedEvent);
34286
34349
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
34287
34350
  const currentPoint = {
34288
34351
  x: mousePoint.x - tempStroke.x(),
34289
34352
  y: mousePoint.y - tempStroke.y(),
34290
34353
  pressure
34291
34354
  };
34292
- const newStrokeElements = [...tempStroke.getAttrs().strokeElements, currentPoint];
34355
+ let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34356
+ if (!isPredicted && this.predictedCount > 0) {
34357
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34358
+ this.predictedCount = 0;
34359
+ }
34360
+ newStrokeElements.push(currentPoint);
34361
+ if (isPredicted) this.predictedCount++;
34293
34362
  const box = this.getBoundingBox(newStrokeElements);
34294
34363
  tempStroke.setAttrs({
34295
34364
  width: box.width,
@@ -34309,17 +34378,22 @@ var WeaveBrushToolAction = class extends WeaveAction {
34309
34378
  if (nodeHandler) {
34310
34379
  const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
34311
34380
  let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34381
+ if (this.predictedCount > 0) {
34382
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34383
+ this.predictedCount = 0;
34384
+ }
34312
34385
  newStrokeElements = newStrokeElements.map((point) => ({
34313
34386
  ...point,
34314
34387
  x: point.x - box.x,
34315
34388
  y: point.y - box.y
34316
34389
  }));
34390
+ const compressedPoints = simplify(newStrokeElements, 1, true);
34317
34391
  tempStroke.setAttrs({
34318
34392
  width: box.width,
34319
34393
  height: box.height,
34320
34394
  x: box.x,
34321
34395
  y: box.y,
34322
- strokeElements: newStrokeElements
34396
+ strokeElements: compressedPoints
34323
34397
  });
34324
34398
  const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
34325
34399
  if (realNode) realNode.destroy();
@@ -34355,6 +34429,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
34355
34429
  }
34356
34430
  cleanup() {
34357
34431
  const stage = this.instance.getStage();
34432
+ stage.container().style.touchAction = this.prevTouchAction;
34358
34433
  stage.container().style.cursor = "default";
34359
34434
  this.instance.emitEvent("onAddedBrush");
34360
34435
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -38670,7 +38745,9 @@ var WeaveStageMinimapPlugin = class extends WeavePlugin {
38670
38745
  skipStroke: true
38671
38746
  });
38672
38747
  if (box.width === 0 || box.height === 0) return;
38673
- const fitScale = Math.min(this.minimapStage.width() / box.width, this.minimapStage.height() / box.height);
38748
+ const width = this.minimapStage?.width();
38749
+ const height = this.minimapStage?.height();
38750
+ const fitScale = Math.min(width / box.width, height / box.height);
38674
38751
  const centerOffset = {
38675
38752
  x: (this.minimapStage.width() - box.width * fitScale) / 2,
38676
38753
  y: (this.minimapStage.height() - box.height * fitScale) / 2