pdfmake 0.2.4 → 0.3.0-beta.2

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 (128) hide show
  1. package/CHANGELOG.md +10 -27
  2. package/README.md +11 -7
  3. package/build/pdfmake.js +44733 -42435
  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/fonts/Roboto/Roboto-Italic.ttf +0 -0
  15. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  16. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  17. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  18. package/fonts/Roboto.js +8 -0
  19. package/js/3rd-party/svg-to-pdfkit/source.js +4301 -0
  20. package/js/3rd-party/svg-to-pdfkit.js +11 -0
  21. package/js/DocMeasure.js +758 -0
  22. package/js/DocPreprocessor.js +291 -0
  23. package/js/DocumentContext.js +306 -0
  24. package/js/ElementWriter.js +400 -0
  25. package/js/LayoutBuilder.js +840 -0
  26. package/js/Line.js +125 -0
  27. package/js/OutputDocument.js +86 -0
  28. package/js/OutputDocumentServer.js +34 -0
  29. package/js/PDFDocument.js +190 -0
  30. package/js/PageElementWriter.js +165 -0
  31. package/js/PageSize.js +88 -0
  32. package/js/Printer.js +300 -0
  33. package/js/Renderer.js +463 -0
  34. package/js/SVGMeasure.js +89 -0
  35. package/js/StyleContextStack.js +206 -0
  36. package/js/TableProcessor.js +590 -0
  37. package/js/TextBreaker.js +182 -0
  38. package/js/TextDecorator.js +181 -0
  39. package/js/TextInlines.js +248 -0
  40. package/js/URLResolver.js +82 -0
  41. package/js/base.js +69 -0
  42. package/js/browser-extensions/OutputDocumentBrowser.js +131 -0
  43. package/js/browser-extensions/URLBrowserResolver.js +94 -0
  44. package/js/browser-extensions/fonts/Roboto.js +42 -0
  45. package/js/browser-extensions/index.js +70 -0
  46. package/js/browser-extensions/pdfMake.js +17 -0
  47. package/js/browser-extensions/standard-fonts/Courier.js +42 -0
  48. package/js/browser-extensions/standard-fonts/Helvetica.js +42 -0
  49. package/js/browser-extensions/standard-fonts/Symbol.js +27 -0
  50. package/js/browser-extensions/standard-fonts/Times.js +42 -0
  51. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +27 -0
  52. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  53. package/js/columnCalculator.js +142 -0
  54. package/js/helpers/node.js +122 -0
  55. package/js/helpers/tools.js +48 -0
  56. package/js/helpers/variableType.js +52 -0
  57. package/js/index.js +21 -0
  58. package/js/qrEnc.js +810 -0
  59. package/js/standardPageSizes.js +57 -0
  60. package/js/tableLayouts.js +127 -0
  61. package/js/virtual-fs.js +77 -0
  62. package/package.json +26 -22
  63. package/src/3rd-party/svg-to-pdfkit.js +2 -2
  64. package/src/DocMeasure.js +703 -0
  65. package/src/DocPreprocessor.js +264 -0
  66. package/src/DocumentContext.js +309 -0
  67. package/src/ElementWriter.js +394 -0
  68. package/src/LayoutBuilder.js +821 -0
  69. package/src/Line.js +114 -0
  70. package/src/OutputDocument.js +78 -0
  71. package/src/OutputDocumentServer.js +26 -0
  72. package/src/PDFDocument.js +174 -0
  73. package/src/PageElementWriter.js +160 -0
  74. package/src/PageSize.js +53 -0
  75. package/src/Printer.js +277 -0
  76. package/src/Renderer.js +405 -0
  77. package/src/SVGMeasure.js +79 -0
  78. package/src/StyleContextStack.js +216 -0
  79. package/src/TableProcessor.js +558 -0
  80. package/src/TextBreaker.js +149 -0
  81. package/src/TextDecorator.js +161 -0
  82. package/src/TextInlines.js +223 -0
  83. package/src/URLResolver.js +72 -0
  84. package/src/base.js +61 -0
  85. package/src/browser-extensions/OutputDocumentBrowser.js +117 -0
  86. package/src/browser-extensions/URLBrowserResolver.js +49 -53
  87. package/src/browser-extensions/fonts/Roboto.js +27 -0
  88. package/src/browser-extensions/index.js +55 -0
  89. package/src/browser-extensions/pdfMake.js +10 -282
  90. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  91. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  92. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  93. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  94. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  95. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  96. package/src/columnCalculator.js +29 -32
  97. package/src/helpers/node.js +110 -0
  98. package/src/helpers/tools.js +39 -0
  99. package/src/helpers/variableType.js +39 -0
  100. package/src/index.js +16 -0
  101. package/src/qrEnc.js +15 -10
  102. package/src/standardPageSizes.js +1 -3
  103. package/src/tableLayouts.js +100 -0
  104. package/src/virtual-fs.js +66 -0
  105. package/standard-fonts/Courier.js +8 -0
  106. package/standard-fonts/Helvetica.js +9 -0
  107. package/standard-fonts/Symbol.js +5 -0
  108. package/standard-fonts/Times.js +8 -0
  109. package/standard-fonts/ZapfDingbats.js +5 -0
  110. package/src/browser-extensions/virtual-fs.js +0 -55
  111. package/src/docMeasure.js +0 -807
  112. package/src/docPreprocessor.js +0 -255
  113. package/src/documentContext.js +0 -314
  114. package/src/elementWriter.js +0 -322
  115. package/src/fontProvider.js +0 -68
  116. package/src/helpers.js +0 -126
  117. package/src/imageMeasure.js +0 -51
  118. package/src/layoutBuilder.js +0 -807
  119. package/src/line.js +0 -91
  120. package/src/pageElementWriter.js +0 -174
  121. package/src/pdfKitEngine.js +0 -21
  122. package/src/printer.js +0 -705
  123. package/src/styleContextStack.js +0 -179
  124. package/src/svgMeasure.js +0 -70
  125. package/src/tableProcessor.js +0 -561
  126. package/src/textDecorator.js +0 -157
  127. package/src/textTools.js +0 -373
  128. package/src/traversalTracker.js +0 -47
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+
6
+ var _variableType = require("./helpers/variableType");
7
+
8
+ /**
9
+ * Used for style inheritance and style overrides
10
+ */
11
+ class StyleContextStack {
12
+ /**
13
+ * @param {object} styleDictionary named styles dictionary
14
+ * @param {object} defaultStyle optional default style definition
15
+ */
16
+ constructor(styleDictionary, defaultStyle = {}) {
17
+ this.styleDictionary = styleDictionary;
18
+ this.defaultStyle = defaultStyle;
19
+ this.styleOverrides = [];
20
+ }
21
+ /**
22
+ * Creates cloned version of current stack
23
+ *
24
+ * @returns {StyleContextStack} current stack snapshot
25
+ */
26
+
27
+
28
+ clone() {
29
+ let stack = new StyleContextStack(this.styleDictionary, this.defaultStyle);
30
+ this.styleOverrides.forEach(item => {
31
+ stack.styleOverrides.push(item);
32
+ });
33
+ return stack;
34
+ }
35
+ /**
36
+ * Pushes style-name or style-overrides-object onto the stack for future evaluation
37
+ *
38
+ * @param {string|object} styleNameOrOverride style-name (referring to styleDictionary) or
39
+ * a new dictionary defining overriding properties
40
+ */
41
+
42
+
43
+ push(styleNameOrOverride) {
44
+ this.styleOverrides.push(styleNameOrOverride);
45
+ }
46
+ /**
47
+ * Removes last style-name or style-overrides-object from the stack
48
+ *
49
+ * @param {number} howMany optional number of elements to be popped (if not specified,
50
+ * one element will be removed from the stack)
51
+ */
52
+
53
+
54
+ pop(howMany = 1) {
55
+ while (howMany-- > 0) {
56
+ this.styleOverrides.pop();
57
+ }
58
+ }
59
+ /**
60
+ * Creates a set of named styles or/and a style-overrides-object based on the item,
61
+ * pushes those elements onto the stack for future evaluation and returns the number
62
+ * of elements pushed, so they can be easily poped then.
63
+ *
64
+ * @param {object} item - an object with optional style property and/or style overrides
65
+ * @returns {number} the number of items pushed onto the stack
66
+ */
67
+
68
+
69
+ autopush(item) {
70
+ if ((0, _variableType.isString)(item)) {
71
+ return 0;
72
+ }
73
+
74
+ let styleNames = [];
75
+
76
+ if (item.style) {
77
+ if (Array.isArray(item.style)) {
78
+ styleNames = item.style;
79
+ } else {
80
+ styleNames = [item.style];
81
+ }
82
+ }
83
+
84
+ for (let i = 0, l = styleNames.length; i < l; i++) {
85
+ this.push(styleNames[i]);
86
+ }
87
+
88
+ let styleProperties = ['font', 'fontSize', 'fontFeatures', 'bold', 'italics', 'alignment', 'color', 'columnGap', 'fillColor', 'fillOpacity', 'decoration', 'decorationStyle', 'decorationColor', 'background', 'lineHeight', 'characterSpacing', 'noWrap', 'markerColor', 'leadingIndent', 'sup', 'sub' //'tableCellPadding'
89
+ // 'cellBorder',
90
+ // 'headerCellBorder',
91
+ // 'oddRowCellBorder',
92
+ // 'evenRowCellBorder',
93
+ // 'tableBorder'
94
+ ];
95
+ let styleOverrideObject = {};
96
+ let pushStyleOverrideObject = false;
97
+ styleProperties.forEach(key => {
98
+ if ((0, _variableType.isValue)(item[key])) {
99
+ styleOverrideObject[key] = item[key];
100
+ pushStyleOverrideObject = true;
101
+ }
102
+ });
103
+
104
+ if (pushStyleOverrideObject) {
105
+ this.push(styleOverrideObject);
106
+ }
107
+
108
+ return styleNames.length + (pushStyleOverrideObject ? 1 : 0);
109
+ }
110
+ /**
111
+ * Automatically pushes elements onto the stack, using autopush based on item,
112
+ * executes callback and then pops elements back. Returns value returned by callback
113
+ *
114
+ * @param {object} item - an object with optional style property and/or style overrides
115
+ * @param {Function} callback to be called between autopush and pop
116
+ * @returns {object} value returned by callback
117
+ */
118
+
119
+
120
+ auto(item, callback) {
121
+ let pushedItems = this.autopush(item);
122
+ let result = callback();
123
+
124
+ if (pushedItems > 0) {
125
+ this.pop(pushedItems);
126
+ }
127
+
128
+ return result;
129
+ }
130
+ /**
131
+ * Evaluates stack and returns value of a named property
132
+ *
133
+ * @param {string} property - property name
134
+ * @returns {?any} property value or null if not found
135
+ */
136
+
137
+
138
+ getProperty(property) {
139
+ if (this.styleOverrides) {
140
+ for (let i = this.styleOverrides.length - 1; i >= 0; i--) {
141
+ let item = this.styleOverrides[i];
142
+
143
+ if ((0, _variableType.isString)(item)) {
144
+ // named-style-override
145
+ let style = this.styleDictionary[item];
146
+
147
+ if (style && (0, _variableType.isValue)(style[property])) {
148
+ return style[property];
149
+ }
150
+ } else if ((0, _variableType.isValue)(item[property])) {
151
+ // style-overrides-object
152
+ return item[property];
153
+ }
154
+ }
155
+ }
156
+
157
+ return this.defaultStyle && this.defaultStyle[property];
158
+ }
159
+ /**
160
+ * @param {object} item
161
+ * @param {StyleContextStack} styleContextStack
162
+ * @param {string} property
163
+ * @param {any} defaultValue
164
+ * @returns {any}
165
+ */
166
+
167
+
168
+ static getStyleProperty(item, styleContextStack, property, defaultValue) {
169
+ let value;
170
+
171
+ if ((0, _variableType.isValue)(item[property])) {
172
+ // item defines this property
173
+ return item[property];
174
+ }
175
+
176
+ if (!styleContextStack) {
177
+ return defaultValue;
178
+ }
179
+
180
+ styleContextStack.auto(item, () => {
181
+ value = styleContextStack.getProperty(property);
182
+ });
183
+ return (0, _variableType.isValue)(value) ? value : defaultValue;
184
+ }
185
+ /**
186
+ * @param {object} source
187
+ * @param {object} destination
188
+ * @returns {object}
189
+ */
190
+
191
+
192
+ static copyStyle(source = {}, destination = {}) {
193
+ // TODO: default style to source
194
+ for (let key in source) {
195
+ if (key != 'text' && source.hasOwnProperty(key)) {
196
+ destination[key] = source[key];
197
+ }
198
+ }
199
+
200
+ return destination;
201
+ }
202
+
203
+ }
204
+
205
+ var _default = StyleContextStack;
206
+ exports.default = _default;