konva 10.4.0 → 10.6.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/README.md +4 -4
- package/konva.js +3432 -3746
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +2 -2
- package/lib/BezierFunctions.d.ts +1 -1
- package/lib/BezierFunctions.js +76 -116
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +8 -5
- package/lib/Container.js +9 -6
- package/lib/Context.d.ts +4 -5
- package/lib/Context.js +77 -72
- package/lib/DragAndDrop.d.ts +5 -3
- package/lib/DragAndDrop.js +65 -29
- package/lib/Factory.d.ts +3 -2
- package/lib/Factory.js +10 -9
- package/lib/Global.d.ts +0 -6
- package/lib/Global.js +2 -8
- package/lib/Layer.js +9 -6
- package/lib/Node.d.ts +33 -15
- package/lib/Node.js +179 -135
- package/lib/PointerEvents.d.ts +1 -2
- package/lib/PointerEvents.js +20 -18
- package/lib/Shape.d.ts +2 -2
- package/lib/Shape.js +51 -7
- package/lib/Stage.d.ts +23 -14
- package/lib/Stage.js +221 -93
- package/lib/Tween.js +59 -66
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +43 -16
- package/lib/_CoreInternals.d.ts +25 -11
- package/lib/_FullInternals.d.ts +25 -11
- package/lib/filters/Blur.js +16 -12
- package/lib/filters/Brighten.d.ts +1 -0
- package/lib/filters/Brighten.js +1 -0
- package/lib/filters/Brightness.d.ts +2 -1
- package/lib/filters/Brightness.js +4 -4
- package/lib/filters/Emboss.js +16 -58
- package/lib/filters/Kaleidoscope.js +8 -15
- package/lib/filters/Mask.js +8 -8
- package/lib/filters/Pixelate.js +16 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +1 -1
- package/lib/shapes/Arc.js +5 -3
- package/lib/shapes/Arrow.d.ts +2 -6
- package/lib/shapes/Arrow.js +68 -46
- package/lib/shapes/Image.js +16 -19
- package/lib/shapes/Label.d.ts +2 -3
- package/lib/shapes/Label.js +7 -21
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +1 -1
- package/lib/shapes/Path.d.ts +27 -2
- package/lib/shapes/Path.js +148 -142
- package/lib/shapes/RegularPolygon.js +1 -1
- package/lib/shapes/Sprite.js +2 -6
- package/lib/shapes/Text.d.ts +12 -4
- package/lib/shapes/Text.js +96 -54
- package/lib/shapes/TextPath.d.ts +4 -3
- package/lib/shapes/TextPath.js +40 -26
- package/lib/shapes/Transformer.d.ts +16 -1
- package/lib/shapes/Transformer.js +209 -130
- package/lib/types.d.ts +2 -2
- package/package.json +4 -3
package/lib/Tween.js
CHANGED
|
@@ -21,6 +21,25 @@ function colorToRGBA(color) {
|
|
|
21
21
|
color +
|
|
22
22
|
'", because it is not a valid color.'));
|
|
23
23
|
}
|
|
24
|
+
function colorDiff(start, end) {
|
|
25
|
+
return {
|
|
26
|
+
r: end.r - start.r,
|
|
27
|
+
g: end.g - start.g,
|
|
28
|
+
b: end.b - start.b,
|
|
29
|
+
a: end.a - start.a,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function tweenColor(start, diff, i) {
|
|
33
|
+
return ('rgba(' +
|
|
34
|
+
Math.round(start.r + diff.r * i) +
|
|
35
|
+
',' +
|
|
36
|
+
Math.round(start.g + diff.g * i) +
|
|
37
|
+
',' +
|
|
38
|
+
Math.round(start.b + diff.b * i) +
|
|
39
|
+
',' +
|
|
40
|
+
(start.a + diff.a * i) +
|
|
41
|
+
')');
|
|
42
|
+
}
|
|
24
43
|
class TweenEngine {
|
|
25
44
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
26
45
|
this.prop = prop;
|
|
@@ -86,15 +105,15 @@ class TweenEngine {
|
|
|
86
105
|
play() {
|
|
87
106
|
this.state = PLAYING;
|
|
88
107
|
this._startTime = this.getTimer() - this._time;
|
|
89
|
-
this.onEnterFrame();
|
|
90
108
|
this.fire('onPlay');
|
|
109
|
+
this.onEnterFrame();
|
|
91
110
|
}
|
|
92
111
|
reverse() {
|
|
93
112
|
this.state = REVERSING;
|
|
94
113
|
this._time = this.duration - this._time;
|
|
95
114
|
this._startTime = this.getTimer() - this._time;
|
|
96
|
-
this.onEnterFrame();
|
|
97
115
|
this.fire('onReverse');
|
|
116
|
+
this.onEnterFrame();
|
|
98
117
|
}
|
|
99
118
|
seek(t) {
|
|
100
119
|
this.pause();
|
|
@@ -222,7 +241,7 @@ export class Tween {
|
|
|
222
241
|
return;
|
|
223
242
|
}
|
|
224
243
|
const node = this.node, nodeId = node._id;
|
|
225
|
-
let diff, len, trueEnd, trueStart
|
|
244
|
+
let diff, len, trueEnd, trueStart;
|
|
226
245
|
// remove conflict from tween map if it exists
|
|
227
246
|
const tweenId = Tween.tweens[nodeId][key];
|
|
228
247
|
if (tweenId !== undefined) {
|
|
@@ -230,59 +249,55 @@ export class Tween {
|
|
|
230
249
|
}
|
|
231
250
|
// add to tween map
|
|
232
251
|
let start = node.getAttr(key);
|
|
233
|
-
if (Util._isArray(end)) {
|
|
252
|
+
if (Util._isArray(end) || Util._isArray(start)) {
|
|
234
253
|
diff = [];
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
|
|
254
|
+
// only normalized arrays are interpolated, so the values the user asked
|
|
255
|
+
// for are restored when the tween ends
|
|
256
|
+
trueStart = start;
|
|
257
|
+
trueEnd = end;
|
|
258
|
+
// an attribute the node does not have yet starts from zeros, a scalar
|
|
259
|
+
// side tweens every entry. A copy of start, as the colour stops are
|
|
260
|
+
// replaced by RGBA objects below
|
|
261
|
+
start = Util._isArray(start)
|
|
262
|
+
? start.slice()
|
|
263
|
+
: new Array(end.length).fill(start || 0);
|
|
264
|
+
if (!Util._isArray(end)) {
|
|
265
|
+
end = new Array(start.length).fill(end);
|
|
266
|
+
}
|
|
238
267
|
len = Math.max(end.length, start.length);
|
|
239
268
|
if (key === 'points' && end.length !== start.length) {
|
|
240
269
|
// before tweening points we need to make sure that start.length === end.length
|
|
241
270
|
// Util._prepareArrayForTween thinking that end.length > start.length
|
|
242
271
|
if (end.length > start.length) {
|
|
243
272
|
// so in this case we will increase number of starting points
|
|
244
|
-
trueStart = start;
|
|
245
273
|
start = Util._prepareArrayForTween(start, end, node.closed());
|
|
246
274
|
}
|
|
247
275
|
else {
|
|
248
276
|
// in this case we will increase number of eding points
|
|
249
|
-
trueEnd = end;
|
|
250
277
|
end = Util._prepareArrayForTween(end, start, node.closed());
|
|
251
278
|
}
|
|
252
279
|
}
|
|
253
|
-
if (key.
|
|
280
|
+
if (key.endsWith('ColorStops')) {
|
|
254
281
|
for (let n = 0; n < len; n++) {
|
|
255
282
|
if (n % 2 === 0) {
|
|
256
|
-
diff.push(end[n] - (start[n] || 0));
|
|
283
|
+
diff.push((end[n] || 0) - (start[n] || 0));
|
|
257
284
|
}
|
|
258
285
|
else {
|
|
259
286
|
const startRGBA = colorToRGBA(start[n]);
|
|
260
|
-
endRGBA = colorToRGBA(end[n]);
|
|
261
287
|
start[n] = startRGBA;
|
|
262
|
-
diff.push(
|
|
263
|
-
r: endRGBA.r - startRGBA.r,
|
|
264
|
-
g: endRGBA.g - startRGBA.g,
|
|
265
|
-
b: endRGBA.b - startRGBA.b,
|
|
266
|
-
a: endRGBA.a - startRGBA.a,
|
|
267
|
-
});
|
|
288
|
+
diff.push(colorDiff(startRGBA, colorToRGBA(end[n])));
|
|
268
289
|
}
|
|
269
290
|
}
|
|
270
291
|
}
|
|
271
292
|
else {
|
|
272
293
|
for (let n = 0; n < len; n++) {
|
|
273
|
-
diff.push(end[n] - (start[n] || 0));
|
|
294
|
+
diff.push((end[n] || 0) - (start[n] || 0));
|
|
274
295
|
}
|
|
275
296
|
}
|
|
276
297
|
}
|
|
277
298
|
else if (colorAttrs.indexOf(key) !== -1) {
|
|
278
299
|
start = colorToRGBA(start);
|
|
279
|
-
|
|
280
|
-
diff = {
|
|
281
|
-
r: endRGBA.r - start.r,
|
|
282
|
-
g: endRGBA.g - start.g,
|
|
283
|
-
b: endRGBA.b - start.b,
|
|
284
|
-
a: endRGBA.a - start.a,
|
|
285
|
-
};
|
|
300
|
+
diff = colorDiff(start, colorToRGBA(end));
|
|
286
301
|
}
|
|
287
302
|
else {
|
|
288
303
|
diff = end - start;
|
|
@@ -297,7 +312,8 @@ export class Tween {
|
|
|
297
312
|
Tween.tweens[nodeId][key] = this._id;
|
|
298
313
|
}
|
|
299
314
|
_tweenFunc(i) {
|
|
300
|
-
|
|
315
|
+
var _a;
|
|
316
|
+
const node = this.node, attrs = (_a = Tween.attrs[node._id]) === null || _a === void 0 ? void 0 : _a[this._id];
|
|
301
317
|
let key, attr, start, diff, newVal, n, len, end;
|
|
302
318
|
for (key in attrs) {
|
|
303
319
|
attr = attrs[key];
|
|
@@ -307,21 +323,13 @@ export class Tween {
|
|
|
307
323
|
if (Util._isArray(start)) {
|
|
308
324
|
newVal = [];
|
|
309
325
|
len = Math.max(start.length, end.length);
|
|
310
|
-
if (key.
|
|
326
|
+
if (key.endsWith('ColorStops')) {
|
|
311
327
|
for (n = 0; n < len; n++) {
|
|
312
328
|
if (n % 2 === 0) {
|
|
313
329
|
newVal.push((start[n] || 0) + diff[n] * i);
|
|
314
330
|
}
|
|
315
331
|
else {
|
|
316
|
-
newVal.push(
|
|
317
|
-
Math.round(start[n].r + diff[n].r * i) +
|
|
318
|
-
',' +
|
|
319
|
-
Math.round(start[n].g + diff[n].g * i) +
|
|
320
|
-
',' +
|
|
321
|
-
Math.round(start[n].b + diff[n].b * i) +
|
|
322
|
-
',' +
|
|
323
|
-
(start[n].a + diff[n].a * i) +
|
|
324
|
-
')');
|
|
332
|
+
newVal.push(tweenColor(start[n], diff[n], i));
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
335
|
}
|
|
@@ -332,16 +340,7 @@ export class Tween {
|
|
|
332
340
|
}
|
|
333
341
|
}
|
|
334
342
|
else if (colorAttrs.indexOf(key) !== -1) {
|
|
335
|
-
newVal =
|
|
336
|
-
'rgba(' +
|
|
337
|
-
Math.round(start.r + diff.r * i) +
|
|
338
|
-
',' +
|
|
339
|
-
Math.round(start.g + diff.g * i) +
|
|
340
|
-
',' +
|
|
341
|
-
Math.round(start.b + diff.b * i) +
|
|
342
|
-
',' +
|
|
343
|
-
(start.a + diff.a * i) +
|
|
344
|
-
')';
|
|
343
|
+
newVal = tweenColor(start, diff, i);
|
|
345
344
|
}
|
|
346
345
|
else {
|
|
347
346
|
newVal = start + diff * i;
|
|
@@ -366,28 +365,22 @@ export class Tween {
|
|
|
366
365
|
this.node.off(destroyEvent);
|
|
367
366
|
this.anim.stop();
|
|
368
367
|
};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
//
|
|
372
|
-
const attrs = Tween.attrs[node._id][this._id];
|
|
373
|
-
if (attrs
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
if (this.onFinish) {
|
|
377
|
-
this.onFinish.call(this);
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
this.tween.onReset = () => {
|
|
381
|
-
const node = this.node;
|
|
382
|
-
// after tweening points of line we need to set original start
|
|
383
|
-
const attrs = Tween.attrs[node._id][this._id];
|
|
384
|
-
if (attrs.points && attrs.points.trueStart) {
|
|
385
|
-
node.points(attrs.points.trueStart);
|
|
368
|
+
const end = (edge, callback) => {
|
|
369
|
+
var _a;
|
|
370
|
+
// no attributes means the tween was destroyed inside the last onUpdate
|
|
371
|
+
const attrs = (_a = Tween.attrs[this.node._id]) === null || _a === void 0 ? void 0 : _a[this._id];
|
|
372
|
+
if (!attrs) {
|
|
373
|
+
return;
|
|
386
374
|
}
|
|
387
|
-
|
|
388
|
-
|
|
375
|
+
for (const key in attrs) {
|
|
376
|
+
if (attrs[key][edge] !== undefined) {
|
|
377
|
+
this.node.setAttr(key, attrs[key][edge]);
|
|
378
|
+
}
|
|
389
379
|
}
|
|
380
|
+
callback === null || callback === void 0 ? void 0 : callback.call(this);
|
|
390
381
|
};
|
|
382
|
+
this.tween.onFinish = () => end('trueEnd', this.onFinish);
|
|
383
|
+
this.tween.onReset = () => end('trueStart', this.onReset);
|
|
391
384
|
this.tween.onUpdate = () => {
|
|
392
385
|
if (this.onUpdate) {
|
|
393
386
|
this.onUpdate.call(this);
|
package/lib/Util.d.ts
CHANGED
|
@@ -133,8 +133,7 @@ export declare const Util: {
|
|
|
133
133
|
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
134
134
|
createCanvasElement(): HTMLCanvasElement;
|
|
135
135
|
createImageElement(): HTMLImageElement;
|
|
136
|
-
|
|
137
|
-
_urlToImage(url: string, callback: Function): void;
|
|
136
|
+
_urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
|
|
138
137
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
139
138
|
_hexToRgb(hex: string): RGB;
|
|
140
139
|
/**
|
|
@@ -258,6 +257,7 @@ export declare const Util: {
|
|
|
258
257
|
throw(str: string): never;
|
|
259
258
|
error(str: string): void;
|
|
260
259
|
warn(str: string): void;
|
|
260
|
+
_batchEvents(batch: ((run: () => void) => void) | undefined, run: () => void): void;
|
|
261
261
|
each(obj: object, func: Function): void;
|
|
262
262
|
_inRange(val: number, left: number, right: number): boolean;
|
|
263
263
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
@@ -265,6 +265,7 @@ export declare const Util: {
|
|
|
265
265
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
266
266
|
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
267
267
|
_assign<T, U>(target: T, source: U): T & U;
|
|
268
|
+
_getEventType(type: string): "mouse" | "touch" | "pointer";
|
|
268
269
|
_getFirstPointerId(evt: any): any;
|
|
269
270
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
270
271
|
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
package/lib/Util.js
CHANGED
|
@@ -464,18 +464,20 @@ const NUMBER_SOURCE = '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?';
|
|
|
464
464
|
const COLOR_COMPONENT_REGEX = new RegExp(`^(${NUMBER_SOURCE})(%?)$`, 'i');
|
|
465
465
|
// Parse one color component. 100% is `max`: 255 for the color channels of
|
|
466
466
|
// rgb(), 1 for the alpha, 100 for the saturation and the lightness of hsl().
|
|
467
|
+
// CSS clamps a component to [0, max], and so do we: Konva multiplies and
|
|
468
|
+
// interpolates these numbers (shadowOpacity, Tween) before the canvas sees
|
|
469
|
+
// them. NaN stays NaN, so a bad value still fails.
|
|
467
470
|
const parseColorComponent = (value, max) => {
|
|
468
471
|
const match = COLOR_COMPONENT_REGEX.exec(value);
|
|
469
472
|
if (!match) {
|
|
470
473
|
return NaN;
|
|
471
474
|
}
|
|
472
|
-
|
|
475
|
+
const n = match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
|
|
476
|
+
return Math.min(Math.max(n, 0), max);
|
|
473
477
|
};
|
|
474
478
|
// parseInt() stops at the first character it can not read, so "#0g0000" would
|
|
475
479
|
// give a valid black instead of failing. The hex parsers test the shape first.
|
|
476
480
|
const HEX_COLOR_REGEX = /^#[0-9a-f]+$/i;
|
|
477
|
-
// Keep a fraction in [0, 1]. NaN stays NaN, so a bad value still fails.
|
|
478
|
-
const clamp01 = (value) => Math.min(Math.max(value, 0), 1);
|
|
479
481
|
// The hue of hsl() is the same number, with a CSS Color 4 angle unit
|
|
480
482
|
// instead of the "%" sign. No unit means degrees.
|
|
481
483
|
const HUE_REGEX = new RegExp(`^(${NUMBER_SOURCE})(deg|grad|rad|turn)?$`, 'i');
|
|
@@ -575,20 +577,18 @@ export const Util = {
|
|
|
575
577
|
ensureBrowser();
|
|
576
578
|
return document.createElement('img');
|
|
577
579
|
},
|
|
578
|
-
_isInDocument(el) {
|
|
579
|
-
// not `el.parentNode == document`, because the element may belong to
|
|
580
|
-
// another document: an iframe, or a popout window
|
|
581
|
-
return !!el.isConnected;
|
|
582
|
-
},
|
|
583
580
|
/*
|
|
584
581
|
* arg can be an image object or image data
|
|
585
582
|
*/
|
|
586
|
-
_urlToImage(url, callback) {
|
|
583
|
+
_urlToImage(url, callback, onError) {
|
|
587
584
|
// if arg is a string, then it's a data url
|
|
588
585
|
const imageObj = Util.createImageElement();
|
|
589
586
|
imageObj.onload = function () {
|
|
590
587
|
callback(imageObj);
|
|
591
588
|
};
|
|
589
|
+
imageObj.onerror = (event) => {
|
|
590
|
+
onError === null || onError === void 0 ? void 0 : onError(event instanceof Error ? event : new Error('Unable to load image.'));
|
|
591
|
+
};
|
|
592
592
|
imageObj.src = url;
|
|
593
593
|
},
|
|
594
594
|
_rgbToHex(r, g, b) {
|
|
@@ -830,11 +830,9 @@ export const Util = {
|
|
|
830
830
|
// negative angles and angles over one full turn
|
|
831
831
|
const h = (((degrees % 360) + 360) % 360) / 360;
|
|
832
832
|
// the saturation and the lightness are percentages of 1, written with or
|
|
833
|
-
// without the "%" sign, so read them out of 100 and then scale them down
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const s = clamp01(parseColorComponent(parts[1], 100) / 100);
|
|
837
|
-
const l = clamp01(parseColorComponent(parts[2], 100) / 100);
|
|
833
|
+
// without the "%" sign, so read them out of 100 and then scale them down
|
|
834
|
+
const s = parseColorComponent(parts[1], 100) / 100;
|
|
835
|
+
const l = parseColorComponent(parts[2], 100) / 100;
|
|
838
836
|
const a = parts.length > 3 ? parseColorComponent(parts[3], 1) : 1;
|
|
839
837
|
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
840
838
|
const t1 = 2 * l - t2;
|
|
@@ -968,6 +966,28 @@ export const Util = {
|
|
|
968
966
|
}
|
|
969
967
|
console.warn(KONVA_WARNING + str);
|
|
970
968
|
},
|
|
969
|
+
_batchEvents(batch, run) {
|
|
970
|
+
if (!batch)
|
|
971
|
+
return run();
|
|
972
|
+
let called = false;
|
|
973
|
+
let active = true;
|
|
974
|
+
try {
|
|
975
|
+
batch(() => {
|
|
976
|
+
if (called || !active) {
|
|
977
|
+
Util.warn('eventBatchFunc must call its argument exactly once, synchronously.');
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
called = true;
|
|
981
|
+
run();
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
finally {
|
|
985
|
+
active = false;
|
|
986
|
+
if (!called) {
|
|
987
|
+
Util.warn('eventBatchFunc must call its argument synchronously.');
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
},
|
|
971
991
|
each(obj, func) {
|
|
972
992
|
for (const key in obj) {
|
|
973
993
|
func(key, obj[key]);
|
|
@@ -1077,10 +1097,17 @@ export const Util = {
|
|
|
1077
1097
|
}
|
|
1078
1098
|
return target;
|
|
1079
1099
|
},
|
|
1100
|
+
_getEventType(type) {
|
|
1101
|
+
if (type.indexOf('pointer') >= 0)
|
|
1102
|
+
return 'pointer';
|
|
1103
|
+
if (type.indexOf('touch') >= 0)
|
|
1104
|
+
return 'touch';
|
|
1105
|
+
return 'mouse';
|
|
1106
|
+
},
|
|
1080
1107
|
_getFirstPointerId(evt) {
|
|
1108
|
+
var _a;
|
|
1081
1109
|
if (!evt.touches) {
|
|
1082
|
-
|
|
1083
|
-
return evt.pointerId || 999;
|
|
1110
|
+
return (_a = evt.pointerId) !== null && _a !== void 0 ? _a : 999;
|
|
1084
1111
|
}
|
|
1085
1112
|
else {
|
|
1086
1113
|
return evt.changedTouches[0].identifier;
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -22,12 +22,6 @@ export declare const Konva: {
|
|
|
22
22
|
autoDrawEnabled: boolean;
|
|
23
23
|
hitOnDragEnabled: boolean;
|
|
24
24
|
capturePointerEventsEnabled: boolean;
|
|
25
|
-
_mouseListenClick: boolean;
|
|
26
|
-
_touchListenClick: boolean;
|
|
27
|
-
_pointerListenClick: boolean;
|
|
28
|
-
_mouseInDblClickWindow: boolean;
|
|
29
|
-
_touchInDblClickWindow: boolean;
|
|
30
|
-
_pointerInDblClickWindow: boolean;
|
|
31
25
|
_renderBackend: string;
|
|
32
26
|
legacyTextRendering: boolean;
|
|
33
27
|
pixelRatio: number;
|
|
@@ -56,8 +50,7 @@ export declare const Konva: {
|
|
|
56
50
|
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
57
51
|
createCanvasElement(): HTMLCanvasElement;
|
|
58
52
|
createImageElement(): HTMLImageElement;
|
|
59
|
-
|
|
60
|
-
_urlToImage(url: string, callback: Function): void;
|
|
53
|
+
_urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
|
|
61
54
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
62
55
|
_hexToRgb(hex: string): import("./types.ts").RGB;
|
|
63
56
|
getRandomColor(): string;
|
|
@@ -126,6 +119,7 @@ export declare const Konva: {
|
|
|
126
119
|
throw(str: string): never;
|
|
127
120
|
error(str: string): void;
|
|
128
121
|
warn(str: string): void;
|
|
122
|
+
_batchEvents(batch: ((run: () => void) => void) | undefined, run: () => void): void;
|
|
129
123
|
each(obj: object, func: Function): void;
|
|
130
124
|
_inRange(val: number, left: number, right: number): boolean;
|
|
131
125
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
@@ -133,6 +127,7 @@ export declare const Konva: {
|
|
|
133
127
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
134
128
|
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
135
129
|
_assign<T, U>(target: T, source: U): T & U;
|
|
130
|
+
_getEventType(type: string): "mouse" | "touch" | "pointer";
|
|
136
131
|
_getFirstPointerId(evt: any): any;
|
|
137
132
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
138
133
|
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
@@ -149,21 +144,40 @@ export declare const Konva: {
|
|
|
149
144
|
Group: typeof Group;
|
|
150
145
|
DD: {
|
|
151
146
|
readonly isDragging: boolean;
|
|
152
|
-
justDragged: boolean;
|
|
153
147
|
readonly node: Node<import("./Node.ts").NodeConfig> | undefined;
|
|
154
148
|
_dragElements: Map<number, {
|
|
155
149
|
node: Node;
|
|
156
150
|
startPointerPos: import("./types.ts").Vector2d;
|
|
157
151
|
offset: import("./types.ts").Vector2d;
|
|
158
152
|
pointerId?: number;
|
|
153
|
+
pointerEventType?: Stage["_pointerEventType"];
|
|
159
154
|
lastPos?: import("./types.ts").Vector2d;
|
|
160
155
|
startEvent?: any;
|
|
161
156
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
162
157
|
}>;
|
|
163
158
|
_listenToWindow(win: Window): void;
|
|
159
|
+
_batchEvents(callback: () => void, win?: Window): void;
|
|
164
160
|
_drag(evt: any, win?: Window): void;
|
|
165
|
-
_endDragBefore(evt?: any, win?: Window
|
|
166
|
-
|
|
161
|
+
_endDragBefore(evt?: any, win?: Window, only?: {
|
|
162
|
+
node: Node;
|
|
163
|
+
startPointerPos: import("./types.ts").Vector2d;
|
|
164
|
+
offset: import("./types.ts").Vector2d;
|
|
165
|
+
pointerId?: number;
|
|
166
|
+
pointerEventType?: Stage["_pointerEventType"];
|
|
167
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
168
|
+
startEvent?: any;
|
|
169
|
+
dragStatus: "ready" | "dragging" | "stopped";
|
|
170
|
+
}): void;
|
|
171
|
+
_endDragAfter(evt: any, only?: {
|
|
172
|
+
node: Node;
|
|
173
|
+
startPointerPos: import("./types.ts").Vector2d;
|
|
174
|
+
offset: import("./types.ts").Vector2d;
|
|
175
|
+
pointerId?: number;
|
|
176
|
+
pointerEventType?: Stage["_pointerEventType"];
|
|
177
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
178
|
+
startEvent?: any;
|
|
179
|
+
dragStatus: "ready" | "dragging" | "stopped";
|
|
180
|
+
}): void;
|
|
167
181
|
};
|
|
168
182
|
Shape: typeof Shape;
|
|
169
183
|
shapes: {
|
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -28,12 +28,6 @@ export declare const Konva: {
|
|
|
28
28
|
autoDrawEnabled: boolean;
|
|
29
29
|
hitOnDragEnabled: boolean;
|
|
30
30
|
capturePointerEventsEnabled: boolean;
|
|
31
|
-
_mouseListenClick: boolean;
|
|
32
|
-
_touchListenClick: boolean;
|
|
33
|
-
_pointerListenClick: boolean;
|
|
34
|
-
_mouseInDblClickWindow: boolean;
|
|
35
|
-
_touchInDblClickWindow: boolean;
|
|
36
|
-
_pointerInDblClickWindow: boolean;
|
|
37
31
|
_renderBackend: string;
|
|
38
32
|
legacyTextRendering: boolean;
|
|
39
33
|
pixelRatio: number;
|
|
@@ -62,8 +56,7 @@ export declare const Konva: {
|
|
|
62
56
|
requestAnimFrame(callback: Function, win?: Window | null): void;
|
|
63
57
|
createCanvasElement(): HTMLCanvasElement;
|
|
64
58
|
createImageElement(): HTMLImageElement;
|
|
65
|
-
|
|
66
|
-
_urlToImage(url: string, callback: Function): void;
|
|
59
|
+
_urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
|
|
67
60
|
_rgbToHex(r: number, g: number, b: number): string;
|
|
68
61
|
_hexToRgb(hex: string): import("./types.ts").RGB;
|
|
69
62
|
getRandomColor(): string;
|
|
@@ -132,6 +125,7 @@ export declare const Konva: {
|
|
|
132
125
|
throw(str: string): never;
|
|
133
126
|
error(str: string): void;
|
|
134
127
|
warn(str: string): void;
|
|
128
|
+
_batchEvents(batch: ((run: () => void) => void) | undefined, run: () => void): void;
|
|
135
129
|
each(obj: object, func: Function): void;
|
|
136
130
|
_inRange(val: number, left: number, right: number): boolean;
|
|
137
131
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
@@ -139,6 +133,7 @@ export declare const Konva: {
|
|
|
139
133
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
140
134
|
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
141
135
|
_assign<T, U>(target: T, source: U): T & U;
|
|
136
|
+
_getEventType(type: string): "mouse" | "touch" | "pointer";
|
|
142
137
|
_getFirstPointerId(evt: any): any;
|
|
143
138
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
144
139
|
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
@@ -155,21 +150,40 @@ export declare const Konva: {
|
|
|
155
150
|
Group: typeof import("./Group.ts").Group;
|
|
156
151
|
DD: {
|
|
157
152
|
readonly isDragging: boolean;
|
|
158
|
-
justDragged: boolean;
|
|
159
153
|
readonly node: import("./Node.ts").Node<import("./Node.ts").NodeConfig> | undefined;
|
|
160
154
|
_dragElements: Map<number, {
|
|
161
155
|
node: import("./Node.ts").Node;
|
|
162
156
|
startPointerPos: import("./types.ts").Vector2d;
|
|
163
157
|
offset: import("./types.ts").Vector2d;
|
|
164
158
|
pointerId?: number;
|
|
159
|
+
pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
|
|
165
160
|
lastPos?: import("./types.ts").Vector2d;
|
|
166
161
|
startEvent?: any;
|
|
167
162
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
168
163
|
}>;
|
|
169
164
|
_listenToWindow(win: Window): void;
|
|
165
|
+
_batchEvents(callback: () => void, win?: Window): void;
|
|
170
166
|
_drag(evt: any, win?: Window): void;
|
|
171
|
-
_endDragBefore(evt?: any, win?: Window
|
|
172
|
-
|
|
167
|
+
_endDragBefore(evt?: any, win?: Window, only?: {
|
|
168
|
+
node: import("./Node.ts").Node;
|
|
169
|
+
startPointerPos: import("./types.ts").Vector2d;
|
|
170
|
+
offset: import("./types.ts").Vector2d;
|
|
171
|
+
pointerId?: number;
|
|
172
|
+
pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
|
|
173
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
174
|
+
startEvent?: any;
|
|
175
|
+
dragStatus: "ready" | "dragging" | "stopped";
|
|
176
|
+
}): void;
|
|
177
|
+
_endDragAfter(evt: any, only?: {
|
|
178
|
+
node: import("./Node.ts").Node;
|
|
179
|
+
startPointerPos: import("./types.ts").Vector2d;
|
|
180
|
+
offset: import("./types.ts").Vector2d;
|
|
181
|
+
pointerId?: number;
|
|
182
|
+
pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
|
|
183
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
184
|
+
startEvent?: any;
|
|
185
|
+
dragStatus: "ready" | "dragging" | "stopped";
|
|
186
|
+
}): void;
|
|
173
187
|
};
|
|
174
188
|
Shape: typeof import("./Shape.ts").Shape;
|
|
175
189
|
shapes: {
|
package/lib/filters/Blur.js
CHANGED
|
@@ -94,12 +94,16 @@ const shg_table = [
|
|
|
94
94
|
function premultiply(channel, alpha) {
|
|
95
95
|
return alpha === 255 ? channel : (channel * alpha) / 255;
|
|
96
96
|
}
|
|
97
|
-
// the
|
|
97
|
+
// Preserve the maximum logical radius; high-DPI caches need larger kernels.
|
|
98
98
|
const MAX_RADIUS = 180;
|
|
99
99
|
function filterGaussBlurRGBA(imageData, radius) {
|
|
100
100
|
const pixels = imageData.data, width = imageData.width, height = imageData.height;
|
|
101
101
|
let p, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
|
102
|
-
const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(),
|
|
102
|
+
const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(),
|
|
103
|
+
// Use floating-point normalization to avoid 32-bit overflow at high DPI.
|
|
104
|
+
normalization = radius <= MAX_RADIUS
|
|
105
|
+
? mul_table[radius] / 2 ** shg_table[radius]
|
|
106
|
+
: 1 / (radiusPlus1 * radiusPlus1);
|
|
103
107
|
let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
|
|
104
108
|
for (let i = 1; i < div; i++) {
|
|
105
109
|
stack = stack.next = new BlurStack();
|
|
@@ -156,10 +160,10 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
156
160
|
stackIn = stackStart;
|
|
157
161
|
stackOut = stackEnd;
|
|
158
162
|
for (let x = 0; x < width; x++) {
|
|
159
|
-
pixels[yi] = (r_sum *
|
|
160
|
-
pixels[yi + 1] = (g_sum *
|
|
161
|
-
pixels[yi + 2] = (b_sum *
|
|
162
|
-
pixels[yi + 3] = (a_sum *
|
|
163
|
+
pixels[yi] = Math.floor(r_sum * normalization);
|
|
164
|
+
pixels[yi + 1] = Math.floor(g_sum * normalization);
|
|
165
|
+
pixels[yi + 2] = Math.floor(b_sum * normalization);
|
|
166
|
+
pixels[yi + 3] = Math.floor(a_sum * normalization);
|
|
163
167
|
r_sum -= r_out_sum;
|
|
164
168
|
g_sum -= g_out_sum;
|
|
165
169
|
b_sum -= b_out_sum;
|
|
@@ -241,12 +245,12 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
241
245
|
stackOut = stackEnd;
|
|
242
246
|
for (let y = 0; y < height; y++) {
|
|
243
247
|
p = yi << 2;
|
|
244
|
-
pixels[p + 3] = pa = (a_sum *
|
|
248
|
+
pixels[p + 3] = pa = Math.floor(a_sum * normalization);
|
|
245
249
|
if (pa > 0) {
|
|
246
250
|
pa = 255 / pa;
|
|
247
|
-
pixels[p] = (
|
|
248
|
-
pixels[p + 1] = (
|
|
249
|
-
pixels[p + 2] = (
|
|
251
|
+
pixels[p] = Math.floor(r_sum * normalization) * pa;
|
|
252
|
+
pixels[p + 1] = Math.floor(g_sum * normalization) * pa;
|
|
253
|
+
pixels[p + 2] = Math.floor(b_sum * normalization) * pa;
|
|
250
254
|
}
|
|
251
255
|
else {
|
|
252
256
|
pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
|
|
@@ -292,8 +296,8 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
292
296
|
* node.filters([Konva.Filters.Blur]);
|
|
293
297
|
* node.blurRadius(10);
|
|
294
298
|
*/
|
|
295
|
-
export const Blur = function Blur(imageData) {
|
|
296
|
-
const radius = Math.
|
|
299
|
+
export const Blur = function Blur(imageData, pixelRatio = 1) {
|
|
300
|
+
const radius = Math.round(Math.min(this.blurRadius(), MAX_RADIUS) * pixelRatio);
|
|
297
301
|
if (radius > 0) {
|
|
298
302
|
filterGaussBlurRGBA(imageData, radius);
|
|
299
303
|
}
|
|
@@ -16,6 +16,7 @@ export declare const Brighten: Filter;
|
|
|
16
16
|
* get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
|
|
17
17
|
* added to every channel: positive values brighten the pixels and negative values darken them.
|
|
18
18
|
* With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
|
|
19
|
+
* Both filters leave pixels unchanged when the attribute is unset. An explicit 0 makes Brightness black.
|
|
19
20
|
* @name Konva.Node#brightness
|
|
20
21
|
* @method
|
|
21
22
|
* @param {Number} brightness
|
package/lib/filters/Brighten.js
CHANGED
|
@@ -29,6 +29,7 @@ Factory.addGetterSetter(Node, 'brightness', 0, getNumberValidator(), Factory.aft
|
|
|
29
29
|
* get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
|
|
30
30
|
* added to every channel: positive values brighten the pixels and negative values darken them.
|
|
31
31
|
* With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
|
|
32
|
+
* Both filters leave pixels unchanged when the attribute is unset. An explicit 0 makes Brightness black.
|
|
32
33
|
* @name Konva.Node#brightness
|
|
33
34
|
* @method
|
|
34
35
|
* @param {Number} brightness
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
import './Brighten.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Brightness Filter.
|
|
4
|
-
* CSS-compatible brightness
|
|
5
|
+
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
|
5
6
|
* @function
|
|
6
7
|
* @memberof Konva.Filters
|
|
7
8
|
* @param {Object} imageData
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
// The shared brightness accessor is registered by Brighten.
|
|
2
|
+
import "./Brighten.js";
|
|
1
3
|
/**
|
|
2
4
|
* Brightness Filter.
|
|
3
|
-
* CSS-compatible brightness
|
|
5
|
+
* CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
|
|
4
6
|
* @function
|
|
5
7
|
* @memberof Konva.Filters
|
|
6
8
|
* @param {Object} imageData
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
11
13
|
*/
|
|
12
14
|
export const Brightness = function (imageData) {
|
|
13
|
-
const brightness = this.brightness(), data = imageData.data, len = data.length;
|
|
15
|
+
const brightness = this.attrs.brightness === undefined ? 1 : this.brightness(), data = imageData.data, len = data.length;
|
|
14
16
|
for (let i = 0; i < len; i += 4) {
|
|
15
17
|
// red
|
|
16
18
|
data[i] = Math.min(255, data[i] * brightness);
|
|
@@ -20,5 +22,3 @@ export const Brightness = function (imageData) {
|
|
|
20
22
|
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
|
-
// Note: brightness property is already defined in Brighten.ts
|
|
24
|
-
// This filter reuses the existing brightness property but with CSS-compatible behavior
|