@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.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 (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
@@ -1,290 +0,0 @@
1
- /* Copyright 2021 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import { selectFont } from "./fonts.js";
17
-
18
- const WIDTH_FACTOR = 1.01;
19
-
20
- class FontInfo {
21
- constructor(xfaFont, margin, lineHeight, fontFinder) {
22
- this.lineHeight = lineHeight;
23
- this.paraMargin = margin || {
24
- top: 0,
25
- bottom: 0,
26
- left: 0,
27
- right: 0,
28
- };
29
-
30
- if (!xfaFont) {
31
- [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
32
- return;
33
- }
34
-
35
- this.xfaFont = {
36
- typeface: xfaFont.typeface,
37
- posture: xfaFont.posture,
38
- weight: xfaFont.weight,
39
- size: xfaFont.size,
40
- letterSpacing: xfaFont.letterSpacing,
41
- };
42
- const typeface = fontFinder.find(xfaFont.typeface);
43
- if (!typeface) {
44
- [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
45
- return;
46
- }
47
-
48
- this.pdfFont = selectFont(xfaFont, typeface);
49
-
50
- if (!this.pdfFont) {
51
- [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
52
- }
53
- }
54
-
55
- defaultFont(fontFinder) {
56
- // TODO: Add a default font based on Liberation.
57
- const font =
58
- fontFinder.find("Helvetica", false) ||
59
- fontFinder.find("Myriad Pro", false) ||
60
- fontFinder.find("Arial", false) ||
61
- fontFinder.getDefault();
62
- if (font && font.regular) {
63
- const pdfFont = font.regular;
64
- const info = pdfFont.cssFontInfo;
65
- const xfaFont = {
66
- typeface: info.fontFamily,
67
- posture: "normal",
68
- weight: "normal",
69
- size: 10,
70
- letterSpacing: 0,
71
- };
72
- return [pdfFont, xfaFont];
73
- }
74
-
75
- const xfaFont = {
76
- typeface: "Courier",
77
- posture: "normal",
78
- weight: "normal",
79
- size: 10,
80
- letterSpacing: 0,
81
- };
82
- return [null, xfaFont];
83
- }
84
- }
85
-
86
- class FontSelector {
87
- constructor(
88
- defaultXfaFont,
89
- defaultParaMargin,
90
- defaultLineHeight,
91
- fontFinder
92
- ) {
93
- this.fontFinder = fontFinder;
94
- this.stack = [
95
- new FontInfo(
96
- defaultXfaFont,
97
- defaultParaMargin,
98
- defaultLineHeight,
99
- fontFinder
100
- ),
101
- ];
102
- }
103
-
104
- pushData(xfaFont, margin, lineHeight) {
105
- const lastFont = this.stack[this.stack.length - 1];
106
- for (const name of [
107
- "typeface",
108
- "posture",
109
- "weight",
110
- "size",
111
- "letterSpacing",
112
- ]) {
113
- if (!xfaFont[name]) {
114
- xfaFont[name] = lastFont.xfaFont[name];
115
- }
116
- }
117
-
118
- for (const name of ["top", "bottom", "left", "right"]) {
119
- if (isNaN(margin[name])) {
120
- margin[name] = lastFont.paraMargin[name];
121
- }
122
- }
123
-
124
- const fontInfo = new FontInfo(
125
- xfaFont,
126
- margin,
127
- lineHeight || lastFont.lineHeight,
128
- this.fontFinder
129
- );
130
- if (!fontInfo.pdfFont) {
131
- fontInfo.pdfFont = lastFont.pdfFont;
132
- }
133
-
134
- this.stack.push(fontInfo);
135
- }
136
-
137
- popFont() {
138
- this.stack.pop();
139
- }
140
-
141
- topFont() {
142
- return this.stack[this.stack.length - 1];
143
- }
144
- }
145
-
146
- /**
147
- * Compute a text area dimensions based on font metrics.
148
- */
149
- class TextMeasure {
150
- constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts) {
151
- this.glyphs = [];
152
- this.fontSelector = new FontSelector(
153
- defaultXfaFont,
154
- defaultParaMargin,
155
- defaultLineHeight,
156
- fonts
157
- );
158
- this.extraHeight = 0;
159
- }
160
-
161
- pushData(xfaFont, margin, lineHeight) {
162
- this.fontSelector.pushData(xfaFont, margin, lineHeight);
163
- }
164
-
165
- popFont(xfaFont) {
166
- return this.fontSelector.popFont();
167
- }
168
-
169
- addPara() {
170
- const lastFont = this.fontSelector.topFont();
171
- this.extraHeight += lastFont.paraMargin.top + lastFont.paraMargin.bottom;
172
- }
173
-
174
- addString(str) {
175
- if (!str) {
176
- return;
177
- }
178
-
179
- const lastFont = this.fontSelector.topFont();
180
- const fontSize = lastFont.xfaFont.size;
181
- if (lastFont.pdfFont) {
182
- const letterSpacing = lastFont.xfaFont.letterSpacing;
183
- const pdfFont = lastFont.pdfFont;
184
- const lineHeight =
185
- lastFont.lineHeight ||
186
- Math.ceil(Math.max(1.2, pdfFont.lineHeight) * fontSize);
187
- const scale = fontSize / 1000;
188
-
189
- for (const line of str.split(/[\u2029\n]/)) {
190
- const encodedLine = pdfFont.encodeString(line).join("");
191
- const glyphs = pdfFont.charsToGlyphs(encodedLine);
192
-
193
- for (const glyph of glyphs) {
194
- this.glyphs.push([
195
- glyph.width * scale + letterSpacing,
196
- lineHeight,
197
- glyph.unicode === " ",
198
- false,
199
- ]);
200
- }
201
-
202
- this.glyphs.push([0, 0, false, true]);
203
- }
204
- this.glyphs.pop();
205
- return;
206
- }
207
-
208
- // When we have no font in the pdf, just use the font size as default width.
209
- for (const line of str.split(/[\u2029\n]/)) {
210
- for (const char of line.split("")) {
211
- this.glyphs.push([fontSize, fontSize, char === " ", false]);
212
- }
213
-
214
- this.glyphs.push([0, 0, false, true]);
215
- }
216
- this.glyphs.pop();
217
- }
218
-
219
- compute(maxWidth) {
220
- let lastSpacePos = -1,
221
- lastSpaceWidth = 0,
222
- width = 0,
223
- height = 0,
224
- currentLineWidth = 0,
225
- currentLineHeight = 0;
226
- let isBroken = false;
227
-
228
- for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
229
- const [glyphWidth, glyphHeight, isSpace, isEOL] = this.glyphs[i];
230
- if (isEOL) {
231
- width = Math.max(width, currentLineWidth);
232
- currentLineWidth = 0;
233
- height += currentLineHeight;
234
- currentLineHeight = glyphHeight;
235
- lastSpacePos = -1;
236
- lastSpaceWidth = 0;
237
- continue;
238
- }
239
-
240
- if (isSpace) {
241
- if (currentLineWidth + glyphWidth > maxWidth) {
242
- // We can break here but the space is not taken into account.
243
- width = Math.max(width, currentLineWidth);
244
- currentLineWidth = 0;
245
- height += currentLineHeight;
246
- currentLineHeight = glyphHeight;
247
- lastSpacePos = -1;
248
- lastSpaceWidth = 0;
249
- isBroken = true;
250
- } else {
251
- currentLineHeight = Math.max(glyphHeight, currentLineHeight);
252
- lastSpaceWidth = currentLineWidth;
253
- currentLineWidth += glyphWidth;
254
- lastSpacePos = i;
255
- }
256
- continue;
257
- }
258
-
259
- if (currentLineWidth + glyphWidth > maxWidth) {
260
- // We must break to the last white position (if available)
261
- height += currentLineHeight;
262
- currentLineHeight = glyphHeight;
263
- if (lastSpacePos !== -1) {
264
- i = lastSpacePos;
265
- width = Math.max(width, lastSpaceWidth);
266
- currentLineWidth = 0;
267
- lastSpacePos = -1;
268
- lastSpaceWidth = 0;
269
- } else {
270
- // Just break in the middle of the word
271
- width = Math.max(width, currentLineWidth);
272
- currentLineWidth = glyphWidth;
273
- }
274
- isBroken = true;
275
-
276
- continue;
277
- }
278
-
279
- currentLineWidth += glyphWidth;
280
- currentLineHeight = Math.max(glyphHeight, currentLineHeight);
281
- }
282
-
283
- width = Math.max(width, currentLineWidth);
284
- height += currentLineHeight + this.extraHeight;
285
-
286
- return { width: WIDTH_FACTOR * width, height, isBroken };
287
- }
288
- }
289
-
290
- export { TextMeasure };
@@ -1,29 +0,0 @@
1
- /* Copyright 2021 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import { $buildXFAObject } from "./namespaces.js";
17
- import { XmlObject } from "./xfa_object.js";
18
-
19
- class UnknownNamespace {
20
- constructor(nsId) {
21
- this.namespaceId = nsId;
22
- }
23
-
24
- [$buildXFAObject](name, attributes) {
25
- return new XmlObject(this.namespaceId, name, attributes);
26
- }
27
- }
28
-
29
- export { UnknownNamespace };
@@ -1,217 +0,0 @@
1
- /* Copyright 2021 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import { shadow } from "../../shared/util.js";
17
-
18
- const dimConverters = {
19
- pt: x => x,
20
- cm: x => (x / 2.54) * 72,
21
- mm: x => (x / (10 * 2.54)) * 72,
22
- in: x => x * 72,
23
- px: x => x,
24
- };
25
- const measurementPattern = /([+-]?[0-9]+\.?[0-9]*)(.*)/;
26
-
27
- function stripQuotes(str) {
28
- if (str.startsWith("'") || str.startsWith('"')) {
29
- return str.slice(1, str.length - 1);
30
- }
31
- return str;
32
- }
33
-
34
- function getInteger({ data, defaultValue, validate }) {
35
- if (!data) {
36
- return defaultValue;
37
- }
38
- data = data.trim();
39
- const n = parseInt(data, 10);
40
- if (!isNaN(n) && validate(n)) {
41
- return n;
42
- }
43
- return defaultValue;
44
- }
45
-
46
- function getFloat({ data, defaultValue, validate }) {
47
- if (!data) {
48
- return defaultValue;
49
- }
50
- data = data.trim();
51
- const n = parseFloat(data);
52
- if (!isNaN(n) && validate(n)) {
53
- return n;
54
- }
55
- return defaultValue;
56
- }
57
-
58
- function getKeyword({ data, defaultValue, validate }) {
59
- if (!data) {
60
- return defaultValue;
61
- }
62
- data = data.trim();
63
- if (validate(data)) {
64
- return data;
65
- }
66
- return defaultValue;
67
- }
68
-
69
- function getStringOption(data, options) {
70
- return getKeyword({
71
- data,
72
- defaultValue: options[0],
73
- validate: k => options.includes(k),
74
- });
75
- }
76
-
77
- function getMeasurement(str, def = "0") {
78
- def = def || "0";
79
- if (!str) {
80
- return getMeasurement(def);
81
- }
82
- const match = str.trim().match(measurementPattern);
83
- if (!match) {
84
- return getMeasurement(def);
85
- }
86
- const [, valueStr, unit] = match;
87
- const value = parseFloat(valueStr);
88
- if (isNaN(value)) {
89
- return getMeasurement(def);
90
- }
91
-
92
- if (value === 0) {
93
- return 0;
94
- }
95
-
96
- const conv = dimConverters[unit];
97
- if (conv) {
98
- return conv(value);
99
- }
100
-
101
- return value;
102
- }
103
-
104
- function getRatio(data) {
105
- if (!data) {
106
- return { num: 1, den: 1 };
107
- }
108
- const ratio = data
109
- .trim()
110
- .split(/\s*:\s*/)
111
- .map(x => parseFloat(x))
112
- .filter(x => !isNaN(x));
113
- if (ratio.length === 1) {
114
- ratio.push(1);
115
- }
116
-
117
- if (ratio.length === 0) {
118
- return { num: 1, den: 1 };
119
- }
120
-
121
- const [num, den] = ratio;
122
- return { num, den };
123
- }
124
-
125
- function getRelevant(data) {
126
- if (!data) {
127
- return [];
128
- }
129
- return data
130
- .trim()
131
- .split(/\s+/)
132
- .map(e => {
133
- return {
134
- excluded: e[0] === "-",
135
- viewname: e.substring(1),
136
- };
137
- });
138
- }
139
-
140
- function getColor(data, def = [0, 0, 0]) {
141
- let [r, g, b] = def;
142
- if (!data) {
143
- return { r, g, b };
144
- }
145
- const color = data
146
- .trim()
147
- .split(/\s*,\s*/)
148
- .map(c => Math.min(Math.max(0, parseInt(c.trim(), 10)), 255))
149
- .map(c => (isNaN(c) ? 0 : c));
150
-
151
- if (color.length < 3) {
152
- return { r, g, b };
153
- }
154
-
155
- [r, g, b] = color;
156
- return { r, g, b };
157
- }
158
-
159
- function getBBox(data) {
160
- const def = -1;
161
- if (!data) {
162
- return { x: def, y: def, width: def, height: def };
163
- }
164
- const bbox = data
165
- .trim()
166
- .split(/\s*,\s*/)
167
- .map(m => getMeasurement(m, "-1"));
168
- if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) {
169
- return { x: def, y: def, width: def, height: def };
170
- }
171
-
172
- const [x, y, width, height] = bbox;
173
- return { x, y, width, height };
174
- }
175
-
176
- class HTMLResult {
177
- static get FAILURE() {
178
- return shadow(this, "FAILURE", new HTMLResult(false, null, null, null));
179
- }
180
-
181
- static get EMPTY() {
182
- return shadow(this, "EMPTY", new HTMLResult(true, null, null, null));
183
- }
184
-
185
- constructor(success, html, bbox, breakNode) {
186
- this.success = success;
187
- this.html = html;
188
- this.bbox = bbox;
189
- this.breakNode = breakNode;
190
- }
191
-
192
- isBreak() {
193
- return !!this.breakNode;
194
- }
195
-
196
- static breakNode(node) {
197
- return new HTMLResult(false, null, null, node);
198
- }
199
-
200
- static success(html, bbox = null) {
201
- return new HTMLResult(true, html, bbox, null);
202
- }
203
- }
204
-
205
- export {
206
- getBBox,
207
- getColor,
208
- getFloat,
209
- getInteger,
210
- getKeyword,
211
- getMeasurement,
212
- getRatio,
213
- getRelevant,
214
- getStringOption,
215
- HTMLResult,
216
- stripQuotes,
217
- };
@@ -1,59 +0,0 @@
1
- /* Copyright 2021 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
-
16
- import { $buildXFAObject, NamespaceIds } from "./namespaces.js";
17
- import {
18
- $namespaceId,
19
- $nodeName,
20
- $onChildCheck,
21
- XFAObject,
22
- XFAObjectArray,
23
- } from "./xfa_object.js";
24
-
25
- const XDP_NS_ID = NamespaceIds.xdp.id;
26
-
27
- class Xdp extends XFAObject {
28
- constructor(attributes) {
29
- super(XDP_NS_ID, "xdp", /* hasChildren = */ true);
30
- this.uuid = attributes.uuid || "";
31
- this.timeStamp = attributes.timeStamp || "";
32
- this.config = null;
33
- this.connectionSet = null;
34
- this.datasets = null;
35
- this.localeSet = null;
36
- this.stylesheet = new XFAObjectArray();
37
- this.template = null;
38
- }
39
-
40
- [$onChildCheck](child) {
41
- const ns = NamespaceIds[child[$nodeName]];
42
- return ns && child[$namespaceId] === ns.id;
43
- }
44
- }
45
-
46
- class XdpNamespace {
47
- static [$buildXFAObject](name, attributes) {
48
- if (XdpNamespace.hasOwnProperty(name)) {
49
- return XdpNamespace[name](attributes);
50
- }
51
- return undefined;
52
- }
53
-
54
- static xdp(attributes) {
55
- return new Xdp(attributes);
56
- }
57
- }
58
-
59
- export { XdpNamespace };