@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.
369 lines • 16.9 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 { ContentItem } from "./ContentItem";
import { BarcodePermissions } from "./BarcodePermissions";
import { ArgumentException } from "../../Exception";
import { ResizeGripsPermissions } from "./ResizeGripsPermissions";
import { RgbColors } from "../../Colors";
import { BarcodeFormat } from "./BarcodeFormat";
import { BarcodeData } from "./BarcodeData";
import { BarcodeSubType } from "./BarcodeSubType";
import { equals, isString, isEqual } from "../../Utils/Utils";
import { Property } from "../Decorators/Property";
import { ModelComponent } from "../ModelComponent";
import { PropertyChanged } from "../Decorators/PropertyChanged";
import { SimplePropertyFactory } from "../Decorators/Factory";
export class BarcodeItem extends ContentItem {
constructor(format, content, options, rectangle) {
super();
this._barcodeContent = "";
this._barcodeFormat = BarcodeFormat.QR_CODE;
this._barcodeOptions = new EncodingOptions();
this._barcodeSubType = BarcodeSubType.Url;
this._color = RgbColors.black;
this.type = BarcodeItem.type;
this._onOptionsPropertyChanged = (s, p) => {
this._propertyChanged.notify(this, "barcodeOptions");
};
this._barcodePermissions = new BarcodePermissions();
this._barcodeOptions.pureBarcode = true;
this._ignorePermissionsChange = true;
this.manipulationPermissions.resizeGrips = new ResizeGripsPermissions(true, false);
this.itemPermissions.itemToolbarPermissions.showEditButton = true;
this.shapePermissions.allowChangeFillColor = true;
this.barcodePermissions.allowChangeBarcodeType = false;
this.barcodePermissions.allowChangeBarcodeColor = true;
this.barcodePermissions.allowChangeBarcodeContent = true;
this._ignorePermissionsChange = false;
this.fillColor = RgbColors.white;
if (format != null)
this._barcodeFormat = format;
if (content != null)
this._barcodeContent = content;
if (options != null)
this._barcodeOptions = options;
this._subscribeOptionsPropertyChanged();
if (rectangle != null)
this.sourceRectangle = rectangle;
this.applyPermissionsConstrain();
}
get barcodePermissions() {
return this._barcodePermissions;
}
set barcodePermissions(value) {
if (value == null) {
throw new ArgumentException("barcodePermissions cannot be null");
}
if (equals(this._barcodePermissions, value))
return;
this._barcodePermissions.propertyChanged.remove(this._onPermissionsChanged);
this._barcodePermissions = value;
this._barcodePermissions.propertyChanged.add(this._onPermissionsChanged);
this._onPermissionsChanged();
}
get barcodeContent() {
return this._barcodeContent;
}
set barcodeContent(value) {
if (this._barcodeContent === value)
return;
this._barcodeContent = value;
this._propertyChanged.notify(this, "barcodeContent");
}
get barcodeFormat() {
return this._barcodeFormat;
}
set barcodeFormat(value) {
if (this._barcodeFormat === value)
return;
this._barcodeFormat = value;
this._propertyChanged.notify(this, "barcodeFormat");
}
get barcodeSubType() {
return this._barcodeSubType;
}
set barcodeSubType(value) {
if (this._barcodeSubType === value)
return;
this._barcodeSubType = value;
this._propertyChanged.notify(this, "barcodeSubType");
}
get color() {
return this._color;
}
set color(value) {
if (this._color.equals(value))
return;
this._color = value;
this._propertyChanged.notify(this, "color");
}
get barcodeOptions() {
return this._barcodeOptions;
}
set barcodeOptions(value) {
if (JSON.stringify(this._barcodeOptions) === JSON.stringify(value))
return;
this._unsubscribeOptionsPropertyChanged();
this._barcodeOptions = value;
this._subscribeOptionsPropertyChanged();
this._propertyChanged.notify(this, "barcodeOptions");
}
_subscribeOptionsPropertyChanged() {
if (this._barcodeOptions != null)
this._barcodeOptions.addPropertyChanged(this._onOptionsPropertyChanged);
}
_unsubscribeOptionsPropertyChanged() {
if (this._barcodeOptions != null)
this._barcodeOptions.removePropertyChanged(this._onOptionsPropertyChanged);
}
get isQrCode() {
return this.barcodeFormat === BarcodeFormat.QR_CODE;
}
get isSquareCode() {
return this.barcodeFormat === BarcodeFormat.QR_CODE || this.barcodeFormat === BarcodeFormat.DATA_MATRIX;
}
get isLinearBarcode() {
return (this.barcodeFormat === BarcodeFormat.EAN_13 || this.barcodeFormat === BarcodeFormat.EAN_8 || this.barcodeFormat == BarcodeFormat.CODE_128 ||
this.barcodeFormat === BarcodeFormat.UPC_A || this.barcodeFormat === BarcodeFormat.UPC_E);
}
_copy(source, destination, generateNewIds, appropriateParentContainer) {
super._copy(source, destination, generateNewIds, appropriateParentContainer);
destination.barcodePermissions = source.barcodePermissions.clone();
destination.barcodeContent = source.barcodeContent;
destination.barcodeFormat = source.barcodeFormat;
destination.barcodeSubType = source.barcodeSubType;
destination.color = source.color.clone();
destination.barcodeOptions = new EncodingOptions();
destination.barcodeOptions.width = source.barcodeOptions.width;
destination.barcodeOptions.height = source.barcodeOptions.height;
destination.barcodeOptions.margin = source.barcodeOptions.margin;
destination.barcodeOptions.pureBarcode = source.barcodeOptions.pureBarcode;
destination.barcodeOptions.errorCorrection = source.barcodeOptions.errorCorrection;
destination.barcodeOptions.characterSet = source.barcodeOptions.characterSet;
destination.barcodeOptions.pdf417Compact = source.barcodeOptions.pdf417Compact;
destination.barcodeOptions.pdf417Compaction = source.barcodeOptions.pdf417Compaction;
destination.barcodeOptions.pdf417Dimensions = source.barcodeOptions.pdf417Dimensions;
destination.barcodeOptions.disableEci = source.barcodeOptions.disableEci;
destination.barcodeOptions.code128ForceCodesetB = source.barcodeOptions.code128ForceCodesetB;
destination.barcodeOptions.aztecLayers = source.barcodeOptions.aztecLayers;
destination.barcodeOptions.qrVersion = source.barcodeOptions.qrVersion;
destination.barcodeOptions.xDimension = source.barcodeOptions.xDimension;
destination.barcodeOptions.databarExpandedSegments = source.barcodeOptions.databarExpandedSegments;
}
equals(other) {
return super.equals(other) &&
equals(this._barcodePermissions, other._barcodePermissions) &&
equals(this._barcodeContent, other._barcodeContent) &&
equals(this._barcodeFormat, other._barcodeFormat) &&
equals(this._barcodeSubType, other._barcodeSubType) &&
equals(this._color, other._color) &&
equals(this._barcodeOptions, other._barcodeOptions);
}
clone(generateNewIds = false, appropriateParentContainer = false) {
const item = new BarcodeItem();
this._copy(this, item, generateNewIds, appropriateParentContainer);
return item;
}
getSimplifiedObject(omitProperties) {
if (!Array.isArray(omitProperties) && !isString(omitProperties))
omitProperties = [];
const simplified = super.getSimplifiedObject([
"barcodePermissions",
"isQrCode",
"isLinearBarcode",
"isSquareCode",
"barcodeData"
].concat(omitProperties));
simplified["barcodePermissions"] = this.barcodePermissions.getSimplifiedObject();
return simplified;
}
applyPermissionsConstrain() {
if (this.itemPermissions != null && this.itemPermissions.itemToolbarPermissions != null) {
if (this.barcodePermissions != null && !this.barcodePermissions.allowChangeBarcodeContent)
this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = this.barcodePermissions.allowChangeBarcodeContent;
else
this.itemPermissions.itemToolbarPermissions.showEditButtonConstraint = null;
this.itemPermissions.itemToolbarPermissions.showSelectButton = false;
}
}
get barcodeData() {
const barcodeMetaData = new BarcodeData();
barcodeMetaData.barcodeSubType = this.barcodeSubType;
barcodeMetaData.barcodeFormat = this.barcodeFormat;
switch (barcodeMetaData.barcodeFormat) {
default:
barcodeMetaData.barcodeValue = this.barcodeContent;
break;
case BarcodeFormat.QR_CODE:
switch (this.barcodeSubType) {
case BarcodeSubType.Phone:
barcodeMetaData.phone = this.barcodeContent;
break;
case BarcodeSubType.Url:
barcodeMetaData.url = this.barcodeContent;
break;
case BarcodeSubType.Data:
barcodeMetaData.data = this.barcodeContent;
break;
case BarcodeSubType.VCard:
return BarcodeData.fromVCardString(this.barcodeContent);
}
break;
}
return barcodeMetaData;
}
applyBarcodeData(barcodeData) {
this.barcodeFormat = barcodeData.barcodeFormat;
this.barcodeSubType = barcodeData.barcodeSubType != null ?
barcodeData.barcodeSubType :
(this.barcodeFormat === BarcodeFormat.QR_CODE ? BarcodeSubType.Phone : BarcodeSubType.None);
let barcodeContent = "";
switch (this.barcodeFormat) {
case BarcodeFormat.QR_CODE:
switch (this.barcodeSubType) {
case BarcodeSubType.Phone:
barcodeContent = barcodeData.phone;
break;
case BarcodeSubType.Data:
barcodeContent = barcodeData.data;
break;
case BarcodeSubType.None:
case BarcodeSubType.Url:
barcodeContent = barcodeData.url;
break;
case BarcodeSubType.VCard:
barcodeContent = barcodeData.toVCardString();
break;
}
break;
default:
barcodeContent = barcodeData.barcodeValue;
break;
}
this.barcodeContent = barcodeContent;
}
}
BarcodeItem.type = "BarcodeItem";
__decorate([
Property({ factory: new SimplePropertyFactory("") }),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], BarcodeItem.prototype, "barcodeContent", null);
__decorate([
Property({ enumObject: BarcodeFormat }),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], BarcodeItem.prototype, "barcodeFormat", null);
__decorate([
Property({ enumObject: BarcodeSubType }),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], BarcodeItem.prototype, "barcodeSubType", null);
export class EncodingOptions extends ModelComponent {
constructor() {
super(...arguments);
this.type = EncodingOptions.type;
}
equals(other) {
return other != null &&
equals(this.width, other.width) &&
equals(this.height, other.height) &&
equals(this.margin, other.margin) &&
equals(this.pureBarcode, other.pureBarcode) &&
equals(this.errorCorrection, other.errorCorrection) &&
equals(this.characterSet, other.characterSet) &&
equals(this.pdf417Compact, other.pdf417Compact) &&
equals(this.pdf417Compaction, other.pdf417Compaction) &&
isEqual(this.pdf417Dimensions, other.pdf417Dimensions) &&
equals(this.disableEci, other.disableEci) &&
equals(this.code128ForceCodesetB, other.code128ForceCodesetB) &&
equals(this.aztecLayers, other.aztecLayers) &&
equals(this.qrVersion, other.qrVersion) &&
equals(this.xDimension, other.xDimension &&
equals(this.databarExpandedSegments, other.databarExpandedSegments));
}
}
EncodingOptions.type = "EncodingOptions";
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "width", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "height", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "margin", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(true) }),
__metadata("design:type", Boolean)
], EncodingOptions.prototype, "pureBarcode", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory("") }),
__metadata("design:type", String)
], EncodingOptions.prototype, "errorCorrection", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory("") }),
__metadata("design:type", String)
], EncodingOptions.prototype, "characterSet", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(false) }),
__metadata("design:type", Boolean)
], EncodingOptions.prototype, "pdf417Compact", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory("") }),
__metadata("design:type", String)
], EncodingOptions.prototype, "pdf417Compaction", void 0);
__decorate([
PropertyChanged(),
Property({ ignore: true }),
__metadata("design:type", Object)
], EncodingOptions.prototype, "pdf417Dimensions", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(false) }),
__metadata("design:type", Boolean)
], EncodingOptions.prototype, "disableEci", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(false) }),
__metadata("design:type", Boolean)
], EncodingOptions.prototype, "code128ForceCodesetB", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "aztecLayers", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "qrVersion", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "xDimension", void 0);
__decorate([
PropertyChanged(),
Property({ factory: new SimplePropertyFactory(0) }),
__metadata("design:type", Number)
], EncodingOptions.prototype, "databarExpandedSegments", void 0);
//# sourceMappingURL=BarcodeItem.js.map