@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +1 -1
  2. package/package.json +42 -26
  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/l10n_utils.js +140 -0
  6. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  7. package/{src/display → pdfjs/dist}/network.js +149 -87
  8. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  9. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  10. package/pdfjs/dist/pdf.js +12778 -0
  11. package/pdfjs/dist/pdf_link_service.js +638 -0
  12. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  13. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  14. package/pdfjs/dist/pdf_viewer.js +3598 -0
  15. package/pdfjs/dist/ui_utils.js +1033 -0
  16. package/{src/shared → pdfjs/dist}/util.js +301 -287
  17. package/pdfjs/dist/worker.js +62813 -0
  18. package/src/vcf-pdf-viewer.js +98 -46
  19. package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
  20. package/theme/material/vcf-pdf-viewer-styles.js +4 -4
  21. package/theme/material/vcf-pdf-viewer.js +2 -2
  22. package/src/core/.eslintrc +0 -13
  23. package/src/core/annotation.js +0 -2948
  24. package/src/core/arithmetic_decoder.js +0 -182
  25. package/src/core/ascii_85_stream.js +0 -98
  26. package/src/core/ascii_hex_stream.js +0 -79
  27. package/src/core/base_stream.js +0 -110
  28. package/src/core/bidi.js +0 -438
  29. package/src/core/calibri_factors.js +0 -308
  30. package/src/core/catalog.js +0 -1459
  31. package/src/core/ccitt.js +0 -1062
  32. package/src/core/ccitt_stream.js +0 -60
  33. package/src/core/cff_font.js +0 -116
  34. package/src/core/cff_parser.js +0 -1949
  35. package/src/core/charsets.js +0 -119
  36. package/src/core/chunked_stream.js +0 -557
  37. package/src/core/cmap.js +0 -1039
  38. package/src/core/colorspace.js +0 -1533
  39. package/src/core/core_utils.js +0 -464
  40. package/src/core/crypto.js +0 -1900
  41. package/src/core/decode_stream.js +0 -170
  42. package/src/core/decrypt_stream.js +0 -59
  43. package/src/core/default_appearance.js +0 -99
  44. package/src/core/document.js +0 -1456
  45. package/src/core/encodings.js +0 -301
  46. package/src/core/evaluator.js +0 -4601
  47. package/src/core/file_spec.js +0 -108
  48. package/src/core/flate_stream.js +0 -402
  49. package/src/core/font_renderer.js +0 -882
  50. package/src/core/fonts.js +0 -3260
  51. package/src/core/fonts_utils.js +0 -221
  52. package/src/core/function.js +0 -1257
  53. package/src/core/glyf.js +0 -706
  54. package/src/core/glyphlist.js +0 -4558
  55. package/src/core/helvetica_factors.js +0 -353
  56. package/src/core/image.js +0 -802
  57. package/src/core/image_utils.js +0 -291
  58. package/src/core/jbig2.js +0 -2572
  59. package/src/core/jbig2_stream.js +0 -73
  60. package/src/core/jpeg_stream.js +0 -105
  61. package/src/core/jpg.js +0 -1416
  62. package/src/core/jpx.js +0 -2343
  63. package/src/core/jpx_stream.js +0 -87
  64. package/src/core/liberationsans_widths.js +0 -221
  65. package/src/core/lzw_stream.js +0 -150
  66. package/src/core/metadata_parser.js +0 -146
  67. package/src/core/metrics.js +0 -2970
  68. package/src/core/murmurhash3.js +0 -139
  69. package/src/core/myriadpro_factors.js +0 -290
  70. package/src/core/name_number_tree.js +0 -153
  71. package/src/core/object_loader.js +0 -149
  72. package/src/core/opentype_file_builder.js +0 -154
  73. package/src/core/operator_list.js +0 -734
  74. package/src/core/parser.js +0 -1416
  75. package/src/core/pattern.js +0 -985
  76. package/src/core/pdf_manager.js +0 -217
  77. package/src/core/predictor_stream.js +0 -238
  78. package/src/core/primitives.js +0 -402
  79. package/src/core/ps_parser.js +0 -272
  80. package/src/core/run_length_stream.js +0 -61
  81. package/src/core/segoeui_factors.js +0 -308
  82. package/src/core/standard_fonts.js +0 -817
  83. package/src/core/stream.js +0 -103
  84. package/src/core/struct_tree.js +0 -335
  85. package/src/core/to_unicode_map.js +0 -103
  86. package/src/core/type1_font.js +0 -421
  87. package/src/core/type1_parser.js +0 -776
  88. package/src/core/unicode.js +0 -1649
  89. package/src/core/worker.js +0 -848
  90. package/src/core/worker_stream.js +0 -135
  91. package/src/core/writer.js +0 -278
  92. package/src/core/xfa/bind.js +0 -652
  93. package/src/core/xfa/builder.js +0 -207
  94. package/src/core/xfa/config.js +0 -1926
  95. package/src/core/xfa/connection_set.js +0 -202
  96. package/src/core/xfa/data.js +0 -82
  97. package/src/core/xfa/datasets.js +0 -76
  98. package/src/core/xfa/factory.js +0 -111
  99. package/src/core/xfa/fonts.js +0 -181
  100. package/src/core/xfa/formcalc_lexer.js +0 -385
  101. package/src/core/xfa/formcalc_parser.js +0 -1340
  102. package/src/core/xfa/html_utils.js +0 -639
  103. package/src/core/xfa/layout.js +0 -383
  104. package/src/core/xfa/locale_set.js +0 -345
  105. package/src/core/xfa/namespaces.js +0 -81
  106. package/src/core/xfa/parser.js +0 -184
  107. package/src/core/xfa/setup.js +0 -38
  108. package/src/core/xfa/signature.js +0 -40
  109. package/src/core/xfa/som.js +0 -338
  110. package/src/core/xfa/stylesheet.js +0 -40
  111. package/src/core/xfa/template.js +0 -6260
  112. package/src/core/xfa/text.js +0 -290
  113. package/src/core/xfa/unknown.js +0 -29
  114. package/src/core/xfa/utils.js +0 -217
  115. package/src/core/xfa/xdp.js +0 -59
  116. package/src/core/xfa/xfa_object.js +0 -1130
  117. package/src/core/xfa/xhtml.js +0 -543
  118. package/src/core/xfa_fonts.js +0 -208
  119. package/src/core/xml_parser.js +0 -507
  120. package/src/core/xref.js +0 -899
  121. package/src/display/annotation_layer.js +0 -2107
  122. package/src/display/annotation_storage.js +0 -113
  123. package/src/display/api.js +0 -3292
  124. package/src/display/base_factory.js +0 -180
  125. package/src/display/canvas.js +0 -2828
  126. package/src/display/font_loader.js +0 -484
  127. package/src/display/metadata.js +0 -41
  128. package/src/display/network_utils.js +0 -100
  129. package/src/display/node_utils.js +0 -83
  130. package/src/display/optional_content_config.js +0 -189
  131. package/src/display/pattern_helper.js +0 -659
  132. package/src/display/svg.js +0 -1709
  133. package/src/display/text_layer.js +0 -847
  134. package/src/display/transport_stream.js +0 -303
  135. package/src/display/worker_options.js +0 -40
  136. package/src/display/xfa_layer.js +0 -204
  137. package/src/doc_helper.js +0 -25
  138. package/src/images/logo.svg +0 -41
  139. package/src/interfaces.js +0 -169
  140. package/src/license_header.js +0 -14
  141. package/src/license_header_libre.js +0 -21
  142. package/src/pdf.image_decoders.js +0 -46
  143. package/src/pdf.js +0 -146
  144. package/src/pdf.sandbox.external.js +0 -181
  145. package/src/pdf.sandbox.js +0 -151
  146. package/src/pdf.scripting.js +0 -25
  147. package/src/pdf.worker.entry.js +0 -19
  148. package/src/pdf.worker.js +0 -23
  149. package/src/scripting_api/aform.js +0 -608
  150. package/src/scripting_api/app.js +0 -621
  151. package/src/scripting_api/color.js +0 -129
  152. package/src/scripting_api/common.js +0 -58
  153. package/src/scripting_api/console.js +0 -38
  154. package/src/scripting_api/constants.js +0 -208
  155. package/src/scripting_api/doc.js +0 -1195
  156. package/src/scripting_api/error.js +0 -23
  157. package/src/scripting_api/event.js +0 -232
  158. package/src/scripting_api/field.js +0 -620
  159. package/src/scripting_api/fullscreen.js +0 -145
  160. package/src/scripting_api/initialization.js +0 -223
  161. package/src/scripting_api/pdf_object.js +0 -24
  162. package/src/scripting_api/print_params.js +0 -146
  163. package/src/scripting_api/proxy.js +0 -139
  164. package/src/scripting_api/thermometer.js +0 -69
  165. package/src/scripting_api/util.js +0 -581
  166. package/src/shared/.eslintrc +0 -13
  167. package/src/shared/cffStandardStrings.js +0 -311
  168. package/src/shared/compatibility.js +0 -114
  169. package/src/shared/fonts_utils.js +0 -429
  170. package/src/shared/is_node.js +0 -27
  171. package/src/shared/scripting_utils.js +0 -85
  172. package/src/worker_loader.js +0 -32
@@ -1,81 +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
- const $buildXFAObject = Symbol();
17
-
18
- const NamespaceIds = {
19
- config: {
20
- id: 0,
21
- check: ns => ns.startsWith("http://www.xfa.org/schema/xci/"),
22
- },
23
- connectionSet: {
24
- id: 1,
25
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-connection-set/"),
26
- },
27
- datasets: {
28
- id: 2,
29
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-data/"),
30
- },
31
- form: {
32
- id: 3,
33
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-form/"),
34
- },
35
- localeSet: {
36
- id: 4,
37
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-locale-set/"),
38
- },
39
- pdf: {
40
- id: 5,
41
- check: ns => ns === "http://ns.adobe.com/xdp/pdf/",
42
- },
43
- signature: {
44
- id: 6,
45
- check: ns => ns === "http://www.w3.org/2000/09/xmldsig#",
46
- },
47
- sourceSet: {
48
- id: 7,
49
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-source-set/"),
50
- },
51
- stylesheet: {
52
- id: 8,
53
- check: ns => ns === "http://www.w3.org/1999/XSL/Transform",
54
- },
55
- template: {
56
- id: 9,
57
- check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-template/"),
58
- },
59
- xdc: {
60
- id: 10,
61
- check: ns => ns.startsWith("http://www.xfa.org/schema/xdc/"),
62
- },
63
- xdp: {
64
- id: 11,
65
- check: ns => ns === "http://ns.adobe.com/xdp/",
66
- },
67
- xfdf: {
68
- id: 12,
69
- check: ns => ns === "http://ns.adobe.com/xfdf/",
70
- },
71
- xhtml: {
72
- id: 13,
73
- check: ns => ns === "http://www.w3.org/1999/xhtml",
74
- },
75
- xmpmeta: {
76
- id: 14,
77
- check: ns => ns === "http://ns.adobe.com/xmpmeta/",
78
- },
79
- };
80
-
81
- export { $buildXFAObject, NamespaceIds };
@@ -1,184 +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
- $acceptWhitespace,
18
- $clean,
19
- $content,
20
- $finalize,
21
- $globalData,
22
- $isCDATAXml,
23
- $nsAttributes,
24
- $onChild,
25
- $onText,
26
- $setId,
27
- } from "./xfa_object.js";
28
- import { XMLParserBase, XMLParserErrorCode } from "../xml_parser.js";
29
- import { Builder } from "./builder.js";
30
- import { warn } from "../../shared/util.js";
31
-
32
- class XFAParser extends XMLParserBase {
33
- constructor() {
34
- super();
35
- this._builder = new Builder();
36
- this._stack = [];
37
- this._globalData = {
38
- usedTypefaces: new Set(),
39
- };
40
- this._ids = new Map();
41
- this._current = this._builder.buildRoot(this._ids);
42
- this._errorCode = XMLParserErrorCode.NoError;
43
- this._whiteRegex = /^\s+$/;
44
- this._nbsps = /\xa0+/g;
45
- }
46
-
47
- parse(data) {
48
- this.parseXml(data);
49
-
50
- if (this._errorCode !== XMLParserErrorCode.NoError) {
51
- return undefined;
52
- }
53
-
54
- this._current[$finalize]();
55
-
56
- return this._current.element;
57
- }
58
-
59
- onText(text) {
60
- // Normally by definition a &nbsp is unbreakable
61
- // but in real life Acrobat can break strings on &nbsp.
62
- text = text.replace(this._nbsps, match => match.slice(1) + " ");
63
- if (this._current[$acceptWhitespace]()) {
64
- this._current[$onText](text);
65
- return;
66
- }
67
-
68
- if (this._whiteRegex.test(text)) {
69
- return;
70
- }
71
- this._current[$onText](text.trim());
72
- }
73
-
74
- onCdata(text) {
75
- this._current[$onText](text);
76
- }
77
-
78
- _mkAttributes(attributes, tagName) {
79
- // Transform attributes into an object and get out
80
- // namespaces information.
81
- let namespace = null;
82
- let prefixes = null;
83
- const attributeObj = Object.create({});
84
- for (const { name, value } of attributes) {
85
- if (name === "xmlns") {
86
- if (!namespace) {
87
- namespace = value;
88
- } else {
89
- warn(`XFA - multiple namespace definition in <${tagName}>`);
90
- }
91
- } else if (name.startsWith("xmlns:")) {
92
- const prefix = name.substring("xmlns:".length);
93
- if (!prefixes) {
94
- prefixes = [];
95
- }
96
- prefixes.push({ prefix, value });
97
- } else {
98
- const i = name.indexOf(":");
99
- if (i === -1) {
100
- attributeObj[name] = value;
101
- } else {
102
- // Attributes can have their own namespace.
103
- // For example in data, we can have <foo xfa:dataNode="dataGroup"/>
104
- let nsAttrs = attributeObj[$nsAttributes];
105
- if (!nsAttrs) {
106
- nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
107
- }
108
- const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
109
- let attrs = nsAttrs[ns];
110
- if (!attrs) {
111
- attrs = nsAttrs[ns] = Object.create(null);
112
- }
113
- attrs[attrName] = value;
114
- }
115
- }
116
- }
117
-
118
- return [namespace, prefixes, attributeObj];
119
- }
120
-
121
- _getNameAndPrefix(name, nsAgnostic) {
122
- const i = name.indexOf(":");
123
- if (i === -1) {
124
- return [name, null];
125
- }
126
- return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)];
127
- }
128
-
129
- onBeginElement(tagName, attributes, isEmpty) {
130
- const [namespace, prefixes, attributesObj] = this._mkAttributes(
131
- attributes,
132
- tagName
133
- );
134
- const [name, nsPrefix] = this._getNameAndPrefix(
135
- tagName,
136
- this._builder.isNsAgnostic()
137
- );
138
- const node = this._builder.build({
139
- nsPrefix,
140
- name,
141
- attributes: attributesObj,
142
- namespace,
143
- prefixes,
144
- });
145
- node[$globalData] = this._globalData;
146
-
147
- if (isEmpty) {
148
- // No children: just push the node into its parent.
149
- node[$finalize]();
150
- if (this._current[$onChild](node)) {
151
- node[$setId](this._ids);
152
- }
153
- node[$clean](this._builder);
154
- return;
155
- }
156
-
157
- this._stack.push(this._current);
158
- this._current = node;
159
- }
160
-
161
- onEndElement(name) {
162
- const node = this._current;
163
- if (node[$isCDATAXml]() && typeof node[$content] === "string") {
164
- const parser = new XFAParser();
165
- parser._globalData = this._globalData;
166
- const root = parser.parse(node[$content]);
167
- node[$content] = null;
168
- node[$onChild](root);
169
- }
170
-
171
- node[$finalize]();
172
- this._current = this._stack.pop();
173
- if (this._current[$onChild](node)) {
174
- node[$setId](this._ids);
175
- }
176
- node[$clean](this._builder);
177
- }
178
-
179
- onError(code) {
180
- this._errorCode = code;
181
- }
182
- }
183
-
184
- export { XFAParser };
@@ -1,38 +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 { ConfigNamespace } from "./config.js";
17
- import { ConnectionSetNamespace } from "./connection_set.js";
18
- import { DatasetsNamespace } from "./datasets.js";
19
- import { LocaleSetNamespace } from "./locale_set.js";
20
- import { SignatureNamespace } from "./signature.js";
21
- import { StylesheetNamespace } from "./stylesheet.js";
22
- import { TemplateNamespace } from "./template.js";
23
- import { XdpNamespace } from "./xdp.js";
24
- import { XhtmlNamespace } from "./xhtml.js";
25
-
26
- const NamespaceSetUp = {
27
- config: ConfigNamespace,
28
- connection: ConnectionSetNamespace,
29
- datasets: DatasetsNamespace,
30
- localeSet: LocaleSetNamespace,
31
- signature: SignatureNamespace,
32
- stylesheet: StylesheetNamespace,
33
- template: TemplateNamespace,
34
- xdp: XdpNamespace,
35
- xhtml: XhtmlNamespace,
36
- };
37
-
38
- export { NamespaceSetUp };
@@ -1,40 +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 { XFAObject } from "./xfa_object.js";
18
-
19
- const SIGNATURE_NS_ID = NamespaceIds.signature.id;
20
-
21
- class Signature extends XFAObject {
22
- constructor(attributes) {
23
- super(SIGNATURE_NS_ID, "signature", /* hasChildren = */ true);
24
- }
25
- }
26
-
27
- class SignatureNamespace {
28
- static [$buildXFAObject](name, attributes) {
29
- if (SignatureNamespace.hasOwnProperty(name)) {
30
- return SignatureNamespace[name](attributes);
31
- }
32
- return undefined;
33
- }
34
-
35
- static signature(attributes) {
36
- return new Signature(attributes);
37
- }
38
- }
39
-
40
- export { SignatureNamespace };
@@ -1,338 +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
- $getChildrenByClass,
19
- $getChildrenByName,
20
- $getParent,
21
- $namespaceId,
22
- XFAObject,
23
- XFAObjectArray,
24
- XmlObject,
25
- } from "./xfa_object.js";
26
- import { warn } from "../../shared/util.js";
27
-
28
- const namePattern = /^[^.[]+/;
29
- const indexPattern = /^[^\]]+/;
30
- const operators = {
31
- dot: 0,
32
- dotDot: 1,
33
- dotHash: 2,
34
- dotBracket: 3,
35
- dotParen: 4,
36
- };
37
-
38
- const shortcuts = new Map([
39
- ["$data", (root, current) => root.datasets.data],
40
- ["$template", (root, current) => root.template],
41
- ["$connectionSet", (root, current) => root.connectionSet],
42
- ["$form", (root, current) => root.form],
43
- ["$layout", (root, current) => root.layout],
44
- ["$host", (root, current) => root.host],
45
- ["$dataWindow", (root, current) => root.dataWindow],
46
- ["$event", (root, current) => root.event],
47
- ["!", (root, current) => root.datasets],
48
- ["$xfa", (root, current) => root],
49
- ["xfa", (root, current) => root],
50
- ["$", (root, current) => current],
51
- ]);
52
-
53
- const somCache = new WeakMap();
54
-
55
- function parseIndex(index) {
56
- index = index.trim();
57
- if (index === "*") {
58
- return Infinity;
59
- }
60
- return parseInt(index, 10) || 0;
61
- }
62
-
63
- // For now expressions containaing .[...] or .(...) are not
64
- // evaluated so don't parse them.
65
- // TODO: implement that stuff and the remove the noExpr param.
66
- function parseExpression(expr, dotDotAllowed, noExpr = true) {
67
- let match = expr.match(namePattern);
68
- if (!match) {
69
- return null;
70
- }
71
-
72
- let [name] = match;
73
- const parsed = [
74
- {
75
- name,
76
- cacheName: "." + name,
77
- index: 0,
78
- js: null,
79
- formCalc: null,
80
- operator: operators.dot,
81
- },
82
- ];
83
-
84
- let pos = name.length;
85
-
86
- while (pos < expr.length) {
87
- const spos = pos;
88
- const char = expr.charAt(pos++);
89
- if (char === "[") {
90
- match = expr.slice(pos).match(indexPattern);
91
- if (!match) {
92
- warn("XFA - Invalid index in SOM expression");
93
- return null;
94
- }
95
- parsed[parsed.length - 1].index = parseIndex(match[0]);
96
- pos += match[0].length + 1;
97
- continue;
98
- }
99
-
100
- let operator;
101
- switch (expr.charAt(pos)) {
102
- case ".":
103
- if (!dotDotAllowed) {
104
- return null;
105
- }
106
- pos++;
107
- operator = operators.dotDot;
108
- break;
109
- case "#":
110
- pos++;
111
- operator = operators.dotHash;
112
- break;
113
- case "[":
114
- if (noExpr) {
115
- warn(
116
- "XFA - SOM expression contains a FormCalc subexpression which is not supported for now."
117
- );
118
- return null;
119
- }
120
- // TODO: FormCalc expression so need to use the parser
121
- operator = operators.dotBracket;
122
- break;
123
- case "(":
124
- if (noExpr) {
125
- warn(
126
- "XFA - SOM expression contains a JavaScript subexpression which is not supported for now."
127
- );
128
- return null;
129
- }
130
- // TODO:
131
- // Javascript expression: should be a boolean operation with a path
132
- // so maybe we can have our own parser for that stuff or
133
- // maybe use the formcalc one.
134
- operator = operators.dotParen;
135
- break;
136
- default:
137
- operator = operators.dot;
138
- break;
139
- }
140
-
141
- match = expr.slice(pos).match(namePattern);
142
- if (!match) {
143
- break;
144
- }
145
-
146
- [name] = match;
147
- pos += name.length;
148
- parsed.push({
149
- name,
150
- cacheName: expr.slice(spos, pos),
151
- operator,
152
- index: 0,
153
- js: null,
154
- formCalc: null,
155
- });
156
- }
157
- return parsed;
158
- }
159
-
160
- function searchNode(
161
- root,
162
- container,
163
- expr,
164
- dotDotAllowed = true,
165
- useCache = true
166
- ) {
167
- const parsed = parseExpression(expr, dotDotAllowed);
168
- if (!parsed) {
169
- return null;
170
- }
171
-
172
- const fn = shortcuts.get(parsed[0].name);
173
- let i = 0;
174
- let isQualified;
175
- if (fn) {
176
- isQualified = true;
177
- root = [fn(root, container)];
178
- i = 1;
179
- } else {
180
- isQualified = container === null;
181
- root = [container || root];
182
- }
183
-
184
- for (let ii = parsed.length; i < ii; i++) {
185
- const { name, cacheName, operator, index } = parsed[i];
186
- const nodes = [];
187
- for (const node of root) {
188
- if (!(node instanceof XFAObject)) {
189
- continue;
190
- }
191
-
192
- let children, cached;
193
-
194
- if (useCache) {
195
- cached = somCache.get(node);
196
- if (!cached) {
197
- cached = new Map();
198
- somCache.set(node, cached);
199
- }
200
- children = cached.get(cacheName);
201
- }
202
-
203
- if (!children) {
204
- switch (operator) {
205
- case operators.dot:
206
- children = node[$getChildrenByName](name, false);
207
- break;
208
- case operators.dotDot:
209
- children = node[$getChildrenByName](name, true);
210
- break;
211
- case operators.dotHash:
212
- children = node[$getChildrenByClass](name);
213
- if (children instanceof XFAObjectArray) {
214
- children = children.children;
215
- } else {
216
- children = [children];
217
- }
218
- break;
219
- default:
220
- break;
221
- }
222
- if (useCache) {
223
- cached.set(cacheName, children);
224
- }
225
- }
226
-
227
- if (children.length > 0) {
228
- nodes.push(children);
229
- }
230
- }
231
-
232
- if (nodes.length === 0 && !isQualified && i === 0) {
233
- // We've an unqualified expression and we didn't find anything
234
- // so look at container and siblings of container and so on.
235
- // http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=114
236
- const parent = container[$getParent]();
237
- container = parent;
238
- if (!container) {
239
- return null;
240
- }
241
- i = -1;
242
- root = [container];
243
- continue;
244
- }
245
-
246
- if (isFinite(index)) {
247
- root = nodes.filter(node => index < node.length).map(node => node[index]);
248
- } else {
249
- root = nodes.reduce((acc, node) => acc.concat(node), []);
250
- }
251
- }
252
-
253
- if (root.length === 0) {
254
- return null;
255
- }
256
-
257
- return root;
258
- }
259
-
260
- function createNodes(root, path) {
261
- let node = null;
262
- for (const { name, index } of path) {
263
- for (let i = 0, ii = !isFinite(index) ? 0 : index; i <= ii; i++) {
264
- node = new XmlObject(root[$namespaceId], name);
265
- root[$appendChild](node);
266
- }
267
-
268
- root = node;
269
- }
270
- return node;
271
- }
272
-
273
- function createDataNode(root, container, expr) {
274
- const parsed = parseExpression(expr);
275
- if (!parsed) {
276
- return null;
277
- }
278
-
279
- if (parsed.some(x => x.operator === operators.dotDot)) {
280
- return null;
281
- }
282
-
283
- const fn = shortcuts.get(parsed[0].name);
284
- let i = 0;
285
- if (fn) {
286
- root = fn(root, container);
287
- i = 1;
288
- } else {
289
- root = container || root;
290
- }
291
-
292
- for (let ii = parsed.length; i < ii; i++) {
293
- const { name, operator, index } = parsed[i];
294
- if (!isFinite(index)) {
295
- parsed[i].index = 0;
296
- return createNodes(root, parsed.slice(i));
297
- }
298
-
299
- let children;
300
- switch (operator) {
301
- case operators.dot:
302
- children = root[$getChildrenByName](name, false);
303
- break;
304
- case operators.dotDot:
305
- children = root[$getChildrenByName](name, true);
306
- break;
307
- case operators.dotHash:
308
- children = root[$getChildrenByClass](name);
309
- if (children instanceof XFAObjectArray) {
310
- children = children.children;
311
- } else {
312
- children = [children];
313
- }
314
- break;
315
- default:
316
- break;
317
- }
318
-
319
- if (children.length === 0) {
320
- return createNodes(root, parsed.slice(i));
321
- }
322
-
323
- if (index < children.length) {
324
- const child = children[index];
325
- if (!(child instanceof XFAObject)) {
326
- warn(`XFA - Cannot create a node.`);
327
- return null;
328
- }
329
- root = child;
330
- } else {
331
- parsed[i].index = index - children.length;
332
- return createNodes(root, parsed.slice(i));
333
- }
334
- }
335
- return null;
336
- }
337
-
338
- export { createDataNode, searchNode };