konva 9.3.11 → 9.3.13
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/README.md +4 -0
- package/konva.js +59 -67
- package/konva.min.js +3 -3
- package/lib/Global.js +1 -1
- package/lib/Shape.d.ts +3 -3
- package/lib/Shape.js +10 -1
- package/lib/shapes/Path.d.ts +12 -3
- package/lib/shapes/Path.js +21 -43
- package/lib/shapes/Text.js +13 -11
- package/lib/shapes/TextPath.d.ts +4 -1
- package/lib/shapes/Transformer.js +3 -0
- package/package.json +1 -1
package/lib/Global.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
|
|
|
16
16
|
: {};
|
|
17
17
|
exports.Konva = {
|
|
18
18
|
_global: exports.glob,
|
|
19
|
-
version: '9.3.
|
|
19
|
+
version: '9.3.13',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/lib/Shape.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type ShapeConfigHandler<TTarget> = {
|
|
|
8
8
|
export type LineJoin = 'round' | 'bevel' | 'miter';
|
|
9
9
|
export type LineCap = 'butt' | 'round' | 'square';
|
|
10
10
|
export interface ShapeConfig extends NodeConfig {
|
|
11
|
-
fill?: string;
|
|
11
|
+
fill?: string | CanvasGradient;
|
|
12
12
|
fillPatternImage?: HTMLImageElement;
|
|
13
13
|
fillPatternX?: number;
|
|
14
14
|
fillPatternY?: number;
|
|
@@ -126,7 +126,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
126
126
|
dash: GetSet<number[], this>;
|
|
127
127
|
dashEnabled: GetSet<boolean, this>;
|
|
128
128
|
dashOffset: GetSet<number, this>;
|
|
129
|
-
fill: GetSet<string, this>;
|
|
129
|
+
fill: GetSet<string | CanvasGradient, this>;
|
|
130
130
|
fillEnabled: GetSet<boolean, this>;
|
|
131
131
|
fillLinearGradientColorStops: GetSet<Array<number | string>, this>;
|
|
132
132
|
fillLinearGradientStartPoint: GetSet<Vector2d, this>;
|
|
@@ -175,7 +175,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
175
175
|
shadowOffsetY: GetSet<number, this>;
|
|
176
176
|
shadowOpacity: GetSet<number, this>;
|
|
177
177
|
shadowBlur: GetSet<number, this>;
|
|
178
|
-
stroke: GetSet<string, this>;
|
|
178
|
+
stroke: GetSet<string | CanvasGradient, this>;
|
|
179
179
|
strokeEnabled: GetSet<boolean, this>;
|
|
180
180
|
fillAfterStrokeEnabled: GetSet<boolean, this>;
|
|
181
181
|
strokeScaleEnabled: GetSet<boolean, this>;
|
package/lib/Shape.js
CHANGED
|
@@ -271,8 +271,17 @@ class Shape extends Node_1.Node {
|
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
getClientRect(config = {}) {
|
|
274
|
+
let hasCachedParent = false;
|
|
275
|
+
let parent = this.getParent();
|
|
276
|
+
while (parent) {
|
|
277
|
+
if (parent.isCached()) {
|
|
278
|
+
hasCachedParent = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
parent = parent.getParent();
|
|
282
|
+
}
|
|
274
283
|
const skipTransform = config.skipTransform;
|
|
275
|
-
const relativeTo = config.relativeTo;
|
|
284
|
+
const relativeTo = config.relativeTo || (hasCachedParent && this.getStage()) || undefined;
|
|
276
285
|
const fillRect = this.getSelfRect();
|
|
277
286
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
278
287
|
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
package/lib/shapes/Path.d.ts
CHANGED
|
@@ -16,12 +16,21 @@ export declare class Path extends Shape<PathConfig> {
|
|
|
16
16
|
height: number;
|
|
17
17
|
};
|
|
18
18
|
getLength(): number;
|
|
19
|
-
getPointAtLength(length: any):
|
|
19
|
+
getPointAtLength(length: any): {
|
|
20
|
+
x: any;
|
|
21
|
+
y: any;
|
|
22
|
+
} | null;
|
|
20
23
|
data: GetSet<string, this>;
|
|
21
24
|
static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
|
|
22
25
|
static getPathLength(dataArray: PathSegment[]): number;
|
|
23
|
-
static getPointAtLengthOfDataArray(length: number, dataArray: any):
|
|
24
|
-
|
|
26
|
+
static getPointAtLengthOfDataArray(length: number, dataArray: any): {
|
|
27
|
+
x: any;
|
|
28
|
+
y: any;
|
|
29
|
+
} | null;
|
|
30
|
+
static getPointOnLine(dist: any, P1x: any, P1y: any, P2x: any, P2y: any, fromX?: any, fromY?: any): {
|
|
31
|
+
x: any;
|
|
32
|
+
y: any;
|
|
33
|
+
};
|
|
25
34
|
static getPointOnCubicBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any, P4x: any, P4y: any): {
|
|
26
35
|
x: number;
|
|
27
36
|
y: number;
|
package/lib/shapes/Path.js
CHANGED
|
@@ -183,51 +183,29 @@ class Path extends Shape_1.Shape {
|
|
|
183
183
|
return null;
|
|
184
184
|
}
|
|
185
185
|
static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
fromX = fromX !== null && fromX !== void 0 ? fromX : P1x;
|
|
187
|
+
fromY = fromY !== null && fromY !== void 0 ? fromY : P1y;
|
|
188
|
+
const len = this.getLineLength(P1x, P1y, P2x, P2y);
|
|
189
|
+
if (len < 1e-10) {
|
|
190
|
+
return { x: P1x, y: P1y };
|
|
188
191
|
}
|
|
189
|
-
if (fromY === undefined) {
|
|
190
|
-
fromY = P1y;
|
|
191
|
-
}
|
|
192
|
-
var m = (P2y - P1y) / (P2x - P1x + 0.00000001);
|
|
193
|
-
var run = Math.sqrt((dist * dist) / (1 + m * m));
|
|
194
|
-
if (P2x < P1x) {
|
|
195
|
-
run *= -1;
|
|
196
|
-
}
|
|
197
|
-
var rise = m * run;
|
|
198
|
-
var pt;
|
|
199
192
|
if (P2x === P1x) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
ix = P1x + u * (P2x - P1x);
|
|
217
|
-
iy = P1y + u * (P2y - P1y);
|
|
218
|
-
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
219
|
-
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
220
|
-
run = Math.sqrt((pRun * pRun) / (1 + m * m));
|
|
221
|
-
if (P2x < P1x) {
|
|
222
|
-
run *= -1;
|
|
223
|
-
}
|
|
224
|
-
rise = m * run;
|
|
225
|
-
pt = {
|
|
226
|
-
x: ix + run,
|
|
227
|
-
y: iy + rise,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return pt;
|
|
193
|
+
return { x: fromX, y: fromY + (P2y > P1y ? dist : -dist) };
|
|
194
|
+
}
|
|
195
|
+
const m = (P2y - P1y) / (P2x - P1x);
|
|
196
|
+
const run = Math.sqrt((dist * dist) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
197
|
+
const rise = m * run;
|
|
198
|
+
if (Math.abs(fromY - P1y - m * (fromX - P1x)) < 1e-10) {
|
|
199
|
+
return { x: fromX + run, y: fromY + rise };
|
|
200
|
+
}
|
|
201
|
+
const u = ((fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y)) / (len * len);
|
|
202
|
+
const ix = P1x + u * (P2x - P1x);
|
|
203
|
+
const iy = P1y + u * (P2y - P1y);
|
|
204
|
+
const pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
205
|
+
const pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
206
|
+
const adjustedRun = Math.sqrt((pRun * pRun) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
207
|
+
const adjustedRise = m * adjustedRun;
|
|
208
|
+
return { x: ix + adjustedRun, y: iy + adjustedRise };
|
|
231
209
|
}
|
|
232
210
|
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
|
|
233
211
|
function CB1(t) {
|
package/lib/shapes/Text.js
CHANGED
|
@@ -221,23 +221,25 @@ class Text extends Shape_1.Shape {
|
|
|
221
221
|
return this.textHeight;
|
|
222
222
|
}
|
|
223
223
|
measureSize(text) {
|
|
224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
224
225
|
var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
|
|
225
226
|
_context.save();
|
|
226
227
|
_context.font = this._getContextFont();
|
|
227
228
|
metrics = _context.measureText(text);
|
|
228
229
|
_context.restore();
|
|
230
|
+
const scaleFactor = fontSize / 100;
|
|
229
231
|
return {
|
|
230
|
-
actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
|
|
231
|
-
actualBoundingBoxDescent: metrics.actualBoundingBoxDescent,
|
|
232
|
-
actualBoundingBoxLeft: metrics.actualBoundingBoxLeft,
|
|
233
|
-
actualBoundingBoxRight: metrics.actualBoundingBoxRight,
|
|
234
|
-
alphabeticBaseline: metrics.alphabeticBaseline,
|
|
235
|
-
emHeightAscent: metrics.emHeightAscent,
|
|
236
|
-
emHeightDescent: metrics.emHeightDescent,
|
|
237
|
-
fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
|
|
238
|
-
fontBoundingBoxDescent: metrics.fontBoundingBoxDescent,
|
|
239
|
-
hangingBaseline: metrics.hangingBaseline,
|
|
240
|
-
ideographicBaseline: metrics.ideographicBaseline,
|
|
232
|
+
actualBoundingBoxAscent: (_a = metrics.actualBoundingBoxAscent) !== null && _a !== void 0 ? _a : 71.58203125 * scaleFactor,
|
|
233
|
+
actualBoundingBoxDescent: (_b = metrics.actualBoundingBoxDescent) !== null && _b !== void 0 ? _b : 0,
|
|
234
|
+
actualBoundingBoxLeft: (_c = metrics.actualBoundingBoxLeft) !== null && _c !== void 0 ? _c : -7.421875 * scaleFactor,
|
|
235
|
+
actualBoundingBoxRight: (_d = metrics.actualBoundingBoxRight) !== null && _d !== void 0 ? _d : 75.732421875 * scaleFactor,
|
|
236
|
+
alphabeticBaseline: (_e = metrics.alphabeticBaseline) !== null && _e !== void 0 ? _e : 0,
|
|
237
|
+
emHeightAscent: (_f = metrics.emHeightAscent) !== null && _f !== void 0 ? _f : 100 * scaleFactor,
|
|
238
|
+
emHeightDescent: (_g = metrics.emHeightDescent) !== null && _g !== void 0 ? _g : -20 * scaleFactor,
|
|
239
|
+
fontBoundingBoxAscent: (_h = metrics.fontBoundingBoxAscent) !== null && _h !== void 0 ? _h : 91 * scaleFactor,
|
|
240
|
+
fontBoundingBoxDescent: (_j = metrics.fontBoundingBoxDescent) !== null && _j !== void 0 ? _j : 21 * scaleFactor,
|
|
241
|
+
hangingBaseline: (_k = metrics.hangingBaseline) !== null && _k !== void 0 ? _k : 72.80000305175781 * scaleFactor,
|
|
242
|
+
ideographicBaseline: (_l = metrics.ideographicBaseline) !== null && _l !== void 0 ? _l : -21 * scaleFactor,
|
|
241
243
|
width: metrics.width,
|
|
242
244
|
height: fontSize,
|
|
243
245
|
};
|
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -27,7 +27,10 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
27
27
|
textHeight: number;
|
|
28
28
|
constructor(config?: TextPathConfig);
|
|
29
29
|
_getTextPathLength(): number;
|
|
30
|
-
_getPointAtLength(length: number):
|
|
30
|
+
_getPointAtLength(length: number): {
|
|
31
|
+
x: any;
|
|
32
|
+
y: any;
|
|
33
|
+
} | null;
|
|
31
34
|
_readDataAttribute(): void;
|
|
32
35
|
_sceneFunc(context: Context): void;
|
|
33
36
|
_hitFunc(context: Context): void;
|
|
@@ -444,6 +444,9 @@ class Transformer extends Group_1.Group {
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
_handleMouseDown(e) {
|
|
447
|
+
if (this._transforming) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
447
450
|
this._movingAnchorName = e.target.name().split(' ')[0];
|
|
448
451
|
var attrs = this._getNodeRect();
|
|
449
452
|
var width = attrs.width;
|