Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aurigma/design-atoms-text

Package Overview
Dependencies
Maintainers
5
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurigma/design-atoms-text - npm Package Compare versions

Comparing version 6.23.0 to 6.23.1

13

dist/Serialization/HtmlParser.d.ts

@@ -18,3 +18,2 @@ import { BlockElement, InlineElement, NumericValue, Paragraph, SpanStyle, Text } from "../Model";

private _useSimpleFontList;
private _previewScale;
private _colorParser;

@@ -24,3 +23,3 @@ private _colorPreviewService;

private _colorConverter;
constructor(_colorPaletteManager: IColorPalette, _fontService: IFontService, _useSimpleFontList: boolean, _previewScale: number, _colorParser: IColorParser, _colorPreviewService: IColorPreviewService);
constructor(_colorPaletteManager: IColorPalette, _fontService: IFontService, _useSimpleFontList: boolean, _colorParser: IColorParser, _colorPreviewService: IColorPreviewService);
static getTrackingValue(value: IStyleDictionary): number;

@@ -52,3 +51,3 @@ static letterSpacingToTracking(letterSpacing: string): number;

static getFontSizeValue(styles: IStyleDictionary, scale?: number): number;
parse(text: string, colorPalette: IColorPalette, defaultFontSize: number): Promise<Text>;
parse(text: string, colorPalette: IColorPalette, previewScale: number): Promise<Text>;
getColorValue(styles: IStyleDictionary, colors: IStyleDictionary, colorPalette: IColorPalette): Promise<number>;

@@ -64,6 +63,6 @@ getStrokeValue(styles: IStyleDictionary, colors: IStyleDictionary, colorPalette: IColorPalette, scale?: number): Promise<{

protected _dbgGetNodeContent(node: Node): string;
protected _convertNode(originalNode: Node, children: (BlockElement | InlineElement | ListItem)[], defaultFontSize: number): Promise<BlockElement | InlineElement>;
protected _convertCommonListStyleToParagraphStyle(targetParagraph: Paragraph, listItemStyle: ListItemStyle, sourceListStyle: UnorderedListStyle | OrderedListStyle, defaultFontSize: number): void;
protected _convertOListItemToParagraph(listItem: ListItem, sourceList: OrderedList, startNumber: number, defaultFontSize: number): Paragraph;
protected _convertUListItemToParagraph(listItem: ListItem, sourceList: UnorderedList, defaultFontSize: number): Paragraph;
protected _convertNode(originalNode: Node, children: (BlockElement | InlineElement | ListItem)[], previewScale: number): Promise<BlockElement | InlineElement>;
protected _convertCommonListStyleToParagraphStyle(targetParagraph: Paragraph, listItemStyle: ListItemStyle, sourceListStyle: UnorderedListStyle | OrderedListStyle): void;
protected _convertOListItemToParagraph(listItem: ListItem, sourceList: OrderedList, startNumber: number): Paragraph;
protected _convertUListItemToParagraph(listItem: ListItem, sourceList: UnorderedList): Paragraph;
protected _convertUnorderedListLevelIndent(levelIndent: NumericValue): number;

@@ -70,0 +69,0 @@ protected _convertUnorderedListBullet(type: UnorderedListType | UnorderedListTypeSymbol): string;

@@ -21,7 +21,6 @@ import { BlockElement, Br, InlineElement, InlineText, ListStyleType, NumberMode, NumericValue, Units, Paragraph, ParagraphListStyle, ParagraphMetadata, ParagraphStyle, Span, SpanStyle, Text } from "../Model";

export class HtmlParser {
constructor(_colorPaletteManager, _fontService, _useSimpleFontList, _previewScale, _colorParser, _colorPreviewService) {
constructor(_colorPaletteManager, _fontService, _useSimpleFontList, _colorParser, _colorPreviewService) {
this._colorPaletteManager = _colorPaletteManager;
this._fontService = _fontService;
this._useSimpleFontList = _useSimpleFontList;
this._previewScale = _previewScale;
this._colorParser = _colorParser;

@@ -251,6 +250,6 @@ this._colorPreviewService = _colorPreviewService;

}
async parse(text, colorPalette, defaultFontSize) {
async parse(text, colorPalette, previewScale) {
const body = this._parse(text);
this._colorConverter = new ColorConverter(colorPalette, this._colorParser);
const result = await this._convert(body, defaultFontSize);
const result = await this._convert(body, previewScale);
return result;

@@ -336,3 +335,3 @@ }

}
async _convertNode(originalNode, children, defaultFontSize) {
async _convertNode(originalNode, children, previewScale) {
const nodeName = this.getNodeName(originalNode);

@@ -343,5 +342,5 @@ switch (nodeName) {

case "p":
return this._convertParagraph(originalNode, children);
return this._convertParagraph(originalNode, children, previewScale);
case "span":
return await this._convertSpan(originalNode, children);
return await this._convertSpan(originalNode, children, previewScale);
case "u":

@@ -352,7 +351,7 @@ case "b":

case "ol":
return this._convertOrderedList(originalNode, children, defaultFontSize);
return this._convertOrderedList(originalNode, children);
case "ul":
return this._convertUnorderedList(originalNode, children, defaultFontSize);
return this._convertUnorderedList(originalNode, children);
case "li":
return this._convertListItem(originalNode, children);
return this._convertListItem(originalNode, children, previewScale);
case "br":

@@ -366,3 +365,3 @@ return this._convertBr();

}
_convertCommonListStyleToParagraphStyle(targetParagraph, listItemStyle, sourceListStyle, defaultFontSize) {
_convertCommonListStyleToParagraphStyle(targetParagraph, listItemStyle, sourceListStyle) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;

@@ -440,7 +439,7 @@ const PX_TO_PT = 0.75;

}
_convertOListItemToParagraph(listItem, sourceList, startNumber, defaultFontSize) {
_convertOListItemToParagraph(listItem, sourceList, startNumber) {
var _a, _b;
const paragraph = new Paragraph();
paragraph.inlineElements = [...listItem.content];
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style, defaultFontSize);
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style);
paragraph.listStyle.type = ListStyleType.numbers;

@@ -464,7 +463,7 @@ const lOrderedListType = (_a = sourceList === null || sourceList === void 0 ? void 0 : sourceList.style) === null || _a === void 0 ? void 0 : _a.type;

}
_convertUListItemToParagraph(listItem, sourceList, defaultFontSize) {
_convertUListItemToParagraph(listItem, sourceList) {
var _a, _b;
const paragraph = new Paragraph();
paragraph.inlineElements = [...listItem.content];
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style, defaultFontSize);
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style);
paragraph.listStyle.type = ListStyleType.bullets;

@@ -513,3 +512,3 @@ paragraph.listStyle.bulletChar = (_b = this._convertUnorderedListBullet((_a = sourceList === null || sourceList === void 0 ? void 0 : sourceList.style) === null || _a === void 0 ? void 0 : _a.type)) === null || _b === void 0 ? void 0 : _b.charCodeAt(0);

}
async _convert(originalNode, defaultFontSize) {
async _convert(originalNode, previewScale) {
var _a, _b;

@@ -526,7 +525,7 @@ let convertedChildren = [];

if (originalNode.childNodes.length == 1) {
const convertedList = await this._convert(childNode, defaultFontSize);
const convertedList = await this._convert(childNode, previewScale);
return convertedList;
}
else {
const convertedList = await this._convert(childNode, defaultFontSize);
const convertedList = await this._convert(childNode, previewScale);
unwrapedChildren.push(convertedList); // may be we should break list and start a new one here

@@ -541,3 +540,3 @@ }

else {
let convertedChild = await this._convert(childNode, defaultFontSize);
let convertedChild = await this._convert(childNode, previewScale);
if (Array.isArray(convertedChild)) {

@@ -553,3 +552,3 @@ for (let j = 0; j < convertedChild.length; ++j)

}
const convertedNode = await this._convertNode(originalNode, convertedChildren, defaultFontSize);
const convertedNode = await this._convertNode(originalNode, convertedChildren, previewScale);
if (unwrapedChildren.length == 0) {

@@ -605,3 +604,3 @@ return convertedNode;

}
_convertParagraph(htmlParagraph, children) {
_convertParagraph(htmlParagraph, children, previewScale) {
const paragraph = new Paragraph();

@@ -626,3 +625,3 @@ if (children != null && children.length > 0)

}
let paragraphStyles = this._convertParagraphStyles(htmlStyle === null || htmlStyle === void 0 ? void 0 : htmlStyle.value);
let paragraphStyles = this._convertParagraphStyles(htmlStyle === null || htmlStyle === void 0 ? void 0 : htmlStyle.value, previewScale);
paragraph.style = paragraphStyles.style;

@@ -643,3 +642,3 @@ paragraph.listStyle = paragraphStyles.listStyle;

}
_convertParagraphStyles(xmlStyle) {
_convertParagraphStyles(xmlStyle, previewScale) {
if (isNullOrEmptyOrWhiteSpace(xmlStyle))

@@ -652,3 +651,3 @@ return {

return {
style: this._convertParagraphStyle(parsedStyles, this._previewScale),
style: this._convertParagraphStyle(parsedStyles, previewScale),
listStyle: this._convertParagraphListStyles(parsedStyles)

@@ -715,3 +714,3 @@ };

}
_convertOrderedList(html, children, defaultFontSize) {
_convertOrderedList(html, children) {
let ol = new OrderedList();

@@ -728,3 +727,3 @@ const htmlStyle = html.getAttributeNode("style");

startNumber = ((_a = x === null || x === void 0 ? void 0 : x.style) === null || _a === void 0 ? void 0 : _a.start) ? x.style.start : null;
let paragraph = this._convertOListItemToParagraph(x, ol, startNumber, defaultFontSize);
let paragraph = this._convertOListItemToParagraph(x, ol, startNumber);
ol.items.push(paragraph);

@@ -738,3 +737,3 @@ if (startNumber != null)

}
_convertUnorderedList(html, children, defaultFontSize) {
_convertUnorderedList(html, children) {
let ul = new UnorderedList();

@@ -748,3 +747,3 @@ const htmlStyle = html.getAttributeNode("style");

if (x instanceof ListItem) {
let paragraph = this._convertUListItemToParagraph(x, ul, defaultFontSize);
let paragraph = this._convertUListItemToParagraph(x, ul);
ul.items.push(paragraph);

@@ -756,3 +755,3 @@ }

}
_convertListItem(html, children) {
_convertListItem(html, children, previewScale) {
const parentNodeName = this.getNodeName(html.parentNode);

@@ -783,3 +782,3 @@ if (parentNodeName == "ol" || parentNodeName == "ul") {

else {
return this._convertParagraph(html, children);
return this._convertParagraph(html, children, previewScale);
}

@@ -818,7 +817,7 @@ function unwrapChildrenFromEmptySpan(listItem) {

}
async _convertSpan(htmlSpan, children) {
async _convertSpan(htmlSpan, children, previewScale) {
const span = new Span();
if (children != null && children.length > 0)
children.forEach(x => span.content.push(x));
span.style = await this._convertSpanStyles(htmlSpan);
span.style = await this._convertSpanStyles(htmlSpan, previewScale);
return span;

@@ -880,3 +879,3 @@ }

}
async _convertSpanStyles(htmlSpan) {
async _convertSpanStyles(htmlSpan, previewScale) {
var _a, _b;

@@ -904,3 +903,3 @@ const htmlStyle = (_a = htmlSpan.getAttributeNode("style")) === null || _a === void 0 ? void 0 : _a.value;

result.underline = this._parseBool(`${underline}`);
const fontSize = HtmlParser.getFontSizeValue(styles, this._previewScale);
const fontSize = HtmlParser.getFontSizeValue(styles, previewScale);
if (fontSize != null)

@@ -914,3 +913,3 @@ result.fontSize = NumericValueConverter.parse(`${fontSize}pt`);

}
const stroke = await this.getStrokeValue(styles, colors, this._colorPaletteManager, this._previewScale);
const stroke = await this.getStrokeValue(styles, colors, this._colorPaletteManager, previewScale);
if (stroke != null) {

@@ -932,3 +931,3 @@ if (stroke.size != null) {

}
const leading = HtmlParser.getLeadingValue(styles, this._previewScale);
const leading = HtmlParser.getLeadingValue(styles, previewScale);
if (leading != null)

@@ -935,0 +934,0 @@ result.leading = NumericValueConverter.parse(`${leading}pt`);

@@ -18,8 +18,7 @@ import { SpanStyle } from "../Model";

private _useSimpleFontList;
private _previewScale;
private _colorConverter;
protected static readonly _defaultSupSubSize = 0.583;
protected static readonly _listsLeftIndentEqualsToModelZero = 30;
constructor(_fontService: IFontService, _colorPreviewSrvice: IColorPreviewService, _colorParser: IColorParser, _useSimpleFontList: boolean, _previewScale: number);
serialize(text: Text, colorPalette: IColorPalette): Promise<string>;
constructor(_fontService: IFontService, _colorPreviewSrvice: IColorPreviewService, _colorParser: IColorParser, _useSimpleFontList: boolean);
serialize(text: Text, colorPalette: IColorPalette, previewScale: number): Promise<string>;
private _serializeBlocks;

@@ -26,0 +25,0 @@ private _changeStartAtToContinuefromPreviousIfRequared;

@@ -12,3 +12,3 @@ import { SerializationException, NotImplementedException } from "../Exceptions";

export class HtmlSerializer {
constructor(_fontService, _colorPreviewSrvice, _colorParser, _useSimpleFontList, _previewScale) {
constructor(_fontService, _colorPreviewSrvice, _colorParser, _useSimpleFontList) {
this._fontService = _fontService;

@@ -18,9 +18,8 @@ this._colorPreviewSrvice = _colorPreviewSrvice;

this._useSimpleFontList = _useSimpleFontList;
this._previewScale = _previewScale;
}
async serialize(text, colorPalette) {
async serialize(text, colorPalette, previewScale) {
if (text == null)
throw new SerializationException("Text must be not null");
this._colorConverter = new ColorConverter(colorPalette, this._colorParser);
let result = await this._serializeBlocks(text.blocks);
let result = await this._serializeBlocks(text.blocks, previewScale);
result = result.replace(/<p><\/p>/g, '<p><span><br /></span></p>') // change empty lines for GM <-> HTML compatibility

@@ -35,3 +34,3 @@ .replace(/<p><span> <\/span><\/p>/g, '<p><span><br /></span></p>')

}
async _serializeBlocks(blocks) {
async _serializeBlocks(blocks, previewScale) {
var _a, _b;

@@ -58,3 +57,3 @@ if (blocks == null)

currentListContent = "";
currentListContent += await this._serializeParagraph(block);
currentListContent += await this._serializeParagraph(block, previewScale);
}

@@ -65,6 +64,6 @@ else {

&& this._changeStartAtToContinuefromPreviousIfRequared(block, blocks[index - 1])) {
currentListContent += await this._serializeParagraph(block, true);
currentListContent += await this._serializeParagraph(block, previewScale, true);
}
else {
currentListContent += await this._serializeParagraph(block);
currentListContent += await this._serializeParagraph(block, previewScale);
}

@@ -82,3 +81,3 @@ }

}
result += await this._serializeBlock(block);
result += await this._serializeBlock(block, previewScale);
}

@@ -104,15 +103,15 @@ }

}
async _serializeBlock(block) {
async _serializeBlock(block, previewScale) {
if (block instanceof Paragraph)
return await this._serializeParagraph(block);
return await this._serializeParagraph(block, previewScale);
else if (block instanceof OrderedList)
return await this._serializeOrderedList(block);
return await this._serializeOrderedList(block, previewScale);
else if (block instanceof UnorderedList)
return await this._serializeUnorderedList(block);
return await this._serializeUnorderedList(block, previewScale);
console.error("Unknown block type, serialization not implemented", block);
throw new NotImplementedException("Unknown block type ");
}
async _serializeParagraph(p, setContinueFromPrevious = false) {
async _serializeParagraph(p, previewScale, setContinueFromPrevious = false) {
var _a, _b, _c;
let pStyleStr = this._serializeParagraphStyle(p.style, p.listStyle);
let pStyleStr = this._serializeParagraphStyle(p.style, p.listStyle, previewScale);
let pMetadataStr = this._serializeParagraphMetadata(p.metadata);

@@ -131,13 +130,13 @@ let attributes = [];

for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
resultTag = this._buildTag("p", attributes, content);
}
else {
let liInnerSpanPadding = this._getLiInnerSpanPadding(p.style, p.listStyle);
let liInnerSpanPadding = this._getLiInnerSpanPadding(p.style, p.listStyle, previewScale);
if (p.inlineElements[0] instanceof Span) {
content += await this._serializeSpan(p.inlineElements[0], liInnerSpanPadding);
content += await this._serializeSpan(p.inlineElements[0], previewScale, liInnerSpanPadding);
p.inlineElements.shift();
if (p.inlineElements)
for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
}

@@ -149,3 +148,3 @@ else {

for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
if (liInnerSpanPadding)

@@ -174,3 +173,3 @@ content += `</span>`;

}
_getLiInnerSpanPadding(liStyle, liListStyle) {
_getLiInnerSpanPadding(liStyle, liListStyle, previewScale) {
let result = null;

@@ -184,3 +183,3 @@ const firstLineIndent = (!this._isEmpty(liStyle === null || liStyle === void 0 ? void 0 : liStyle.firstLineIndent)) ? liStyle.firstLineIndent.value : 0;

if (paddingLeft != 0)
result = `padding-left: ${HtmlSerializer.setValueInPoints(paddingLeft, this._previewScale)}`;
result = `padding-left: ${HtmlSerializer.setValueInPoints(paddingLeft, previewScale)}`;
return result;

@@ -230,3 +229,3 @@ }

}
_serializeParagraphStyle(pStyle, pListStyle) {
_serializeParagraphStyle(pStyle, pListStyle, previewScale) {
let styleProps = [];

@@ -240,22 +239,22 @@ if (pStyle) {

const textIndent = HtmlSerializer.getCorrectTextIndentValue(firstLineIndentValue, (!this._isEmpty(pStyle.leftIndent)) ? pStyle.leftIndent.value : HtmlSerializer._listsLeftIndentEqualsToModelZero);
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(textIndent, this._previewScale)}`);
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(textIndent, previewScale)}`);
if (textIndent != firstLineIndentValue)
styleProps.push(`text-indent-cropped-part: ${HtmlSerializer.setValueInPoints(-textIndent + firstLineIndentValue, this._previewScale)}`);
styleProps.push(`text-indent-cropped-part: ${HtmlSerializer.setValueInPoints(-textIndent + firstLineIndentValue, previewScale)}`);
}
else
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(pStyle.firstLineIndent.value, this._previewScale)}`);
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(pStyle.firstLineIndent.value, previewScale)}`);
}
if (!this._isEmpty(pStyle.spaceBefore))
styleProps.push(`padding-top: ${HtmlSerializer.setValueInPoints(pStyle.spaceBefore.value, this._previewScale)}`);
styleProps.push(`padding-top: ${HtmlSerializer.setValueInPoints(pStyle.spaceBefore.value, previewScale)}`);
if (!this._isEmpty(pStyle.spaceAfter))
styleProps.push(`padding-bottom: ${HtmlSerializer.setValueInPoints(pStyle.spaceAfter.value, this._previewScale)}`);
styleProps.push(`padding-bottom: ${HtmlSerializer.setValueInPoints(pStyle.spaceAfter.value, previewScale)}`);
if (!this._isEmpty(pStyle.leftIndent)) {
if (!this._isEmpty(pListStyle === null || pListStyle === void 0 ? void 0 : pListStyle.type)) {
styleProps.push(`margin-left: ${HtmlSerializer.setCorrectedForListsLeftIndentValue(pStyle.leftIndent.value, this._previewScale)}`);
styleProps.push(`margin-left: ${HtmlSerializer.setCorrectedForListsLeftIndentValue(pStyle.leftIndent.value, previewScale)}`);
}
else
styleProps.push(`margin-left: ${HtmlSerializer.setValueInPoints(pStyle.leftIndent.value, this._previewScale)}`);
styleProps.push(`margin-left: ${HtmlSerializer.setValueInPoints(pStyle.leftIndent.value, previewScale)}`);
}
if (!this._isEmpty(pStyle.rightIndent))
styleProps.push(`margin-right: ${HtmlSerializer.setValueInPoints(pStyle.rightIndent.value, this._previewScale)}`);
styleProps.push(`margin-right: ${HtmlSerializer.setValueInPoints(pStyle.rightIndent.value, previewScale)}`);
}

@@ -266,3 +265,3 @@ if (pListStyle) {

if (!this._isEmpty(pListStyle.tabPosition)) //apply in inner span, used only to save value
styleProps.push(`bullet-number-tab-position: ${HtmlSerializer.setBulletTabPosition(pListStyle.tabPosition, this._previewScale)}`);
styleProps.push(`bullet-number-tab-position: ${HtmlSerializer.setBulletTabPosition(pListStyle.tabPosition, previewScale)}`);
if (!this._isEmpty(pListStyle.level))

@@ -338,9 +337,9 @@ styleProps.push(`level: ${pListStyle.level}`);

}
async _serializeInlineElement(e) {
if (e instanceof Span)
return await this._serializeSpan(e);
else if (e instanceof InlineText)
return this._serializeInlineText(e);
else if (e instanceof Br)
return this._serializeBr(e);
async _serializeInlineElement(element, previewScale) {
if (element instanceof Span)
return await this._serializeSpan(element, previewScale);
else if (element instanceof InlineText)
return this._serializeInlineText(element);
else if (element instanceof Br)
return this._serializeBr(element);
}

@@ -350,4 +349,4 @@ _serializeBr(br) {

}
async _serializeSpan(span, liPadding = null) {
let style = (span.style || liPadding) ? await this._serializeSpanStyle(span, liPadding) : null;
async _serializeSpan(span, previewScale, liPadding = null) {
let style = (span.style || liPadding) ? await this._serializeSpanStyle(span, previewScale, liPadding) : null;
let openTag = style ? `<span ${style}>` : '<span>';

@@ -358,3 +357,3 @@ let closeTag = '</span>';

for (let element of span.content) {
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
}

@@ -366,3 +365,3 @@ }

}
async _serializeSpanStyle(spanObj, liPadding = null) {
async _serializeSpanStyle(spanObj, previewScale, liPadding = null) {
const style = spanObj.style;

@@ -385,6 +384,6 @@ let styleProps = [];

if (!this._isEmpty(style.fontSize)) {
styleProps.push(`font-size: ${HtmlSerializer.setValueInPoints(style.fontSize.value, this._previewScale)}`);
styleProps.push(`font-size: ${HtmlSerializer.setValueInPoints(style.fontSize.value, previewScale)}`);
}
if (!this._isEmpty(style.leading)) {
styleProps.push(`line-height: ${style.leading.value === 0 ? "normal" : `${HtmlSerializer.setValueInPoints(style.leading.value, this._previewScale)}`}`);
styleProps.push(`line-height: ${style.leading.value === 0 ? "normal" : `${HtmlSerializer.setValueInPoints(style.leading.value, previewScale)}`}`);
}

@@ -400,3 +399,3 @@ if (!this._isEmpty(style.tracking))

const colorPreview = await this._colorPreviewSrvice.getPreviewAsync(style.penColor.color);
styleProps.push(`-webkit-text-stroke: ${HtmlSerializer.setValueInPoints(style.penWidth.value, this._previewScale)} ${colorPreview}`);
styleProps.push(`-webkit-text-stroke: ${HtmlSerializer.setValueInPoints(style.penWidth.value, previewScale)} ${colorPreview}`);
colorDataProps.push(`pen-color-index: ${this._colorConverter.serialize(style.penColor)}`);

@@ -651,3 +650,3 @@ }

}
async _serializeOrderedList(list) {
async _serializeOrderedList(list, previewScale) {
let olStyle = list.style ? this._serializeOrderedListStyle(list.style) : null;

@@ -659,3 +658,3 @@ let olTag = olStyle ? `<ol ${olStyle}>` : '<ol>';

for (let item of list.items) {
olContent += await this._serializeListItem(item);
olContent += await this._serializeListItem(item, previewScale);
}

@@ -676,3 +675,3 @@ return `${olTag}${olContent}</ol>`;

}
async _serializeUnorderedList(list) {
async _serializeUnorderedList(list, previewScale) {
let ulStyle = list.style ? this._serializeUnorderedListStyle(list.style) : null;

@@ -684,3 +683,3 @@ let ulTag = ulStyle ? `<ul ${ulStyle}>` : '<ul>';

for (let item of list.items) {
ulContent += await this._serializeListItem(item);
ulContent += await this._serializeListItem(item, previewScale);
}

@@ -703,5 +702,5 @@ return `${ulTag}${ulContent}</ul>`;

}
async _serializeListItem(item) {
async _serializeListItem(item, previewScale) {
if (item instanceof Paragraph) {
return await this._serializeParagraph(item);
return await this._serializeParagraph(item, previewScale);
}

@@ -708,0 +707,0 @@ else

@@ -74,3 +74,3 @@ import { EventObject } from "@aurigma/design-atoms-model/EventObject";

*/
getInlineStyle(): ICharStyle;
getInlineStyle(): ICharStyle | null;
/**

@@ -77,0 +77,0 @@ * Sets the character style for the current cursor position or selected text.

@@ -19,2 +19,4 @@ import { EventObject } from "@aurigma/design-atoms-model/EventObject";

private readonly _textMetricsChangedEvent;
private readonly _frameChangedEvent;
private _initData;
private _listStyleSheetManager;

@@ -49,9 +51,17 @@ private _colorPalette;

get redrawActiveTextInEditMode(): boolean;
isApplyingListsEnabled(): boolean;
private readonly _frameChangedEvent;
get frameChanged(): EventObject<RectangleF>;
get invalidCharEntered(): EventObject<void>;
get textMetrics(): ITextMetrics;
get textLimits(): ITextLimits;
get canUndo(): boolean;
get canRedo(): boolean;
get isActive(): boolean;
get isReady(): boolean;
get textMetricsChangedEvent(): EventObject<ITextMetrics>;
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData>;
private get _div();
private get _innerDiv();
isApplyingListsEnabled(): boolean;
executeCommand(commandType: CommandType, initData?: any): void;
getTextModel(): TextModel;
private _initData;
initialize(data: EditorInitData, colorPalette: IColorPalette, listStyleSheetManager: IListStyleSheetManager): void;

@@ -67,15 +77,8 @@ /** @inheritDoc */

isIndentationHidden(): boolean;
private _validateInputText;
enterEditMode(point?: IPoint): Promise<void>;
private _convertInputEventToKeyboardCommand;
exitEditMode(): void;
ensureFocus(): void;
getFormattedText(): Promise<string>;
private _updateTextMetrics;
get textMetrics(): ITextMetrics;
get textLimits(): ITextLimits;
undo(): void;
redo(): void;
get canUndo(): boolean;
get canRedo(): boolean;
processMouseEvent(e: IMouseEvent): void;

@@ -86,4 +89,9 @@ processKeyEvent(e: KeyboardEvent): Promise<boolean>;

dispose(): void;
private get _div();
private get _innerDiv();
getInlineStyle(): ICharStyle | null;
setInlineStyle(value: ICharStyle): Promise<void>;
getParagraphStyle(): IParagraphStyle;
setParagraphStyle(value: IParagraphStyle): Promise<void>;
private _validateInputText;
private _convertInputEventToKeyboardCommand;
private _updateTextMetrics;
private _updateColors;

@@ -93,13 +101,7 @@ private _findUsedColor;

private _onSelectionChange;
get isActive(): boolean;
get isReady(): boolean;
private _updateStyles;
private _updateInlineStyles;
private _updateParagraphStyles;
getInlineStyle(): ICharStyle;
setInlineStyle(value: ICharStyle): Promise<void>;
private _removeCurrentStyles;
private _inlineStyleToCommands;
getParagraphStyle(): IParagraphStyle;
setParagraphStyle(value: IParagraphStyle): Promise<void>;
private _customParagraphCommand;

@@ -109,4 +111,2 @@ private _setDefaultStyles;

private _updateLimitsEvent;
get textMetricsChangedEvent(): EventObject<ITextMetrics>;
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData>;
}

@@ -60,5 +60,5 @@ import { Color } from "@aurigma/design-atoms-model/Colors";

});
this._htmlSerializer = new HtmlSerializer(this._fontService, this._colorPreviewService, this._colorParser, this._useSimpleFontList, this._previewScale);
this._htmlSerializer = new HtmlSerializer(this._fontService, this._colorPreviewService, this._colorParser, this._useSimpleFontList);
this._gmXmlParser = new GmXmlParser(this._colorParser);
this._htmlParser = new HtmlParser(this._colorPalette, this._fontService, this._useSimpleFontList, this._previewScale, this._colorParser, this._colorPreviewService);
this._htmlParser = new HtmlParser(this._colorPalette, this._fontService, this._useSimpleFontList, this._colorParser, this._colorPreviewService);
this._GmXmlSerializer = new GmXmlSerializer(this._colorParser);

@@ -75,5 +75,2 @@ }

}
isApplyingListsEnabled() {
return true; // TODO: add disable for curved text
}
get frameChanged() {

@@ -85,2 +82,35 @@ return this._frameChangedEvent;

}
get textMetrics() {
return this._textMetrics;
}
get textLimits() {
return this._textLimits;
}
get canUndo() {
return document.queryCommandEnabled("undo");
}
get canRedo() {
return document.queryCommandEnabled("redo");
}
get isActive() {
return this._isActive;
}
get isReady() {
return this._ready;
}
get textMetricsChangedEvent() {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent() {
return this._textLimitsViolationEvent;
}
get _div() {
return this._elementHandler.textEditorDiv;
}
get _innerDiv() {
return this._elementHandler.textEditorInnerDiv;
}
isApplyingListsEnabled() {
return true; // TODO: add disable for curved text
}
executeCommand(commandType, initData) {

@@ -156,15 +186,2 @@ if (commandType === 29) { // add/remove list comand

}
_validateInputText(text, insertText) {
this._inputTextValidator.validateWithConfirmation(text).then(x => {
if (x.isTextValid)
insertText();
else {
if (x.isInputConfirmed === true) {
this.ensureFocus();
insertText();
this._invalidCharEntered.notify();
}
}
});
}
async enterEditMode(point) {

@@ -178,4 +195,4 @@ var _a, _b, _c, _d, _e, _f;

const textFormattingEnabled = (_b = data.textFormattingEnabled) !== null && _b !== void 0 ? _b : true;
const parsedObj = this._gmXmlParser.parse(data.text, this._colorPalette, null /*defaultFontSize: number*/, this._listStyleSheetManager);
const html = await this._htmlSerializer.serialize(parsedObj, this._colorPalette);
const textModel = this._gmXmlParser.parse(data.text, this._colorPalette, null, this._listStyleSheetManager);
const html = await this._htmlSerializer.serialize(textModel, this._colorPalette, this._previewScale);
this._elementHandler.showTextEditor(data.rectangle, data.textAlignment, html, data.borderWidth, data.borderColor, data.fillColor, data.opacity, data.textVerticalAlignment, data.isVertical);

@@ -286,22 +303,2 @@ await this._setDefaultStyles(data.defaultInlineStyle, data.defaultParagraphStyle);

}
_convertInputEventToKeyboardCommand(e) {
const allowedKeyPresed = (e.key === 'ArrowLeft' || e.key === 'ArrowRight' || e.key === 'ArrowUp' || e.key === 'ArrowDown'
|| e.key === 'Shift' || e.key === 'Alt' || e.key === 'Control' || e.key === 'Windows' || e.key === 'CapsLock'
|| e.key === 'NumLock' || e.key === 'Clear' || e.key === 'Home' || e.key === 'PageUp' || e.key === 'PageDown'
|| e.key === 'End' || e.key === 'NumLock' || e.key === 'Insert' || e.key === 'ScrollLock' || e.key === 'Pause'
|| e.key === 'F1' || e.key === 'F2' || e.key === 'F3' || e.key === 'F4' || e.key === 'F5' || e.key === 'F6'
|| e.key === 'F7' || e.key === 'F8' || e.key === 'F9' || e.key === 'F10' || e.key === 'F11' || e.key === 'F12'
|| e.key === 'Escape' || e.key === 'ContextMenu' || e.key === 'Meta' || e.key === 'Tab');
if (allowedKeyPresed)
return null;
if (e.key == 'Backspace')
return { type: InputCommandType.deleteToLeft };
if (e.key == 'Delete')
return { type: InputCommandType.deleteToRight };
if (e.key == 'Enter')
return { type: InputCommandType.insertNewLine };
if (e.ctrlKey)
return null;
return { type: InputCommandType.insertChar };
}
exitEditMode() {

@@ -317,21 +314,6 @@ this._isActive = false;

this._updateColors();
const text = this._elementHandler.getTextEditorFormattedText();
const defaultFontValue = HtmlProcessor.getDefaultFontValue(this._defaultInlineStyle.font);
const parsedObj = await this._htmlParser.parse(text, this._colorPalette, defaultFontValue);
return this._GmXmlSerializer.serialize(parsedObj, this._colorPalette);
const htmlText = this._elementHandler.getTextEditorFormattedText();
const textModel = await this._htmlParser.parse(htmlText, this._colorPalette, this._previewScale);
return this._GmXmlSerializer.serialize(textModel, this._colorPalette);
}
_updateTextMetrics() {
if (!this._isActive)
return;
const isChanged = this._textMetrics.update(this._innerDiv.textContent.length, HtmlProcessor.getCurrentParagraphLength(), HtmlProcessor.getCorrectLinesCount(this._innerDiv));
this._currentTextInfo.updateTextMetrics(this._textMetrics);
if (isChanged)
this._textMetricsChangedEvent.notify(this._textMetrics);
}
get textMetrics() {
return this._textMetrics;
}
get textLimits() {
return this._textLimits;
}
undo() {

@@ -343,9 +325,4 @@ document.execCommand("undo");

}
get canUndo() {
return document.queryCommandEnabled("undo");
processMouseEvent(e) {
}
get canRedo() {
return document.queryCommandEnabled("redo");
}
processMouseEvent(e) { }
async processKeyEvent(e) {

@@ -361,8 +338,98 @@ return true;

}
get _div() {
return this._elementHandler.textEditorDiv;
getInlineStyle() {
return this.isActive ? this._inlineStyle : null;
}
get _innerDiv() {
return this._elementHandler.textEditorInnerDiv;
async setInlineStyle(value) {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._inlineStyle);
if (_.isEmpty(value))
return;
const commands = this._inlineStyleToCommands(value);
if (commands.length == 0)
return;
this._focusOnDiv();
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
if (command.key == CommandKeys.color) {
const color = command.value;
if (color != null) {
const preview = await this._colorPreviewService.getPreviewAsync(color.color);
document.execCommand("foreColor", false, preview.toString());
this._usedColors.push({ preview: preview.toString(), color: color.color });
}
else
console.warn("Incorrect color value");
}
else
document.execCommand(command.key, false, command.value);
}
else
await HtmlProcessor.customInlineCommand(commands, this._range, this._innerDiv, this._colorPalette, this._colorPreviewService);
if (!(this._range == null || this._range.collapsed))
await this._onSelectionChange(false);
await this._updateStyles();
}
getParagraphStyle() {
return this.isActive ? this._paragraphStyle : null;
}
async setParagraphStyle(value) {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._paragraphStyle);
if (_.isEmpty(value))
return;
const commands = HtmlProcessor.paragraphStyleToCommands(value);
if (commands.length == 0)
return;
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
this._innerDiv.focus();
document.execCommand(command.key, false, command.value);
}
else
await this._customParagraphCommand(commands);
await this._updateStyles();
}
_validateInputText(text, insertText) {
this._inputTextValidator.validateWithConfirmation(text).then(x => {
if (x.isTextValid)
insertText();
else {
if (x.isInputConfirmed === true) {
this.ensureFocus();
insertText();
this._invalidCharEntered.notify();
}
}
});
}
_convertInputEventToKeyboardCommand(e) {
const allowedKeyPresed = (e.key === 'ArrowLeft' || e.key === 'ArrowRight' || e.key === 'ArrowUp' || e.key === 'ArrowDown'
|| e.key === 'Shift' || e.key === 'Alt' || e.key === 'Control' || e.key === 'Windows' || e.key === 'CapsLock'
|| e.key === 'NumLock' || e.key === 'Clear' || e.key === 'Home' || e.key === 'PageUp' || e.key === 'PageDown'
|| e.key === 'End' || e.key === 'NumLock' || e.key === 'Insert' || e.key === 'ScrollLock' || e.key === 'Pause'
|| e.key === 'F1' || e.key === 'F2' || e.key === 'F3' || e.key === 'F4' || e.key === 'F5' || e.key === 'F6'
|| e.key === 'F7' || e.key === 'F8' || e.key === 'F9' || e.key === 'F10' || e.key === 'F11' || e.key === 'F12'
|| e.key === 'Escape' || e.key === 'ContextMenu' || e.key === 'Meta' || e.key === 'Tab');
if (allowedKeyPresed)
return null;
if (e.key == 'Backspace')
return { type: InputCommandType.deleteToLeft };
if (e.key == 'Delete')
return { type: InputCommandType.deleteToRight };
if (e.key == 'Enter')
return { type: InputCommandType.insertNewLine };
if (e.ctrlKey)
return null;
return { type: InputCommandType.insertChar };
}
_updateTextMetrics() {
if (!this._isActive)
return;
const isChanged = this._textMetrics.update(this._innerDiv.textContent.length, HtmlProcessor.getCurrentParagraphLength(), HtmlProcessor.getCorrectLinesCount(this._innerDiv));
this._currentTextInfo.updateTextMetrics(this._textMetrics);
if (isChanged)
this._textMetricsChangedEvent.notify(this._textMetrics);
}
_updateColors() {

@@ -413,8 +480,2 @@ const spans = this._innerDiv.querySelectorAll("span[style*=color]");

}
get isActive() {
return this._isActive;
}
get isReady() {
return this._ready;
}
async _updateStyles() {

@@ -554,36 +615,2 @@ if (!this.isActive)

}
getInlineStyle() {
return this.isActive ? this._inlineStyle : null;
}
async setInlineStyle(value) {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._inlineStyle);
if (_.isEmpty(value))
return;
const commands = this._inlineStyleToCommands(value);
if (commands.length == 0)
return;
this._focusOnDiv();
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
if (command.key == CommandKeys.color) {
const color = command.value;
if (color != null) {
const preview = await this._colorPreviewService.getPreviewAsync(color.color);
document.execCommand("foreColor", false, preview.toString());
this._usedColors.push({ preview: preview.toString(), color: color.color });
}
else
console.warn("Incorrect color value");
}
else
document.execCommand(command.key, false, command.value);
}
else
await HtmlProcessor.customInlineCommand(commands, this._range, this._innerDiv, this._colorPalette, this._colorPreviewService);
if (!(this._range == null || this._range.collapsed))
await this._onSelectionChange(false);
await this._updateStyles();
}
_removeCurrentStyles(newValue, curValue) {

@@ -654,23 +681,2 @@ _.keys(newValue).forEach(k => {

}
getParagraphStyle() {
return this.isActive ? this._paragraphStyle : null;
}
async setParagraphStyle(value) {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._paragraphStyle);
if (_.isEmpty(value))
return;
const commands = HtmlProcessor.paragraphStyleToCommands(value);
if (commands.length == 0)
return;
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
this._innerDiv.focus();
document.execCommand(command.key, false, command.value);
}
else
await this._customParagraphCommand(commands);
await this._updateStyles();
}
async _customParagraphCommand(commands) {

@@ -715,8 +721,2 @@ const range = this._range;

}
get textMetricsChangedEvent() {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent() {
return this._textLimitsViolationEvent;
}
}

@@ -41,3 +41,2 @@ import { EventObject } from "@aurigma/design-atoms-model/EventObject";

private _previewScale;
private _textVerticalAlignment;
private _overflowStrategy?;

@@ -52,3 +51,2 @@ private _isBoundedText;

private _paragraphStyle;
private _cursorBlinkInterval;
private _textMetrics;

@@ -70,9 +68,2 @@ private _textLimits;

/**
* Initializes the text editor.
* @param tw text engine.
* @param itemData text item data.
* @param listStyleSheetManager style manager for lists.
*/
initialize(tw: ITextEngineWrapper, itemData: TextEditorInitData, listStyleSheetManager: IListStyleSheetManager): void;
/**
* Indicates if the editor has to be highlighted when in editing mode.

@@ -89,2 +80,34 @@ */

get isActive(): boolean;
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged(): EventObject<RectangleF>;
/**
* Invalid character input event.
*/
get invalidCharEntered(): EventObject<void>;
/**
* Character or paragraph style change event.
*/
get styleChanged(): EventObject<void>;
/**
* Indicates if the action can be undone.
*/
get canUndo(): boolean;
/**
* Indicates if the action can be redone.
*/
get canRedo(): boolean;
get textMetrics(): ITextMetrics;
get textLimits(): ITextLimits;
get textMetricsChangedEvent(): EventObject<ITextMetrics>;
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData>;
/**
* Initializes the text editor.
* @param tw text engine.
* @param itemData text item data.
* @param listStyleSheetManager style manager for lists.
*/
initialize(tw: ITextEngineWrapper, itemData: TextEditorInitData, listStyleSheetManager: IListStyleSheetManager): void;
/** @inheritDoc */

@@ -104,14 +127,4 @@ enterEditMode(point: IPoint): void;

processKeyEvent(e: IKeyboardEvent): Promise<boolean>;
private _updateTextMetrics;
processZoomChangedEvent(): Promise<boolean>;
redraw(): boolean;
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged(): EventObject<RectangleF>;
/**
* Invalid character input event.
*/
get invalidCharEntered(): EventObject<void>;
/** @inheritDoc */

@@ -121,6 +134,2 @@ getFormattedText(): Promise<string>;

getTextModel(): Text;
/**
* Character or paragraph style change event.
*/
get styleChanged(): EventObject<void>;
/** @inheritDoc */

@@ -144,10 +153,2 @@ getInlineStyle(): ICharStyle;

isApplyingListsEnabled(): boolean;
/**
* Indicates if the action can be undone.
*/
get canUndo(): boolean;
/**
* Indicates if the action can be redone.
*/
get canRedo(): boolean;
/** @inheritDoc */

@@ -166,13 +167,9 @@ undo(): void;

private _drawSelection;
private _setCursorBlinking;
private _updateCharStyle;
private _updateParagraphStyle;
private _updateTextMetrics;
private _executeCommand;
private _bindToManager;
private _unbindFromManager;
get textMetrics(): ITextMetrics;
get textLimits(): ITextLimits;
private _updateLimitsEvent;
get textMetricsChangedEvent(): EventObject<ITextMetrics>;
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData>;
}

@@ -24,3 +24,2 @@ import { EventObject } from "@aurigma/design-atoms-model/EventObject";

this._textLimits = null;
//#region - Private - Event handlers -
this._onCursorChanged = () => {

@@ -81,5 +80,3 @@ this._updateCharStyle();

this._paragraphStyle = null;
this._setCursorBlinking(500);
}
//#region - Initialization -
/**

@@ -105,2 +102,63 @@ * Indicates if the editor is initialized and ready to work.

/**
* Indicates if the editor has to be highlighted when in editing mode.
*/
get highlightInEditingModeEnabled() {
return true;
}
/**
* Indicates if the editor needs to redraw ActiveText when it is edited.
*/
get redrawActiveTextInEditMode() {
return true;
}
/**
* Indicates if the editor is in editing mode.
*/
get isActive() {
return this._isActive;
}
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged() {
return this._frameChangedEvent;
}
/**
* Invalid character input event.
*/
get invalidCharEntered() {
return this._invalidCharEntered;
}
/**
* Character or paragraph style change event.
*/
get styleChanged() {
return this._styleChangedEvent;
}
/**
* Indicates if the action can be undone.
*/
get canUndo() {
return this._textManager.canUndo;
}
/**
* Indicates if the action can be redone.
*/
get canRedo() {
return this._textManager.canRedo;
}
get textMetrics() {
return this._textMetrics;
}
get textLimits() {
return this._textLimits;
}
get textMetricsChangedEvent() {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent() {
return this._textLimitsViolationEvent;
}
/**
* Initializes the text editor.

@@ -114,3 +172,2 @@ * @param tw text engine.

this._previewScale = itemData.previewScale;
this._textVerticalAlignment = itemData.textVerticalAlignment;
this._overflowStrategy = itemData.overflowStrategy;

@@ -130,22 +187,2 @@ this._isBoundedText = itemData.isBoundedText;

}
//#endregion - Initialization -
//#region - Edit mode control -
/**
* Indicates if the editor has to be highlighted when in editing mode.
*/
get highlightInEditingModeEnabled() {
return true;
}
/**
* Indicates if the editor needs to redraw ActiveText when it is edited.
*/
get redrawActiveTextInEditMode() {
return true;
}
/**
* Indicates if the editor is in editing mode.
*/
get isActive() {
return this._isActive;
}
/** @inheritDoc */

@@ -173,4 +210,2 @@ enterEditMode(point) {

}
//#endregion - Edit mode control -
//#region - Processing commands -
/**

@@ -187,4 +222,2 @@ * Executes a command of the specified type.

}
//#endregion - Processing commands -
//#region - Mouse & keyboard processor -
/** @inheritDoc */

@@ -214,6 +247,2 @@ processMouseEvent(e) {

}
_updateTextMetrics() {
this._textMetrics = this._currentTextInfo.getTextMetrics();
this._textMetricsChangedEvent.notify(this._textMetrics);
}
async processZoomChangedEvent() {

@@ -230,17 +259,2 @@ this.redraw();

}
//#endregion - Mouse & keyboard processor -
//#region - Text -
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged() {
return this._frameChangedEvent;
}
/**
* Invalid character input event.
*/
get invalidCharEntered() {
return this._invalidCharEntered;
}
/** @inheritDoc */

@@ -254,10 +268,2 @@ async getFormattedText() {

}
//#endregion - Text -
//#region - Styles -
/**
* Character or paragraph style change event.
*/
get styleChanged() {
return this._styleChangedEvent;
}
/** @inheritDoc */

@@ -291,4 +297,2 @@ getInlineStyle() {

}
//#endregion - Styles -
//#region - Lists -
/** @inheritDoc */

@@ -314,16 +318,2 @@ isBulletedList() {

}
//#endregion - Lists -
//#region - Undo/Redo -
/**
* Indicates if the action can be undone.
*/
get canUndo() {
return this._textManager.canUndo;
}
/**
* Indicates if the action can be redone.
*/
get canRedo() {
return this._textManager.canRedo;
}
/** @inheritDoc */

@@ -337,3 +327,2 @@ undo() {

}
//#endregion - Undo/Redo -
dispose() {

@@ -363,4 +352,2 @@ }

}
//#endregion - Private - Event handlers -
//#region - Private - Rendering -
_drawCursor(isForce = false) {

@@ -378,10 +365,2 @@ if (!this._isActive)

}
_setCursorBlinking(periodInMilliseconds) {
this._cursorBlinkInterval = setInterval(() => {
if (this._isActive === true)
this._drawCursor();
}, periodInMilliseconds);
}
//#endregion - Private - Rendering -
//#region - Private - Styles -
_updateCharStyle() {

@@ -395,4 +374,6 @@ const currentStyle = this._textManager.getCurrentCharStyle();

}
//#endregion - Private - Styles -
//#region - Private - Control -
_updateTextMetrics() {
this._textMetrics = this._currentTextInfo.getTextMetrics();
this._textMetricsChangedEvent.notify(this._textMetrics);
}
_executeCommand(command) {

@@ -427,14 +408,2 @@ let commandResult = false;

}
get textMetrics() {
return this._textMetrics;
}
get textLimits() {
return this._textLimits;
}
get textMetricsChangedEvent() {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent() {
return this._textLimitsViolationEvent;
}
}
{
"name": "@aurigma/design-atoms-text",
"version": "6.23.0",
"version": "6.23.1",
"description": "",

@@ -37,3 +37,3 @@ "main": "dist/index.js",

"dependencies": {
"@aurigma/design-atoms-model": "6.6.0",
"@aurigma/design-atoms-model": "6.6.1",
"@aurigma/text-whizz": "1.6.31",

@@ -40,0 +40,0 @@ "xmldom": "^0.6.0"

import { BlockElement } from "./BlockElement";
export class Text{
export class Text {
blocks: BlockElement[] = [];
}

@@ -55,3 +55,2 @@ import {

private _useSimpleFontList: boolean,
private _previewScale: number,
private _colorParser: IColorParser,

@@ -330,7 +329,7 @@ private _colorPreviewService: IColorPreviewService) {

async parse(text: string, colorPalette: IColorPalette, defaultFontSize: number) : Promise<Text> {
async parse(text: string, colorPalette: IColorPalette, previewScale: number) : Promise<Text> {
const body = this._parse(text);
this._colorConverter = new ColorConverter(colorPalette, this._colorParser);
const result = await this._convert(body, defaultFontSize);
const result = await this._convert(body, previewScale);

@@ -435,3 +434,3 @@ return result as Text;

protected async _convertNode(originalNode: Node, children: (BlockElement | InlineElement | ListItem)[], defaultFontSize: number): Promise<BlockElement | InlineElement> {
protected async _convertNode(originalNode: Node, children: (BlockElement | InlineElement | ListItem)[], previewScale: number): Promise<BlockElement | InlineElement> {
const nodeName = this.getNodeName(originalNode);

@@ -443,5 +442,5 @@

case "p":
return this._convertParagraph(originalNode as Element, children);
return this._convertParagraph(originalNode as Element, children, previewScale);
case "span":
return await this._convertSpan(originalNode as Element, children);
return await this._convertSpan(originalNode as Element, children, previewScale);
case "u":

@@ -452,7 +451,7 @@ case "b":

case "ol":
return this._convertOrderedList(originalNode as Element, children as ListItem[], defaultFontSize);
return this._convertOrderedList(originalNode as Element, children as ListItem[]);
case "ul":
return this._convertUnorderedList(originalNode as Element, children as ListItem[], defaultFontSize);
return this._convertUnorderedList(originalNode as Element, children as ListItem[]);
case "li":
return this._convertListItem(originalNode as Element, children);
return this._convertListItem(originalNode as Element, children, previewScale);
case "br":

@@ -467,3 +466,3 @@ return this._convertBr();

protected _convertCommonListStyleToParagraphStyle(targetParagraph: Paragraph, listItemStyle: ListItemStyle, sourceListStyle: UnorderedListStyle | OrderedListStyle, defaultFontSize: number){
protected _convertCommonListStyleToParagraphStyle(targetParagraph: Paragraph, listItemStyle: ListItemStyle, sourceListStyle: UnorderedListStyle | OrderedListStyle) {
const PX_TO_PT = 0.75;

@@ -531,6 +530,6 @@ const DEFAULT_LIST_LEFT_INTENDENED = 30;

protected _convertOListItemToParagraph(listItem: ListItem, sourceList: OrderedList, startNumber: number, defaultFontSize: number){
protected _convertOListItemToParagraph(listItem: ListItem, sourceList: OrderedList, startNumber: number){
const paragraph = new Paragraph();
paragraph.inlineElements = [...listItem.content];
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style, defaultFontSize);
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style);

@@ -555,6 +554,6 @@ paragraph.listStyle.type = ListStyleType.numbers;

protected _convertUListItemToParagraph(listItem: ListItem, sourceList: UnorderedList, defaultFontSize: number) : Paragraph {
protected _convertUListItemToParagraph(listItem: ListItem, sourceList: UnorderedList) : Paragraph {
const paragraph = new Paragraph();
paragraph.inlineElements = [...listItem.content];
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style, defaultFontSize);
this._convertCommonListStyleToParagraphStyle(paragraph, listItem.style, sourceList.style);
paragraph.listStyle.type = ListStyleType.bullets;

@@ -615,3 +614,3 @@ paragraph.listStyle.bulletChar = this._convertUnorderedListBullet(sourceList?.style?.type)?.charCodeAt(0);

private async _convert(originalNode: Node, defaultFontSize: number): Promise<BlockElement | InlineElement | Text | ListItem> {
private async _convert(originalNode: Node, previewScale: number): Promise<BlockElement | InlineElement | Text | ListItem> {
let convertedChildren: (BlockElement | InlineElement)[] = [];

@@ -627,6 +626,6 @@ let unwrapedChildren: (BlockElement | InlineElement)[] = [];

if ( originalNode.childNodes.length == 1) {
const convertedList = await this._convert(childNode, defaultFontSize);
const convertedList = await this._convert(childNode, previewScale);
return convertedList;
} else {
const convertedList = await this._convert(childNode, defaultFontSize);
const convertedList = await this._convert(childNode, previewScale);
unwrapedChildren.push(convertedList); // may be we should break list and start a new one here

@@ -639,3 +638,3 @@ }

} else {
let convertedChild = await this._convert(childNode, defaultFontSize);
let convertedChild = await this._convert(childNode, previewScale);
if (Array.isArray(convertedChild)) {

@@ -650,3 +649,3 @@ for (let j = 0; j < convertedChild.length; ++j) convertedChildren.push(convertedChild[j]);

const convertedNode = await this._convertNode(originalNode, convertedChildren, defaultFontSize);
const convertedNode = await this._convertNode(originalNode, convertedChildren, previewScale);

@@ -707,3 +706,3 @@ if (unwrapedChildren.length == 0) {

private _convertParagraph(htmlParagraph: Element, children: InlineElement[]): Paragraph {
private _convertParagraph(htmlParagraph: Element, children: InlineElement[], previewScale: number): Paragraph {
const paragraph = new Paragraph();

@@ -729,3 +728,3 @@ if (children != null && children.length > 0)

let paragraphStyles = this._convertParagraphStyles(htmlStyle?.value);
let paragraphStyles = this._convertParagraphStyles(htmlStyle?.value, previewScale);
paragraph.style = paragraphStyles.style;

@@ -753,3 +752,3 @@ paragraph.listStyle = paragraphStyles.listStyle;

private _convertParagraphStyles(xmlStyle: string) : { style: ParagraphStyle, listStyle: ParagraphListStyle } {
private _convertParagraphStyles(xmlStyle: string, previewScale: number) : { style: ParagraphStyle, listStyle: ParagraphListStyle } {
if (isNullOrEmptyOrWhiteSpace(xmlStyle))

@@ -764,3 +763,3 @@ return {

return {
style: this._convertParagraphStyle(parsedStyles, this._previewScale),
style: this._convertParagraphStyle(parsedStyles, previewScale),
listStyle: this._convertParagraphListStyles(parsedStyles)

@@ -839,3 +838,3 @@ };

private _convertOrderedList(html: Element, children: ListItem[], defaultFontSize: number): OrderedList {
private _convertOrderedList(html: Element, children: ListItem[]): OrderedList {
let ol = new OrderedList();

@@ -852,3 +851,3 @@ const htmlStyle = html.getAttributeNode("style");

startNumber = (x?.style?.start)? x.style.start : null;
let paragraph = this._convertOListItemToParagraph(x, ol, startNumber, defaultFontSize);
let paragraph = this._convertOListItemToParagraph(x, ol, startNumber);
ol.items.push(paragraph);

@@ -863,3 +862,3 @@ if (startNumber != null)

private _convertUnorderedList(html: Element, children: ListItem[], defaultFontSize: number): UnorderedList {
private _convertUnorderedList(html: Element, children: ListItem[]): UnorderedList {
let ul = new UnorderedList();

@@ -875,3 +874,3 @@ const htmlStyle = html.getAttributeNode("style");

if (x instanceof ListItem){
let paragraph = this._convertUListItemToParagraph(x, ul, defaultFontSize);
let paragraph = this._convertUListItemToParagraph(x, ul);
ul.items.push(paragraph);

@@ -884,3 +883,3 @@ }

private _convertListItem(html: Element, children: InlineElement[]): ListItem | Paragraph {
private _convertListItem(html: Element, children: InlineElement[], previewScale: number): ListItem | Paragraph {
const parentNodeName = this.getNodeName(html.parentNode);

@@ -909,3 +908,3 @@ if (parentNodeName == "ol" || parentNodeName == "ul" ) {

else {
return this._convertParagraph(html, children);
return this._convertParagraph(html, children, previewScale);
}

@@ -948,3 +947,3 @@

private async _convertSpan(htmlSpan: Element, children: InlineElement[]): Promise<Span> {
private async _convertSpan(htmlSpan: Element, children: InlineElement[], previewScale: number): Promise<Span> {
const span = new Span();

@@ -955,3 +954,3 @@

span.style = await this._convertSpanStyles(htmlSpan);
span.style = await this._convertSpanStyles(htmlSpan, previewScale);

@@ -1032,3 +1031,3 @@ return span;

private async _convertSpanStyles(htmlSpan: Element): Promise<SpanStyle> {
private async _convertSpanStyles(htmlSpan: Element, previewScale: number): Promise<SpanStyle> {
const htmlStyle = htmlSpan.getAttributeNode("style")?.value;

@@ -1061,3 +1060,3 @@ const colorData = htmlSpan.getAttributeNode("colordata")?.value;

const fontSize = HtmlParser.getFontSizeValue(styles, this._previewScale);
const fontSize = HtmlParser.getFontSizeValue(styles, previewScale);
if (fontSize != null)

@@ -1073,3 +1072,3 @@ result.fontSize = NumericValueConverter.parse(`${fontSize}pt`);

const stroke = await this.getStrokeValue(styles, colors, this._colorPaletteManager, this._previewScale);
const stroke = await this.getStrokeValue(styles, colors, this._colorPaletteManager, previewScale);
if (stroke != null) {

@@ -1093,3 +1092,3 @@ if (stroke.size != null) {

const leading = HtmlParser.getLeadingValue(styles, this._previewScale);
const leading = HtmlParser.getLeadingValue(styles, previewScale);
if (leading != null)

@@ -1096,0 +1095,0 @@ result.leading = NumericValueConverter.parse(`${leading}pt`);

@@ -42,12 +42,11 @@ import {SerializationException, NotImplementedException} from "../Exceptions";

private _colorParser: IColorParser,
private _useSimpleFontList: boolean,
private _previewScale: number) {
private _useSimpleFontList: boolean) {
}
async serialize(text: Text, colorPalette: IColorPalette): Promise<string> {
async serialize(text: Text, colorPalette: IColorPalette, previewScale: number): Promise<string> {
if (text == null)
throw new SerializationException("Text must be not null");
this._colorConverter = new ColorConverter(colorPalette, this._colorParser);
let result = await this._serializeBlocks(text.blocks);
let result = await this._serializeBlocks(text.blocks, previewScale);
result = result.replace(/<p><\/p>/g, '<p><span><br /></span></p>') // change empty lines for GM <-> HTML compatibility

@@ -63,3 +62,3 @@ .replace(/<p><span> <\/span><\/p>/g, '<p><span><br /></span></p>')

private async _serializeBlocks(blocks: BlockElement[]): Promise<string> {
private async _serializeBlocks(blocks: BlockElement[], previewScale: number): Promise<string> {
if (blocks == null)

@@ -83,3 +82,3 @@ return "";

currentListContent = "";
currentListContent += await this._serializeParagraph(block);
currentListContent += await this._serializeParagraph(block, previewScale);
} else {

@@ -89,5 +88,5 @@ if (currentListType == ListStyleType.numbers

&& this._changeStartAtToContinuefromPreviousIfRequared(block, blocks[index - 1] as Paragraph) ) {
currentListContent += await this._serializeParagraph(block, true);
currentListContent += await this._serializeParagraph(block, previewScale, true);
} else {
currentListContent += await this._serializeParagraph(block);
currentListContent += await this._serializeParagraph(block, previewScale);
}

@@ -101,3 +100,3 @@ }

}
result += await this._serializeBlock(block);
result += await this._serializeBlock(block, previewScale);
}

@@ -121,9 +120,9 @@ }

private async _serializeBlock(block: BlockElement): Promise<string> {
private async _serializeBlock(block: BlockElement, previewScale: number): Promise<string> {
if (block instanceof Paragraph)
return await this._serializeParagraph(block);
return await this._serializeParagraph(block, previewScale);
else if (block instanceof OrderedList)
return await this._serializeOrderedList(block);
return await this._serializeOrderedList(block, previewScale);
else if (block instanceof UnorderedList)
return await this._serializeUnorderedList(block);
return await this._serializeUnorderedList(block, previewScale);

@@ -134,5 +133,5 @@ console.error("Unknown block type, serialization not implemented", block);

private async _serializeParagraph(p: Paragraph, setContinueFromPrevious: boolean = false): Promise<string> {
private async _serializeParagraph(p: Paragraph, previewScale: number, setContinueFromPrevious: boolean = false): Promise<string> {
let pStyleStr = this._serializeParagraphStyle(p.style, p.listStyle);
let pStyleStr = this._serializeParagraphStyle(p.style, p.listStyle, previewScale);
let pMetadataStr = this._serializeParagraphMetadata(p.metadata);

@@ -153,12 +152,12 @@ let attributes = [];

for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
resultTag = this._buildTag("p", attributes, content);
} else {
let liInnerSpanPadding = this._getLiInnerSpanPadding(p.style, p.listStyle);
let liInnerSpanPadding = this._getLiInnerSpanPadding(p.style, p.listStyle, previewScale);
if (p.inlineElements[0] instanceof Span){
content += await this._serializeSpan(<Span> p.inlineElements[0], liInnerSpanPadding);
content += await this._serializeSpan(<Span> p.inlineElements[0], previewScale, liInnerSpanPadding);
p.inlineElements.shift();
if (p.inlineElements)
for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
} else {

@@ -168,3 +167,3 @@ if (liInnerSpanPadding) content += `<span style="${liInnerSpanPadding}">`;

for (let element of p.inlineElements)
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
if (liInnerSpanPadding) content += `</span>`;

@@ -201,3 +200,3 @@ }

private _getLiInnerSpanPadding(liStyle: ParagraphStyle, liListStyle: ParagraphListStyle): string {
private _getLiInnerSpanPadding(liStyle: ParagraphStyle, liListStyle: ParagraphListStyle, previewScale: number): string {
let result = null;

@@ -212,3 +211,3 @@ const firstLineIndent = (!this._isEmpty(liStyle?.firstLineIndent))? liStyle.firstLineIndent.value : 0;

if (paddingLeft != 0)
result = `padding-left: ${HtmlSerializer.setValueInPoints(paddingLeft, this._previewScale)}`;
result = `padding-left: ${HtmlSerializer.setValueInPoints(paddingLeft, previewScale)}`;

@@ -261,3 +260,3 @@ return result;

private _serializeParagraphStyle(pStyle: ParagraphStyle, pListStyle: ParagraphListStyle) {
private _serializeParagraphStyle(pStyle: ParagraphStyle, pListStyle: ParagraphListStyle, previewScale: number) {
let styleProps = [];

@@ -273,23 +272,23 @@

const textIndent = HtmlSerializer.getCorrectTextIndentValue(firstLineIndentValue, (!this._isEmpty(pStyle.leftIndent))? pStyle.leftIndent.value : HtmlSerializer._listsLeftIndentEqualsToModelZero );
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(textIndent, this._previewScale)}`);
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(textIndent, previewScale)}`);
if (textIndent != firstLineIndentValue)
styleProps.push(`text-indent-cropped-part: ${HtmlSerializer.setValueInPoints(-textIndent + firstLineIndentValue, this._previewScale)}`);
styleProps.push(`text-indent-cropped-part: ${HtmlSerializer.setValueInPoints(-textIndent + firstLineIndentValue, previewScale)}`);
} else
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(pStyle.firstLineIndent.value, this._previewScale)}`);
styleProps.push(`text-indent: ${HtmlSerializer.setValueInPoints(pStyle.firstLineIndent.value, previewScale)}`);
}
if (!this._isEmpty(pStyle.spaceBefore))
styleProps.push(`padding-top: ${HtmlSerializer.setValueInPoints(pStyle.spaceBefore.value, this._previewScale)}`);
styleProps.push(`padding-top: ${HtmlSerializer.setValueInPoints(pStyle.spaceBefore.value, previewScale)}`);
if (!this._isEmpty(pStyle.spaceAfter))
styleProps.push(`padding-bottom: ${HtmlSerializer.setValueInPoints(pStyle.spaceAfter.value, this._previewScale)}`);
styleProps.push(`padding-bottom: ${HtmlSerializer.setValueInPoints(pStyle.spaceAfter.value, previewScale)}`);
if (!this._isEmpty(pStyle.leftIndent)){
if (!this._isEmpty(pListStyle?.type)) {
styleProps.push(`margin-left: ${HtmlSerializer.setCorrectedForListsLeftIndentValue(pStyle.leftIndent.value, this._previewScale)}`);
} else styleProps.push(`margin-left: ${HtmlSerializer.setValueInPoints(pStyle.leftIndent.value, this._previewScale)}`);
styleProps.push(`margin-left: ${HtmlSerializer.setCorrectedForListsLeftIndentValue(pStyle.leftIndent.value, previewScale)}`);
} else styleProps.push(`margin-left: ${HtmlSerializer.setValueInPoints(pStyle.leftIndent.value, previewScale)}`);
}
if (!this._isEmpty(pStyle.rightIndent))
styleProps.push(`margin-right: ${HtmlSerializer.setValueInPoints(pStyle.rightIndent.value, this._previewScale)}`);
styleProps.push(`margin-right: ${HtmlSerializer.setValueInPoints(pStyle.rightIndent.value, previewScale)}`);

@@ -303,3 +302,3 @@ }

if (!this._isEmpty(pListStyle.tabPosition)) //apply in inner span, used only to save value
styleProps.push(`bullet-number-tab-position: ${HtmlSerializer.setBulletTabPosition(pListStyle.tabPosition, this._previewScale)}`);
styleProps.push(`bullet-number-tab-position: ${HtmlSerializer.setBulletTabPosition(pListStyle.tabPosition, previewScale)}`);

@@ -388,9 +387,9 @@ if (!this._isEmpty(pListStyle.level))

private async _serializeInlineElement(e: InlineElement): Promise<string> {
if (e instanceof Span)
return await this._serializeSpan(e);
else if (e instanceof InlineText)
return this._serializeInlineText(e);
else if (e instanceof Br)
return this._serializeBr(e);
private async _serializeInlineElement(element: InlineElement, previewScale: number): Promise<string> {
if (element instanceof Span)
return await this._serializeSpan(element, previewScale);
else if (element instanceof InlineText)
return this._serializeInlineText(element);
else if (element instanceof Br)
return this._serializeBr(element);
}

@@ -402,4 +401,4 @@

private async _serializeSpan(span: Span, liPadding: string = null): Promise<string> {
let style = (span.style || liPadding) ? await this._serializeSpanStyle(span, liPadding) : null;
private async _serializeSpan(span: Span, previewScale: number, liPadding: string = null): Promise<string> {
let style = (span.style || liPadding) ? await this._serializeSpanStyle(span, previewScale, liPadding) : null;
let openTag = style ? `<span ${style}>` : '<span>';

@@ -410,3 +409,3 @@ let closeTag = '</span>';

for(let element of span.content) {
content += await this._serializeInlineElement(element);
content += await this._serializeInlineElement(element, previewScale);
}

@@ -418,3 +417,3 @@ } else content += '<br>';

private async _serializeSpanStyle(spanObj: Span, liPadding: string = null): Promise<string> {
private async _serializeSpanStyle(spanObj: Span, previewScale: number, liPadding: string = null): Promise<string> {
const style = spanObj.style;

@@ -443,7 +442,7 @@ let styleProps = [];

if (!this._isEmpty(style.fontSize)){
styleProps.push(`font-size: ${HtmlSerializer.setValueInPoints(style.fontSize.value, this._previewScale)}`);
styleProps.push(`font-size: ${HtmlSerializer.setValueInPoints(style.fontSize.value, previewScale)}`);
}
if (!this._isEmpty(style.leading)) {
styleProps.push(`line-height: ${style.leading.value === 0 ? "normal" : `${HtmlSerializer.setValueInPoints(style.leading.value, this._previewScale)}`}`);
styleProps.push(`line-height: ${style.leading.value === 0 ? "normal" : `${HtmlSerializer.setValueInPoints(style.leading.value, previewScale)}`}`);
}

@@ -463,3 +462,3 @@

const colorPreview = await this._colorPreviewSrvice.getPreviewAsync(style.penColor.color);
styleProps.push(`-webkit-text-stroke: ${HtmlSerializer.setValueInPoints(style.penWidth.value, this._previewScale)} ${colorPreview}`);
styleProps.push(`-webkit-text-stroke: ${HtmlSerializer.setValueInPoints(style.penWidth.value, previewScale)} ${colorPreview}`);
colorDataProps.push(`pen-color-index: ${this._colorConverter.serialize(style.penColor)}`);

@@ -774,3 +773,3 @@ }

private async _serializeOrderedList(list: OrderedList): Promise<string> {
private async _serializeOrderedList(list: OrderedList, previewScale: number): Promise<string> {
let olStyle = list.style ? this._serializeOrderedListStyle(list.style) : null;

@@ -782,3 +781,3 @@ let olTag = olStyle ? `<ol ${olStyle}>` : '<ol>';

for(let item of list.items) {
olContent += await this._serializeListItem(item);
olContent += await this._serializeListItem(item, previewScale);
}

@@ -803,3 +802,3 @@ return `${olTag}${olContent}</ol>`;

private async _serializeUnorderedList(list: UnorderedList): Promise<string> {
private async _serializeUnorderedList(list: UnorderedList, previewScale: number): Promise<string> {
let ulStyle = list.style ? this._serializeUnorderedListStyle(list.style) : null;

@@ -811,3 +810,3 @@ let ulTag = ulStyle ? `<ul ${ulStyle}>` : '<ul>';

for(let item of list.items) {
ulContent += await this._serializeListItem(item);
ulContent += await this._serializeListItem(item, previewScale);
}

@@ -832,6 +831,6 @@ return `${ulTag}${ulContent}</ul>`;

private async _serializeListItem(item: BlockElement): Promise<string> {
private async _serializeListItem(item: BlockElement, previewScale: number): Promise<string> {
if (item instanceof Paragraph){
return await this._serializeParagraph(item);
return await this._serializeParagraph(item, previewScale);
}

@@ -838,0 +837,0 @@ else throw new Error("not implemented");

@@ -108,3 +108,3 @@ import {EventObject} from "@aurigma/design-atoms-model/EventObject";

*/
getInlineStyle(): ICharStyle;
getInlineStyle(): ICharStyle | null;

@@ -111,0 +111,0 @@ /**

@@ -38,3 +38,5 @@ import { Color, RgbColor } from "@aurigma/design-atoms-model/Colors";

private readonly _textMetricsChangedEvent: EventObject<ITextMetrics>;
private readonly _frameChangedEvent: EventObject<RectangleF>;
private _initData: EditorInitData;
private _listStyleSheetManager: IListStyleSheetManager = null;

@@ -48,5 +50,4 @@ private _colorPalette: IColorPalette = null;

private _GmXmlSerializer: GmXmlSerializer;
private _gmXmlParser;
private _gmXmlParser: GmXmlParser;
private _range: Range = null;

@@ -115,4 +116,3 @@

this._colorParser,
this._useSimpleFontList,
this._previewScale
this._useSimpleFontList
);

@@ -125,3 +125,2 @@ this._gmXmlParser = new GmXmlParser(this._colorParser);

this._useSimpleFontList,
this._previewScale,
this._colorParser,

@@ -144,7 +143,2 @@ this._colorPreviewService

isApplyingListsEnabled(): boolean {
return true; // TODO: add disable for curved text
}
private readonly _frameChangedEvent: EventObject<RectangleF>;
get frameChanged(): EventObject<RectangleF> {

@@ -158,3 +152,46 @@ return this._frameChangedEvent;

get textMetrics() : ITextMetrics {
return this._textMetrics;
}
get textLimits(): ITextLimits {
return this._textLimits;
}
get canUndo(): boolean {
return document.queryCommandEnabled("undo");
}
get canRedo(): boolean {
return document.queryCommandEnabled("redo");
}
get isActive(): boolean {
return this._isActive;
}
get isReady(): boolean {
return this._ready;
}
get textMetricsChangedEvent(): EventObject<ITextMetrics> {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData> {
return this._textLimitsViolationEvent;
}
private get _div(): HTMLElement {
return this._elementHandler.textEditorDiv;
}
private get _innerDiv(): HTMLElement {
return this._elementHandler.textEditorInnerDiv;
}
isApplyingListsEnabled(): boolean {
return true; // TODO: add disable for curved text
}
executeCommand(commandType: CommandType, initData?: any): void {

@@ -186,4 +223,2 @@

private _initData: EditorInitData;
initialize(data: EditorInitData, colorPalette: IColorPalette, listStyleSheetManager: IListStyleSheetManager) {

@@ -218,6 +253,7 @@ this._initData = data;

getTextMetrics(){
getTextMetrics() {
return this._textMetrics;
}
getParagraphLength(index: number): number{
getParagraphLength(index: number): number {
return HtmlProcessor.getParagraphLengthByIndex(index);

@@ -234,16 +270,2 @@ }

}
private _validateInputText(text: string, insertText?: Function): void {
this._inputTextValidator.validateWithConfirmation(text).then(x => {
if (x.isTextValid)
insertText();
else {
if (x.isInputConfirmed === true) {
this.ensureFocus();
insertText();
this._invalidCharEntered.notify();
}
}
})
}

@@ -258,4 +280,4 @@ async enterEditMode(point?: IPoint): Promise<void> {

const textFormattingEnabled = data.textFormattingEnabled ?? true;
const parsedObj = this._gmXmlParser.parse(data.text, this._colorPalette, null /*defaultFontSize: number*/, this._listStyleSheetManager);
const html = await this._htmlSerializer.serialize(parsedObj, this._colorPalette);
const textModel = this._gmXmlParser.parse(data.text, this._colorPalette, null, this._listStyleSheetManager);
const html = await this._htmlSerializer.serialize(textModel, this._colorPalette, this._previewScale);
this._elementHandler.showTextEditor(data.rectangle, data.textAlignment, html, data.borderWidth, data.borderColor, data.fillColor, data.opacity, data.textVerticalAlignment, data.isVertical);

@@ -385,27 +407,2 @@ await this._setDefaultStyles(data.defaultInlineStyle, data.defaultParagraphStyle);

}
private _convertInputEventToKeyboardCommand(e: KeyboardEvent): IKeyboardInputCommand {
const allowedKeyPresed = (e.key === 'ArrowLeft' || e.key === 'ArrowRight' || e.key === 'ArrowUp' || e.key === 'ArrowDown'
|| e.key === 'Shift' || e.key === 'Alt' || e.key === 'Control' || e.key === 'Windows' || e.key === 'CapsLock'
|| e.key === 'NumLock' || e.key === 'Clear' || e.key === 'Home' || e.key === 'PageUp' || e.key === 'PageDown'
|| e.key === 'End' || e.key === 'NumLock' || e.key === 'Insert' || e.key === 'ScrollLock' || e.key === 'Pause'
|| e.key === 'F1' || e.key === 'F2' || e.key === 'F3' || e.key === 'F4' || e.key === 'F5' || e.key === 'F6'
|| e.key === 'F7' || e.key === 'F8' || e.key === 'F9' || e.key === 'F10' || e.key === 'F11' || e.key === 'F12'
|| e.key === 'Escape' || e.key === 'ContextMenu' || e.key === 'Meta' || e.key === 'Tab');
if (allowedKeyPresed)
return null;
if (e.key == 'Backspace')
return {type: InputCommandType.deleteToLeft};
if (e.key == 'Delete')
return {type: InputCommandType.deleteToRight};
if (e.key == 'Enter')
return {type: InputCommandType.insertNewLine};
if (e.ctrlKey)
return null;
return {type: InputCommandType.insertChar}
}

@@ -424,33 +421,8 @@ exitEditMode() {

this._updateColors();
const text = this._elementHandler.getTextEditorFormattedText();
const defaultFontValue = HtmlProcessor.getDefaultFontValue(this._defaultInlineStyle.font);
const parsedObj = await this._htmlParser.parse(text, this._colorPalette, defaultFontValue as number);
return this._GmXmlSerializer.serialize(parsedObj, this._colorPalette);
}
const htmlText = this._elementHandler.getTextEditorFormattedText();
const textModel = await this._htmlParser.parse(htmlText, this._colorPalette, this._previewScale);
private _updateTextMetrics(){
if (!this._isActive)
return;
const isChanged = this._textMetrics.update(this._innerDiv.textContent.length,
HtmlProcessor.getCurrentParagraphLength(),
HtmlProcessor.getCorrectLinesCount(this._innerDiv));
this._currentTextInfo.updateTextMetrics(this._textMetrics);
if (isChanged)
this._textMetricsChangedEvent.notify(this._textMetrics);
return this._GmXmlSerializer.serialize(textModel, this._colorPalette);
}
get textMetrics() : ITextMetrics {
return this._textMetrics;
}
get textLimits(): ITextLimits {
return this._textLimits;
}
undo(): void {

@@ -463,12 +435,6 @@ document.execCommand("undo");

}
get canUndo(): boolean {
return document.queryCommandEnabled("undo");
}
get canRedo(): boolean {
return document.queryCommandEnabled("redo");
processMouseEvent(e: IMouseEvent): void {
}
processMouseEvent(e: IMouseEvent): void { }

@@ -484,15 +450,129 @@ async processKeyEvent(e: KeyboardEvent): Promise<boolean> {

redraw(): void {
}
dispose(): void {
}
getInlineStyle(): ICharStyle | null {
return this.isActive ? this._inlineStyle : null;
}
private get _div(): HTMLElement {
return this._elementHandler.textEditorDiv;
async setInlineStyle(value: ICharStyle): Promise<void> {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._inlineStyle);
if (_.isEmpty(value))
return;
const commands = this._inlineStyleToCommands(value);
if (commands.length == 0)
return;
this._focusOnDiv();
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
if (command.key == CommandKeys.color) {
const color = command.value as IColorData;
if (color != null) {
const preview = await this._colorPreviewService.getPreviewAsync(color.color);
document.execCommand("foreColor", false, preview.toString());
this._usedColors.push({ preview: preview.toString(), color: color.color });
}
else
console.warn("Incorrect color value");
} else
document.execCommand(command.key, false, command.value);
} else
await HtmlProcessor.customInlineCommand(commands, this._range, this._innerDiv, this._colorPalette, this._colorPreviewService);
if (!(this._range == null || this._range.collapsed))
await this._onSelectionChange(false);
await this._updateStyles();
}
getParagraphStyle(): IParagraphStyle {
return this.isActive ? this._paragraphStyle : null;
}
async setParagraphStyle(value: IParagraphStyle): Promise<void> {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._paragraphStyle);
if (_.isEmpty(value))
return;
const commands = HtmlProcessor.paragraphStyleToCommands(value);
if (commands.length == 0)
return;
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
this._innerDiv.focus();
document.execCommand(command.key, false, command.value);
} else
await this._customParagraphCommand(commands);
private get _innerDiv(): HTMLElement {
return this._elementHandler.textEditorInnerDiv;
await this._updateStyles();
}
private _validateInputText(text: string, insertText?: Function): void {
this._inputTextValidator.validateWithConfirmation(text).then(x => {
if (x.isTextValid)
insertText();
else {
if (x.isInputConfirmed === true) {
this.ensureFocus();
insertText();
this._invalidCharEntered.notify();
}
}
})
}
private _convertInputEventToKeyboardCommand(e: KeyboardEvent): IKeyboardInputCommand {
const allowedKeyPresed = (e.key === 'ArrowLeft' || e.key === 'ArrowRight' || e.key === 'ArrowUp' || e.key === 'ArrowDown'
|| e.key === 'Shift' || e.key === 'Alt' || e.key === 'Control' || e.key === 'Windows' || e.key === 'CapsLock'
|| e.key === 'NumLock' || e.key === 'Clear' || e.key === 'Home' || e.key === 'PageUp' || e.key === 'PageDown'
|| e.key === 'End' || e.key === 'NumLock' || e.key === 'Insert' || e.key === 'ScrollLock' || e.key === 'Pause'
|| e.key === 'F1' || e.key === 'F2' || e.key === 'F3' || e.key === 'F4' || e.key === 'F5' || e.key === 'F6'
|| e.key === 'F7' || e.key === 'F8' || e.key === 'F9' || e.key === 'F10' || e.key === 'F11' || e.key === 'F12'
|| e.key === 'Escape' || e.key === 'ContextMenu' || e.key === 'Meta' || e.key === 'Tab');
if (allowedKeyPresed)
return null;
if (e.key == 'Backspace')
return {type: InputCommandType.deleteToLeft};
if (e.key == 'Delete')
return {type: InputCommandType.deleteToRight};
if (e.key == 'Enter')
return {type: InputCommandType.insertNewLine};
if (e.ctrlKey)
return null;
return {type: InputCommandType.insertChar}
}
private _updateTextMetrics(){
if (!this._isActive)
return;
const isChanged = this._textMetrics.update(this._innerDiv.textContent.length,
HtmlProcessor.getCurrentParagraphLength(),
HtmlProcessor.getCorrectLinesCount(this._innerDiv));
this._currentTextInfo.updateTextMetrics(this._textMetrics);
if (isChanged)
this._textMetricsChangedEvent.notify(this._textMetrics);
}
private _updateColors(): void {

@@ -556,10 +636,2 @@ const spans = this._innerDiv.querySelectorAll("span[style*=color]");

get isActive(): boolean {
return this._isActive;
}
get isReady(): boolean {
return this._ready;
}
private async _updateStyles(): Promise<void> {

@@ -736,43 +808,3 @@ if (!this.isActive)

}
getInlineStyle(): ICharStyle {
return this.isActive ? this._inlineStyle : null;
}
async setInlineStyle(value: ICharStyle): Promise<void> {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._inlineStyle);
if (_.isEmpty(value))
return;
const commands = this._inlineStyleToCommands(value);
if (commands.length == 0)
return;
this._focusOnDiv();
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
if (command.key == CommandKeys.color) {
const color = command.value as IColorData;
if (color != null) {
const preview = await this._colorPreviewService.getPreviewAsync(color.color);
document.execCommand("foreColor", false, preview.toString());
this._usedColors.push({ preview: preview.toString(), color: color.color });
}
else
console.warn("Incorrect color value");
} else
document.execCommand(command.key, false, command.value);
} else
await HtmlProcessor.customInlineCommand(commands, this._range, this._innerDiv, this._colorPalette, this._colorPreviewService);
if (!(this._range == null || this._range.collapsed))
await this._onSelectionChange(false);
await this._updateStyles();
}
private _removeCurrentStyles(newValue: object, curValue: object) {

@@ -862,29 +894,3 @@ _.keys(newValue).forEach(k => {

}
getParagraphStyle(): IParagraphStyle {
return this.isActive ? this._paragraphStyle : null;
}
async setParagraphStyle(value: IParagraphStyle): Promise<void> {
if (!this.isActive)
return;
this._removeCurrentStyles(value, this._paragraphStyle);
if (_.isEmpty(value))
return;
const commands = HtmlProcessor.paragraphStyleToCommands(value);
if (commands.length == 0)
return;
const command = commands[0];
if (commands.length == 1 && CommandKeys.documentCommands.includes(command.key)) {
this._innerDiv.focus();
document.execCommand(command.key, false, command.value);
} else
await this._customParagraphCommand(commands);
await this._updateStyles();
}
private async _customParagraphCommand(commands: Command[]): Promise<void> {

@@ -938,10 +944,2 @@ const range = this._range;

}
get textMetricsChangedEvent(): EventObject<ITextMetrics> {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData> {
return this._textLimitsViolationEvent;
}
}

@@ -54,3 +54,2 @@ import {EventObject} from "@aurigma/design-atoms-model/EventObject";

private _previewScale: number;
private _textVerticalAlignment: TextVerticalAlignment;
private _overflowStrategy?: OverflowStrategy;

@@ -67,3 +66,2 @@ private _isBoundedText: boolean;

private _paragraphStyle: IParagraphStyle;
private _cursorBlinkInterval: any;

@@ -100,8 +98,4 @@ private _textMetrics: ITextMetrics = null;

this._paragraphStyle = null;
this._setCursorBlinking(500);
}
//#region - Initialization -
/**

@@ -130,2 +124,75 @@ * Indicates if the editor is initialized and ready to work.

/**
* Indicates if the editor has to be highlighted when in editing mode.
*/
get highlightInEditingModeEnabled(): boolean{
return true;
}
/**
* Indicates if the editor needs to redraw ActiveText when it is edited.
*/
get redrawActiveTextInEditMode(): boolean{
return true;
}
/**
* Indicates if the editor is in editing mode.
*/
get isActive(): boolean {
return this._isActive;
}
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged(): EventObject<RectangleF> {
return this._frameChangedEvent;
}
/**
* Invalid character input event.
*/
get invalidCharEntered(): EventObject<void> {
return this._invalidCharEntered;
}
/**
* Character or paragraph style change event.
*/
get styleChanged(): EventObject<void> {
return this._styleChangedEvent;
}
/**
* Indicates if the action can be undone.
*/
get canUndo(): boolean {
return this._textManager.canUndo;
}
/**
* Indicates if the action can be redone.
*/
get canRedo(): boolean {
return this._textManager.canRedo;
}
get textMetrics() : ITextMetrics {
return this._textMetrics;
}
get textLimits(): ITextLimits {
return this._textLimits;
}
get textMetricsChangedEvent(): EventObject<ITextMetrics> {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData> {
return this._textLimitsViolationEvent;
}
/**
* Initializes the text editor.

@@ -142,3 +209,2 @@ * @param tw text engine.

this._previewScale = itemData.previewScale;
this._textVerticalAlignment = itemData.textVerticalAlignment;
this._overflowStrategy = itemData.overflowStrategy;

@@ -163,28 +229,2 @@ this._isBoundedText = itemData.isBoundedText;

//#endregion - Initialization -
//#region - Edit mode control -
/**
* Indicates if the editor has to be highlighted when in editing mode.
*/
get highlightInEditingModeEnabled(): boolean{
return true;
}
/**
* Indicates if the editor needs to redraw ActiveText when it is edited.
*/
get redrawActiveTextInEditMode(): boolean{
return true;
}
/**
* Indicates if the editor is in editing mode.
*/
get isActive(): boolean {
return this._isActive;
}
/** @inheritDoc */

@@ -218,6 +258,2 @@ enterEditMode(point: IPoint): void {

//#endregion - Edit mode control -
//#region - Processing commands -
/**

@@ -234,6 +270,2 @@ * Executes a command of the specified type.

//#endregion - Processing commands -
//#region - Mouse & keyboard processor -
/** @inheritDoc */

@@ -269,7 +301,2 @@ processMouseEvent(e: IMouseEvent): boolean {

private _updateTextMetrics(){
this._textMetrics = this._currentTextInfo.getTextMetrics();
this._textMetricsChangedEvent.notify(this._textMetrics);
}
async processZoomChangedEvent(): Promise<boolean> {

@@ -282,3 +309,3 @@

redraw(){
redraw() {
if (!this._isReady)

@@ -292,21 +319,2 @@ return false;

//#endregion - Mouse & keyboard processor -
//#region - Text -
/**
* Text frame change event.
* @remarks Reports the currently text frame.
*/
get frameChanged(): EventObject<RectangleF> {
return this._frameChangedEvent;
}
/**
* Invalid character input event.
*/
get invalidCharEntered(): EventObject<void> {
return this._invalidCharEntered;
}
/** @inheritDoc */

@@ -322,13 +330,2 @@ async getFormattedText(): Promise<string> {

//#endregion - Text -
//#region - Styles -
/**
* Character or paragraph style change event.
*/
get styleChanged(): EventObject<void> {
return this._styleChangedEvent;
}
/** @inheritDoc */

@@ -370,6 +367,2 @@ getInlineStyle(): ICharStyle {

//#endregion - Styles -
//#region - Lists -
/** @inheritDoc */

@@ -402,20 +395,2 @@ isBulletedList(): boolean {

//#endregion - Lists -
//#region - Undo/Redo -
/**
* Indicates if the action can be undone.
*/
get canUndo(): boolean {
return this._textManager.canUndo;
}
/**
* Indicates if the action can be redone.
*/
get canRedo(): boolean {
return this._textManager.canRedo;
}
/** @inheritDoc */

@@ -431,9 +406,6 @@ undo(): void {

//#endregion - Undo/Redo -
dispose(): void {
dispose(): void {
}
//#region - Private - Event handlers -
private _onCursorChanged = () => {

@@ -507,6 +479,2 @@ this._updateCharStyle();

//#endregion - Private - Event handlers -
//#region - Private - Rendering -
private _drawCursor(isForce = false) {

@@ -527,13 +495,2 @@ if (!this._isActive)

private _setCursorBlinking(periodInMilliseconds: number): void {
this._cursorBlinkInterval = setInterval(() => {
if (this._isActive === true)
this._drawCursor();
}, periodInMilliseconds);
}
//#endregion - Private - Rendering -
//#region - Private - Styles -
private _updateCharStyle(): void {

@@ -549,6 +506,7 @@ const currentStyle = this._textManager.getCurrentCharStyle();

//#endregion - Private - Styles -
private _updateTextMetrics(){
this._textMetrics = this._currentTextInfo.getTextMetrics();
this._textMetricsChangedEvent.notify(this._textMetrics);
}
//#region - Private - Control -
private _executeCommand(command: ICommand): boolean {

@@ -588,23 +546,5 @@ let commandResult = false;

get textMetrics() : ITextMetrics {
return this._textMetrics;
}
get textLimits(): ITextLimits {
return this._textLimits;
}
private _updateLimitsEvent = (data: ILimitsViolationEventData) => {
this?._textLimitsViolationEvent.notify(data);
}
get textMetricsChangedEvent(): EventObject<ITextMetrics> {
return this._textMetricsChangedEvent;
}
get textLimitsViolationEvent(): EventObject<ILimitsViolationEventData> {
return this._textLimitsViolationEvent;
}
//#endregion - Private - Control -
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc