Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: check formatting
on:
pull_request:
jobs:
fmt-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
with:
node-version: 'latest'
- run: npm install
- run: npm run fmt:check
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,6 @@ That changes are private and internal specific. They should not break most of `K
Differences from last official `KineticJS` release

- Bug Fixes

- `strokeScaleEnabled = false` is disabled for text as I can not find a way to implement this
- `strokeScaleEnabled = false` for Line now creates a correct hit graph
- working "this-example" as name for nodes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ At the current moment `Konva` doesn't work in IE11 directly. To make it work you

# Debugging

The Chrome inspector simply shows the canvas element. To see the Konva objects and their details, install the konva-dev extension at https://github.com/konvajs/konva-devtool.
The Chrome inspector simply shows the canvas element. To see the Konva objects and their details, install the konva-dev extension at https://github.com/konvajs/konva-devtool.

# Loading and installing Konva

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"start": "npm run test:watch",
"compile": "npm run clean && npm run tsc && cp ./src/index-types.d.ts ./lib/index-types.d.ts && npm run rollup",
"build": "npm run compile && cp ./src/index-types.d.ts ./lib && gulp build && node ./rename-imports.mjs",
"fmt": "prettier --write .",
"fmt:check": "prettier --check .",
"test:import": "npm run build && node ./test/import-test.cjs && node ./test/import-test.mjs",
"test": "npm run test:browser && npm run test:node && npm run test:import",
"test:build": "PARCEL_WORKER_BACKEND=process parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
Expand Down Expand Up @@ -100,6 +102,7 @@
"mocha": "10.2.0",
"mocha-headless-chrome": "^4.0.0",
"parcel": "2.13.3",
"prettier": "^3.6.2",
"process": "^0.11.10",
"rollup": "^4.46.2",
"rollup-plugin-typescript2": "^0.36.0",
Expand All @@ -116,7 +119,8 @@
"html5"
],
"prettier": {
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5"
Copy link
Copy Markdown
Contributor Author

@nathan-muir nathan-muir Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es5 was the prettier default before prettier v3 (now all) [1] This results in much less code churn.

[1] https://prettier.io/docs/options#trailing-commas

},
"bugs": {
"url": "https://github.com/konvajs/konva/issues"
Expand Down
50 changes: 25 additions & 25 deletions resources/jsdoc.conf.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"path" : "ink-docstrap",
"tags" : {
"allowUnknownTags" : true
},
"plugins" : ["plugins/markdown"],
"path": "ink-docstrap",
"tags": {
"allowUnknownTags": true
},
"plugins": ["plugins/markdown"],

"templates" : {
"cleverLinks" : false,
"monospaceLinks" : false,
"dateFormat" : "ddd MMM Do YYYY",
"outputSourceFiles" : true,
"outputSourcePath" : true,
"systemName" : "Konva",
"footer" : "",
"copyright" : "Konva Copyright © 2015 The contributors to the Konva project.",
"navType" : "vertical",
"theme" : "cosmo",
"linenums" : true,
"collapseSymbols" : false,
"inverseNav" : true,
"highlightTutorialCode" : true
},
"markdown" : {
"parser" : "gfm",
"hardwrap" : true
}
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"dateFormat": "ddd MMM Do YYYY",
"outputSourceFiles": true,
"outputSourcePath": true,
"systemName": "Konva",
"footer": "",
"copyright": "Konva Copyright © 2015 The contributors to the Konva project.",
"navType": "vertical",
"theme": "cosmo",
"linenums": true,
"collapseSymbols": false,
"inverseNav": true,
"highlightTutorialCode": true
},
"markdown": {
"parser": "gfm",
"hardwrap": true
}
}
2 changes: 1 addition & 1 deletion src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ContainerConfig extends NodeConfig {
* @@containerParams
*/
export abstract class Container<
ChildType extends Node = Node
ChildType extends Node = Node,
> extends Node<ContainerConfig> {
children: Array<ChildType> = [];

Expand Down
10 changes: 4 additions & 6 deletions src/Factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ type ValidatorFunc<T> = (val: ExtractGetSet<T>, attr: string) => T;
/**
* Extracts the "components" (keys) of a GetSet value. The value must be an object.
*/
type ExtractComponents<T extends Constructor, U extends Attr<T>> = Value<
T,
U
> extends Record<string, any>
? EnforceString<keyof Value<T, U>>[]
: never;
type ExtractComponents<T extends Constructor, U extends Attr<T>> =
Value<T, U> extends Record<string, any>
? EnforceString<keyof Value<T, U>>[]
: never;

export const Factory = {
addGetterSetter<T extends Constructor, U extends Attr<T>>(
Expand Down
8 changes: 4 additions & 4 deletions src/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const glob: any =
typeof global !== 'undefined'
? global
: typeof window !== 'undefined'
? window
: typeof WorkerGlobalScope !== 'undefined'
? self
: {};
? window
: typeof WorkerGlobalScope !== 'undefined'
? self
: {};

export const Konva = {
_global: glob,
Expand Down
2 changes: 1 addition & 1 deletion src/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function _clearRadialGradientCache(this: Node) {
*});
*/
export class Shape<
Config extends ShapeConfig = ShapeConfig
Config extends ShapeConfig = ShapeConfig,
> extends Node<Config> {
_centroid: boolean;
colorKey: string;
Expand Down
27 changes: 14 additions & 13 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,16 +1068,16 @@ export const Util = {
);
context.lineTo(xOrigin, yOrigin + topLeft);
context.arc(
xOrigin + topLeft,
yOrigin + topLeft,
topLeft,
Math.PI,
(Math.PI * 3) / 2,
false
xOrigin + topLeft,
yOrigin + topLeft,
topLeft,
Math.PI,
(Math.PI * 3) / 2,
false
);
},
drawRoundedPolygonPath(
context: Context,
context: Context,
points: Vector2d[],
sides: number,
radius: number,
Expand All @@ -1088,8 +1088,8 @@ export const Util = {
const prev = points[(i - 1 + sides) % sides];
const curr = points[i];
const next = points[(i + 1) % sides];
const vec1 = {x: curr.x - prev.x, y: curr.y - prev.y};
const vec2 = {x: next.x - curr.x, y: next.y - curr.y};
const vec1 = { x: curr.x - prev.x, y: curr.y - prev.y };
const vec2 = { x: next.x - curr.x, y: next.y - curr.y };
const len1 = Math.hypot(vec1.x, vec1.y);
const len2 = Math.hypot(vec2.x, vec2.y);
let currCornerRadius;
Expand All @@ -1100,9 +1100,10 @@ export const Util = {
}
const maxCornerRadius = radius * Math.cos(Math.PI / sides);
// cornerRadius creates perfect circle at 1/2 radius
currCornerRadius = maxCornerRadius * Math.min(1, (currCornerRadius / radius) * 2);
const normalVec1 = {x: vec1.x / len1, y: vec1.y / len1};
const normalVec2 = {x: vec2.x / len2, y: vec2.y / len2};
currCornerRadius =
maxCornerRadius * Math.min(1, (currCornerRadius / radius) * 2);
const normalVec1 = { x: vec1.x / len1, y: vec1.y / len1 };
const normalVec2 = { x: vec2.x / len2, y: vec2.y / len2 };
const p1 = {
x: curr.x - normalVec1.x * currCornerRadius,
y: curr.y - normalVec1.y * currCornerRadius,
Expand All @@ -1118,5 +1119,5 @@ export const Util = {
}
context.arcTo(curr.x, curr.y, p2.x, p2.y, currCornerRadius);
}
}
},
};
2 changes: 1 addition & 1 deletion src/filters/Emboss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Emboss: Filter = function (imageData) {
w = imageData.width,
h = imageData.height,
w4 = w * 4;
let dirY = 0,
let dirY = 0,
dirX = 0,
y = h;

Expand Down
8 changes: 7 additions & 1 deletion src/filters/Enhance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Factory } from '../Factory';
import { Node, Filter } from '../Node';
import { getNumberValidator } from '../Validators';

function remap(fromValue: number, fromMin: number, fromMax: number, toMin: number, toMax: number) {
function remap(
fromValue: number,
fromMin: number,
fromMax: number,
toMin: number,
toMax: number
) {
// Compute the range of the data
const fromRange = fromMax - fromMin,
toRange = toMax - toMin;
Expand Down
3 changes: 2 additions & 1 deletion src/filters/Kaleidoscope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const FromPolar = function (src, dst, opt) {
const dx = x - xMid;
const dy = y - yMid;
const radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
let theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
let theta =
((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
theta = (theta * tSize) / 360;
x1 = Math.floor(theta);
y1 = Math.floor(radius);
Expand Down
12 changes: 11 additions & 1 deletion src/filters/Mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,17 @@ function dilateMask(mask, sw, sh) {
}

function smoothEdgeMask(mask, sw: number, sh: number) {
const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
const weights = [
1 / 9,
1 / 9,
1 / 9,
1 / 9,
1 / 9,
1 / 9,
1 / 9,
1 / 9,
1 / 9,
];
const side = Math.round(Math.sqrt(weights.length));
const halfSide = Math.floor(side / 2);

Expand Down
2 changes: 1 addition & 1 deletion src/shapes/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface LineConfig extends ShapeConfig {
*/

export class Line<
Config extends LineConfig = LineConfig
Config extends LineConfig = LineConfig,
> extends Shape<Config> {
constructor(config?: Config) {
super(config);
Expand Down
5 changes: 4 additions & 1 deletion src/shapes/RegularPolygon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { GetSet, Vector2d } from '../types';
import { getNumberOrArrayOfNumbersValidator, getNumberValidator } from '../Validators';
import {
getNumberOrArrayOfNumbersValidator,
getNumberValidator,
} from '../Validators';
import { _registerNode } from '../Global';
import { Context } from '../Context';
import { Util } from '../Util';
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ export class Text extends Shape<TextConfig> {
const str = Util._isString(text)
? text
: text === null || text === undefined
? ''
: text + '';
? ''
: text + '';
this._setAttr(TEXT, str);
return this;
}
Expand Down
Loading