type fixes. close #1692

This commit is contained in:
Anton Lavrenov 2023-12-25 11:10:37 -05:00
parent 813cd4f780
commit a8efcd554a
3 changed files with 24 additions and 13 deletions

View File

@ -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;

View File

@ -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);
} }

View File

@ -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;