From 01134dcf2adf5a84898402199abbff3bf048a7a1 Mon Sep 17 00:00:00 2001 From: Tim de Koning Date: Mon, 8 Aug 2022 12:19:47 +0200 Subject: [PATCH 1/2] Allow line points to be of type TypedArray. --- src/Validators.ts | 3 +++ src/shapes/Line.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Validators.ts b/src/Validators.ts index a41e6537..48da4d2d 100644 --- a/src/Validators.ts +++ b/src/Validators.ts @@ -142,6 +142,9 @@ export function getFunctionValidator() { export function getNumberArrayValidator() { if (Konva.isUnminified) { return function (val: any, attr: string) { + if (val instanceof Uint8Array || val instanceof Uint16Array || val instanceof Uint32Array || val instanceof Uint8ClampedArray) { + return val + } if (!Util._isArray(val)) { Util.warn( _formatValue(val) + diff --git a/src/shapes/Line.ts b/src/shapes/Line.ts index df80694c..fb3340d1 100644 --- a/src/shapes/Line.ts +++ b/src/shapes/Line.ts @@ -51,7 +51,7 @@ function expandPoints(p, tension) { } export interface LineConfig extends ShapeConfig { - points?: number[]; + points?: number[] | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray; tension?: number; closed?: boolean; bezier?: boolean; From f6d077b3ec545b05d259c20f8f49f2fe044dcfbe Mon Sep 17 00:00:00 2001 From: Tim de Koning Date: Mon, 8 Aug 2022 15:55:43 +0200 Subject: [PATCH 2/2] - Allow all TypedArrays - Validator should not crash when TypedArray is not available --- src/Validators.ts | 5 ++++- src/shapes/Line.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Validators.ts b/src/Validators.ts index 48da4d2d..bbc861b2 100644 --- a/src/Validators.ts +++ b/src/Validators.ts @@ -142,7 +142,10 @@ export function getFunctionValidator() { export function getNumberArrayValidator() { if (Konva.isUnminified) { return function (val: any, attr: string) { - if (val instanceof Uint8Array || val instanceof Uint16Array || val instanceof Uint32Array || val instanceof Uint8ClampedArray) { + // Retrieve TypedArray constructor as found in MDN (if TypedArray is available) + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description + const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null; + if (TypedArray && val instanceof TypedArray) { return val } if (!Util._isArray(val)) { diff --git a/src/shapes/Line.ts b/src/shapes/Line.ts index fb3340d1..09fa8ccb 100644 --- a/src/shapes/Line.ts +++ b/src/shapes/Line.ts @@ -51,7 +51,7 @@ function expandPoints(p, tension) { } export interface LineConfig extends ShapeConfig { - points?: number[] | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray; + points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; tension?: number; closed?: boolean; bezier?: boolean;