exifreader 4.53.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 +404 -33
- 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/base64-image.js +27 -0
- 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/dom-parser.js +5 -6
- package/src/engine.js +332 -0
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +118 -1121
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header-avif.js +7 -8
- package/src/image-header-gif.js +9 -10
- package/src/image-header-heic.js +7 -8
- package/src/image-header-iso-bmff.js +71 -92
- package/src/image-header-jpeg.js +60 -59
- package/src/image-header-jxl.js +59 -65
- package/src/image-header-png.js +199 -76
- package/src/image-header-tiff.js +7 -4
- package/src/image-header-webp.js +29 -35
- package/src/image-header.js +25 -59
- 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 +197 -498
- package/src/mpf-tags.js +10 -7
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +90 -327
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +67 -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 +33 -10
- package/src/tags-helpers.js +14 -24
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +64 -119
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-tag-names.js +42 -21
- package/src/xmp-tags.js +9 -10
- package/webpack.config.js +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
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 {NOOP_TAG_FILTER} from '../tag-filter.js';
|
|
6
|
+
import {FILTER_GROUPS, EXIF_POINTER_TAGS, addExifTagNamePointers} from '../tag-filter-config.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds the filter a reader composed without the tag filter runs with. For
|
|
10
|
+
* the includeTags configs createReader builds from a composition it gives the
|
|
11
|
+
* verdicts createTagFilter gives with includeTagsIsLimit, without its
|
|
12
|
+
* name-based selection of the caller's includeTags and excludeTags.
|
|
13
|
+
*
|
|
14
|
+
* @param {object|undefined} includeTags `file` and the composed format
|
|
15
|
+
* readers' and groups' keys set to true, and a group composed by tag
|
|
16
|
+
* descriptors alone set to their names.
|
|
17
|
+
* @param {Array<string>} exifDependencies The Exif tag names the composed
|
|
18
|
+
* groups read their data from.
|
|
19
|
+
* @returns {object} The filter, NOOP_TAG_FILTER without includeTags.
|
|
20
|
+
*/
|
|
21
|
+
export function createCompositionTagFilter(includeTags, exifDependencies) {
|
|
22
|
+
if (!includeTags) {
|
|
23
|
+
return NOOP_TAG_FILTER;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const returnNames = getReturnNames(includeTags);
|
|
27
|
+
const exifNames = Array.isArray(includeTags.exif) ? includeTags.exif : [];
|
|
28
|
+
const exifParseNames = getLowercasedNames(exifNames.concat(exifDependencies, getExifPointerNames(includeTags, exifNames)));
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
isActive: true,
|
|
32
|
+
shouldReturnGroup,
|
|
33
|
+
shouldParseGroup,
|
|
34
|
+
shouldReturnTag,
|
|
35
|
+
shouldParseTag,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function shouldReturnGroup(groupKey) {
|
|
39
|
+
return !FILTER_GROUPS[groupKey] || Object.prototype.hasOwnProperty.call(includeTags, groupKey);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function shouldParseGroup(groupKey) {
|
|
43
|
+
return shouldReturnGroup(groupKey) || (groupKey === 'exif' && exifDependencies.length > 0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function shouldReturnTag(groupKey, tagName) {
|
|
47
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return shouldReturnGroup(groupKey) && matchesNames(includeTags[groupKey], returnNames[groupKey], tagName);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function shouldParseTag(groupKey, tagName) {
|
|
54
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return shouldParseGroup(groupKey)
|
|
58
|
+
&& matchesNames(includeTags[groupKey], groupKey === 'exif' ? exifParseNames : returnNames[groupKey], tagName);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getReturnNames(includeTags) {
|
|
63
|
+
const returnNames = Object.create(null);
|
|
64
|
+
for (const key in includeTags) {
|
|
65
|
+
if (Array.isArray(includeTags[key])) {
|
|
66
|
+
returnNames[key] = getLowercasedNames(includeTags[key]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return returnNames;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getLowercasedNames(names) {
|
|
73
|
+
const lowercased = Object.create(null);
|
|
74
|
+
for (let i = 0; i < names.length; i++) {
|
|
75
|
+
lowercased[names[i].toLowerCase()] = true;
|
|
76
|
+
}
|
|
77
|
+
return lowercased;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The pointers to the IFDs the descriptors and the groups' dependencies are in.
|
|
81
|
+
// The parse names are read only when there are descriptors or dependencies, so
|
|
82
|
+
// the Exif IFD pointer needs no condition.
|
|
83
|
+
function getExifPointerNames(includeTags, exifNames) {
|
|
84
|
+
const pointers = Object.create(null);
|
|
85
|
+
pointers[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(includeTags, 'gps')) {
|
|
87
|
+
pointers[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
88
|
+
}
|
|
89
|
+
for (let i = 0; i < exifNames.length; i++) {
|
|
90
|
+
addExifTagNamePointers(pointers, exifNames[i]);
|
|
91
|
+
}
|
|
92
|
+
return Object.keys(pointers);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function matchesNames(includeValue, lowercasedNames, tagName) {
|
|
96
|
+
return includeValue === true || (!!tagName && lowercasedNames[String(tagName).toLowerCase()] === true);
|
|
97
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
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 {objectAssign} from '../utils.js';
|
|
6
|
+
import {isPngTextChunkBlock} from './group-helpers.js';
|
|
7
|
+
|
|
8
|
+
const DETECTION_ORDER = ['tiff', 'jpeg', 'png', 'heic', 'avif', 'jxl', 'webp', 'gif', 'xml'];
|
|
9
|
+
// By the first kind a group consumes. The engine dispatches finder blocks in
|
|
10
|
+
// group order, so this order is part of the output.
|
|
11
|
+
const DISPATCH_ORDER = [
|
|
12
|
+
'file', 'jfif', 'exif', 'iptc', 'xmp', 'icc', 'mpf', 'pngFile', 'pngText', 'pngChunk',
|
|
13
|
+
'riff', 'gif', 'jxlFile', 'isoBmffFile', 'photoshop', 'makerNote', 'thumbnail',
|
|
14
|
+
];
|
|
15
|
+
const DERIVED_ORDER = ['gps', 'composite'];
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
createComposition,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Turns a formats table and a groups table into what the engine runs, in a
|
|
23
|
+
* fixed detection and dispatch order whatever order they are listed in. A
|
|
24
|
+
* format or reader listed twice, or brought by two formats, is used once, and
|
|
25
|
+
* a group carrying `combine` combines the engine groups, which makes the
|
|
26
|
+
* maker note groups one.
|
|
27
|
+
*
|
|
28
|
+
* @param {{formats: Array<object>, groups: Array<object>}} tables The formats,
|
|
29
|
+
* each `{header, readers}`, and the groups, block-reading ones as engine
|
|
30
|
+
* groups and derived ones without `read`.
|
|
31
|
+
* @returns {object} The engine composition (`groups`, `dispatchKind`, `rank`,
|
|
32
|
+
* `suppressions`) plus `formats` in detection order, the `derived` groups,
|
|
33
|
+
* the `composed` facts (the `formats`, `groups` and `kinds` maps, and
|
|
34
|
+
* `fromExif`, the extractor of each composed group that builds its block
|
|
35
|
+
* from the Exif tags, keyed by the kind it consumes),
|
|
36
|
+
* `decompression` (the pooled decompression the png and jxl formats
|
|
37
|
+
* bring, or undefined when neither is composed), `mergeModes` (the merge
|
|
38
|
+
* modes the engine and derived groups bring) and the engine groups'
|
|
39
|
+
* `prepareMergeBlocks` and `finishTags` steps in dispatch order.
|
|
40
|
+
*/
|
|
41
|
+
function createComposition({formats, groups}) {
|
|
42
|
+
const engineGroups = getEngineGroups(formats, groups);
|
|
43
|
+
const derived = sortByOrder(unique(groups.filter(isDerivedGroup)), DERIVED_ORDER, (group) => group.key);
|
|
44
|
+
return {
|
|
45
|
+
groups: engineGroups,
|
|
46
|
+
dispatchKind,
|
|
47
|
+
rank,
|
|
48
|
+
suppressions: getSuppressions(engineGroups),
|
|
49
|
+
formats: sortByOrder(unique(formats), DETECTION_ORDER, (format) => format.header.fileType.value),
|
|
50
|
+
derived,
|
|
51
|
+
composed: {
|
|
52
|
+
formats: getFlags(formats, (format) => [format.header.fileType.value]),
|
|
53
|
+
groups: getFlags(groups, (group) => [group.key]),
|
|
54
|
+
kinds: getFlags(engineGroups, (group) => group.consumes),
|
|
55
|
+
fromExif: getFromExif(engineGroups),
|
|
56
|
+
},
|
|
57
|
+
decompression: getDecompression(formats),
|
|
58
|
+
mergeModes: getMergeModes(engineGroups.concat(derived)),
|
|
59
|
+
prepareMergeBlocks: getSteps(engineGroups, 'prepareMergeBlocks'),
|
|
60
|
+
finishTags: getSteps(engineGroups, 'finishTags'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getEngineGroups(formats, groups) {
|
|
65
|
+
let candidates = [];
|
|
66
|
+
for (let i = 0; i < formats.length; i++) {
|
|
67
|
+
candidates = candidates.concat(formats[i].readers);
|
|
68
|
+
}
|
|
69
|
+
candidates = candidates.concat(groups.filter((group) => !isDerivedGroup(group)));
|
|
70
|
+
|
|
71
|
+
const readers = unique(candidates.filter((group) => group !== undefined));
|
|
72
|
+
return sortByOrder(combineGroups(readers), DISPATCH_ORDER, (group) => group.consumes[0]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// A derived group reads no block.
|
|
76
|
+
function isDerivedGroup(group) {
|
|
77
|
+
return group.read === undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function combineGroups(groups) {
|
|
81
|
+
for (let i = 0; i < groups.length; i++) {
|
|
82
|
+
if (groups[i].combine !== undefined) {
|
|
83
|
+
return groups[i].combine(groups);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return groups;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function unique(items) {
|
|
90
|
+
return items.filter((item, index) => items.indexOf(item) === index);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// The explicit index tie-break keeps list order, since sort is not stable on
|
|
94
|
+
// every target.
|
|
95
|
+
function sortByOrder(items, order, getName) {
|
|
96
|
+
return items
|
|
97
|
+
.map((item, index) => ({item, index, position: order.indexOf(getName(item))}))
|
|
98
|
+
.sort((a, b) => (a.position - b.position) || (a.index - b.index))
|
|
99
|
+
.map((entry) => entry.item);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A raw-profile text chunk keeps its exif or iptc kind, which the suppression
|
|
103
|
+
// rules key on, but dispatches with the other text chunks.
|
|
104
|
+
function dispatchKind(block) {
|
|
105
|
+
return isPngTextChunkBlock(block) ? 'pngText' : block.kind;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A brob Exif box ranks below an Exif box; a compressed raw-profile text chunk
|
|
109
|
+
// is not a brob, so it ranks with the eXIf chunk and the uncompressed profiles.
|
|
110
|
+
function rank(block) {
|
|
111
|
+
return block.kind === 'exif' && block.compression !== undefined && !isPngTextChunkBlock(block) ? 0 : 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function getSuppressions(groups) {
|
|
115
|
+
let suppressions = [];
|
|
116
|
+
for (let i = 0; i < groups.length; i++) {
|
|
117
|
+
if (groups[i].suppressions !== undefined) {
|
|
118
|
+
suppressions = suppressions.concat(groups[i].suppressions);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return suppressions;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getFlags(items, getNames) {
|
|
125
|
+
const flags = Object.create(null);
|
|
126
|
+
for (let i = 0; i < items.length; i++) {
|
|
127
|
+
const names = getNames(items[i]);
|
|
128
|
+
for (let j = 0; j < names.length; j++) {
|
|
129
|
+
flags[names[j]] = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return flags;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getFromExif(groups) {
|
|
136
|
+
const fromExif = Object.create(null);
|
|
137
|
+
for (let i = 0; i < groups.length; i++) {
|
|
138
|
+
if (groups[i].fromExif !== undefined) {
|
|
139
|
+
fromExif[groups[i].consumes[0]] = groups[i].fromExif;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return fromExif;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getDecompression(formats) {
|
|
146
|
+
for (let i = 0; i < formats.length; i++) {
|
|
147
|
+
if (formats[i].header.decompression !== undefined) {
|
|
148
|
+
return formats[i].header.decompression;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function getMergeModes(groups) {
|
|
155
|
+
const modes = Object.create(null);
|
|
156
|
+
for (let i = 0; i < groups.length; i++) {
|
|
157
|
+
objectAssign(modes, groups[i].mergeModes);
|
|
158
|
+
}
|
|
159
|
+
return modes;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function getSteps(groups, name) {
|
|
163
|
+
const steps = [];
|
|
164
|
+
for (let i = 0; i < groups.length; i++) {
|
|
165
|
+
if (groups[i][name] !== undefined) {
|
|
166
|
+
steps.push(groups[i][name]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return steps;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sync mode leaves the PNG compressed-text chunks, whatever their header says,
|
|
174
|
+
* and the iCCP chunk (always compressed) out of metadataRange, the
|
|
175
|
+
* potential-metadata check and the readers, as the default entry has always
|
|
176
|
+
* done in sync mode. A compressed iTXt and a brob box stay listed, and unread.
|
|
177
|
+
* Only the default entry loads in sync mode, so only it adds the result to its
|
|
178
|
+
* composition as `isHiddenInSyncMode`.
|
|
179
|
+
*
|
|
180
|
+
* @param {Array<object>} formats The formats table.
|
|
181
|
+
* @returns {function(object): boolean}
|
|
182
|
+
*/
|
|
183
|
+
export function createIsHiddenInSyncMode(formats) {
|
|
184
|
+
const formatRules = [];
|
|
185
|
+
for (let i = 0; i < formats.length; i++) {
|
|
186
|
+
if (formats[i].header.isHiddenInSyncMode !== undefined) {
|
|
187
|
+
formatRules.push(formats[i].header.isHiddenInSyncMode);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return function isHiddenInSyncMode(block) {
|
|
192
|
+
return (block.kind === 'icc' && block.compression !== undefined)
|
|
193
|
+
|| formatRules.some((isHidden) => isHidden(block));
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
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 type {Tags, ExpandedTags, ExifTags, NumberArrayTag, CanonTags, PentaxTags, CommonOptions, XmlDomParser, DecompressOptions} from '../../exif-reader.js';
|
|
6
|
+
import type * as ExifDescriptors from './tags/exif.js';
|
|
7
|
+
import type * as IptcDescriptors from './tags/iptc.js';
|
|
8
|
+
|
|
9
|
+
declare const formatBrand: unique symbol;
|
|
10
|
+
declare const formatKeys: unique symbol;
|
|
11
|
+
declare const groupBrand: unique symbol;
|
|
12
|
+
declare const groupKeys: unique symbol;
|
|
13
|
+
declare const groupMakerNotes: unique symbol;
|
|
14
|
+
declare const tagDescriptorBrand: unique symbol;
|
|
15
|
+
declare const tagDescriptorName: unique symbol;
|
|
16
|
+
declare const tagFilterBrand: unique symbol;
|
|
17
|
+
|
|
18
|
+
type ReaderTagGroup = 'exif' | 'iptc';
|
|
19
|
+
type RepeatableIptcName = 'Destination' | 'Subject Reference' | 'Supplemental Category' | 'Keywords' | 'Content Location Code'
|
|
20
|
+
| 'Content Location Name' | 'Reference Service' | 'Reference Date' | 'Reference Number' | 'By-line' | 'By-line Title'
|
|
21
|
+
| 'Contact' | 'Writer/Editor';
|
|
22
|
+
type ExifDescriptorName = DescriptorNames<(typeof ExifDescriptors)[keyof typeof ExifDescriptors], 'exif'>;
|
|
23
|
+
type IptcDescriptorName = DescriptorNames<(typeof IptcDescriptors)[keyof typeof IptcDescriptors], 'iptc'>;
|
|
24
|
+
// The names of 2:200 and 2:201 have no descriptor: they come only with the whole iptc group.
|
|
25
|
+
type IptcGroupOnlyName = 'ObjectData Preview File Format' | 'Record 2 destination' | 'ObjectData Preview File Format Version';
|
|
26
|
+
type ComposedExifTags = Pick<ExifTags, ExifDescriptorName>;
|
|
27
|
+
// A composed reader returns a repeatable IPTC dataset as an array, also when the file holds it once.
|
|
28
|
+
type ComposedIptcTags = Pick<ExifTags, Exclude<IptcDescriptorName | IptcGroupOnlyName, RepeatableIptcName>> & {[Name in RepeatableIptcName]?: NumberArrayTag[]};
|
|
29
|
+
type ComposedExpandedTags = Omit<ExpandedTags, 'exif' | 'iptc' | 'Thumbnail'> & {exif?: ComposedExifTags, iptc?: ComposedIptcTags};
|
|
30
|
+
// Omit cannot remove a named key from Tags, whose index signatures swallow the named keys.
|
|
31
|
+
type ComposedTags = Tags & {Thumbnail?: never};
|
|
32
|
+
type MakerNoteTagsByMake = {canon: CanonTags, pentax: PentaxTags};
|
|
33
|
+
type MakerNoteMake = keyof MakerNoteTagsByMake;
|
|
34
|
+
|
|
35
|
+
// Keys are the top-level keys of the grouped result a value can add; a type argument left at string means not known.
|
|
36
|
+
export interface Format<Keys extends string = string> {
|
|
37
|
+
readonly [formatBrand]: true;
|
|
38
|
+
readonly [formatKeys]?: Keys;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Group<Keys extends string = string, MakerNotes extends MakerNoteMake = MakerNoteMake> {
|
|
42
|
+
readonly [groupBrand]: true;
|
|
43
|
+
readonly [groupKeys]?: Keys;
|
|
44
|
+
readonly [groupMakerNotes]?: MakerNotes;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TagDescriptor<TagGroup extends string = ReaderTagGroup, Name extends string = string> {
|
|
48
|
+
readonly [tagDescriptorBrand]: TagGroup;
|
|
49
|
+
readonly [tagDescriptorName]?: Name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TagFilter {
|
|
53
|
+
readonly [tagFilterBrand]: true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type LoadInput = ArrayBuffer | SharedArrayBuffer | ArrayBufferView | Blob;
|
|
57
|
+
|
|
58
|
+
// `never` also rejects a domParser or decompress in options built before the call.
|
|
59
|
+
type ReaderCommonOptions = Omit<CommonOptions, 'domParser' | 'decompress'> & {domParser?: never, decompress?: never};
|
|
60
|
+
|
|
61
|
+
type FilterOptions<HasFilter extends boolean> = true extends HasFilter ? {} : {includeTags?: never, excludeTags?: never};
|
|
62
|
+
|
|
63
|
+
type ReaderOptions<HasFilter extends boolean> = ReaderCommonOptions & FilterOptions<HasFilter>;
|
|
64
|
+
|
|
65
|
+
export type LoadOptions<HasFilter extends boolean = boolean> = ReaderOptions<HasFilter>
|
|
66
|
+
& ({expanded?: true, includeOffsets?: boolean} | {expanded?: boolean, includeOffsets?: false});
|
|
67
|
+
|
|
68
|
+
export interface Reader<Grouped = ComposedExpandedTags, Flat = ComposedTags, HasFilter extends boolean = boolean, GroupedWithOffsets = Grouped> {
|
|
69
|
+
load(data: LoadInput): Promise<Grouped>;
|
|
70
|
+
load(data: LoadInput, options: ReaderOptions<HasFilter> & {expanded?: true, includeOffsets?: false}): Promise<Grouped>;
|
|
71
|
+
load(data: LoadInput, options: ReaderOptions<HasFilter> & {expanded?: true, includeOffsets?: boolean}): Promise<GroupedWithOffsets>;
|
|
72
|
+
load(data: LoadInput, options: ReaderOptions<HasFilter> & {expanded: false, includeOffsets?: false}): Promise<Flat>;
|
|
73
|
+
load(data: LoadInput, options: LoadOptions<HasFilter>): Promise<Flat | GroupedWithOffsets>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type FormatKeys<F> = F extends Format<infer Keys> ? Keys : never;
|
|
77
|
+
type GroupKeys<G> = G extends Group<infer Keys, MakerNoteMake> ? Keys : never;
|
|
78
|
+
type DescriptorGroups<T> = T extends TagDescriptor<infer TagGroup, string> ? TagGroup : never;
|
|
79
|
+
type DescriptorNames<T, TagGroup extends string> = T extends TagDescriptor<infer DescriptorGroup, infer Name>
|
|
80
|
+
? (TagGroup extends DescriptorGroup ? Name : never)
|
|
81
|
+
: never;
|
|
82
|
+
type MakerNotesOf<G> = G extends Group<infer Keys, infer MakerNotes> ? ('makerNotes' extends Keys ? MakerNotes : never) : never;
|
|
83
|
+
type HasUnknown<F, G, T> = (F extends Format<infer Keys> ? (string extends Keys ? true : never) : never)
|
|
84
|
+
| (G extends Group<infer Keys, MakerNoteMake> ? (string extends Keys ? true : never) : never)
|
|
85
|
+
| (T extends TagDescriptor<string, infer Name> ? (string extends Name ? true : never) : never);
|
|
86
|
+
type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (i: infer I) => void ? I : never;
|
|
87
|
+
// Extract narrows the inferred keys, which TypeScript bounds only by string, to the keys GroupedTags takes.
|
|
88
|
+
type ComposedKeys<F, G, T> = Extract<FormatKeys<F> | GroupKeys<G> | DescriptorGroups<T>, keyof ComposedExpandedTags>;
|
|
89
|
+
// TypeScript 5.4.5 without skipLibCheck rejects ComposedExpandedTags[K] in the group branch (TS2536); the intersection avoids it.
|
|
90
|
+
type GroupedTags<Keys extends keyof ComposedExpandedTags, F, G, T> = {
|
|
91
|
+
[K in Keys]?: K extends 'makerNotes' ? UnionToIntersection<MakerNoteTagsByMake[MakerNotesOf<G>]>
|
|
92
|
+
: K extends FormatKeys<F> | GroupKeys<G> ? ComposedExpandedTags[K & keyof ComposedExpandedTags]
|
|
93
|
+
: K extends 'iptc' ? Pick<ComposedIptcTags, Extract<DescriptorNames<T, K>, keyof ComposedIptcTags>>
|
|
94
|
+
: K extends ReaderTagGroup ? Pick<ExifTags, Extract<DescriptorNames<T, K>, keyof ExifTags>>
|
|
95
|
+
: ComposedExpandedTags[K];
|
|
96
|
+
};
|
|
97
|
+
type HasTagFilter<Filter> = [Filter] extends [undefined] ? false : true;
|
|
98
|
+
type ComposedReader<F, G, T, Filter> = Reader<
|
|
99
|
+
GroupedTags<ComposedKeys<F, G, T>, F, G, T>,
|
|
100
|
+
ComposedTags,
|
|
101
|
+
HasTagFilter<Filter>,
|
|
102
|
+
GroupedTags<ComposedKeys<F, G, T> | 'metadataRange', F, G, T>
|
|
103
|
+
>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Builds a reader of the given formats, groups and tags only.
|
|
107
|
+
*
|
|
108
|
+
* @param tables Values from 'exifreader/formats', 'exifreader/groups',
|
|
109
|
+
* 'exifreader/tags/exif' and 'exifreader/tags/iptc', `tagFilter` to let
|
|
110
|
+
* `load` take includeTags and excludeTags, `domParser` for xmp where
|
|
111
|
+
* there is no global DOMParser, and `decompress` for custom Brotli and
|
|
112
|
+
* deflate functions and maxDecompressedSize, for every load.
|
|
113
|
+
* @returns A reader whose `load` always returns a Promise, of the grouped
|
|
114
|
+
* tags unless `expanded` is false. The grouped result has only the groups
|
|
115
|
+
* and tags the tables compose; a table whose contents are not known
|
|
116
|
+
* statically (allFormats, allGroups, a `Format[]`, `Group[]` or
|
|
117
|
+
* `TagDescriptor[]`) gives every group, typed as this module's
|
|
118
|
+
* `ExpandedTags`, and `Tags`.
|
|
119
|
+
* @throws When a table holds a value that was not imported from its module,
|
|
120
|
+
* domParser is given and has no parseFromString method, or decompress is
|
|
121
|
+
* invalid.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createReader<
|
|
124
|
+
F extends readonly Format[],
|
|
125
|
+
G extends readonly Group[] = [],
|
|
126
|
+
T extends readonly TagDescriptor[] = [],
|
|
127
|
+
Filter extends TagFilter | undefined = undefined
|
|
128
|
+
>(tables: {
|
|
129
|
+
formats: F,
|
|
130
|
+
groups?: G,
|
|
131
|
+
tags?: T,
|
|
132
|
+
tagFilter?: Filter,
|
|
133
|
+
domParser?: XmlDomParser,
|
|
134
|
+
decompress?: DecompressOptions
|
|
135
|
+
}): [HasUnknown<F[number], G[number], T[number]>] extends [never]
|
|
136
|
+
? ComposedReader<F[number], G[number], T[number], Filter>
|
|
137
|
+
: Reader<ComposedExpandedTags, ComposedTags, HasTagFilter<Filter>>;
|
|
138
|
+
|
|
139
|
+
export namespace errors {
|
|
140
|
+
export class UnsupportedFormatError extends Error {}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export declare const tagFilter: TagFilter;
|
|
144
|
+
|
|
145
|
+
export type {ComposedTags as Tags, ComposedExpandedTags as ExpandedTags};
|
|
146
|
+
|
|
147
|
+
// Only the declarations marked export are exported; the brand symbols stay private.
|
|
148
|
+
export {};
|