mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 21:34:50 +08:00
tests refactor, clean build
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { glob } from './Global';
|
||||
import { Layer } from './Layer';
|
||||
import { glob } from './Global.js';
|
||||
import { Layer } from './Layer.js';
|
||||
import { IFrame, AnimationFn } from './types';
|
||||
import { Util } from './Util';
|
||||
import { Util } from './Util.js';
|
||||
|
||||
var now = (function (): () => number {
|
||||
if (glob.performance && glob.performance.now) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Util } from './Util';
|
||||
import { SceneContext, HitContext, Context } from './Context';
|
||||
import { Konva } from './Global';
|
||||
import { Factory } from './Factory';
|
||||
import { getNumberValidator } from './Validators';
|
||||
import { Util } from './Util.js';
|
||||
import { SceneContext, HitContext, Context } from './Context.js';
|
||||
import { Konva } from './Global.js';
|
||||
import { Factory } from './Factory.js';
|
||||
import { getNumberValidator } from './Validators.js';
|
||||
|
||||
// calculate pixel ratio
|
||||
var _pixelRatio;
|
||||
@@ -12,7 +12,7 @@ function getDevicePixelRatio() {
|
||||
}
|
||||
var canvas = Util.createCanvasElement();
|
||||
var context = canvas.getContext('2d') as any;
|
||||
_pixelRatio = (function() {
|
||||
_pixelRatio = (function () {
|
||||
var devicePixelRatio = Konva._global.devicePixelRatio || 1,
|
||||
backingStoreRatio =
|
||||
context.webkitBackingStorePixelRatio ||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Util } from './Util';
|
||||
import { Factory } from './Factory';
|
||||
import { Node, NodeConfig } from './Node';
|
||||
import { getNumberValidator } from './Validators';
|
||||
import { Factory } from './Factory.js';
|
||||
import { Node, NodeConfig } from './Node.js';
|
||||
import { getNumberValidator } from './Validators.js';
|
||||
|
||||
import { GetSet, IRect } from './types';
|
||||
import { Shape } from './Shape';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas';
|
||||
import { Shape } from './Shape.js';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas.js';
|
||||
|
||||
export interface ContainerConfig extends NodeConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
@@ -27,7 +26,7 @@ export interface ContainerConfig extends NodeConfig {
|
||||
* @@containerParams
|
||||
*/
|
||||
export abstract class Container<
|
||||
ChildType extends Node
|
||||
ChildType extends Node = Node
|
||||
> extends Node<ContainerConfig> {
|
||||
children: Array<ChildType> | undefined = [];
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Util } from './Util';
|
||||
import { Konva } from './Global';
|
||||
import { Canvas } from './Canvas';
|
||||
import { Shape } from './Shape';
|
||||
import { Util } from './Util.js';
|
||||
import { Konva } from './Global.js';
|
||||
import { Canvas } from './Canvas.js';
|
||||
import { Shape } from './Shape.js';
|
||||
|
||||
var COMMA = ',',
|
||||
OPEN_PAREN = '(',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// enter file of limited Konva version with only core functions
|
||||
export { Konva } from './_CoreInternals';
|
||||
import { Konva } from './_CoreInternals';
|
||||
export { Konva } from './_CoreInternals.js';
|
||||
import { Konva } from './_CoreInternals.js';
|
||||
|
||||
export default Konva;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Konva } from './Global';
|
||||
import { Node } from './Node';
|
||||
import { Konva } from './Global.js';
|
||||
import { Node } from './Node.js';
|
||||
import { Vector2d } from './types';
|
||||
import { Util } from './Util';
|
||||
import { Util } from './Util.js';
|
||||
|
||||
export const DD = {
|
||||
get isDragging() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Util } from './Util';
|
||||
import { getComponentValidator } from './Validators';
|
||||
import { Util } from './Util.js';
|
||||
import { getComponentValidator } from './Validators.js';
|
||||
|
||||
var GET = 'get',
|
||||
SET = 'set';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Util } from './Util';
|
||||
import { Layer } from './Layer';
|
||||
import { _registerNode } from './Global';
|
||||
import { Util } from './Util.js';
|
||||
import { Layer } from './Layer.js';
|
||||
import { _registerNode } from './Global.js';
|
||||
|
||||
/**
|
||||
* FastLayer constructor. **DEPRECATED!** Please use `Konva.Layer({ listening: false})` instead. Layers are tied to their own canvas element and are used
|
||||
|
||||
@@ -24,57 +24,6 @@ function detectBrowser() {
|
||||
);
|
||||
}
|
||||
|
||||
const _detectIE = function (ua) {
|
||||
var msie = ua.indexOf('msie ');
|
||||
if (msie > 0) {
|
||||
// IE 10 or older => return version number
|
||||
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
|
||||
}
|
||||
|
||||
var trident = ua.indexOf('trident/');
|
||||
if (trident > 0) {
|
||||
// IE 11 => return version number
|
||||
var rv = ua.indexOf('rv:');
|
||||
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
|
||||
}
|
||||
|
||||
var edge = ua.indexOf('edge/');
|
||||
if (edge > 0) {
|
||||
// Edge (IE 12+) => return version number
|
||||
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
|
||||
}
|
||||
|
||||
// other browser
|
||||
return false;
|
||||
};
|
||||
|
||||
export const _parseUA = function (userAgent) {
|
||||
var ua = userAgent.toLowerCase(),
|
||||
// jQuery UA regex
|
||||
match =
|
||||
/(chrome)[ /]([\w.]+)/.exec(ua) ||
|
||||
/(webkit)[ /]([\w.]+)/.exec(ua) ||
|
||||
/(opera)(?:.*version|)[ /]([\w.]+)/.exec(ua) ||
|
||||
/(msie) ([\w.]+)/.exec(ua) ||
|
||||
(ua.indexOf('compatible') < 0 &&
|
||||
/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua)) ||
|
||||
[],
|
||||
// adding mobile flag as well
|
||||
mobile = !!userAgent.match(
|
||||
/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i
|
||||
),
|
||||
ieMobile = !!userAgent.match(/IEMobile/i);
|
||||
|
||||
return {
|
||||
browser: match[1] || '',
|
||||
version: match[2] || '0',
|
||||
isIE: _detectIE(ua),
|
||||
// adding mobile flab
|
||||
mobile: mobile,
|
||||
ieMobile: ieMobile, // If this is true (i.e., WP8), then Konva touch events are executed instead of equivalent Konva mouse events
|
||||
};
|
||||
};
|
||||
|
||||
declare const WorkerGlobalScope: any;
|
||||
|
||||
export const glob: any =
|
||||
@@ -90,9 +39,9 @@ export const Konva = {
|
||||
_global: glob,
|
||||
version: '@@version',
|
||||
isBrowser: detectBrowser(),
|
||||
isUnminified: /param/.test(function (param) {}.toString()),
|
||||
isUnminified: /param/.test(function (param: any) {}.toString()),
|
||||
dblClickWindow: 400,
|
||||
getAngle(angle) {
|
||||
getAngle(angle: number) {
|
||||
return Konva.angleDeg ? angle * PI_OVER_180 : angle;
|
||||
},
|
||||
enableTrace: false,
|
||||
@@ -210,20 +159,15 @@ export const Konva = {
|
||||
return !!Konva['DD'].node;
|
||||
},
|
||||
// user agent
|
||||
UA: _parseUA((glob.navigator && glob.navigator.userAgent) || ''),
|
||||
document: glob.document,
|
||||
// insert Konva into global namespace (window)
|
||||
// it is required for npm packages
|
||||
_injectGlobal(Konva) {
|
||||
glob.Konva = Konva;
|
||||
},
|
||||
_parseUA,
|
||||
};
|
||||
|
||||
export const _NODES_REGISTRY = {};
|
||||
|
||||
export const _registerNode = (NodeClass) => {
|
||||
_NODES_REGISTRY[NodeClass.prototype.getClassName()] = NodeClass;
|
||||
export const _registerNode = (NodeClass: any) => {
|
||||
Konva[NodeClass.prototype.getClassName()] = NodeClass;
|
||||
};
|
||||
|
||||
|
||||
10
src/Group.ts
10
src/Group.ts
@@ -1,8 +1,8 @@
|
||||
import { Util } from './Util';
|
||||
import { Container } from './Container';
|
||||
import { _registerNode } from './Global';
|
||||
import { Node } from './Node';
|
||||
import { Shape } from './Shape';
|
||||
import { Util } from './Util.js';
|
||||
import { Container } from './Container.js';
|
||||
import { _registerNode } from './Global.js';
|
||||
import { Node } from './Node.js';
|
||||
import { Shape } from './Shape.js';
|
||||
|
||||
/**
|
||||
* Group constructor. Groups are used to contain shapes or other groups.
|
||||
|
||||
20
src/Layer.ts
20
src/Layer.ts
@@ -1,15 +1,15 @@
|
||||
import { Util } from './Util';
|
||||
import { Container, ContainerConfig } from './Container';
|
||||
import { Node } from './Node';
|
||||
import { Factory } from './Factory';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { Stage } from './Stage';
|
||||
import { getBooleanValidator } from './Validators';
|
||||
import { Util } from './Util.js';
|
||||
import { Container, ContainerConfig } from './Container.js';
|
||||
import { Node } from './Node.js';
|
||||
import { Factory } from './Factory.js';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas.js';
|
||||
import { Stage } from './Stage.js';
|
||||
import { getBooleanValidator } from './Validators.js';
|
||||
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { Group } from './Group';
|
||||
import { Shape, shapes } from './Shape';
|
||||
import { _registerNode } from './Global';
|
||||
import { Group } from './Group.js';
|
||||
import { Shape, shapes } from './Shape.js';
|
||||
import { _registerNode } from './Global.js';
|
||||
|
||||
export interface LayerConfig extends ContainerConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
|
||||
74
src/Node.ts
74
src/Node.ts
@@ -1,19 +1,19 @@
|
||||
import { Util, Transform } from './Util';
|
||||
import { Factory } from './Factory';
|
||||
import { SceneCanvas, HitCanvas, Canvas } from './Canvas';
|
||||
import { Konva, _NODES_REGISTRY } from './Global';
|
||||
import { Container } from './Container';
|
||||
import { Util, Transform } from './Util.js';
|
||||
import { Factory } from './Factory.js';
|
||||
import { SceneCanvas, HitCanvas, Canvas } from './Canvas.js';
|
||||
import { Konva } from './Global.js';
|
||||
import { Container } from './Container.js';
|
||||
import { GetSet, Vector2d, IRect } from './types';
|
||||
import { DD } from './DragAndDrop';
|
||||
import { DD } from './DragAndDrop.js';
|
||||
import {
|
||||
getNumberValidator,
|
||||
getStringValidator,
|
||||
getBooleanValidator,
|
||||
} from './Validators';
|
||||
import { Stage } from './Stage';
|
||||
import { Context } from './Context';
|
||||
import { Shape } from './Shape';
|
||||
import { Layer } from './Layer';
|
||||
} from './Validators.js';
|
||||
import { Stage } from './Stage.js';
|
||||
import { Context } from './Context.js';
|
||||
import { Shape } from './Shape.js';
|
||||
import { Layer } from './Layer.js';
|
||||
|
||||
export const ids: any = {};
|
||||
export const names: any = {};
|
||||
@@ -227,10 +227,6 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
return false;
|
||||
}
|
||||
|
||||
getChildren() {
|
||||
return emptyChildren;
|
||||
}
|
||||
|
||||
_clearCache(attr?: string) {
|
||||
// if we want to clear transform cache
|
||||
// we don't really need to remove it from the cache
|
||||
@@ -264,7 +260,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
return cache;
|
||||
}
|
||||
|
||||
_calculate(name, deps, getter) {
|
||||
_calculate(name: string, deps: Array<string>, getter: Function) {
|
||||
// if we are trying to calculate function for the first time
|
||||
// we need to attach listeners for change events
|
||||
if (!this._attachedDepsListeners.get(name)) {
|
||||
@@ -285,7 +281,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* when the logic for a cached result depends on ancestor propagation, use this
|
||||
* method to clear self and children cache
|
||||
*/
|
||||
_clearSelfAndDescendantCache(attr?: string, forceEvent?: boolean) {
|
||||
_clearSelfAndDescendantCache(attr?: string) {
|
||||
this._clearCache(attr);
|
||||
// trigger clear cache, so transformer can use it
|
||||
if (attr === ABSOLUTE_TRANSFORM) {
|
||||
@@ -587,7 +583,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
0,
|
||||
0,
|
||||
hitCanvas.width / hitCanvas.pixelRatio,
|
||||
hitCanvas.height / hitCanvas.pixelRatio,
|
||||
hitCanvas.height / hitCanvas.pixelRatio
|
||||
);
|
||||
context.restore();
|
||||
}
|
||||
@@ -1010,7 +1006,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
isListening() {
|
||||
return this._getCache(LISTENING, this._isListening);
|
||||
}
|
||||
_isListening(relativeTo?: Node) {
|
||||
_isListening(relativeTo?: Node): boolean {
|
||||
const listening = this.listening();
|
||||
if (!listening) {
|
||||
return false;
|
||||
@@ -1039,7 +1035,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
isVisible() {
|
||||
return this._getCache(VISIBLE, this._isVisible);
|
||||
}
|
||||
_isVisible(relativeTo) {
|
||||
_isVisible(relativeTo?: Node): boolean {
|
||||
const visible = this.visible();
|
||||
if (!visible) {
|
||||
return false;
|
||||
@@ -1171,7 +1167,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
this._needClearTransformCache = false;
|
||||
}
|
||||
|
||||
setPosition(pos) {
|
||||
setPosition(pos: Vector2d) {
|
||||
this._batchTransformChanges(() => {
|
||||
this.x(pos.x);
|
||||
this.y(pos.y);
|
||||
@@ -1199,7 +1195,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // so stage transforms are ignored
|
||||
* node.getAbsolutePosition(stage)
|
||||
*/
|
||||
getAbsolutePosition(top?) {
|
||||
getAbsolutePosition(top?: Node) {
|
||||
let haveCachedParent = false;
|
||||
let parent = this.parent;
|
||||
while (parent) {
|
||||
@@ -1224,7 +1220,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
|
||||
return absoluteTransform.getTranslation();
|
||||
}
|
||||
setAbsolutePosition(pos) {
|
||||
setAbsolutePosition(pos: Vector2d) {
|
||||
var origTrans = this._clearTransform();
|
||||
|
||||
// don't clear translation
|
||||
@@ -1300,7 +1296,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* y: 2
|
||||
* });
|
||||
*/
|
||||
move(change) {
|
||||
move(change: Vector2d) {
|
||||
var changeX = change.x,
|
||||
changeY = change.y,
|
||||
x = this.x(),
|
||||
@@ -1350,7 +1346,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* @param {Number} theta
|
||||
* @returns {Konva.Node}
|
||||
*/
|
||||
rotate(theta) {
|
||||
rotate(theta: number) {
|
||||
this.rotation(this.rotation() + theta);
|
||||
return this;
|
||||
}
|
||||
@@ -1479,7 +1475,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // move node from current layer into layer2
|
||||
* node.moveTo(layer2);
|
||||
*/
|
||||
moveTo(newContainer) {
|
||||
moveTo(newContainer: Container) {
|
||||
// do nothing if new container is already parent
|
||||
if (this.getParent() !== newContainer) {
|
||||
this._remove();
|
||||
@@ -1557,7 +1553,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // get one of the parent group
|
||||
* var parentGroups = node.findAncestors('Group');
|
||||
*/
|
||||
findAncestors(selector, includeSelf?, stopNode?) {
|
||||
findAncestors(selector: string, includeSelf?: boolean, stopNode?: Container) {
|
||||
var res: Array<Node> = [];
|
||||
|
||||
if (includeSelf && this._isMatch(selector)) {
|
||||
@@ -1575,7 +1571,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
isAncestorOf(node) {
|
||||
isAncestorOf(node: Node) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
@@ -1590,11 +1586,11 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // get one of the parent group
|
||||
* var group = node.findAncestors('.mygroup');
|
||||
*/
|
||||
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Node) {
|
||||
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container) {
|
||||
return this.findAncestors(selector, includeSelf, stopNode)[0];
|
||||
}
|
||||
// is current node match passed selector?
|
||||
_isMatch(selector) {
|
||||
_isMatch(selector: string | Function) {
|
||||
if (!selector) {
|
||||
return false;
|
||||
}
|
||||
@@ -1687,7 +1683,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // fire click event that bubbles
|
||||
* node.fire('click', null, true);
|
||||
*/
|
||||
fire(eventType, evt: any = {}, bubble?) {
|
||||
fire(eventType: string, evt: any = {}, bubble?: boolean) {
|
||||
evt.target = evt.target || this;
|
||||
// bubble
|
||||
if (bubble) {
|
||||
@@ -1768,7 +1764,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* // get absolute scale x
|
||||
* var scaleX = node.getAbsoluteScale().x;
|
||||
*/
|
||||
getAbsoluteScale(top?) {
|
||||
getAbsoluteScale(top?: Node) {
|
||||
// do not cache this calculations,
|
||||
// because it use cache transform
|
||||
// this is special logic for caching with some shapes with shadow
|
||||
@@ -1872,7 +1868,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* x: 5
|
||||
* });
|
||||
*/
|
||||
clone(obj?) {
|
||||
clone(obj?: any) {
|
||||
// instantiate new node
|
||||
var attrs = Util.cloneObject(this.attrs),
|
||||
key,
|
||||
@@ -2071,7 +2067,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
getType() {
|
||||
return this.nodeType;
|
||||
}
|
||||
getDragDistance() {
|
||||
getDragDistance(): number {
|
||||
// compare with undefined because we need to track 0 value
|
||||
if (this.attrs.dragDistance !== undefined) {
|
||||
return this.attrs.dragDistance;
|
||||
@@ -2435,11 +2431,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
this._lastPos.y !== newNodePos.y
|
||||
) {
|
||||
this.setAbsolutePosition(newNodePos);
|
||||
if (this.getLayer()) {
|
||||
this.getLayer().batchDraw();
|
||||
} else if (this.getStage()) {
|
||||
this.getStage().batchDraw();
|
||||
}
|
||||
this._requestDraw();
|
||||
}
|
||||
|
||||
this._lastPos = newNodePos;
|
||||
@@ -2632,7 +2624,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
obj.attrs.container = container;
|
||||
}
|
||||
|
||||
if (!_NODES_REGISTRY[className]) {
|
||||
if (!Konva[className]) {
|
||||
Util.warn(
|
||||
'Can not find a node with class name "' +
|
||||
className +
|
||||
@@ -2641,7 +2633,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
className = 'Shape';
|
||||
}
|
||||
|
||||
const Class = _NODES_REGISTRY[className];
|
||||
const Class = Konva[className];
|
||||
|
||||
no = new Class(obj.attrs);
|
||||
if (children) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { KonvaEventObject } from './Node';
|
||||
import { Konva } from './Global';
|
||||
import { KonvaEventObject } from './Node.js';
|
||||
import { Konva } from './Global.js';
|
||||
|
||||
import { Shape } from './Shape';
|
||||
import { Stage } from './Stage';
|
||||
import { Shape } from './Shape.js';
|
||||
import { Stage } from './Stage.js';
|
||||
|
||||
const Captures = new Map<number, Shape | Stage>();
|
||||
|
||||
@@ -21,7 +21,7 @@ export function getCapturedShape(pointerId: number) {
|
||||
export function createEvent(evt: PointerEvent): KonvaPointerEvent {
|
||||
return {
|
||||
evt,
|
||||
pointerId: evt.pointerId
|
||||
pointerId: evt.pointerId,
|
||||
} as any;
|
||||
}
|
||||
|
||||
|
||||
18
src/Shape.ts
18
src/Shape.ts
@@ -1,20 +1,20 @@
|
||||
import { Util } from './Util';
|
||||
import { Factory } from './Factory';
|
||||
import { Node, NodeConfig } from './Node';
|
||||
import { Util } from './Util.js';
|
||||
import { Factory } from './Factory.js';
|
||||
import { Node, NodeConfig } from './Node.js';
|
||||
import {
|
||||
getNumberValidator,
|
||||
getNumberOrAutoValidator,
|
||||
getStringValidator,
|
||||
getBooleanValidator,
|
||||
getStringOrGradientValidator,
|
||||
} from './Validators';
|
||||
} from './Validators.js';
|
||||
|
||||
import { Context, SceneContext } from './Context';
|
||||
import { _registerNode } from './Global';
|
||||
import * as PointerEvents from './PointerEvents';
|
||||
import { Context, SceneContext } from './Context.js';
|
||||
import { _registerNode } from './Global.js';
|
||||
import * as PointerEvents from './PointerEvents.js';
|
||||
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas';
|
||||
import { HitCanvas, SceneCanvas } from './Canvas.js';
|
||||
|
||||
// hack from here https://stackoverflow.com/questions/52667959/what-is-the-purpose-of-bivariancehack-in-typescript-types/52668133#52668133
|
||||
export type ShapeConfigHandler<TTarget> = {
|
||||
@@ -202,6 +202,7 @@ export class Shape<
|
||||
* @name Konva.Shape#getContext
|
||||
* @returns {Konva.Context}
|
||||
*/
|
||||
// TODO: remove method
|
||||
getContext() {
|
||||
return this.getLayer().getContext();
|
||||
}
|
||||
@@ -211,6 +212,7 @@ export class Shape<
|
||||
* @name Konva.Shape#getCanvas
|
||||
* @returns {Konva.Canvas}
|
||||
*/
|
||||
// TODO: remove method
|
||||
getCanvas() {
|
||||
return this.getLayer().getCanvas();
|
||||
}
|
||||
|
||||
33
src/Stage.ts
33
src/Stage.ts
@@ -1,14 +1,14 @@
|
||||
import { Util } from './Util';
|
||||
import { Factory } from './Factory';
|
||||
import { Container, ContainerConfig } from './Container';
|
||||
import { Konva } from './Global';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { Util } from './Util.js';
|
||||
import { Factory } from './Factory.js';
|
||||
import { Container, ContainerConfig } from './Container.js';
|
||||
import { Konva } from './Global.js';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas.js';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { Shape } from './Shape';
|
||||
import { Layer } from './Layer';
|
||||
import { DD } from './DragAndDrop';
|
||||
import { _registerNode } from './Global';
|
||||
import * as PointerEvents from './PointerEvents';
|
||||
import { Shape } from './Shape.js';
|
||||
import { Layer } from './Layer.js';
|
||||
import { DD } from './DragAndDrop.js';
|
||||
import { _registerNode } from './Global.js';
|
||||
import * as PointerEvents from './PointerEvents.js';
|
||||
|
||||
export interface StageConfig extends ContainerConfig {
|
||||
container: HTMLDivElement | string;
|
||||
@@ -464,10 +464,7 @@ export class Stage extends Container<Layer> {
|
||||
this._fire(CONTENT_MOUSEOUT, { evt: evt });
|
||||
}
|
||||
_mousemove(evt) {
|
||||
// workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
|
||||
if (Konva.UA.ieMobile) {
|
||||
return this._touchmove(evt);
|
||||
}
|
||||
|
||||
this.setPointersPositions(evt);
|
||||
var pointerId = Util._getFirstPointerId(evt);
|
||||
var targetShape = this.targetShape?.getStage() ? this.targetShape : null;
|
||||
@@ -535,10 +532,6 @@ export class Stage extends Container<Layer> {
|
||||
}
|
||||
}
|
||||
_mousedown(evt) {
|
||||
// workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
|
||||
if (Konva.UA.ieMobile) {
|
||||
return this._touchstart(evt);
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
var pointerId = Util._getFirstPointerId(evt);
|
||||
var shape = this.getIntersection(this.getPointerPosition()) as Shape;
|
||||
@@ -569,10 +562,6 @@ export class Stage extends Container<Layer> {
|
||||
// }
|
||||
}
|
||||
_mouseup(evt) {
|
||||
// workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
|
||||
if (Konva.UA.ieMobile) {
|
||||
return this._touchend(evt);
|
||||
}
|
||||
this.setPointersPositions(evt);
|
||||
var pointerId = Util._getFirstPointerId(evt);
|
||||
var shape = this.getIntersection(this.getPointerPosition()) as Shape,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Util } from './Util';
|
||||
import { Animation } from './Animation';
|
||||
import { Node, NodeConfig } from './Node';
|
||||
import { Konva } from './Global';
|
||||
import { Util } from './Util.js';
|
||||
import { Animation } from './Animation.js';
|
||||
import { Node, NodeConfig } from './Node.js';
|
||||
import { Konva } from './Global.js';
|
||||
import { Line } from './shapes/Line';
|
||||
|
||||
var blacklist = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Konva } from './Global';
|
||||
import { Konva } from './Global.js';
|
||||
import { IRect, RGB, RGBA, Vector2d } from './types';
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Konva } from './Global';
|
||||
import { Util } from './Util';
|
||||
import { Konva } from './Global.js';
|
||||
import { Util } from './Util.js';
|
||||
|
||||
function _formatValue(val: any) {
|
||||
if (Util._isString(val)) {
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
// what is core parts of Konva?
|
||||
import { Konva as Global } from './Global';
|
||||
import { Konva as Global } from './Global.js';
|
||||
|
||||
import { Util, Transform } from './Util';
|
||||
import { Node, ids, names } from './Node';
|
||||
import { Container } from './Container';
|
||||
import { Util, Transform } from './Util.js';
|
||||
import { Node, ids, names } from './Node.js';
|
||||
import { Container } from './Container.js';
|
||||
|
||||
import { Stage, stages } from './Stage';
|
||||
import { Stage, stages } from './Stage.js';
|
||||
|
||||
import { Layer } from './Layer';
|
||||
import { FastLayer } from './FastLayer';
|
||||
import { Layer } from './Layer.js';
|
||||
import { FastLayer } from './FastLayer.js';
|
||||
|
||||
import { Group } from './Group';
|
||||
import { Group } from './Group.js';
|
||||
|
||||
import { DD } from './DragAndDrop';
|
||||
import { DD } from './DragAndDrop.js';
|
||||
|
||||
import { Shape, shapes } from './Shape';
|
||||
import { Shape, shapes } from './Shape.js';
|
||||
|
||||
import { Animation } from './Animation';
|
||||
import { Tween, Easings } from './Tween';
|
||||
import { Animation } from './Animation.js';
|
||||
import { Tween, Easings } from './Tween.js';
|
||||
|
||||
import { Context } from './Context';
|
||||
import { Canvas } from './Canvas';
|
||||
import { Context } from './Context.js';
|
||||
import { Canvas } from './Canvas.js';
|
||||
|
||||
export const Konva = Util._assign(Global, {
|
||||
Util,
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
// we need to import core of the Konva and then extend it with all additional objects
|
||||
|
||||
import { Konva as Core } from './_CoreInternals';
|
||||
import { Konva as Core } from './_CoreInternals.js';
|
||||
|
||||
// shapes
|
||||
import { Arc } from './shapes/Arc';
|
||||
import { Arrow } from './shapes/Arrow';
|
||||
import { Circle } from './shapes/Circle';
|
||||
import { Ellipse } from './shapes/Ellipse';
|
||||
import { Image } from './shapes/Image';
|
||||
import { Label, Tag } from './shapes/Label';
|
||||
import { Line } from './shapes/Line';
|
||||
import { Path } from './shapes/Path';
|
||||
import { Rect } from './shapes/Rect';
|
||||
import { RegularPolygon } from './shapes/RegularPolygon';
|
||||
import { Ring } from './shapes/Ring';
|
||||
import { Sprite } from './shapes/Sprite';
|
||||
import { Star } from './shapes/Star';
|
||||
import { Text } from './shapes/Text';
|
||||
import { TextPath } from './shapes/TextPath';
|
||||
import { Transformer } from './shapes/Transformer';
|
||||
import { Wedge } from './shapes/Wedge';
|
||||
import { Arc } from './shapes/Arc.js';
|
||||
import { Arrow } from './shapes/Arrow.js';
|
||||
import { Circle } from './shapes/Circle.js';
|
||||
import { Ellipse } from './shapes/Ellipse.js';
|
||||
import { Image } from './shapes/Image.js';
|
||||
import { Label, Tag } from './shapes/Label.js';
|
||||
import { Line } from './shapes/Line.js';
|
||||
import { Path } from './shapes/Path.js';
|
||||
import { Rect } from './shapes/Rect.js';
|
||||
import { RegularPolygon } from './shapes/RegularPolygon.js';
|
||||
import { Ring } from './shapes/Ring.js';
|
||||
import { Sprite } from './shapes/Sprite.js';
|
||||
import { Star } from './shapes/Star.js';
|
||||
import { Text } from './shapes/Text.js';
|
||||
import { TextPath } from './shapes/TextPath.js';
|
||||
import { Transformer } from './shapes/Transformer.js';
|
||||
import { Wedge } from './shapes/Wedge.js';
|
||||
|
||||
// filters
|
||||
import { Blur } from './filters/Blur';
|
||||
import { Brighten } from './filters/Brighten';
|
||||
import { Contrast } from './filters/Contrast';
|
||||
import { Emboss } from './filters/Emboss';
|
||||
import { Enhance } from './filters/Enhance';
|
||||
import { Grayscale } from './filters/Grayscale';
|
||||
import { HSL } from './filters/HSL';
|
||||
import { HSV } from './filters/HSV';
|
||||
import { Invert } from './filters/Invert';
|
||||
import { Kaleidoscope } from './filters/Kaleidoscope';
|
||||
import { Mask } from './filters/Mask';
|
||||
import { Noise } from './filters/Noise';
|
||||
import { Pixelate } from './filters/Pixelate';
|
||||
import { Posterize } from './filters/Posterize';
|
||||
import { RGB } from './filters/RGB';
|
||||
import { RGBA } from './filters/RGBA';
|
||||
import { Sepia } from './filters/Sepia';
|
||||
import { Solarize } from './filters/Solarize';
|
||||
import { Threshold } from './filters/Threshold';
|
||||
import { Blur } from './filters/Blur.js';
|
||||
import { Brighten } from './filters/Brighten.js';
|
||||
import { Contrast } from './filters/Contrast.js';
|
||||
import { Emboss } from './filters/Emboss.js';
|
||||
import { Enhance } from './filters/Enhance.js';
|
||||
import { Grayscale } from './filters/Grayscale.js';
|
||||
import { HSL } from './filters/HSL.js';
|
||||
import { HSV } from './filters/HSV.js';
|
||||
import { Invert } from './filters/Invert.js';
|
||||
import { Kaleidoscope } from './filters/Kaleidoscope.js';
|
||||
import { Mask } from './filters/Mask.js';
|
||||
import { Noise } from './filters/Noise.js';
|
||||
import { Pixelate } from './filters/Pixelate.js';
|
||||
import { Posterize } from './filters/Posterize.js';
|
||||
import { RGB } from './filters/RGB.js';
|
||||
import { RGBA } from './filters/RGBA.js';
|
||||
import { Sepia } from './filters/Sepia.js';
|
||||
import { Solarize } from './filters/Solarize.js';
|
||||
import { Threshold } from './filters/Threshold.js';
|
||||
|
||||
export const Konva = Core.Util._assign(Core, {
|
||||
Arc,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
/*
|
||||
the Gauss filter
|
||||
master repo: https://github.com/pavelpower/kineticjsGaussFilter
|
||||
@@ -309,7 +309,7 @@ var mul_table = [
|
||||
265,
|
||||
263,
|
||||
261,
|
||||
259
|
||||
259,
|
||||
];
|
||||
|
||||
var shg_table = [
|
||||
@@ -567,7 +567,7 @@ var shg_table = [
|
||||
24,
|
||||
24,
|
||||
24,
|
||||
24
|
||||
24,
|
||||
];
|
||||
|
||||
function filterGaussBlurRGBA(imageData, radius) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* Brighten Filter.
|
||||
@@ -12,7 +12,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.filters([Konva.Filters.Brighten]);
|
||||
* node.brightness(0.8);
|
||||
*/
|
||||
export const Brighten: Filter = function(imageData) {
|
||||
export const Brighten: Filter = function (imageData) {
|
||||
var brightness = this.brightness() * 255,
|
||||
data = imageData.data,
|
||||
len = data.length,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
/**
|
||||
* Contrast Filter.
|
||||
* @function
|
||||
@@ -12,7 +12,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.contrast(10);
|
||||
*/
|
||||
|
||||
export const Contrast: Filter = function(imageData) {
|
||||
export const Contrast: Filter = function (imageData) {
|
||||
var adjust = Math.pow((this.contrast() + 100) / 100, 2);
|
||||
|
||||
var data = imageData.data,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { Util } from '../Util';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { Util } from '../Util.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
/**
|
||||
* Emboss Filter.
|
||||
* Pixastic Lib - Emboss filter - v0.1.0
|
||||
@@ -18,7 +18,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.embossDirection('right');
|
||||
* node.embossBlend(true);
|
||||
*/
|
||||
export const Emboss: Filter = function(imageData) {
|
||||
export const Emboss: Filter = function (imageData) {
|
||||
// pixastic strength is between 0 and 10. I want it between 0 and 1
|
||||
// pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also,
|
||||
// a max value of greyLevel yields a white emboss, and the min value yields a black
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
||||
// Compute the range of the data
|
||||
@@ -37,7 +37,7 @@ function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
||||
* node.filters([Konva.Filters.Enhance]);
|
||||
* node.enhance(0.4);
|
||||
*/
|
||||
export const Enhance: Filter = function(imageData) {
|
||||
export const Enhance: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nSubPixels = data.length,
|
||||
rMin = data[0],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Filter } from '../Node';
|
||||
import { Filter } from '../Node.js';
|
||||
|
||||
/**
|
||||
* Grayscale Filter
|
||||
@@ -9,7 +9,7 @@ import { Filter } from '../Node';
|
||||
* node.cache();
|
||||
* node.filters([Konva.Filters.Grayscale]);
|
||||
*/
|
||||
export const Grayscale: Filter = function(imageData) {
|
||||
export const Grayscale: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
len = data.length,
|
||||
i,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
Factory.addGetterSetter(
|
||||
Node,
|
||||
@@ -58,7 +58,7 @@ Factory.addGetterSetter(
|
||||
* image.luminance(0.2);
|
||||
*/
|
||||
|
||||
export const HSL: Filter = function(imageData) {
|
||||
export const HSL: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nPixels = data.length,
|
||||
v = 1,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* HSV Filter. Adjusts the hue, saturation and value
|
||||
@@ -14,7 +14,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* image.value(200);
|
||||
*/
|
||||
|
||||
export const HSV: Filter = function(imageData) {
|
||||
export const HSV: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nPixels = data.length,
|
||||
v = Math.pow(2, this.value()),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Filter } from '../Node';
|
||||
import { Filter } from '../Node.js';
|
||||
/**
|
||||
* Invert Filter
|
||||
* @function
|
||||
@@ -8,7 +8,7 @@ import { Filter } from '../Node';
|
||||
* node.cache();
|
||||
* node.filters([Konva.Filters.Invert]);
|
||||
*/
|
||||
export const Invert: Filter = function(imageData) {
|
||||
export const Invert: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
len = data.length,
|
||||
i;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { Util } from '../Util';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { Util } from '../Util.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
/*
|
||||
* ToPolar Filter. Converts image data to polar coordinates. Performs
|
||||
@@ -19,7 +19,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* default is in the middle
|
||||
*/
|
||||
|
||||
var ToPolar = function(src, dst, opt) {
|
||||
var ToPolar = function (src, dst, opt) {
|
||||
var srcPixels = src.data,
|
||||
dstPixels = dst.data,
|
||||
xSize = src.width,
|
||||
@@ -96,7 +96,7 @@ var ToPolar = function(src, dst, opt) {
|
||||
* 0 is no rotation, 360 degrees is a full rotation
|
||||
*/
|
||||
|
||||
var FromPolar = function(src, dst, opt) {
|
||||
var FromPolar = function (src, dst, opt) {
|
||||
var srcPixels = src.data,
|
||||
dstPixels = dst.data,
|
||||
xSize = src.width,
|
||||
@@ -177,7 +177,7 @@ var FromPolar = function(src, dst, opt) {
|
||||
* node.kaleidoscopePower(3);
|
||||
* node.kaleidoscopeAngle(45);
|
||||
*/
|
||||
export const Kaleidoscope: Filter = function(imageData) {
|
||||
export const Kaleidoscope: Filter = function (imageData) {
|
||||
var xSize = imageData.width,
|
||||
ySize = imageData.height;
|
||||
|
||||
@@ -201,7 +201,7 @@ export const Kaleidoscope: Filter = function(imageData) {
|
||||
// Convert thhe original to polar coordinates
|
||||
ToPolar(imageData, scratchData, {
|
||||
polarCenterX: xSize / 2,
|
||||
polarCenterY: ySize / 2
|
||||
polarCenterY: ySize / 2,
|
||||
});
|
||||
|
||||
// Determine how big each section will be, if it's too small
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
function pixelAt(idata, x, y) {
|
||||
var idx = (y * idata.width + x) * 4;
|
||||
@@ -60,7 +60,7 @@ function backgroundMask(idata, threshold) {
|
||||
var d = rgbDistance(mean, [
|
||||
idata.data[i * 4],
|
||||
idata.data[i * 4 + 1],
|
||||
idata.data[i * 4 + 2]
|
||||
idata.data[i * 4 + 2],
|
||||
]);
|
||||
mask[i] = d < thres ? 0 : 255;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ function smoothEdgeMask(mask, sw, sh) {
|
||||
* node.filters([Konva.Filters.Mask]);
|
||||
* node.threshold(200);
|
||||
*/
|
||||
export const Mask: Filter = function(imageData) {
|
||||
export const Mask: Filter = function (imageData) {
|
||||
// Detect pixels close to the background color
|
||||
var threshold = this.threshold(),
|
||||
mask = backgroundMask(imageData, threshold);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* Noise Filter. Randomly adds or substracts to the color channels
|
||||
@@ -14,7 +14,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.filters([Konva.Filters.Noise]);
|
||||
* node.noise(0.8);
|
||||
*/
|
||||
export const Noise: Filter = function(imageData) {
|
||||
export const Noise: Filter = function (imageData) {
|
||||
var amount = this.noise() * 255,
|
||||
data = imageData.data,
|
||||
nPixels = data.length,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*eslint-disable max-depth */
|
||||
import { Factory } from '../Factory';
|
||||
import { Util } from '../Util';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Util } from '../Util.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* Pixelate Filter. Averages groups of pixels and redraws
|
||||
@@ -18,7 +18,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.pixelSize(10);
|
||||
*/
|
||||
|
||||
export const Pixelate: Filter = function(imageData) {
|
||||
export const Pixelate: Filter = function (imageData) {
|
||||
var pixelSize = Math.ceil(this.pixelSize()),
|
||||
width = imageData.width,
|
||||
height = imageData.height,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
/**
|
||||
* Posterize Filter. Adjusts the channels so that there are no more
|
||||
* than n different values for that channel. This is also applied
|
||||
@@ -16,7 +16,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.levels(0.8); // between 0 and 1
|
||||
*/
|
||||
|
||||
export const Posterize: Filter = function(imageData) {
|
||||
export const Posterize: Filter = function (imageData) {
|
||||
// level must be between 1 and 255
|
||||
var levels = Math.round(this.levels() * 254) + 1,
|
||||
data = imageData.data,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { RGBComponent } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { RGBComponent } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* RGB Filter
|
||||
@@ -16,7 +16,7 @@ import { RGBComponent } from '../Validators';
|
||||
* node.green(200);
|
||||
*/
|
||||
|
||||
export const RGB: Filter = function(imageData) {
|
||||
export const RGB: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nPixels = data.length,
|
||||
red = this.red(),
|
||||
@@ -35,7 +35,7 @@ export const RGB: Filter = function(imageData) {
|
||||
}
|
||||
};
|
||||
|
||||
Factory.addGetterSetter(Node, 'red', 0, function(val) {
|
||||
Factory.addGetterSetter(Node, 'red', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
@@ -54,7 +54,7 @@ Factory.addGetterSetter(Node, 'red', 0, function(val) {
|
||||
* @returns {Integer}
|
||||
*/
|
||||
|
||||
Factory.addGetterSetter(Node, 'green', 0, function(val) {
|
||||
Factory.addGetterSetter(Node, 'green', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { RGBComponent } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { RGBComponent } from '../Validators.js';
|
||||
|
||||
/**
|
||||
* RGBA Filter
|
||||
@@ -17,7 +17,7 @@ import { RGBComponent } from '../Validators';
|
||||
* node.alpha(0.3);
|
||||
*/
|
||||
|
||||
export const RGBA: Filter = function(imageData) {
|
||||
export const RGBA: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nPixels = data.length,
|
||||
red = this.red(),
|
||||
@@ -36,7 +36,7 @@ export const RGBA: Filter = function(imageData) {
|
||||
}
|
||||
};
|
||||
|
||||
Factory.addGetterSetter(Node, 'red', 0, function(val) {
|
||||
Factory.addGetterSetter(Node, 'red', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
@@ -55,7 +55,7 @@ Factory.addGetterSetter(Node, 'red', 0, function(val) {
|
||||
* @returns {Integer}
|
||||
*/
|
||||
|
||||
Factory.addGetterSetter(Node, 'green', 0, function(val) {
|
||||
Factory.addGetterSetter(Node, 'green', 0, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
@@ -84,7 +84,7 @@ Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
|
||||
* @returns {Integer}
|
||||
*/
|
||||
|
||||
Factory.addGetterSetter(Node, 'alpha', 1, function(val) {
|
||||
Factory.addGetterSetter(Node, 'alpha', 1, function (val) {
|
||||
this._filterUpToDate = false;
|
||||
if (val > 1) {
|
||||
return 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Filter } from '../Node';
|
||||
import { Filter } from '../Node.js';
|
||||
|
||||
// based on https://stackoverflow.com/questions/1061093/how-is-a-sepia-tone-created
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Filter } from '../Node';
|
||||
* node.cache();
|
||||
* node.filters([Konva.Filters.Sepia]);
|
||||
*/
|
||||
export const Sepia: Filter = function(imageData) {
|
||||
export const Sepia: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
nPixels = data.length,
|
||||
i,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Filter } from '../Node';
|
||||
import { Filter } from '../Node.js';
|
||||
/**
|
||||
* Solarize Filter
|
||||
* Pixastic Lib - Solarize filter - v0.1.0
|
||||
@@ -13,7 +13,7 @@ import { Filter } from '../Node';
|
||||
* node.filters([Konva.Filters.Solarize]);
|
||||
*/
|
||||
|
||||
export const Solarize: Filter = function(imageData) {
|
||||
export const Solarize: Filter = function (imageData) {
|
||||
var data = imageData.data,
|
||||
w = imageData.width,
|
||||
h = imageData.height,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Node, Filter } from '../Node';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node, Filter } from '../Node.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
/**
|
||||
* Threshold Filter. Pushes any value above the mid point to
|
||||
* the max and any value below the mid point to the min.
|
||||
@@ -16,7 +16,7 @@ import { getNumberValidator } from '../Validators';
|
||||
* node.threshold(0.1);
|
||||
*/
|
||||
|
||||
export const Threshold: Filter = function(imageData) {
|
||||
export const Threshold: Filter = function (imageData) {
|
||||
var level = this.threshold() * 255,
|
||||
data = imageData.data,
|
||||
len = data.length,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// main entry for umd build for rollup
|
||||
import { Konva } from './_FullInternals';
|
||||
import { Konva } from './_FullInternals.js';
|
||||
import * as canvas from 'canvas';
|
||||
|
||||
const isNode = typeof global.document === 'undefined';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Konva } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Konva } from '../Global.js';
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberValidator, getBooleanValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { getNumberValidator, getBooleanValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
export interface ArcConfig extends ShapeConfig {
|
||||
angle: number;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Line, LineConfig } from './Line';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Line, LineConfig } from './Line.js';
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
export interface ArrowConfig extends LineConfig {
|
||||
points: number[];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
export interface CircleConfig extends ShapeConfig {
|
||||
radius?: number;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet, Vector2d } from '../types';
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Util } from '../Util';
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Util } from '../Util.js';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet, IRect } from '../types';
|
||||
import { Context } from '../Context';
|
||||
import { Context } from '../Context.js';
|
||||
|
||||
export interface ImageConfig extends ShapeConfig {
|
||||
image: CanvasImageSource | undefined;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Group } from '../Group';
|
||||
import { ContainerConfig } from '../Container';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Group } from '../Group.js';
|
||||
import { ContainerConfig } from '../Container.js';
|
||||
import {
|
||||
getNumberOrArrayOfNumbersValidator,
|
||||
getNumberValidator,
|
||||
} from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
} from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
import { Text } from './Text';
|
||||
import { Text } from './Text.js';
|
||||
|
||||
export interface LabelConfig extends ContainerConfig {}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Util } from '../Util';
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { getNumberValidator, getNumberArrayValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Util } from '../Util.js';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { getNumberValidator, getNumberArrayValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
import { Context } from '../Context';
|
||||
import { Context } from '../Context.js';
|
||||
|
||||
export interface LineConfig extends ShapeConfig {
|
||||
points?: number[];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberOrArrayOfNumbersValidator } from '../Validators';
|
||||
import { getNumberOrArrayOfNumbersValidator } from '../Validators.js';
|
||||
export interface RectConfig extends ShapeConfig {
|
||||
cornerRadius?: number | number[];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
export interface RegularPolygonConfig extends ShapeConfig {
|
||||
sides: number;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { GetSet } from '../types';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
export interface RingConfig extends ShapeConfig {
|
||||
innerRadius: number;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Animation } from '../Animation';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Animation } from '../Animation.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Util } from '../Util';
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Konva } from '../Global';
|
||||
import { Util } from '../Util.js';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Konva } from '../Global.js';
|
||||
import {
|
||||
getNumberValidator,
|
||||
getStringValidator,
|
||||
getNumberOrAutoValidator,
|
||||
getBooleanValidator,
|
||||
} from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
} from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
|
||||
@@ -379,20 +379,6 @@ export class Text extends Shape<TextConfig> {
|
||||
};
|
||||
}
|
||||
_getContextFont() {
|
||||
// IE don't want to work with usual font style
|
||||
// bold was not working
|
||||
// removing font variant will solve
|
||||
// fix for: https://github.com/konvajs/konva/issues/94
|
||||
if (Konva.UA.isIE) {
|
||||
return (
|
||||
this.fontStyle() +
|
||||
SPACE +
|
||||
this.fontSize() +
|
||||
PX_SPACE +
|
||||
this.fontFamily()
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
this.fontStyle() +
|
||||
SPACE +
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Util } from '../Util';
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Path } from './Path';
|
||||
import { Text, stringToArray } from './Text';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Util } from '../Util.js';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Path } from './Path.js';
|
||||
import { Text, stringToArray } from './Text.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet, Vector2d } from '../types';
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Util, Transform } from '../Util';
|
||||
import { Factory } from '../Factory';
|
||||
import { Node } from '../Node';
|
||||
import { Shape } from '../Shape';
|
||||
import { Rect } from './Rect';
|
||||
import { Group } from '../Group';
|
||||
import { ContainerConfig } from '../Container';
|
||||
import { Konva } from '../Global';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Util, Transform } from '../Util.js';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Node } from '../Node.js';
|
||||
import { Shape } from '../Shape.js';
|
||||
import { Rect } from './Rect.js';
|
||||
import { Group } from '../Group.js';
|
||||
import { ContainerConfig } from '../Container.js';
|
||||
import { Konva } from '../Global.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet, IRect, Vector2d } from '../types';
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { Konva } from '../Global';
|
||||
import { getNumberValidator } from '../Validators';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Factory } from '../Factory.js';
|
||||
import { Shape, ShapeConfig } from '../Shape.js';
|
||||
import { Konva } from '../Global.js';
|
||||
import { getNumberValidator } from '../Validators.js';
|
||||
import { _registerNode } from '../Global.js';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user