asma-doc-viewer 1.0.2 → 1.0.3
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.
- package/.idea/asma-doc-viewer.iml +9 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +66 -0
- package/package.json +62 -62
- package/build/components/DocumentNav.d.ts +0 -2
- package/build/components/DocumentNav.js +0 -60
- package/build/components/FileName.d.ts +0 -2
- package/build/components/FileName.js +0 -57
- package/build/components/HeaderBar.d.ts +0 -2
- package/build/components/HeaderBar.js +0 -54
- package/build/components/ProxyRenderer.d.ts +0 -2
- package/build/components/ProxyRenderer.js +0 -76
- package/build/components/common/Button.d.ts +0 -11
- package/build/components/common/Button.js +0 -34
- package/build/components/common/index.d.ts +0 -1
- package/build/components/common/index.js +0 -13
- package/build/components/icons/index.d.ts +0 -9
- package/build/components/icons/index.js +0 -45
- package/build/index.d.ts +0 -25
- package/build/index.js +0 -85
- package/build/plugins/bmp/index.d.ts +0 -3
- package/build/plugins/bmp/index.js +0 -22
- package/build/plugins/html/index.d.ts +0 -3
- package/build/plugins/html/index.js +0 -56
- package/build/plugins/image/index.d.ts +0 -3
- package/build/plugins/image/index.js +0 -34
- package/build/plugins/index.d.ts +0 -1
- package/build/plugins/index.js +0 -24
- package/build/plugins/jpg/index.d.ts +0 -3
- package/build/plugins/jpg/index.js +0 -22
- package/build/plugins/msdoc/index.d.ts +0 -3
- package/build/plugins/msdoc/index.js +0 -54
- package/build/plugins/pdf/components/PDFControls.d.ts +0 -3
- package/build/plugins/pdf/components/PDFControls.js +0 -57
- package/build/plugins/pdf/components/PDFPagination.d.ts +0 -3
- package/build/plugins/pdf/components/PDFPagination.js +0 -53
- package/build/plugins/pdf/components/icons/index.d.ts +0 -9
- package/build/plugins/pdf/components/icons/index.js +0 -73
- package/build/plugins/pdf/components/pages/PDFAllPages.d.ts +0 -6
- package/build/plugins/pdf/components/pages/PDFAllPages.js +0 -37
- package/build/plugins/pdf/components/pages/PDFPages.d.ts +0 -3
- package/build/plugins/pdf/components/pages/PDFPages.js +0 -52
- package/build/plugins/pdf/components/pages/PDFSinglePage.d.ts +0 -6
- package/build/plugins/pdf/components/pages/PDFSinglePage.js +0 -49
- package/build/plugins/pdf/index.d.ts +0 -3
- package/build/plugins/pdf/index.js +0 -51
- package/build/plugins/pdf/state/actions.d.ts +0 -25
- package/build/plugins/pdf/state/actions.js +0 -31
- package/build/plugins/pdf/state/index.d.ts +0 -12
- package/build/plugins/pdf/state/index.js +0 -43
- package/build/plugins/pdf/state/reducer.d.ts +0 -12
- package/build/plugins/pdf/state/reducer.js +0 -45
- package/build/plugins/png/index.d.ts +0 -3
- package/build/plugins/png/index.js +0 -29
- package/build/plugins/tiff/index.d.ts +0 -3
- package/build/plugins/tiff/index.js +0 -73
- package/build/plugins/tiff/tiffToCanvas.d.ts +0 -1
- package/build/plugins/tiff/tiffToCanvas.js +0 -602
- package/build/plugins/txt/index.d.ts +0 -3
- package/build/plugins/txt/index.js +0 -22
- package/build/state/actions.d.ts +0 -42
- package/build/state/actions.js +0 -45
- package/build/state/index.d.ts +0 -10
- package/build/state/index.js +0 -50
- package/build/state/reducer.d.ts +0 -14
- package/build/state/reducer.js +0 -64
- package/build/theme/index.d.ts +0 -2
- package/build/theme/index.js +0 -12
- package/build/types/index.d.ts +0 -40
- package/build/types/index.js +0 -2
- package/build/utils/fileLoaders.d.ts +0 -12
- package/build/utils/fileLoaders.js +0 -105
- package/build/utils/useDocumentLoader.d.ts +0 -12
- package/build/utils/useDocumentLoader.js +0 -82
- package/build/utils/useRendererSelector.d.ts +0 -7
- package/build/utils/useRendererSelector.js +0 -40
- package/build/utils/useWindowSize.d.ts +0 -4
- package/build/utils/useWindowSize.js +0 -34
|
@@ -1,602 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _this = this;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.parseTIFF = void 0;
|
|
5
|
-
var tiffDataView = undefined;
|
|
6
|
-
var littleEndian = undefined;
|
|
7
|
-
var fileDirectories = [];
|
|
8
|
-
var isLittleEndian = function () {
|
|
9
|
-
// Get byte order mark.
|
|
10
|
-
var BOM = getBytes(2, 0);
|
|
11
|
-
// Find out the endianness.
|
|
12
|
-
if (BOM === 0x4949) {
|
|
13
|
-
littleEndian = true;
|
|
14
|
-
}
|
|
15
|
-
else if (BOM === 0x4d4d) {
|
|
16
|
-
littleEndian = false;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
throw TypeError("Invalid byte order value.");
|
|
20
|
-
}
|
|
21
|
-
return littleEndian;
|
|
22
|
-
};
|
|
23
|
-
var hasTowel = function () {
|
|
24
|
-
// Check for towel.
|
|
25
|
-
if (getBytes(2, 2) !== 42) {
|
|
26
|
-
throw RangeError("You forgot your towel!");
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
31
|
-
var getFieldTagName = function (fieldTag) {
|
|
32
|
-
// See: http://www.digitizationguidelines.gov/guidelines/TIFF_Metadata_Final.pdf
|
|
33
|
-
// See: http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml
|
|
34
|
-
var fieldTagNames = {
|
|
35
|
-
// TIFF Baseline
|
|
36
|
-
0x013b: "Artist",
|
|
37
|
-
0x0102: "BitsPerSample",
|
|
38
|
-
0x0109: "CellLength",
|
|
39
|
-
0x0108: "CellWidth",
|
|
40
|
-
0x0140: "ColorMap",
|
|
41
|
-
0x0103: "Compression",
|
|
42
|
-
0x8298: "Copyright",
|
|
43
|
-
0x0132: "DateTime",
|
|
44
|
-
0x0152: "ExtraSamples",
|
|
45
|
-
0x010a: "FillOrder",
|
|
46
|
-
0x0121: "FreeByteCounts",
|
|
47
|
-
0x0120: "FreeOffsets",
|
|
48
|
-
0x0123: "GrayResponseCurve",
|
|
49
|
-
0x0122: "GrayResponseUnit",
|
|
50
|
-
0x013c: "HostComputer",
|
|
51
|
-
0x010e: "ImageDescription",
|
|
52
|
-
0x0101: "ImageLength",
|
|
53
|
-
0x0100: "ImageWidth",
|
|
54
|
-
0x010f: "Make",
|
|
55
|
-
0x0119: "MaxSampleValue",
|
|
56
|
-
0x0118: "MinSampleValue",
|
|
57
|
-
0x0110: "Model",
|
|
58
|
-
0x00fe: "NewSubfileType",
|
|
59
|
-
0x0112: "Orientation",
|
|
60
|
-
0x0106: "PhotometricInterpretation",
|
|
61
|
-
0x011c: "PlanarConfiguration",
|
|
62
|
-
0x0128: "ResolutionUnit",
|
|
63
|
-
0x0116: "RowsPerStrip",
|
|
64
|
-
0x0115: "SamplesPerPixel",
|
|
65
|
-
0x0131: "Software",
|
|
66
|
-
0x0117: "StripByteCounts",
|
|
67
|
-
0x0111: "StripOffsets",
|
|
68
|
-
0x00ff: "SubfileType",
|
|
69
|
-
0x0107: "Threshholding",
|
|
70
|
-
0x011a: "XResolution",
|
|
71
|
-
0x011b: "YResolution",
|
|
72
|
-
// TIFF Extended
|
|
73
|
-
0x0146: "BadFaxLines",
|
|
74
|
-
0x0147: "CleanFaxData",
|
|
75
|
-
0x0157: "ClipPath",
|
|
76
|
-
0x0148: "ConsecutiveBadFaxLines",
|
|
77
|
-
0x01b1: "Decode",
|
|
78
|
-
0x01b2: "DefaultImageColor",
|
|
79
|
-
0x010d: "DocumentName",
|
|
80
|
-
0x0150: "DotRange",
|
|
81
|
-
0x0141: "HalftoneHints",
|
|
82
|
-
0x015a: "Indexed",
|
|
83
|
-
0x015b: "JPEGTables",
|
|
84
|
-
0x011d: "PageName",
|
|
85
|
-
0x0129: "PageNumber",
|
|
86
|
-
0x013d: "Predictor",
|
|
87
|
-
0x013f: "PrimaryChromaticities",
|
|
88
|
-
0x0214: "ReferenceBlackWhite",
|
|
89
|
-
0x0153: "SampleFormat",
|
|
90
|
-
0x022f: "StripRowCounts",
|
|
91
|
-
0x014a: "SubIFDs",
|
|
92
|
-
0x0124: "T4Options",
|
|
93
|
-
0x0125: "T6Options",
|
|
94
|
-
0x0145: "TileByteCounts",
|
|
95
|
-
0x0143: "TileLength",
|
|
96
|
-
0x0144: "TileOffsets",
|
|
97
|
-
0x0142: "TileWidth",
|
|
98
|
-
0x012d: "TransferFunction",
|
|
99
|
-
0x013e: "WhitePoint",
|
|
100
|
-
0x0158: "XClipPathUnits",
|
|
101
|
-
0x011e: "XPosition",
|
|
102
|
-
0x0211: "YCbCrCoefficients",
|
|
103
|
-
0x0213: "YCbCrPositioning",
|
|
104
|
-
0x0212: "YCbCrSubSampling",
|
|
105
|
-
0x0159: "YClipPathUnits",
|
|
106
|
-
0x011f: "YPosition",
|
|
107
|
-
// EXIF
|
|
108
|
-
0x9202: "ApertureValue",
|
|
109
|
-
0xa001: "ColorSpace",
|
|
110
|
-
0x9004: "DateTimeDigitized",
|
|
111
|
-
0x9003: "DateTimeOriginal",
|
|
112
|
-
0x8769: "Exif IFD",
|
|
113
|
-
0x9000: "ExifVersion",
|
|
114
|
-
0x829a: "ExposureTime",
|
|
115
|
-
0xa300: "FileSource",
|
|
116
|
-
0x9209: "Flash",
|
|
117
|
-
0xa000: "FlashpixVersion",
|
|
118
|
-
0x829d: "FNumber",
|
|
119
|
-
0xa420: "ImageUniqueID",
|
|
120
|
-
0x9208: "LightSource",
|
|
121
|
-
0x927c: "MakerNote",
|
|
122
|
-
0x9201: "ShutterSpeedValue",
|
|
123
|
-
0x9286: "UserComment",
|
|
124
|
-
// IPTC
|
|
125
|
-
0x83bb: "IPTC",
|
|
126
|
-
// ICC
|
|
127
|
-
0x8773: "ICC Profile",
|
|
128
|
-
// XMP
|
|
129
|
-
0x02bc: "XMP",
|
|
130
|
-
// GDAL
|
|
131
|
-
0xa480: "GDAL_METADATA",
|
|
132
|
-
0xa481: "GDAL_NODATA",
|
|
133
|
-
// Photoshop
|
|
134
|
-
0x8649: "Photoshop",
|
|
135
|
-
};
|
|
136
|
-
var fieldTagName;
|
|
137
|
-
if (fieldTag in fieldTagNames) {
|
|
138
|
-
fieldTagName = fieldTagNames[fieldTag];
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
fieldTagName = "Tag" + fieldTag;
|
|
142
|
-
}
|
|
143
|
-
return fieldTagName;
|
|
144
|
-
};
|
|
145
|
-
var getFieldTypeName = function (fieldType) {
|
|
146
|
-
var fieldTypeNames = {
|
|
147
|
-
0x0001: "BYTE",
|
|
148
|
-
0x0002: "ASCII",
|
|
149
|
-
0x0003: "SHORT",
|
|
150
|
-
0x0004: "LONG",
|
|
151
|
-
0x0005: "RATIONAL",
|
|
152
|
-
0x0006: "SBYTE",
|
|
153
|
-
0x0007: "UNDEFINED",
|
|
154
|
-
0x0008: "SSHORT",
|
|
155
|
-
0x0009: "SLONG",
|
|
156
|
-
0x000a: "SRATIONAL",
|
|
157
|
-
0x000b: "FLOAT",
|
|
158
|
-
0x000c: "DOUBLE",
|
|
159
|
-
};
|
|
160
|
-
var fieldTypeName;
|
|
161
|
-
if (fieldType in fieldTypeNames) {
|
|
162
|
-
fieldTypeName = fieldTypeNames[fieldType];
|
|
163
|
-
}
|
|
164
|
-
return fieldTypeName;
|
|
165
|
-
};
|
|
166
|
-
var getFieldTypeLength = function (fieldTypeName) {
|
|
167
|
-
var fieldTypeLength;
|
|
168
|
-
if (["BYTE", "ASCII", "SBYTE", "UNDEFINED"].indexOf(fieldTypeName) !== -1) {
|
|
169
|
-
fieldTypeLength = 1;
|
|
170
|
-
}
|
|
171
|
-
else if (["SHORT", "SSHORT"].indexOf(fieldTypeName) !== -1) {
|
|
172
|
-
fieldTypeLength = 2;
|
|
173
|
-
}
|
|
174
|
-
else if (["LONG", "SLONG", "FLOAT"].indexOf(fieldTypeName) !== -1) {
|
|
175
|
-
fieldTypeLength = 4;
|
|
176
|
-
}
|
|
177
|
-
else if (["RATIONAL", "SRATIONAL", "DOUBLE"].indexOf(fieldTypeName) !== -1) {
|
|
178
|
-
fieldTypeLength = 8;
|
|
179
|
-
}
|
|
180
|
-
return fieldTypeLength;
|
|
181
|
-
};
|
|
182
|
-
var getBits = function (numBits, byteOffset, bitOffset) {
|
|
183
|
-
bitOffset = bitOffset || 0;
|
|
184
|
-
var extraBytes = Math.floor(bitOffset / 8);
|
|
185
|
-
var newByteOffset = byteOffset + extraBytes;
|
|
186
|
-
var totalBits = bitOffset + numBits;
|
|
187
|
-
var shiftRight = 32 - numBits;
|
|
188
|
-
if (totalBits <= 0) {
|
|
189
|
-
throw RangeError("No bits requested");
|
|
190
|
-
}
|
|
191
|
-
else if (totalBits <= 8) {
|
|
192
|
-
var shiftLeft = 24 + bitOffset;
|
|
193
|
-
var rawBits = tiffDataView.getUint8(newByteOffset, littleEndian);
|
|
194
|
-
}
|
|
195
|
-
else if (totalBits <= 16) {
|
|
196
|
-
var shiftLeft = 16 + bitOffset;
|
|
197
|
-
var rawBits = tiffDataView.getUint16(newByteOffset, littleEndian);
|
|
198
|
-
}
|
|
199
|
-
else if (totalBits <= 32) {
|
|
200
|
-
var shiftLeft = bitOffset;
|
|
201
|
-
var rawBits = tiffDataView.getUint32(newByteOffset, littleEndian);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
throw RangeError("Too many bits requested");
|
|
205
|
-
}
|
|
206
|
-
var chunkInfo = {
|
|
207
|
-
bits: (rawBits << shiftLeft) >>> shiftRight,
|
|
208
|
-
byteOffset: newByteOffset + Math.floor(totalBits / 8),
|
|
209
|
-
bitOffset: totalBits % 8,
|
|
210
|
-
};
|
|
211
|
-
return chunkInfo;
|
|
212
|
-
};
|
|
213
|
-
var getBytes = function (numBytes, offset) {
|
|
214
|
-
if (numBytes <= 0) {
|
|
215
|
-
throw RangeError("No bytes requested");
|
|
216
|
-
}
|
|
217
|
-
else if (numBytes <= 1) {
|
|
218
|
-
return tiffDataView.getUint8(offset, littleEndian);
|
|
219
|
-
}
|
|
220
|
-
else if (numBytes <= 2) {
|
|
221
|
-
return tiffDataView.getUint16(offset, littleEndian);
|
|
222
|
-
}
|
|
223
|
-
else if (numBytes <= 3) {
|
|
224
|
-
return tiffDataView.getUint32(offset, littleEndian) >>> 8;
|
|
225
|
-
}
|
|
226
|
-
else if (numBytes <= 4) {
|
|
227
|
-
return tiffDataView.getUint32(offset, littleEndian);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
throw RangeError("Too many bytes requested");
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
var getFieldValues = function (fieldTagName, fieldTypeName, typeCount, valueOffset) {
|
|
234
|
-
var fieldValues = [];
|
|
235
|
-
var fieldTypeLength = getFieldTypeLength(fieldTypeName);
|
|
236
|
-
var fieldValueSize = fieldTypeLength * typeCount;
|
|
237
|
-
if (fieldValueSize <= 4) {
|
|
238
|
-
// The value is stored at the big end of the valueOffset.
|
|
239
|
-
if (littleEndian === false) {
|
|
240
|
-
var value = valueOffset >>> ((4 - fieldTypeLength) * 8);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
var value = valueOffset;
|
|
244
|
-
}
|
|
245
|
-
fieldValues.push(value);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
for (var i = 0; i < typeCount; i++) {
|
|
249
|
-
var indexOffset = fieldTypeLength * i;
|
|
250
|
-
if (fieldTypeLength >= 8) {
|
|
251
|
-
if (["RATIONAL", "SRATIONAL"].indexOf(fieldTypeName) !== -1) {
|
|
252
|
-
// Numerator
|
|
253
|
-
fieldValues.push(getBytes(4, valueOffset + indexOffset));
|
|
254
|
-
// Denominator
|
|
255
|
-
fieldValues.push(getBytes(4, valueOffset + indexOffset + 4));
|
|
256
|
-
// } else if (['DOUBLE'].indexOf(fieldTypeName) !== -1) {
|
|
257
|
-
// fieldValues.push(getBytes(4, valueOffset + indexOffset) + getBytes(4, valueOffset + indexOffset + 4));
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
throw TypeError("Can't handle this field type or size");
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
fieldValues.push(getBytes(fieldTypeLength, valueOffset + indexOffset));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (fieldTypeName === "ASCII") {
|
|
269
|
-
fieldValues.forEach(function (e, i, a) {
|
|
270
|
-
a[i] = String.fromCharCode(e);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return fieldValues;
|
|
274
|
-
};
|
|
275
|
-
var clampColorSample = function (colorSample, bitsPerSample) {
|
|
276
|
-
var multiplier = Math.pow(2, 8 - bitsPerSample);
|
|
277
|
-
return Math.floor(colorSample * multiplier + (multiplier - 1));
|
|
278
|
-
};
|
|
279
|
-
var makeRGBAFillValue = function (r, g, b, a) {
|
|
280
|
-
if (typeof a === "undefined") {
|
|
281
|
-
a = 1.0;
|
|
282
|
-
}
|
|
283
|
-
return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
|
|
284
|
-
};
|
|
285
|
-
var parseFileDirectory = function (byteOffset) {
|
|
286
|
-
var numDirEntries = getBytes(2, byteOffset);
|
|
287
|
-
var tiffFields = [];
|
|
288
|
-
for (var i = byteOffset + 2, entryCount = 0; entryCount < numDirEntries; i += 12, entryCount++) {
|
|
289
|
-
var fieldTag = getBytes(2, i);
|
|
290
|
-
var fieldType = getBytes(2, i + 2);
|
|
291
|
-
var typeCount = getBytes(4, i + 4);
|
|
292
|
-
var valueOffset = getBytes(4, i + 8);
|
|
293
|
-
var fieldTagName = getFieldTagName(fieldTag);
|
|
294
|
-
var fieldTypeName = getFieldTypeName(fieldType);
|
|
295
|
-
var fieldValues = getFieldValues(fieldTagName, fieldTypeName, typeCount, valueOffset);
|
|
296
|
-
tiffFields[fieldTagName] = { type: fieldTypeName, values: fieldValues };
|
|
297
|
-
}
|
|
298
|
-
fileDirectories.push(tiffFields);
|
|
299
|
-
var nextIFDByteOffset = getBytes(4, i);
|
|
300
|
-
if (nextIFDByteOffset === 0x00000000) {
|
|
301
|
-
return fileDirectories;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
return parseFileDirectory(nextIFDByteOffset);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
var parseTIFF = function (tiffArrayBuffer, _canvas) {
|
|
308
|
-
var canvas = _canvas || document.createElement("canvas");
|
|
309
|
-
if (!tiffArrayBuffer)
|
|
310
|
-
return;
|
|
311
|
-
tiffDataView = new DataView(tiffArrayBuffer);
|
|
312
|
-
// canvas = _canvas;
|
|
313
|
-
littleEndian = isLittleEndian(tiffDataView);
|
|
314
|
-
if (!hasTowel(tiffDataView, littleEndian))
|
|
315
|
-
return;
|
|
316
|
-
var firstIFDByteOffset = getBytes(4, 4);
|
|
317
|
-
fileDirectories = parseFileDirectory(firstIFDByteOffset);
|
|
318
|
-
var fileDirectory = fileDirectories[0];
|
|
319
|
-
var imageWidth = fileDirectory.ImageWidth.values[0];
|
|
320
|
-
var imageLength = fileDirectory.ImageLength.values[0];
|
|
321
|
-
canvas.width = imageWidth;
|
|
322
|
-
canvas.height = imageLength;
|
|
323
|
-
var strips = [];
|
|
324
|
-
var compression = fileDirectory.Compression
|
|
325
|
-
? fileDirectory.Compression.values[0]
|
|
326
|
-
: 1;
|
|
327
|
-
var samplesPerPixel = fileDirectory.SamplesPerPixel.values[0];
|
|
328
|
-
var sampleProperties = [];
|
|
329
|
-
var bitsPerPixel = 0;
|
|
330
|
-
var hasBytesPerPixel = false;
|
|
331
|
-
fileDirectory.BitsPerSample.values.forEach(function (bitsPerSample, i, bitsPerSampleValues) {
|
|
332
|
-
sampleProperties[i] = {
|
|
333
|
-
bitsPerSample: bitsPerSample,
|
|
334
|
-
hasBytesPerSample: false,
|
|
335
|
-
bytesPerSample: undefined,
|
|
336
|
-
};
|
|
337
|
-
if (bitsPerSample % 8 === 0) {
|
|
338
|
-
sampleProperties[i].hasBytesPerSample = true;
|
|
339
|
-
sampleProperties[i].bytesPerSample = bitsPerSample / 8;
|
|
340
|
-
}
|
|
341
|
-
bitsPerPixel += bitsPerSample;
|
|
342
|
-
}, _this);
|
|
343
|
-
if (bitsPerPixel % 8 === 0) {
|
|
344
|
-
hasBytesPerPixel = true;
|
|
345
|
-
var bytesPerPixel = bitsPerPixel / 8;
|
|
346
|
-
}
|
|
347
|
-
var stripOffsetValues = fileDirectory.StripOffsets.values;
|
|
348
|
-
var numStripOffsetValues = stripOffsetValues.length;
|
|
349
|
-
// StripByteCounts is supposed to be required, but see if we can recover anyway.
|
|
350
|
-
if (fileDirectory.StripByteCounts) {
|
|
351
|
-
var stripByteCountValues = fileDirectory.StripByteCounts.values;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// Infer StripByteCounts, if possible.
|
|
355
|
-
if (numStripOffsetValues === 1) {
|
|
356
|
-
var stripByteCountValues = [
|
|
357
|
-
Math.ceil((imageWidth * imageLength * bitsPerPixel) / 8),
|
|
358
|
-
];
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
throw Error("Cannot recover from missing StripByteCounts");
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
// Loop through strips and decompress as necessary.
|
|
365
|
-
for (var i = 0; i < numStripOffsetValues; i++) {
|
|
366
|
-
var stripOffset = stripOffsetValues[i];
|
|
367
|
-
strips[i] = [];
|
|
368
|
-
var stripByteCount = stripByteCountValues[i];
|
|
369
|
-
// Loop through pixels.
|
|
370
|
-
for (var byteOffset = 0, bitOffset = 0, jIncrement = 1, getHeader = true, pixel = [], numBytes = 0, sample = 0, currentSample = 0; byteOffset < stripByteCount; byteOffset += jIncrement) {
|
|
371
|
-
// Decompress strip.
|
|
372
|
-
switch (compression) {
|
|
373
|
-
// Uncompressed
|
|
374
|
-
case 1:
|
|
375
|
-
// Loop through samples (sub-pixels).
|
|
376
|
-
for (var m = 0, pixel = []; m < samplesPerPixel; m++) {
|
|
377
|
-
if (sampleProperties[m].hasBytesPerSample) {
|
|
378
|
-
// XXX: This is wrong!
|
|
379
|
-
var sampleOffset = sampleProperties[m].bytesPerSample * m;
|
|
380
|
-
pixel.push(getBytes(sampleProperties[m].bytesPerSample, stripOffset + byteOffset + sampleOffset));
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
var sampleInfo = getBits(sampleProperties[m].bitsPerSample, stripOffset + byteOffset, bitOffset);
|
|
384
|
-
pixel.push(sampleInfo.bits);
|
|
385
|
-
byteOffset = sampleInfo.byteOffset - stripOffset;
|
|
386
|
-
bitOffset = sampleInfo.bitOffset;
|
|
387
|
-
throw RangeError("Cannot handle sub-byte bits per sample");
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
strips[i].push(pixel);
|
|
391
|
-
if (hasBytesPerPixel) {
|
|
392
|
-
jIncrement = bytesPerPixel;
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
jIncrement = 0;
|
|
396
|
-
throw RangeError("Cannot handle sub-byte bits per pixel");
|
|
397
|
-
}
|
|
398
|
-
break;
|
|
399
|
-
// CITT Group 3 1-Dimensional Modified Huffman run-length encoding
|
|
400
|
-
case 2:
|
|
401
|
-
// XXX: Use PDF.js code?
|
|
402
|
-
break;
|
|
403
|
-
// Group 3 Fax
|
|
404
|
-
case 3:
|
|
405
|
-
// XXX: Use PDF.js code?
|
|
406
|
-
break;
|
|
407
|
-
// Group 4 Fax
|
|
408
|
-
case 4:
|
|
409
|
-
// XXX: Use PDF.js code?
|
|
410
|
-
break;
|
|
411
|
-
// LZW
|
|
412
|
-
case 5:
|
|
413
|
-
// XXX: Use PDF.js code?
|
|
414
|
-
break;
|
|
415
|
-
// Old-style JPEG (TIFF 6.0)
|
|
416
|
-
case 6:
|
|
417
|
-
// XXX: Use PDF.js code?
|
|
418
|
-
break;
|
|
419
|
-
// New-style JPEG (TIFF Specification Supplement 2)
|
|
420
|
-
case 7:
|
|
421
|
-
// XXX: Use PDF.js code?
|
|
422
|
-
break;
|
|
423
|
-
// PackBits
|
|
424
|
-
case 32773:
|
|
425
|
-
// Are we ready for a new block?
|
|
426
|
-
if (getHeader) {
|
|
427
|
-
getHeader = false;
|
|
428
|
-
var blockLength = 1;
|
|
429
|
-
var iterations = 1;
|
|
430
|
-
// The header byte is signed.
|
|
431
|
-
var header = tiffDataView.getInt8(stripOffset + byteOffset, littleEndian);
|
|
432
|
-
if (header >= 0 && header <= 127) {
|
|
433
|
-
// Normal pixels.
|
|
434
|
-
blockLength = header + 1;
|
|
435
|
-
}
|
|
436
|
-
else if (header >= -127 && header <= -1) {
|
|
437
|
-
// Collapsed pixels.
|
|
438
|
-
iterations = -header + 1;
|
|
439
|
-
} /*if (header === -128)*/
|
|
440
|
-
else {
|
|
441
|
-
// Placeholder byte?
|
|
442
|
-
getHeader = true;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
var currentByte = getBytes(1, stripOffset + byteOffset);
|
|
447
|
-
// Duplicate bytes, if necessary.
|
|
448
|
-
for (var m = 0; m < iterations; m++) {
|
|
449
|
-
if (sampleProperties[sample].hasBytesPerSample) {
|
|
450
|
-
// We're reading one byte at a time, so we need to handle multi-byte samples.
|
|
451
|
-
currentSample = (currentSample << (8 * numBytes)) | currentByte;
|
|
452
|
-
numBytes++;
|
|
453
|
-
// Is our sample complete?
|
|
454
|
-
if (numBytes === sampleProperties[sample].bytesPerSample) {
|
|
455
|
-
pixel.push(currentSample);
|
|
456
|
-
currentSample = numBytes = 0;
|
|
457
|
-
sample++;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
throw RangeError("Cannot handle sub-byte bits per sample");
|
|
462
|
-
}
|
|
463
|
-
// Is our pixel complete?
|
|
464
|
-
if (sample === samplesPerPixel) {
|
|
465
|
-
strips[i].push(pixel);
|
|
466
|
-
pixel = [];
|
|
467
|
-
sample = 0;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
blockLength--;
|
|
471
|
-
// Is our block complete?
|
|
472
|
-
if (blockLength === 0) {
|
|
473
|
-
getHeader = true;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
jIncrement = 1;
|
|
477
|
-
break;
|
|
478
|
-
// Unknown compression algorithm
|
|
479
|
-
default:
|
|
480
|
-
// Do not attempt to parse the image data.
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (canvas.getContext) {
|
|
486
|
-
var ctx = canvas.getContext("2d");
|
|
487
|
-
// Set a default fill style.
|
|
488
|
-
ctx.fillStyle = makeRGBAFillValue(255, 255, 255, 0);
|
|
489
|
-
// If RowsPerStrip is missing, the whole image is in one strip.
|
|
490
|
-
if (fileDirectory.RowsPerStrip) {
|
|
491
|
-
var rowsPerStrip = fileDirectory.RowsPerStrip.values[0];
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
var rowsPerStrip = imageLength;
|
|
495
|
-
}
|
|
496
|
-
var numStrips = strips.length;
|
|
497
|
-
var imageLengthModRowsPerStrip = imageLength % rowsPerStrip;
|
|
498
|
-
var rowsInLastStrip = imageLengthModRowsPerStrip === 0
|
|
499
|
-
? rowsPerStrip
|
|
500
|
-
: imageLengthModRowsPerStrip;
|
|
501
|
-
var numRowsInStrip = rowsPerStrip;
|
|
502
|
-
var numRowsInPreviousStrip = 0;
|
|
503
|
-
var photometricInterpretation = fileDirectory.PhotometricInterpretation.values[0];
|
|
504
|
-
var extraSamplesValues = [];
|
|
505
|
-
var numExtraSamples = 0;
|
|
506
|
-
if (fileDirectory.ExtraSamples) {
|
|
507
|
-
extraSamplesValues = fileDirectory.ExtraSamples.values;
|
|
508
|
-
numExtraSamples = extraSamplesValues.length;
|
|
509
|
-
}
|
|
510
|
-
if (fileDirectory.ColorMap) {
|
|
511
|
-
var colorMapValues = fileDirectory.ColorMap.values;
|
|
512
|
-
var colorMapSampleSize = Math.pow(2, sampleProperties[0].bitsPerSample);
|
|
513
|
-
}
|
|
514
|
-
// Loop through the strips in the image.
|
|
515
|
-
for (var i = 0; i < numStrips; i++) {
|
|
516
|
-
// The last strip may be short.
|
|
517
|
-
if (i + 1 === numStrips) {
|
|
518
|
-
numRowsInStrip = rowsInLastStrip;
|
|
519
|
-
}
|
|
520
|
-
var numPixels = strips[i].length;
|
|
521
|
-
var yPadding = numRowsInPreviousStrip * i;
|
|
522
|
-
// Loop through the rows in the strip.
|
|
523
|
-
for (var y = 0, j = 0; y < numRowsInStrip, j < numPixels; y++) {
|
|
524
|
-
// Loop through the pixels in the row.
|
|
525
|
-
for (var x = 0; x < imageWidth; x++, j++) {
|
|
526
|
-
var pixelSamples = strips[i][j];
|
|
527
|
-
var red = 0;
|
|
528
|
-
var green = 0;
|
|
529
|
-
var blue = 0;
|
|
530
|
-
var opacity = 1.0;
|
|
531
|
-
if (numExtraSamples > 0) {
|
|
532
|
-
for (var k = 0; k < numExtraSamples; k++) {
|
|
533
|
-
if (extraSamplesValues[k] === 1 || extraSamplesValues[k] === 2) {
|
|
534
|
-
// Clamp opacity to the range [0,1].
|
|
535
|
-
opacity = pixelSamples[3 + k] / 256;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
switch (photometricInterpretation) {
|
|
541
|
-
// Bilevel or Grayscale
|
|
542
|
-
// WhiteIsZero
|
|
543
|
-
case 0:
|
|
544
|
-
if (sampleProperties[0].hasBytesPerSample) {
|
|
545
|
-
var invertValue = Math.pow(0x10, sampleProperties[0].bytesPerSample * 2);
|
|
546
|
-
}
|
|
547
|
-
// Invert samples.
|
|
548
|
-
pixelSamples.forEach(function (sample, index, samples) {
|
|
549
|
-
samples[index] = invertValue - sample;
|
|
550
|
-
});
|
|
551
|
-
// Bilevel or Grayscale
|
|
552
|
-
// BlackIsZero
|
|
553
|
-
case 1:
|
|
554
|
-
red = green = blue = clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
|
|
555
|
-
break;
|
|
556
|
-
// RGB Full Color
|
|
557
|
-
case 2:
|
|
558
|
-
red = clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
|
|
559
|
-
green = clampColorSample(pixelSamples[1], sampleProperties[1].bitsPerSample);
|
|
560
|
-
blue = clampColorSample(pixelSamples[2], sampleProperties[2].bitsPerSample);
|
|
561
|
-
break;
|
|
562
|
-
// RGB Color Palette
|
|
563
|
-
case 3:
|
|
564
|
-
if (colorMapValues === undefined) {
|
|
565
|
-
throw Error("Palette image missing color map");
|
|
566
|
-
}
|
|
567
|
-
var colorMapIndex = pixelSamples[0];
|
|
568
|
-
red = clampColorSample(colorMapValues[colorMapIndex], 16);
|
|
569
|
-
green = clampColorSample(colorMapValues[colorMapSampleSize + colorMapIndex], 16);
|
|
570
|
-
blue = clampColorSample(colorMapValues[2 * colorMapSampleSize + colorMapIndex], 16);
|
|
571
|
-
break;
|
|
572
|
-
// Transparency mask
|
|
573
|
-
case 4:
|
|
574
|
-
throw RangeError("Not Yet Implemented: Transparency mask");
|
|
575
|
-
break;
|
|
576
|
-
// CMYK
|
|
577
|
-
case 5:
|
|
578
|
-
throw RangeError("Not Yet Implemented: CMYK");
|
|
579
|
-
break;
|
|
580
|
-
// YCbCr
|
|
581
|
-
case 6:
|
|
582
|
-
throw RangeError("Not Yet Implemented: YCbCr");
|
|
583
|
-
break;
|
|
584
|
-
// CIELab
|
|
585
|
-
case 8:
|
|
586
|
-
throw RangeError("Not Yet Implemented: CIELab");
|
|
587
|
-
break;
|
|
588
|
-
// Unknown Photometric Interpretation
|
|
589
|
-
default:
|
|
590
|
-
throw RangeError("Unknown Photometric Interpretation:", photometricInterpretation);
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
ctx.fillStyle = makeRGBAFillValue(red, green, blue, opacity);
|
|
594
|
-
ctx.fillRect(x, yPadding + y, 1, 1);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
numRowsInPreviousStrip = numRowsInStrip;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
return canvas;
|
|
601
|
-
};
|
|
602
|
-
exports.parseTIFF = parseTIFF;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
var react_1 = __importDefault(require("react"));
|
|
11
|
-
var styled_components_1 = __importDefault(require("styled-components"));
|
|
12
|
-
var fileLoaders_1 = require("../../utils/fileLoaders");
|
|
13
|
-
var TXTRenderer = function (_a) {
|
|
14
|
-
var currentDocument = _a.mainState.currentDocument;
|
|
15
|
-
return react_1.default.createElement(Container, { id: "txt-renderer" }, currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.fileData);
|
|
16
|
-
};
|
|
17
|
-
exports.default = TXTRenderer;
|
|
18
|
-
TXTRenderer.fileTypes = ["txt", "text/plain"];
|
|
19
|
-
TXTRenderer.weight = 0;
|
|
20
|
-
TXTRenderer.fileLoader = fileLoaders_1.textFileLoader;
|
|
21
|
-
var Container = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n width: 100%;\n padding: 30px;\n"], ["\n display: flex;\n flex-direction: column;\n width: 100%;\n padding: 30px;\n"])));
|
|
22
|
-
var templateObject_1;
|
package/build/state/actions.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { IConfig, IDocument } from "../types";
|
|
2
|
-
export declare const SET_ALL_DOCUMENTS: string;
|
|
3
|
-
export interface SetAllDocuments {
|
|
4
|
-
type: typeof SET_ALL_DOCUMENTS;
|
|
5
|
-
documents: IDocument[];
|
|
6
|
-
}
|
|
7
|
-
export declare const setAllDocuments: (documents: IDocument[]) => SetAllDocuments;
|
|
8
|
-
export declare const SET_DOCUMENT_LOADING: string;
|
|
9
|
-
export interface SetDocumentLoading {
|
|
10
|
-
type: typeof SET_DOCUMENT_LOADING;
|
|
11
|
-
value: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare const setDocumentLoading: (value: boolean) => SetDocumentLoading;
|
|
14
|
-
export declare const NEXT_DOCUMENT: string;
|
|
15
|
-
export interface NextDocument {
|
|
16
|
-
type: typeof NEXT_DOCUMENT;
|
|
17
|
-
}
|
|
18
|
-
export declare const nextDocument: () => NextDocument;
|
|
19
|
-
export declare const PREVIOUS_DOCUMENT: string;
|
|
20
|
-
export interface PreviousDocument {
|
|
21
|
-
type: typeof PREVIOUS_DOCUMENT;
|
|
22
|
-
}
|
|
23
|
-
export declare const previousDocument: () => PreviousDocument;
|
|
24
|
-
export declare const UPDATE_CURRENT_DOCUMENT: string;
|
|
25
|
-
export interface UpdateCurrentDocument {
|
|
26
|
-
type: typeof UPDATE_CURRENT_DOCUMENT;
|
|
27
|
-
document: IDocument;
|
|
28
|
-
}
|
|
29
|
-
export declare const updateCurrentDocument: (document: IDocument) => UpdateCurrentDocument;
|
|
30
|
-
export declare const SET_RENDERER_RECT: string;
|
|
31
|
-
export interface SetRendererRect {
|
|
32
|
-
type: typeof SET_RENDERER_RECT;
|
|
33
|
-
rect: DOMRect;
|
|
34
|
-
}
|
|
35
|
-
export declare const setRendererRect: (rect: DOMRect) => SetRendererRect;
|
|
36
|
-
export declare const SET_MAIN_CONFIG: string;
|
|
37
|
-
export interface SetMainConfig {
|
|
38
|
-
type: typeof SET_MAIN_CONFIG;
|
|
39
|
-
config: IConfig;
|
|
40
|
-
}
|
|
41
|
-
export declare const setMainConfig: (config: IConfig) => SetMainConfig;
|
|
42
|
-
export declare type MainStateActions = SetAllDocuments | SetDocumentLoading | NextDocument | PreviousDocument | UpdateCurrentDocument | SetRendererRect | SetMainConfig;
|