mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
commit
d6c6d87b73
@ -2,7 +2,7 @@ import { glob } from './Global';
|
||||
import { Layer } from './Layer';
|
||||
import { IFrame, AnimationFn } from './types';
|
||||
|
||||
var now = (function() {
|
||||
var now = (function(): () => number {
|
||||
if (glob.performance && glob.performance.now) {
|
||||
return function() {
|
||||
return glob.performance.now();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Util } from './Util';
|
||||
import { SceneContext, HitContext, Context } from './Context';
|
||||
import { glob, Konva } from './Global';
|
||||
import { Konva } from './Global';
|
||||
import { Factory } from './Factory';
|
||||
import { getNumberValidator } from './Validators';
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { Util } from './Util';
|
||||
import { Animation } from './Animation';
|
||||
import { Node } from './Node';
|
||||
import { Konva } from './Global';
|
||||
import { Line } from './shapes/Line';
|
||||
|
||||
var blacklist = {
|
||||
node: 1,
|
||||
@ -249,7 +250,7 @@ export class Tween {
|
||||
this.onReset = config.onReset;
|
||||
}
|
||||
_addAttr(key, end) {
|
||||
var node = this.node as any,
|
||||
var node = this.node,
|
||||
nodeId = node._id,
|
||||
start,
|
||||
diff,
|
||||
@ -280,11 +281,11 @@ export class Tween {
|
||||
if (end.length > start.length) {
|
||||
// so in this case we will increase number of starting points
|
||||
trueStart = start;
|
||||
start = Util._prepareArrayForTween(start, end, node.closed());
|
||||
start = Util._prepareArrayForTween(start, end, (node as Line).closed());
|
||||
} else {
|
||||
// in this case we will increase number of eding points
|
||||
trueEnd = end;
|
||||
end = Util._prepareArrayForTween(end, start, node.closed());
|
||||
end = Util._prepareArrayForTween(end, start, (node as Line).closed());
|
||||
}
|
||||
}
|
||||
|
||||
|
28
src/Util.ts
28
src/Util.ts
@ -1,6 +1,6 @@
|
||||
import { glob, Konva } from './Global';
|
||||
import { Node } from './Node';
|
||||
import { IRect } from './types';
|
||||
import { IRect, RGB, RGBA } from './types';
|
||||
|
||||
export type Point = {
|
||||
x: number;
|
||||
@ -500,7 +500,7 @@ export const Util = {
|
||||
/*
|
||||
* cherry-picked utilities from underscore.js
|
||||
*/
|
||||
_isElement(obj: any) {
|
||||
_isElement(obj: any): obj is Element {
|
||||
return !!(obj && obj.nodeType == 1);
|
||||
},
|
||||
_isFunction(obj: any) {
|
||||
@ -512,21 +512,21 @@ export const Util = {
|
||||
_isArray(obj: any) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_ARRAY;
|
||||
},
|
||||
_isNumber(obj: any) {
|
||||
_isNumber(obj: any): obj is number {
|
||||
return (
|
||||
Object.prototype.toString.call(obj) === OBJECT_NUMBER &&
|
||||
!isNaN(obj) &&
|
||||
isFinite(obj)
|
||||
);
|
||||
},
|
||||
_isString(obj: any) {
|
||||
_isString(obj: any): obj is string {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
||||
},
|
||||
_isBoolean(obj: any) {
|
||||
_isBoolean(obj: any): obj is boolean {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_BOOLEAN;
|
||||
},
|
||||
// arrays are objects too
|
||||
isObject(val: any) {
|
||||
isObject(val: any): val is Object {
|
||||
return val instanceof Object;
|
||||
},
|
||||
isValidSelector(selector: any) {
|
||||
@ -616,7 +616,7 @@ export const Util = {
|
||||
_rgbToHex(r: number, g: number, b: number) {
|
||||
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
||||
},
|
||||
_hexToRgb(hex: string) {
|
||||
_hexToRgb(hex: string): RGB {
|
||||
hex = hex.replace(HASH, EMPTY_STRING);
|
||||
var bigint = parseInt(hex, 16);
|
||||
return {
|
||||
@ -658,7 +658,7 @@ export const Util = {
|
||||
* var rgb = Konva.Util.getRGB('#0000ff');
|
||||
* var rgb = Konva.Util.getRGB('rgb(0,0,255)');
|
||||
*/
|
||||
getRGB(color: string) {
|
||||
getRGB(color: string): RGB {
|
||||
var rgb;
|
||||
// color string
|
||||
if (color in COLORS) {
|
||||
@ -690,7 +690,7 @@ export const Util = {
|
||||
},
|
||||
// convert any color string to RGBA object
|
||||
// from https://github.com/component/color-parser
|
||||
colorToRGBA(str: string) {
|
||||
colorToRGBA(str: string): RGBA {
|
||||
str = str || 'black';
|
||||
return (
|
||||
Util._namedColorToRBA(str) ||
|
||||
@ -715,7 +715,7 @@ export const Util = {
|
||||
};
|
||||
},
|
||||
// Parse rgb(n, n, n)
|
||||
_rgbColorToRGBA(str: string) {
|
||||
_rgbColorToRGBA(str: string): RGBA {
|
||||
if (str.indexOf('rgb(') === 0) {
|
||||
str = str.match(/rgb\(([^)]+)\)/)[1];
|
||||
var parts = str.split(/ *, */).map(Number);
|
||||
@ -728,7 +728,7 @@ export const Util = {
|
||||
}
|
||||
},
|
||||
// Parse rgba(n, n, n, n)
|
||||
_rgbaColorToRGBA(str: string) {
|
||||
_rgbaColorToRGBA(str: string): RGBA {
|
||||
if (str.indexOf('rgba(') === 0) {
|
||||
str = str.match(/rgba\(([^)]+)\)/)[1];
|
||||
var parts = str.split(/ *, */).map(Number);
|
||||
@ -741,7 +741,7 @@ export const Util = {
|
||||
}
|
||||
},
|
||||
// Parse #nnnnnn
|
||||
_hex6ColorToRGBA(str: string) {
|
||||
_hex6ColorToRGBA(str: string): RGBA {
|
||||
if (str[0] === '#' && str.length === 7) {
|
||||
return {
|
||||
r: parseInt(str.slice(1, 3), 16),
|
||||
@ -752,7 +752,7 @@ export const Util = {
|
||||
}
|
||||
},
|
||||
// Parse #nnn
|
||||
_hex3ColorToRGBA(str: string) {
|
||||
_hex3ColorToRGBA(str: string): RGBA {
|
||||
if (str[0] === '#' && str.length === 4) {
|
||||
return {
|
||||
r: parseInt(str[1] + str[1], 16),
|
||||
@ -763,7 +763,7 @@ export const Util = {
|
||||
}
|
||||
},
|
||||
// Code adapted from https://github.com/Qix-/color-convert/blob/master/conversions.js#L244
|
||||
_hslColorToRGBA(str: string) {
|
||||
_hslColorToRGBA(str: string): RGBA {
|
||||
// Check hsl() format
|
||||
if (/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(str)) {
|
||||
// Extract h, s, l
|
||||
|
@ -35,7 +35,7 @@ export function alphaComponent(val: number) {
|
||||
|
||||
export function getNumberValidator() {
|
||||
if (Konva.isUnminified) {
|
||||
return function(val: any, attr: string) {
|
||||
return function<T>(val: T, attr: string): T|void {
|
||||
if (!Util._isNumber(val)) {
|
||||
Util.warn(
|
||||
_formatValue(val) +
|
||||
@ -50,7 +50,7 @@ export function getNumberValidator() {
|
||||
}
|
||||
export function getNumberOrAutoValidator() {
|
||||
if (Konva.isUnminified) {
|
||||
return function(val: any, attr: string) {
|
||||
return function<T extends string>(val: T, attr: string): T|void {
|
||||
var isNumber = Util._isNumber(val);
|
||||
var isAuto = val === 'auto';
|
||||
|
||||
|
12
src/types.ts
12
src/types.ts
@ -21,7 +21,7 @@ export interface IRect {
|
||||
export interface IFrame {
|
||||
time: number;
|
||||
timeDiff: number;
|
||||
lastTime: any;
|
||||
lastTime: number;
|
||||
frameRate: number;
|
||||
}
|
||||
|
||||
@ -48,3 +48,13 @@ export enum KonvaNodeEvent {
|
||||
dragmove = 'dragmove',
|
||||
dragend = 'dragend'
|
||||
}
|
||||
|
||||
export interface RGB {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
}
|
||||
|
||||
export interface RGBA extends RGB {
|
||||
a: number;
|
||||
}
|
Loading…
Reference in New Issue
Block a user