@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
113 lines • 5.22 kB
JavaScript
import { ArchedTextItem } from "@aurigma/design-atoms-model/Product/Items";
import { NewBaseTextItemHandler } from "./NewBaseTextItemHandler";
import { RectangleF } from "@aurigma/design-atoms-model/Math";
import { TextFrameType } from "@aurigma/design-atoms-text/TextEditor/Enums/TextFrameType";
import { ListStyleSheetManagerFactory } from "@aurigma/design-atoms-text/TextEditor/Services";
import { GmXmlParser } from "@aurigma/design-atoms-text/Serialization/GmXmlParser";
import { GmXmlSerializer } from "@aurigma/design-atoms-text/Serialization/GmXmlSerializer";
import { ColorPalette } from "@aurigma/design-atoms-text/Serialization/Model/ColorPalette";
import { ItemUtils } from "../Utils/ItemUtils";
import { Paragraph, Span } from "@aurigma/design-atoms-text/Model";
export class NewArchedTextItemHandler extends NewBaseTextItemHandler {
constructor(fontRegistry, textEditorControllerFactory, item, textWhizz = null, apiClient, colorPreviewService, colorParser) {
super(fontRegistry, textEditorControllerFactory, item, textWhizz, apiClient, colorPreviewService, colorParser);
}
get item() {
return this._getItem();
}
set item(item) {
super._setItem(item);
}
isHighlightNeeded() {
return true;
}
getFramesData() {
const data = {
point: this.item.center.clone(),
bend: this.isInEdit ? 0 : this.item.bend
};
return {
type: TextFrameType.archedTextFrame,
frames: [data],
};
}
;
getWrappingPathData() {
return {};
}
setTextWhizzWrappingPath(handler) {
}
_onItemPropertyChanged(sender, propertyName) {
switch (propertyName) {
case "center":
case "bend":
case "warp":
this.update();
break;
}
super._onItemPropertyChanged(sender, propertyName);
}
_setDataItem(item, itemHandlerData) {
super._setDataItem(item, itemHandlerData);
this.item.center = item.center;
this.item.bend = item.bend;
this.item.warp = item.warp;
}
_getDefaultPermissions() {
const permissions = super._getDefaultPermissions();
permissions.manipulation.resizeGrips.setCornerArbitrary(false);
permissions.manipulation.resizeGrips.edge = false;
return permissions;
}
async _applyTransform(item, transform, center) {
var _a, _b;
if (!(item instanceof ArchedTextItem))
return;
const origCenter = item.center.clone();
const point = item.center.clone();
point.transform(transform, center);
item.center = point;
const limits = this._getPreviewScaleLimits();
let previewScale = this.item.previewScale * transform.scaleX;
previewScale = Math.min((_a = limits.max) !== null && _a !== void 0 ? _a : Number.MAX_VALUE, previewScale);
previewScale = Math.max((_b = limits.min) !== null && _b !== void 0 ? _b : Number.MIN_VALUE, previewScale);
item.font.size = item.font.size * previewScale;
await this._scaleFontSizes(item, previewScale);
await this._updateRectangleAfterTextScale(item);
this.textEditorController.updateText("frame", true);
}
async _scaleFontSizes(item, previewScale) {
const textParser = new GmXmlParser(this._colorParser);
const textSerializer = new GmXmlSerializer(this._colorParser);
const listStyleSheetManagerFactory = new ListStyleSheetManagerFactory();
let listStyleSheetManager = listStyleSheetManagerFactory.create();
listStyleSheetManager.initialize();
const colorPalette = new ColorPalette(await ItemUtils.getColorPalette(item, this._colorPreviewService));
const textModel = textParser.parse(item.text, colorPalette, item.font.size, listStyleSheetManager);
this._scaleTextModelStyles(textModel, previewScale);
const updatedText = textSerializer.serialize(textModel, colorPalette);
item.text = updatedText;
}
_scaleTextModelStyles(textModel, previewScale) {
textModel.blocks.forEach(block => {
if (block instanceof Paragraph) {
block.inlineElements.forEach(inlineElement => {
if (inlineElement instanceof Span) {
const spanStyle = inlineElement.style;
if (spanStyle === null || spanStyle === void 0 ? void 0 : spanStyle.fontSize) {
spanStyle.fontSize.value *= previewScale;
}
}
});
}
});
}
async _updateRectangleAfterTextScale(item) {
await this.textEditorController.waitUpdate();
const textBounds = item.sourceRectangle;
const rectangle = new RectangleF(textBounds.left, textBounds.top, textBounds.width, textBounds.height);
this.updateRectangle(rectangle, false);
}
}
NewArchedTextItemHandler.typeName = "NewArchedTextItemHandler";
//# sourceMappingURL=NewArchedTextItemHandler.js.map