konva 10.2.5 → 10.3.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/README.md +12 -6
- package/konva.js +763 -515
- package/konva.min.js +4 -4
- package/lib/BezierFunctions.d.ts +2 -0
- package/lib/BezierFunctions.js +46 -0
- package/lib/Container.js +20 -6
- package/lib/Context.js +6 -0
- package/lib/Factory.d.ts +1 -1
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +3 -0
- package/lib/Node.js +20 -4
- package/lib/Shape.js +1 -0
- package/lib/Tween.js +10 -4
- package/lib/Util.d.ts +0 -6
- package/lib/Util.js +113 -119
- package/lib/_CoreInternals.d.ts +0 -6
- package/lib/_FullInternals.d.ts +0 -6
- package/lib/shapes/Arc.js +11 -0
- package/lib/shapes/Line.d.ts +2 -0
- package/lib/shapes/Line.js +39 -59
- package/lib/shapes/Path.js +10 -6
- package/lib/shapes/Text.js +3 -4
- package/lib/shapes/TextPath.d.ts +2 -0
- package/lib/shapes/TextPath.js +5 -1
- package/lib/shapes/Transformer.d.ts +3 -0
- package/lib/shapes/Transformer.js +35 -5
- package/package.json +14 -2
package/lib/BezierFunctions.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export declare const binomialCoefficients: number[][];
|
|
|
4
4
|
export declare const getCubicArcLength: (xs: number[], ys: number[], t: number) => number;
|
|
5
5
|
export declare const getQuadraticArcLength: (xs: number[], ys: number[], t: number) => number;
|
|
6
6
|
export declare const t2length: (length: number, totalLength: number, func: (t: number) => number) => number;
|
|
7
|
+
export declare const getQuadraticExtremaPoints: (x0: number, y0: number, x1: number, y1: number, x2: number, y2: number) => number[];
|
|
8
|
+
export declare const getCubicExtremaPoints: (x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) => number[];
|
package/lib/BezierFunctions.js
CHANGED
|
@@ -782,3 +782,49 @@ export const t2length = (length, totalLength, func) => {
|
|
|
782
782
|
}
|
|
783
783
|
return t;
|
|
784
784
|
};
|
|
785
|
+
const quadraticAt = (p0, p1, p2, t) => {
|
|
786
|
+
const mt = 1 - t;
|
|
787
|
+
return mt * mt * p0 + 2 * mt * t * p1 + t * t * p2;
|
|
788
|
+
};
|
|
789
|
+
export const getQuadraticExtremaPoints = (x0, y0, x1, y1, x2, y2) => {
|
|
790
|
+
const extrema = [];
|
|
791
|
+
for (const axis of [
|
|
792
|
+
[x0, x1, x2],
|
|
793
|
+
[y0, y1, y2],
|
|
794
|
+
]) {
|
|
795
|
+
const t = (axis[0] - axis[1]) / (axis[0] - 2 * axis[1] + axis[2]);
|
|
796
|
+
if (t > 0 && t < 1) {
|
|
797
|
+
extrema.push(quadraticAt(x0, x1, x2, t), quadraticAt(y0, y1, y2, t));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return extrema;
|
|
801
|
+
};
|
|
802
|
+
const cubicAt = (p0, p1, p2, p3, t) => {
|
|
803
|
+
const mt = 1 - t;
|
|
804
|
+
return (mt * mt * mt * p0 +
|
|
805
|
+
3 * mt * mt * t * p1 +
|
|
806
|
+
3 * mt * t * t * p2 +
|
|
807
|
+
t * t * t * p3);
|
|
808
|
+
};
|
|
809
|
+
export const getCubicExtremaPoints = (x0, y0, x1, y1, x2, y2, x3, y3) => {
|
|
810
|
+
const extrema = [];
|
|
811
|
+
for (const axis of [
|
|
812
|
+
[x0, x1, x2, x3],
|
|
813
|
+
[y0, y1, y2, y3],
|
|
814
|
+
]) {
|
|
815
|
+
const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
|
|
816
|
+
const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
|
|
817
|
+
const c = -3 * axis[0] + 3 * axis[1];
|
|
818
|
+
const discriminant = b * b - 4 * a * c;
|
|
819
|
+
if (discriminant < 0) {
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
const q = -(b + (b < 0 ? -1 : 1) * Math.sqrt(discriminant)) / 2;
|
|
823
|
+
for (const t of [q / a, c / q]) {
|
|
824
|
+
if (t > 0 && t < 1) {
|
|
825
|
+
extrema.push(cubicAt(x0, x1, x2, x3, t), cubicAt(y0, y1, y2, y3, t));
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return extrema;
|
|
830
|
+
};
|
package/lib/Container.js
CHANGED
|
@@ -144,13 +144,27 @@ export class Container extends Node {
|
|
|
144
144
|
}
|
|
145
145
|
_clearSelfAndDescendantCache(attr) {
|
|
146
146
|
var _a;
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
147
|
+
const isAbsTransform = attr === 'absoluteTransform';
|
|
148
|
+
if (isAbsTransform)
|
|
149
|
+
Node._absTransformCascadeDepth++;
|
|
150
|
+
try {
|
|
151
|
+
super._clearSelfAndDescendantCache(attr);
|
|
152
|
+
if (this.isCached())
|
|
153
|
+
return;
|
|
154
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
|
155
|
+
node._clearSelfAndDescendantCache(attr);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
if (isAbsTransform && --Node._absTransformCascadeDepth === 0) {
|
|
160
|
+
const callbacks = Node._pendingAfterCascade;
|
|
161
|
+
if (callbacks.length) {
|
|
162
|
+
Node._pendingAfterCascade = [];
|
|
163
|
+
for (let i = 0; i < callbacks.length; i++)
|
|
164
|
+
callbacks[i]();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
150
167
|
}
|
|
151
|
-
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
|
152
|
-
node._clearSelfAndDescendantCache(attr);
|
|
153
|
-
});
|
|
154
168
|
}
|
|
155
169
|
_setChildrenIndices() {
|
|
156
170
|
var _a;
|
package/lib/Context.js
CHANGED
|
@@ -419,6 +419,12 @@ export class SceneContext extends Context {
|
|
|
419
419
|
shape._fillFunc(this);
|
|
420
420
|
}
|
|
421
421
|
_fillPattern(shape) {
|
|
422
|
+
const context = this._context;
|
|
423
|
+
if ('patternQuality' in context) {
|
|
424
|
+
context.patternQuality = context.imageSmoothingEnabled
|
|
425
|
+
? 'good'
|
|
426
|
+
: 'nearest';
|
|
427
|
+
}
|
|
422
428
|
this.setAttr('fillStyle', shape._getFillPattern());
|
|
423
429
|
shape._fillFunc(this);
|
|
424
430
|
}
|
package/lib/Factory.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type Attr<T extends Constructor> = EnforceString<keyof InstanceType<T>>;
|
|
|
6
6
|
type AfterFunc<T extends Constructor> = (this: InstanceType<T>) => void;
|
|
7
7
|
type ExtractGetSet<T> = T extends GetSet<infer U, any> ? U : never;
|
|
8
8
|
type Value<T extends Constructor, U extends Attr<T>> = ExtractGetSet<InstanceType<T>[U]>;
|
|
9
|
-
type ValidatorFunc<T> = (val:
|
|
9
|
+
type ValidatorFunc<T> = (val: T, attr: string) => T;
|
|
10
10
|
type ExtractComponents<T extends Constructor, U extends Attr<T>> = Value<T, U> extends Record<string, any> ? EnforceString<keyof Value<T, U>>[] : never;
|
|
11
11
|
export declare const Factory: {
|
|
12
12
|
addGetterSetter<T extends Constructor, U extends Attr<T>>(constructor: T, attr: U, def?: Value<T, U>, validator?: ValidatorFunc<Value<T, U>>, after?: AfterFunc<T>): void;
|
package/lib/Global.js
CHANGED
|
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
13
13
|
: {};
|
|
14
14
|
export const Konva = {
|
|
15
15
|
_global: glob,
|
|
16
|
-
version: '10.
|
|
16
|
+
version: '10.3.1',
|
|
17
17
|
isBrowser: detectBrowser(),
|
|
18
18
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
19
19
|
dblClickWindow: 400,
|
package/lib/Node.d.ts
CHANGED
|
@@ -95,6 +95,9 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
95
95
|
_calculate(name: string, deps: Array<string>, getter: Function): any;
|
|
96
96
|
_getCanvasCache(): any;
|
|
97
97
|
_clearSelfAndDescendantCache(attr?: string): void;
|
|
98
|
+
static _absTransformCascadeDepth: number;
|
|
99
|
+
static _pendingAfterCascade: Array<() => void>;
|
|
100
|
+
static _runAfterAbsTransformCascade(cb: () => void): void;
|
|
98
101
|
clearCache(): this;
|
|
99
102
|
cache(config?: CanvasConfig & {
|
|
100
103
|
drawBorder?: boolean;
|
package/lib/Node.js
CHANGED
|
@@ -152,6 +152,14 @@ export class Node {
|
|
|
152
152
|
this.fire('absoluteTransformChange');
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
static _runAfterAbsTransformCascade(cb) {
|
|
156
|
+
if (Node._absTransformCascadeDepth > 0) {
|
|
157
|
+
Node._pendingAfterCascade.push(cb);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
cb();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
155
163
|
clearCache() {
|
|
156
164
|
if (this._cache.has(CANVAS)) {
|
|
157
165
|
const { scene, filter, hit } = this._cache.get(CANVAS);
|
|
@@ -1284,10 +1292,17 @@ export class Node {
|
|
|
1284
1292
|
let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
|
|
1285
1293
|
if (events === undefined) {
|
|
1286
1294
|
events = [];
|
|
1295
|
+
const seen = new Set();
|
|
1287
1296
|
let obj = Object.getPrototypeOf(this);
|
|
1288
1297
|
while (obj) {
|
|
1289
1298
|
const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
|
|
1290
|
-
|
|
1299
|
+
for (let i = 0; i < hierarchyEvents.length; i++) {
|
|
1300
|
+
const entry = hierarchyEvents[i];
|
|
1301
|
+
if (!seen.has(entry)) {
|
|
1302
|
+
seen.add(entry);
|
|
1303
|
+
events.push(entry);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1291
1306
|
obj = Object.getPrototypeOf(obj);
|
|
1292
1307
|
}
|
|
1293
1308
|
allListeners[eventType] = events;
|
|
@@ -1301,9 +1316,8 @@ export class Node {
|
|
|
1301
1316
|
evt.type = eventType;
|
|
1302
1317
|
const topListeners = this._getProtoListeners(eventType);
|
|
1303
1318
|
if (topListeners) {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
list[i].handler.call(this, evt);
|
|
1319
|
+
for (let i = 0; i < topListeners.length; i++) {
|
|
1320
|
+
topListeners[i].handler.call(this, evt);
|
|
1307
1321
|
}
|
|
1308
1322
|
}
|
|
1309
1323
|
const selfListeners = this.eventListeners[eventType];
|
|
@@ -1491,6 +1505,8 @@ export class Node {
|
|
|
1491
1505
|
return no;
|
|
1492
1506
|
}
|
|
1493
1507
|
}
|
|
1508
|
+
Node._absTransformCascadeDepth = 0;
|
|
1509
|
+
Node._pendingAfterCascade = [];
|
|
1494
1510
|
Node.protoListenerMap = new Map();
|
|
1495
1511
|
Node.prototype.nodeType = 'Node';
|
|
1496
1512
|
Node.prototype._attrsAffectingSize = [];
|
package/lib/Shape.js
CHANGED
|
@@ -355,6 +355,7 @@ export class Shape extends Node {
|
|
|
355
355
|
bufferContext.clear();
|
|
356
356
|
}
|
|
357
357
|
bufferContext.save();
|
|
358
|
+
bufferContext.imageSmoothingEnabled = context.imageSmoothingEnabled;
|
|
358
359
|
bufferContext._applyLineJoin(this);
|
|
359
360
|
bufferContext._applyMiterLimit(this);
|
|
360
361
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
package/lib/Tween.js
CHANGED
|
@@ -10,6 +10,12 @@ const blacklist = {
|
|
|
10
10
|
yoyo: 1,
|
|
11
11
|
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
12
12
|
let idCounter = 0;
|
|
13
|
+
function colorToRGBA(color) {
|
|
14
|
+
return (Util.colorToRGBA(color) ||
|
|
15
|
+
Util.throw('can not tween the color "' +
|
|
16
|
+
color +
|
|
17
|
+
'", because it is not a valid color.'));
|
|
18
|
+
}
|
|
13
19
|
class TweenEngine {
|
|
14
20
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
15
21
|
this.prop = prop;
|
|
@@ -197,8 +203,8 @@ export class Tween {
|
|
|
197
203
|
diff.push(end[n] - start[n]);
|
|
198
204
|
}
|
|
199
205
|
else {
|
|
200
|
-
const startRGBA =
|
|
201
|
-
endRGBA =
|
|
206
|
+
const startRGBA = colorToRGBA(start[n]);
|
|
207
|
+
endRGBA = colorToRGBA(end[n]);
|
|
202
208
|
start[n] = startRGBA;
|
|
203
209
|
diff.push({
|
|
204
210
|
r: endRGBA.r - startRGBA.r,
|
|
@@ -216,8 +222,8 @@ export class Tween {
|
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
else if (colorAttrs.indexOf(key) !== -1) {
|
|
219
|
-
start =
|
|
220
|
-
endRGBA =
|
|
225
|
+
start = colorToRGBA(start);
|
|
226
|
+
endRGBA = colorToRGBA(end);
|
|
221
227
|
diff = {
|
|
222
228
|
r: endRGBA.r - start.r,
|
|
223
229
|
g: endRGBA.g - start.g,
|
package/lib/Util.d.ts
CHANGED
package/lib/Util.js
CHANGED
|
@@ -165,7 +165,7 @@ export class Transform {
|
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ',
|
|
168
|
+
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', COLORS = {
|
|
169
169
|
aliceblue: [240, 248, 255],
|
|
170
170
|
antiquewhite: [250, 235, 215],
|
|
171
171
|
aqua: [0, 255, 255],
|
|
@@ -189,7 +189,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
189
189
|
cyan: [0, 255, 255],
|
|
190
190
|
darkblue: [0, 0, 139],
|
|
191
191
|
darkcyan: [0, 139, 139],
|
|
192
|
-
darkgoldenrod: [184,
|
|
192
|
+
darkgoldenrod: [184, 134, 11],
|
|
193
193
|
darkgray: [169, 169, 169],
|
|
194
194
|
darkgreen: [0, 100, 0],
|
|
195
195
|
darkgrey: [169, 169, 169],
|
|
@@ -212,7 +212,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
212
212
|
dimgrey: [105, 105, 105],
|
|
213
213
|
dodgerblue: [30, 144, 255],
|
|
214
214
|
firebrick: [178, 34, 34],
|
|
215
|
-
floralwhite: [255,
|
|
215
|
+
floralwhite: [255, 250, 240],
|
|
216
216
|
forestgreen: [34, 139, 34],
|
|
217
217
|
fuchsia: [255, 0, 255],
|
|
218
218
|
gainsboro: [220, 220, 220],
|
|
@@ -282,7 +282,7 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
282
282
|
peachpuff: [255, 218, 185],
|
|
283
283
|
peru: [205, 133, 63],
|
|
284
284
|
pink: [255, 192, 203],
|
|
285
|
-
plum: [221, 160,
|
|
285
|
+
plum: [221, 160, 221],
|
|
286
286
|
powderblue: [176, 224, 230],
|
|
287
287
|
purple: [128, 0, 128],
|
|
288
288
|
rebeccapurple: [102, 51, 153],
|
|
@@ -298,9 +298,9 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
298
298
|
silver: [192, 192, 192],
|
|
299
299
|
skyblue: [135, 206, 235],
|
|
300
300
|
slateblue: [106, 90, 205],
|
|
301
|
-
slategray: [
|
|
302
|
-
slategrey: [
|
|
303
|
-
snow: [255,
|
|
301
|
+
slategray: [112, 128, 144],
|
|
302
|
+
slategrey: [112, 128, 144],
|
|
303
|
+
snow: [255, 250, 250],
|
|
304
304
|
springgreen: [0, 255, 127],
|
|
305
305
|
steelblue: [70, 130, 180],
|
|
306
306
|
tan: [210, 180, 140],
|
|
@@ -314,14 +314,39 @@ const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT
|
|
|
314
314
|
white: [255, 255, 255],
|
|
315
315
|
whitesmoke: [245, 245, 245],
|
|
316
316
|
yellow: [255, 255, 0],
|
|
317
|
-
yellowgreen: [154, 205,
|
|
318
|
-
}
|
|
317
|
+
yellowgreen: [154, 205, 50],
|
|
318
|
+
};
|
|
319
319
|
let animQueue = [];
|
|
320
320
|
let _isCanvasFarblingActive = null;
|
|
321
321
|
const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
|
|
322
322
|
function (f) {
|
|
323
323
|
setTimeout(f, 16);
|
|
324
324
|
};
|
|
325
|
+
const capitalizeCache = new Map();
|
|
326
|
+
const splitColorComponents = (str) => {
|
|
327
|
+
const components = str.trim();
|
|
328
|
+
return components.indexOf(',') === -1
|
|
329
|
+
? components.split(/\s*\/\s*|\s+/)
|
|
330
|
+
: components.split(/\s*,\s*/);
|
|
331
|
+
};
|
|
332
|
+
const NUMBER_SOURCE = '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?';
|
|
333
|
+
const COLOR_COMPONENT_REGEX = new RegExp(`^(${NUMBER_SOURCE})(%?)$`, 'i');
|
|
334
|
+
const parseColorComponent = (value, max) => {
|
|
335
|
+
const match = COLOR_COMPONENT_REGEX.exec(value);
|
|
336
|
+
if (!match) {
|
|
337
|
+
return NaN;
|
|
338
|
+
}
|
|
339
|
+
return match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
|
|
340
|
+
};
|
|
341
|
+
const HEX_COLOR_REGEX = /^#[0-9a-f]+$/i;
|
|
342
|
+
const clamp01 = (value) => Math.min(Math.max(value, 0), 1);
|
|
343
|
+
const HUE_REGEX = new RegExp(`^(${NUMBER_SOURCE})(deg|grad|rad|turn)?$`, 'i');
|
|
344
|
+
const HUE_UNITS = {
|
|
345
|
+
deg: 1,
|
|
346
|
+
grad: 0.9,
|
|
347
|
+
rad: DEG180_OVER_PI,
|
|
348
|
+
turn: 360,
|
|
349
|
+
};
|
|
325
350
|
export const Util = {
|
|
326
351
|
_isElement(obj) {
|
|
327
352
|
return !!(obj && obj.nodeType == 1);
|
|
@@ -480,44 +505,22 @@ export const Util = {
|
|
|
480
505
|
this._rgbToHex(Math.round(rgb.r / 5) * 5, Math.round(rgb.g / 5) * 5, Math.round(rgb.b / 5) * 5));
|
|
481
506
|
},
|
|
482
507
|
getRGB(color) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return {
|
|
487
|
-
r: rgb[0],
|
|
488
|
-
g: rgb[1],
|
|
489
|
-
b: rgb[2],
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
else if (color[0] === HASH) {
|
|
493
|
-
return this._hexToRgb(color.substring(1));
|
|
494
|
-
}
|
|
495
|
-
else if (color.substr(0, 4) === RGB_PAREN) {
|
|
496
|
-
rgb = RGB_REGEX.exec(color.replace(/ /g, ''));
|
|
497
|
-
return {
|
|
498
|
-
r: parseInt(rgb[1], 10),
|
|
499
|
-
g: parseInt(rgb[2], 10),
|
|
500
|
-
b: parseInt(rgb[3], 10),
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
return {
|
|
505
|
-
r: 0,
|
|
506
|
-
g: 0,
|
|
507
|
-
b: 0,
|
|
508
|
-
};
|
|
509
|
-
}
|
|
508
|
+
var _a;
|
|
509
|
+
const { r = 0, g = 0, b = 0 } = (_a = Util.colorToRGBA(color)) !== null && _a !== void 0 ? _a : {};
|
|
510
|
+
return { r, g, b };
|
|
510
511
|
},
|
|
511
512
|
colorToRGBA(str) {
|
|
512
|
-
str = str || 'black';
|
|
513
|
-
|
|
513
|
+
str = (str || '').trim() || 'black';
|
|
514
|
+
const color = Util._namedColorToRBA(str) ||
|
|
514
515
|
Util._hex3ColorToRGBA(str) ||
|
|
515
516
|
Util._hex4ColorToRGBA(str) ||
|
|
516
517
|
Util._hex6ColorToRGBA(str) ||
|
|
517
518
|
Util._hex8ColorToRGBA(str) ||
|
|
518
519
|
Util._rgbColorToRGBA(str) ||
|
|
519
|
-
Util.
|
|
520
|
-
|
|
520
|
+
Util._hslColorToRGBA(str);
|
|
521
|
+
if (color && [color.r, color.g, color.b, color.a].every(Util._isNumber)) {
|
|
522
|
+
return color;
|
|
523
|
+
}
|
|
521
524
|
},
|
|
522
525
|
_namedColorToRBA(str) {
|
|
523
526
|
const c = COLORS[str.toLowerCase()];
|
|
@@ -528,40 +531,27 @@ export const Util = {
|
|
|
528
531
|
r: c[0],
|
|
529
532
|
g: c[1],
|
|
530
533
|
b: c[2],
|
|
531
|
-
a: 1,
|
|
534
|
+
a: c.length > 3 ? c[3] : 1,
|
|
532
535
|
};
|
|
533
536
|
},
|
|
534
537
|
_rgbColorToRGBA(str) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return {
|
|
539
|
-
r: parts[0],
|
|
540
|
-
g: parts[1],
|
|
541
|
-
b: parts[2],
|
|
542
|
-
a: 1,
|
|
543
|
-
};
|
|
538
|
+
const match = /^rgba?\(([^)]*)\)$/i.exec(str);
|
|
539
|
+
if (!match) {
|
|
540
|
+
return;
|
|
544
541
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
549
|
-
const parts = str.split(/ *, */).map((n, index) => {
|
|
550
|
-
if (n.slice(-1) === '%') {
|
|
551
|
-
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
552
|
-
}
|
|
553
|
-
return Number(n);
|
|
554
|
-
});
|
|
555
|
-
return {
|
|
556
|
-
r: parts[0],
|
|
557
|
-
g: parts[1],
|
|
558
|
-
b: parts[2],
|
|
559
|
-
a: parts[3],
|
|
560
|
-
};
|
|
542
|
+
const parts = splitColorComponents(match[1]);
|
|
543
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
544
|
+
return;
|
|
561
545
|
}
|
|
546
|
+
return {
|
|
547
|
+
r: parseColorComponent(parts[0], 255),
|
|
548
|
+
g: parseColorComponent(parts[1], 255),
|
|
549
|
+
b: parseColorComponent(parts[2], 255),
|
|
550
|
+
a: parts.length > 3 ? parseColorComponent(parts[3], 1) : 1,
|
|
551
|
+
};
|
|
562
552
|
},
|
|
563
553
|
_hex8ColorToRGBA(str) {
|
|
564
|
-
if (str
|
|
554
|
+
if (str.length === 9 && HEX_COLOR_REGEX.test(str)) {
|
|
565
555
|
return {
|
|
566
556
|
r: parseInt(str.slice(1, 3), 16),
|
|
567
557
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -571,7 +561,7 @@ export const Util = {
|
|
|
571
561
|
}
|
|
572
562
|
},
|
|
573
563
|
_hex6ColorToRGBA(str) {
|
|
574
|
-
if (str
|
|
564
|
+
if (str.length === 7 && HEX_COLOR_REGEX.test(str)) {
|
|
575
565
|
return {
|
|
576
566
|
r: parseInt(str.slice(1, 3), 16),
|
|
577
567
|
g: parseInt(str.slice(3, 5), 16),
|
|
@@ -581,7 +571,7 @@ export const Util = {
|
|
|
581
571
|
}
|
|
582
572
|
},
|
|
583
573
|
_hex4ColorToRGBA(str) {
|
|
584
|
-
if (str
|
|
574
|
+
if (str.length === 5 && HEX_COLOR_REGEX.test(str)) {
|
|
585
575
|
return {
|
|
586
576
|
r: parseInt(str[1] + str[1], 16),
|
|
587
577
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -591,7 +581,7 @@ export const Util = {
|
|
|
591
581
|
}
|
|
592
582
|
},
|
|
593
583
|
_hex3ColorToRGBA(str) {
|
|
594
|
-
if (str
|
|
584
|
+
if (str.length === 4 && HEX_COLOR_REGEX.test(str)) {
|
|
595
585
|
return {
|
|
596
586
|
r: parseInt(str[1] + str[1], 16),
|
|
597
587
|
g: parseInt(str[2] + str[2], 16),
|
|
@@ -601,60 +591,59 @@ export const Util = {
|
|
|
601
591
|
}
|
|
602
592
|
},
|
|
603
593
|
_hslColorToRGBA(str) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
594
|
+
const match = /^hsla?\(([^)]*)\)$/i.exec(str);
|
|
595
|
+
if (!match) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const parts = splitColorComponents(match[1]);
|
|
599
|
+
if (parts.length < 3 || parts.length > 4) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const hue = HUE_REGEX.exec(parts[0]);
|
|
603
|
+
if (!hue) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const unit = hue[2];
|
|
607
|
+
const degrees = Number(hue[1]) * (unit ? HUE_UNITS[unit.toLowerCase()] : 1);
|
|
608
|
+
if (!isFinite(degrees)) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
const h = (((degrees % 360) + 360) % 360) / 360;
|
|
612
|
+
const s = clamp01(parseColorComponent(parts[1], 100) / 100);
|
|
613
|
+
const l = clamp01(parseColorComponent(parts[2], 100) / 100);
|
|
614
|
+
const a = parts.length > 3 ? parseColorComponent(parts[3], 1) : 1;
|
|
615
|
+
const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
616
|
+
const t1 = 2 * l - t2;
|
|
617
|
+
const rgb = [0, 0, 0];
|
|
618
|
+
for (let i = 0; i < 3; i++) {
|
|
619
|
+
let t3 = h + (1 / 3) * -(i - 1);
|
|
620
|
+
if (t3 < 0) {
|
|
621
|
+
t3++;
|
|
622
|
+
}
|
|
623
|
+
if (t3 > 1) {
|
|
624
|
+
t3--;
|
|
625
|
+
}
|
|
611
626
|
let val;
|
|
612
|
-
if (
|
|
613
|
-
val =
|
|
614
|
-
return {
|
|
615
|
-
r: Math.round(val),
|
|
616
|
-
g: Math.round(val),
|
|
617
|
-
b: Math.round(val),
|
|
618
|
-
a: 1,
|
|
619
|
-
};
|
|
627
|
+
if (6 * t3 < 1) {
|
|
628
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
620
629
|
}
|
|
621
|
-
if (
|
|
622
|
-
|
|
630
|
+
else if (2 * t3 < 1) {
|
|
631
|
+
val = t2;
|
|
623
632
|
}
|
|
624
|
-
else {
|
|
625
|
-
|
|
633
|
+
else if (3 * t3 < 2) {
|
|
634
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
626
635
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
for (let i = 0; i < 3; i++) {
|
|
630
|
-
t3 = h + (1 / 3) * -(i - 1);
|
|
631
|
-
if (t3 < 0) {
|
|
632
|
-
t3++;
|
|
633
|
-
}
|
|
634
|
-
if (t3 > 1) {
|
|
635
|
-
t3--;
|
|
636
|
-
}
|
|
637
|
-
if (6 * t3 < 1) {
|
|
638
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
639
|
-
}
|
|
640
|
-
else if (2 * t3 < 1) {
|
|
641
|
-
val = t2;
|
|
642
|
-
}
|
|
643
|
-
else if (3 * t3 < 2) {
|
|
644
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
val = t1;
|
|
648
|
-
}
|
|
649
|
-
rgb[i] = val * 255;
|
|
636
|
+
else {
|
|
637
|
+
val = t1;
|
|
650
638
|
}
|
|
651
|
-
|
|
652
|
-
r: Math.round(rgb[0]),
|
|
653
|
-
g: Math.round(rgb[1]),
|
|
654
|
-
b: Math.round(rgb[2]),
|
|
655
|
-
a: 1,
|
|
656
|
-
};
|
|
639
|
+
rgb[i] = val * 255;
|
|
657
640
|
}
|
|
641
|
+
return {
|
|
642
|
+
r: Math.round(rgb[0]),
|
|
643
|
+
g: Math.round(rgb[1]),
|
|
644
|
+
b: Math.round(rgb[2]),
|
|
645
|
+
a,
|
|
646
|
+
};
|
|
658
647
|
},
|
|
659
648
|
haveIntersection(r1, r2) {
|
|
660
649
|
return !(r2.x > r1.x + r1.width ||
|
|
@@ -698,7 +687,12 @@ export const Util = {
|
|
|
698
687
|
return Konva.angleDeg ? Util.radToDeg(radians) : radians;
|
|
699
688
|
},
|
|
700
689
|
_capitalize(str) {
|
|
701
|
-
|
|
690
|
+
const cached = capitalizeCache.get(str);
|
|
691
|
+
if (cached !== undefined)
|
|
692
|
+
return cached;
|
|
693
|
+
const out = str.charAt(0).toUpperCase() + str.slice(1);
|
|
694
|
+
capitalizeCache.set(str, out);
|
|
695
|
+
return out;
|
|
702
696
|
},
|
|
703
697
|
throw(str) {
|
|
704
698
|
throw new Error(KONVA_ERROR + str);
|
package/lib/_CoreInternals.d.ts
CHANGED
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -93,12 +93,6 @@ export declare const Konva: {
|
|
|
93
93
|
b: number;
|
|
94
94
|
a: number;
|
|
95
95
|
} | undefined;
|
|
96
|
-
_rgbaColorToRGBA(str: string): {
|
|
97
|
-
r: number;
|
|
98
|
-
g: number;
|
|
99
|
-
b: number;
|
|
100
|
-
a: number;
|
|
101
|
-
} | undefined;
|
|
102
96
|
_hex8ColorToRGBA(str: string): {
|
|
103
97
|
r: number;
|
|
104
98
|
g: number;
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -28,6 +28,17 @@ export class Arc extends Shape {
|
|
|
28
28
|
const innerRadius = this.innerRadius();
|
|
29
29
|
const outerRadius = this.outerRadius();
|
|
30
30
|
const clockwise = this.clockwise();
|
|
31
|
+
const rawAngle = Konva.getAngle(this.angle());
|
|
32
|
+
if (rawAngle % (Math.PI * 2) === 0) {
|
|
33
|
+
return rawAngle !== 0
|
|
34
|
+
? {
|
|
35
|
+
x: -outerRadius,
|
|
36
|
+
y: -outerRadius,
|
|
37
|
+
width: outerRadius * 2,
|
|
38
|
+
height: outerRadius * 2,
|
|
39
|
+
}
|
|
40
|
+
: { x: innerRadius, y: 0, width: outerRadius - innerRadius, height: 0 };
|
|
41
|
+
}
|
|
31
42
|
const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
32
43
|
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
33
44
|
const boundRightRatio = 1;
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface LineConfig extends ShapeConfig {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
|
|
12
12
|
constructor(config?: Config);
|
|
13
|
+
_hasTension(): boolean;
|
|
14
|
+
_eachTensionSegment(onQuadratic: (x0: number, y0: number, cpx: number, cpy: number, x: number, y: number) => void, onCubic: (x0: number, y0: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) => void): void;
|
|
13
15
|
_sceneFunc(context: Context): void;
|
|
14
16
|
getTensionPoints(): any;
|
|
15
17
|
_getTensionPoints(): number[];
|