@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,1130 +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 { getInteger, getKeyword, HTMLResult } from "./utils.js";
17
- import { shadow, warn } from "../../shared/util.js";
18
- import { encodeToXmlString } from "../core_utils.js";
19
- import { NamespaceIds } from "./namespaces.js";
20
- import { searchNode } from "./som.js";
21
-
22
- // We use these symbols to avoid name conflict between tags
23
- // and properties/methods names.
24
- const $acceptWhitespace = Symbol();
25
- const $addHTML = Symbol();
26
- const $appendChild = Symbol();
27
- const $childrenToHTML = Symbol();
28
- const $clean = Symbol();
29
- const $cleanPage = Symbol();
30
- const $cleanup = Symbol();
31
- const $clone = Symbol();
32
- const $consumed = Symbol();
33
- const $content = Symbol("content");
34
- const $data = Symbol("data");
35
- const $dump = Symbol();
36
- const $extra = Symbol("extra");
37
- const $finalize = Symbol();
38
- const $flushHTML = Symbol();
39
- const $getAttributeIt = Symbol();
40
- const $getAttributes = Symbol();
41
- const $getAvailableSpace = Symbol();
42
- const $getChildrenByClass = Symbol();
43
- const $getChildrenByName = Symbol();
44
- const $getChildrenByNameIt = Symbol();
45
- const $getDataValue = Symbol();
46
- const $getExtra = Symbol();
47
- const $getRealChildrenByNameIt = Symbol();
48
- const $getChildren = Symbol();
49
- const $getContainedChildren = Symbol();
50
- const $getNextPage = Symbol();
51
- const $getSubformParent = Symbol();
52
- const $getParent = Symbol();
53
- const $getTemplateRoot = Symbol();
54
- const $globalData = Symbol();
55
- const $hasSettableValue = Symbol();
56
- const $ids = Symbol();
57
- const $indexOf = Symbol();
58
- const $insertAt = Symbol();
59
- const $isCDATAXml = Symbol();
60
- const $isBindable = Symbol();
61
- const $isDataValue = Symbol();
62
- const $isDescendent = Symbol();
63
- const $isNsAgnostic = Symbol();
64
- const $isSplittable = Symbol();
65
- const $isThereMoreWidth = Symbol();
66
- const $isTransparent = Symbol();
67
- const $isUsable = Symbol();
68
- const $lastAttribute = Symbol();
69
- const $namespaceId = Symbol("namespaceId");
70
- const $nodeName = Symbol("nodeName");
71
- const $nsAttributes = Symbol();
72
- const $onChild = Symbol();
73
- const $onChildCheck = Symbol();
74
- const $onText = Symbol();
75
- const $pushGlyphs = Symbol();
76
- const $removeChild = Symbol();
77
- const $root = Symbol("root");
78
- const $resolvePrototypes = Symbol();
79
- const $searchNode = Symbol();
80
- const $setId = Symbol();
81
- const $setSetAttributes = Symbol();
82
- const $setValue = Symbol();
83
- const $tabIndex = Symbol();
84
- const $text = Symbol();
85
- const $toHTML = Symbol();
86
- const $toString = Symbol();
87
- const $toStyle = Symbol();
88
- const $uid = Symbol("uid");
89
-
90
- const _applyPrototype = Symbol();
91
- const _attributes = Symbol();
92
- const _attributeNames = Symbol();
93
- const _children = Symbol("_children");
94
- const _cloneAttribute = Symbol();
95
- const _dataValue = Symbol();
96
- const _defaultValue = Symbol();
97
- const _filteredChildrenGenerator = Symbol();
98
- const _getPrototype = Symbol();
99
- const _getUnsetAttributes = Symbol();
100
- const _hasChildren = Symbol();
101
- const _max = Symbol();
102
- const _options = Symbol();
103
- const _parent = Symbol("parent");
104
- const _resolvePrototypesHelper = Symbol();
105
- const _setAttributes = Symbol();
106
- const _validator = Symbol();
107
-
108
- let uid = 0;
109
-
110
- const NS_DATASETS = NamespaceIds.datasets.id;
111
-
112
- class XFAObject {
113
- constructor(nsId, name, hasChildren = false) {
114
- this[$namespaceId] = nsId;
115
- this[$nodeName] = name;
116
- this[_hasChildren] = hasChildren;
117
- this[_parent] = null;
118
- this[_children] = [];
119
- this[$uid] = `${name}${uid++}`;
120
- this[$globalData] = null;
121
- }
122
-
123
- [$onChild](child) {
124
- if (!this[_hasChildren] || !this[$onChildCheck](child)) {
125
- return false;
126
- }
127
-
128
- const name = child[$nodeName];
129
- const node = this[name];
130
-
131
- if (node instanceof XFAObjectArray) {
132
- if (node.push(child)) {
133
- this[$appendChild](child);
134
- return true;
135
- }
136
- } else {
137
- // IRL it's possible to already have a node.
138
- // So just replace it with the last version.
139
- if (node !== null) {
140
- this[$removeChild](node);
141
- }
142
- this[name] = child;
143
- this[$appendChild](child);
144
- return true;
145
- }
146
-
147
- let id = "";
148
- if (this.id) {
149
- id = ` (id: ${this.id})`;
150
- } else if (this.name) {
151
- id = ` (name: ${this.name} ${this.h.value})`;
152
- }
153
- warn(`XFA - node "${this[$nodeName]}"${id} has already enough "${name}"!`);
154
- return false;
155
- }
156
-
157
- [$onChildCheck](child) {
158
- return (
159
- this.hasOwnProperty(child[$nodeName]) &&
160
- child[$namespaceId] === this[$namespaceId]
161
- );
162
- }
163
-
164
- [$isNsAgnostic]() {
165
- return false;
166
- }
167
-
168
- [$acceptWhitespace]() {
169
- return false;
170
- }
171
-
172
- [$isCDATAXml]() {
173
- return false;
174
- }
175
-
176
- [$isBindable]() {
177
- return false;
178
- }
179
-
180
- [$setId](ids) {
181
- if (this.id && this[$namespaceId] === NamespaceIds.template.id) {
182
- ids.set(this.id, this);
183
- }
184
- }
185
-
186
- [$getTemplateRoot]() {
187
- return this[$globalData].template;
188
- }
189
-
190
- [$isSplittable]() {
191
- return false;
192
- }
193
-
194
- /**
195
- Return true if this node (typically a container)
196
- can provide more width during layout.
197
- The goal is to help to know what a descendant must
198
- do in case of horizontal overflow.
199
- */
200
- [$isThereMoreWidth]() {
201
- return false;
202
- }
203
-
204
- [$appendChild](child) {
205
- child[_parent] = this;
206
- this[_children].push(child);
207
- }
208
-
209
- [$removeChild](child) {
210
- const i = this[_children].indexOf(child);
211
- this[_children].splice(i, 1);
212
- }
213
-
214
- [$hasSettableValue]() {
215
- return this.hasOwnProperty("value");
216
- }
217
-
218
- [$setValue](_) {}
219
-
220
- [$onText](_) {}
221
-
222
- [$finalize]() {}
223
-
224
- [$clean](builder) {
225
- delete this[_hasChildren];
226
- if (this[$cleanup]) {
227
- builder.clean(this[$cleanup]);
228
- delete this[$cleanup];
229
- }
230
- }
231
-
232
- [$indexOf](child) {
233
- return this[_children].indexOf(child);
234
- }
235
-
236
- [$insertAt](i, child) {
237
- child[_parent] = this;
238
- this[_children].splice(i, 0, child);
239
- }
240
-
241
- /**
242
- * If true the element is transparent when searching a node using
243
- * a SOM expression which means that looking for "foo.bar" in
244
- * <... name="foo"><toto><titi><... name="bar"></titi></toto>...
245
- * is fine because toto and titi are transparent.
246
- */
247
- [$isTransparent]() {
248
- return !this.name;
249
- }
250
-
251
- [$lastAttribute]() {
252
- return "";
253
- }
254
-
255
- [$text]() {
256
- if (this[_children].length === 0) {
257
- return this[$content];
258
- }
259
- return this[_children].map(c => c[$text]()).join("");
260
- }
261
-
262
- get [_attributeNames]() {
263
- // Lazily get attributes names
264
- const proto = Object.getPrototypeOf(this);
265
- if (!proto._attributes) {
266
- const attributes = (proto._attributes = new Set());
267
- for (const name of Object.getOwnPropertyNames(this)) {
268
- if (
269
- this[name] === null ||
270
- this[name] instanceof XFAObject ||
271
- this[name] instanceof XFAObjectArray
272
- ) {
273
- break;
274
- }
275
- attributes.add(name);
276
- }
277
- }
278
- return shadow(this, _attributeNames, proto._attributes);
279
- }
280
-
281
- [$isDescendent](parent) {
282
- let node = this;
283
- while (node) {
284
- if (node === parent) {
285
- return true;
286
- }
287
- node = node[$getParent]();
288
- }
289
- return false;
290
- }
291
-
292
- [$getParent]() {
293
- return this[_parent];
294
- }
295
-
296
- [$getSubformParent]() {
297
- return this[$getParent]();
298
- }
299
-
300
- [$getChildren](name = null) {
301
- if (!name) {
302
- return this[_children];
303
- }
304
-
305
- return this[name];
306
- }
307
-
308
- [$dump]() {
309
- const dumped = Object.create(null);
310
- if (this[$content]) {
311
- dumped.$content = this[$content];
312
- }
313
-
314
- for (const name of Object.getOwnPropertyNames(this)) {
315
- const value = this[name];
316
- if (value === null) {
317
- continue;
318
- }
319
- if (value instanceof XFAObject) {
320
- dumped[name] = value[$dump]();
321
- } else if (value instanceof XFAObjectArray) {
322
- if (!value.isEmpty()) {
323
- dumped[name] = value.dump();
324
- }
325
- } else {
326
- dumped[name] = value;
327
- }
328
- }
329
-
330
- return dumped;
331
- }
332
-
333
- [$toStyle]() {
334
- return null;
335
- }
336
-
337
- [$toHTML]() {
338
- return HTMLResult.EMPTY;
339
- }
340
-
341
- *[$getContainedChildren]() {
342
- // This function is overriden in Subform and SubformSet.
343
- for (const node of this[$getChildren]()) {
344
- yield node;
345
- }
346
- }
347
-
348
- *[_filteredChildrenGenerator](filter, include) {
349
- for (const node of this[$getContainedChildren]()) {
350
- if (!filter || include === filter.has(node[$nodeName])) {
351
- const availableSpace = this[$getAvailableSpace]();
352
- const res = node[$toHTML](availableSpace);
353
- if (!res.success) {
354
- this[$extra].failingNode = node;
355
- }
356
- yield res;
357
- }
358
- }
359
- }
360
-
361
- [$flushHTML]() {
362
- return null;
363
- }
364
-
365
- [$addHTML](html, bbox) {
366
- this[$extra].children.push(html);
367
- }
368
-
369
- [$getAvailableSpace]() {}
370
-
371
- [$childrenToHTML]({ filter = null, include = true }) {
372
- if (!this[$extra].generator) {
373
- this[$extra].generator = this[_filteredChildrenGenerator](
374
- filter,
375
- include
376
- );
377
- } else {
378
- const availableSpace = this[$getAvailableSpace]();
379
- const res = this[$extra].failingNode[$toHTML](availableSpace);
380
- if (!res.success) {
381
- return res;
382
- }
383
- if (res.html) {
384
- this[$addHTML](res.html, res.bbox);
385
- }
386
- delete this[$extra].failingNode;
387
- }
388
-
389
- while (true) {
390
- const gen = this[$extra].generator.next();
391
- if (gen.done) {
392
- break;
393
- }
394
- const res = gen.value;
395
- if (!res.success) {
396
- return res;
397
- }
398
- if (res.html) {
399
- this[$addHTML](res.html, res.bbox);
400
- }
401
- }
402
-
403
- this[$extra].generator = null;
404
-
405
- return HTMLResult.EMPTY;
406
- }
407
-
408
- [$setSetAttributes](attributes) {
409
- // Just keep set attributes because it can be used in a proto.
410
- this[_setAttributes] = new Set(Object.keys(attributes));
411
- }
412
-
413
- /**
414
- * Get attribute names which have been set in the proto but not in this.
415
- */
416
- [_getUnsetAttributes](protoAttributes) {
417
- const allAttr = this[_attributeNames];
418
- const setAttr = this[_setAttributes];
419
- return [...protoAttributes].filter(x => allAttr.has(x) && !setAttr.has(x));
420
- }
421
-
422
- /**
423
- * Update the node with properties coming from a prototype and apply
424
- * this function recursivly to all children.
425
- */
426
- [$resolvePrototypes](ids, ancestors = new Set()) {
427
- for (const child of this[_children]) {
428
- child[_resolvePrototypesHelper](ids, ancestors);
429
- }
430
- }
431
-
432
- [_resolvePrototypesHelper](ids, ancestors) {
433
- const proto = this[_getPrototype](ids, ancestors);
434
- if (proto) {
435
- // _applyPrototype will apply $resolvePrototypes with correct ancestors
436
- // to avoid infinite loop.
437
- this[_applyPrototype](proto, ids, ancestors);
438
- } else {
439
- this[$resolvePrototypes](ids, ancestors);
440
- }
441
- }
442
-
443
- [_getPrototype](ids, ancestors) {
444
- const { use, usehref } = this;
445
- if (!use && !usehref) {
446
- return null;
447
- }
448
-
449
- let proto = null;
450
- let somExpression = null;
451
- let id = null;
452
- let ref = use;
453
-
454
- // If usehref and use are non-empty then use usehref.
455
- if (usehref) {
456
- ref = usehref;
457
- // Href can be one of the following:
458
- // - #ID
459
- // - URI#ID
460
- // - #som(expression)
461
- // - URI#som(expression)
462
- // - URI
463
- // For now we don't handle URI other than "." (current document).
464
- if (usehref.startsWith("#som(") && usehref.endsWith(")")) {
465
- somExpression = usehref.slice("#som(".length, usehref.length - 1);
466
- } else if (usehref.startsWith(".#som(") && usehref.endsWith(")")) {
467
- somExpression = usehref.slice(".#som(".length, usehref.length - 1);
468
- } else if (usehref.startsWith("#")) {
469
- id = usehref.slice(1);
470
- } else if (usehref.startsWith(".#")) {
471
- id = usehref.slice(2);
472
- }
473
- } else if (use.startsWith("#")) {
474
- id = use.slice(1);
475
- } else {
476
- somExpression = use;
477
- }
478
-
479
- this.use = this.usehref = "";
480
- if (id) {
481
- proto = ids.get(id);
482
- } else {
483
- proto = searchNode(
484
- ids.get($root),
485
- this,
486
- somExpression,
487
- true /* = dotDotAllowed */,
488
- false /* = useCache */
489
- );
490
- if (proto) {
491
- proto = proto[0];
492
- }
493
- }
494
-
495
- if (!proto) {
496
- warn(`XFA - Invalid prototype reference: ${ref}.`);
497
- return null;
498
- }
499
-
500
- if (proto[$nodeName] !== this[$nodeName]) {
501
- warn(
502
- `XFA - Incompatible prototype: ${proto[$nodeName]} !== ${this[$nodeName]}.`
503
- );
504
- return null;
505
- }
506
-
507
- if (ancestors.has(proto)) {
508
- // We've a cycle so break it.
509
- warn(`XFA - Cycle detected in prototypes use.`);
510
- return null;
511
- }
512
-
513
- ancestors.add(proto);
514
-
515
- // The prototype can have a "use" attribute itself.
516
- const protoProto = proto[_getPrototype](ids, ancestors);
517
- if (protoProto) {
518
- proto[_applyPrototype](protoProto, ids, ancestors);
519
- }
520
-
521
- // The prototype can have a child which itself has a "use" property.
522
- proto[$resolvePrototypes](ids, ancestors);
523
-
524
- ancestors.delete(proto);
525
-
526
- return proto;
527
- }
528
-
529
- [_applyPrototype](proto, ids, ancestors) {
530
- if (ancestors.has(proto)) {
531
- // We've a cycle so break it.
532
- warn(`XFA - Cycle detected in prototypes use.`);
533
- return;
534
- }
535
-
536
- if (!this[$content] && proto[$content]) {
537
- this[$content] = proto[$content];
538
- }
539
-
540
- const newAncestors = new Set(ancestors);
541
- newAncestors.add(proto);
542
-
543
- for (const unsetAttrName of this[_getUnsetAttributes](
544
- proto[_setAttributes]
545
- )) {
546
- this[unsetAttrName] = proto[unsetAttrName];
547
- if (this[_setAttributes]) {
548
- this[_setAttributes].add(unsetAttrName);
549
- }
550
- }
551
-
552
- for (const name of Object.getOwnPropertyNames(this)) {
553
- if (this[_attributeNames].has(name)) {
554
- continue;
555
- }
556
- const value = this[name];
557
- const protoValue = proto[name];
558
-
559
- if (value instanceof XFAObjectArray) {
560
- for (const child of value[_children]) {
561
- child[_resolvePrototypesHelper](ids, ancestors);
562
- }
563
-
564
- for (
565
- let i = value[_children].length, ii = protoValue[_children].length;
566
- i < ii;
567
- i++
568
- ) {
569
- const child = proto[_children][i][$clone]();
570
- if (value.push(child)) {
571
- child[_parent] = this;
572
- this[_children].push(child);
573
- child[_resolvePrototypesHelper](ids, ancestors);
574
- } else {
575
- // No need to continue: other nodes will be rejected.
576
- break;
577
- }
578
- }
579
- continue;
580
- }
581
-
582
- if (value !== null) {
583
- value[$resolvePrototypes](ids, ancestors);
584
- if (protoValue) {
585
- // protoValue must be treated as a prototype for value.
586
- value[_applyPrototype](protoValue, ids, ancestors);
587
- }
588
- continue;
589
- }
590
-
591
- if (protoValue !== null) {
592
- const child = protoValue[$clone]();
593
- child[_parent] = this;
594
- this[name] = child;
595
- this[_children].push(child);
596
- child[_resolvePrototypesHelper](ids, ancestors);
597
- }
598
- }
599
- }
600
-
601
- static [_cloneAttribute](obj) {
602
- if (Array.isArray(obj)) {
603
- return obj.map(x => XFAObject[_cloneAttribute](x));
604
- }
605
- if (typeof obj === "object" && obj !== null) {
606
- return Object.assign({}, obj);
607
- }
608
- return obj;
609
- }
610
-
611
- [$clone]() {
612
- const clone = Object.create(Object.getPrototypeOf(this));
613
- for (const $symbol of Object.getOwnPropertySymbols(this)) {
614
- try {
615
- clone[$symbol] = this[$symbol];
616
- } catch (_) {
617
- shadow(clone, $symbol, this[$symbol]);
618
- }
619
- }
620
- clone[$uid] = `${clone[$nodeName]}${uid++}`;
621
- clone[_children] = [];
622
-
623
- for (const name of Object.getOwnPropertyNames(this)) {
624
- if (this[_attributeNames].has(name)) {
625
- clone[name] = XFAObject[_cloneAttribute](this[name]);
626
- continue;
627
- }
628
- const value = this[name];
629
- if (value instanceof XFAObjectArray) {
630
- clone[name] = new XFAObjectArray(value[_max]);
631
- } else {
632
- clone[name] = null;
633
- }
634
- }
635
-
636
- for (const child of this[_children]) {
637
- const name = child[$nodeName];
638
- const clonedChild = child[$clone]();
639
- clone[_children].push(clonedChild);
640
- clonedChild[_parent] = clone;
641
- if (clone[name] === null) {
642
- clone[name] = clonedChild;
643
- } else {
644
- clone[name][_children].push(clonedChild);
645
- }
646
- }
647
-
648
- return clone;
649
- }
650
-
651
- [$getChildren](name = null) {
652
- if (!name) {
653
- return this[_children];
654
- }
655
-
656
- return this[_children].filter(c => c[$nodeName] === name);
657
- }
658
-
659
- [$getChildrenByClass](name) {
660
- return this[name];
661
- }
662
-
663
- [$getChildrenByName](name, allTransparent, first = true) {
664
- return Array.from(this[$getChildrenByNameIt](name, allTransparent, first));
665
- }
666
-
667
- *[$getChildrenByNameIt](name, allTransparent, first = true) {
668
- if (name === "parent") {
669
- yield this[_parent];
670
- return;
671
- }
672
-
673
- for (const child of this[_children]) {
674
- if (child[$nodeName] === name) {
675
- yield child;
676
- }
677
-
678
- if (child.name === name) {
679
- yield child;
680
- }
681
-
682
- if (allTransparent || child[$isTransparent]()) {
683
- yield* child[$getChildrenByNameIt](name, allTransparent, false);
684
- }
685
- }
686
-
687
- if (first && this[_attributeNames].has(name)) {
688
- yield new XFAAttribute(this, name, this[name]);
689
- }
690
- }
691
- }
692
-
693
- class XFAObjectArray {
694
- constructor(max = Infinity) {
695
- this[_max] = max;
696
- this[_children] = [];
697
- }
698
-
699
- push(child) {
700
- const len = this[_children].length;
701
- if (len <= this[_max]) {
702
- this[_children].push(child);
703
- return true;
704
- }
705
- warn(
706
- `XFA - node "${child[$nodeName]}" accepts no more than ${this[_max]} children`
707
- );
708
- return false;
709
- }
710
-
711
- isEmpty() {
712
- return this[_children].length === 0;
713
- }
714
-
715
- dump() {
716
- return this[_children].length === 1
717
- ? this[_children][0][$dump]()
718
- : this[_children].map(x => x[$dump]());
719
- }
720
-
721
- [$clone]() {
722
- const clone = new XFAObjectArray(this[_max]);
723
- clone[_children] = this[_children].map(c => c[$clone]());
724
- return clone;
725
- }
726
-
727
- get children() {
728
- return this[_children];
729
- }
730
-
731
- clear() {
732
- this[_children].length = 0;
733
- }
734
- }
735
-
736
- class XFAAttribute {
737
- constructor(node, name, value) {
738
- this[_parent] = node;
739
- this[$nodeName] = name;
740
- this[$content] = value;
741
- this[$consumed] = false;
742
- this[$uid] = `attribute${uid++}`;
743
- }
744
-
745
- [$getParent]() {
746
- return this[_parent];
747
- }
748
-
749
- [$isDataValue]() {
750
- return true;
751
- }
752
-
753
- [$getDataValue]() {
754
- return this[$content].trim();
755
- }
756
-
757
- [$setValue](value) {
758
- value = value.value || "";
759
- this[$content] = value.toString();
760
- }
761
-
762
- [$text]() {
763
- return this[$content];
764
- }
765
-
766
- [$isDescendent](parent) {
767
- return this[_parent] === parent || this[_parent][$isDescendent](parent);
768
- }
769
- }
770
-
771
- class XmlObject extends XFAObject {
772
- constructor(nsId, name, attributes = {}) {
773
- super(nsId, name);
774
- this[$content] = "";
775
- this[_dataValue] = null;
776
- if (name !== "#text") {
777
- const map = new Map();
778
- this[_attributes] = map;
779
- for (const [attrName, value] of Object.entries(attributes)) {
780
- map.set(attrName, new XFAAttribute(this, attrName, value));
781
- }
782
- if (attributes.hasOwnProperty($nsAttributes)) {
783
- // XFA attributes.
784
- const dataNode = attributes[$nsAttributes].xfa.dataNode;
785
- if (dataNode !== undefined) {
786
- if (dataNode === "dataGroup") {
787
- this[_dataValue] = false;
788
- } else if (dataNode === "dataValue") {
789
- this[_dataValue] = true;
790
- }
791
- }
792
- }
793
- }
794
- this[$consumed] = false;
795
- }
796
-
797
- [$toString](buf) {
798
- const tagName = this[$nodeName];
799
- if (tagName === "#text") {
800
- buf.push(encodeToXmlString(this[$content]));
801
- return;
802
- }
803
- const prefix = this[$namespaceId] === NS_DATASETS ? "xfa:" : "";
804
- buf.push(`<${prefix}${tagName}`);
805
- for (const [name, value] of this[_attributes].entries()) {
806
- buf.push(` ${name}="${encodeToXmlString(value[$content])}"`);
807
- }
808
- if (this[_dataValue] !== null) {
809
- if (this[_dataValue]) {
810
- buf.push(` xfa:dataNode="dataValue"`);
811
- } else {
812
- buf.push(` xfa:dataNode="dataGroup"`);
813
- }
814
- }
815
- if (!this[$content] && this[_children].length === 0) {
816
- buf.push("/>");
817
- return;
818
- }
819
-
820
- buf.push(">");
821
- if (this[$content]) {
822
- if (typeof this[$content] === "string") {
823
- buf.push(encodeToXmlString(this[$content]));
824
- } else {
825
- this[$content][$toString](buf);
826
- }
827
- } else {
828
- for (const child of this[_children]) {
829
- child[$toString](buf);
830
- }
831
- }
832
- buf.push(`</${prefix}${tagName}>`);
833
- }
834
-
835
- [$onChild](child) {
836
- if (this[$content]) {
837
- const node = new XmlObject(this[$namespaceId], "#text");
838
- this[$appendChild](node);
839
- node[$content] = this[$content];
840
- this[$content] = "";
841
- }
842
- this[$appendChild](child);
843
- return true;
844
- }
845
-
846
- [$onText](str) {
847
- this[$content] += str;
848
- }
849
-
850
- [$finalize]() {
851
- if (this[$content] && this[_children].length > 0) {
852
- const node = new XmlObject(this[$namespaceId], "#text");
853
- this[$appendChild](node);
854
- node[$content] = this[$content];
855
- delete this[$content];
856
- }
857
- }
858
-
859
- [$toHTML]() {
860
- if (this[$nodeName] === "#text") {
861
- return HTMLResult.success({
862
- name: "#text",
863
- value: this[$content],
864
- });
865
- }
866
-
867
- return HTMLResult.EMPTY;
868
- }
869
-
870
- [$getChildren](name = null) {
871
- if (!name) {
872
- return this[_children];
873
- }
874
-
875
- return this[_children].filter(c => c[$nodeName] === name);
876
- }
877
-
878
- [$getAttributes]() {
879
- return this[_attributes];
880
- }
881
-
882
- [$getChildrenByClass](name) {
883
- const value = this[_attributes].get(name);
884
- if (value !== undefined) {
885
- return value;
886
- }
887
- return this[$getChildren](name);
888
- }
889
-
890
- *[$getChildrenByNameIt](name, allTransparent) {
891
- const value = this[_attributes].get(name);
892
- if (value) {
893
- yield value;
894
- }
895
-
896
- for (const child of this[_children]) {
897
- if (child[$nodeName] === name) {
898
- yield child;
899
- }
900
-
901
- if (allTransparent) {
902
- yield* child[$getChildrenByNameIt](name, allTransparent);
903
- }
904
- }
905
- }
906
-
907
- *[$getAttributeIt](name, skipConsumed) {
908
- const value = this[_attributes].get(name);
909
- if (value && (!skipConsumed || !value[$consumed])) {
910
- yield value;
911
- }
912
- for (const child of this[_children]) {
913
- yield* child[$getAttributeIt](name, skipConsumed);
914
- }
915
- }
916
-
917
- *[$getRealChildrenByNameIt](name, allTransparent, skipConsumed) {
918
- for (const child of this[_children]) {
919
- if (child[$nodeName] === name && (!skipConsumed || !child[$consumed])) {
920
- yield child;
921
- }
922
-
923
- if (allTransparent) {
924
- yield* child[$getRealChildrenByNameIt](
925
- name,
926
- allTransparent,
927
- skipConsumed
928
- );
929
- }
930
- }
931
- }
932
-
933
- [$isDataValue]() {
934
- if (this[_dataValue] === null) {
935
- return (
936
- this[_children].length === 0 ||
937
- this[_children][0][$namespaceId] === NamespaceIds.xhtml.id
938
- );
939
- }
940
- return this[_dataValue];
941
- }
942
-
943
- [$getDataValue]() {
944
- if (this[_dataValue] === null) {
945
- if (this[_children].length === 0) {
946
- return this[$content].trim();
947
- }
948
- if (this[_children][0][$namespaceId] === NamespaceIds.xhtml.id) {
949
- return this[_children][0][$text]().trim();
950
- }
951
- return null;
952
- }
953
- return this[$content].trim();
954
- }
955
-
956
- [$setValue](value) {
957
- value = value.value || "";
958
- this[$content] = value.toString();
959
- }
960
-
961
- [$dump]() {
962
- const dumped = Object.create(null);
963
- if (this[$content]) {
964
- dumped.$content = this[$content];
965
- }
966
- dumped.$name = this[$nodeName];
967
-
968
- dumped.children = [];
969
- for (const child of this[_children]) {
970
- dumped.children.push(child[$dump]());
971
- }
972
-
973
- dumped.attributes = Object.create(null);
974
- for (const [name, value] of this[_attributes]) {
975
- dumped.attributes[name] = value[$content];
976
- }
977
-
978
- return dumped;
979
- }
980
- }
981
-
982
- class ContentObject extends XFAObject {
983
- constructor(nsId, name) {
984
- super(nsId, name);
985
- this[$content] = "";
986
- }
987
-
988
- [$onText](text) {
989
- this[$content] += text;
990
- }
991
-
992
- [$finalize]() {}
993
- }
994
-
995
- class OptionObject extends ContentObject {
996
- constructor(nsId, name, options) {
997
- super(nsId, name);
998
- this[_options] = options;
999
- }
1000
-
1001
- [$finalize]() {
1002
- this[$content] = getKeyword({
1003
- data: this[$content],
1004
- defaultValue: this[_options][0],
1005
- validate: k => this[_options].includes(k),
1006
- });
1007
- }
1008
-
1009
- [$clean](builder) {
1010
- super[$clean](builder);
1011
- delete this[_options];
1012
- }
1013
- }
1014
-
1015
- class StringObject extends ContentObject {
1016
- [$finalize]() {
1017
- this[$content] = this[$content].trim();
1018
- }
1019
- }
1020
-
1021
- class IntegerObject extends ContentObject {
1022
- constructor(nsId, name, defaultValue, validator) {
1023
- super(nsId, name);
1024
- this[_defaultValue] = defaultValue;
1025
- this[_validator] = validator;
1026
- }
1027
-
1028
- [$finalize]() {
1029
- this[$content] = getInteger({
1030
- data: this[$content],
1031
- defaultValue: this[_defaultValue],
1032
- validate: this[_validator],
1033
- });
1034
- }
1035
-
1036
- [$clean](builder) {
1037
- super[$clean](builder);
1038
- delete this[_defaultValue];
1039
- delete this[_validator];
1040
- }
1041
- }
1042
-
1043
- class Option01 extends IntegerObject {
1044
- constructor(nsId, name) {
1045
- super(nsId, name, 0, n => n === 1);
1046
- }
1047
- }
1048
-
1049
- class Option10 extends IntegerObject {
1050
- constructor(nsId, name) {
1051
- super(nsId, name, 1, n => n === 0);
1052
- }
1053
- }
1054
-
1055
- export {
1056
- $acceptWhitespace,
1057
- $addHTML,
1058
- $appendChild,
1059
- $childrenToHTML,
1060
- $clean,
1061
- $cleanPage,
1062
- $cleanup,
1063
- $clone,
1064
- $consumed,
1065
- $content,
1066
- $data,
1067
- $dump,
1068
- $extra,
1069
- $finalize,
1070
- $flushHTML,
1071
- $getAttributeIt,
1072
- $getAttributes,
1073
- $getAvailableSpace,
1074
- $getChildren,
1075
- $getChildrenByClass,
1076
- $getChildrenByName,
1077
- $getChildrenByNameIt,
1078
- $getContainedChildren,
1079
- $getDataValue,
1080
- $getExtra,
1081
- $getNextPage,
1082
- $getParent,
1083
- $getRealChildrenByNameIt,
1084
- $getSubformParent,
1085
- $getTemplateRoot,
1086
- $globalData,
1087
- $hasSettableValue,
1088
- $ids,
1089
- $indexOf,
1090
- $insertAt,
1091
- $isBindable,
1092
- $isCDATAXml,
1093
- $isDataValue,
1094
- $isDescendent,
1095
- $isNsAgnostic,
1096
- $isSplittable,
1097
- $isThereMoreWidth,
1098
- $isTransparent,
1099
- $isUsable,
1100
- $namespaceId,
1101
- $nodeName,
1102
- $nsAttributes,
1103
- $onChild,
1104
- $onChildCheck,
1105
- $onText,
1106
- $pushGlyphs,
1107
- $removeChild,
1108
- $resolvePrototypes,
1109
- $root,
1110
- $searchNode,
1111
- $setId,
1112
- $setSetAttributes,
1113
- $setValue,
1114
- $tabIndex,
1115
- $text,
1116
- $toHTML,
1117
- $toString,
1118
- $toStyle,
1119
- $uid,
1120
- ContentObject,
1121
- IntegerObject,
1122
- Option01,
1123
- Option10,
1124
- OptionObject,
1125
- StringObject,
1126
- XFAAttribute,
1127
- XFAObject,
1128
- XFAObjectArray,
1129
- XmlObject,
1130
- };