pdfmake 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -21
  3. package/README.md +75 -78
  4. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  5. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  6. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  7. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  8. package/build/fonts/Roboto.js +27 -0
  9. package/build/pdfmake.js +64552 -64404
  10. package/build/pdfmake.js.map +1 -1
  11. package/build/pdfmake.min.js +2 -2
  12. package/build/pdfmake.min.js.map +1 -1
  13. package/build/standard-fonts/Courier.js +27 -27
  14. package/build/standard-fonts/Helvetica.js +27 -27
  15. package/build/standard-fonts/Symbol.js +21 -21
  16. package/build/standard-fonts/Times.js +27 -27
  17. package/build/standard-fonts/ZapfDingbats.js +21 -21
  18. package/build/vfs_fonts.js +5 -5
  19. package/build-vfs.js +44 -44
  20. package/fonts/Roboto.js +8 -8
  21. package/js/DocMeasure.js +6 -6
  22. package/js/DocumentContext.js +8 -3
  23. package/js/ElementWriter.js +42 -16
  24. package/js/LayoutBuilder.js +141 -78
  25. package/js/Line.js +16 -16
  26. package/js/OutputDocument.js +10 -10
  27. package/js/OutputDocumentServer.js +3 -3
  28. package/js/PDFDocument.js +3 -3
  29. package/js/PageElementWriter.js +15 -9
  30. package/js/Printer.js +28 -28
  31. package/js/Renderer.js +40 -8
  32. package/js/SVGMeasure.js +10 -10
  33. package/js/StyleContextStack.js +48 -48
  34. package/js/TableProcessor.js +14 -0
  35. package/js/TextBreaker.js +17 -17
  36. package/js/TextInlines.js +33 -33
  37. package/js/base.js +4 -4
  38. package/js/browser-extensions/OutputDocumentBrowser.js +24 -24
  39. package/js/columnCalculator.js +2 -2
  40. package/js/helpers/node.js +14 -15
  41. package/js/helpers/variableType.js +18 -18
  42. package/js/qrEnc.js +38 -38
  43. package/js/virtual-fs.js +11 -11
  44. package/package.json +8 -8
  45. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
  46. package/src/3rd-party/svg-to-pdfkit/source.js +2745 -2745
  47. package/src/3rd-party/svg-to-pdfkit.js +3 -3
  48. package/src/DocMeasure.js +745 -745
  49. package/src/DocPreprocessor.js +283 -283
  50. package/src/DocumentContext.js +345 -338
  51. package/src/ElementWriter.js +441 -417
  52. package/src/LayoutBuilder.js +1336 -1262
  53. package/src/Line.js +114 -114
  54. package/src/OutputDocument.js +64 -64
  55. package/src/OutputDocumentServer.js +32 -32
  56. package/src/PDFDocument.js +174 -174
  57. package/src/PageElementWriter.js +187 -179
  58. package/src/PageSize.js +53 -53
  59. package/src/Printer.js +306 -306
  60. package/src/Renderer.js +445 -409
  61. package/src/SVGMeasure.js +109 -109
  62. package/src/StyleContextStack.js +208 -208
  63. package/src/TableProcessor.js +620 -602
  64. package/src/TextBreaker.js +168 -168
  65. package/src/TextDecorator.js +175 -175
  66. package/src/TextInlines.js +224 -224
  67. package/src/URLResolver.js +43 -43
  68. package/src/base.js +70 -70
  69. package/src/browser-extensions/OutputDocumentBrowser.js +80 -80
  70. package/src/browser-extensions/fonts/Roboto.js +27 -27
  71. package/src/browser-extensions/index.js +55 -55
  72. package/src/browser-extensions/pdfMake.js +1 -1
  73. package/src/browser-extensions/standard-fonts/Courier.js +27 -27
  74. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -27
  75. package/src/browser-extensions/standard-fonts/Symbol.js +21 -21
  76. package/src/browser-extensions/standard-fonts/Times.js +27 -27
  77. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -21
  78. package/src/browser-extensions/virtual-fs-cjs.js +1 -1
  79. package/src/columnCalculator.js +154 -154
  80. package/src/helpers/node.js +134 -136
  81. package/src/helpers/tools.js +44 -44
  82. package/src/helpers/variableType.js +50 -50
  83. package/src/index.js +16 -16
  84. package/src/qrEnc.js +796 -796
  85. package/src/standardPageSizes.js +52 -52
  86. package/src/tableLayouts.js +100 -100
  87. package/src/virtual-fs.js +66 -66
  88. package/standard-fonts/Courier.js +8 -8
  89. package/standard-fonts/Helvetica.js +8 -8
  90. package/standard-fonts/Symbol.js +5 -5
  91. package/standard-fonts/Times.js +8 -8
  92. package/standard-fonts/ZapfDingbats.js +5 -5
@@ -1,154 +1,154 @@
1
- import { isString } from './helpers/variableType';
2
-
3
- function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
4
- let autoColumns = [];
5
- let autoMin = 0;
6
- let autoMax = 0;
7
- let starColumns = [];
8
- let starMaxMin = 0;
9
- let starMaxMax = 0;
10
- let fixedColumns = [];
11
- let initial_availableWidth = availableWidth;
12
-
13
- columns.forEach(column => {
14
- if (isAutoColumn(column)) {
15
- autoColumns.push(column);
16
- autoMin += column._minWidth;
17
- autoMax += column._maxWidth;
18
- } else if (isStarColumn(column)) {
19
- starColumns.push(column);
20
- starMaxMin = Math.max(starMaxMin, column._minWidth);
21
- starMaxMax = Math.max(starMaxMax, column._maxWidth);
22
- } else {
23
- fixedColumns.push(column);
24
- }
25
- });
26
-
27
- fixedColumns.forEach((col, colIndex) => {
28
- // width specified as %
29
- if (isString(col.width) && /\d+%/.test(col.width)) {
30
- // In tables we have to take into consideration the reserved width for paddings and borders
31
- let reservedWidth = 0;
32
- if (tableNode) {
33
- const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
34
- const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
35
- const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
36
- const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
37
- if (colIndex === 0) {
38
- // first column assumes whole borderLeft and half of border right
39
- reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
40
-
41
- } else if (colIndex === fixedColumns.length - 1) {
42
- // last column assumes whole borderRight and half of border left
43
- reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
44
-
45
- } else {
46
- // Columns in the middle assume half of each border
47
- reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
48
- }
49
- }
50
- const totalAvailableWidth = initial_availableWidth + offsetTotal;
51
- col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
52
- }
53
- if (col.width < (col._minWidth) && col.elasticWidth) {
54
- col._calcWidth = col._minWidth;
55
- } else {
56
- col._calcWidth = col.width;
57
- }
58
-
59
- availableWidth -= col._calcWidth;
60
- });
61
-
62
- // http://www.freesoft.org/CIE/RFC/1942/18.htm
63
- // http://www.w3.org/TR/CSS2/tables.html#width-layout
64
- // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
65
- let minW = autoMin + starMaxMin * starColumns.length;
66
- let maxW = autoMax + starMaxMax * starColumns.length;
67
- if (minW >= availableWidth) {
68
- // case 1 - there's no way to fit all columns within available width
69
- // that's actually pretty bad situation with PDF as we have no horizontal scroll
70
- // no easy workaround (unless we decide, in the future, to split single words)
71
- // currently we simply use minWidths for all columns
72
- autoColumns.forEach(col => {
73
- col._calcWidth = col._minWidth;
74
- });
75
-
76
- starColumns.forEach(col => {
77
- col._calcWidth = starMaxMin; // starMaxMin already contains padding
78
- });
79
- } else {
80
- if (maxW < availableWidth) {
81
- // case 2 - we can fit rest of the table within available space
82
- autoColumns.forEach(col => {
83
- col._calcWidth = col._maxWidth;
84
- availableWidth -= col._calcWidth;
85
- });
86
- } else {
87
- // maxW is too large, but minW fits within available width
88
- let W = availableWidth - minW;
89
- let D = maxW - minW;
90
-
91
- autoColumns.forEach(col => {
92
- let d = col._maxWidth - col._minWidth;
93
- col._calcWidth = col._minWidth + d * W / D;
94
- availableWidth -= col._calcWidth;
95
- });
96
- }
97
-
98
- if (starColumns.length > 0) {
99
- let starSize = availableWidth / starColumns.length;
100
-
101
- starColumns.forEach(col => {
102
- col._calcWidth = starSize;
103
- });
104
- }
105
- }
106
- }
107
-
108
- function isAutoColumn(column) {
109
- return column.width === 'auto';
110
- }
111
-
112
- function isStarColumn(column) {
113
- return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
114
- }
115
-
116
- //TODO: refactor and reuse in measureTable
117
- function measureMinMax(columns) {
118
- let result = { min: 0, max: 0 };
119
- let maxStar = { min: 0, max: 0 };
120
- let starCount = 0;
121
-
122
- for (let i = 0, l = columns.length; i < l; i++) {
123
- let c = columns[i];
124
-
125
- if (isStarColumn(c)) {
126
- maxStar.min = Math.max(maxStar.min, c._minWidth);
127
- maxStar.max = Math.max(maxStar.max, c._maxWidth);
128
- starCount++;
129
- } else if (isAutoColumn(c)) {
130
- result.min += c._minWidth;
131
- result.max += c._maxWidth;
132
- } else {
133
- result.min += ((c.width !== undefined && c.width) || c._minWidth);
134
- result.max += ((c.width !== undefined && c.width) || c._maxWidth);
135
- }
136
- }
137
-
138
- if (starCount) {
139
- result.min += starCount * maxStar.min;
140
- result.max += starCount * maxStar.max;
141
- }
142
-
143
- return result;
144
- }
145
-
146
- /**
147
- * Calculates column widths
148
- */
149
- export default {
150
- buildColumnWidths: buildColumnWidths,
151
- measureMinMax: measureMinMax,
152
- isAutoColumn: isAutoColumn,
153
- isStarColumn: isStarColumn
154
- };
1
+ import { isString } from './helpers/variableType';
2
+
3
+ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
4
+ let autoColumns = [];
5
+ let autoMin = 0;
6
+ let autoMax = 0;
7
+ let starColumns = [];
8
+ let starMaxMin = 0;
9
+ let starMaxMax = 0;
10
+ let fixedColumns = [];
11
+ let initial_availableWidth = availableWidth;
12
+
13
+ columns.forEach(column => {
14
+ if (isAutoColumn(column)) {
15
+ autoColumns.push(column);
16
+ autoMin += column._minWidth;
17
+ autoMax += column._maxWidth;
18
+ } else if (isStarColumn(column)) {
19
+ starColumns.push(column);
20
+ starMaxMin = Math.max(starMaxMin, column._minWidth);
21
+ starMaxMax = Math.max(starMaxMax, column._maxWidth);
22
+ } else {
23
+ fixedColumns.push(column);
24
+ }
25
+ });
26
+
27
+ fixedColumns.forEach((col, colIndex) => {
28
+ // width specified as %
29
+ if (isString(col.width) && /\d+%/.test(col.width)) {
30
+ // In tables we have to take into consideration the reserved width for paddings and borders
31
+ let reservedWidth = 0;
32
+ if (tableNode) {
33
+ const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
34
+ const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
35
+ const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
36
+ const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
37
+ if (colIndex === 0) {
38
+ // first column assumes whole borderLeft and half of border right
39
+ reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
40
+
41
+ } else if (colIndex === fixedColumns.length - 1) {
42
+ // last column assumes whole borderRight and half of border left
43
+ reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
44
+
45
+ } else {
46
+ // Columns in the middle assume half of each border
47
+ reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
48
+ }
49
+ }
50
+ const totalAvailableWidth = initial_availableWidth + offsetTotal;
51
+ col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
52
+ }
53
+ if (col.width < (col._minWidth) && col.elasticWidth) {
54
+ col._calcWidth = col._minWidth;
55
+ } else {
56
+ col._calcWidth = col.width;
57
+ }
58
+
59
+ availableWidth -= col._calcWidth;
60
+ });
61
+
62
+ // http://www.freesoft.org/CIE/RFC/1942/18.htm
63
+ // http://www.w3.org/TR/CSS2/tables.html#width-layout
64
+ // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
65
+ let minW = autoMin + starMaxMin * starColumns.length;
66
+ let maxW = autoMax + starMaxMax * starColumns.length;
67
+ if (minW >= availableWidth) {
68
+ // case 1 - there's no way to fit all columns within available width
69
+ // that's actually pretty bad situation with PDF as we have no horizontal scroll
70
+ // no easy workaround (unless we decide, in the future, to split single words)
71
+ // currently we simply use minWidths for all columns
72
+ autoColumns.forEach(col => {
73
+ col._calcWidth = col._minWidth;
74
+ });
75
+
76
+ starColumns.forEach(col => {
77
+ col._calcWidth = starMaxMin; // starMaxMin already contains padding
78
+ });
79
+ } else {
80
+ if (maxW < availableWidth) {
81
+ // case 2 - we can fit rest of the table within available space
82
+ autoColumns.forEach(col => {
83
+ col._calcWidth = col._maxWidth;
84
+ availableWidth -= col._calcWidth;
85
+ });
86
+ } else {
87
+ // maxW is too large, but minW fits within available width
88
+ let W = availableWidth - minW;
89
+ let D = maxW - minW;
90
+
91
+ autoColumns.forEach(col => {
92
+ let d = col._maxWidth - col._minWidth;
93
+ col._calcWidth = col._minWidth + d * W / D;
94
+ availableWidth -= col._calcWidth;
95
+ });
96
+ }
97
+
98
+ if (starColumns.length > 0) {
99
+ let starSize = availableWidth / starColumns.length;
100
+
101
+ starColumns.forEach(col => {
102
+ col._calcWidth = starSize;
103
+ });
104
+ }
105
+ }
106
+ }
107
+
108
+ function isAutoColumn(column) {
109
+ return column.width === 'auto';
110
+ }
111
+
112
+ function isStarColumn(column) {
113
+ return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
114
+ }
115
+
116
+ //TODO: refactor and reuse in measureTable
117
+ function measureMinMax(columns) {
118
+ let result = { min: 0, max: 0 };
119
+ let maxStar = { min: 0, max: 0 };
120
+ let starCount = 0;
121
+
122
+ for (let i = 0, l = columns.length; i < l; i++) {
123
+ let c = columns[i];
124
+
125
+ if (isStarColumn(c)) {
126
+ maxStar.min = Math.max(maxStar.min, c._minWidth);
127
+ maxStar.max = Math.max(maxStar.max, c._maxWidth);
128
+ starCount++;
129
+ } else if (isAutoColumn(c)) {
130
+ result.min += c._minWidth;
131
+ result.max += c._maxWidth;
132
+ } else {
133
+ result.min += ((c.width !== undefined && c.width) || c._minWidth);
134
+ result.max += ((c.width !== undefined && c.width) || c._maxWidth);
135
+ }
136
+ }
137
+
138
+ if (starCount) {
139
+ result.min += starCount * maxStar.min;
140
+ result.max += starCount * maxStar.max;
141
+ }
142
+
143
+ return result;
144
+ }
145
+
146
+ /**
147
+ * Calculates column widths
148
+ */
149
+ export default {
150
+ buildColumnWidths: buildColumnWidths,
151
+ measureMinMax: measureMinMax,
152
+ isAutoColumn: isAutoColumn,
153
+ isStarColumn: isStarColumn
154
+ };
@@ -1,136 +1,134 @@
1
- import { isNumber, isString } from './variableType';
2
-
3
- function fontStringify(key, val) {
4
- if (key === 'font') {
5
- return 'font';
6
- }
7
- return val;
8
- }
9
-
10
- /**
11
- * Convert node to readable string
12
- *
13
- * @param {object} node
14
- * @returns {string}
15
- */
16
- export function stringifyNode(node) {
17
- return JSON.stringify(node, fontStringify);
18
- }
19
-
20
- /**
21
- * @param {object} node
22
- * @returns {?string}
23
- */
24
- export function getNodeId(node) {
25
- if (node.id) {
26
- return node.id;
27
- }
28
-
29
- if (Array.isArray(node.text)) {
30
- for (let n of node.text) {
31
- let nodeId = getNodeId(n);
32
- if (nodeId) {
33
- return nodeId;
34
- }
35
- }
36
- }
37
-
38
- return null;
39
- }
40
-
41
- /**
42
- * @param {object} node
43
- * @param {object} styleStack object is instance of PDFDocument
44
- * @returns {?Array}
45
- */
46
- export function getNodeMargin(node, styleStack) {
47
-
48
- function processSingleMargins(node, currentMargin, defaultMargin = 0) {
49
- if (node.marginLeft !== undefined || node.marginTop !== undefined || node.marginRight !== undefined || node.marginBottom !== undefined) {
50
- return [
51
- node.marginLeft ?? currentMargin[0] ?? defaultMargin,
52
- node.marginTop ?? currentMargin[1] ?? defaultMargin,
53
- node.marginRight ?? currentMargin[2] ?? defaultMargin,
54
- node.marginBottom ?? currentMargin[3] ?? defaultMargin
55
- ];
56
- }
57
- return currentMargin;
58
- }
59
-
60
- function flattenStyleArray(styleArray, styleStack, visited = new Set()) {
61
- styleArray = Array.isArray(styleArray) ? styleArray : [styleArray];
62
-
63
- // style is not valid array of strings
64
- if (!styleArray.every(item => isString(item))) {
65
- return {};
66
- }
67
-
68
- let flattenedStyles = {};
69
- for (let index = 0; index < styleArray.length; index++) {
70
- let styleName = styleArray[index];
71
- let style = styleStack.styleDictionary[styleName];
72
-
73
- // style not found
74
- if (style === undefined) {
75
- continue;
76
- }
77
-
78
- if (visited.has(styleName)) {
79
- continue;
80
- }
81
-
82
- visited.add(styleName);
83
-
84
- if (style.extends !== undefined) {
85
- flattenedStyles = { ...flattenStyleArray(style.extends, styleStack, visited), ...flattenedStyles };
86
- }
87
-
88
- if (style.margin !== undefined) {
89
- flattenedStyles = { margin : convertMargin(style.margin) };
90
- continue;
91
- }
92
-
93
- flattenedStyles = { margin: processSingleMargins(style, flattenedStyles.margin ?? {}, undefined) };
94
- }
95
-
96
- return flattenedStyles;
97
- }
98
-
99
- function convertMargin(margin) {
100
- if (isNumber(margin)) {
101
- margin = [margin, margin, margin, margin];
102
- } else if (Array.isArray(margin)) {
103
- if (margin.length === 2) {
104
- margin = [margin[0], margin[1], margin[0], margin[1]];
105
- }
106
- }
107
- return margin;
108
- }
109
-
110
- let margin = [undefined, undefined, undefined, undefined];
111
-
112
- if (node.style) {
113
- let styleArray = Array.isArray(node.style) ? node.style : [node.style];
114
- let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
115
-
116
- if (flattenedStyleArray) {
117
- margin = processSingleMargins(flattenedStyleArray, margin);
118
- }
119
-
120
- if (flattenedStyleArray.margin) {
121
- margin = convertMargin(flattenedStyleArray.margin);
122
- }
123
- }
124
-
125
- margin = processSingleMargins(node, margin);
126
-
127
- if (node.margin !== undefined) {
128
- margin = convertMargin(node.margin);
129
- }
130
-
131
- if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
132
- return null;
133
- }
134
-
135
- return margin;
136
- }
1
+ import { isNumber, isString } from './variableType';
2
+
3
+ function fontStringify(key, val) {
4
+ if (key === 'font') {
5
+ return 'font';
6
+ }
7
+ return val;
8
+ }
9
+
10
+ /**
11
+ * Convert node to readable string
12
+ *
13
+ * @param {object} node
14
+ * @returns {string}
15
+ */
16
+ export function stringifyNode(node) {
17
+ return JSON.stringify(node, fontStringify);
18
+ }
19
+
20
+ /**
21
+ * @param {object} node
22
+ * @returns {?string}
23
+ */
24
+ export function getNodeId(node) {
25
+ if (node.id) {
26
+ return node.id;
27
+ }
28
+
29
+ if (Array.isArray(node.text)) {
30
+ for (let n of node.text) {
31
+ let nodeId = getNodeId(n);
32
+ if (nodeId) {
33
+ return nodeId;
34
+ }
35
+ }
36
+ }
37
+
38
+ return null;
39
+ }
40
+
41
+ /**
42
+ * @param {object} node
43
+ * @param {object} styleStack object is instance of PDFDocument
44
+ * @returns {?Array}
45
+ */
46
+ export function getNodeMargin(node, styleStack) {
47
+
48
+ function processSingleMargins(node, currentMargin, defaultMargin = 0) {
49
+ if (node.marginLeft !== undefined || node.marginTop !== undefined || node.marginRight !== undefined || node.marginBottom !== undefined) {
50
+ return [
51
+ node.marginLeft ?? currentMargin[0] ?? defaultMargin,
52
+ node.marginTop ?? currentMargin[1] ?? defaultMargin,
53
+ node.marginRight ?? currentMargin[2] ?? defaultMargin,
54
+ node.marginBottom ?? currentMargin[3] ?? defaultMargin
55
+ ];
56
+ }
57
+ return currentMargin;
58
+ }
59
+
60
+ function flattenStyleArray(styleArray, styleStack, visited = new Set()) {
61
+ styleArray = Array.isArray(styleArray) ? styleArray : [styleArray];
62
+
63
+ // style is not valid array of strings
64
+ if (!styleArray.every(item => isString(item))) {
65
+ return {};
66
+ }
67
+
68
+ let flattenedStyles = {};
69
+ for (let index = 0; index < styleArray.length; index++) {
70
+ let styleName = styleArray[index];
71
+ let style = styleStack.styleDictionary[styleName];
72
+
73
+ // style not found
74
+ if (style === undefined) {
75
+ continue;
76
+ }
77
+
78
+ if (visited.has(styleName)) {
79
+ continue;
80
+ }
81
+
82
+ if (style.extends !== undefined) {
83
+ flattenedStyles = { ...flattenedStyles, ...flattenStyleArray(style.extends, styleStack, new Set([...visited, styleName])) };
84
+ }
85
+
86
+ if (style.margin !== undefined) {
87
+ flattenedStyles = { margin: convertMargin(style.margin) };
88
+ continue;
89
+ }
90
+
91
+ flattenedStyles = { margin: processSingleMargins(style, flattenedStyles.margin ?? {}, undefined) };
92
+ }
93
+
94
+ return flattenedStyles;
95
+ }
96
+
97
+ function convertMargin(margin) {
98
+ if (isNumber(margin)) {
99
+ margin = [margin, margin, margin, margin];
100
+ } else if (Array.isArray(margin)) {
101
+ if (margin.length === 2) {
102
+ margin = [margin[0], margin[1], margin[0], margin[1]];
103
+ }
104
+ }
105
+ return margin;
106
+ }
107
+
108
+ let margin = [undefined, undefined, undefined, undefined];
109
+
110
+ if (node.style) {
111
+ let styleArray = Array.isArray(node.style) ? node.style : [node.style];
112
+ let flattenedStyleArray = flattenStyleArray(styleArray, styleStack);
113
+
114
+ if (flattenedStyleArray) {
115
+ margin = processSingleMargins(flattenedStyleArray, margin);
116
+ }
117
+
118
+ if (flattenedStyleArray.margin) {
119
+ margin = convertMargin(flattenedStyleArray.margin);
120
+ }
121
+ }
122
+
123
+ margin = processSingleMargins(node, margin);
124
+
125
+ if (node.margin !== undefined) {
126
+ margin = convertMargin(node.margin);
127
+ }
128
+
129
+ if (margin[0] === undefined && margin[1] === undefined && margin[2] === undefined && margin[3] === undefined) {
130
+ return null;
131
+ }
132
+
133
+ return margin;
134
+ }
@@ -1,44 +1,44 @@
1
- export function pack(...args) {
2
- let result = {};
3
-
4
- for (let i = 0, l = args.length; i < l; i++) {
5
- let obj = args[i];
6
-
7
- if (obj) {
8
- for (let key in obj) {
9
- if (obj.hasOwnProperty(key)) {
10
- result[key] = obj[key];
11
- }
12
- }
13
- }
14
- }
15
-
16
- return result;
17
- }
18
-
19
- export function offsetVector(vector, x, y) {
20
- switch (vector.type) {
21
- case 'ellipse':
22
- case 'rect':
23
- vector.x += x;
24
- vector.y += y;
25
- break;
26
- case 'line':
27
- vector.x1 += x;
28
- vector.x2 += x;
29
- vector.y1 += y;
30
- vector.y2 += y;
31
- break;
32
- case 'polyline':
33
- for (let i = 0, l = vector.points.length; i < l; i++) {
34
- vector.points[i].x += x;
35
- vector.points[i].y += y;
36
- }
37
- break;
38
- }
39
- }
40
-
41
- export function convertToDynamicContent(staticContent) {
42
- return () => // copy to new object
43
- JSON.parse(JSON.stringify(staticContent));
44
- }
1
+ export function pack(...args) {
2
+ let result = {};
3
+
4
+ for (let i = 0, l = args.length; i < l; i++) {
5
+ let obj = args[i];
6
+
7
+ if (obj) {
8
+ for (let key in obj) {
9
+ if (obj.hasOwnProperty(key)) {
10
+ result[key] = obj[key];
11
+ }
12
+ }
13
+ }
14
+ }
15
+
16
+ return result;
17
+ }
18
+
19
+ export function offsetVector(vector, x, y) {
20
+ switch (vector.type) {
21
+ case 'ellipse':
22
+ case 'rect':
23
+ vector.x += x;
24
+ vector.y += y;
25
+ break;
26
+ case 'line':
27
+ vector.x1 += x;
28
+ vector.x2 += x;
29
+ vector.y1 += y;
30
+ vector.y2 += y;
31
+ break;
32
+ case 'polyline':
33
+ for (let i = 0, l = vector.points.length; i < l; i++) {
34
+ vector.points[i].x += x;
35
+ vector.points[i].y += y;
36
+ }
37
+ break;
38
+ }
39
+ }
40
+
41
+ export function convertToDynamicContent(staticContent) {
42
+ return () => // copy to new object
43
+ JSON.parse(JSON.stringify(staticContent));
44
+ }