exifreader 4.34.0 → 4.36.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 +88 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +56 -3
- package/package.json +7 -5
- package/src/canon-tags.js +20 -2
- package/src/exif-reader.js +617 -220
- package/src/image-header-jpeg.js +135 -1
- package/src/image-header-tiff.js +1 -3
- package/src/iptc-tags.js +56 -6
- package/src/loadview-pipeline.js +417 -0
- package/src/mpf-tags.js +10 -2
- package/src/pentax-tags.js +11 -2
- package/src/photoshop-tags.js +24 -1
- package/src/png-text-tags.js +28 -4
- package/src/tag-filter-config.js +124 -0
- package/src/tag-filter.js +409 -0
- package/src/tags-helpers.js +71 -18
- package/src/tags.js +29 -13
- package/src/tiff-constants.js +25 -0
- package/webpack.config.js +3 -0
package/src/mpf-tags.js
CHANGED
|
@@ -14,7 +14,13 @@ export default {
|
|
|
14
14
|
|
|
15
15
|
const ENTRY_SIZE = 16;
|
|
16
16
|
|
|
17
|
-
function read(
|
|
17
|
+
function read(
|
|
18
|
+
dataView,
|
|
19
|
+
dataOffset,
|
|
20
|
+
includeUnknown,
|
|
21
|
+
computed = false,
|
|
22
|
+
tagFilter = undefined
|
|
23
|
+
) {
|
|
18
24
|
const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
|
|
19
25
|
const tags = readIfd(
|
|
20
26
|
dataView,
|
|
@@ -23,7 +29,9 @@ function read(dataView, dataOffset, includeUnknown, computed = false) {
|
|
|
23
29
|
get0thIfdOffset(dataView, dataOffset, byteOrder),
|
|
24
30
|
byteOrder,
|
|
25
31
|
includeUnknown,
|
|
26
|
-
computed
|
|
32
|
+
computed,
|
|
33
|
+
tagFilter,
|
|
34
|
+
'mpf'
|
|
27
35
|
);
|
|
28
36
|
return addMpfImages(dataView, dataOffset, tags, byteOrder);
|
|
29
37
|
}
|
package/src/pentax-tags.js
CHANGED
|
@@ -31,7 +31,14 @@ export default {
|
|
|
31
31
|
LIK3III
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
function read(
|
|
34
|
+
function read(
|
|
35
|
+
dataView,
|
|
36
|
+
tiffHeaderOffset,
|
|
37
|
+
offset,
|
|
38
|
+
includeUnknown,
|
|
39
|
+
computed = false,
|
|
40
|
+
tagFilter = undefined
|
|
41
|
+
) {
|
|
35
42
|
// Pentax does not use the standard TIFF header offset as base for tag
|
|
36
43
|
// offsets but instead uses the start of the IFD, i.e. directly after the
|
|
37
44
|
// two byte order bytes. originOffset below is this offset.
|
|
@@ -44,7 +51,9 @@ function read(dataView, tiffHeaderOffset, offset, includeUnknown, computed = fal
|
|
|
44
51
|
originOffset + PENTAX_IFD_OFFSET,
|
|
45
52
|
byteOrder,
|
|
46
53
|
includeUnknown,
|
|
47
|
-
computed
|
|
54
|
+
computed,
|
|
55
|
+
tagFilter,
|
|
56
|
+
'makerNotes'
|
|
48
57
|
);
|
|
49
58
|
|
|
50
59
|
if (hasLevelInfoK3III(tags)) {
|
package/src/photoshop-tags.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import {getDataView, getStringFromDataView, getPascalStringFromDataView} from './utils.js';
|
|
8
8
|
import Types from './types.js';
|
|
9
9
|
import TagNames from './photoshop-tag-names.js';
|
|
10
|
+
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
10
11
|
|
|
11
12
|
export default {
|
|
12
13
|
read
|
|
@@ -18,7 +19,7 @@ const RESOURCE_LENGTH_SIZE = 4;
|
|
|
18
19
|
|
|
19
20
|
const SIGNATURE_SIZE = SIGNATURE.length;
|
|
20
21
|
|
|
21
|
-
function read(bytes, includeUnknown) {
|
|
22
|
+
function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
22
23
|
const dataView = getDataView(new Uint8Array(bytes).buffer);
|
|
23
24
|
const tags = {};
|
|
24
25
|
let offset = 0;
|
|
@@ -33,6 +34,12 @@ function read(bytes, includeUnknown) {
|
|
|
33
34
|
const resourceSize = Types.getLongAt(dataView, offset);
|
|
34
35
|
offset += RESOURCE_LENGTH_SIZE;
|
|
35
36
|
if (signature === SIGNATURE) {
|
|
37
|
+
const resolvedTagName = getTagNameForFiltering(tagId, tagName, includeUnknown);
|
|
38
|
+
if (!tagFilter.shouldParseTag('photoshop', resolvedTagName, tagId)) {
|
|
39
|
+
offset += resourceSize + (resourceSize % 2);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
const valueDataView = getDataView(dataView.buffer, offset, resourceSize);
|
|
37
44
|
const tag = {
|
|
38
45
|
id: tagId,
|
|
@@ -55,6 +62,22 @@ function read(bytes, includeUnknown) {
|
|
|
55
62
|
return tags;
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
function getTagNameForFiltering(tagId, tagName, includeUnknown) {
|
|
66
|
+
if (tagName) {
|
|
67
|
+
return tagName;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (TagNames[tagId] && TagNames[tagId].name) {
|
|
71
|
+
return TagNames[tagId].name;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (includeUnknown) {
|
|
75
|
+
return `undefined-${tagId}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
58
81
|
function getTagName(dataView, offset) {
|
|
59
82
|
// The name is encoded as a Pascal string (the string is prefixed with one
|
|
60
83
|
// byte containing the length of the string) and everything is padded with a
|
package/src/png-text-tags.js
CHANGED
|
@@ -10,6 +10,7 @@ import {TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT} from './image-header-png.js';
|
|
|
10
10
|
import Tags from './tags.js';
|
|
11
11
|
import IptcTags from './iptc-tags.js';
|
|
12
12
|
import Constants from './constants.js';
|
|
13
|
+
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
13
14
|
|
|
14
15
|
export default {
|
|
15
16
|
read
|
|
@@ -24,9 +25,17 @@ const COMPRESSION_SECTION_ITXT_EXTRA_BYTE = 1;
|
|
|
24
25
|
const COMPRESSION_FLAG_COMPRESSED = 1;
|
|
25
26
|
const EXIF_OFFSET = 6;
|
|
26
27
|
|
|
27
|
-
function read(
|
|
28
|
+
function read(
|
|
29
|
+
dataView,
|
|
30
|
+
pngTextChunks,
|
|
31
|
+
async,
|
|
32
|
+
includeUnknown,
|
|
33
|
+
computed = false,
|
|
34
|
+
tagFilter = NOOP_TAG_FILTER
|
|
35
|
+
) {
|
|
28
36
|
const tags = {};
|
|
29
37
|
const tagsPromises = [];
|
|
38
|
+
|
|
30
39
|
for (let i = 0; i < pngTextChunks.length; i++) {
|
|
31
40
|
const {offset, length, type} = pngTextChunks[i];
|
|
32
41
|
const nameAndValue = getNameAndValue(dataView, offset, length, type, async);
|
|
@@ -34,19 +43,34 @@ function read(dataView, pngTextChunks, async, includeUnknown, computed = false)
|
|
|
34
43
|
tagsPromises.push(nameAndValue.then(({name, value, description}) => {
|
|
35
44
|
try {
|
|
36
45
|
if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
|
|
46
|
+
if (!tagFilter.shouldParseGroup('exif')) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
37
49
|
return {
|
|
38
50
|
__exif: Tags.read(
|
|
39
51
|
decodeRawData(value),
|
|
40
52
|
EXIF_OFFSET,
|
|
41
53
|
includeUnknown,
|
|
42
|
-
computed
|
|
54
|
+
computed,
|
|
55
|
+
tagFilter
|
|
43
56
|
).tags
|
|
44
57
|
};
|
|
45
58
|
} else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
|
|
59
|
+
if (!tagFilter.shouldParseGroup('iptc')) {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
46
62
|
return {
|
|
47
|
-
__iptc: IptcTags.read(
|
|
63
|
+
__iptc: IptcTags.read(
|
|
64
|
+
decodeRawData(value),
|
|
65
|
+
0,
|
|
66
|
+
includeUnknown,
|
|
67
|
+
tagFilter
|
|
68
|
+
)
|
|
48
69
|
};
|
|
49
70
|
} else if (name && !isExifGroupTag(name, value) && !isIptcGroupTag(name, value)) {
|
|
71
|
+
if (!tagFilter.shouldParseGroup('png')) {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
50
74
|
return {
|
|
51
75
|
[name]: {
|
|
52
76
|
value,
|
|
@@ -61,7 +85,7 @@ function read(dataView, pngTextChunks, async, includeUnknown, computed = false)
|
|
|
61
85
|
}));
|
|
62
86
|
} else {
|
|
63
87
|
const {name, value, description} = nameAndValue;
|
|
64
|
-
if (name) {
|
|
88
|
+
if (name && tagFilter.shouldParseGroup('png')) {
|
|
65
89
|
tags[name] = {
|
|
66
90
|
value,
|
|
67
91
|
description
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
export const ID_CAPABLE_GROUPS = {
|
|
6
|
+
exif: true,
|
|
7
|
+
iptc: true,
|
|
8
|
+
photoshop: true,
|
|
9
|
+
mpf: true,
|
|
10
|
+
makerNotes: true,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const FILTER_GROUPS = {
|
|
14
|
+
exif: true,
|
|
15
|
+
iptc: true,
|
|
16
|
+
xmp: true,
|
|
17
|
+
icc: true,
|
|
18
|
+
photoshop: true,
|
|
19
|
+
makerNotes: true,
|
|
20
|
+
mpf: true,
|
|
21
|
+
file: true,
|
|
22
|
+
jfif: true,
|
|
23
|
+
png: true,
|
|
24
|
+
riff: true,
|
|
25
|
+
gif: true,
|
|
26
|
+
gps: true,
|
|
27
|
+
composite: true,
|
|
28
|
+
thumbnail: true,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const EXIF_POINTER_TAGS = {
|
|
32
|
+
exifIfdPointer: 'Exif IFD Pointer',
|
|
33
|
+
gpsInfoIfdPointer: 'GPS Info IFD Pointer',
|
|
34
|
+
interoperabilityIfdPointer: 'Interoperability IFD Pointer',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const EXIF_DEPENDENCY_TAGS = {
|
|
38
|
+
thumbnail: [
|
|
39
|
+
'JPEGInterchangeFormat',
|
|
40
|
+
'JPEGInterchangeFormatLength',
|
|
41
|
+
],
|
|
42
|
+
iptc: ['IPTC-NAA'],
|
|
43
|
+
xmp: ['ApplicationNotes'],
|
|
44
|
+
icc: ['ICC_Profile'],
|
|
45
|
+
photoshop: ['ImageSourceData', 'PhotoshopSettings'],
|
|
46
|
+
makerNotes: ['MakerNote', 'Make'],
|
|
47
|
+
gps: [
|
|
48
|
+
'GPSLatitude',
|
|
49
|
+
'GPSLatitudeRef',
|
|
50
|
+
'GPSLongitude',
|
|
51
|
+
'GPSLongitudeRef',
|
|
52
|
+
'GPSAltitude',
|
|
53
|
+
'GPSAltitudeRef',
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const COMPOSITE_DEPENDENCY_TAGS = {
|
|
58
|
+
file: ['Image Width', 'Image Height'],
|
|
59
|
+
exif: [
|
|
60
|
+
'FocalLength',
|
|
61
|
+
'FocalPlaneXResolution',
|
|
62
|
+
'FocalPlaneYResolution',
|
|
63
|
+
'FocalPlaneResolutionUnit',
|
|
64
|
+
'FocalLengthIn35mmFilm',
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function getExifTagDependenciesForInclude(includeTags) {
|
|
69
|
+
const requiredTags = Object.create(null);
|
|
70
|
+
|
|
71
|
+
if (!includeTags) {
|
|
72
|
+
return requiredTags;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(includeTags.exif) && includeTags.exif.length > 0) {
|
|
76
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
77
|
+
addPointerDependenciesFromExifTagSelectors(requiredTags, includeTags.exif);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const groupKey in EXIF_DEPENDENCY_TAGS) {
|
|
81
|
+
if (isRequestedIncludeValue(includeTags[groupKey])) {
|
|
82
|
+
const dependencyTags = EXIF_DEPENDENCY_TAGS[groupKey];
|
|
83
|
+
for (let i = 0; i < dependencyTags.length; i++) {
|
|
84
|
+
requiredTags[dependencyTags[i]] = true;
|
|
85
|
+
}
|
|
86
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isRequestedIncludeValue(includeTags.gps)) {
|
|
91
|
+
requiredTags[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
92
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return requiredTags;
|
|
96
|
+
|
|
97
|
+
function addPointerDependenciesFromExifTagSelectors(pointerSet, selectors) {
|
|
98
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
99
|
+
const selector = selectors[i];
|
|
100
|
+
if (typeof selector !== 'string') {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const selectorLower = selector.toLowerCase();
|
|
105
|
+
if (selectorLower.indexOf('gps') === 0) {
|
|
106
|
+
pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
selectorLower.indexOf('interoperability') === 0
|
|
110
|
+
|| selectorLower.indexOf('relatedimage') === 0
|
|
111
|
+
) {
|
|
112
|
+
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isRequestedIncludeValue(includeValue) {
|
|
119
|
+
if (includeValue === true) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return Array.isArray(includeValue) && includeValue.length > 0;
|
|
124
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
FILTER_GROUPS,
|
|
7
|
+
ID_CAPABLE_GROUPS,
|
|
8
|
+
COMPOSITE_DEPENDENCY_TAGS,
|
|
9
|
+
getExifTagDependenciesForInclude,
|
|
10
|
+
} from './tag-filter-config.js';
|
|
11
|
+
|
|
12
|
+
export function createTagFilter({includeTags, excludeTags} = {}) {
|
|
13
|
+
const hasIncludeTags = Boolean(includeTags);
|
|
14
|
+
const hasExcludeTags = Boolean(excludeTags);
|
|
15
|
+
const isActive = hasIncludeTags || hasExcludeTags;
|
|
16
|
+
|
|
17
|
+
const shouldReturn = Object.create(null);
|
|
18
|
+
const returnSelections = Object.create(null);
|
|
19
|
+
const parseSelections = Object.create(null);
|
|
20
|
+
|
|
21
|
+
if (!isActive) {
|
|
22
|
+
return createNoopFilter();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const shouldParseExif = hasIncludeTags
|
|
26
|
+
&& (
|
|
27
|
+
isGroupRequested(includeTags, 'iptc')
|
|
28
|
+
|| isGroupRequested(includeTags, 'xmp')
|
|
29
|
+
|| isGroupRequested(includeTags, 'icc')
|
|
30
|
+
|| isGroupRequested(includeTags, 'photoshop')
|
|
31
|
+
|| isGroupRequested(includeTags, 'makerNotes')
|
|
32
|
+
|| isGroupRequested(includeTags, 'thumbnail')
|
|
33
|
+
|| isGroupRequested(includeTags, 'gps')
|
|
34
|
+
|| isGroupRequested(includeTags, 'composite')
|
|
35
|
+
);
|
|
36
|
+
const shouldParseFile = hasIncludeTags && isGroupRequested(includeTags, 'composite');
|
|
37
|
+
|
|
38
|
+
let exifIncludeDependencies = Object.create(null);
|
|
39
|
+
if (hasIncludeTags) {
|
|
40
|
+
exifIncludeDependencies = getExifIncludeDependencies(includeTags);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let fileIncludeDependencies = Object.create(null);
|
|
44
|
+
if (hasIncludeTags && shouldParseFile) {
|
|
45
|
+
fileIncludeDependencies = buildLowercasedNameMap(
|
|
46
|
+
COMPOSITE_DEPENDENCY_TAGS.file
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const groupKey in FILTER_GROUPS) {
|
|
51
|
+
const hasIncludeEntry =
|
|
52
|
+
hasIncludeTags && Object.prototype.hasOwnProperty.call(includeTags, groupKey);
|
|
53
|
+
const hasExcludeEntry =
|
|
54
|
+
hasExcludeTags && Object.prototype.hasOwnProperty.call(excludeTags, groupKey);
|
|
55
|
+
|
|
56
|
+
let excludeValue = undefined;
|
|
57
|
+
if (hasExcludeEntry && !hasIncludeEntry) {
|
|
58
|
+
excludeValue = excludeTags[groupKey];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const returnSelection = buildSelection({
|
|
62
|
+
groupKey,
|
|
63
|
+
includeValue: hasIncludeEntry ? includeTags[groupKey] : undefined,
|
|
64
|
+
excludeValue,
|
|
65
|
+
extraIncludeNames: Object.create(null),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
shouldReturn[groupKey] = hasIncludeTags ? hasIncludeEntry : true;
|
|
69
|
+
if (hasIncludeEntry && isEmptyArray(includeTags[groupKey])) {
|
|
70
|
+
shouldReturn[groupKey] = false;
|
|
71
|
+
}
|
|
72
|
+
if (returnSelection.excludeAll) {
|
|
73
|
+
shouldReturn[groupKey] = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
returnSelections[groupKey] = returnSelection;
|
|
77
|
+
|
|
78
|
+
const parseSelection = buildSelection({
|
|
79
|
+
groupKey,
|
|
80
|
+
includeValue: getParseIncludeValue({
|
|
81
|
+
groupKey,
|
|
82
|
+
hasIncludeTags,
|
|
83
|
+
hasIncludeEntry,
|
|
84
|
+
includeTags,
|
|
85
|
+
shouldParseExif,
|
|
86
|
+
shouldParseFile,
|
|
87
|
+
}),
|
|
88
|
+
excludeValue,
|
|
89
|
+
extraIncludeNames: getExtraParseIncludeNames({
|
|
90
|
+
groupKey,
|
|
91
|
+
hasIncludeTags,
|
|
92
|
+
hasIncludeEntry,
|
|
93
|
+
shouldParseExif,
|
|
94
|
+
shouldParseFile,
|
|
95
|
+
exifIncludeDependencies,
|
|
96
|
+
fileIncludeDependencies,
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
parseSelections[groupKey] = parseSelection;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
isActive,
|
|
105
|
+
shouldReturnGroup,
|
|
106
|
+
shouldParseGroup,
|
|
107
|
+
shouldReturnTag,
|
|
108
|
+
shouldParseTag,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function shouldReturnGroup(groupKey) {
|
|
112
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return !!shouldReturn[groupKey];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shouldParseGroup(groupKey) {
|
|
120
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (shouldReturnGroup(groupKey)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (groupKey === 'exif') {
|
|
129
|
+
return shouldParseExif;
|
|
130
|
+
}
|
|
131
|
+
if (groupKey === 'file') {
|
|
132
|
+
return shouldParseFile;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function shouldReturnTag(groupKey, tagName, tagId) {
|
|
139
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!shouldReturnGroup(groupKey)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return matchesSelection(returnSelections[groupKey], tagName, tagId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function shouldParseTag(groupKey, tagName, tagId) {
|
|
151
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!shouldParseGroup(groupKey)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return matchesSelection(parseSelections[groupKey], tagName, tagId);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function createNoopFilter() {
|
|
164
|
+
return {
|
|
165
|
+
isActive: false,
|
|
166
|
+
shouldReturnGroup: alwaysTrue,
|
|
167
|
+
shouldParseGroup: alwaysTrue,
|
|
168
|
+
shouldReturnTag: alwaysTrue,
|
|
169
|
+
shouldParseTag: alwaysTrue,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
function alwaysTrue() {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const NOOP_TAG_FILTER = createNoopFilter();
|
|
178
|
+
|
|
179
|
+
function getExifIncludeDependencies(includeTags) {
|
|
180
|
+
const requiredTags = getExifTagDependenciesForInclude(includeTags);
|
|
181
|
+
|
|
182
|
+
if (isGroupRequested(includeTags, 'composite')) {
|
|
183
|
+
addRequiredTags(requiredTags, COMPOSITE_DEPENDENCY_TAGS.exif);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return requiredTags;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getParseIncludeValue({
|
|
190
|
+
groupKey,
|
|
191
|
+
hasIncludeTags,
|
|
192
|
+
hasIncludeEntry,
|
|
193
|
+
includeTags,
|
|
194
|
+
shouldParseExif,
|
|
195
|
+
shouldParseFile,
|
|
196
|
+
}) {
|
|
197
|
+
if (!hasIncludeTags) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (hasIncludeEntry) {
|
|
202
|
+
if (
|
|
203
|
+
groupKey === 'thumbnail'
|
|
204
|
+
&& Array.isArray(includeTags[groupKey])
|
|
205
|
+
) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return includeTags[groupKey];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (groupKey === 'exif' && shouldParseExif) {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
if (groupKey === 'file' && shouldParseFile) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function getExtraParseIncludeNames({
|
|
223
|
+
groupKey,
|
|
224
|
+
hasIncludeTags,
|
|
225
|
+
hasIncludeEntry,
|
|
226
|
+
shouldParseExif,
|
|
227
|
+
shouldParseFile,
|
|
228
|
+
exifIncludeDependencies,
|
|
229
|
+
fileIncludeDependencies,
|
|
230
|
+
}) {
|
|
231
|
+
if (!hasIncludeTags) {
|
|
232
|
+
return Object.create(null);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (groupKey === 'exif') {
|
|
236
|
+
if (shouldParseExif || (hasIncludeEntry && Object.keys(exifIncludeDependencies).length > 0)) {
|
|
237
|
+
return exifIncludeDependencies;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (groupKey === 'file' && shouldParseFile) {
|
|
242
|
+
return fileIncludeDependencies;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return Object.create(null);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isGroupRequested(includeTags, groupKey) {
|
|
249
|
+
if (!includeTags || !Object.prototype.hasOwnProperty.call(includeTags, groupKey)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const includeValue = includeTags[groupKey];
|
|
254
|
+
if (includeValue === true) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return Array.isArray(includeValue) && includeValue.length > 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function isEmptyArray(value) {
|
|
262
|
+
return Array.isArray(value) && value.length === 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function buildSelection({groupKey, includeValue, excludeValue, extraIncludeNames}) {
|
|
266
|
+
const isIdCapable = !!ID_CAPABLE_GROUPS[groupKey];
|
|
267
|
+
|
|
268
|
+
const selection = {
|
|
269
|
+
includeAll: false,
|
|
270
|
+
includeNames: undefined,
|
|
271
|
+
includeIds: undefined,
|
|
272
|
+
excludeAll: false,
|
|
273
|
+
excludeNames: undefined,
|
|
274
|
+
excludeIds: undefined,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
if (includeValue === true) {
|
|
278
|
+
selection.includeAll = true;
|
|
279
|
+
} else if (Array.isArray(includeValue)) {
|
|
280
|
+
selection.includeNames = Object.create(null);
|
|
281
|
+
if (isIdCapable) {
|
|
282
|
+
selection.includeIds = Object.create(null);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
for (let i = 0; i < includeValue.length; i++) {
|
|
286
|
+
addSelector(selection, includeValue[i]);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
for (const extraName in extraIncludeNames) {
|
|
290
|
+
selection.includeNames[extraName.toLowerCase()] = true;
|
|
291
|
+
}
|
|
292
|
+
} else if (extraIncludeNames && Object.keys(extraIncludeNames).length > 0) {
|
|
293
|
+
selection.includeNames = Object.create(null);
|
|
294
|
+
for (const extraName in extraIncludeNames) {
|
|
295
|
+
selection.includeNames[extraName.toLowerCase()] = true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (excludeValue === true) {
|
|
300
|
+
selection.excludeAll = true;
|
|
301
|
+
|
|
302
|
+
return selection;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (Array.isArray(excludeValue)) {
|
|
306
|
+
selection.excludeNames = Object.create(null);
|
|
307
|
+
if (isIdCapable) {
|
|
308
|
+
selection.excludeIds = Object.create(null);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (let i = 0; i < excludeValue.length; i++) {
|
|
312
|
+
addExcludeSelector(selection, excludeValue[i]);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return selection;
|
|
317
|
+
|
|
318
|
+
function addSelector(targetSelection, selector) {
|
|
319
|
+
if (typeof selector === 'number' && targetSelection.includeIds) {
|
|
320
|
+
targetSelection.includeIds[String(selector)] = true;
|
|
321
|
+
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (typeof selector === 'string') {
|
|
326
|
+
targetSelection.includeNames[selector.toLowerCase()] = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function addExcludeSelector(targetSelection, selector) {
|
|
331
|
+
if (typeof selector === 'number' && targetSelection.excludeIds) {
|
|
332
|
+
targetSelection.excludeIds[String(selector)] = true;
|
|
333
|
+
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (typeof selector === 'string') {
|
|
338
|
+
targetSelection.excludeNames[selector.toLowerCase()] = true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function matchesSelection(selection, tagName, tagId) {
|
|
344
|
+
if (selection.excludeAll) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (selection.includeAll) {
|
|
349
|
+
return !isExcluded(selection, tagName, tagId);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!selection.includeNames && !selection.includeIds) {
|
|
353
|
+
return !isExcluded(selection, tagName, tagId);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (isIncluded(selection, tagName, tagId)) {
|
|
357
|
+
return !isExcluded(selection, tagName, tagId);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isIncluded(selection, tagName, tagId) {
|
|
364
|
+
if (tagId !== undefined && selection.includeIds) {
|
|
365
|
+
if (selection.includeIds[String(tagId)]) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (tagName && selection.includeNames) {
|
|
371
|
+
if (selection.includeNames[String(tagName).toLowerCase()]) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function isExcluded(selection, tagName, tagId) {
|
|
380
|
+
if (tagId !== undefined && selection.excludeIds) {
|
|
381
|
+
if (selection.excludeIds[String(tagId)]) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (tagName && selection.excludeNames) {
|
|
387
|
+
if (selection.excludeNames[String(tagName).toLowerCase()]) {
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function buildLowercasedNameMap(names) {
|
|
396
|
+
const map = Object.create(null);
|
|
397
|
+
|
|
398
|
+
for (let i = 0; i < names.length; i++) {
|
|
399
|
+
map[names[i].toLowerCase()] = true;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return map;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function addRequiredTags(requiredTags, tags) {
|
|
406
|
+
for (let i = 0; i < tags.length; i++) {
|
|
407
|
+
requiredTags[tags[i]] = true;
|
|
408
|
+
}
|
|
409
|
+
}
|