@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,652 +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 {
17
- $appendChild,
18
- $clone,
19
- $consumed,
20
- $content,
21
- $data,
22
- $finalize,
23
- $getAttributeIt,
24
- $getChildren,
25
- $getDataValue,
26
- $getParent,
27
- $getRealChildrenByNameIt,
28
- $hasSettableValue,
29
- $indexOf,
30
- $insertAt,
31
- $isBindable,
32
- $isDataValue,
33
- $isDescendent,
34
- $namespaceId,
35
- $nodeName,
36
- $removeChild,
37
- $setValue,
38
- $text,
39
- XFAAttribute,
40
- XmlObject,
41
- } from "./xfa_object.js";
42
- import { BindItems, Field, Items, SetProperty, Text } from "./template.js";
43
- import { createDataNode, searchNode } from "./som.js";
44
- import { NamespaceIds } from "./namespaces.js";
45
- import { warn } from "../../shared/util.js";
46
-
47
- function createText(content) {
48
- const node = new Text({});
49
- node[$content] = content;
50
- return node;
51
- }
52
-
53
- class Binder {
54
- constructor(root) {
55
- this.root = root;
56
- this.datasets = root.datasets;
57
- if (root.datasets && root.datasets.data) {
58
- this.data = root.datasets.data;
59
- } else {
60
- this.data = new XmlObject(NamespaceIds.datasets.id, "data");
61
- }
62
- this.emptyMerge = this.data[$getChildren]().length === 0;
63
-
64
- this.root.form = this.form = root.template[$clone]();
65
- }
66
-
67
- _isConsumeData() {
68
- return !this.emptyMerge && this._mergeMode;
69
- }
70
-
71
- _isMatchTemplate() {
72
- return !this._isConsumeData();
73
- }
74
-
75
- bind() {
76
- this._bindElement(this.form, this.data);
77
- return this.form;
78
- }
79
-
80
- getData() {
81
- return this.data;
82
- }
83
-
84
- _bindValue(formNode, data, picture) {
85
- // Nodes must have the same "type": container or value.
86
- // Here we make the link between form node and
87
- // data node (through $data property): we'll use it
88
- // to save form data.
89
-
90
- formNode[$data] = data;
91
- if (formNode[$hasSettableValue]()) {
92
- if (data[$isDataValue]()) {
93
- const value = data[$getDataValue]();
94
- // TODO: use picture.
95
- formNode[$setValue](createText(value));
96
- } else if (
97
- formNode instanceof Field &&
98
- formNode.ui &&
99
- formNode.ui.choiceList &&
100
- formNode.ui.choiceList.open === "multiSelect"
101
- ) {
102
- const value = data[$getChildren]()
103
- .map(child => child[$content].trim())
104
- .join("\n");
105
- formNode[$setValue](createText(value));
106
- } else if (this._isConsumeData()) {
107
- warn(`XFA - Nodes haven't the same type.`);
108
- }
109
- } else if (!data[$isDataValue]() || this._isMatchTemplate()) {
110
- this._bindElement(formNode, data);
111
- } else {
112
- warn(`XFA - Nodes haven't the same type.`);
113
- }
114
- }
115
-
116
- _findDataByNameToConsume(name, isValue, dataNode, global) {
117
- if (!name) {
118
- return null;
119
- }
120
-
121
- // Firstly, we try to find a node with the given name:
122
- // - in dataNode;
123
- // - if not found, then in parent;
124
- // - and if not in found, then in grand-parent.
125
- let generator, match;
126
- for (let i = 0; i < 3; i++) {
127
- generator = dataNode[$getRealChildrenByNameIt](
128
- name,
129
- /* allTransparent = */ false,
130
- /* skipConsumed = */ true
131
- );
132
- // Try to find a match of the same kind.
133
- while (true) {
134
- match = generator.next().value;
135
- if (!match) {
136
- break;
137
- }
138
-
139
- if (isValue === match[$isDataValue]()) {
140
- return match;
141
- }
142
- }
143
- if (
144
- dataNode[$namespaceId] === NamespaceIds.datasets.id &&
145
- dataNode[$nodeName] === "data"
146
- ) {
147
- break;
148
- }
149
- dataNode = dataNode[$getParent]();
150
- }
151
-
152
- if (!global) {
153
- return null;
154
- }
155
-
156
- // Secondly, if global try to find it just under the root of datasets
157
- // (which is the location of global variables).
158
- generator = this.data[$getRealChildrenByNameIt](
159
- name,
160
- /* allTransparent = */ true,
161
- /* skipConsumed = */ false
162
- );
163
-
164
- match = generator.next().value;
165
- if (match) {
166
- return match;
167
- }
168
-
169
- // Thirdly, try to find it in attributes.
170
- generator = this.data[$getAttributeIt](name, /* skipConsumed = */ true);
171
- match = generator.next().value;
172
- if (match && match[$isDataValue]()) {
173
- return match;
174
- }
175
-
176
- return null;
177
- }
178
-
179
- _setProperties(formNode, dataNode) {
180
- // For example:
181
- // <field name="LastName" ...>
182
- // <setProperty ref="$data.Main.Style.NameFont" target="font.typeface"/>
183
- // <setProperty ref="$data.Main.Style.NameSize" target="font.size"/>
184
- // <setProperty ref="$data.Main.Help.LastName" target="assist.toolTip"/>
185
- // </field>
186
-
187
- if (!formNode.hasOwnProperty("setProperty")) {
188
- return;
189
- }
190
-
191
- for (const { ref, target, connection } of formNode.setProperty.children) {
192
- if (connection) {
193
- // TODO: evaluate if we should implement this feature.
194
- // Skip for security reasons.
195
- continue;
196
- }
197
- if (!ref) {
198
- continue;
199
- }
200
-
201
- const nodes = searchNode(
202
- this.root,
203
- dataNode,
204
- ref,
205
- false /* = dotDotAllowed */,
206
- false /* = useCache */
207
- );
208
- if (!nodes) {
209
- warn(`XFA - Invalid reference: ${ref}.`);
210
- continue;
211
- }
212
- const [node] = nodes;
213
-
214
- if (!node[$isDescendent](this.data)) {
215
- warn(`XFA - Invalid node: must be a data node.`);
216
- continue;
217
- }
218
-
219
- const targetNodes = searchNode(
220
- this.root,
221
- formNode,
222
- target,
223
- false /* = dotDotAllowed */,
224
- false /* = useCache */
225
- );
226
- if (!targetNodes) {
227
- warn(`XFA - Invalid target: ${target}.`);
228
- continue;
229
- }
230
- const [targetNode] = targetNodes;
231
-
232
- if (!targetNode[$isDescendent](formNode)) {
233
- warn(`XFA - Invalid target: must be a property or subproperty.`);
234
- continue;
235
- }
236
-
237
- const targetParent = targetNode[$getParent]();
238
- if (
239
- targetNode instanceof SetProperty ||
240
- targetParent instanceof SetProperty
241
- ) {
242
- warn(
243
- `XFA - Invalid target: cannot be a setProperty or one of its properties.`
244
- );
245
- continue;
246
- }
247
-
248
- if (
249
- targetNode instanceof BindItems ||
250
- targetParent instanceof BindItems
251
- ) {
252
- warn(
253
- `XFA - Invalid target: cannot be a bindItems or one of its properties.`
254
- );
255
- continue;
256
- }
257
-
258
- const content = node[$text]();
259
- const name = targetNode[$nodeName];
260
-
261
- if (targetNode instanceof XFAAttribute) {
262
- const attrs = Object.create(null);
263
- attrs[name] = content;
264
- const obj = Reflect.construct(
265
- Object.getPrototypeOf(targetParent).constructor,
266
- [attrs]
267
- );
268
- targetParent[name] = obj[name];
269
- continue;
270
- }
271
-
272
- if (!targetNode.hasOwnProperty($content)) {
273
- warn(`XFA - Invalid node to use in setProperty`);
274
- continue;
275
- }
276
-
277
- targetNode[$data] = node;
278
- targetNode[$content] = content;
279
- targetNode[$finalize]();
280
- }
281
- }
282
-
283
- _bindItems(formNode, dataNode) {
284
- // For example:
285
- // <field name="CardName"...>
286
- // <bindItems ref="$data.main.ccs.cc[*]" labelRef="uiname"
287
- // valueRef="token"/>
288
- // <ui><choiceList/></ui>
289
- // </field>
290
-
291
- if (
292
- !formNode.hasOwnProperty("items") ||
293
- !formNode.hasOwnProperty("bindItems") ||
294
- formNode.bindItems.isEmpty()
295
- ) {
296
- return;
297
- }
298
-
299
- for (const item of formNode.items.children) {
300
- formNode[$removeChild](item);
301
- }
302
-
303
- formNode.items.clear();
304
-
305
- const labels = new Items({});
306
- const values = new Items({});
307
-
308
- formNode[$appendChild](labels);
309
- formNode.items.push(labels);
310
-
311
- formNode[$appendChild](values);
312
- formNode.items.push(values);
313
-
314
- for (const { ref, labelRef, valueRef, connection } of formNode.bindItems
315
- .children) {
316
- if (connection) {
317
- // TODO: evaluate if we should implement this feature.
318
- // Skip for security reasons.
319
- continue;
320
- }
321
- if (!ref) {
322
- continue;
323
- }
324
-
325
- const nodes = searchNode(
326
- this.root,
327
- dataNode,
328
- ref,
329
- false /* = dotDotAllowed */,
330
- false /* = useCache */
331
- );
332
- if (!nodes) {
333
- warn(`XFA - Invalid reference: ${ref}.`);
334
- continue;
335
- }
336
- for (const node of nodes) {
337
- if (!node[$isDescendent](this.datasets)) {
338
- warn(`XFA - Invalid ref (${ref}): must be a datasets child.`);
339
- continue;
340
- }
341
-
342
- const labelNodes = searchNode(
343
- this.root,
344
- node,
345
- labelRef,
346
- true /* = dotDotAllowed */,
347
- false /* = useCache */
348
- );
349
- if (!labelNodes) {
350
- warn(`XFA - Invalid label: ${labelRef}.`);
351
- continue;
352
- }
353
- const [labelNode] = labelNodes;
354
-
355
- if (!labelNode[$isDescendent](this.datasets)) {
356
- warn(`XFA - Invalid label: must be a datasets child.`);
357
- continue;
358
- }
359
-
360
- const valueNodes = searchNode(
361
- this.root,
362
- node,
363
- valueRef,
364
- true /* = dotDotAllowed */,
365
- false /* = useCache */
366
- );
367
- if (!valueNodes) {
368
- warn(`XFA - Invalid value: ${valueRef}.`);
369
- continue;
370
- }
371
- const [valueNode] = valueNodes;
372
-
373
- if (!valueNode[$isDescendent](this.datasets)) {
374
- warn(`XFA - Invalid value: must be a datasets child.`);
375
- continue;
376
- }
377
-
378
- const label = createText(labelNode[$text]());
379
- const value = createText(valueNode[$text]());
380
-
381
- labels[$appendChild](label);
382
- labels.text.push(label);
383
-
384
- values[$appendChild](value);
385
- values.text.push(value);
386
- }
387
- }
388
- }
389
-
390
- _bindOccurrences(formNode, matches, picture) {
391
- // Insert nodes which are not in the template but reflect
392
- // what we've in data tree.
393
-
394
- let baseClone;
395
- if (matches.length > 1) {
396
- // Clone before binding to avoid bad state.
397
- baseClone = formNode[$clone]();
398
- }
399
-
400
- this._bindValue(formNode, matches[0], picture);
401
- this._setProperties(formNode, matches[0]);
402
- this._bindItems(formNode, matches[0]);
403
-
404
- if (matches.length === 1) {
405
- return;
406
- }
407
-
408
- const parent = formNode[$getParent]();
409
- const name = formNode[$nodeName];
410
- const pos = parent[$indexOf](formNode);
411
-
412
- for (let i = 1, ii = matches.length; i < ii; i++) {
413
- const match = matches[i];
414
- const clone = baseClone[$clone]();
415
- clone.occur.min = 1;
416
- clone.occur.max = 1;
417
- clone.occur.initial = 1;
418
- parent[name].push(clone);
419
- parent[$insertAt](pos + i, clone);
420
-
421
- this._bindValue(clone, match, picture);
422
- this._setProperties(clone, match);
423
- this._bindItems(clone, match);
424
- }
425
- }
426
-
427
- _createOccurrences(formNode) {
428
- if (!this.emptyMerge) {
429
- return;
430
- }
431
-
432
- const { occur } = formNode;
433
- if (!occur || occur.initial <= 1) {
434
- return;
435
- }
436
-
437
- const parent = formNode[$getParent]();
438
- const name = formNode[$nodeName];
439
-
440
- for (let i = 0, ii = occur.initial; i < ii; i++) {
441
- const clone = formNode[$clone]();
442
- clone.occur.min = 1;
443
- clone.occur.max = 1;
444
- clone.occur.initial = 1;
445
- parent[name].push(clone);
446
- parent[$appendChild](clone);
447
- }
448
- }
449
-
450
- _getOccurInfo(formNode) {
451
- const { occur } = formNode;
452
- const dataName = formNode.name;
453
- if (!occur || !dataName) {
454
- return [1, 1];
455
- }
456
- const max = occur.max === -1 ? Infinity : occur.max;
457
- return [occur.min, max];
458
- }
459
-
460
- _bindElement(formNode, dataNode) {
461
- // Some nodes can be useless because min=0 so remove them
462
- // after the loop to avoid bad things.
463
-
464
- const uselessNodes = [];
465
-
466
- this._createOccurrences(formNode);
467
-
468
- for (const child of formNode[$getChildren]()) {
469
- if (child[$data]) {
470
- // Already bound.
471
- continue;
472
- }
473
-
474
- if (this._mergeMode === undefined && child[$nodeName] === "subform") {
475
- this._mergeMode = child.mergeMode === "consumeData";
476
-
477
- // XFA specs p. 182:
478
- // The highest-level subform and the data node representing
479
- // the current record are special; they are always
480
- // bound even if their names don't match.
481
- const dataChildren = dataNode[$getChildren]();
482
- if (dataChildren.length > 0) {
483
- this._bindOccurrences(child, [dataChildren[0]], null);
484
- } else if (this.emptyMerge) {
485
- const dataChild = (child[$data] = new XmlObject(
486
- dataNode[$namespaceId],
487
- child.name || "root"
488
- ));
489
- dataNode[$appendChild](dataChild);
490
- this._bindElement(child, dataChild);
491
- }
492
- continue;
493
- }
494
-
495
- if (!child[$isBindable]()) {
496
- // The node cannot contain some new data so there is nothing
497
- // to create in the data node.
498
- continue;
499
- }
500
-
501
- let global = false;
502
- let picture = null;
503
- let ref = null;
504
- let match = null;
505
- if (child.bind) {
506
- switch (child.bind.match) {
507
- case "none":
508
- this._bindElement(child, dataNode);
509
- continue;
510
- case "global":
511
- global = true;
512
- break;
513
- case "dataRef":
514
- if (!child.bind.ref) {
515
- warn(`XFA - ref is empty in node ${child[$nodeName]}.`);
516
- this._bindElement(child, dataNode);
517
- continue;
518
- }
519
- ref = child.bind.ref;
520
- break;
521
- default:
522
- break;
523
- }
524
- if (child.bind.picture) {
525
- picture = child.bind.picture[$content];
526
- }
527
- }
528
-
529
- const [min, max] = this._getOccurInfo(child);
530
-
531
- if (ref) {
532
- // Don't use a cache for searching: nodes can change during binding.
533
- match = searchNode(
534
- this.root,
535
- dataNode,
536
- ref,
537
- true /* = dotDotAllowed */,
538
- false /* = useCache */
539
- );
540
- if (match === null) {
541
- // Nothing found: we must create some nodes in data in order
542
- // to have something to match with the given expression.
543
- // See http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=199
544
- match = createDataNode(this.data, dataNode, ref);
545
- if (!match) {
546
- // For example if the node contains a .(...) then it isn't
547
- // findable.
548
- // TODO: remove this when .(...) is implemented.
549
- continue;
550
- }
551
- if (this._isConsumeData()) {
552
- match[$consumed] = true;
553
- }
554
-
555
- // Don't bind the value in newly created node because it's empty.
556
- this._bindElement(child, match);
557
- continue;
558
- } else {
559
- if (this._isConsumeData()) {
560
- // Filter out consumed nodes.
561
- match = match.filter(node => !node[$consumed]);
562
- }
563
- if (match.length > max) {
564
- match = match.slice(0, max);
565
- } else if (match.length === 0) {
566
- match = null;
567
- }
568
- if (match && this._isConsumeData()) {
569
- match.forEach(node => {
570
- node[$consumed] = true;
571
- });
572
- }
573
- }
574
- } else {
575
- if (!child.name) {
576
- this._bindElement(child, dataNode);
577
- continue;
578
- }
579
- if (this._isConsumeData()) {
580
- // In consumeData mode, search for the next node with the given name.
581
- // occurs.max gives us the max number of node to match.
582
- const matches = [];
583
- while (matches.length < max) {
584
- const found = this._findDataByNameToConsume(
585
- child.name,
586
- child[$hasSettableValue](),
587
- dataNode,
588
- global
589
- );
590
-
591
- if (!found) {
592
- break;
593
- }
594
- found[$consumed] = true;
595
- matches.push(found);
596
- }
597
- match = matches.length > 0 ? matches : null;
598
- } else {
599
- // If we've an empty merge, there are no reason
600
- // to make multiple bind so skip consumed nodes.
601
- match = dataNode[$getRealChildrenByNameIt](
602
- child.name,
603
- /* allTransparent = */ false,
604
- /* skipConsumed = */ this.emptyMerge
605
- ).next().value;
606
- if (!match) {
607
- // We're in matchTemplate mode so create a node in data to reflect
608
- // what we've in template.
609
- match = child[$data] = new XmlObject(
610
- dataNode[$namespaceId],
611
- child.name
612
- );
613
- if (this.emptyMerge) {
614
- match[$consumed] = true;
615
- }
616
- dataNode[$appendChild](match);
617
-
618
- // Don't bind the value in newly created node because it's empty.
619
- this._setProperties(child, match);
620
- this._bindItems(child, match);
621
- this._bindElement(child, match);
622
- continue;
623
- }
624
- if (this.emptyMerge) {
625
- match[$consumed] = true;
626
- }
627
- match = [match];
628
- }
629
- }
630
-
631
- if (match) {
632
- if (match.length < min) {
633
- warn(
634
- `XFA - Must have at least ${min} occurrences: ${formNode[$nodeName]}.`
635
- );
636
- continue;
637
- }
638
- this._bindOccurrences(child, match, picture);
639
- } else if (min > 0) {
640
- this._setProperties(child, dataNode);
641
- this._bindItems(child, dataNode);
642
- this._bindElement(child, dataNode);
643
- } else {
644
- uselessNodes.push(child);
645
- }
646
- }
647
-
648
- uselessNodes.forEach(node => node[$getParent]()[$removeChild](node));
649
- }
650
- }
651
-
652
- export { Binder };