mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
type fixes. close #1692
This commit is contained in:
parent
813cd4f780
commit
a8efcd554a
@ -270,7 +270,7 @@ export abstract class Container<
|
|||||||
obj.children = [];
|
obj.children = [];
|
||||||
|
|
||||||
this.getChildren().forEach((child) => {
|
this.getChildren().forEach((child) => {
|
||||||
obj.children.push(child.toObject());
|
obj.children!.push(child.toObject());
|
||||||
});
|
});
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
29
src/Node.ts
29
src/Node.ts
@ -60,6 +60,8 @@ export interface NodeConfig {
|
|||||||
opacity?: number;
|
opacity?: number;
|
||||||
scale?: Vector2d;
|
scale?: Vector2d;
|
||||||
scaleX?: number;
|
scaleX?: number;
|
||||||
|
skewX?: number;
|
||||||
|
skewY?: number;
|
||||||
scaleY?: number;
|
scaleY?: number;
|
||||||
rotation?: number;
|
rotation?: number;
|
||||||
rotationDeg?: number;
|
rotationDeg?: number;
|
||||||
@ -911,7 +913,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
getAttrs() {
|
getAttrs() {
|
||||||
return this.attrs || {};
|
return (this.attrs || {}) as Config & Record<string, any>;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* set multiple attrs at once using an object literal
|
* set multiple attrs at once using an object literal
|
||||||
@ -1481,15 +1483,21 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
toObject() {
|
toObject() {
|
||||||
var obj = {} as any,
|
var attrs = this.getAttrs() as any,
|
||||||
attrs = this.getAttrs(),
|
|
||||||
key,
|
key,
|
||||||
val,
|
val,
|
||||||
getter,
|
getter,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
nonPlainObject;
|
nonPlainObject;
|
||||||
|
|
||||||
obj.attrs = {};
|
const obj: {
|
||||||
|
attrs: Config & Record<string, any>;
|
||||||
|
className: string;
|
||||||
|
children?: Array<any>;
|
||||||
|
} = {
|
||||||
|
attrs: {} as Config & Record<string, any>,
|
||||||
|
className: this.getClassName(),
|
||||||
|
};
|
||||||
|
|
||||||
for (key in attrs) {
|
for (key in attrs) {
|
||||||
val = attrs[key];
|
val = attrs[key];
|
||||||
@ -1507,12 +1515,11 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
// restore attr value
|
// restore attr value
|
||||||
attrs[key] = val;
|
attrs[key] = val;
|
||||||
if (defaultValue !== val) {
|
if (defaultValue !== val) {
|
||||||
obj.attrs[key] = val;
|
(obj.attrs as any)[key] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.className = this.getClassName();
|
return Util._prepareToStringify(obj) as typeof obj;
|
||||||
return Util._prepareToStringify(obj);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* convert Node into a JSON string. Returns a JSON string.
|
* convert Node into a JSON string. Returns a JSON string.
|
||||||
@ -2088,10 +2095,14 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
try {
|
try {
|
||||||
const callback = config?.callback;
|
const callback = config?.callback;
|
||||||
if (callback) delete config.callback;
|
if (callback) delete config.callback;
|
||||||
this.toCanvas(config).toBlob((blob) => {
|
this.toCanvas(config).toBlob(
|
||||||
|
(blob) => {
|
||||||
resolve(blob);
|
resolve(blob);
|
||||||
callback?.(blob);
|
callback?.(blob);
|
||||||
}, config?.mimeType, config?.quality);
|
},
|
||||||
|
config?.mimeType,
|
||||||
|
config?.quality
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
@ -933,7 +933,7 @@ export const Util = {
|
|||||||
});
|
});
|
||||||
return newStart;
|
return newStart;
|
||||||
},
|
},
|
||||||
_prepareToStringify(obj) {
|
_prepareToStringify<T>(obj: any): T | null {
|
||||||
var desc;
|
var desc;
|
||||||
|
|
||||||
obj.visitedByCircularReferenceRemoval = true;
|
obj.visitedByCircularReferenceRemoval = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user