mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 13:38:15 +08:00
typescript fixes
This commit is contained in:
parent
a6122178c6
commit
e6282bf73a
4
konva.js
4
konva.js
@ -8,7 +8,7 @@
|
||||
* Konva JavaScript Framework v3.2.4
|
||||
* http://konvajs.org/
|
||||
* Licensed under the MIT
|
||||
* Date: Mon Apr 08 2019
|
||||
* Date: Wed Apr 17 2019
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
@ -3988,7 +3988,7 @@
|
||||
/**
|
||||
* get the node type, which may return Stage, Layer, Group, or Shape
|
||||
* @method
|
||||
* @name Konva.Node#getTranslation
|
||||
* @name Konva.Node#getType
|
||||
* @returns {String}
|
||||
*/
|
||||
Node.prototype.getType = function () {
|
||||
|
2
konva.min.js
vendored
2
konva.min.js
vendored
@ -3,7 +3,7 @@
|
||||
* Konva JavaScript Framework v3.2.4
|
||||
* http://konvajs.org/
|
||||
* Licensed under the MIT
|
||||
* Date: Mon Apr 08 2019
|
||||
* Date: Wed Apr 17 2019
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
|
@ -31,24 +31,24 @@
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-connect": "^5.7.0",
|
||||
"gulp-eslint": "^5.0.0",
|
||||
"gulp-exec": "^3.0.2",
|
||||
"gulp-jscpd": "0.0.8",
|
||||
"gulp-jsdoc3": "^2.0.0",
|
||||
"gulp-rename": "^1.4.0",
|
||||
"gulp-replace": "^1.0.0",
|
||||
"gulp-typescript": "^5.0.1",
|
||||
"gulp-uglify": "^3.0.2",
|
||||
"gulp-util": "^3.0.8",
|
||||
"mocha": "5.2.0",
|
||||
"mocha-headless-chrome": "^2.0.2",
|
||||
"parcel-bundler": "^1.12.3",
|
||||
"prettier": "^1.16.4",
|
||||
"typescript": "^3.4.1",
|
||||
"gulp-exec": "^3.0.2",
|
||||
"gulp-typescript": "^5.0.1",
|
||||
"rollup": "^1.7.4",
|
||||
"rollup-plugin-commonjs": "^9.2.2",
|
||||
"rollup-plugin-node-resolve": "^4.0.1",
|
||||
"rollup-plugin-sourcemaps": "^0.4.2",
|
||||
"rollup-plugin-typescript2": "^0.20.1"
|
||||
"rollup-plugin-typescript2": "^0.20.1",
|
||||
"typescript": "^3.4.3"
|
||||
},
|
||||
"keywords": [
|
||||
"canvas",
|
||||
|
@ -6,6 +6,8 @@ import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { Stage } from './Stage';
|
||||
|
||||
import { GetSet } from './types';
|
||||
import { Group } from './Group';
|
||||
import { Shape } from './Shape';
|
||||
|
||||
export interface LayerConfig extends ContainerConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
@ -23,7 +25,7 @@ export interface LayerConfig extends ContainerConfig {
|
||||
* @@nodeParams
|
||||
* @@containerParams
|
||||
*/
|
||||
export abstract class BaseLayer extends Container {
|
||||
export abstract class BaseLayer extends Container<Group | Shape> {
|
||||
canvas = new SceneCanvas();
|
||||
hitCanvas: HitCanvas;
|
||||
|
||||
|
@ -26,8 +26,10 @@ export interface ContainerConfig extends NodeConfig {
|
||||
* @@nodeParams
|
||||
* @@containerParams
|
||||
*/
|
||||
export abstract class Container extends Node<ContainerConfig> {
|
||||
children = new Collection();
|
||||
export abstract class Container<ChildType extends Node> extends Node<
|
||||
ContainerConfig
|
||||
> {
|
||||
children = new Collection<ChildType>();
|
||||
|
||||
/**
|
||||
* returns a {@link Konva.Collection} of direct descendant nodes
|
||||
@ -113,7 +115,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
* // remember to redraw layer if you changed something
|
||||
* layer.draw();
|
||||
*/
|
||||
add(child: Node) {
|
||||
add(child: ChildType) {
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this.add(arguments[i]);
|
||||
@ -249,7 +251,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
if (!child.hasChildren()) {
|
||||
continue;
|
||||
}
|
||||
shouldStop = (child as Container)._descendants(fn);
|
||||
shouldStop = (child as any)._descendants(fn);
|
||||
if (shouldStop) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { Util, Collection } from './Util';
|
||||
import { Container } from './Container';
|
||||
import { _registerNode } from './Global';
|
||||
import { Node } from './Node';
|
||||
import { Shape } from './Shape';
|
||||
|
||||
/**
|
||||
* Group constructor. Groups are used to contain shapes or other groups.
|
||||
@ -14,8 +15,8 @@ import { Node } from './Node';
|
||||
* @example
|
||||
* var group = new Konva.Group();
|
||||
*/
|
||||
export class Group extends Container {
|
||||
_validateAdd(child) {
|
||||
export class Group extends Container<Group | Shape> {
|
||||
_validateAdd(child: Group | Shape) {
|
||||
var type = child.getType();
|
||||
if (type !== 'Group' && type !== 'Shape') {
|
||||
Util.throw('You may only add groups and shapes to groups.');
|
||||
|
@ -170,7 +170,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
eventListeners = {};
|
||||
attrs: any = {};
|
||||
index = 0;
|
||||
parent: Container | null = null;
|
||||
parent: Container<Node> | null = null;
|
||||
_cache: Map<string, any> = new Map<string, any>();
|
||||
_lastPos = null;
|
||||
_attrsAffectingSize: string[];
|
||||
@ -453,7 +453,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
skipTransform?: boolean;
|
||||
skipShadow?: boolean;
|
||||
skipStroke?: boolean;
|
||||
relativeTo?: Container;
|
||||
relativeTo?: Container<Node>;
|
||||
}): { x: number; y: number; width: number; height: number } {
|
||||
// abstract method
|
||||
// redefine in Container and Shape
|
||||
@ -466,7 +466,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
||||
{ x: rect.x, y: rect.y + rect.height }
|
||||
];
|
||||
var minX, minY, maxX, maxY;
|
||||
var minX: number, minY: number, maxX: number, maxY: number;
|
||||
var trans = this.getAbsoluteTransform(top);
|
||||
points.forEach(function(point) {
|
||||
var transformed = trans.point(point);
|
||||
@ -1877,7 +1877,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
/**
|
||||
* get the node type, which may return Stage, Layer, Group, or Shape
|
||||
* @method
|
||||
* @name Konva.Node#getTranslation
|
||||
* @name Konva.Node#getType
|
||||
* @returns {String}
|
||||
*/
|
||||
getType() {
|
||||
|
@ -109,7 +109,7 @@ function checkNoClip(attrs: any = {}) {
|
||||
* });
|
||||
*/
|
||||
|
||||
export class Stage extends Container {
|
||||
export class Stage extends Container<BaseLayer> {
|
||||
content: HTMLDivElement;
|
||||
pointerPos: Vector2d | null;
|
||||
bufferCanvas: SceneCanvas;
|
||||
@ -120,8 +120,6 @@ export class Stage extends Container {
|
||||
dblTimeout: any;
|
||||
tapStartShape: Shape;
|
||||
|
||||
children: Collection<BaseLayer>;
|
||||
|
||||
constructor(config: StageConfig) {
|
||||
super(checkNoClip(config));
|
||||
this._buildDOM();
|
||||
|
2
src/index-types.d.ts
vendored
2
src/index-types.d.ts
vendored
@ -43,7 +43,7 @@ declare namespace Konva {
|
||||
export type NodeConfig = import('./Node').NodeConfig;
|
||||
|
||||
export const Container: typeof import('./Container').Container;
|
||||
export type Container = import('./Container').Container;
|
||||
export type Container = import('./Container').Container<Node>;
|
||||
export type ContainerConfig = import('./Container').ContainerConfig;
|
||||
|
||||
export const Collection: typeof import('./Util').Collection;
|
||||
|
Loading…
Reference in New Issue
Block a user