pdfmake 0.3.0-beta.8 → 0.3.0

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 (87) hide show
  1. package/CHANGELOG.md +7 -40
  2. package/LICENSE +1 -1
  3. package/README.md +78 -85
  4. package/build/pdfmake.js +60308 -68400
  5. package/build/pdfmake.js.map +1 -1
  6. package/build/pdfmake.min.js +2 -2
  7. package/build/pdfmake.min.js.map +1 -1
  8. package/build/vfs_fonts.js +4 -4
  9. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  10. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  11. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  12. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  13. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  14. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  15. package/js/DocMeasure.js +645 -0
  16. package/js/DocPreprocessor.js +253 -0
  17. package/js/DocumentContext.js +305 -0
  18. package/js/ElementWriter.js +354 -0
  19. package/js/LayoutBuilder.js +1105 -0
  20. package/js/Line.js +105 -0
  21. package/js/OutputDocument.js +64 -0
  22. package/js/OutputDocumentServer.js +22 -0
  23. package/js/PDFDocument.js +144 -0
  24. package/js/PageElementWriter.js +155 -0
  25. package/js/PageSize.js +74 -0
  26. package/js/Printer.js +291 -0
  27. package/js/Renderer.js +383 -0
  28. package/js/SVGMeasure.js +69 -0
  29. package/js/StyleContextStack.js +168 -0
  30. package/js/TableProcessor.js +548 -0
  31. package/js/TextBreaker.js +166 -0
  32. package/js/TextDecorator.js +143 -0
  33. package/js/TextInlines.js +206 -0
  34. package/js/URLResolver.js +43 -0
  35. package/js/base.js +52 -0
  36. package/js/browser-extensions/OutputDocumentBrowser.js +81 -0
  37. package/js/browser-extensions/fonts/Roboto.js +38 -0
  38. package/js/browser-extensions/index.js +53 -0
  39. package/js/browser-extensions/pdfMake.js +3 -0
  40. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  41. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  42. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  43. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  44. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  45. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  46. package/js/columnCalculator.js +148 -0
  47. package/js/helpers/node.js +98 -0
  48. package/js/helpers/tools.js +46 -0
  49. package/js/helpers/variableType.js +59 -0
  50. package/js/index.js +15 -0
  51. package/js/qrEnc.js +721 -0
  52. package/js/standardPageSizes.js +56 -0
  53. package/js/tableLayouts.js +98 -0
  54. package/js/virtual-fs.js +60 -0
  55. package/package.json +25 -24
  56. package/src/DocMeasure.js +28 -7
  57. package/src/DocPreprocessor.js +25 -6
  58. package/src/DocumentContext.js +62 -33
  59. package/src/ElementWriter.js +30 -7
  60. package/src/LayoutBuilder.js +557 -120
  61. package/src/OutputDocument.js +23 -37
  62. package/src/OutputDocumentServer.js +6 -11
  63. package/src/PDFDocument.js +1 -1
  64. package/src/PageElementWriter.js +21 -2
  65. package/src/Printer.js +134 -131
  66. package/src/Renderer.js +13 -15
  67. package/src/SVGMeasure.js +2 -2
  68. package/src/StyleContextStack.js +7 -44
  69. package/src/TableProcessor.js +62 -22
  70. package/src/TextBreaker.js +24 -5
  71. package/src/TextInlines.js +1 -1
  72. package/src/URLResolver.js +24 -58
  73. package/src/base.js +1 -1
  74. package/src/browser-extensions/OutputDocumentBrowser.js +33 -71
  75. package/src/browser-extensions/index.js +3 -3
  76. package/src/browser-extensions/pdfMake.js +0 -14
  77. package/src/browser-extensions/standard-fonts/Courier.js +4 -4
  78. package/src/browser-extensions/standard-fonts/Helvetica.js +4 -4
  79. package/src/browser-extensions/standard-fonts/Symbol.js +1 -1
  80. package/src/browser-extensions/standard-fonts/Times.js +4 -4
  81. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +1 -1
  82. package/src/columnCalculator.js +24 -3
  83. package/src/helpers/tools.js +5 -0
  84. package/src/helpers/variableType.js +11 -0
  85. package/src/index.js +1 -1
  86. package/standard-fonts/Helvetica.js +0 -1
  87. package/src/browser-extensions/URLBrowserResolver.js +0 -84
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _xmldoc = _interopRequireDefault(require("xmldoc"));
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
+ /**
8
+ * Strip unit postfix, parse number, but return undefined instead of NaN for bad input
9
+ *
10
+ * @param {string} textVal
11
+ * @returns {?number}
12
+ */
13
+ const stripUnits = textVal => {
14
+ let n = parseFloat(textVal);
15
+ if (typeof n !== 'number' || isNaN(n)) {
16
+ return undefined;
17
+ }
18
+ return n;
19
+ };
20
+
21
+ /**
22
+ * Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM
23
+ *
24
+ * @param {string} svgString
25
+ * @returns {object}
26
+ */
27
+ const parseSVG = svgString => {
28
+ let doc;
29
+ try {
30
+ doc = new _xmldoc.default.XmlDocument(svgString);
31
+ } catch (err) {
32
+ throw new Error('SVGMeasure: ' + err);
33
+ }
34
+ if (doc.name !== "svg") {
35
+ throw new Error('SVGMeasure: expected <svg> document');
36
+ }
37
+ return doc;
38
+ };
39
+ class SVGMeasure {
40
+ constructor() {}
41
+ measureSVG(svgString) {
42
+ let doc = parseSVG(svgString);
43
+ let docWidth = stripUnits(doc.attr.width);
44
+ let docHeight = stripUnits(doc.attr.height);
45
+ if ((docWidth === undefined || docHeight === undefined) && typeof doc.attr.viewBox === 'string') {
46
+ let viewBoxParts = doc.attr.viewBox.split(/[,\s]+/);
47
+ if (viewBoxParts.length !== 4) {
48
+ throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + doc.attr.viewBox + "'");
49
+ }
50
+ if (docWidth === undefined) {
51
+ docWidth = stripUnits(viewBoxParts[2]);
52
+ }
53
+ if (docHeight === undefined) {
54
+ docHeight = stripUnits(viewBoxParts[3]);
55
+ }
56
+ }
57
+ return {
58
+ width: docWidth,
59
+ height: docHeight
60
+ };
61
+ }
62
+ writeDimensions(svgString, dimensions) {
63
+ let doc = parseSVG(svgString);
64
+ doc.attr.width = "" + dimensions.width;
65
+ doc.attr.height = "" + dimensions.height;
66
+ return doc.toString();
67
+ }
68
+ }
69
+ var _default = exports.default = SVGMeasure;
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _variableType = require("./helpers/variableType");
6
+ /**
7
+ * Used for style inheritance and style overrides
8
+ */
9
+ class StyleContextStack {
10
+ /**
11
+ * @param {object} styleDictionary named styles dictionary
12
+ * @param {object} defaultStyle optional default style definition
13
+ */
14
+ constructor(styleDictionary, defaultStyle = {}) {
15
+ this.styleDictionary = styleDictionary;
16
+ this.defaultStyle = defaultStyle;
17
+ this.styleOverrides = [];
18
+ }
19
+
20
+ /**
21
+ * Creates cloned version of current stack
22
+ *
23
+ * @returns {StyleContextStack} current stack snapshot
24
+ */
25
+ clone() {
26
+ let stack = new StyleContextStack(this.styleDictionary, this.defaultStyle);
27
+ this.styleOverrides.forEach(item => {
28
+ stack.styleOverrides.push(item);
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 ((0, _variableType.isString)(item)) {
65
+ return 0;
66
+ }
67
+ if (typeof item.section !== 'undefined') {
68
+ // section node not support style overrides
69
+ return 0;
70
+ }
71
+ let styleNames = [];
72
+ if (item.style) {
73
+ if (Array.isArray(item.style)) {
74
+ styleNames = item.style;
75
+ } else {
76
+ styleNames = [item.style];
77
+ }
78
+ }
79
+ for (let i = 0, l = styleNames.length; i < l; i++) {
80
+ this.push(styleNames[i]);
81
+ }
82
+
83
+ // rather than spend significant time making a styleOverrideObject, just add item
84
+ this.push(item);
85
+ return styleNames.length + 1;
86
+ }
87
+
88
+ /**
89
+ * Automatically pushes elements onto the stack, using autopush based on item,
90
+ * executes callback and then pops elements back. Returns value returned by callback
91
+ *
92
+ * @param {object} item - an object with optional style property and/or style overrides
93
+ * @param {Function} callback to be called between autopush and pop
94
+ * @returns {object} value returned by callback
95
+ */
96
+ auto(item, callback) {
97
+ let pushedItems = this.autopush(item);
98
+ let result = callback();
99
+ if (pushedItems > 0) {
100
+ this.pop(pushedItems);
101
+ }
102
+ return result;
103
+ }
104
+
105
+ /**
106
+ * Evaluates stack and returns value of a named property
107
+ *
108
+ * @param {string} property - property name
109
+ * @returns {?any} property value or null if not found
110
+ */
111
+ getProperty(property) {
112
+ if (this.styleOverrides) {
113
+ for (let i = this.styleOverrides.length - 1; i >= 0; i--) {
114
+ let item = this.styleOverrides[i];
115
+ if ((0, _variableType.isString)(item)) {
116
+ // named-style-override
117
+ let style = this.styleDictionary[item];
118
+ if (style && (0, _variableType.isValue)(style[property])) {
119
+ return style[property];
120
+ }
121
+ } else if ((0, _variableType.isValue)(item[property])) {
122
+ // style-overrides-object
123
+ return item[property];
124
+ }
125
+ }
126
+ }
127
+ return this.defaultStyle && this.defaultStyle[property];
128
+ }
129
+
130
+ /**
131
+ * @param {object} item
132
+ * @param {StyleContextStack} styleContextStack
133
+ * @param {string} property
134
+ * @param {any} defaultValue
135
+ * @returns {any}
136
+ */
137
+ static getStyleProperty(item, styleContextStack, property, defaultValue) {
138
+ let value;
139
+ if ((0, _variableType.isValue)(item[property])) {
140
+ // item defines this property
141
+ return item[property];
142
+ }
143
+ if (!styleContextStack) {
144
+ return defaultValue;
145
+ }
146
+ styleContextStack.auto(item, () => {
147
+ value = styleContextStack.getProperty(property);
148
+ });
149
+ return (0, _variableType.isValue)(value) ? value : defaultValue;
150
+ }
151
+
152
+ /**
153
+ * @param {object} source
154
+ * @param {object} destination
155
+ * @returns {object}
156
+ */
157
+ static copyStyle(source = {}, destination = {}) {
158
+ // TODO: default style to source
159
+
160
+ for (let key in source) {
161
+ if (key != 'text' && source.hasOwnProperty(key)) {
162
+ destination[key] = source[key];
163
+ }
164
+ }
165
+ return destination;
166
+ }
167
+ }
168
+ var _default = exports.default = StyleContextStack;