Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

abstract-document

Package Overview
Dependencies
137
Maintainers
14
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.10.4 to 6.11.0

lib/abstract-document-exporters/__tests__/pdf/test-defs/manual-line-break-empty-lines.d.ts

12

CHANGELOG.md

@@ -5,6 +5,16 @@ # Change Log

## [Unreleased](https://github.com/dividab/abstract-visuals/compare/abstract-document@6.9.6...master)
## [Unreleased](https://github.com/dividab/abstract-visuals/compare/abstract-document@6.10.4...master)
### Added
- Added support for explicit line breaks inside paragraphs
### Changed
### Removed
## [6.10.4](https://github.com/dividab/abstract-visuals/compare/abstract-document@6.9.6...abstract-document@6.10.4) - 2023-04-25
### Added
- Abstract doc xml

@@ -11,0 +21,0 @@

84

lib/abstract-document-exporters/pdf/measure.js

@@ -83,37 +83,52 @@ "use strict";

const contentAvailableSize = AD.Size.create(contentAvailableWidth, contentAvailableHeight);
const initialHeight = style.margins.top + style.margins.bottom;
let desiredHeight = initialHeight;
let currentRowWidth = 0;
let currentRowHeight = 0;
let paragraphHeight = style.margins.top + style.margins.bottom;
let desiredSizes = new Map();
let concatenatedText = "";
let hasAtomImage = false;
let textOptions;
for (let atom of paragraph.children) {
if (atom.type === "Image") {
hasAtomImage = true;
const rows = [];
let currentRow = [];
for (const atom of paragraph.children) {
currentRow.push(atom);
if (atom.type === "LineBreak") {
rows.push(currentRow);
currentRow = [];
}
const atomSize = measureAtom(pdf, resources, style.textStyle, contentAvailableSize, contentAvailableSize.width - currentRowWidth, atom);
if (atom.type === "TextRun" || atom.type === "TextField" || atom.type === "HyperLink") {
concatenatedText += atom.text;
textOptions = getBiggestStyle(atom, style, resources, textOptions);
}
if (currentRow.length > 0) {
rows.push(currentRow);
}
for (const row of rows) {
let desiredHeight = 0;
let currentRowWidth = 0;
let currentRowHeight = 0;
let concatenatedText = "";
let hasAtomImage = false;
let textOptions;
for (const atom of row) {
if (atom.type === "Image") {
hasAtomImage = true;
}
const atomSize = measureAtom(pdf, resources, style.textStyle, contentAvailableSize, contentAvailableSize.width - currentRowWidth, atom);
if (atom.type === "TextRun" || atom.type === "TextField" || atom.type === "HyperLink") {
concatenatedText += atom.text;
textOptions = getBiggestStyle(atom, style, resources, textOptions);
}
desiredSizes.set(atom, atomSize);
currentRowWidth += atomSize.width;
currentRowHeight = Math.max(atomSize.height, currentRowHeight);
if (currentRowWidth > contentAvailableSize.width) {
desiredHeight += currentRowHeight;
currentRowWidth = 0;
currentRowHeight = 0;
}
}
desiredSizes.set(atom, atomSize);
currentRowWidth += atomSize.width;
currentRowHeight = Math.max(atomSize.height, currentRowHeight);
if (currentRowWidth > contentAvailableSize.width) {
desiredHeight += currentRowHeight;
currentRowWidth = 0;
currentRowHeight = 0;
if (row.length === 1 && row[0].type === "LineBreak") {
paragraphHeight += currentRowHeight;
}
else if (hasAtomImage) {
paragraphHeight += desiredHeight + currentRowHeight;
}
else {
paragraphHeight += pdf.heightOfString(concatenatedText, Object.assign({ width: textOptions && textOptions.lineBreak === false ? Infinity : availableSize.width }, textOptions));
}
}
if (hasAtomImage) {
desiredHeight += currentRowHeight;
}
else {
desiredHeight =
initialHeight +
pdf.heightOfString(concatenatedText, Object.assign({ width: textOptions && textOptions.lineBreak === false ? Infinity : availableSize.width }, textOptions));
}
desiredSizes.set(paragraph, AD.Size.create(availableSize.width, desiredHeight));
desiredSizes.set(paragraph, AD.Size.create(availableSize.width, paragraphHeight));
return desiredSizes;

@@ -229,2 +244,4 @@ }

return measureTocSeparator(pdf, textStyle, availableSize, availableRowSpace);
case "LineBreak":
return measureLineBreak(pdf, resources, textStyle, availableSize);
case "LinkTarget":

@@ -239,2 +256,9 @@ return {

}
function measureLineBreak(pdf, resources, textStyle, availableSize) {
const textSize = measureText(pdf, "A", textStyle, availableSize);
return {
height: textSize.height,
width: 0,
};
}
function measureTextRun(pdf, resources, textStyle, textRun, availableSize) {

@@ -241,0 +265,0 @@ const style = AD.Resources.getNestedStyle(textStyle, textRun.style, "TextStyle", textRun.styleName, resources, textRun.nestedStyleNames || []);

@@ -186,2 +186,3 @@ "use strict";

function renderParagraph(resources, pdf, desiredSizes, finalRect, paragraph) {
var _a;
const style = AD.Resources.getStyle(undefined, paragraph.style, "ParagraphStyle", paragraph.styleName, resources);

@@ -194,2 +195,8 @@ const availableWidth = finalRect.width - (style.margins.left + style.margins.right);

for (const atom of paragraph.children) {
if (atom.type === "LineBreak") {
currentRow.push(atom);
rows.push(currentRow);
currentRow = [];
continue;
}
if (!previousAtomType) {

@@ -268,3 +275,3 @@ // First atom

let rowHeight = 0;
const lastIndex = row.length - 1;
const lastIndex = ((_a = row[row.length - 1]) === null || _a === void 0 ? void 0 : _a.type) === "LineBreak" ? row.length - 2 : row.length - 1;
for (const [i, atom] of row.entries()) {

@@ -312,2 +319,4 @@ const atomSize = getDesiredSize(atom, desiredSizes);

return;
case "LineBreak":
return;
}

@@ -314,0 +323,0 @@ }

@@ -1,2 +0,2 @@

import { Group as Group1, Paragraph as Paragraph1, Table as Table1, TableRow as TableRow1, TableCell as TableCell1, HyperLink as HyperLink1, LinkTarget as LinkTarget1, TocSeparator as TocSeparator1, Image as Image1, Markdown as Markdown1, TextField as TextField1, TextRun as TextRun1, PageBreak as PageBreak1 } from "../abstract-document/index";
import { Group as Group1, Paragraph as Paragraph1, Table as Table1, TableRow as TableRow1, TableCell as TableCell1, HyperLink as HyperLink1, LinkTarget as LinkTarget1, TocSeparator as TocSeparator1, Image as Image1, Markdown as Markdown1, TextField as TextField1, TextRun as TextRun1, PageBreak as PageBreak1, LineBreak as LineBreak1 } from "../abstract-document/index";
export interface ChildrenProp {

@@ -26,3 +26,4 @@ readonly children?: Child;

export declare const PageBreak: (props: PageBreak1.PageBreakProps) => JSX.Element;
export declare const LineBreak: (props: LineBreak1.LineBreakProps) => JSX.Element;
export declare function render(element: any): any;
//# sourceMappingURL=index.d.ts.map

@@ -22,3 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.render = exports.PageBreak = exports.TextRun = exports.TextField = exports.Markdown = exports.TocSeparator = exports.Image = exports.LinkTarget = exports.HyperLink = exports.TableCell = exports.TableRow = exports.Table = exports.Paragraph = exports.Group = exports.Section = exports.AbstractDoc = void 0;
exports.render = exports.LineBreak = exports.PageBreak = exports.TextRun = exports.TextField = exports.Markdown = exports.TocSeparator = exports.Image = exports.LinkTarget = exports.HyperLink = exports.TableCell = exports.TableRow = exports.Table = exports.Paragraph = exports.Group = exports.Section = exports.AbstractDoc = void 0;
const R = __importStar(require("ramda"));

@@ -56,2 +56,4 @@ const index_1 = require("../abstract-document/index");

exports.PageBreak = PageBreak;
const LineBreak = (props) => index_1.LineBreak.create(props);
exports.LineBreak = LineBreak;
function render(element) {

@@ -58,0 +60,0 @@ if (typeof element.type !== "function") {

@@ -7,3 +7,4 @@ import { Image } from "./image";

import { LinkTarget } from "./link-target";
export declare type Atom = Image | TextField | TextRun | HyperLink | TocSeparator | LinkTarget;
import { LineBreak } from "./line-break";
export declare type Atom = Image | TextField | TextRun | HyperLink | TocSeparator | LinkTarget | LineBreak;
//# sourceMappingURL=atom.d.ts.map

@@ -8,2 +8,3 @@ import * as AbstractDoc from "./abstract-doc";

import * as LinkTarget from "./atoms/link-target";
import * as LineBreak from "./atoms/line-break";
import * as TocSeparator from "./atoms/toc-separator";

@@ -45,3 +46,3 @@ import * as Font from "./primitives/font";

import * as Position from "./styles/position";
export { AbstractDoc, Atom, Image, TextField, TextRun, HyperLink, LinkTarget, TocSeparator, Font, Numbering, NumberingDefinition, NumberingFormat, NumberingLevelDefinition, MasterPage, Section, Length, ImageResource, LayoutFoundation, LayoutFoundationColor, Point, Rect, Size, Group, Paragraph, ParagraphNumbering, SectionElement, Table, Markdown, PageStyle, ParagraphStyle, Style, StyleKey, TableCellStyle, TableStyle, TextStyle, TableCell, TableRow, DefaultStyles, Resources, Types, PageBreak, Position, GroupStyle, };
export { AbstractDoc, Atom, Image, TextField, TextRun, HyperLink, LinkTarget, LineBreak, TocSeparator, Font, Numbering, NumberingDefinition, NumberingFormat, NumberingLevelDefinition, MasterPage, Section, Length, ImageResource, LayoutFoundation, LayoutFoundationColor, Point, Rect, Size, Group, Paragraph, ParagraphNumbering, SectionElement, Table, Markdown, PageStyle, ParagraphStyle, Style, StyleKey, TableCellStyle, TableStyle, TextStyle, TableCell, TableRow, DefaultStyles, Resources, Types, PageBreak, Position, GroupStyle, };
//# sourceMappingURL=index.d.ts.map

@@ -22,3 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.GroupStyle = exports.Position = exports.PageBreak = exports.Types = exports.Resources = exports.DefaultStyles = exports.TableRow = exports.TableCell = exports.TextStyle = exports.TableStyle = exports.TableCellStyle = exports.StyleKey = exports.Style = exports.ParagraphStyle = exports.PageStyle = exports.Markdown = exports.Table = exports.SectionElement = exports.ParagraphNumbering = exports.Paragraph = exports.Group = exports.Size = exports.Rect = exports.Point = exports.LayoutFoundationColor = exports.LayoutFoundation = exports.ImageResource = exports.Length = exports.Section = exports.MasterPage = exports.NumberingLevelDefinition = exports.NumberingFormat = exports.NumberingDefinition = exports.Numbering = exports.Font = exports.TocSeparator = exports.LinkTarget = exports.HyperLink = exports.TextRun = exports.TextField = exports.Image = exports.Atom = exports.AbstractDoc = void 0;
exports.GroupStyle = exports.Position = exports.PageBreak = exports.Types = exports.Resources = exports.DefaultStyles = exports.TableRow = exports.TableCell = exports.TextStyle = exports.TableStyle = exports.TableCellStyle = exports.StyleKey = exports.Style = exports.ParagraphStyle = exports.PageStyle = exports.Markdown = exports.Table = exports.SectionElement = exports.ParagraphNumbering = exports.Paragraph = exports.Group = exports.Size = exports.Rect = exports.Point = exports.LayoutFoundationColor = exports.LayoutFoundation = exports.ImageResource = exports.Length = exports.Section = exports.MasterPage = exports.NumberingLevelDefinition = exports.NumberingFormat = exports.NumberingDefinition = exports.Numbering = exports.Font = exports.TocSeparator = exports.LineBreak = exports.LinkTarget = exports.HyperLink = exports.TextRun = exports.TextField = exports.Image = exports.Atom = exports.AbstractDoc = void 0;
const AbstractDoc = __importStar(require("./abstract-doc"));

@@ -38,2 +38,4 @@ exports.AbstractDoc = AbstractDoc;

exports.LinkTarget = LinkTarget;
const LineBreak = __importStar(require("./atoms/line-break"));
exports.LineBreak = LineBreak;
const TocSeparator = __importStar(require("./atoms/toc-separator"));

@@ -40,0 +42,0 @@ exports.TocSeparator = TocSeparator;

@@ -32,7 +32,7 @@ "use strict";

function preProcessMarkdownAst(ast, styles, atoms, paragraphs, d, listItemParams = undefined) {
if (ast.type === "text") {
if (ast.type === "text" || ast.type === "break") {
return { atoms, paragraphs };
} // Need to convice TS that we never go below this line with a Str element.
if (ast.children) {
ast.children.forEach((child) => {
ast.children.forEach((child, i) => {
let style = styles.slice(); // create a new copy of styles

@@ -85,2 +85,5 @@ switch (ast.type) {

}
else if (child.type === "break") {
atoms.push({ type: "LineBreak" });
}
else if (child.type === "text") {

@@ -87,0 +90,0 @@ atoms = atoms.concat(child.value.split("\n").map((v) => ({

import * as AD from "../../abstract-document/index";
export declare type AstChildElements = AstHeading | AstText | AstParagraph | AstEmphasis | AstStrong | AstSubscript | AstSuperscript | AstList | AstListItem;
export declare type AstChildElements = AstHeading | AstText | AstParagraph | AstEmphasis | AstStrong | AstSubscript | AstSuperscript | AstList | AstListItem | AstBreak;
export declare type AstElements = AstRoot | AstChildElements;

@@ -59,2 +59,5 @@ export interface AstMetaLoc {

}
export interface AstBreak {
readonly type: "break";
}
export interface MarkDownProcessData {

@@ -61,0 +64,0 @@ readonly atoms: Array<AD.Atom.Atom>;

{
"name": "abstract-document",
"version": "6.10.4",
"version": "6.11.0",
"description": "Dynamically create documents using code or JSX and render to any format",

@@ -43,3 +43,3 @@ "repository": "https://github.com/dividab/abstract-visuals/tree/master/packages/abstract-document",

},
"gitHead": "e78e62680b8ae6ff53cd593c1e229c34573ec2e2"
"gitHead": "8b02d04a7c6849d3faf9dc0033866fbe63243ef0"
}

@@ -105,47 +105,63 @@ import * as R from "ramda";

const initialHeight = style.margins.top + style.margins.bottom;
let desiredHeight = initialHeight;
let currentRowWidth = 0;
let currentRowHeight = 0;
let paragraphHeight = style.margins.top + style.margins.bottom;
let desiredSizes = new Map<any, AD.Size.Size>();
let concatenatedText = "";
let hasAtomImage = false;
let textOptions;
for (let atom of paragraph.children) {
if (atom.type === "Image") {
hasAtomImage = true;
const rows: Array<Array<AD.Atom.Atom>> = [];
let currentRow: Array<AD.Atom.Atom> = [];
for (const atom of paragraph.children) {
currentRow.push(atom);
if (atom.type === "LineBreak") {
rows.push(currentRow);
currentRow = [];
}
const atomSize = measureAtom(
pdf,
resources,
style.textStyle,
contentAvailableSize,
contentAvailableSize.width - currentRowWidth,
atom
);
if (atom.type === "TextRun" || atom.type === "TextField" || atom.type === "HyperLink") {
concatenatedText += atom.text;
textOptions = getBiggestStyle(atom, style, resources, textOptions);
}
if (currentRow.length > 0) {
rows.push(currentRow);
}
for (const row of rows) {
let desiredHeight = 0;
let currentRowWidth = 0;
let currentRowHeight = 0;
let concatenatedText = "";
let hasAtomImage = false;
let textOptions;
for (const atom of row) {
if (atom.type === "Image") {
hasAtomImage = true;
}
const atomSize = measureAtom(
pdf,
resources,
style.textStyle,
contentAvailableSize,
contentAvailableSize.width - currentRowWidth,
atom
);
if (atom.type === "TextRun" || atom.type === "TextField" || atom.type === "HyperLink") {
concatenatedText += atom.text;
textOptions = getBiggestStyle(atom, style, resources, textOptions);
}
desiredSizes.set(atom, atomSize);
currentRowWidth += atomSize.width;
currentRowHeight = Math.max(atomSize.height, currentRowHeight);
if (currentRowWidth > contentAvailableSize.width) {
desiredHeight += currentRowHeight;
currentRowWidth = 0;
currentRowHeight = 0;
}
}
desiredSizes.set(atom, atomSize);
currentRowWidth += atomSize.width;
currentRowHeight = Math.max(atomSize.height, currentRowHeight);
if (currentRowWidth > contentAvailableSize.width) {
desiredHeight += currentRowHeight;
currentRowWidth = 0;
currentRowHeight = 0;
}
}
if (hasAtomImage) {
desiredHeight += currentRowHeight;
} else {
desiredHeight =
initialHeight +
pdf.heightOfString(concatenatedText, {
if (row.length === 1 && row[0].type === "LineBreak") {
paragraphHeight += currentRowHeight;
} else if (hasAtomImage) {
paragraphHeight += desiredHeight + currentRowHeight;
} else {
paragraphHeight += pdf.heightOfString(concatenatedText, {
width: textOptions && textOptions.lineBreak === false ? Infinity : availableSize.width,
...textOptions,
});
}
}
desiredSizes.set(paragraph, AD.Size.create(availableSize.width, desiredHeight));
desiredSizes.set(paragraph, AD.Size.create(availableSize.width, paragraphHeight));

@@ -317,2 +333,4 @@ return desiredSizes;

return measureTocSeparator(pdf, textStyle, availableSize, availableRowSpace);
case "LineBreak":
return measureLineBreak(pdf, resources, textStyle, availableSize);
case "LinkTarget":

@@ -328,2 +346,15 @@ return {

function measureLineBreak(
pdf: any,
resources: AD.Resources.Resources,
textStyle: AD.TextStyle.TextStyle,
availableSize: AD.Size.Size
): AD.Size.Size {
const textSize = measureText(pdf, "A", textStyle, availableSize);
return {
height: textSize.height,
width: 0,
};
}
function measureTextRun(

@@ -330,0 +361,0 @@ pdf: any,

@@ -244,2 +244,9 @@ import * as AD from "../../abstract-document/index";

for (const atom of paragraph.children) {
if (atom.type === "LineBreak") {
currentRow.push(atom);
rows.push(currentRow);
currentRow = [];
continue;
}
if (!previousAtomType) {

@@ -324,3 +331,3 @@ // First atom

const lastIndex = row.length - 1;
const lastIndex = row[row.length - 1]?.type === "LineBreak" ? row.length - 2 : row.length - 1;
for (const [i, atom] of row.entries()) {

@@ -392,2 +399,4 @@ const atomSize = getDesiredSize(atom, desiredSizes);

return;
case "LineBreak":
return;
}

@@ -394,0 +403,0 @@ }

@@ -19,2 +19,3 @@ import * as R from "ramda";

PageBreak as PageBreak1,
LineBreak as LineBreak1,
//Resources,

@@ -58,2 +59,3 @@ //MasterPage,

export const PageBreak = (props: PageBreak1.PageBreakProps): JSX.Element => PageBreak1.create(props) as any;
export const LineBreak = (props: LineBreak1.LineBreakProps): JSX.Element => LineBreak1.create(props) as any;

@@ -60,0 +62,0 @@ export function render(element: any): any {

@@ -7,9 +7,4 @@ import { Image } from "./image";

import { LinkTarget } from "./link-target";
import { LineBreak } from "./line-break";
export type Atom =
| Image
| TextField
| TextRun
| HyperLink
| TocSeparator
| LinkTarget;
export type Atom = Image | TextField | TextRun | HyperLink | TocSeparator | LinkTarget | LineBreak;

@@ -8,2 +8,3 @@ import * as AbstractDoc from "./abstract-doc";

import * as LinkTarget from "./atoms/link-target";
import * as LineBreak from "./atoms/line-break";
import * as TocSeparator from "./atoms/toc-separator";

@@ -54,2 +55,3 @@ import * as Font from "./primitives/font";

LinkTarget,
LineBreak,
TocSeparator,

@@ -56,0 +58,0 @@ Font,

@@ -31,3 +31,3 @@ import unified from "unified";

): MarkDownProcessData {
if (ast.type === "text") {
if (ast.type === "text" || ast.type === "break") {
return { atoms, paragraphs };

@@ -37,3 +37,3 @@ } // Need to convice TS that we never go below this line with a Str element.

if (ast.children) {
ast.children.forEach((child) => {
ast.children.forEach((child, i) => {
let style = styles.slice(); // create a new copy of styles

@@ -96,2 +96,4 @@ switch (ast.type) {

atoms = []; // Flush the Atoms-array for the next paragraph.
} else if (child.type === "break") {
atoms.push({ type: "LineBreak" });
} else if (child.type === "text") {

@@ -98,0 +100,0 @@ atoms = atoms.concat(

@@ -12,3 +12,4 @@ import * as AD from "../../abstract-document/index";

| AstList
| AstListItem;
| AstListItem
| AstBreak;
export type AstElements = AstRoot | AstChildElements;

@@ -76,2 +77,6 @@

export interface AstBreak {
readonly type: "break";
}
export interface MarkDownProcessData {

@@ -78,0 +83,0 @@ readonly atoms: Array<AD.Atom.Atom>;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc