@inditextech/weave-sdk 3.9.2 → 3.10.0

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/sdk.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
@@ -22075,7 +22076,7 @@ var WeaveRegisterManager = class {
22075
22076
 
22076
22077
  //#endregion
22077
22078
  //#region package.json
22078
- var version = "3.9.2";
22079
+ var version = "3.10.0";
22079
22080
 
22080
22081
  //#endregion
22081
22082
  //#region src/managers/setup.ts
@@ -28051,8 +28052,8 @@ var WeaveStrokeNode = class extends WeaveNode {
28051
28052
  const segLen = Math.hypot(dx, dy) || 1;
28052
28053
  const nx = -dy / segLen;
28053
28054
  const ny = dx / segLen;
28054
- const w0 = baseW * p0.pressure / 2;
28055
- const w1 = baseW * p1.pressure / 2;
28055
+ const w0 = Math.max(baseW * p0.pressure / 2, .5);
28056
+ const w1 = Math.max(baseW * p1.pressure / 2, .5);
28056
28057
  let traveled = 0;
28057
28058
  while (traveled < segLen) {
28058
28059
  const step = Math.min(dashRemaining, segLen - traveled);
@@ -34129,6 +34130,11 @@ const BRUSH_TOOL_DEFAULT_CONFIG = { interpolationSteps: 10 };
34129
34130
  var WeaveBrushToolAction = class extends WeaveAction {
34130
34131
  initialized = false;
34131
34132
  isSpacePressed = false;
34133
+ penActive = false;
34134
+ lastSmoothedPressure = .5;
34135
+ lastPointerPos = null;
34136
+ lastPointerTime = 0;
34137
+ predictedCount = 0;
34132
34138
  onPropsChange = void 0;
34133
34139
  onInit = void 0;
34134
34140
  constructor(params) {
@@ -34158,11 +34164,29 @@ var WeaveBrushToolAction = class extends WeaveAction {
34158
34164
  };
34159
34165
  }
34160
34166
  getEventPressure(e) {
34161
- if (e.evt.pointerType && e.evt.pointerType === "pen") return e.evt.pressure || .5;
34162
- return .5;
34167
+ const now$2 = performance.now();
34168
+ let velocity = 0;
34169
+ if (this.lastPointerPos && now$2 - this.lastPointerTime > 0) {
34170
+ const dx = e.evt.clientX - this.lastPointerPos.x;
34171
+ const dy = e.evt.clientY - this.lastPointerPos.y;
34172
+ velocity = Math.hypot(dx, dy) / (now$2 - this.lastPointerTime) * 1e3;
34173
+ }
34174
+ this.lastPointerPos = {
34175
+ x: e.evt.clientX,
34176
+ y: e.evt.clientY
34177
+ };
34178
+ this.lastPointerTime = now$2;
34179
+ const alpha = Math.min(Math.max(velocity / 1500, .15), .6);
34180
+ let raw;
34181
+ if (e.evt.pointerType === "pen") raw = e.evt.pressure || .5;
34182
+ else raw = .5;
34183
+ this.lastSmoothedPressure = alpha * raw + (1 - alpha) * this.lastSmoothedPressure;
34184
+ return Math.max(this.lastSmoothedPressure, .15);
34163
34185
  }
34164
34186
  setupEvents() {
34165
34187
  const stage = this.instance.getStage();
34188
+ this.prevTouchAction = stage.container().style.touchAction;
34189
+ stage.container().style.touchAction = "none";
34166
34190
  window.addEventListener("keyup", (e) => {
34167
34191
  if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.isSpacePressed = false;
34168
34192
  }, { signal: this.instance.getEventsController()?.signal });
@@ -34188,6 +34212,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
34188
34212
  if (this.getZoomPlugin()?.isPinching()) return;
34189
34213
  if (this.isSpacePressed) return;
34190
34214
  if (e?.evt?.button !== 0) return;
34215
+ if (e.evt.pointerType === "touch" && this.penActive) return;
34216
+ if (e.evt.pointerType === "pen") this.penActive = true;
34191
34217
  const pointPressure = this.getEventPressure(e);
34192
34218
  this.handleStartStroke(pointPressure);
34193
34219
  e.evt.stopPropagation();
@@ -34198,12 +34224,27 @@ var WeaveBrushToolAction = class extends WeaveAction {
34198
34224
  this.setCursor();
34199
34225
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34200
34226
  if (this.getZoomPlugin()?.isPinching()) return;
34201
- const pointPressure = this.getEventPressure(e);
34202
- this.handleMovement(pointPressure);
34227
+ const coalescedEvents = e.evt.getCoalescedEvents ? e.evt.getCoalescedEvents() : [];
34228
+ if (coalescedEvents.length > 1) {
34229
+ for (const ce of coalescedEvents) {
34230
+ const pointPressure = ce.pointerType === "pen" && typeof ce.pressure === "number" ? ce.pressure : .5;
34231
+ this.handleMovement(pointPressure, void 0, false);
34232
+ }
34233
+ const predictedEvents = e.evt.getPredictedEvents ? e.evt.getPredictedEvents() : [];
34234
+ if (predictedEvents.length > 0) {
34235
+ const last = predictedEvents[predictedEvents.length - 1];
34236
+ const predPressure = last.pointerType === "pen" && typeof last.pressure === "number" ? last.pressure : .5;
34237
+ this.handleMovement(predPressure, last, true);
34238
+ }
34239
+ } else {
34240
+ const pointPressure = this.getEventPressure(e);
34241
+ this.handleMovement(pointPressure, void 0, false);
34242
+ }
34203
34243
  e.evt.stopPropagation();
34204
34244
  };
34205
34245
  stage.on("pointermove", handlePointerMove);
34206
34246
  const handlePointerUp = (e) => {
34247
+ this.penActive = false;
34207
34248
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34208
34249
  if (this.getZoomPlugin()?.isPinching()) return;
34209
34250
  this.handleEndStroke();
@@ -34240,6 +34281,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
34240
34281
  };
34241
34282
  }
34242
34283
  handleStartStroke(pressure) {
34284
+ this.lastSmoothedPressure = .5;
34285
+ this.lastPointerPos = null;
34286
+ this.lastPointerTime = 0;
34287
+ this.predictedCount = 0;
34243
34288
  const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
34244
34289
  this.clickPoint = mousePoint;
34245
34290
  this.container = container;
@@ -34268,17 +34313,25 @@ var WeaveBrushToolAction = class extends WeaveAction {
34268
34313
  }
34269
34314
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
34270
34315
  }
34271
- handleMovement(pressure) {
34316
+ handleMovement(pressure, predictedEvent, isPredicted = false) {
34272
34317
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34318
+ const stage = this.instance.getStage();
34273
34319
  const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
34274
34320
  if (this.measureContainer && tempStroke) {
34321
+ if (predictedEvent) stage.setPointersPositions(predictedEvent);
34275
34322
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
34276
34323
  const currentPoint = {
34277
34324
  x: mousePoint.x - tempStroke.x(),
34278
34325
  y: mousePoint.y - tempStroke.y(),
34279
34326
  pressure
34280
34327
  };
34281
- const newStrokeElements = [...tempStroke.getAttrs().strokeElements, currentPoint];
34328
+ let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34329
+ if (!isPredicted && this.predictedCount > 0) {
34330
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34331
+ this.predictedCount = 0;
34332
+ }
34333
+ newStrokeElements.push(currentPoint);
34334
+ if (isPredicted) this.predictedCount++;
34282
34335
  const box = this.getBoundingBox(newStrokeElements);
34283
34336
  tempStroke.setAttrs({
34284
34337
  width: box.width,
@@ -34298,17 +34351,22 @@ var WeaveBrushToolAction = class extends WeaveAction {
34298
34351
  if (nodeHandler) {
34299
34352
  const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
34300
34353
  let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34354
+ if (this.predictedCount > 0) {
34355
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34356
+ this.predictedCount = 0;
34357
+ }
34301
34358
  newStrokeElements = newStrokeElements.map((point) => ({
34302
34359
  ...point,
34303
34360
  x: point.x - box.x,
34304
34361
  y: point.y - box.y
34305
34362
  }));
34363
+ const compressedPoints = simplify(newStrokeElements, 1, true);
34306
34364
  tempStroke.setAttrs({
34307
34365
  width: box.width,
34308
34366
  height: box.height,
34309
34367
  x: box.x,
34310
34368
  y: box.y,
34311
- strokeElements: newStrokeElements
34369
+ strokeElements: compressedPoints
34312
34370
  });
34313
34371
  const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
34314
34372
  if (realNode) realNode.destroy();
@@ -34344,6 +34402,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
34344
34402
  }
34345
34403
  cleanup() {
34346
34404
  const stage = this.instance.getStage();
34405
+ stage.container().style.touchAction = this.prevTouchAction;
34347
34406
  stage.container().style.cursor = "default";
34348
34407
  this.instance.emitEvent("onAddedBrush");
34349
34408
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
package/dist/sdk.node.js CHANGED
@@ -4,6 +4,7 @@ import pino from "pino";
4
4
  import { WEAVE_ASYNC_STATUS, WEAVE_AWARENESS_LAYER_ID, WEAVE_EXPORT_BACKGROUND_COLOR, WEAVE_EXPORT_FORMATS, WEAVE_EXPORT_RETURN_FORMAT, WEAVE_INSTANCE_STATUS, WEAVE_KONVA_BACKEND, WEAVE_LOG_LEVEL, WEAVE_NODE_CHANGE_TYPE, WEAVE_NODE_CUSTOM_EVENTS, WEAVE_NODE_LAYER_ID, WEAVE_NODE_POSITION, WEAVE_STORE_CONNECTION_STATUS, WEAVE_UTILITY_LAYER_ID } from "@inditextech/weave-types";
5
5
  import { getYjsDoc, getYjsValue, observeDeep, syncedStore } from "@syncedstore/core";
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
@@ -22074,7 +22075,7 @@ var WeaveRegisterManager = class {
22074
22075
 
22075
22076
  //#endregion
22076
22077
  //#region package.json
22077
- var version = "3.9.2";
22078
+ var version = "3.10.0";
22078
22079
 
22079
22080
  //#endregion
22080
22081
  //#region src/managers/setup.ts
@@ -28050,8 +28051,8 @@ var WeaveStrokeNode = class extends WeaveNode {
28050
28051
  const segLen = Math.hypot(dx, dy) || 1;
28051
28052
  const nx = -dy / segLen;
28052
28053
  const ny = dx / segLen;
28053
- const w0 = baseW * p0.pressure / 2;
28054
- const w1 = baseW * p1.pressure / 2;
28054
+ const w0 = Math.max(baseW * p0.pressure / 2, .5);
28055
+ const w1 = Math.max(baseW * p1.pressure / 2, .5);
28055
28056
  let traveled = 0;
28056
28057
  while (traveled < segLen) {
28057
28058
  const step = Math.min(dashRemaining, segLen - traveled);
@@ -34128,6 +34129,11 @@ const BRUSH_TOOL_DEFAULT_CONFIG = { interpolationSteps: 10 };
34128
34129
  var WeaveBrushToolAction = class extends WeaveAction {
34129
34130
  initialized = false;
34130
34131
  isSpacePressed = false;
34132
+ penActive = false;
34133
+ lastSmoothedPressure = .5;
34134
+ lastPointerPos = null;
34135
+ lastPointerTime = 0;
34136
+ predictedCount = 0;
34131
34137
  onPropsChange = void 0;
34132
34138
  onInit = void 0;
34133
34139
  constructor(params) {
@@ -34157,11 +34163,29 @@ var WeaveBrushToolAction = class extends WeaveAction {
34157
34163
  };
34158
34164
  }
34159
34165
  getEventPressure(e) {
34160
- if (e.evt.pointerType && e.evt.pointerType === "pen") return e.evt.pressure || .5;
34161
- return .5;
34166
+ const now$2 = performance.now();
34167
+ let velocity = 0;
34168
+ if (this.lastPointerPos && now$2 - this.lastPointerTime > 0) {
34169
+ const dx = e.evt.clientX - this.lastPointerPos.x;
34170
+ const dy = e.evt.clientY - this.lastPointerPos.y;
34171
+ velocity = Math.hypot(dx, dy) / (now$2 - this.lastPointerTime) * 1e3;
34172
+ }
34173
+ this.lastPointerPos = {
34174
+ x: e.evt.clientX,
34175
+ y: e.evt.clientY
34176
+ };
34177
+ this.lastPointerTime = now$2;
34178
+ const alpha = Math.min(Math.max(velocity / 1500, .15), .6);
34179
+ let raw;
34180
+ if (e.evt.pointerType === "pen") raw = e.evt.pressure || .5;
34181
+ else raw = .5;
34182
+ this.lastSmoothedPressure = alpha * raw + (1 - alpha) * this.lastSmoothedPressure;
34183
+ return Math.max(this.lastSmoothedPressure, .15);
34162
34184
  }
34163
34185
  setupEvents() {
34164
34186
  const stage = this.instance.getStage();
34187
+ this.prevTouchAction = stage.container().style.touchAction;
34188
+ stage.container().style.touchAction = "none";
34165
34189
  window.addEventListener("keyup", (e) => {
34166
34190
  if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.isSpacePressed = false;
34167
34191
  }, { signal: this.instance.getEventsController()?.signal });
@@ -34187,6 +34211,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
34187
34211
  if (this.getZoomPlugin()?.isPinching()) return;
34188
34212
  if (this.isSpacePressed) return;
34189
34213
  if (e?.evt?.button !== 0) return;
34214
+ if (e.evt.pointerType === "touch" && this.penActive) return;
34215
+ if (e.evt.pointerType === "pen") this.penActive = true;
34190
34216
  const pointPressure = this.getEventPressure(e);
34191
34217
  this.handleStartStroke(pointPressure);
34192
34218
  e.evt.stopPropagation();
@@ -34197,12 +34223,27 @@ var WeaveBrushToolAction = class extends WeaveAction {
34197
34223
  this.setCursor();
34198
34224
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34199
34225
  if (this.getZoomPlugin()?.isPinching()) return;
34200
- const pointPressure = this.getEventPressure(e);
34201
- this.handleMovement(pointPressure);
34226
+ const coalescedEvents = e.evt.getCoalescedEvents ? e.evt.getCoalescedEvents() : [];
34227
+ if (coalescedEvents.length > 1) {
34228
+ for (const ce of coalescedEvents) {
34229
+ const pointPressure = ce.pointerType === "pen" && typeof ce.pressure === "number" ? ce.pressure : .5;
34230
+ this.handleMovement(pointPressure, void 0, false);
34231
+ }
34232
+ const predictedEvents = e.evt.getPredictedEvents ? e.evt.getPredictedEvents() : [];
34233
+ if (predictedEvents.length > 0) {
34234
+ const last = predictedEvents[predictedEvents.length - 1];
34235
+ const predPressure = last.pointerType === "pen" && typeof last.pressure === "number" ? last.pressure : .5;
34236
+ this.handleMovement(predPressure, last, true);
34237
+ }
34238
+ } else {
34239
+ const pointPressure = this.getEventPressure(e);
34240
+ this.handleMovement(pointPressure, void 0, false);
34241
+ }
34202
34242
  e.evt.stopPropagation();
34203
34243
  };
34204
34244
  stage.on("pointermove", handlePointerMove);
34205
34245
  const handlePointerUp = (e) => {
34246
+ this.penActive = false;
34206
34247
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34207
34248
  if (this.getZoomPlugin()?.isPinching()) return;
34208
34249
  this.handleEndStroke();
@@ -34239,6 +34280,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
34239
34280
  };
34240
34281
  }
34241
34282
  handleStartStroke(pressure) {
34283
+ this.lastSmoothedPressure = .5;
34284
+ this.lastPointerPos = null;
34285
+ this.lastPointerTime = 0;
34286
+ this.predictedCount = 0;
34242
34287
  const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
34243
34288
  this.clickPoint = mousePoint;
34244
34289
  this.container = container;
@@ -34267,17 +34312,25 @@ var WeaveBrushToolAction = class extends WeaveAction {
34267
34312
  }
34268
34313
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
34269
34314
  }
34270
- handleMovement(pressure) {
34315
+ handleMovement(pressure, predictedEvent, isPredicted = false) {
34271
34316
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
34317
+ const stage = this.instance.getStage();
34272
34318
  const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
34273
34319
  if (this.measureContainer && tempStroke) {
34320
+ if (predictedEvent) stage.setPointersPositions(predictedEvent);
34274
34321
  const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
34275
34322
  const currentPoint = {
34276
34323
  x: mousePoint.x - tempStroke.x(),
34277
34324
  y: mousePoint.y - tempStroke.y(),
34278
34325
  pressure
34279
34326
  };
34280
- const newStrokeElements = [...tempStroke.getAttrs().strokeElements, currentPoint];
34327
+ let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34328
+ if (!isPredicted && this.predictedCount > 0) {
34329
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34330
+ this.predictedCount = 0;
34331
+ }
34332
+ newStrokeElements.push(currentPoint);
34333
+ if (isPredicted) this.predictedCount++;
34281
34334
  const box = this.getBoundingBox(newStrokeElements);
34282
34335
  tempStroke.setAttrs({
34283
34336
  width: box.width,
@@ -34297,17 +34350,22 @@ var WeaveBrushToolAction = class extends WeaveAction {
34297
34350
  if (nodeHandler) {
34298
34351
  const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
34299
34352
  let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
34353
+ if (this.predictedCount > 0) {
34354
+ newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
34355
+ this.predictedCount = 0;
34356
+ }
34300
34357
  newStrokeElements = newStrokeElements.map((point) => ({
34301
34358
  ...point,
34302
34359
  x: point.x - box.x,
34303
34360
  y: point.y - box.y
34304
34361
  }));
34362
+ const compressedPoints = simplify(newStrokeElements, 1, true);
34305
34363
  tempStroke.setAttrs({
34306
34364
  width: box.width,
34307
34365
  height: box.height,
34308
34366
  x: box.x,
34309
34367
  y: box.y,
34310
- strokeElements: newStrokeElements
34368
+ strokeElements: compressedPoints
34311
34369
  });
34312
34370
  const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
34313
34371
  if (realNode) realNode.destroy();
@@ -34343,6 +34401,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
34343
34401
  }
34344
34402
  cleanup() {
34345
34403
  const stage = this.instance.getStage();
34404
+ stage.container().style.touchAction = this.prevTouchAction;
34346
34405
  stage.container().style.cursor = "default";
34347
34406
  this.instance.emitEvent("onAddedBrush");
34348
34407
  const selectionPlugin = this.instance.getPlugin("nodesSelection");