@flowaccount/pdfmake 1.0.6-staging.3 → 1.0.6

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.
@@ -1,16 +1,16 @@
1
- // Browser shim for @flowaccount/node-icu-tokenizer
2
- // The original package depends on native bindings resolved via 'bindings' which
3
- // pulls in Node core modules (path) not polyfilled by default in webpack 5.
4
- // For browser builds we degrade gracefully: tokenize() will produce a single
5
- // token spanning the whole input so existing logic that iterates tokens still works.
6
-
7
- 'use strict';
8
-
9
- class BrowserTokenizer {
10
- tokenize(str) {
11
- if (typeof str !== 'string') { return []; }
12
- return [ { token: str, type: 'TEXT', start: 0, end: str.length } ];
13
- }
14
- }
15
-
1
+ // Browser shim for @flowaccount/node-icu-tokenizer
2
+ // The original package depends on native bindings resolved via 'bindings' which
3
+ // pulls in Node core modules (path) not polyfilled by default in webpack 5.
4
+ // For browser builds we degrade gracefully: tokenize() will produce a single
5
+ // token spanning the whole input so existing logic that iterates tokens still works.
6
+
7
+ 'use strict';
8
+
9
+ class BrowserTokenizer {
10
+ tokenize(str) {
11
+ if (typeof str !== 'string') { return []; }
12
+ return [ { token: str, type: 'TEXT', start: 0, end: str.length } ];
13
+ }
14
+ }
15
+
16
16
  module.exports = BrowserTokenizer;
@@ -1,55 +1,55 @@
1
- 'use strict';
2
-
3
- function VirtualFileSystem() {
4
- this.fileSystem = {};
5
- this.dataSystem = {};
6
- }
7
-
8
- VirtualFileSystem.prototype.existsSync = function (filename) {
9
- filename = fixFilename(filename);
10
- return typeof this.fileSystem[filename] !== 'undefined'
11
- || typeof this.dataSystem[filename] !== 'undefined';
12
- };
13
-
14
- VirtualFileSystem.prototype.readFileSync = function (filename, options) {
15
- filename = fixFilename(filename);
16
-
17
- var dataContent = this.dataSystem[filename];
18
- if (typeof dataContent === 'string' && options === 'utf8') {
19
- return dataContent;
20
- }
21
-
22
- if (dataContent) {
23
- return new Buffer(dataContent, typeof dataContent === 'string' ? 'base64' : undefined);
24
- }
25
-
26
- var content = this.fileSystem[filename];
27
- if (content) {
28
- return content;
29
- }
30
-
31
- throw 'File \'' + filename + '\' not found in virtual file system';
32
- };
33
-
34
- VirtualFileSystem.prototype.writeFileSync = function (filename, content) {
35
- this.fileSystem[fixFilename(filename)] = content;
36
- };
37
-
38
- VirtualFileSystem.prototype.bindFS = function (data) {
39
- this.dataSystem = data || {};
40
- };
41
-
42
-
43
- function fixFilename(filename) {
44
- if (filename.indexOf(__dirname) === 0) {
45
- filename = filename.substring(__dirname.length);
46
- }
47
-
48
- if (filename.indexOf('/') === 0) {
49
- filename = filename.substring(1);
50
- }
51
-
52
- return filename;
53
- }
54
-
55
- module.exports = new VirtualFileSystem();
1
+ 'use strict';
2
+
3
+ function VirtualFileSystem() {
4
+ this.fileSystem = {};
5
+ this.dataSystem = {};
6
+ }
7
+
8
+ VirtualFileSystem.prototype.existsSync = function (filename) {
9
+ filename = fixFilename(filename);
10
+ return typeof this.fileSystem[filename] !== 'undefined'
11
+ || typeof this.dataSystem[filename] !== 'undefined';
12
+ };
13
+
14
+ VirtualFileSystem.prototype.readFileSync = function (filename, options) {
15
+ filename = fixFilename(filename);
16
+
17
+ var dataContent = this.dataSystem[filename];
18
+ if (typeof dataContent === 'string' && options === 'utf8') {
19
+ return dataContent;
20
+ }
21
+
22
+ if (dataContent) {
23
+ return new Buffer(dataContent, typeof dataContent === 'string' ? 'base64' : undefined);
24
+ }
25
+
26
+ var content = this.fileSystem[filename];
27
+ if (content) {
28
+ return content;
29
+ }
30
+
31
+ throw 'File \'' + filename + '\' not found in virtual file system';
32
+ };
33
+
34
+ VirtualFileSystem.prototype.writeFileSync = function (filename, content) {
35
+ this.fileSystem[fixFilename(filename)] = content;
36
+ };
37
+
38
+ VirtualFileSystem.prototype.bindFS = function (data) {
39
+ this.dataSystem = data || {};
40
+ };
41
+
42
+
43
+ function fixFilename(filename) {
44
+ if (filename.indexOf(__dirname) === 0) {
45
+ filename = filename.substring(__dirname.length);
46
+ }
47
+
48
+ if (filename.indexOf('/') === 0) {
49
+ filename = filename.substring(1);
50
+ }
51
+
52
+ return filename;
53
+ }
54
+
55
+ module.exports = new VirtualFileSystem();
@@ -1,157 +1,157 @@
1
- 'use strict';
2
-
3
- var isString = require('./helpers').isString;
4
-
5
- function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
6
- var autoColumns = [],
7
- autoMin = 0, autoMax = 0,
8
- starColumns = [],
9
- starMaxMin = 0,
10
- starMaxMax = 0,
11
- fixedColumns = [],
12
- initial_availableWidth = availableWidth;
13
-
14
- columns.forEach(function (column) {
15
- if (isAutoColumn(column)) {
16
- autoColumns.push(column);
17
- autoMin += column._minWidth;
18
- autoMax += column._maxWidth;
19
- } else if (isStarColumn(column)) {
20
- starColumns.push(column);
21
- starMaxMin = Math.max(starMaxMin, column._minWidth);
22
- starMaxMax = Math.max(starMaxMax, column._maxWidth);
23
- } else {
24
- fixedColumns.push(column);
25
- }
26
- });
27
-
28
- fixedColumns.forEach(function (col, colIndex) {
29
- // width specified as %
30
- if (isString(col.width) && /\d+%/.test(col.width)) {
31
- // In tables we have to take into consideration the reserved width for paddings and borders
32
- var reservedWidth = 0;
33
- if (tableNode) {
34
- var paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
35
- var paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
36
- var borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
37
- var borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
38
- if (colIndex === 0) {
39
- // first column assumes whole borderLeft and half of border right
40
- reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
41
-
42
- } else if (colIndex === fixedColumns.length - 1) {
43
- // last column assumes whole borderRight and half of border left
44
- reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
45
-
46
- } else {
47
- // Columns in the middle assume half of each border
48
- reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
49
- }
50
- }
51
- var totalAvailableWidth = initial_availableWidth + offsetTotal;
52
- col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
53
- }
54
- if (col.width < (col._minWidth) && col.elasticWidth) {
55
- col._calcWidth = col._minWidth;
56
- } else {
57
- col._calcWidth = col.width;
58
- }
59
-
60
- availableWidth -= col._calcWidth;
61
- });
62
-
63
- // http://www.freesoft.org/CIE/RFC/1942/18.htm
64
- // http://www.w3.org/TR/CSS2/tables.html#width-layout
65
- // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
66
- var minW = autoMin + starMaxMin * starColumns.length;
67
- var maxW = autoMax + starMaxMax * starColumns.length;
68
- if (minW >= availableWidth) {
69
- // case 1 - there's no way to fit all columns within available width
70
- // that's actually pretty bad situation with PDF as we have no horizontal scroll
71
- // no easy workaround (unless we decide, in the future, to split single words)
72
- // currently we simply use minWidths for all columns
73
- autoColumns.forEach(function (col) {
74
- col._calcWidth = col._minWidth;
75
- });
76
-
77
- starColumns.forEach(function (col) {
78
- col._calcWidth = starMaxMin; // starMaxMin already contains padding
79
- });
80
- } else {
81
- if (maxW < availableWidth) {
82
- // case 2 - we can fit rest of the table within available space
83
- autoColumns.forEach(function (col) {
84
- col._calcWidth = col._maxWidth;
85
- availableWidth -= col._calcWidth;
86
- });
87
- } else {
88
- // maxW is too large, but minW fits within available width
89
- var W = availableWidth - minW;
90
- var D = maxW - minW;
91
-
92
- autoColumns.forEach(function (col) {
93
- var d = col._maxWidth - col._minWidth;
94
- col._calcWidth = col._minWidth + d * W / D;
95
- availableWidth -= col._calcWidth;
96
- });
97
- }
98
-
99
- if (starColumns.length > 0) {
100
- var starSize = availableWidth / starColumns.length;
101
-
102
- starColumns.forEach(function (col) {
103
- col._calcWidth = starSize;
104
- });
105
- }
106
- }
107
- }
108
-
109
- function isAutoColumn(column) {
110
- return column.width === 'auto';
111
- }
112
-
113
- function isStarColumn(column) {
114
- return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
115
- }
116
-
117
- //TODO: refactor and reuse in measureTable
118
- function measureMinMax(columns) {
119
- var result = { min: 0, max: 0 };
120
-
121
- var maxStar = { min: 0, max: 0 };
122
- var starCount = 0;
123
-
124
- for (var i = 0, l = columns.length; i < l; i++) {
125
- var c = columns[i];
126
-
127
- if (isStarColumn(c)) {
128
- maxStar.min = Math.max(maxStar.min, c._minWidth);
129
- maxStar.max = Math.max(maxStar.max, c._maxWidth);
130
- starCount++;
131
- } else if (isAutoColumn(c)) {
132
- result.min += c._minWidth;
133
- result.max += c._maxWidth;
134
- } else {
135
- result.min += ((c.width !== undefined && c.width) || c._minWidth);
136
- result.max += ((c.width !== undefined && c.width) || c._maxWidth);
137
- }
138
- }
139
-
140
- if (starCount) {
141
- result.min += starCount * maxStar.min;
142
- result.max += starCount * maxStar.max;
143
- }
144
-
145
- return result;
146
- }
147
-
148
- /**
149
- * Calculates column widths
150
- * @private
151
- */
152
- module.exports = {
153
- buildColumnWidths: buildColumnWidths,
154
- measureMinMax: measureMinMax,
155
- isAutoColumn: isAutoColumn,
156
- isStarColumn: isStarColumn
157
- };
1
+ 'use strict';
2
+
3
+ var isString = require('./helpers').isString;
4
+
5
+ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
6
+ var autoColumns = [],
7
+ autoMin = 0, autoMax = 0,
8
+ starColumns = [],
9
+ starMaxMin = 0,
10
+ starMaxMax = 0,
11
+ fixedColumns = [],
12
+ initial_availableWidth = availableWidth;
13
+
14
+ columns.forEach(function (column) {
15
+ if (isAutoColumn(column)) {
16
+ autoColumns.push(column);
17
+ autoMin += column._minWidth;
18
+ autoMax += column._maxWidth;
19
+ } else if (isStarColumn(column)) {
20
+ starColumns.push(column);
21
+ starMaxMin = Math.max(starMaxMin, column._minWidth);
22
+ starMaxMax = Math.max(starMaxMax, column._maxWidth);
23
+ } else {
24
+ fixedColumns.push(column);
25
+ }
26
+ });
27
+
28
+ fixedColumns.forEach(function (col, colIndex) {
29
+ // width specified as %
30
+ if (isString(col.width) && /\d+%/.test(col.width)) {
31
+ // In tables we have to take into consideration the reserved width for paddings and borders
32
+ var reservedWidth = 0;
33
+ if (tableNode) {
34
+ var paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
35
+ var paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
36
+ var borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
37
+ var borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
38
+ if (colIndex === 0) {
39
+ // first column assumes whole borderLeft and half of border right
40
+ reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
41
+
42
+ } else if (colIndex === fixedColumns.length - 1) {
43
+ // last column assumes whole borderRight and half of border left
44
+ reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
45
+
46
+ } else {
47
+ // Columns in the middle assume half of each border
48
+ reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
49
+ }
50
+ }
51
+ var totalAvailableWidth = initial_availableWidth + offsetTotal;
52
+ col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
53
+ }
54
+ if (col.width < (col._minWidth) && col.elasticWidth) {
55
+ col._calcWidth = col._minWidth;
56
+ } else {
57
+ col._calcWidth = col.width;
58
+ }
59
+
60
+ availableWidth -= col._calcWidth;
61
+ });
62
+
63
+ // http://www.freesoft.org/CIE/RFC/1942/18.htm
64
+ // http://www.w3.org/TR/CSS2/tables.html#width-layout
65
+ // http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
66
+ var minW = autoMin + starMaxMin * starColumns.length;
67
+ var maxW = autoMax + starMaxMax * starColumns.length;
68
+ if (minW >= availableWidth) {
69
+ // case 1 - there's no way to fit all columns within available width
70
+ // that's actually pretty bad situation with PDF as we have no horizontal scroll
71
+ // no easy workaround (unless we decide, in the future, to split single words)
72
+ // currently we simply use minWidths for all columns
73
+ autoColumns.forEach(function (col) {
74
+ col._calcWidth = col._minWidth;
75
+ });
76
+
77
+ starColumns.forEach(function (col) {
78
+ col._calcWidth = starMaxMin; // starMaxMin already contains padding
79
+ });
80
+ } else {
81
+ if (maxW < availableWidth) {
82
+ // case 2 - we can fit rest of the table within available space
83
+ autoColumns.forEach(function (col) {
84
+ col._calcWidth = col._maxWidth;
85
+ availableWidth -= col._calcWidth;
86
+ });
87
+ } else {
88
+ // maxW is too large, but minW fits within available width
89
+ var W = availableWidth - minW;
90
+ var D = maxW - minW;
91
+
92
+ autoColumns.forEach(function (col) {
93
+ var d = col._maxWidth - col._minWidth;
94
+ col._calcWidth = col._minWidth + d * W / D;
95
+ availableWidth -= col._calcWidth;
96
+ });
97
+ }
98
+
99
+ if (starColumns.length > 0) {
100
+ var starSize = availableWidth / starColumns.length;
101
+
102
+ starColumns.forEach(function (col) {
103
+ col._calcWidth = starSize;
104
+ });
105
+ }
106
+ }
107
+ }
108
+
109
+ function isAutoColumn(column) {
110
+ return column.width === 'auto';
111
+ }
112
+
113
+ function isStarColumn(column) {
114
+ return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
115
+ }
116
+
117
+ //TODO: refactor and reuse in measureTable
118
+ function measureMinMax(columns) {
119
+ var result = { min: 0, max: 0 };
120
+
121
+ var maxStar = { min: 0, max: 0 };
122
+ var starCount = 0;
123
+
124
+ for (var i = 0, l = columns.length; i < l; i++) {
125
+ var c = columns[i];
126
+
127
+ if (isStarColumn(c)) {
128
+ maxStar.min = Math.max(maxStar.min, c._minWidth);
129
+ maxStar.max = Math.max(maxStar.max, c._maxWidth);
130
+ starCount++;
131
+ } else if (isAutoColumn(c)) {
132
+ result.min += c._minWidth;
133
+ result.max += c._maxWidth;
134
+ } else {
135
+ result.min += ((c.width !== undefined && c.width) || c._minWidth);
136
+ result.max += ((c.width !== undefined && c.width) || c._maxWidth);
137
+ }
138
+ }
139
+
140
+ if (starCount) {
141
+ result.min += starCount * maxStar.min;
142
+ result.max += starCount * maxStar.max;
143
+ }
144
+
145
+ return result;
146
+ }
147
+
148
+ /**
149
+ * Calculates column widths
150
+ * @private
151
+ */
152
+ module.exports = {
153
+ buildColumnWidths: buildColumnWidths,
154
+ measureMinMax: measureMinMax,
155
+ isAutoColumn: isAutoColumn,
156
+ isStarColumn: isStarColumn
157
+ };