Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set(newSetting) {
const setting = this.getCurrentSetting();
const isChangingFlipX = (setting.flipX !== newSetting.flipX);
const isChangingFlipY = (setting.flipY !== newSetting.flipY);
if (!isChangingFlipX && !isChangingFlipY) {
return Promise.reject(rejectMessages.flip);
}
snippet.extend(setting, newSetting);
this.setImageProperties(setting, true);
this._invertAngle(isChangingFlipX, isChangingFlipY);
this._flipObjects(isChangingFlipX, isChangingFlipY);
return Promise.resolve({
flipX: setting.flipX,
flipY: setting.flipY,
angle: this.getCanvasImage().angle
});
}
loadImageFromURL(url, imageName) {
if (!imageName || !url) {
return Promise.reject(rejectMessages.invalidParameters);
}
return this.execute(commands.LOAD_IMAGE, imageName, url);
}
execute(graphics, id, styles) {
const textComp = graphics.getComponent(TEXT);
const targetObj = graphics.getObject(id);
if (!targetObj) {
return Promise.reject(rejectMessages.noObject);
}
this.undoData.object = targetObj;
this.undoData.styles = {};
snippet.forEachOwnProperties(styles, (value, key) => {
this.undoData.styles[key] = targetObj[key];
});
return textComp.setStyle(targetObj, styles);
},
/**
if (command && this._isLocked) {
this.pushRedoStack(command, true);
command = null;
}
if (command) {
if (this.isEmptyRedoStack()) {
this._fireRedoStackChanged();
}
promise = this._invokeExecution(command);
} else {
message = rejectMessages.redo;
if (this._isLocked) {
message = `${message} Because ${rejectMessages.isLock}`;
}
promise = Promise.reject(message);
}
return promise;
}
if (command && this._isLocked) {
this.pushUndoStack(command, true);
command = null;
}
if (command) {
if (this.isEmptyUndoStack()) {
this._fireUndoStackChanged();
}
promise = this._invokeUndo(command);
} else {
message = rejectMessages.undo;
if (this._isLocked) {
message = `${message} Because ${rejectMessages.isLock}`;
}
promise = Promise.reject(message);
}
return promise;
}
execute(...args) {
if (this._isLocked) {
return Promise.reject(rejectMessages.isLock);
}
let [command] = args;
if (isString(command)) {
command = commandFactory.create(...args);
}
return this._invokeExecution(command)
.then(value => {
this.clearRedoStack();
return value;
});
}
execute(graphics, id, options) {
const shapeComp = graphics.getComponent(SHAPE);
const targetObj = graphics.getObject(id);
if (!targetObj) {
return Promise.reject(rejectMessages.noObject);
}
this.undoData.object = targetObj;
this.undoData.options = {};
snippet.forEachOwnProperties(options, (value, key) => {
this.undoData.options[key] = targetObj[key];
});
return shapeComp.change(targetObj, options);
},
/**
_setBackgroundImage(img) {
if (!img) {
return Promise.reject(rejectMessages.loadImage);
}
return new Promise((resolve, reject) => {
const canvas = this.getCanvas();
canvas.setBackgroundImage(img, () => {
const oImage = canvas.backgroundImage;
if (oImage && oImage.getElement()) {
resolve(oImage);
} else {
reject(rejectMessages.loadingImageFailed);
}
}, imageOption);
});
}