@aurigma/design-atoms-model
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
158 lines • 7.69 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { BaseTextItem } from "./BaseTextItem";
import { EqualsOfFloatNumbers } from "../../Math/index";
import { ParagraphSettings } from "./ParagraphSettings";
import { PathBoundedTextPermissions } from "./PathBoundedTextPermissions";
import { ArgumentException } from "../../Exception";
import { equals } from "../../Utils/Utils";
import { FirstBaselineOffset } from "./TextEnums";
import { Property } from "../Decorators/Property";
import { arraysIsEqual } from "@aurigma/utils-js/algorithms/array";
export class PathBoundedTextItem extends BaseTextItem {
constructor(text, paths, postScriptFontName, fontSize) {
super(text, postScriptFontName, fontSize);
this._boundingPaths = [];
this._wrappingMargin = 7;
this._wrappingPath = null;
this._paragraphSettings = new ParagraphSettings();
this._isVertical = false;
this._firstBaselineOffset = FirstBaselineOffset.Ascent;
this._firstBaselineMinOffset = 0;
this.type = PathBoundedTextItem.type;
if (paths != null)
this.boundingPaths = paths;
this._pathBoundedTextPermissions = new PathBoundedTextPermissions();
this._pathBoundedTextPermissions.propertyChanged.add(this._onPermissionsChanged);
}
get boundingPaths() {
return this._boundingPaths;
}
set boundingPaths(value) {
if (value.length === this.boundingPaths.length && this.boundingPaths.every((path, index) => path.isEqual(value[index])))
return;
this._boundingPaths = value;
this._propertyChanged.notify(this, "boundingPaths");
}
get wrappingPath() {
return this._wrappingPath;
}
set wrappingPath(value) {
if (this._wrappingPath == null && value == null || this._wrappingPath != null && this._wrappingPath.isEqual(value))
return;
this._wrappingPath = value;
this._propertyChanged.notify(this, "wrappingPath");
}
get wrappingMargin() {
return this._wrappingMargin;
}
set wrappingMargin(value) {
if (EqualsOfFloatNumbers(this._wrappingMargin, value))
return;
this._wrappingMargin = value;
this._propertyChanged.notify(this, "wrappingMargin");
}
get paragraphSettings() {
return this._paragraphSettings;
}
set paragraphSettings(value) {
if (ParagraphSettings.equals(this._paragraphSettings, value))
return;
this._paragraphSettings = value;
this._propertyChanged.notify(this, "paragraphSettings");
}
get isVertical() {
return this._isVertical;
}
set isVertical(value) {
if (this._isVertical === value)
return;
this._isVertical = value;
this._propertyChanged.notify(this, "isVertical");
}
get pathBoundedTextPermissions() {
return this._pathBoundedTextPermissions;
}
set pathBoundedTextPermissions(value) {
if (value == null)
throw new ArgumentException("pathBoundedTextPermissions cannot be null");
if (equals(this._pathBoundedTextPermissions, value))
return;
this._pathBoundedTextPermissions.propertyChanged.remove(this._onPermissionsChanged);
this._pathBoundedTextPermissions = value;
this._pathBoundedTextPermissions.propertyChanged.add(this._onPermissionsChanged);
this._onPermissionsChanged();
}
get firstBaselineOffset() {
return this._firstBaselineOffset;
}
set firstBaselineOffset(value) {
if (this._firstBaselineOffset === value)
return;
this._firstBaselineOffset = value;
if (value != null)
this._propertyChanged.notify(this, "firstBaselineOffset");
}
get firstBaselineMinOffset() {
return this._firstBaselineMinOffset;
}
set firstBaselineMinOffset(value) {
if (EqualsOfFloatNumbers(this._firstBaselineMinOffset, value))
return;
this._firstBaselineMinOffset = value;
if (value != null)
this._propertyChanged.notify(this, "firstBaselineMinOffset");
}
getSimplifiedObject(omitProperties) {
const simplified = super.getSimplifiedObject(["pathBoundedTextPermissions"].concat(omitProperties));
simplified["pathBoundedTextPermissions"] = this.pathBoundedTextPermissions.getSimplifiedObject();
return simplified;
}
_copy(source, destination, generateNewIds, appropriateParentContainer) {
super._copy(source, destination, generateNewIds, appropriateParentContainer);
if (destination.type == "AutoScaledTextItem" || destination.type == "BoundedTextItem" || destination.type == "PathBoundedTextItem" || destination.type == "PlainTextItem") {
destination["isVertical"] = source.isVertical;
}
if (destination.type == "PathBoundedTextItem" || destination.type == "BoundedTextItem") {
destination["wrappingMargin"] = source.wrappingMargin;
destination["paragraphSettings"] = source.paragraphSettings.clone();
destination["wrappingPath"] = source.wrappingPath != null ? source.wrappingPath.clone() : null;
destination["firstBaselineOffset"] = source.firstBaselineOffset;
destination["firstBaselineMinOffset"] = source.firstBaselineMinOffset;
}
if (destination instanceof PathBoundedTextItem) {
destination.boundingPaths = source.boundingPaths.map(i => i.clone());
destination.pathBoundedTextPermissions = source.pathBoundedTextPermissions.clone();
}
}
equals(other) {
return super.equals(other) &&
arraysIsEqual(this._boundingPaths, other._boundingPaths, equals) &&
equals(this._wrappingMargin, other._wrappingMargin) &&
equals(this._paragraphSettings, other._paragraphSettings) &&
equals(this._isVertical, other._isVertical) &&
equals(this._pathBoundedTextPermissions, other._pathBoundedTextPermissions) &&
equals(this._wrappingPath, other._wrappingPath) &&
equals(this.firstBaselineOffset, other.firstBaselineOffset) &&
equals(this.firstBaselineMinOffset, other.firstBaselineMinOffset);
}
clone(generateNewIds = false, appropriateParentContainer = false) {
const item = new PathBoundedTextItem();
this._copy(this, item, generateNewIds, appropriateParentContainer);
return item;
}
}
PathBoundedTextItem.type = "PathBoundedTextItem";
__decorate([
Property({ enumObject: FirstBaselineOffset }),
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
], PathBoundedTextItem.prototype, "firstBaselineOffset", null);
//# sourceMappingURL=PathBoundedTextItem.js.map