Util
Own Methods
createDOMMatrix(init)
Make a DOMMatrix of the canvas library Konva draws with. Without a createDOMMatrix in Konva.setCanvasBackend(), the class comes from the library's own context.
Parameters:
init(Array) (optional): the six numbers a, b, c, d, e, f
Returns: DOMMatrix
createPath2D(path)
Make a Path2D of the canvas library Konva draws with, for example for a clipFunc. Without a createPath2D in Konva.setCanvasBackend(), it is the global Path2D.
Parameters:
path(String) (optional): SVG path data
Returns: Path2D
getRandomColor()
return random hex color
Example:
shape.fill(Konva.Util.getRandomColor());
isCanvasFarblingActive()
Check if canvas farbling is active (e.g., Brave browser fingerprinting protection)
Returns: Boolean
getHitColor()
Get a random color for hit detection (snapped to the hit color grid)
Returns: String hex color string
getHitColorKey(r, g, b)
Get hit color key from RGB values (snapped to the hit color grid)
Parameters:
r(Number): red component (0-255)g(Number): green component (0-255)b(Number): blue component (0-255)
Returns: String hex color key string
getSnappedHexColor(hex)
Snap a hex color to the hit color grid
Parameters:
hex(String): hex color string (e.g., "#ff00ff")
Returns: String snapped hex color string
getRGB(color)
get RGB components of a color
Parameters:
color(String)
Example:
// each of the following examples return {r:0, g:0, b:255}
var rgb = Konva.Util.getRGB('blue');
var rgb = Konva.Util.getRGB('#0000ff');
var rgb = Konva.Util.getRGB('rgb(0,0,255)');
haveIntersection(r1, r2)
check intersection of two client rectangles
Parameters:
r1(Object): { x, y, width, height } client rectangler2(Object): { x, y, width, height } client rectangle
Example:
const overlapping = Konva.Util.haveIntersection(shape1.getClientRect(), shape2.getClientRect());