exifreader 4.54.0 → 4.55.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.
- package/README.md +398 -27
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/engine.js +50 -106
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +112 -763
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header.js +13 -47
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +52 -192
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +5 -3
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +15 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +28 -3
- package/src/tags-helpers.js +6 -2
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +22 -85
- package/src/xmp-tag-names.js +42 -21
- package/webpack.config.js +1 -1
package/src/jfif-tags.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import {getShortAt, getByteAt} from './types.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
read
|
|
@@ -39,7 +39,7 @@ function read(dataView, jfifDataOffset) {
|
|
|
39
39
|
|
|
40
40
|
function getLength(dataView, jfifDataOffset) {
|
|
41
41
|
// The declared length is untrusted, so bound it by the bytes present.
|
|
42
|
-
return Math.min(
|
|
42
|
+
return Math.min(getShortAt(dataView, jfifDataOffset), dataView.byteLength - jfifDataOffset);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function getVersion(dataView, jfifDataOffset, length) {
|
|
@@ -50,8 +50,8 @@ function getVersion(dataView, jfifDataOffset, length) {
|
|
|
50
50
|
return undefined;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const majorVersion =
|
|
54
|
-
const minorVersion =
|
|
53
|
+
const majorVersion = getByteAt(dataView, jfifDataOffset + OFFSET);
|
|
54
|
+
const minorVersion = getByteAt(dataView, jfifDataOffset + OFFSET + 1);
|
|
55
55
|
return {
|
|
56
56
|
value: majorVersion * 0x100 + minorVersion,
|
|
57
57
|
description: majorVersion + '.' + minorVersion
|
|
@@ -66,7 +66,7 @@ function getResolutionUnit(dataView, jfifDataOffset, length) {
|
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
const value =
|
|
69
|
+
const value = getByteAt(dataView, jfifDataOffset + OFFSET);
|
|
70
70
|
return {
|
|
71
71
|
value,
|
|
72
72
|
description: getResolutionUnitDescription(value)
|
|
@@ -94,7 +94,7 @@ function getXResolution(dataView, jfifDataOffset, length) {
|
|
|
94
94
|
return undefined;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const value =
|
|
97
|
+
const value = getShortAt(dataView, jfifDataOffset + OFFSET);
|
|
98
98
|
return {
|
|
99
99
|
value,
|
|
100
100
|
description: '' + value
|
|
@@ -109,7 +109,7 @@ function getYResolution(dataView, jfifDataOffset, length) {
|
|
|
109
109
|
return undefined;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const value =
|
|
112
|
+
const value = getShortAt(dataView, jfifDataOffset + OFFSET);
|
|
113
113
|
return {
|
|
114
114
|
value,
|
|
115
115
|
description: '' + value
|
|
@@ -124,7 +124,7 @@ function getThumbnailWidth(dataView, jfifDataOffset, length) {
|
|
|
124
124
|
return undefined;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
const value =
|
|
127
|
+
const value = getByteAt(dataView, jfifDataOffset + OFFSET);
|
|
128
128
|
return {
|
|
129
129
|
value,
|
|
130
130
|
description: `${value}px`
|
|
@@ -139,7 +139,7 @@ function getThumbnailHeight(dataView, jfifDataOffset, length) {
|
|
|
139
139
|
return undefined;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
const value =
|
|
142
|
+
const value = getByteAt(dataView, jfifDataOffset + OFFSET);
|
|
143
143
|
return {
|
|
144
144
|
value,
|
|
145
145
|
description: `${value}px`
|
package/src/load-auto.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
fetchRange, nodeGetRange, readLocalFileRange, readFileObjectRange,
|
|
9
|
-
concatBuffers, isFilePathOrURL, isBrowserFileObject, isDataUri,
|
|
9
|
+
concatBuffers, isFilePathOrURL, isBrowserFileObject, isDataUri, dataUriToBuffer,
|
|
10
10
|
HTTP_STATUS_OK, HTTP_STATUS_RANGE_NOT_SATISFIABLE,
|
|
11
11
|
} from './file-loaders.js';
|
|
12
|
-
import {objectAssign,
|
|
12
|
+
import {objectAssign, assertPromiseSupport, isArrayBufferViewLike} from './utils.js';
|
|
13
13
|
|
|
14
14
|
const AUTO_INITIAL_LENGTH = 128 * 1024;
|
|
15
15
|
const AUTO_MAX_ITERATIONS = 4;
|
package/src/loadview-pipeline.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
-
import Constants from './constants.js';
|
|
6
|
-
|
|
7
5
|
// A block's position in each mode is the index of its slot. Expanded output
|
|
8
6
|
// takes its key order from the first block of each group: discovery order,
|
|
9
7
|
// with the groups an Exif block carries just before it. In flat output a later
|
|
@@ -26,19 +24,11 @@ export const MERGE_ORDER = {
|
|
|
26
24
|
],
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
// built once at import.
|
|
31
|
-
const MERGE_MODES = {
|
|
27
|
+
export const CORE_MERGE_MODES = {
|
|
32
28
|
assign: assignGroupTags,
|
|
33
29
|
merge: mergeGroupTags,
|
|
34
|
-
brobXmp: assignBrobXmpTags,
|
|
35
|
-
pngFile: mergePngFileTags,
|
|
36
|
-
pngTextTags: mergePngTextTags,
|
|
37
30
|
nested: mergeNestedBlocks,
|
|
38
|
-
|
|
39
|
-
gps: addGpsGroup,
|
|
40
|
-
composite: addCompositeGroup,
|
|
41
|
-
thumbnail: addThumbnail,
|
|
31
|
+
thumbnail: removeThumbnailTag,
|
|
42
32
|
fileType: addFileType,
|
|
43
33
|
metadataRange: addMetadataRange,
|
|
44
34
|
};
|
|
@@ -48,15 +38,22 @@ const MERGE_MODES = {
|
|
|
48
38
|
* current mode, whatever order they were pushed in.
|
|
49
39
|
*
|
|
50
40
|
* A block has a `slot` (its place in MERGE_ORDER) and a `mode` (a key of
|
|
51
|
-
*
|
|
52
|
-
* `tags`; a `nested` container has `blocks`, merged among
|
|
53
|
-
* order at the container's position
|
|
54
|
-
*
|
|
55
|
-
*
|
|
41
|
+
* `modes` or of CORE_MERGE_MODES). A tag block also has the `group` it merges
|
|
42
|
+
* into and its parsed `tags`; a `nested` container has `blocks`, merged among
|
|
43
|
+
* themselves in slot order at the container's position. A metadataRange block
|
|
44
|
+
* carries `metadataBlocks` and `metadataTruncated`.
|
|
45
|
+
*
|
|
46
|
+
* `modes` holds the modes the composed formats and groups bring, each
|
|
47
|
+
* `(tags, block, context) => tags`; one of them wins over a core mode of the
|
|
48
|
+
* same name.
|
|
56
49
|
*
|
|
57
50
|
* The top level merges in place, so a PNG with thousands of text chunk blocks
|
|
58
51
|
* stays linear.
|
|
59
52
|
*
|
|
53
|
+
* `tagFilterIsReadCap` says the tag filter is active only because includeTags
|
|
54
|
+
* caps what is read; flat Composite then reads every parsed tag block, returned
|
|
55
|
+
* or not, merged in flat order as an unfiltered load merges them.
|
|
56
|
+
*
|
|
60
57
|
* @returns {object} The tags.
|
|
61
58
|
*/
|
|
62
59
|
export function buildTagsFromMergeBlocks({
|
|
@@ -64,19 +61,21 @@ export function buildTagsFromMergeBlocks({
|
|
|
64
61
|
parsedGroups,
|
|
65
62
|
expanded,
|
|
66
63
|
tagFilter,
|
|
64
|
+
tagFilterIsReadCap,
|
|
67
65
|
dataView,
|
|
68
66
|
fileType,
|
|
69
|
-
|
|
70
|
-
pngTextIsAsync,
|
|
67
|
+
modes = {},
|
|
71
68
|
deps,
|
|
72
69
|
}) {
|
|
73
70
|
const context = {
|
|
74
71
|
parsedGroups,
|
|
75
72
|
expanded,
|
|
76
73
|
tagFilter,
|
|
74
|
+
compositeInput: tagFilterIsReadCap && !expanded && tagFilter.shouldReturnGroup('composite') ? {} : undefined,
|
|
77
75
|
dataView,
|
|
78
76
|
fileType,
|
|
79
77
|
thumbnails: [],
|
|
78
|
+
modes,
|
|
80
79
|
deps,
|
|
81
80
|
merge: createInPlaceMerge(deps),
|
|
82
81
|
};
|
|
@@ -87,7 +86,7 @@ export function buildTagsFromMergeBlocks({
|
|
|
87
86
|
tags = applyMergeMode(tags, orderedBlocks[i], context);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
return
|
|
89
|
+
return tags;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
// Sorts by position, then push order, without relying on a stable sort.
|
|
@@ -101,43 +100,16 @@ function getBlocksInMergeOrder(blocks, expanded) {
|
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
function applyMergeMode(tags, block, context) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// Expanded output gets a pngText group that copies png when the text chunks
|
|
108
|
-
// are read asynchronously, or when there are text chunks (raw profiles
|
|
109
|
-
// included) but none of them gave PNG text tags.
|
|
110
|
-
function addPngTextCopyOfPng(tags, {expanded, tagFilter, pngTextBlocks, pngTextIsAsync, deps}) {
|
|
111
|
-
if (
|
|
112
|
-
Constants.USE_PNG
|
|
113
|
-
&& expanded
|
|
114
|
-
&& pngTextIsAsync
|
|
115
|
-
&& tagFilter.shouldReturnGroup('png')
|
|
116
|
-
&& tags.png
|
|
117
|
-
) {
|
|
118
|
-
tags.pngText = deps.objectAssign({}, tags.png);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
Constants.USE_PNG
|
|
123
|
-
&& expanded
|
|
124
|
-
&& tagFilter.shouldReturnGroup('png')
|
|
125
|
-
&& deps.hasPngTextData(pngTextBlocks)
|
|
126
|
-
&& tags.png
|
|
127
|
-
&& !tags.pngText
|
|
128
|
-
) {
|
|
129
|
-
tags.pngText = deps.objectAssign({}, tags.png);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return tags;
|
|
103
|
+
const mode = context.modes[block.mode] || CORE_MERGE_MODES[block.mode];
|
|
104
|
+
return mode(tags, block, context);
|
|
133
105
|
}
|
|
134
106
|
|
|
135
107
|
/**
|
|
136
108
|
* Merges one block into the tags with the function its mode names.
|
|
137
109
|
*
|
|
138
110
|
* @param {object} context The block, the tags so far and the merge state; see
|
|
139
|
-
* buildTagsFromMergeBlocks for the block shape
|
|
140
|
-
* merge and `thumbnails` to a new list.
|
|
111
|
+
* buildTagsFromMergeBlocks for the block shape and `modes`. `merge` defaults
|
|
112
|
+
* to a copying merge and `thumbnails` to a new list.
|
|
141
113
|
* @returns {object} The tags, which flat output replaces rather than mutates.
|
|
142
114
|
*/
|
|
143
115
|
export function mergeBlock({
|
|
@@ -149,6 +121,7 @@ export function mergeBlock({
|
|
|
149
121
|
dataView,
|
|
150
122
|
fileType,
|
|
151
123
|
thumbnails = [],
|
|
124
|
+
modes = {},
|
|
152
125
|
deps,
|
|
153
126
|
merge = createCopyingMerge(deps),
|
|
154
127
|
}) {
|
|
@@ -159,15 +132,22 @@ export function mergeBlock({
|
|
|
159
132
|
dataView,
|
|
160
133
|
fileType,
|
|
161
134
|
thumbnails,
|
|
135
|
+
modes,
|
|
162
136
|
deps,
|
|
163
137
|
merge,
|
|
164
138
|
});
|
|
165
139
|
}
|
|
166
140
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Merges a tag block by assigning its group: it writes the parsed group
|
|
143
|
+
* whether or not the group is returned, since gps, composite and metadataRange
|
|
144
|
+
* read it, adds the tags to the Composite input and merges the returned tags.
|
|
145
|
+
*
|
|
146
|
+
* @returns {object} The tags.
|
|
147
|
+
*/
|
|
148
|
+
export function assignGroupTags(tags, block, context) {
|
|
170
149
|
context.parsedGroups[block.group] = block.tags;
|
|
150
|
+
addToCompositeInput(block.tags, context);
|
|
171
151
|
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
172
152
|
return tags;
|
|
173
153
|
}
|
|
@@ -176,6 +156,16 @@ function assignGroupTags(tags, block, context) {
|
|
|
176
156
|
return mergeAssignGroup(tags, block.group, returnedTags, context.expanded, context.deps);
|
|
177
157
|
}
|
|
178
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Adds a block's parsed tags to the flat Composite input, when the merge
|
|
161
|
+
* collects one (see tagFilterIsReadCap in buildTagsFromMergeBlocks).
|
|
162
|
+
*/
|
|
163
|
+
export function addToCompositeInput(blockTags, context) {
|
|
164
|
+
if (context.compositeInput) {
|
|
165
|
+
context.deps.objectAssign(context.compositeInput, blockTags);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
179
169
|
export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
180
170
|
if (expanded) {
|
|
181
171
|
tags[groupKey] = returnedTags;
|
|
@@ -188,7 +178,7 @@ export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
|
188
178
|
|
|
189
179
|
// Every XMP block drops the raw packet in flat output.
|
|
190
180
|
function getTagsForFlat(groupKey, returnedTags, deps) {
|
|
191
|
-
if (
|
|
181
|
+
if (groupKey !== 'xmp') {
|
|
192
182
|
return returnedTags;
|
|
193
183
|
}
|
|
194
184
|
const xmpTagsWithoutRaw = deps.objectAssign({}, returnedTags);
|
|
@@ -199,6 +189,7 @@ function getTagsForFlat(groupKey, returnedTags, deps) {
|
|
|
199
189
|
|
|
200
190
|
function mergeGroupTags(tags, block, context) {
|
|
201
191
|
context.merge.group(context.parsedGroups, block.group, block.tags);
|
|
192
|
+
addToCompositeInput(block.tags, context);
|
|
202
193
|
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
203
194
|
return tags;
|
|
204
195
|
}
|
|
@@ -213,42 +204,6 @@ function mergeGroupTags(tags, block, context) {
|
|
|
213
204
|
return context.merge.topLevel(tags, getTagsForFlat(block.group, returnedTags, context.deps));
|
|
214
205
|
}
|
|
215
206
|
|
|
216
|
-
// In expanded output a brob XMP replaces the xmp group, in flat output it
|
|
217
|
-
// merges key by key, and an empty, failed or over-bound one leaves the earlier
|
|
218
|
-
// xmp group as it is.
|
|
219
|
-
function assignBrobXmpTags(tags, block, context) {
|
|
220
|
-
if (!Constants.USE_JXL) {
|
|
221
|
-
return tags;
|
|
222
|
-
}
|
|
223
|
-
if (!block.tags || Object.keys(block.tags).length === 0) {
|
|
224
|
-
return tags;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return assignGroupTags(tags, block, context);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// The png group gathers the file, text and chunk tags; pngFile keeps the file
|
|
231
|
-
// tags alone.
|
|
232
|
-
function mergePngFileTags(tags, block, context) {
|
|
233
|
-
if (!Constants.USE_PNG) {
|
|
234
|
-
return tags;
|
|
235
|
-
}
|
|
236
|
-
context.parsedGroups.pngFile = block.tags;
|
|
237
|
-
if (!context.tagFilter.shouldReturnGroup('png')) {
|
|
238
|
-
return tags;
|
|
239
|
-
}
|
|
240
|
-
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
241
|
-
|
|
242
|
-
if (context.expanded) {
|
|
243
|
-
context.merge.group(tags, 'png', returnedTags);
|
|
244
|
-
tags.pngFile = returnedTags;
|
|
245
|
-
|
|
246
|
-
return tags;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return context.merge.topLevel(tags, returnedTags);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
207
|
// The blocks of one container (an Exif block with the groups it carries, or
|
|
253
208
|
// the uncompressed text chunks of a PNG) merge among themselves in slot order.
|
|
254
209
|
function mergeNestedBlocks(tags, block, context) {
|
|
@@ -265,112 +220,17 @@ function mergeEmbeddedBlocks(tags, blocks, context) {
|
|
|
265
220
|
return tags;
|
|
266
221
|
}
|
|
267
222
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
275
|
-
|
|
276
|
-
if (context.expanded) {
|
|
277
|
-
context.merge.group(tags, 'png', returnedTags);
|
|
278
|
-
if (Object.keys(returnedTags).length > 0) {
|
|
279
|
-
context.merge.group(tags, 'pngText', returnedTags);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return tags;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return context.merge.topLevel(tags, returnedTags);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function addThumbnailCandidate(tags, block, context) {
|
|
289
|
-
context.thumbnails.push({rank: block.rank, thumbnail: block.tags});
|
|
290
|
-
return tags;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Expanded output only, derived from the parsed Exif group.
|
|
294
|
-
function addGpsGroup(tags, block, context) {
|
|
295
|
-
if (
|
|
296
|
-
Constants.USE_EXIF
|
|
297
|
-
&& context.expanded
|
|
298
|
-
&& context.tagFilter.shouldReturnGroup('gps')
|
|
299
|
-
&& context.parsedGroups.exif
|
|
300
|
-
) {
|
|
301
|
-
const gpsGroup = context.deps.getGpsGroupFromExifTags(context.parsedGroups.exif);
|
|
302
|
-
if (gpsGroup) {
|
|
303
|
-
tags.gps = context.deps.filterTagsForReturn('gps', gpsGroup, context.tagFilter);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return tags;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Composite reads the merged tags, or with an active tag filter the parsed exif
|
|
311
|
-
// and file groups.
|
|
312
|
-
function addCompositeGroup(tags, block, context) {
|
|
313
|
-
if (!(Constants.USE_EXIF || Constants.USE_XMP) || !context.tagFilter.shouldReturnGroup('composite')) {
|
|
314
|
-
return tags;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
let compositeInput = tags;
|
|
318
|
-
let compositeInputExpanded = context.expanded;
|
|
319
|
-
if (context.tagFilter.isActive) {
|
|
320
|
-
compositeInput = {exif: context.parsedGroups.exif, file: context.parsedGroups.file};
|
|
321
|
-
compositeInputExpanded = true;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const composite = context.deps.Composite.get(compositeInput, compositeInputExpanded);
|
|
325
|
-
if (!composite) {
|
|
326
|
-
return tags;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const returnedCompositeTags = context.deps.filterTagsForReturn('composite', composite, context.tagFilter);
|
|
330
|
-
|
|
331
|
-
return mergeAssignGroup(tags, 'composite', returnedCompositeTags, context.expanded, context.deps);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// The main thumbnail when it has an image, else the first embedded Exif
|
|
335
|
-
// thumbnail with one, else the main thumbnail without an image.
|
|
336
|
-
function addThumbnail(tags, block, context) {
|
|
223
|
+
/**
|
|
224
|
+
* The core thumbnail mode, which the thumbnail group's mode also runs.
|
|
225
|
+
*
|
|
226
|
+
* @returns {object} The tags without a top-level Thumbnail tag.
|
|
227
|
+
*/
|
|
228
|
+
export function removeThumbnailTag(tags) {
|
|
337
229
|
// Flat output can already hold an XMP or PNG text tag named Thumbnail.
|
|
338
230
|
delete tags.Thumbnail;
|
|
339
|
-
|
|
340
|
-
if (
|
|
341
|
-
!context.tagFilter.shouldReturnGroup('thumbnail')
|
|
342
|
-
|| !context.tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
343
|
-
) {
|
|
344
|
-
return tags;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const thumbnail = selectThumbnail(context.thumbnails);
|
|
348
|
-
if (thumbnail) {
|
|
349
|
-
tags.Thumbnail = thumbnail;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
231
|
return tags;
|
|
353
232
|
}
|
|
354
233
|
|
|
355
|
-
function selectThumbnail(candidates) {
|
|
356
|
-
if (!(Constants.USE_EXIF && Constants.USE_THUMBNAIL)) {
|
|
357
|
-
return undefined;
|
|
358
|
-
}
|
|
359
|
-
const main = candidates.filter((candidate) => candidate.rank === 'main')[0];
|
|
360
|
-
if (main && hasImage(main.thumbnail)) {
|
|
361
|
-
return main.thumbnail;
|
|
362
|
-
}
|
|
363
|
-
const embedded = candidates.filter((candidate) => candidate.rank === 'embedded' && hasImage(candidate.thumbnail))[0];
|
|
364
|
-
if (embedded) {
|
|
365
|
-
return embedded.thumbnail;
|
|
366
|
-
}
|
|
367
|
-
return main ? main.thumbnail : undefined;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function hasImage(thumbnail) {
|
|
371
|
-
return !!thumbnail && !!thumbnail.image;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
234
|
function addFileType(tags, block, context) {
|
|
375
235
|
// Flat output can already hold an XMP or PNG text tag named FileType.
|
|
376
236
|
delete tags.FileType;
|
package/src/node-require.js
CHANGED
|
@@ -35,11 +35,15 @@ function optionalPackage(name) {
|
|
|
35
35
|
// A loader throws where its mechanism is missing (no process, no
|
|
36
36
|
// getBuiltinModule, no mainModule), which moves on to the next one. process is
|
|
37
37
|
// never named as a free variable: Parcel 2 and webpack 4 would then bundle a
|
|
38
|
-
// process polyfill into browser builds of the source.
|
|
38
|
+
// process polyfill into browser builds of the source. The empty object a
|
|
39
|
+
// bundler gives for a module the browser field maps to false also moves on.
|
|
39
40
|
function firstLoaded(name, loaders) {
|
|
40
41
|
for (let i = 0; i < loaders.length; i++) {
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
+
const loaded = loaders[i](name);
|
|
44
|
+
if (!isEmptyStub(loaded)) {
|
|
45
|
+
return loaded;
|
|
46
|
+
}
|
|
43
47
|
} catch (error) {
|
|
44
48
|
// Try the next loader.
|
|
45
49
|
}
|
|
@@ -47,6 +51,15 @@ function firstLoaded(name, loaders) {
|
|
|
47
51
|
return undefined;
|
|
48
52
|
}
|
|
49
53
|
|
|
54
|
+
// Not typeof 'object': Babel would inline its _typeof helper into this module for that.
|
|
55
|
+
function isEmptyStub(loaded) {
|
|
56
|
+
if (Object(loaded) !== loaded) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const prototype = Object.getPrototypeOf(loaded);
|
|
60
|
+
return (prototype === Object.prototype || prototype === null) && Object.keys(loaded).length === 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
50
63
|
// Literal names make webpack emit require('fs') and so on, which bundlers and
|
|
51
64
|
// file tracers follow. No typeof guard: webpack may not rewrite the identifier there.
|
|
52
65
|
// A try in this function makes bundlers treat fs, @xmldom/xmldom and its package.json as optional.
|
package/src/png-text-tags.js
CHANGED
|
@@ -24,7 +24,8 @@ const MAX_COMPRESSED_TEXT_CHUNKS = 255;
|
|
|
24
24
|
*
|
|
25
25
|
* @param {object} block The finder's block.
|
|
26
26
|
* @param {object} context The load context: `dataView`, `tagFilter` and the
|
|
27
|
-
* pooled `decompress`.
|
|
27
|
+
* pooled `decompress`. `read` counts the load's compressed chunks on it as
|
|
28
|
+
* `compressedPngTextChunks`, created on first use.
|
|
28
29
|
* @returns {{tags: object, blocks?: Array<object>}|Promise<{tags: object, blocks?: Array<object>}>|undefined}
|
|
29
30
|
* The text tag, parse-filtered, or for a raw profile no tags and an emitted
|
|
30
31
|
* exif or iptc block whose `getDataView()` decodes the profile on demand
|
|
@@ -38,10 +39,11 @@ function read(block, context) {
|
|
|
38
39
|
if (block.compression === undefined) {
|
|
39
40
|
return classify(getUncompressedTag(context.dataView, block.text), context, false);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
const count = context.compressedPngTextChunks || 0;
|
|
43
|
+
if (count >= MAX_COMPRESSED_TEXT_CHUNKS) {
|
|
42
44
|
return undefined;
|
|
43
45
|
}
|
|
44
|
-
context.compressedPngTextChunks
|
|
46
|
+
context.compressedPngTextChunks = count + 1;
|
|
45
47
|
return decompressTextChunk(context, block).then((tag) => classify(tag, context, true));
|
|
46
48
|
}
|
|
47
49
|
|
package/src/tag-filter-config.js
CHANGED
|
@@ -36,8 +36,8 @@ export const EXIF_POINTER_TAGS = {
|
|
|
36
36
|
|
|
37
37
|
// The two id sets mirror the keys of tag-names-gps-ifd.js and tag-names-interoperability-ifd.js.
|
|
38
38
|
// Importing those files here instead would bring them into builds that leave Exif out.
|
|
39
|
-
const GPS_IFD_TAG_IDS = getIdLookup([[0x0000, 0x001f]]);
|
|
40
|
-
const INTEROPERABILITY_IFD_TAG_IDS = getIdLookup([[0x0001, 0x0002], [0x1000, 0x1002]]);
|
|
39
|
+
const GPS_IFD_TAG_IDS = /* #__PURE__ */ getIdLookup([[0x0000, 0x001f]]);
|
|
40
|
+
const INTEROPERABILITY_IFD_TAG_IDS = /* #__PURE__ */ getIdLookup([[0x0001, 0x0002], [0x1000, 0x1002]]);
|
|
41
41
|
|
|
42
42
|
function getIdLookup(idRanges) {
|
|
43
43
|
const lookup = Object.create(null);
|
|
@@ -122,24 +122,33 @@ export function getExifTagDependenciesForInclude(includeTags) {
|
|
|
122
122
|
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
if (typeof selector
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const selectorLower = selector.toLowerCase();
|
|
130
|
-
if (selectorLower.indexOf('gps') === 0) {
|
|
131
|
-
pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
132
|
-
}
|
|
133
|
-
if (
|
|
134
|
-
selectorLower.indexOf('interoperability') === 0
|
|
135
|
-
|| selectorLower.indexOf('relatedimage') === 0
|
|
136
|
-
) {
|
|
137
|
-
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
125
|
+
if (typeof selector === 'string') {
|
|
126
|
+
addExifTagNamePointers(pointerSet, selector);
|
|
138
127
|
}
|
|
139
128
|
}
|
|
140
129
|
}
|
|
141
130
|
}
|
|
142
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Adds to pointerSet the sub-IFD pointer an Exif tag name needs, judged by the
|
|
134
|
+
* name's prefix.
|
|
135
|
+
*
|
|
136
|
+
* @param {object} pointerSet Pointer tag names, set to true.
|
|
137
|
+
* @param {string} name The tag name.
|
|
138
|
+
*/
|
|
139
|
+
export function addExifTagNamePointers(pointerSet, name) {
|
|
140
|
+
const nameLower = name.toLowerCase();
|
|
141
|
+
if (nameLower.indexOf('gps') === 0) {
|
|
142
|
+
pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
143
|
+
}
|
|
144
|
+
if (
|
|
145
|
+
nameLower.indexOf('interoperability') === 0
|
|
146
|
+
|| nameLower.indexOf('relatedimage') === 0
|
|
147
|
+
) {
|
|
148
|
+
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
143
152
|
function isRequestedIncludeValue(includeValue) {
|
|
144
153
|
if (includeValue === true) {
|
|
145
154
|
return true;
|
package/src/tag-filter.js
CHANGED
|
@@ -11,7 +11,17 @@ import {
|
|
|
11
11
|
getExifTagDependenciesForInclude,
|
|
12
12
|
} from './tag-filter-config.js';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Builds the filter the readers and the merge consult for includeTags and
|
|
16
|
+
* excludeTags.
|
|
17
|
+
*
|
|
18
|
+
* @param {{includeTags: (object|undefined), excludeTags: (object|undefined), includeTagsIsLimit: (boolean|undefined)}} options
|
|
19
|
+
* With `includeTagsIsLimit`, includeTags only caps what is read and
|
|
20
|
+
* excludeTags applies to every group; without it a group listed in both
|
|
21
|
+
* ignores its excludeTags entry.
|
|
22
|
+
* @returns {object} The filter.
|
|
23
|
+
*/
|
|
24
|
+
export function createTagFilter({includeTags, excludeTags, includeTagsIsLimit} = {}) {
|
|
15
25
|
const hasIncludeTags = Boolean(includeTags);
|
|
16
26
|
const hasExcludeTags = Boolean(excludeTags);
|
|
17
27
|
const isActive = hasIncludeTags || hasExcludeTags;
|
|
@@ -51,12 +61,14 @@ export function createTagFilter({includeTags, excludeTags} = {}) {
|
|
|
51
61
|
|
|
52
62
|
for (const groupKey in FILTER_GROUPS) {
|
|
53
63
|
const hasIncludeEntry =
|
|
54
|
-
hasIncludeTags
|
|
64
|
+
hasIncludeTags
|
|
65
|
+
&& Object.prototype.hasOwnProperty.call(includeTags, groupKey)
|
|
66
|
+
&& !!includeTags[groupKey];
|
|
55
67
|
const hasExcludeEntry =
|
|
56
68
|
hasExcludeTags && Object.prototype.hasOwnProperty.call(excludeTags, groupKey);
|
|
57
69
|
|
|
58
70
|
let excludeValue = undefined;
|
|
59
|
-
if (hasExcludeEntry && !hasIncludeEntry) {
|
|
71
|
+
if (hasExcludeEntry && (!hasIncludeEntry || includeTagsIsLimit)) {
|
|
60
72
|
excludeValue = excludeTags[groupKey];
|
|
61
73
|
}
|
|
62
74
|
|