@inditextech/weave-sdk 0.55.2 → 0.56.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/sdk.cjs +215 -56
- package/dist/sdk.d.cts +31 -4
- package/dist/sdk.d.cts.map +1 -1
- package/dist/sdk.d.ts +31 -4
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +213 -57
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.js
CHANGED
|
@@ -18239,6 +18239,9 @@ function memoize(fn) {
|
|
|
18239
18239
|
return result;
|
|
18240
18240
|
};
|
|
18241
18241
|
}
|
|
18242
|
+
function isIOS() {
|
|
18243
|
+
return /iPad|iPhone|iPod/.test(navigator.userAgent) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
|
18244
|
+
}
|
|
18242
18245
|
|
|
18243
18246
|
//#endregion
|
|
18244
18247
|
//#region src/actions/selection-tool/constants.ts
|
|
@@ -19542,8 +19545,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19542
19545
|
let transformerAttrs = { ...this.config.selection };
|
|
19543
19546
|
const currentAttrs = this.tr.getAttrs();
|
|
19544
19547
|
Object.keys(currentAttrs).forEach((key) => {
|
|
19545
|
-
if (["rotationSnaps", "enabledAnchors"].includes(key)) this.tr
|
|
19546
|
-
else this.tr
|
|
19548
|
+
if (["rotationSnaps", "enabledAnchors"].includes(key)) this.tr?.setAttr(key, []);
|
|
19549
|
+
else this.tr?.setAttr(key, void 0);
|
|
19547
19550
|
});
|
|
19548
19551
|
if (nodesSelected === 1) {
|
|
19549
19552
|
transformerAttrs = (0, import_merge.default)(transformerAttrs, nodes[0].getTransformerProperties());
|
|
@@ -19554,8 +19557,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
19554
19557
|
for (const node of nodes) anchorsArrays.push(node.allowedAnchors());
|
|
19555
19558
|
transformerAttrs.enabledAnchors = intersectArrays(anchorsArrays);
|
|
19556
19559
|
}
|
|
19557
|
-
this.tr
|
|
19558
|
-
this.tr
|
|
19560
|
+
this.tr?.setAttrs(transformerAttrs);
|
|
19561
|
+
this.tr?.forceUpdate();
|
|
19559
19562
|
}
|
|
19560
19563
|
setSelectedNodes(nodes) {
|
|
19561
19564
|
this.tr.setNodes(nodes);
|
|
@@ -19732,7 +19735,6 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
19732
19735
|
});
|
|
19733
19736
|
if (catcher) {
|
|
19734
19737
|
document.addEventListener("paste", async (e) => {
|
|
19735
|
-
e.preventDefault();
|
|
19736
19738
|
const dataList = e.clipboardData?.items;
|
|
19737
19739
|
if (!dataList) return;
|
|
19738
19740
|
if (dataList?.length > 0) this.sendExternalPasteEvent(dataList);
|
|
@@ -20599,15 +20601,15 @@ var WeaveReconciler = class {
|
|
|
20599
20601
|
child,
|
|
20600
20602
|
beforeChild
|
|
20601
20603
|
}, "insertBefore ");
|
|
20602
|
-
if (parentInstance instanceof Konva.Layer) {
|
|
20603
|
-
parentInstance.
|
|
20604
|
-
const
|
|
20605
|
-
|
|
20606
|
-
|
|
20607
|
-
|
|
20608
|
-
|
|
20609
|
-
|
|
20610
|
-
|
|
20604
|
+
if (parentInstance instanceof Konva.Layer || parentInstance instanceof Konva.Group) {
|
|
20605
|
+
const children = parentInstance.getChildren();
|
|
20606
|
+
const fromIndex = children.indexOf(child);
|
|
20607
|
+
const toIndex = children.indexOf(beforeChild);
|
|
20608
|
+
if (fromIndex === -1 || toIndex === -1) return;
|
|
20609
|
+
children.splice(fromIndex, 1);
|
|
20610
|
+
const adjustedIndex = fromIndex < toIndex ? toIndex - 1 : toIndex;
|
|
20611
|
+
parentInstance.getChildren().splice(adjustedIndex, 0, child);
|
|
20612
|
+
parentInstance.children = parentInstance.getChildren();
|
|
20611
20613
|
}
|
|
20612
20614
|
},
|
|
20613
20615
|
appendChild(parentInstance, child) {
|
|
@@ -21565,7 +21567,6 @@ var WeaveZIndexManager = class {
|
|
|
21565
21567
|
}
|
|
21566
21568
|
moveUp(instance) {
|
|
21567
21569
|
this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], up one step of z-index`);
|
|
21568
|
-
instance.moveUp();
|
|
21569
21570
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
21570
21571
|
if (handler) {
|
|
21571
21572
|
const nodeState = handler.serialize(instance);
|
|
@@ -21574,7 +21575,6 @@ var WeaveZIndexManager = class {
|
|
|
21574
21575
|
}
|
|
21575
21576
|
moveDown(instance) {
|
|
21576
21577
|
this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], down one step of z-index`);
|
|
21577
|
-
instance.moveDown();
|
|
21578
21578
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
21579
21579
|
if (handler) {
|
|
21580
21580
|
const nodeState = handler.serialize(instance);
|
|
@@ -21585,7 +21585,6 @@ var WeaveZIndexManager = class {
|
|
|
21585
21585
|
const nodes = Array.isArray(instances) ? instances : [instances];
|
|
21586
21586
|
const nodesDescending = nodes.toSorted((a, b) => b.zIndex() - a.zIndex());
|
|
21587
21587
|
for (const node of nodesDescending) {
|
|
21588
|
-
node.moveToBottom();
|
|
21589
21588
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
21590
21589
|
if (handler) {
|
|
21591
21590
|
const nodeState = handler.serialize(node);
|
|
@@ -21597,7 +21596,6 @@ var WeaveZIndexManager = class {
|
|
|
21597
21596
|
const nodes = Array.isArray(instances) ? instances : [instances];
|
|
21598
21597
|
const nodesAscending = nodes.toSorted((a, b) => a.zIndex() - b.zIndex());
|
|
21599
21598
|
for (const node of nodesAscending) {
|
|
21600
|
-
node.moveToTop();
|
|
21601
21599
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
21602
21600
|
if (handler) {
|
|
21603
21601
|
const nodeState = handler.serialize(node);
|
|
@@ -21924,7 +21922,7 @@ var WeaveRegisterManager = class {
|
|
|
21924
21922
|
|
|
21925
21923
|
//#endregion
|
|
21926
21924
|
//#region package.json
|
|
21927
|
-
var version = "0.
|
|
21925
|
+
var version = "0.56.1";
|
|
21928
21926
|
|
|
21929
21927
|
//#endregion
|
|
21930
21928
|
//#region src/managers/setup.ts
|
|
@@ -22152,6 +22150,23 @@ var WeaveExportManager = class {
|
|
|
22152
22150
|
this.logger = this.instance.getChildLogger("export-manager");
|
|
22153
22151
|
this.logger.debug("Export manager created");
|
|
22154
22152
|
}
|
|
22153
|
+
fitKonvaPixelRatio(sw, sh, targetPR = 1, maxArea = 16777216) {
|
|
22154
|
+
if (sw <= 0 || sh <= 0) return {
|
|
22155
|
+
pixelRatio: 0,
|
|
22156
|
+
outW: 0,
|
|
22157
|
+
outH: 0
|
|
22158
|
+
};
|
|
22159
|
+
const desiredArea = sw * sh * targetPR * targetPR;
|
|
22160
|
+
let pr = targetPR;
|
|
22161
|
+
if (desiredArea > maxArea) pr = Math.sqrt(maxArea / (sw * sh));
|
|
22162
|
+
const outW = Math.max(1, Math.floor(sw * pr));
|
|
22163
|
+
const outH = Math.max(1, Math.floor(sh * pr));
|
|
22164
|
+
return {
|
|
22165
|
+
pixelRatio: pr,
|
|
22166
|
+
outW,
|
|
22167
|
+
outH
|
|
22168
|
+
};
|
|
22169
|
+
}
|
|
22155
22170
|
exportNodes(nodes, boundingNodes, options) {
|
|
22156
22171
|
return new Promise((resolve) => {
|
|
22157
22172
|
const { format: format$2 = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
|
|
@@ -22205,13 +22220,14 @@ var WeaveExportManager = class {
|
|
|
22205
22220
|
mainLayer.add(exportGroup);
|
|
22206
22221
|
const backgroundRect = background.getClientRect();
|
|
22207
22222
|
stage.batchDraw();
|
|
22223
|
+
const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
|
|
22208
22224
|
exportGroup.toImage({
|
|
22209
22225
|
x: Math.round(backgroundRect.x),
|
|
22210
22226
|
y: Math.round(backgroundRect.y),
|
|
22211
22227
|
width: Math.round(backgroundRect.width),
|
|
22212
22228
|
height: Math.round(backgroundRect.height),
|
|
22213
22229
|
mimeType: format$2,
|
|
22214
|
-
pixelRatio,
|
|
22230
|
+
pixelRatio: finalPixelRatio,
|
|
22215
22231
|
quality: options.quality ?? 1,
|
|
22216
22232
|
callback: (img) => {
|
|
22217
22233
|
exportGroup.destroy();
|
|
@@ -25069,6 +25085,11 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
25069
25085
|
//#endregion
|
|
25070
25086
|
//#region src/nodes/stroke/constants.ts
|
|
25071
25087
|
const WEAVE_STROKE_NODE_TYPE = "stroke";
|
|
25088
|
+
const WEAVE_STROKE_NODE_DEFAULT_CONFIG = {
|
|
25089
|
+
smoothingFactor: .1,
|
|
25090
|
+
resamplingSpacing: 2,
|
|
25091
|
+
pressureScale: 1
|
|
25092
|
+
};
|
|
25072
25093
|
|
|
25073
25094
|
//#endregion
|
|
25074
25095
|
//#region src/nodes/stroke/stroke.ts
|
|
@@ -25077,45 +25098,145 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
25077
25098
|
constructor(params) {
|
|
25078
25099
|
super();
|
|
25079
25100
|
const { config } = params ?? {};
|
|
25080
|
-
this.config =
|
|
25101
|
+
this.config = (0, import_merge.default)(WEAVE_STROKE_NODE_DEFAULT_CONFIG, config);
|
|
25102
|
+
}
|
|
25103
|
+
resamplePoints(pts, spacing) {
|
|
25104
|
+
if (pts.length < 2) return pts;
|
|
25105
|
+
const resampled = [pts[0]];
|
|
25106
|
+
for (let i = 1; i < pts.length; i++) {
|
|
25107
|
+
let last = resampled[resampled.length - 1];
|
|
25108
|
+
const current = pts[i];
|
|
25109
|
+
const segDist = this.dist(last, current);
|
|
25110
|
+
if (segDist === 0) continue;
|
|
25111
|
+
let remaining = segDist;
|
|
25112
|
+
while (remaining >= spacing) {
|
|
25113
|
+
const t = spacing / segDist;
|
|
25114
|
+
const newPt = this.lerpPoint(last, current, t);
|
|
25115
|
+
resampled.push(newPt);
|
|
25116
|
+
last = newPt;
|
|
25117
|
+
remaining = this.dist(last, current);
|
|
25118
|
+
}
|
|
25119
|
+
}
|
|
25120
|
+
return resampled;
|
|
25121
|
+
}
|
|
25122
|
+
dist(a, b) {
|
|
25123
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
25124
|
+
return Math.hypot(dx, dy);
|
|
25081
25125
|
}
|
|
25082
|
-
|
|
25083
|
-
|
|
25084
|
-
|
|
25085
|
-
|
|
25086
|
-
|
|
25087
|
-
|
|
25088
|
-
|
|
25089
|
-
|
|
25090
|
-
|
|
25091
|
-
|
|
25092
|
-
|
|
25093
|
-
|
|
25094
|
-
const
|
|
25095
|
-
|
|
25096
|
-
|
|
25126
|
+
lerpPoint(a, b, t) {
|
|
25127
|
+
return {
|
|
25128
|
+
x: a.x + (b.x - a.x) * t,
|
|
25129
|
+
y: a.y + (b.y - a.y) * t,
|
|
25130
|
+
pressure: a.pressure + (b.pressure - a.pressure) * t
|
|
25131
|
+
};
|
|
25132
|
+
}
|
|
25133
|
+
buildPolygonFromPressure(pts, baseWidth) {
|
|
25134
|
+
if (pts.length < 2) return [];
|
|
25135
|
+
const left = [];
|
|
25136
|
+
const right = [];
|
|
25137
|
+
for (let i = 0; i < pts.length; i++) {
|
|
25138
|
+
const p = pts[i];
|
|
25139
|
+
const w = (baseWidth + p.pressure * this.config.pressureScale) / 2;
|
|
25140
|
+
let dx, dy;
|
|
25141
|
+
if (i === 0) {
|
|
25142
|
+
dx = pts[1].x - p.x;
|
|
25143
|
+
dy = pts[1].y - p.y;
|
|
25144
|
+
} else if (i === pts.length - 1) {
|
|
25145
|
+
dx = p.x - pts[i - 1].x;
|
|
25146
|
+
dy = p.y - pts[i - 1].y;
|
|
25147
|
+
} else {
|
|
25148
|
+
dx = pts[i + 1].x - pts[i - 1].x;
|
|
25149
|
+
dy = pts[i + 1].y - pts[i - 1].y;
|
|
25150
|
+
}
|
|
25151
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
25152
|
+
const nx = -dy / len;
|
|
25153
|
+
const ny = dx / len;
|
|
25154
|
+
left.push({
|
|
25155
|
+
x: p.x + nx * w,
|
|
25156
|
+
y: p.y + ny * w
|
|
25157
|
+
});
|
|
25158
|
+
right.push({
|
|
25159
|
+
x: p.x - nx * w,
|
|
25160
|
+
y: p.y - ny * w
|
|
25161
|
+
});
|
|
25162
|
+
}
|
|
25163
|
+
const reversed = right.toReversed();
|
|
25164
|
+
return left.concat(reversed);
|
|
25165
|
+
}
|
|
25166
|
+
dashSegments(pts, pattern) {
|
|
25167
|
+
const segments = [];
|
|
25168
|
+
let patIndex = 0;
|
|
25169
|
+
let patDist = pattern[patIndex];
|
|
25170
|
+
let draw = true;
|
|
25171
|
+
let segPts = [pts[0]];
|
|
25172
|
+
for (let i = 1; i < pts.length; i++) {
|
|
25173
|
+
let d = this.dist(pts[i - 1], pts[i]);
|
|
25174
|
+
while (d >= patDist) {
|
|
25175
|
+
const t = patDist / d;
|
|
25176
|
+
const mid = this.lerpPoint(pts[i - 1], pts[i], t);
|
|
25177
|
+
segPts.push(mid);
|
|
25178
|
+
if (draw) segments.push(segPts);
|
|
25179
|
+
draw = !draw;
|
|
25180
|
+
patIndex = (patIndex + 1) % pattern.length;
|
|
25181
|
+
patDist = pattern[patIndex];
|
|
25182
|
+
segPts = [mid];
|
|
25183
|
+
d -= patDist;
|
|
25184
|
+
pts[i - 1] = mid;
|
|
25185
|
+
}
|
|
25186
|
+
segPts.push(pts[i]);
|
|
25187
|
+
patDist -= d;
|
|
25188
|
+
}
|
|
25189
|
+
if (draw && segPts.length > 1) segments.push(segPts);
|
|
25190
|
+
return segments;
|
|
25191
|
+
}
|
|
25192
|
+
catmullRomSpline(pts, spacing) {
|
|
25193
|
+
const curvePoints = [];
|
|
25194
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
25195
|
+
const p0 = pts[i - 1] || pts[i];
|
|
25196
|
+
const p1 = pts[i];
|
|
25197
|
+
const p2 = pts[i + 1];
|
|
25198
|
+
const p3 = pts[i + 2] || p2;
|
|
25199
|
+
for (let t = 0; t < 1; t += spacing) {
|
|
25200
|
+
const t2 = t * t;
|
|
25201
|
+
const t3 = t2 * t;
|
|
25202
|
+
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);
|
|
25203
|
+
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);
|
|
25204
|
+
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);
|
|
25205
|
+
curvePoints.push({
|
|
25206
|
+
x,
|
|
25207
|
+
y,
|
|
25208
|
+
pressure
|
|
25209
|
+
});
|
|
25210
|
+
}
|
|
25097
25211
|
}
|
|
25212
|
+
return curvePoints;
|
|
25098
25213
|
}
|
|
25099
25214
|
onRender(props) {
|
|
25100
25215
|
const stroke = new Konva.Shape({
|
|
25101
25216
|
...props,
|
|
25102
25217
|
name: "node",
|
|
25103
|
-
sceneFunc: (
|
|
25104
|
-
context.beginPath();
|
|
25105
|
-
context.strokeStyle = shape.getAttrs().stroke ?? "black";
|
|
25106
|
-
context.setLineDash(shape.getAttrs().dash || []);
|
|
25107
|
-
context.lineCap = shape.getAttrs().lineCap ?? "round";
|
|
25108
|
-
context.lineJoin = shape.getAttrs().lineJoin ?? "round";
|
|
25218
|
+
sceneFunc: (ctx, shape) => {
|
|
25109
25219
|
const strokeElements = shape.getAttrs().strokeElements;
|
|
25110
25220
|
if (strokeElements.length === 0) return;
|
|
25111
|
-
|
|
25112
|
-
|
|
25113
|
-
const
|
|
25114
|
-
strokeElements.
|
|
25115
|
-
|
|
25116
|
-
|
|
25221
|
+
if (strokeElements.length < 2) return;
|
|
25222
|
+
const color = shape.getAttrs().stroke ?? "black";
|
|
25223
|
+
const strokeWidth = shape.getAttrs().strokeWidth ?? 1;
|
|
25224
|
+
const smoothPoints = this.catmullRomSpline(strokeElements, this.config.smoothingFactor);
|
|
25225
|
+
const evenlySpaced = this.resamplePoints(smoothPoints, this.config.resamplingSpacing);
|
|
25226
|
+
const dashes = this.dashSegments(evenlySpaced, shape.getAttrs().dash || []);
|
|
25227
|
+
dashes.forEach((segment) => {
|
|
25228
|
+
const poly = this.buildPolygonFromPressure(segment, strokeWidth);
|
|
25229
|
+
if (!poly.length) return;
|
|
25230
|
+
ctx.beginPath();
|
|
25231
|
+
ctx.moveTo(poly[0].x, poly[0].y);
|
|
25232
|
+
for (let i = 1; i < poly.length; i++) ctx.lineTo(poly[i].x, poly[i].y);
|
|
25233
|
+
ctx.strokeStyle = color;
|
|
25234
|
+
ctx.lineCap = shape.getAttrs().lineCap ?? "butt";
|
|
25235
|
+
ctx.lineJoin = shape.getAttrs().lineJoin ?? "miter";
|
|
25236
|
+
ctx.closePath();
|
|
25237
|
+
ctx.fillStyle = color;
|
|
25238
|
+
ctx.fill();
|
|
25117
25239
|
});
|
|
25118
|
-
context.strokeShape(shape);
|
|
25119
25240
|
},
|
|
25120
25241
|
dashEnabled: false,
|
|
25121
25242
|
hitFunc: (context, shape) => {
|
|
@@ -26646,15 +26767,18 @@ const BRUSH_TOOL_STATE = {
|
|
|
26646
26767
|
["IDLE"]: "idle",
|
|
26647
26768
|
["DEFINE_STROKE"]: "defineStroke"
|
|
26648
26769
|
};
|
|
26770
|
+
const BRUSH_TOOL_DEFAULT_CONFIG = { interpolationSteps: 10 };
|
|
26649
26771
|
|
|
26650
26772
|
//#endregion
|
|
26651
26773
|
//#region src/actions/brush-tool/brush-tool.ts
|
|
26652
26774
|
var WeaveBrushToolAction = class extends WeaveAction {
|
|
26653
26775
|
initialized = false;
|
|
26776
|
+
rawPoints = [];
|
|
26654
26777
|
onPropsChange = void 0;
|
|
26655
26778
|
onInit = void 0;
|
|
26656
|
-
constructor() {
|
|
26779
|
+
constructor(params) {
|
|
26657
26780
|
super();
|
|
26781
|
+
this.config = (0, import_merge.default)(BRUSH_TOOL_DEFAULT_CONFIG, params?.config ?? {});
|
|
26658
26782
|
this.initialized = false;
|
|
26659
26783
|
this.state = BRUSH_TOOL_STATE.INACTIVE;
|
|
26660
26784
|
this.strokeId = null;
|
|
@@ -26699,7 +26823,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26699
26823
|
this.handleStartStroke(pointPressure);
|
|
26700
26824
|
e.evt.stopPropagation();
|
|
26701
26825
|
};
|
|
26702
|
-
stage.on("
|
|
26826
|
+
if (isIOS()) stage.on("touchstart", handlePointerDown);
|
|
26827
|
+
else stage.on("pointerdown", handlePointerDown);
|
|
26703
26828
|
const handlePointerMove = (e) => {
|
|
26704
26829
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26705
26830
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
@@ -26708,14 +26833,16 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26708
26833
|
this.handleMovement(pointPressure);
|
|
26709
26834
|
e.evt.stopPropagation();
|
|
26710
26835
|
};
|
|
26711
|
-
stage.on("
|
|
26836
|
+
if (isIOS()) stage.on("touchmove", handlePointerMove);
|
|
26837
|
+
else stage.on("pointermove", handlePointerMove);
|
|
26712
26838
|
const handlePointerUp = (e) => {
|
|
26713
26839
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26714
26840
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
26715
26841
|
this.handleEndStroke();
|
|
26716
26842
|
e.evt.stopPropagation();
|
|
26717
26843
|
};
|
|
26718
|
-
stage.on("
|
|
26844
|
+
if (isIOS()) stage.on("touchend", handlePointerUp);
|
|
26845
|
+
else stage.on("pointerup", handlePointerUp);
|
|
26719
26846
|
this.initialized = true;
|
|
26720
26847
|
}
|
|
26721
26848
|
setState(state) {
|
|
@@ -26773,17 +26900,44 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26773
26900
|
}
|
|
26774
26901
|
this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
|
|
26775
26902
|
}
|
|
26903
|
+
catmullRom1D(p0, p1, p2, p3, t) {
|
|
26904
|
+
const t2 = t * t;
|
|
26905
|
+
const t3 = t2 * t;
|
|
26906
|
+
return .5 * (2 * p1 + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3);
|
|
26907
|
+
}
|
|
26908
|
+
smoothInterpolation(last4Points, steps) {
|
|
26909
|
+
const [p0, p1, p2, p3] = last4Points;
|
|
26910
|
+
const pts = [];
|
|
26911
|
+
for (let i = 0; i <= steps; i++) {
|
|
26912
|
+
const t = i / steps;
|
|
26913
|
+
pts.push({
|
|
26914
|
+
x: this.catmullRom1D(p0.x, p1.x, p2.x, p3.x, t),
|
|
26915
|
+
y: this.catmullRom1D(p0.y, p1.y, p2.y, p3.y, t),
|
|
26916
|
+
pressure: this.catmullRom1D(p0.pressure, p1.pressure, p2.pressure, p3.pressure, t)
|
|
26917
|
+
});
|
|
26918
|
+
}
|
|
26919
|
+
return pts;
|
|
26920
|
+
}
|
|
26776
26921
|
handleMovement(pressure) {
|
|
26777
26922
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
26778
26923
|
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
26779
26924
|
if (this.measureContainer && tempStroke) {
|
|
26780
26925
|
const { mousePoint } = this.instance.getMousePointerRelativeToContainer(this.measureContainer);
|
|
26781
|
-
const
|
|
26782
|
-
newStrokeElements.push({
|
|
26926
|
+
const currentPoint = {
|
|
26783
26927
|
x: mousePoint.x - tempStroke.x(),
|
|
26784
26928
|
y: mousePoint.y - tempStroke.y(),
|
|
26785
26929
|
pressure
|
|
26786
|
-
}
|
|
26930
|
+
};
|
|
26931
|
+
this.rawPoints.push(currentPoint);
|
|
26932
|
+
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
26933
|
+
const smoothPoints = [];
|
|
26934
|
+
if (isIOS()) if (this.rawPoints.length >= 4) {
|
|
26935
|
+
const last4 = this.rawPoints.slice(-4);
|
|
26936
|
+
const interpolatedPts = this.smoothInterpolation(last4, this.config.interpolationSteps);
|
|
26937
|
+
smoothPoints.push(...interpolatedPts);
|
|
26938
|
+
} else smoothPoints.push(currentPoint);
|
|
26939
|
+
else smoothPoints.push(currentPoint);
|
|
26940
|
+
newStrokeElements = [...newStrokeElements, ...smoothPoints];
|
|
26787
26941
|
const box = this.getBoundingBox(newStrokeElements);
|
|
26788
26942
|
tempStroke.setAttrs({
|
|
26789
26943
|
width: box.width,
|
|
@@ -26820,6 +26974,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26820
26974
|
if (realNode) realNode.destroy();
|
|
26821
26975
|
if (tempStroke.getAttrs().strokeElements.length >= 3) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
26822
26976
|
}
|
|
26977
|
+
this.rawPoints = [];
|
|
26823
26978
|
this.clickPoint = null;
|
|
26824
26979
|
stage.container().style.cursor = "crosshair";
|
|
26825
26980
|
stage.container().tabIndex = 1;
|
|
@@ -26855,6 +27010,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
26855
27010
|
if (node) selectionPlugin.setSelectedNodes([node]);
|
|
26856
27011
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
26857
27012
|
}
|
|
27013
|
+
this.rawPoints = [];
|
|
26858
27014
|
this.clickPoint = null;
|
|
26859
27015
|
this.setState(BRUSH_TOOL_STATE.INACTIVE);
|
|
26860
27016
|
}
|
|
@@ -29852,5 +30008,5 @@ var WeaveNodesDistanceSnappingPlugin = class extends WeavePlugin {
|
|
|
29852
30008
|
};
|
|
29853
30009
|
|
|
29854
30010
|
//#endregion
|
|
29855
|
-
export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, GUIDE_ENTER_SNAPPING_TOLERANCE, GUIDE_EXIT_SNAPPING_TOLERANCE, GUIDE_HORIZONTAL_LINE_NAME, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, GUIDE_VERTICAL_LINE_NAME, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, NODE_SNAP_HORIZONTAL, NODE_SNAP_VERTICAL, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_GRID_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTERS_DEFAULT_PROPS, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesDistanceSnappingPlugin, WeaveNodesEdgeSnappingPlugin, WeaveNodesSelectionPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveStrokeNode, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveZoomInToolAction, WeaveZoomOutToolAction, clearContainerTargets, containerOverCursor, containsNodeDeep, getBoundingBox, getClosestParentWithId, getExportBoundingBox, getSelectedNodesMetadata, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, intersectArrays, isInShadowDOM, isNodeInSelection, memoize, moveNodeToContainer, resetScale };
|
|
30011
|
+
export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_DEFAULT_CONFIG, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, GUIDE_ENTER_SNAPPING_TOLERANCE, GUIDE_EXIT_SNAPPING_TOLERANCE, GUIDE_HORIZONTAL_LINE_NAME, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, GUIDE_VERTICAL_LINE_NAME, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, NODE_SNAP_HORIZONTAL, NODE_SNAP_VERTICAL, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_GRID_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTERS_DEFAULT_PROPS, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesDistanceSnappingPlugin, WeaveNodesEdgeSnappingPlugin, WeaveNodesSelectionPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveStrokeNode, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveZoomInToolAction, WeaveZoomOutToolAction, clearContainerTargets, containerOverCursor, containsNodeDeep, getBoundingBox, getClosestParentWithId, getExportBoundingBox, getSelectedNodesMetadata, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, intersectArrays, isIOS, isInShadowDOM, isNodeInSelection, memoize, moveNodeToContainer, resetScale };
|
|
29856
30012
|
//# sourceMappingURL=sdk.js.map
|