pdfmake 0.2.13 → 0.3.0-beta.10

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 (136) hide show
  1. package/CHANGELOG.md +23 -41
  2. package/README.md +11 -7
  3. package/build/pdfmake.js +22291 -23202
  4. package/build/pdfmake.js.map +1 -1
  5. package/build/pdfmake.min.js +2 -2
  6. package/build/pdfmake.min.js.map +1 -1
  7. package/build/standard-fonts/Courier.js +27 -0
  8. package/build/standard-fonts/Helvetica.js +27 -0
  9. package/build/standard-fonts/Symbol.js +21 -0
  10. package/build/standard-fonts/Times.js +27 -0
  11. package/build/standard-fonts/ZapfDingbats.js +21 -0
  12. package/build/vfs_fonts.js +2 -2
  13. package/build-vfs.js +2 -2
  14. package/eslint.config.mjs +52 -0
  15. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  16. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  17. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  18. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  19. package/fonts/Roboto.js +8 -0
  20. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  21. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  22. package/js/DocMeasure.js +626 -0
  23. package/js/DocPreprocessor.js +238 -0
  24. package/js/DocumentContext.js +288 -0
  25. package/js/ElementWriter.js +342 -0
  26. package/js/LayoutBuilder.js +881 -0
  27. package/js/Line.js +105 -0
  28. package/js/OutputDocument.js +76 -0
  29. package/js/OutputDocumentServer.js +27 -0
  30. package/js/PDFDocument.js +144 -0
  31. package/js/PageElementWriter.js +140 -0
  32. package/js/PageSize.js +74 -0
  33. package/js/Printer.js +291 -0
  34. package/js/Renderer.js +375 -0
  35. package/js/SVGMeasure.js +69 -0
  36. package/js/StyleContextStack.js +164 -0
  37. package/js/TableProcessor.js +524 -0
  38. package/js/TextBreaker.js +139 -0
  39. package/js/TextDecorator.js +143 -0
  40. package/js/TextInlines.js +206 -0
  41. package/js/URLResolver.js +73 -0
  42. package/js/base.js +52 -0
  43. package/js/browser-extensions/OutputDocumentBrowser.js +118 -0
  44. package/js/browser-extensions/URLBrowserResolver.js +76 -0
  45. package/js/browser-extensions/fonts/Roboto.js +38 -0
  46. package/js/browser-extensions/index.js +53 -0
  47. package/js/browser-extensions/pdfMake.js +3 -0
  48. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  49. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  50. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  51. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  52. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  53. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  54. package/js/columnCalculator.js +148 -0
  55. package/js/helpers/node.js +98 -0
  56. package/js/helpers/tools.js +40 -0
  57. package/js/helpers/variableType.js +59 -0
  58. package/js/index.js +15 -0
  59. package/js/qrEnc.js +721 -0
  60. package/js/standardPageSizes.js +56 -0
  61. package/js/tableLayouts.js +98 -0
  62. package/js/virtual-fs.js +60 -0
  63. package/package.json +34 -28
  64. package/src/3rd-party/svg-to-pdfkit.js +2 -2
  65. package/src/DocMeasure.js +707 -0
  66. package/src/DocPreprocessor.js +264 -0
  67. package/src/DocumentContext.js +324 -0
  68. package/src/ElementWriter.js +405 -0
  69. package/src/LayoutBuilder.js +997 -0
  70. package/src/Line.js +114 -0
  71. package/src/OutputDocument.js +78 -0
  72. package/src/OutputDocumentServer.js +26 -0
  73. package/src/PDFDocument.js +174 -0
  74. package/src/PageElementWriter.js +160 -0
  75. package/src/PageSize.js +53 -0
  76. package/src/Printer.js +306 -0
  77. package/src/Renderer.js +405 -0
  78. package/src/SVGMeasure.js +79 -0
  79. package/src/StyleContextStack.js +175 -0
  80. package/src/TableProcessor.js +580 -0
  81. package/src/TextBreaker.js +149 -0
  82. package/src/TextDecorator.js +161 -0
  83. package/src/TextInlines.js +223 -0
  84. package/src/URLResolver.js +77 -0
  85. package/src/base.js +61 -0
  86. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  87. package/src/browser-extensions/URLBrowserResolver.js +45 -57
  88. package/src/browser-extensions/fonts/Roboto.js +27 -0
  89. package/src/browser-extensions/index.js +55 -0
  90. package/src/browser-extensions/pdfMake.js +1 -329
  91. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  92. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  93. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  94. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  95. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  96. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  97. package/src/columnCalculator.js +35 -38
  98. package/src/helpers/node.js +110 -0
  99. package/src/helpers/tools.js +39 -0
  100. package/src/helpers/variableType.js +50 -0
  101. package/src/index.js +16 -0
  102. package/src/qrEnc.js +15 -10
  103. package/src/standardPageSizes.js +1 -3
  104. package/src/tableLayouts.js +100 -0
  105. package/src/virtual-fs.js +66 -0
  106. package/standard-fonts/Courier.js +8 -0
  107. package/standard-fonts/Helvetica.js +9 -0
  108. package/standard-fonts/Symbol.js +5 -0
  109. package/standard-fonts/Times.js +8 -0
  110. package/standard-fonts/ZapfDingbats.js +5 -0
  111. package/.idea/codeStyles/Project.xml +0 -7
  112. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  113. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  114. package/.idea/misc.xml +0 -6
  115. package/.idea/modules.xml +0 -8
  116. package/.idea/pdfmake.iml +0 -11
  117. package/.idea/vcs.xml +0 -6
  118. package/src/browser-extensions/virtual-fs.js +0 -55
  119. package/src/docMeasure.js +0 -810
  120. package/src/docPreprocessor.js +0 -255
  121. package/src/documentContext.js +0 -328
  122. package/src/elementWriter.js +0 -333
  123. package/src/fontProvider.js +0 -68
  124. package/src/helpers.js +0 -138
  125. package/src/imageMeasure.js +0 -55
  126. package/src/layoutBuilder.js +0 -989
  127. package/src/line.js +0 -91
  128. package/src/pageElementWriter.js +0 -174
  129. package/src/pdfKitEngine.js +0 -21
  130. package/src/printer.js +0 -710
  131. package/src/styleContextStack.js +0 -138
  132. package/src/svgMeasure.js +0 -70
  133. package/src/tableProcessor.js +0 -584
  134. package/src/textDecorator.js +0 -157
  135. package/src/textTools.js +0 -373
  136. package/src/traversalTracker.js +0 -47
@@ -0,0 +1,79 @@
1
+ import xmldoc from 'xmldoc';
2
+
3
+ /**
4
+ * Strip unit postfix, parse number, but return undefined instead of NaN for bad input
5
+ *
6
+ * @param {string} textVal
7
+ * @returns {?number}
8
+ */
9
+ const stripUnits = textVal => {
10
+ var n = parseFloat(textVal);
11
+ if (typeof n !== 'number' || isNaN(n)) {
12
+ return undefined;
13
+ }
14
+ return n;
15
+ };
16
+
17
+ /**
18
+ * Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM
19
+ *
20
+ * @param {string} svgString
21
+ * @returns {object}
22
+ */
23
+ const parseSVG = (svgString) => {
24
+ var doc;
25
+
26
+ try {
27
+ doc = new xmldoc.XmlDocument(svgString);
28
+ } catch (err) {
29
+ throw new Error('SVGMeasure: ' + err);
30
+ }
31
+
32
+ if (doc.name !== "svg") {
33
+ throw new Error('SVGMeasure: expected <svg> document');
34
+ }
35
+
36
+ return doc;
37
+ };
38
+
39
+ class SVGMeasure {
40
+ constructor() {
41
+
42
+ }
43
+
44
+ measureSVG(svgString) {
45
+ let doc = parseSVG(svgString);
46
+
47
+ let docWidth = stripUnits(doc.attr.width);
48
+ let docHeight = stripUnits(doc.attr.height);
49
+
50
+ if ((docWidth === undefined || docHeight === undefined) && typeof doc.attr.viewBox === 'string') {
51
+ let viewBoxParts = doc.attr.viewBox.split(/[,\s]+/);
52
+ if (viewBoxParts.length !== 4) {
53
+ throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + doc.attr.viewBox + "'");
54
+ }
55
+ if (docWidth === undefined) {
56
+ docWidth = stripUnits(viewBoxParts[2]);
57
+ }
58
+ if (docHeight === undefined) {
59
+ docHeight = stripUnits(viewBoxParts[3]);
60
+ }
61
+ }
62
+
63
+ return {
64
+ width: docWidth,
65
+ height: docHeight
66
+ };
67
+ }
68
+
69
+ writeDimensions(svgString, dimensions) {
70
+ let doc = parseSVG(svgString);
71
+
72
+ doc.attr.width = "" + dimensions.width;
73
+ doc.attr.height = "" + dimensions.height;
74
+
75
+ return doc.toString();
76
+ }
77
+ }
78
+
79
+ export default SVGMeasure;
@@ -0,0 +1,175 @@
1
+ import { isString, isValue } from './helpers/variableType';
2
+
3
+ /**
4
+ * Used for style inheritance and style overrides
5
+ */
6
+ class StyleContextStack {
7
+
8
+ /**
9
+ * @param {object} styleDictionary named styles dictionary
10
+ * @param {object} defaultStyle optional default style definition
11
+ */
12
+ constructor(styleDictionary, defaultStyle = {}) {
13
+ this.styleDictionary = styleDictionary;
14
+ this.defaultStyle = defaultStyle;
15
+ this.styleOverrides = [];
16
+ }
17
+
18
+ /**
19
+ * Creates cloned version of current stack
20
+ *
21
+ * @returns {StyleContextStack} current stack snapshot
22
+ */
23
+ clone() {
24
+ let stack = new StyleContextStack(this.styleDictionary, this.defaultStyle);
25
+
26
+ this.styleOverrides.forEach(item => {
27
+ stack.styleOverrides.push(item);
28
+ });
29
+
30
+ return stack;
31
+ }
32
+
33
+ /**
34
+ * Pushes style-name or style-overrides-object onto the stack for future evaluation
35
+ *
36
+ * @param {string|object} styleNameOrOverride style-name (referring to styleDictionary) or
37
+ * a new dictionary defining overriding properties
38
+ */
39
+ push(styleNameOrOverride) {
40
+ this.styleOverrides.push(styleNameOrOverride);
41
+ }
42
+
43
+ /**
44
+ * Removes last style-name or style-overrides-object from the stack
45
+ *
46
+ * @param {number} howMany optional number of elements to be popped (if not specified,
47
+ * one element will be removed from the stack)
48
+ */
49
+ pop(howMany = 1) {
50
+ while (howMany-- > 0) {
51
+ this.styleOverrides.pop();
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Creates a set of named styles or/and a style-overrides-object based on the item,
57
+ * pushes those elements onto the stack for future evaluation and returns the number
58
+ * of elements pushed, so they can be easily poped then.
59
+ *
60
+ * @param {object} item - an object with optional style property and/or style overrides
61
+ * @returns {number} the number of items pushed onto the stack
62
+ */
63
+ autopush(item) {
64
+ if (isString(item)) {
65
+ return 0;
66
+ }
67
+
68
+ let styleNames = [];
69
+
70
+ if (item.style) {
71
+ if (Array.isArray(item.style)) {
72
+ styleNames = item.style;
73
+ } else {
74
+ styleNames = [item.style];
75
+ }
76
+ }
77
+
78
+ for (let i = 0, l = styleNames.length; i < l; i++) {
79
+ this.push(styleNames[i]);
80
+ }
81
+
82
+ // rather than spend significant time making a styleOverrideObject, just add item
83
+ this.push(item);
84
+ return styleNames.length + 1;
85
+ }
86
+
87
+ /**
88
+ * Automatically pushes elements onto the stack, using autopush based on item,
89
+ * executes callback and then pops elements back. Returns value returned by callback
90
+ *
91
+ * @param {object} item - an object with optional style property and/or style overrides
92
+ * @param {Function} callback to be called between autopush and pop
93
+ * @returns {object} value returned by callback
94
+ */
95
+ auto(item, callback) {
96
+ let pushedItems = this.autopush(item);
97
+ let result = callback();
98
+
99
+ if (pushedItems > 0) {
100
+ this.pop(pushedItems);
101
+ }
102
+
103
+ return result;
104
+ }
105
+
106
+ /**
107
+ * Evaluates stack and returns value of a named property
108
+ *
109
+ * @param {string} property - property name
110
+ * @returns {?any} property value or null if not found
111
+ */
112
+ getProperty(property) {
113
+ if (this.styleOverrides) {
114
+ for (let i = this.styleOverrides.length - 1; i >= 0; i--) {
115
+ let item = this.styleOverrides[i];
116
+
117
+ if (isString(item)) { // named-style-override
118
+ let style = this.styleDictionary[item];
119
+ if (style && isValue(style[property])) {
120
+ return style[property];
121
+ }
122
+ } else if (isValue(item[property])) { // style-overrides-object
123
+ return item[property];
124
+ }
125
+ }
126
+ }
127
+
128
+ return this.defaultStyle && this.defaultStyle[property];
129
+ }
130
+
131
+ /**
132
+ * @param {object} item
133
+ * @param {StyleContextStack} styleContextStack
134
+ * @param {string} property
135
+ * @param {any} defaultValue
136
+ * @returns {any}
137
+ */
138
+ static getStyleProperty(item, styleContextStack, property, defaultValue) {
139
+ let value;
140
+
141
+ if (isValue(item[property])) { // item defines this property
142
+ return item[property];
143
+ }
144
+
145
+ if (!styleContextStack) {
146
+ return defaultValue;
147
+ }
148
+
149
+ styleContextStack.auto(item, () => {
150
+ value = styleContextStack.getProperty(property);
151
+ });
152
+
153
+ return isValue(value) ? value : defaultValue;
154
+ }
155
+
156
+ /**
157
+ * @param {object} source
158
+ * @param {object} destination
159
+ * @returns {object}
160
+ */
161
+ static copyStyle(source = {}, destination = {}) {
162
+ // TODO: default style to source
163
+
164
+ for (let key in source) {
165
+ if (key != 'text' && source.hasOwnProperty(key)) {
166
+ destination[key] = source[key];
167
+ }
168
+ }
169
+
170
+ return destination;
171
+ }
172
+
173
+ }
174
+
175
+ export default StyleContextStack;