@syzlm/ofdparser 0.0.1

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 (213) hide show
  1. package/.babelrc +14 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +18 -0
  4. package/.prettierrc.json +9 -0
  5. package/dist/OFD.d.ts +8 -0
  6. package/dist/Pages.d.ts +7 -0
  7. package/dist/RootDocumnet.d.ts +1 -0
  8. package/dist/bundle.cjs.js +64123 -0
  9. package/dist/bundle.esm.js +64115 -0
  10. package/dist/bundle.iife.js +14743 -0
  11. package/dist/bundle.umd.js +64045 -0
  12. package/dist/constant/index.d.ts +7 -0
  13. package/dist/constant.d.ts +6 -0
  14. package/dist/core/ofd-core/Annotations/AnnotationsXml.d.ts +16 -0
  15. package/dist/core/ofd-core/Asn.1Utils.d.ts +47 -0
  16. package/dist/core/ofd-core/Documents/DocumentResXml.d.ts +15 -0
  17. package/dist/core/ofd-core/Documents/DocumnetXml.d.ts +25 -0
  18. package/dist/core/ofd-core/Documents/PublicResXml.d.ts +15 -0
  19. package/dist/core/ofd-core/OFDElement.d.ts +232 -0
  20. package/dist/core/ofd-core/Ofd/OFDXml.d.ts +19 -0
  21. package/dist/core/ofd-core/Pages/PageXml.d.ts +20 -0
  22. package/dist/core/ofd-core/Signatures/Signatures.d.ts +20 -0
  23. package/dist/core/ofd-core/TemplatePages/TemplatePages.d.ts +20 -0
  24. package/dist/core/ofd-core/constant.d.ts +29 -0
  25. package/dist/core/ofd-core/utils.d.ts +21 -0
  26. package/dist/dicom/dicom.d.ts +15 -0
  27. package/dist/dicom/index.d.ts +1 -0
  28. package/dist/errors/ErrorHandle.d.ts +6 -0
  29. package/dist/errors/ErrorMsg.d.ts +16 -0
  30. package/dist/errors/FetchErrors.d.ts +4 -0
  31. package/dist/errors/MimeError.d.ts +4 -0
  32. package/dist/errors/OFDErrors.d.ts +4 -0
  33. package/dist/errors/UnzipErrors.d.ts +4 -0
  34. package/dist/errors/XmlErrors.d.ts +4 -0
  35. package/dist/errors/error-msg.d.ts +9 -0
  36. package/dist/es.d.ts +2 -0
  37. package/dist/index.d.ts +6 -0
  38. package/dist/lib/ParseFile.d.ts +7 -0
  39. package/dist/lib/UnitCoversion.d.ts +31 -0
  40. package/dist/lib/asn1/Asn.1.d.ts +34 -0
  41. package/dist/lib/asn1/Stream.d.ts +27 -0
  42. package/dist/lib/asn1/asn1.d.ts +4 -0
  43. package/dist/lib/asn1/base64.d.ts +4 -0
  44. package/dist/lib/asn1/hex.d.ts +5 -0
  45. package/dist/lib/asn1/index.d.ts +5 -0
  46. package/dist/lib/asn1/int10.d.ts +34 -0
  47. package/dist/lib/asn1/oids.d.ts +2 -0
  48. package/dist/lib/asn1/string-cut.d.ts +2 -0
  49. package/dist/lib/decode-html.d.ts +7 -0
  50. package/dist/lib/fetch.d.ts +17 -0
  51. package/dist/lib/is-element.d.ts +5 -0
  52. package/dist/lib/load-files.d.ts +3 -0
  53. package/dist/lib/load-opentype.d.ts +34 -0
  54. package/dist/lib/load-script.d.ts +1 -0
  55. package/dist/lib/mime.d.ts +8 -0
  56. package/dist/lib/read-buffer.d.ts +2 -0
  57. package/dist/lib/toFixeds.d.ts +7 -0
  58. package/dist/libs/Asn.1Utils.d.ts +47 -0
  59. package/dist/libs/asn1/Asn.1.d.ts +34 -0
  60. package/dist/libs/asn1/Stream.d.ts +27 -0
  61. package/dist/libs/asn1/asn1.d.ts +4 -0
  62. package/dist/libs/asn1/base64.d.ts +4 -0
  63. package/dist/libs/asn1/hex.d.ts +5 -0
  64. package/dist/libs/asn1/index.d.ts +5 -0
  65. package/dist/libs/asn1/int10.d.ts +34 -0
  66. package/dist/libs/asn1/oids.d.ts +2 -0
  67. package/dist/libs/asn1/string-cut.d.ts +2 -0
  68. package/dist/libs/decode-html.d.ts +7 -0
  69. package/dist/libs/fetch.d.ts +17 -0
  70. package/dist/libs/mime.d.ts +8 -0
  71. package/dist/libs/ofdArray.d.ts +10 -0
  72. package/dist/libs/ofdImageObject.d.ts +9 -0
  73. package/dist/libs/ofdLayer.d.ts +3 -0
  74. package/dist/libs/ofdName.d.ts +17 -0
  75. package/dist/libs/ofdPathObject.d.ts +11 -0
  76. package/dist/libs/ofdTextObject.d.ts +6 -0
  77. package/dist/libs/parseAnnotation.d.ts +5 -0
  78. package/dist/libs/parseColor.d.ts +5 -0
  79. package/dist/libs/parsePageArea.d.ts +17 -0
  80. package/dist/libs/parser-elements.d.ts +8 -0
  81. package/dist/libs/parserElements.d.ts +8 -0
  82. package/dist/libs/pipeExtensions.d.ts +4 -0
  83. package/dist/libs/read-buffer.d.ts +2 -0
  84. package/dist/main.d.ts +15 -0
  85. package/dist/ofd/ConverterDpi.d.ts +16 -0
  86. package/dist/ofd/index.d.ts +1 -0
  87. package/dist/ofd/ofd-utils.d.ts +137 -0
  88. package/dist/ofd/ofd.d.ts +35 -0
  89. package/dist/ofd/parse-ofd.d.ts +18 -0
  90. package/dist/ofd/render.d.ts +18 -0
  91. package/dist/ofd/svg-image.d.ts +12 -0
  92. package/dist/ofd/svg-path.d.ts +5 -0
  93. package/dist/ofd/svg-text.d.ts +8 -0
  94. package/dist/ofd.parse.d.ts +6 -0
  95. package/dist/ofd.xml.d.ts +1 -0
  96. package/dist/ofdParse.d.ts +6 -0
  97. package/dist/pipe/annotations.d.ts +13 -0
  98. package/dist/pipe/attachments.d.ts +13 -0
  99. package/dist/pipe/commonData.d.ts +18 -0
  100. package/dist/pipe/customTags.d.ts +14 -0
  101. package/dist/pipe/extensions.d.ts +14 -0
  102. package/dist/pipe/output.d.ts +7 -0
  103. package/dist/pipe/pages.d.ts +13 -0
  104. package/dist/pipe/permissions.d.ts +14 -0
  105. package/dist/pipe/pipeline.d.ts +63 -0
  106. package/dist/pipe/startPipe.d.ts +11 -0
  107. package/dist/xml/index.d.ts +2 -0
  108. package/dist/xml/render.d.ts +6 -0
  109. package/dist/xml/xml.d.ts +18 -0
  110. package/package.json +47 -0
  111. package/public/index.html +75 -0
  112. package/public/opentype.min.js +2 -0
  113. package/rollup.config.dev.mjs +47 -0
  114. package/rollup.config.mjs +70 -0
  115. package/src/constant/index.ts +13 -0
  116. package/src/core/ofd-core/Annotations/Annotation.km +206 -0
  117. package/src/core/ofd-core/Annotations/Annotations.km +59 -0
  118. package/src/core/ofd-core/Annotations/Annotations.md +13 -0
  119. package/src/core/ofd-core/Annotations/AnnotationsXml.ts +114 -0
  120. package/src/core/ofd-core/Asn.1Utils.ts +225 -0
  121. package/src/core/ofd-core/Documents/DocumentResXml.ts +55 -0
  122. package/src/core/ofd-core/Documents/Documnet.km +862 -0
  123. package/src/core/ofd-core/Documents/DocumnetXml.ts +118 -0
  124. package/src/core/ofd-core/Documents/Documnets.md +296 -0
  125. package/src/core/ofd-core/Documents/PublicResXml.ts +63 -0
  126. package/src/core/ofd-core/Documents//345/233/276/345/261/202/346/270/262/346/237/223/351/241/272/345/272/217.png +0 -0
  127. package/src/core/ofd-core/Documents//350/241/25022/347/272/277/346/235/241/350/277/236/346/216/245/346/240/267/345/274/217.png +0 -0
  128. package/src/core/ofd-core/Documents//350/241/25023/347/272/277/346/235/241/350/231/232/347/272/277/346/240/267/345/274/217.png +0 -0
  129. package/src/core/ofd-core/Documents//350/241/25023/347/273/223/345/220/210/347/202/271/351/225/277/345/272/246.png +0 -0
  130. package/src/core/ofd-core/Documents//350/241/25024/347/272/277/346/235/241/347/253/257/347/202/271/346/240/267/345/274/217.png +0 -0
  131. package/src/core/ofd-core/Documents//351/241/265/350/276/271/347/225/214/345/261/202/346/254/241/347/273/223/346/236/204.png +0 -0
  132. package/src/core/ofd-core/OFDElement.ts +724 -0
  133. package/src/core/ofd-core/Ofd/CT_DocInfo.km +197 -0
  134. package/src/core/ofd-core/Ofd/OFD.km +114 -0
  135. package/src/core/ofd-core/Ofd/OFD.md +99 -0
  136. package/src/core/ofd-core/Ofd/OFDXml.ts +69 -0
  137. package/src/core/ofd-core/Pages/PAGE.md +40 -0
  138. package/src/core/ofd-core/Pages/PageXml.ts +59 -0
  139. package/src/core/ofd-core/Signatures/Signature.km +308 -0
  140. package/src/core/ofd-core/Signatures/Signature.md +21 -0
  141. package/src/core/ofd-core/Signatures/Signatures.km +315 -0
  142. package/src/core/ofd-core/Signatures/Signatures.md +24 -0
  143. package/src/core/ofd-core/Signatures/Signatures.ts +247 -0
  144. package/src/core/ofd-core/TemplatePages/TemplatePages.ts +56 -0
  145. package/src/core/ofd-core/asn.md +60 -0
  146. package/src/core/ofd-core/constant.ts +35 -0
  147. package/src/core/ofd-core/index.d.ts +867 -0
  148. package/src/core/ofd-core/utils.ts +86 -0
  149. package/src/dicom/dicom.ts +42 -0
  150. package/src/dicom/index.ts +1 -0
  151. package/src/errors/ErrorHandle.ts +14 -0
  152. package/src/errors/FetchErrors.ts +8 -0
  153. package/src/errors/MimeError.ts +9 -0
  154. package/src/errors/OFDErrors.ts +11 -0
  155. package/src/errors/UnzipErrors.ts +9 -0
  156. package/src/errors/XmlErrors.ts +11 -0
  157. package/src/errors/error-msg.ts +17 -0
  158. package/src/es.ts +3 -0
  159. package/src/global.d.ts +7 -0
  160. package/src/index.ts +7 -0
  161. package/src/lib/ParseFile.ts +12 -0
  162. package/src/lib/README.md +69 -0
  163. package/src/lib/UnitCoversion.ts +55 -0
  164. package/src/lib/asn1/Asn.1.ts +284 -0
  165. package/src/lib/asn1/README.md +1 -0
  166. package/src/lib/asn1/Stream.ts +314 -0
  167. package/src/lib/asn1/asn1.ts +120 -0
  168. package/src/lib/asn1/base64.ts +97 -0
  169. package/src/lib/asn1/hex.ts +60 -0
  170. package/src/lib/asn1/index.ts +5 -0
  171. package/src/lib/asn1/int10.ts +103 -0
  172. package/src/lib/asn1/oids.ts +6164 -0
  173. package/src/lib/asn1/string-cut.ts +8 -0
  174. package/src/lib/decode-html.ts +37 -0
  175. package/src/lib/fetch.ts +70 -0
  176. package/src/lib/is-element.ts +13 -0
  177. package/src/lib/jbig/README.md +1 -0
  178. package/src/lib/jbig/arithmetic_decoder.js +184 -0
  179. package/src/lib/jbig/base_stream.js +117 -0
  180. package/src/lib/jbig/ccitt.js +1068 -0
  181. package/src/lib/jbig/ccitt_stream.js +60 -0
  182. package/src/lib/jbig/compatibility.js +108 -0
  183. package/src/lib/jbig/core_utils.js +591 -0
  184. package/src/lib/jbig/decode_stream.js +184 -0
  185. package/src/lib/jbig/is_node.js +28 -0
  186. package/src/lib/jbig/jbig2.js +2582 -0
  187. package/src/lib/jbig/jbig2_stream.js +78 -0
  188. package/src/lib/jbig/primitives.js +441 -0
  189. package/src/lib/jbig/stream.js +101 -0
  190. package/src/lib/jbig/util.js +1231 -0
  191. package/src/lib/load-files.ts +26 -0
  192. package/src/lib/load-opentype.ts +161 -0
  193. package/src/lib/load-script.ts +33 -0
  194. package/src/lib/mime.ts +97 -0
  195. package/src/lib/read-buffer.ts +19 -0
  196. package/src/lib/toFixeds.ts +56 -0
  197. package/src/ofd/ConverterDpi.ts +35 -0
  198. package/src/ofd/OFD.md +38 -0
  199. package/src/ofd/TODO.md +10 -0
  200. package/src/ofd/index.ts +1 -0
  201. package/src/ofd/ofd-utils.ts +627 -0
  202. package/src/ofd/ofd.demo.md +12 -0
  203. package/src/ofd/ofd.ts +200 -0
  204. package/src/ofd/ofdxml.km +162 -0
  205. package/src/ofd/parse-ofd.ts +103 -0
  206. package/src/ofd/render.ts +393 -0
  207. package/src/ofd/svg-image.ts +318 -0
  208. package/src/ofd/svg-path.ts +283 -0
  209. package/src/ofd/svg-text.ts +272 -0
  210. package/src/xml/index.ts +3 -0
  211. package/src/xml/render.ts +171 -0
  212. package/src/xml/xml.ts +136 -0
  213. package/tsconfig.json +21 -0
@@ -0,0 +1,184 @@
1
+ /* Copyright 2012 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 { BaseStream } from './base_stream.js';
17
+ import { Stream } from './stream.js';
18
+
19
+ // Lots of DecodeStreams are created whose buffers are never used. For these
20
+ // we share a single empty buffer. This is (a) space-efficient and (b) avoids
21
+ // having special cases that would be required if we used |null| for an empty
22
+ // buffer.
23
+ const emptyBuffer = new Uint8Array(0);
24
+
25
+ // Super class for the decoding streams.
26
+ class DecodeStream extends BaseStream {
27
+ constructor(maybeMinBufferLength) {
28
+ super();
29
+ this._rawMinBufferLength = maybeMinBufferLength || 0;
30
+
31
+ this.pos = 0;
32
+ this.bufferLength = 0;
33
+ this.eof = false;
34
+ this.buffer = emptyBuffer;
35
+ this.minBufferLength = 512;
36
+ if (maybeMinBufferLength) {
37
+ // Compute the first power of two that is as big as maybeMinBufferLength.
38
+ while (this.minBufferLength < maybeMinBufferLength) {
39
+ this.minBufferLength *= 2;
40
+ }
41
+ }
42
+ }
43
+
44
+ // @ts-ignore
45
+ get isEmpty() {
46
+ while (!this.eof && this.bufferLength === 0) {
47
+ // @ts-ignore
48
+ this.readBlock();
49
+ }
50
+ return this.bufferLength === 0;
51
+ }
52
+
53
+ ensureBuffer(requested) {
54
+ const buffer = this.buffer;
55
+ if (requested <= buffer.byteLength) {
56
+ return buffer;
57
+ }
58
+ let size = this.minBufferLength;
59
+ while (size < requested) {
60
+ size *= 2;
61
+ }
62
+ const buffer2 = new Uint8Array(size);
63
+ buffer2.set(buffer);
64
+ return (this.buffer = buffer2);
65
+ }
66
+
67
+ getByte() {
68
+ const pos = this.pos;
69
+ while (this.bufferLength <= pos) {
70
+ if (this.eof) {
71
+ return -1;
72
+ }
73
+ // @ts-ignore
74
+ this.readBlock();
75
+ }
76
+ return this.buffer[this.pos++];
77
+ }
78
+
79
+ getBytes(length) {
80
+ const pos = this.pos;
81
+ let end;
82
+
83
+ if (length) {
84
+ this.ensureBuffer(pos + length);
85
+ end = pos + length;
86
+
87
+ while (!this.eof && this.bufferLength < end) {
88
+ // @ts-ignore
89
+ this.readBlock();
90
+ }
91
+ const bufEnd = this.bufferLength;
92
+ if (end > bufEnd) {
93
+ end = bufEnd;
94
+ }
95
+ } else {
96
+ while (!this.eof) {
97
+ // @ts-ignore
98
+ this.readBlock();
99
+ }
100
+ end = this.bufferLength;
101
+ }
102
+
103
+ this.pos = end;
104
+ return this.buffer.subarray(pos, end);
105
+ }
106
+
107
+ reset() {
108
+ this.pos = 0;
109
+ }
110
+
111
+ makeSubStream(start, length, dict = null) {
112
+ if (length === undefined) {
113
+ while (!this.eof) {
114
+ // @ts-ignore
115
+ this.readBlock();
116
+ }
117
+ } else {
118
+ const end = start + length;
119
+ while (this.bufferLength <= end && !this.eof) {
120
+ // @ts-ignore
121
+ this.readBlock();
122
+ }
123
+ }
124
+ return new Stream(this.buffer, start, length, dict);
125
+ }
126
+
127
+ getBaseStreams() {
128
+ // @ts-ignore
129
+ return this.str ? this.str.getBaseStreams() : null;
130
+ }
131
+ }
132
+
133
+ class StreamsSequenceStream extends DecodeStream {
134
+ constructor(streams, onError = null) {
135
+ let maybeLength = 0;
136
+ for (const stream of streams) {
137
+ maybeLength +=
138
+ stream instanceof DecodeStream
139
+ ? stream._rawMinBufferLength
140
+ : stream.length;
141
+ }
142
+ super(maybeLength);
143
+
144
+ this.streams = streams;
145
+ this._onError = onError;
146
+ }
147
+
148
+ readBlock() {
149
+ const streams = this.streams;
150
+ if (streams.length === 0) {
151
+ this.eof = true;
152
+ return;
153
+ }
154
+ const stream = streams.shift();
155
+ let chunk;
156
+ try {
157
+ chunk = stream.getBytes();
158
+ } catch (reason) {
159
+ if (this._onError) {
160
+ this._onError(reason, stream.dict && stream.dict.objId);
161
+ return;
162
+ }
163
+ throw reason;
164
+ }
165
+ const bufferLength = this.bufferLength;
166
+ const newLength = bufferLength + chunk.length;
167
+ const buffer = this.ensureBuffer(newLength);
168
+ buffer.set(chunk, bufferLength);
169
+ this.bufferLength = newLength;
170
+ }
171
+
172
+ getBaseStreams() {
173
+ const baseStreamsBuf = [];
174
+ for (const stream of this.streams) {
175
+ const baseStreams = stream.getBaseStreams();
176
+ if (baseStreams) {
177
+ baseStreamsBuf.push(...baseStreams);
178
+ }
179
+ }
180
+ return baseStreamsBuf.length > 0 ? baseStreamsBuf : null;
181
+ }
182
+ }
183
+
184
+ export { DecodeStream, StreamsSequenceStream };
@@ -0,0 +1,28 @@
1
+ /* Copyright 2018 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
+ /* globals process */
16
+
17
+ // NW.js / Electron is a browser context, but copies some Node.js objects; see
18
+ // http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
19
+ // https://www.electronjs.org/docs/api/process#processversionselectron-readonly
20
+ // https://www.electronjs.org/docs/api/process#processtype-readonly
21
+ const isNodeJS =
22
+ typeof process === 'object' &&
23
+ process + '' === '[object process]' &&
24
+ !process.versions.nw &&
25
+ // @ts-ignore
26
+ !(process.versions.electron && process.type && process.type !== 'browser');
27
+
28
+ export { isNodeJS };