@inditextech/weave-sdk 0.56.2 → 0.57.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.cjs +150 -169
- package/dist/sdk.d.cts +8 -13
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +8 -13
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +162 -182
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.cjs
CHANGED
|
@@ -21930,7 +21930,7 @@ var WeaveRegisterManager = class {
|
|
|
21930
21930
|
|
|
21931
21931
|
//#endregion
|
|
21932
21932
|
//#region package.json
|
|
21933
|
-
var version = "0.
|
|
21933
|
+
var version = "0.57.0";
|
|
21934
21934
|
|
|
21935
21935
|
//#endregion
|
|
21936
21936
|
//#region src/managers/setup.ts
|
|
@@ -25094,9 +25094,9 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
25094
25094
|
//#region src/nodes/stroke/constants.ts
|
|
25095
25095
|
const WEAVE_STROKE_NODE_TYPE = "stroke";
|
|
25096
25096
|
const WEAVE_STROKE_NODE_DEFAULT_CONFIG = {
|
|
25097
|
-
|
|
25097
|
+
splineResolution: 8,
|
|
25098
25098
|
resamplingSpacing: 2,
|
|
25099
|
-
|
|
25099
|
+
cachePixelRatio: 4
|
|
25100
25100
|
};
|
|
25101
25101
|
|
|
25102
25102
|
//#endregion
|
|
@@ -25108,143 +25108,147 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
25108
25108
|
const { config } = params ?? {};
|
|
25109
25109
|
this.config = (0, import_merge.default)(WEAVE_STROKE_NODE_DEFAULT_CONFIG, config);
|
|
25110
25110
|
}
|
|
25111
|
-
resamplePoints(pts,
|
|
25111
|
+
resamplePoints(pts, minDist = 2) {
|
|
25112
25112
|
if (pts.length < 2) return pts;
|
|
25113
|
-
const
|
|
25113
|
+
const result = [pts[0]];
|
|
25114
|
+
let last = pts[0];
|
|
25114
25115
|
for (let i = 1; i < pts.length; i++) {
|
|
25115
|
-
|
|
25116
|
-
const
|
|
25117
|
-
|
|
25118
|
-
|
|
25119
|
-
|
|
25120
|
-
|
|
25121
|
-
const t = spacing / segDist;
|
|
25122
|
-
const newPt = this.lerpPoint(last, current, t);
|
|
25123
|
-
resampled.push(newPt);
|
|
25124
|
-
last = newPt;
|
|
25125
|
-
remaining = this.dist(last, current);
|
|
25126
|
-
}
|
|
25127
|
-
}
|
|
25128
|
-
return resampled;
|
|
25129
|
-
}
|
|
25130
|
-
dist(a, b) {
|
|
25131
|
-
const dx = b.x - a.x, dy = b.y - a.y;
|
|
25132
|
-
return Math.hypot(dx, dy);
|
|
25133
|
-
}
|
|
25134
|
-
lerpPoint(a, b, t) {
|
|
25135
|
-
return {
|
|
25136
|
-
x: a.x + (b.x - a.x) * t,
|
|
25137
|
-
y: a.y + (b.y - a.y) * t,
|
|
25138
|
-
pressure: a.pressure + (b.pressure - a.pressure) * t
|
|
25139
|
-
};
|
|
25140
|
-
}
|
|
25141
|
-
buildPolygonFromPressure(pts, baseWidth) {
|
|
25142
|
-
if (pts.length < 2) return [];
|
|
25143
|
-
const left = [];
|
|
25144
|
-
const right = [];
|
|
25145
|
-
for (let i = 0; i < pts.length; i++) {
|
|
25146
|
-
const p = pts[i];
|
|
25147
|
-
const w = (baseWidth + p.pressure * this.config.pressureScale) / 2;
|
|
25148
|
-
let dx, dy;
|
|
25149
|
-
if (i === 0) {
|
|
25150
|
-
dx = pts[1].x - p.x;
|
|
25151
|
-
dy = pts[1].y - p.y;
|
|
25152
|
-
} else if (i === pts.length - 1) {
|
|
25153
|
-
dx = p.x - pts[i - 1].x;
|
|
25154
|
-
dy = p.y - pts[i - 1].y;
|
|
25155
|
-
} else {
|
|
25156
|
-
dx = pts[i + 1].x - pts[i - 1].x;
|
|
25157
|
-
dy = pts[i + 1].y - pts[i - 1].y;
|
|
25158
|
-
}
|
|
25159
|
-
const len = Math.hypot(dx, dy) || 1;
|
|
25160
|
-
const nx = -dy / len;
|
|
25161
|
-
const ny = dx / len;
|
|
25162
|
-
left.push({
|
|
25163
|
-
x: p.x + nx * w,
|
|
25164
|
-
y: p.y + ny * w
|
|
25165
|
-
});
|
|
25166
|
-
right.push({
|
|
25167
|
-
x: p.x - nx * w,
|
|
25168
|
-
y: p.y - ny * w
|
|
25169
|
-
});
|
|
25116
|
+
const dx = pts[i].x - last.x;
|
|
25117
|
+
const dy = pts[i].y - last.y;
|
|
25118
|
+
if (dx * dx + dy * dy >= minDist * minDist) {
|
|
25119
|
+
result.push(pts[i]);
|
|
25120
|
+
last = pts[i];
|
|
25121
|
+
}
|
|
25170
25122
|
}
|
|
25171
|
-
|
|
25172
|
-
return left.concat(reversed);
|
|
25123
|
+
return result;
|
|
25173
25124
|
}
|
|
25174
|
-
|
|
25175
|
-
const
|
|
25176
|
-
let
|
|
25177
|
-
|
|
25178
|
-
|
|
25179
|
-
|
|
25180
|
-
|
|
25181
|
-
let
|
|
25182
|
-
|
|
25183
|
-
const
|
|
25184
|
-
const
|
|
25185
|
-
|
|
25186
|
-
|
|
25187
|
-
|
|
25188
|
-
|
|
25189
|
-
|
|
25190
|
-
|
|
25191
|
-
|
|
25192
|
-
pts[i - 1] = mid;
|
|
25193
|
-
}
|
|
25194
|
-
segPts.push(pts[i]);
|
|
25195
|
-
patDist -= d;
|
|
25196
|
-
}
|
|
25197
|
-
if (draw && segPts.length > 1) segments.push(segPts);
|
|
25198
|
-
return segments;
|
|
25199
|
-
}
|
|
25200
|
-
catmullRomSpline(pts, spacing) {
|
|
25201
|
-
const curvePoints = [];
|
|
25202
|
-
for (let i = 0; i < pts.length - 1; i++) {
|
|
25203
|
-
const p0 = pts[i - 1] || pts[i];
|
|
25204
|
-
const p1 = pts[i];
|
|
25205
|
-
const p2 = pts[i + 1];
|
|
25206
|
-
const p3 = pts[i + 2] || p2;
|
|
25207
|
-
for (let t = 0; t < 1; t += spacing) {
|
|
25208
|
-
const t2 = t * t;
|
|
25209
|
-
const t3 = t2 * t;
|
|
25210
|
-
const x = .5 * (2 * p1.x + (-p0.x + p2.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3);
|
|
25211
|
-
const y = .5 * (2 * p1.y + (-p0.y + p2.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3);
|
|
25212
|
-
const pressure = .5 * (2 * p1.pressure + (-p0.pressure + p2.pressure) * t + (2 * p0.pressure - 5 * p1.pressure + 4 * p2.pressure - p3.pressure) * t2 + (-p0.pressure + 3 * p1.pressure - 3 * p2.pressure + p3.pressure) * t3);
|
|
25213
|
-
curvePoints.push({
|
|
25125
|
+
getSplinePoints(pts, resolution = 8) {
|
|
25126
|
+
const result = [];
|
|
25127
|
+
for (let i = -1; i < pts.length - 2; i++) {
|
|
25128
|
+
const p0 = pts[Math.max(i, 0)];
|
|
25129
|
+
const p1 = pts[i + 1];
|
|
25130
|
+
const p2 = pts[i + 2];
|
|
25131
|
+
const p3 = pts[Math.min(i + 3, pts.length - 1)];
|
|
25132
|
+
for (let t = 0; t < 1; t += 1 / resolution) {
|
|
25133
|
+
const tt = t * t;
|
|
25134
|
+
const ttt = tt * t;
|
|
25135
|
+
const q1 = -ttt + 2 * tt - t;
|
|
25136
|
+
const q2 = 3 * ttt - 5 * tt + 2;
|
|
25137
|
+
const q3 = -3 * ttt + 4 * tt + t;
|
|
25138
|
+
const q4 = ttt - tt;
|
|
25139
|
+
const x = (q1 * p0.x + q2 * p1.x + q3 * p2.x + q4 * p3.x) / 2;
|
|
25140
|
+
const y = (q1 * p0.y + q2 * p1.y + q3 * p2.y + q4 * p3.y) / 2;
|
|
25141
|
+
const pressure = (q1 * p0.pressure + q2 * p1.pressure + q3 * p2.pressure + q4 * p3.pressure) / 2;
|
|
25142
|
+
result.push({
|
|
25214
25143
|
x,
|
|
25215
25144
|
y,
|
|
25216
25145
|
pressure
|
|
25217
25146
|
});
|
|
25218
25147
|
}
|
|
25219
25148
|
}
|
|
25220
|
-
|
|
25149
|
+
result.push(pts[pts.length - 1]);
|
|
25150
|
+
return result;
|
|
25151
|
+
}
|
|
25152
|
+
drawRibbonWithDash(ctx, pts, baseW, color, dash) {
|
|
25153
|
+
if (pts.length < 2) return;
|
|
25154
|
+
const filtered = this.resamplePoints(pts, 2);
|
|
25155
|
+
const centerline = this.getSplinePoints(filtered, 8);
|
|
25156
|
+
let dashIndex = 0;
|
|
25157
|
+
let dashOn = true;
|
|
25158
|
+
let dashRemaining = dash.length ? dash[0] : Infinity;
|
|
25159
|
+
let leftSide = [];
|
|
25160
|
+
let rightSide = [];
|
|
25161
|
+
for (let i = 0; i < centerline.length - 1; i++) {
|
|
25162
|
+
const p0 = centerline[i];
|
|
25163
|
+
const p1 = centerline[i + 1];
|
|
25164
|
+
const dx = p1.x - p0.x;
|
|
25165
|
+
const dy = p1.y - p0.y;
|
|
25166
|
+
const segLen = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
25167
|
+
const nx = -dy / segLen;
|
|
25168
|
+
const ny = dx / segLen;
|
|
25169
|
+
const w0 = baseW * p0.pressure / 2;
|
|
25170
|
+
const w1 = baseW * p1.pressure / 2;
|
|
25171
|
+
let traveled = 0;
|
|
25172
|
+
while (traveled < segLen) {
|
|
25173
|
+
const step = Math.min(dashRemaining, segLen - traveled);
|
|
25174
|
+
const t0 = traveled / segLen;
|
|
25175
|
+
const t1 = (traveled + step) / segLen;
|
|
25176
|
+
const x0 = p0.x + dx * t0;
|
|
25177
|
+
const y0 = p0.y + dy * t0;
|
|
25178
|
+
const x1 = p0.x + dx * t1;
|
|
25179
|
+
const y1 = p0.y + dy * t1;
|
|
25180
|
+
const pw0 = w0 + (w1 - w0) * t0;
|
|
25181
|
+
const pw1 = w0 + (w1 - w0) * t1;
|
|
25182
|
+
if (dashOn) {
|
|
25183
|
+
leftSide.push({
|
|
25184
|
+
x: x0 + nx * pw0,
|
|
25185
|
+
y: y0 + ny * pw0,
|
|
25186
|
+
pressure: 1
|
|
25187
|
+
});
|
|
25188
|
+
rightSide.push({
|
|
25189
|
+
x: x0 - nx * pw0,
|
|
25190
|
+
y: y0 - ny * pw0,
|
|
25191
|
+
pressure: 1
|
|
25192
|
+
});
|
|
25193
|
+
leftSide.push({
|
|
25194
|
+
x: x1 + nx * pw1,
|
|
25195
|
+
y: y1 + ny * pw1,
|
|
25196
|
+
pressure: 1
|
|
25197
|
+
});
|
|
25198
|
+
rightSide.push({
|
|
25199
|
+
x: x1 - nx * pw1,
|
|
25200
|
+
y: y1 - ny * pw1,
|
|
25201
|
+
pressure: 1
|
|
25202
|
+
});
|
|
25203
|
+
}
|
|
25204
|
+
dashRemaining -= step;
|
|
25205
|
+
if (dashRemaining <= 0) {
|
|
25206
|
+
if (dashOn && leftSide.length && rightSide.length) {
|
|
25207
|
+
const smoothLeft = this.getSplinePoints(leftSide, 4);
|
|
25208
|
+
const smoothRight = this.getSplinePoints(rightSide.reverse(), 4);
|
|
25209
|
+
ctx.beginPath();
|
|
25210
|
+
ctx.fillStyle = color;
|
|
25211
|
+
ctx.moveTo(smoothLeft[0].x, smoothLeft[0].y);
|
|
25212
|
+
for (const p of smoothLeft) ctx.lineTo(p.x, p.y);
|
|
25213
|
+
for (const p of smoothRight) ctx.lineTo(p.x, p.y);
|
|
25214
|
+
ctx.closePath();
|
|
25215
|
+
ctx.fill();
|
|
25216
|
+
}
|
|
25217
|
+
leftSide = [];
|
|
25218
|
+
rightSide = [];
|
|
25219
|
+
dashOn = !dashOn;
|
|
25220
|
+
dashIndex = (dashIndex + 1) % dash.length;
|
|
25221
|
+
dashRemaining = dash[dashIndex];
|
|
25222
|
+
}
|
|
25223
|
+
traveled += step;
|
|
25224
|
+
}
|
|
25225
|
+
}
|
|
25226
|
+
if (dashOn && leftSide.length && rightSide.length) {
|
|
25227
|
+
const smoothLeft = this.getSplinePoints(leftSide, 4);
|
|
25228
|
+
const smoothRight = this.getSplinePoints(rightSide.reverse(), 4);
|
|
25229
|
+
ctx.beginPath();
|
|
25230
|
+
ctx.fillStyle = color;
|
|
25231
|
+
ctx.moveTo(smoothLeft[0].x, smoothLeft[0].y);
|
|
25232
|
+
for (const p of smoothLeft) ctx.lineTo(p.x, p.y);
|
|
25233
|
+
for (const p of smoothRight) ctx.lineTo(p.x, p.y);
|
|
25234
|
+
ctx.closePath();
|
|
25235
|
+
ctx.fill();
|
|
25236
|
+
}
|
|
25237
|
+
}
|
|
25238
|
+
drawShape(ctx, shape) {
|
|
25239
|
+
const strokeElements = shape.getAttrs().strokeElements;
|
|
25240
|
+
if (strokeElements.length === 0) return;
|
|
25241
|
+
const color = shape.getAttrs().stroke ?? "black";
|
|
25242
|
+
const strokeWidth = shape.getAttrs().strokeWidth ?? 1;
|
|
25243
|
+
const dash = shape.getAttrs().dash ?? [];
|
|
25244
|
+
this.drawRibbonWithDash(ctx, strokeElements, strokeWidth, color, dash);
|
|
25221
25245
|
}
|
|
25222
25246
|
onRender(props) {
|
|
25223
25247
|
const stroke = new konva.default.Shape({
|
|
25224
25248
|
...props,
|
|
25225
25249
|
name: "node",
|
|
25226
25250
|
sceneFunc: (ctx, shape) => {
|
|
25227
|
-
|
|
25228
|
-
if (strokeElements.length === 0) return;
|
|
25229
|
-
if (strokeElements.length < 2) return;
|
|
25230
|
-
const color = shape.getAttrs().stroke ?? "black";
|
|
25231
|
-
const strokeWidth = shape.getAttrs().strokeWidth ?? 1;
|
|
25232
|
-
const smoothPoints = this.catmullRomSpline(strokeElements, this.config.smoothingFactor);
|
|
25233
|
-
const evenlySpaced = this.resamplePoints(smoothPoints, this.config.resamplingSpacing);
|
|
25234
|
-
const dashes = this.dashSegments(evenlySpaced, shape.getAttrs().dash || []);
|
|
25235
|
-
dashes.forEach((segment) => {
|
|
25236
|
-
const poly = this.buildPolygonFromPressure(segment, strokeWidth);
|
|
25237
|
-
if (!poly.length) return;
|
|
25238
|
-
ctx.beginPath();
|
|
25239
|
-
ctx.moveTo(poly[0].x, poly[0].y);
|
|
25240
|
-
for (let i = 1; i < poly.length; i++) ctx.lineTo(poly[i].x, poly[i].y);
|
|
25241
|
-
ctx.strokeStyle = color;
|
|
25242
|
-
ctx.lineCap = shape.getAttrs().lineCap ?? "butt";
|
|
25243
|
-
ctx.lineJoin = shape.getAttrs().lineJoin ?? "miter";
|
|
25244
|
-
ctx.closePath();
|
|
25245
|
-
ctx.fillStyle = color;
|
|
25246
|
-
ctx.fill();
|
|
25247
|
-
});
|
|
25251
|
+
this.drawShape(ctx, shape);
|
|
25248
25252
|
},
|
|
25249
25253
|
dashEnabled: false,
|
|
25250
25254
|
hitFunc: (context, shape) => {
|
|
@@ -25254,6 +25258,7 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
25254
25258
|
context.fillStrokeShape(shape);
|
|
25255
25259
|
}
|
|
25256
25260
|
});
|
|
25261
|
+
if (props.cacheStroke) stroke.cache({ pixelRatio: this.config.cachePixelRatio });
|
|
25257
25262
|
this.setupDefaultNodeAugmentation(stroke);
|
|
25258
25263
|
const defaultTransformerProperties = this.defaultGetTransformerProperties(this.config.transform);
|
|
25259
25264
|
stroke.getTransformerProperties = function() {
|
|
@@ -25263,7 +25268,15 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
25263
25268
|
return stroke;
|
|
25264
25269
|
}
|
|
25265
25270
|
onUpdate(nodeInstance, nextProps) {
|
|
25271
|
+
const actAttrs = nodeInstance.getAttrs();
|
|
25272
|
+
if (actAttrs.stroke !== nextProps.stroke || actAttrs.strokeWidth !== nextProps.strokeWidth || actAttrs.dash !== nextProps.dash) nodeInstance.clearCache();
|
|
25266
25273
|
nodeInstance.setAttrs({ ...nextProps });
|
|
25274
|
+
if (nextProps.cacheStroke) {
|
|
25275
|
+
nodeInstance.sceneFunc((ctx, shape) => {
|
|
25276
|
+
this.drawShape(ctx, shape);
|
|
25277
|
+
});
|
|
25278
|
+
nodeInstance.cache({ pixelRatio: this.config.cachePixelRatio });
|
|
25279
|
+
}
|
|
25267
25280
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
25268
25281
|
if (nodesSelectionPlugin) nodesSelectionPlugin.getTransformer().forceUpdate();
|
|
25269
25282
|
}
|
|
@@ -26781,7 +26794,6 @@ const BRUSH_TOOL_DEFAULT_CONFIG = { interpolationSteps: 10 };
|
|
|
26781
26794
|
//#region src/actions/brush-tool/brush-tool.ts
|
|
26782
26795
|
var WeaveBrushToolAction = class extends WeaveAction {
|
|
26783
26796
|
initialized = false;
|
|
26784
|
-
rawPoints = [];
|
|
26785
26797
|
onPropsChange = void 0;
|
|
26786
26798
|
onInit = void 0;
|
|
26787
26799
|
constructor(params) {
|
|
@@ -26805,10 +26817,9 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26805
26817
|
opacity: 1
|
|
26806
26818
|
};
|
|
26807
26819
|
}
|
|
26808
|
-
|
|
26809
|
-
|
|
26810
|
-
|
|
26811
|
-
return pressure;
|
|
26820
|
+
getEventPressure(e) {
|
|
26821
|
+
if (e.evt.pointerType && e.evt.pointerType === "pen") return e.evt.pressure || .5;
|
|
26822
|
+
return .5;
|
|
26812
26823
|
}
|
|
26813
26824
|
setupEvents() {
|
|
26814
26825
|
const stage = this.instance.getStage();
|
|
@@ -26827,30 +26838,27 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26827
26838
|
const handlePointerDown = (e) => {
|
|
26828
26839
|
if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
|
|
26829
26840
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
26830
|
-
const pointPressure = this.
|
|
26841
|
+
const pointPressure = this.getEventPressure(e);
|
|
26831
26842
|
this.handleStartStroke(pointPressure);
|
|
26832
26843
|
e.evt.stopPropagation();
|
|
26833
26844
|
};
|
|
26834
|
-
|
|
26835
|
-
else stage.on("pointerdown", handlePointerDown);
|
|
26845
|
+
stage.on("pointerdown", handlePointerDown);
|
|
26836
26846
|
const handlePointerMove = (e) => {
|
|
26837
26847
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26838
26848
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
26839
26849
|
stage.container().style.cursor = "crosshair";
|
|
26840
|
-
const pointPressure = this.
|
|
26850
|
+
const pointPressure = this.getEventPressure(e);
|
|
26841
26851
|
this.handleMovement(pointPressure);
|
|
26842
26852
|
e.evt.stopPropagation();
|
|
26843
26853
|
};
|
|
26844
|
-
|
|
26845
|
-
else stage.on("pointermove", handlePointerMove);
|
|
26854
|
+
stage.on("pointermove", handlePointerMove);
|
|
26846
26855
|
const handlePointerUp = (e) => {
|
|
26847
26856
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26848
26857
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
26849
26858
|
this.handleEndStroke();
|
|
26850
26859
|
e.evt.stopPropagation();
|
|
26851
26860
|
};
|
|
26852
|
-
|
|
26853
|
-
else stage.on("pointerup", handlePointerUp);
|
|
26861
|
+
stage.on("pointerup", handlePointerUp);
|
|
26854
26862
|
this.initialized = true;
|
|
26855
26863
|
}
|
|
26856
26864
|
setState(state) {
|
|
@@ -26901,31 +26909,14 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26901
26909
|
y: 0,
|
|
26902
26910
|
width: 0,
|
|
26903
26911
|
height: 0,
|
|
26904
|
-
strokeElements: newStrokeElements
|
|
26912
|
+
strokeElements: newStrokeElements,
|
|
26913
|
+
cacheStroke: false
|
|
26905
26914
|
});
|
|
26906
26915
|
const nodeInstance = nodeHandler.onRender(node.props);
|
|
26907
26916
|
this.measureContainer?.add(nodeInstance);
|
|
26908
26917
|
}
|
|
26909
26918
|
this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
|
|
26910
26919
|
}
|
|
26911
|
-
catmullRom1D(p0, p1, p2, p3, t) {
|
|
26912
|
-
const t2 = t * t;
|
|
26913
|
-
const t3 = t2 * t;
|
|
26914
|
-
return .5 * (2 * p1 + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3);
|
|
26915
|
-
}
|
|
26916
|
-
smoothInterpolation(last4Points, steps) {
|
|
26917
|
-
const [p0, p1, p2, p3] = last4Points;
|
|
26918
|
-
const pts = [];
|
|
26919
|
-
for (let i = 0; i <= steps; i++) {
|
|
26920
|
-
const t = i / steps;
|
|
26921
|
-
pts.push({
|
|
26922
|
-
x: this.catmullRom1D(p0.x, p1.x, p2.x, p3.x, t),
|
|
26923
|
-
y: this.catmullRom1D(p0.y, p1.y, p2.y, p3.y, t),
|
|
26924
|
-
pressure: this.catmullRom1D(p0.pressure, p1.pressure, p2.pressure, p3.pressure, t)
|
|
26925
|
-
});
|
|
26926
|
-
}
|
|
26927
|
-
return pts;
|
|
26928
|
-
}
|
|
26929
26920
|
handleMovement(pressure) {
|
|
26930
26921
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26931
26922
|
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
@@ -26936,16 +26927,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26936
26927
|
y: mousePoint.y - tempStroke.y(),
|
|
26937
26928
|
pressure
|
|
26938
26929
|
};
|
|
26939
|
-
|
|
26940
|
-
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
26941
|
-
const smoothPoints = [];
|
|
26942
|
-
if (isIOS()) if (this.rawPoints.length >= 4) {
|
|
26943
|
-
const last4 = this.rawPoints.slice(-4);
|
|
26944
|
-
const interpolatedPts = this.smoothInterpolation(last4, this.config.interpolationSteps);
|
|
26945
|
-
smoothPoints.push(...interpolatedPts);
|
|
26946
|
-
} else smoothPoints.push(currentPoint);
|
|
26947
|
-
else smoothPoints.push(currentPoint);
|
|
26948
|
-
newStrokeElements = [...newStrokeElements, ...smoothPoints];
|
|
26930
|
+
const newStrokeElements = [...tempStroke.getAttrs().strokeElements, currentPoint];
|
|
26949
26931
|
const box = this.getBoundingBox(newStrokeElements);
|
|
26950
26932
|
tempStroke.setAttrs({
|
|
26951
26933
|
width: box.width,
|
|
@@ -26976,13 +26958,13 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26976
26958
|
height: box.height,
|
|
26977
26959
|
x: box.x,
|
|
26978
26960
|
y: box.y,
|
|
26979
|
-
strokeElements: newStrokeElements
|
|
26961
|
+
strokeElements: newStrokeElements,
|
|
26962
|
+
cacheStroke: true
|
|
26980
26963
|
});
|
|
26981
26964
|
const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
|
|
26982
26965
|
if (realNode) realNode.destroy();
|
|
26983
26966
|
if (tempStroke.getAttrs().strokeElements.length >= 3) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
26984
26967
|
}
|
|
26985
|
-
this.rawPoints = [];
|
|
26986
26968
|
this.clickPoint = null;
|
|
26987
26969
|
stage.container().style.cursor = "crosshair";
|
|
26988
26970
|
stage.container().tabIndex = 1;
|
|
@@ -27018,7 +27000,6 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
27018
27000
|
if (node) selectionPlugin.setSelectedNodes([node]);
|
|
27019
27001
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
27020
27002
|
}
|
|
27021
|
-
this.rawPoints = [];
|
|
27022
27003
|
this.clickPoint = null;
|
|
27023
27004
|
this.setState(BRUSH_TOOL_STATE.INACTIVE);
|
|
27024
27005
|
}
|
package/dist/sdk.d.cts
CHANGED
|
@@ -1327,9 +1327,9 @@ declare const WEAVE_FRAME_NODE_DEFAULT_PROPS: {
|
|
|
1327
1327
|
//#region src/nodes/stroke/types.d.ts
|
|
1328
1328
|
//# sourceMappingURL=constants.d.ts.map
|
|
1329
1329
|
type WeaveStrokeProperties = {
|
|
1330
|
-
|
|
1330
|
+
splineResolution: number;
|
|
1331
1331
|
resamplingSpacing: number;
|
|
1332
|
-
|
|
1332
|
+
cachePixelRatio: number;
|
|
1333
1333
|
transform?: WeaveNodeTransformerProperties;
|
|
1334
1334
|
};
|
|
1335
1335
|
type WeaveStrokeNodeParams = {
|
|
@@ -1349,11 +1349,9 @@ declare class WeaveStrokeNode extends WeaveNode {
|
|
|
1349
1349
|
protected nodeType: string;
|
|
1350
1350
|
constructor(params?: WeaveStrokeNodeParams);
|
|
1351
1351
|
private resamplePoints;
|
|
1352
|
-
private
|
|
1353
|
-
private
|
|
1354
|
-
private
|
|
1355
|
-
private dashSegments;
|
|
1356
|
-
private catmullRomSpline;
|
|
1352
|
+
private getSplinePoints;
|
|
1353
|
+
private drawRibbonWithDash;
|
|
1354
|
+
private drawShape;
|
|
1357
1355
|
onRender(props: WeaveElementAttributes): WeaveElementInstance;
|
|
1358
1356
|
onUpdate(nodeInstance: WeaveElementInstance, nextProps: WeaveElementAttributes): void;
|
|
1359
1357
|
scaleReset(node: Konva.Node): void;
|
|
@@ -1365,9 +1363,9 @@ declare class WeaveStrokeNode extends WeaveNode {
|
|
|
1365
1363
|
//# sourceMappingURL=stroke.d.ts.map
|
|
1366
1364
|
declare const WEAVE_STROKE_NODE_TYPE = "stroke";
|
|
1367
1365
|
declare const WEAVE_STROKE_NODE_DEFAULT_CONFIG: {
|
|
1368
|
-
|
|
1366
|
+
splineResolution: number;
|
|
1369
1367
|
resamplingSpacing: number;
|
|
1370
|
-
|
|
1368
|
+
cachePixelRatio: number;
|
|
1371
1369
|
};
|
|
1372
1370
|
|
|
1373
1371
|
//#endregion
|
|
@@ -1920,7 +1918,6 @@ declare class WeaveBrushToolAction extends WeaveAction {
|
|
|
1920
1918
|
protected container: Konva.Layer | Konva.Node | undefined;
|
|
1921
1919
|
protected measureContainer: Konva.Layer | Konva.Group | undefined;
|
|
1922
1920
|
protected cancelAction: () => void;
|
|
1923
|
-
protected rawPoints: WeaveStrokePoint[];
|
|
1924
1921
|
onPropsChange: undefined;
|
|
1925
1922
|
onInit: undefined;
|
|
1926
1923
|
constructor(params?: WeaveBrushToolActionParams);
|
|
@@ -1930,13 +1927,11 @@ declare class WeaveBrushToolAction extends WeaveAction {
|
|
|
1930
1927
|
strokeWidth: number;
|
|
1931
1928
|
opacity: number;
|
|
1932
1929
|
};
|
|
1933
|
-
private
|
|
1930
|
+
private getEventPressure;
|
|
1934
1931
|
private setupEvents;
|
|
1935
1932
|
private setState;
|
|
1936
1933
|
private getBoundingBox;
|
|
1937
1934
|
private handleStartStroke;
|
|
1938
|
-
private catmullRom1D;
|
|
1939
|
-
private smoothInterpolation;
|
|
1940
1935
|
private handleMovement;
|
|
1941
1936
|
private handleEndStroke;
|
|
1942
1937
|
trigger(cancel: () => void): void;
|