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.
Files changed (100) hide show
  1. package/README.md +404 -33
  2. package/bin/analyze.js +139 -9
  3. package/bin/build-pages.js +21 -35
  4. package/bin/cli.js +81 -13
  5. package/bin/generate-tag-modules.js +287 -0
  6. package/dist/exif-reader.js +1 -1
  7. package/dist/exif-reader.js.map +1 -1
  8. package/exif-reader.d.ts +213 -38
  9. package/package.json +71 -11
  10. package/src/base64-image.js +27 -0
  11. package/src/composable/brand.js +10 -0
  12. package/src/composable/composition-tag-filter.js +97 -0
  13. package/src/composable/composition.js +195 -0
  14. package/src/composable/core.d.ts +148 -0
  15. package/src/composable/core.js +526 -0
  16. package/src/composable/exif-block-reader.js +197 -0
  17. package/src/composable/formats/avif.js +19 -0
  18. package/src/composable/formats/gif.js +28 -0
  19. package/src/composable/formats/heic.js +19 -0
  20. package/src/composable/formats/iso-bmff-file-reader.js +14 -0
  21. package/src/composable/formats/jpeg.js +55 -0
  22. package/src/composable/formats/jxl.js +30 -0
  23. package/src/composable/formats/png.js +187 -0
  24. package/src/composable/formats/tiff.js +18 -0
  25. package/src/composable/formats/webp.js +28 -0
  26. package/src/composable/formats/xml.js +18 -0
  27. package/src/composable/formats.d.ts +17 -0
  28. package/src/composable/formats.js +17 -0
  29. package/src/composable/group-helpers.js +129 -0
  30. package/src/composable/groups/canon.js +26 -0
  31. package/src/composable/groups/composite.js +43 -0
  32. package/src/composable/groups/exif.js +48 -0
  33. package/src/composable/groups/gps.js +75 -0
  34. package/src/composable/groups/icc.js +52 -0
  35. package/src/composable/groups/iptc.js +86 -0
  36. package/src/composable/groups/maker-notes.js +21 -0
  37. package/src/composable/groups/mpf.js +25 -0
  38. package/src/composable/groups/pentax.js +34 -0
  39. package/src/composable/groups/photoshop.js +18 -0
  40. package/src/composable/groups/thumbnail.js +131 -0
  41. package/src/composable/groups/xmp.js +118 -0
  42. package/src/composable/groups.d.ts +20 -0
  43. package/src/composable/groups.js +105 -0
  44. package/src/composable/iptc-block-reader.js +44 -0
  45. package/src/composable/read-view.js +165 -0
  46. package/src/composable/tag-binding-name.js +17 -0
  47. package/src/composable/tags/exif.d.ts +295 -0
  48. package/src/composable/tags/exif.js +396 -0
  49. package/src/composable/tags/iptc.d.ts +84 -0
  50. package/src/composable/tags/iptc.js +109 -0
  51. package/src/composable/value-budget.js +24 -0
  52. package/src/composite.js +2 -2
  53. package/src/decompression.js +60 -0
  54. package/src/dom-parser.js +5 -6
  55. package/src/engine.js +332 -0
  56. package/src/errors.js +8 -2
  57. package/src/exif-reader.d.ts +8 -0
  58. package/src/exif-reader.js +118 -1121
  59. package/src/file-loaders.js +74 -1
  60. package/src/file-tags.js +9 -9
  61. package/src/image-header-avif.js +7 -8
  62. package/src/image-header-gif.js +9 -10
  63. package/src/image-header-heic.js +7 -8
  64. package/src/image-header-iso-bmff.js +71 -92
  65. package/src/image-header-jpeg.js +60 -59
  66. package/src/image-header-jxl.js +59 -65
  67. package/src/image-header-png.js +199 -76
  68. package/src/image-header-tiff.js +7 -4
  69. package/src/image-header-webp.js +29 -35
  70. package/src/image-header.js +25 -59
  71. package/src/iptc-tag-names-descriptions.js +334 -0
  72. package/src/iptc-tag-names.js +50 -306
  73. package/src/iptc-tags.js +41 -27
  74. package/src/jfif-tags.js +9 -9
  75. package/src/load-auto.js +2 -2
  76. package/src/loadview-pipeline.js +197 -498
  77. package/src/mpf-tags.js +10 -7
  78. package/src/node-require.js +15 -2
  79. package/src/png-text-tags.js +90 -327
  80. package/src/tag-filter-config.js +24 -15
  81. package/src/tag-filter.js +67 -3
  82. package/src/tag-names-0th-ifd-descriptions.js +232 -0
  83. package/src/tag-names-0th-ifd.js +49 -173
  84. package/src/tag-names-common.js +263 -211
  85. package/src/tag-names-exif-ifd-descriptions.js +249 -0
  86. package/src/tag-names-exif-ifd.js +55 -187
  87. package/src/tag-names-gps-ifd-descriptions.js +156 -0
  88. package/src/tag-names-gps-ifd.js +39 -146
  89. package/src/tag-names-utils.js +33 -10
  90. package/src/tags-helpers.js +14 -24
  91. package/src/tags.js +23 -11
  92. package/src/thumbnail.js +7 -5
  93. package/src/types.js +2 -0
  94. package/src/unsupported-format-error.js +21 -0
  95. package/src/utils.js +64 -119
  96. package/src/writer/exif-tag-table.js +321 -0
  97. package/src/xml.js +12 -15
  98. package/src/xmp-tag-names.js +42 -21
  99. package/src/xmp-tags.js +9 -10
  100. package/webpack.config.js +1 -1
@@ -0,0 +1,109 @@
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
+ // Generated by bin/generate-tag-modules.js from the tag dictionaries; do not edit.
6
+
7
+ import {
8
+ getARMIdentifierDescription,
9
+ getARMVersionDescription,
10
+ getActionAdvisedDescription,
11
+ getAudioDurationDescription,
12
+ getAudioSamplingRateDescription,
13
+ getAudioSamplingResolutionDescription,
14
+ getAudioTypeDescription,
15
+ getCreationDate,
16
+ getCreationTime,
17
+ getEditorialUpdateDescription,
18
+ getEncodingName,
19
+ getFileFormatDescription,
20
+ getFileFormatVersionDescription,
21
+ getImageOrientationDescription,
22
+ getMaxSubfileSizeDescription,
23
+ getMaximumObjectDataSizeDescription,
24
+ getModelVersionDescription,
25
+ getObjectCycleDescription,
26
+ getObjectDataSizeAnnouncedDescription,
27
+ getRasterizedCaptionDescription,
28
+ getRecordVersionDescription,
29
+ getSizeModeDescription,
30
+ getSubjectReferenceDescription
31
+ } from '../../iptc-tag-names-descriptions.js';
32
+ import {iptcBlockReader} from '../iptc-block-reader.js';
33
+
34
+ export const ModelVersion = {name: 'Model Version', ids: [0x0100], group: 'iptc', dictionary: 'iptc', description: getModelVersionDescription, reader: iptcBlockReader};
35
+ export const Destination = {name: 'Destination', ids: [0x0105], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
36
+ export const FileFormat = {name: 'File Format', ids: [0x0114], group: 'iptc', dictionary: 'iptc', description: getFileFormatDescription, reader: iptcBlockReader};
37
+ export const FileFormatVersion = {name: 'File Format Version', ids: [0x0116], group: 'iptc', dictionary: 'iptc', description: getFileFormatVersionDescription, reader: iptcBlockReader};
38
+ export const ServiceIdentifier = {name: 'Service Identifier', ids: [0x011e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
39
+ export const EnvelopeNumber = {name: 'Envelope Number', ids: [0x0128], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
40
+ export const ProductID = {name: 'Product ID', ids: [0x0132], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
41
+ export const EnvelopePriority = {name: 'Envelope Priority', ids: [0x013c], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
42
+ export const DateSent = {name: 'Date Sent', ids: [0x0146], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
43
+ export const TimeSent = {name: 'Time Sent', ids: [0x0150], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
44
+ export const CodedCharacterSet = {name: 'Coded Character Set', ids: [0x015a], group: 'iptc', dictionary: 'iptc', description: getEncodingName, reader: iptcBlockReader};
45
+ export const UNO = {name: 'UNO', ids: [0x0164], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
46
+ export const ARMIdentifier = {name: 'ARM Identifier', ids: [0x0178], group: 'iptc', dictionary: 'iptc', description: getARMIdentifierDescription, reader: iptcBlockReader};
47
+ export const ARMVersion = {name: 'ARM Version', ids: [0x017a], group: 'iptc', dictionary: 'iptc', description: getARMVersionDescription, reader: iptcBlockReader};
48
+ export const RecordVersion = {name: 'Record Version', ids: [0x0200], group: 'iptc', dictionary: 'iptc', description: getRecordVersionDescription, reader: iptcBlockReader};
49
+ export const ObjectTypeReference = {name: 'Object Type Reference', ids: [0x0203], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
50
+ export const ObjectAttributeReference = {name: 'Object Attribute Reference', ids: [0x0204], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
51
+ export const ObjectName = {name: 'Object Name', ids: [0x0205], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
52
+ export const EditStatus = {name: 'Edit Status', ids: [0x0207], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
53
+ export const EditorialUpdate = {name: 'Editorial Update', ids: [0x0208], group: 'iptc', dictionary: 'iptc', description: getEditorialUpdateDescription, reader: iptcBlockReader};
54
+ export const Urgency = {name: 'Urgency', ids: [0x020a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
55
+ export const SubjectReference = {name: 'Subject Reference', ids: [0x020c], group: 'iptc', dictionary: 'iptc', description: getSubjectReferenceDescription, repeatable: true, reader: iptcBlockReader};
56
+ export const Category = {name: 'Category', ids: [0x020f], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
57
+ export const SupplementalCategory = {name: 'Supplemental Category', ids: [0x0214], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
58
+ export const FixtureIdentifier = {name: 'Fixture Identifier', ids: [0x0216], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
59
+ export const Keywords = {name: 'Keywords', ids: [0x0219], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
60
+ export const ContentLocationCode = {name: 'Content Location Code', ids: [0x021a], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
61
+ export const ContentLocationName = {name: 'Content Location Name', ids: [0x021b], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
62
+ export const ReleaseDate = {name: 'Release Date', ids: [0x021e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
63
+ export const ReleaseTime = {name: 'Release Time', ids: [0x0223], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
64
+ export const ExpirationDate = {name: 'Expiration Date', ids: [0x0225], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
65
+ export const ExpirationTime = {name: 'Expiration Time', ids: [0x0226], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
66
+ export const SpecialInstructions = {name: 'Special Instructions', ids: [0x0228], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
67
+ export const ActionAdvised = {name: 'Action Advised', ids: [0x022a], group: 'iptc', dictionary: 'iptc', description: getActionAdvisedDescription, reader: iptcBlockReader};
68
+ export const ReferenceService = {name: 'Reference Service', ids: [0x022d], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
69
+ export const ReferenceDate = {name: 'Reference Date', ids: [0x022f], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
70
+ export const ReferenceNumber = {name: 'Reference Number', ids: [0x0232], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
71
+ export const DateCreated = {name: 'Date Created', ids: [0x0237], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
72
+ export const TimeCreated = {name: 'Time Created', ids: [0x023c], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
73
+ export const DigitalCreationDate = {name: 'Digital Creation Date', ids: [0x023e], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
74
+ export const DigitalCreationTime = {name: 'Digital Creation Time', ids: [0x023f], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
75
+ export const OriginatingProgram = {name: 'Originating Program', ids: [0x0241], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
76
+ export const ProgramVersion = {name: 'Program Version', ids: [0x0246], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
77
+ export const ObjectCycle = {name: 'Object Cycle', ids: [0x024b], group: 'iptc', dictionary: 'iptc', description: getObjectCycleDescription, reader: iptcBlockReader};
78
+ export const ByLine = {name: 'By-line', ids: [0x0250], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
79
+ export const ByLineTitle = {name: 'By-line Title', ids: [0x0255], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
80
+ export const City = {name: 'City', ids: [0x025a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
81
+ export const SubLocation = {name: 'Sub-location', ids: [0x025c], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
82
+ export const ProvinceState = {name: 'Province/State', ids: [0x025f], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
83
+ export const CountryPrimaryLocationCode = {name: 'Country/Primary Location Code', ids: [0x0264], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
84
+ export const CountryPrimaryLocationName = {name: 'Country/Primary Location Name', ids: [0x0265], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
85
+ export const OriginalTransmissionReference = {name: 'Original Transmission Reference', ids: [0x0267], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
86
+ export const Headline = {name: 'Headline', ids: [0x0269], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
87
+ export const Credit = {name: 'Credit', ids: [0x026e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
88
+ export const Source = {name: 'Source', ids: [0x0273], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
89
+ export const CopyrightNotice = {name: 'Copyright Notice', ids: [0x0274], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
90
+ export const Contact = {name: 'Contact', ids: [0x0276], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
91
+ export const CaptionAbstract = {name: 'Caption/Abstract', ids: [0x0278], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
92
+ export const WriterEditor = {name: 'Writer/Editor', ids: [0x027a], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
93
+ export const RasterizedCaption = {name: 'Rasterized Caption', ids: [0x027d], group: 'iptc', dictionary: 'iptc', description: getRasterizedCaptionDescription, reader: iptcBlockReader};
94
+ export const ImageType = {name: 'Image Type', ids: [0x0282], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
95
+ export const ImageOrientation = {name: 'Image Orientation', ids: [0x0283], group: 'iptc', dictionary: 'iptc', description: getImageOrientationDescription, reader: iptcBlockReader};
96
+ export const LanguageIdentifier = {name: 'Language Identifier', ids: [0x0287], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
97
+ export const AudioType = {name: 'Audio Type', ids: [0x0296], group: 'iptc', dictionary: 'iptc', description: getAudioTypeDescription, reader: iptcBlockReader};
98
+ export const AudioSamplingRate = {name: 'Audio Sampling Rate', ids: [0x0297], group: 'iptc', dictionary: 'iptc', description: getAudioSamplingRateDescription, reader: iptcBlockReader};
99
+ export const AudioSamplingResolution = {name: 'Audio Sampling Resolution', ids: [0x0298], group: 'iptc', dictionary: 'iptc', description: getAudioSamplingResolutionDescription, reader: iptcBlockReader};
100
+ export const AudioDuration = {name: 'Audio Duration', ids: [0x0299], group: 'iptc', dictionary: 'iptc', description: getAudioDurationDescription, reader: iptcBlockReader};
101
+ export const AudioOutcue = {name: 'Audio Outcue', ids: [0x029a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
102
+ export const ShortDocumentID = {name: 'Short Document ID', ids: [0x02ba], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
103
+ export const UniqueDocumentID = {name: 'Unique Document ID', ids: [0x02bb], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
104
+ export const OwnerID = {name: 'Owner ID', ids: [0x02bc], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
105
+ export const ObjectDataPreviewData = {name: 'ObjectData Preview Data', ids: [0x02ca], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
106
+ export const SizeMode = {name: 'Size Mode', ids: [0x070a], group: 'iptc', dictionary: 'iptc', description: getSizeModeDescription, reader: iptcBlockReader};
107
+ export const MaxSubfileSize = {name: 'Max Subfile Size', ids: [0x0714], group: 'iptc', dictionary: 'iptc', description: getMaxSubfileSizeDescription, reader: iptcBlockReader};
108
+ export const ObjectDataSizeAnnounced = {name: 'ObjectData Size Announced', ids: [0x075a], group: 'iptc', dictionary: 'iptc', description: getObjectDataSizeAnnouncedDescription, reader: iptcBlockReader};
109
+ export const MaximumObjectDataSize = {name: 'Maximum ObjectData Size', ids: [0x075f], group: 'iptc', dictionary: 'iptc', description: getMaximumObjectDataSizeDescription, reader: iptcBlockReader};
@@ -0,0 +1,24 @@
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 {getValueBudget} from '../tags-helpers.js';
6
+
7
+ /**
8
+ * Returns the load's one value budget, creating it on the first call from
9
+ * `view`, or from `ctx.dataView` when no view is given. Later calls return the
10
+ * same object whatever view they pass. Undefined when there is no view at all.
11
+ *
12
+ * @param {object} ctx The load's engine context.
13
+ * @param {DataView} [view] The view to size the budget from on the first call.
14
+ * @returns {(object|undefined)} The shared budget.
15
+ */
16
+ export function getSharedValueBudget(ctx, view) {
17
+ if (ctx.valueBudget === undefined) {
18
+ const budgetView = view || ctx.dataView;
19
+ if (budgetView !== undefined) {
20
+ ctx.valueBudget = getValueBudget(budgetView);
21
+ }
22
+ }
23
+ return ctx.valueBudget;
24
+ }
package/src/composite.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 {FocalLengthIn35mmFilm} from './tag-names-common.js';
5
+ import {getFocalLengthIn35mmFilmDescription} from './tag-names-common.js';
6
6
 
7
7
  const FOCAL_PLANE_RESOLUTION_UNIT = {
8
8
  INCHES: 2,
@@ -37,7 +37,7 @@ function get(tags, expanded) {
37
37
  if (focalLengthIn35mmFilm) {
38
38
  compositeTags.FocalLength35efl = {
39
39
  value: focalLengthIn35mmFilm,
40
- description: FocalLengthIn35mmFilm(focalLengthIn35mmFilm)
40
+ description: getFocalLengthIn35mmFilmDescription(focalLengthIn35mmFilm)
41
41
  };
42
42
  hasCompositeTags = true;
43
43
  }
@@ -0,0 +1,60 @@
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 {decompress, withDecompressBudget} from './utils.js';
6
+
7
+ const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
8
+
9
+ export const decompression = {
10
+ withDecompressBudget,
11
+ createPooledDecompress,
12
+ };
13
+
14
+ /**
15
+ * Makes a decompress function for one load whose calls share a pool of at
16
+ * most MAX_DECOMPRESSIONS_IN_FLIGHT tasks.
17
+ *
18
+ * @param {object|undefined} decompressConfig Given to every call of decompress
19
+ * in utils.js, normally the load's config from withDecompressBudget.
20
+ * @returns {function(DataView, (number|string), string, string): Promise}
21
+ * `(view, compressionMethod, encoding, returnType)`.
22
+ */
23
+ function createPooledDecompress(decompressConfig) {
24
+ const pool = createPool(MAX_DECOMPRESSIONS_IN_FLIGHT);
25
+ return (view, compressionMethod, encoding, returnType) => pool.run(() => decompress(view, compressionMethod, encoding, returnType, decompressConfig));
26
+ }
27
+
28
+ // Starts a task when fewer than `limit` are running, else queues it until one
29
+ // settles. Promise is only referenced once a task is given, in async mode.
30
+ function createPool(limit) {
31
+ const queue = [];
32
+ let running = 0;
33
+
34
+ return {
35
+ run(task) {
36
+ return new Promise((resolve, reject) => {
37
+ queue.push({task, resolve, reject});
38
+ startNext();
39
+ });
40
+ },
41
+ };
42
+
43
+ function startNext() {
44
+ if (running >= limit || queue.length === 0) {
45
+ return;
46
+ }
47
+ const {task, resolve, reject} = queue.shift();
48
+ running++;
49
+ // The wrapper turns a synchronous throw from a task into a rejection.
50
+ new Promise((start) => start(task())).then((result) => {
51
+ running--;
52
+ startNext();
53
+ resolve(result);
54
+ }, (error) => {
55
+ running--;
56
+ startNext();
57
+ reject(error);
58
+ });
59
+ }
60
+ }
package/src/dom-parser.js CHANGED
@@ -57,19 +57,18 @@ function getXmldomVersionWarning(version) {
57
57
  if (!match) {
58
58
  return UNREADABLE_VERSION_WARNING;
59
59
  }
60
- if (isOlderThanMinimum(match)) {
60
+ if (isOlderThanMinimum(match.slice(1, 4).map(Number), match[4] === '-')) {
61
61
  return `Warning: XMP tags are skipped because the @xmldom/xmldom that was found is version ${version}. ${XMLDOM_REMEDY}`;
62
62
  }
63
63
  return undefined;
64
64
  }
65
65
 
66
66
  // A prerelease of the minimum version (0.9.12-beta.1) comes before it.
67
- function isOlderThanMinimum(match) {
67
+ function isOlderThanMinimum(parts, isPrerelease) {
68
68
  for (let i = 0; i < MIN_XMLDOM_VERSION.length; i++) {
69
- const part = Number(match[i + 1]);
70
- if (part !== MIN_XMLDOM_VERSION[i]) {
71
- return part < MIN_XMLDOM_VERSION[i];
69
+ if (parts[i] !== MIN_XMLDOM_VERSION[i]) {
70
+ return parts[i] < MIN_XMLDOM_VERSION[i];
72
71
  }
73
72
  }
74
- return match[4] === '-';
73
+ return isPrerelease;
75
74
  }
package/src/engine.js ADDED
@@ -0,0 +1,332 @@
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 {isThenable, objectAssign} from './utils.js';
6
+
7
+ // A finder block, a block it emits and a block emitted by that one.
8
+ export const MAX_BLOCK_DEPTH = 3;
9
+
10
+ /**
11
+ * Runs the composition's groups over the finder's blocks and the blocks the
12
+ * groups emit, and collects their merge blocks in dispatch order.
13
+ *
14
+ * @param {{groups: Array<object>, dispatchKind: function, rank: function, suppressions: Array<object>}} composition
15
+ * `groups` in dispatch order of the kinds they consume, each
16
+ * `{key, consumes, emits, read(block, context), merge(block)}`;
17
+ * `dispatchKind(block)` the kind a block dispatches under; `rank(block)` an
18
+ * integer, of which only the top one per `block.kind` dispatches among the
19
+ * finder blocks; `suppressions` rules `{kind, isSuppressed(block,
20
+ * finderBlocks, context)}` that drop an emitted block.
21
+ * @param {Array<object>} blocks The finder's blocks.
22
+ * @param {object} context From createContext.
23
+ * @returns {{mergeBlocks: Array<object>}|Promise<{mergeBlocks: Array<object>}>}
24
+ * A promise when `context.options.async` is set.
25
+ */
26
+ export function run(composition, blocks, context) {
27
+ const plan = createDispatchPlan(composition, blocks, context);
28
+ const roots = [];
29
+ const deferred = [];
30
+
31
+ for (let i = 0; i < plan.finderBlocks.length; i++) {
32
+ dispatchBlock(plan.finderBlocks[i], 1, roots, deferred, plan);
33
+ }
34
+
35
+ if (!context.options.async) {
36
+ return {mergeBlocks: getMergeBlocks(roots)};
37
+ }
38
+
39
+ return runDeferredRounds(deferred, plan).then(() => ({mergeBlocks: getMergeBlocks(roots)}));
40
+ }
41
+
42
+ function createDispatchPlan(composition, blocks, context) {
43
+ const consumedKinds = Object.create(null);
44
+ const groups = composition.groups;
45
+ for (let i = 0; i < groups.length; i++) {
46
+ for (let j = 0; j < groups[i].consumes.length; j++) {
47
+ consumedKinds[groups[i].consumes[j]] = true;
48
+ }
49
+ }
50
+
51
+ const plan = {
52
+ composition,
53
+ context,
54
+ consumedKinds,
55
+ consumersOf,
56
+ shouldDispatch: createShouldDispatch(groups, consumersOf, context.tagFilter),
57
+ finderBlocks: undefined,
58
+ };
59
+ plan.finderBlocks = getFinderBlocksToDispatch(composition.rank, getFinderCandidates(composition, blocks, plan));
60
+
61
+ return plan;
62
+
63
+ function consumersOf(kind) {
64
+ return groups.filter((group) => group.consumes.indexOf(kind) !== -1);
65
+ }
66
+ }
67
+
68
+ // A group dispatches when the filter parses its key, or a group that consumes
69
+ // a kind it emits does. A cycle counts as false, so a forged cyclic group
70
+ // cannot recurse forever.
71
+ function createShouldDispatch(groups, consumersOf, tagFilter) {
72
+ const verdicts = [];
73
+
74
+ return shouldDispatch;
75
+
76
+ function shouldDispatch(group) {
77
+ const index = groups.indexOf(group);
78
+ if (verdicts[index] === undefined) {
79
+ verdicts[index] = 'visiting';
80
+ verdicts[index] = tagFilter.shouldParseGroup(group.key)
81
+ || group.emits.some((kind) => consumersOf(kind).some(shouldDispatch));
82
+ }
83
+ return verdicts[index] === true;
84
+ }
85
+ }
86
+
87
+ function getFinderCandidates(composition, blocks, plan) {
88
+ const candidates = [];
89
+ for (let i = 0; i < blocks.length; i++) {
90
+ const position = getDispatchPosition(composition.groups, composition.dispatchKind(blocks[i]));
91
+ if (position === -1 || isCompressedInSyncMode(blocks[i], plan.context)) {
92
+ continue;
93
+ }
94
+ candidates.push({block: blocks[i], index: i, position});
95
+ }
96
+ return candidates;
97
+ }
98
+
99
+ function getDispatchPosition(groups, kind) {
100
+ for (let i = 0; i < groups.length; i++) {
101
+ if (groups[i].consumes.indexOf(kind) !== -1) {
102
+ return i;
103
+ }
104
+ }
105
+ return -1;
106
+ }
107
+
108
+ // Of each block.kind only the top rank dispatches. The explicit comparator keeps
109
+ // block-list order within a kind, since sort is not stable on every target.
110
+ function getFinderBlocksToDispatch(rank, candidates) {
111
+ const topRanks = Object.create(null);
112
+ for (let i = 0; i < candidates.length; i++) {
113
+ const kind = candidates[i].block.kind;
114
+ candidates[i].rank = rank(candidates[i].block);
115
+ if (topRanks[kind] === undefined || candidates[i].rank > topRanks[kind]) {
116
+ topRanks[kind] = candidates[i].rank;
117
+ }
118
+ }
119
+
120
+ return candidates
121
+ .filter((candidate) => candidate.rank === topRanks[candidate.block.kind])
122
+ .sort((a, b) => (a.position - b.position) || (a.index - b.index))
123
+ .map((candidate) => candidate.block);
124
+ }
125
+
126
+ function isCompressedInSyncMode(block, context) {
127
+ return !context.options.async && block.compression !== undefined;
128
+ }
129
+
130
+ // Every group consuming the block's kind reads it, in table order. A read that
131
+ // throws drops the block for that group alone.
132
+ function dispatchBlock(block, depth, siblings, deferred, plan) {
133
+ const groups = plan.consumersOf(plan.composition.dispatchKind(block));
134
+
135
+ for (let i = 0; i < groups.length; i++) {
136
+ const group = groups[i];
137
+ if (!plan.shouldDispatch(group)) {
138
+ continue;
139
+ }
140
+ const node = {group, block, tags: undefined, children: []};
141
+ let result;
142
+ try {
143
+ result = group.read(block, plan.context);
144
+ } catch (error) {
145
+ continue;
146
+ }
147
+ if (isThenable(result)) {
148
+ if (!plan.context.options.async) {
149
+ throw new Error('Promise is required when async mode is enabled.');
150
+ }
151
+ siblings.push(node);
152
+ deferred.push({node, depth, promise: Promise.resolve(result).then(keepResult, dropResult)});
153
+ continue;
154
+ }
155
+ if (result === undefined) {
156
+ continue;
157
+ }
158
+ siblings.push(node);
159
+ node.tags = result.tags;
160
+ dispatchEmittedBlocks(result.blocks, depth + 1, node.children, deferred, plan);
161
+ }
162
+ }
163
+
164
+ function keepResult(result) {
165
+ return result;
166
+ }
167
+
168
+ // A rejected read (a decompression failure, a bad header) drops its block alone.
169
+ function dropResult() {
170
+ return undefined;
171
+ }
172
+
173
+ function dispatchEmittedBlocks(blocks, depth, children, deferred, plan) {
174
+ if (!blocks) {
175
+ return;
176
+ }
177
+ for (let i = 0; i < blocks.length; i++) {
178
+ const block = blocks[i];
179
+ if (
180
+ depth > MAX_BLOCK_DEPTH
181
+ || !plan.consumedKinds[plan.composition.dispatchKind(block)]
182
+ || isCompressedInSyncMode(block, plan.context)
183
+ || isSuppressed(block, plan)
184
+ ) {
185
+ continue;
186
+ }
187
+ dispatchBlock(block, depth, children, deferred, plan);
188
+ }
189
+ }
190
+
191
+ function isSuppressed(block, plan) {
192
+ const rules = plan.composition.suppressions;
193
+ for (let i = 0; i < rules.length; i++) {
194
+ if (rules[i].kind === block.kind && rules[i].isSuppressed(block, plan.finderBlocks, plan.context)) {
195
+ return true;
196
+ }
197
+ }
198
+ return false;
199
+ }
200
+
201
+ // The deferred blocks of a round settle together, then their emitted blocks
202
+ // dispatch in block-list order, whatever order the decompressions finished in.
203
+ // A dropped block's node keeps undefined tags and no children, so it merges
204
+ // nothing.
205
+ function runDeferredRounds(deferred, plan) {
206
+ if (deferred.length === 0) {
207
+ return Promise.resolve();
208
+ }
209
+ return Promise.all(deferred.map((entry) => entry.promise)).then((results) => {
210
+ const nextRound = [];
211
+ for (let i = 0; i < deferred.length; i++) {
212
+ const {node, depth} = deferred[i];
213
+ if (results[i] === undefined) {
214
+ continue;
215
+ }
216
+ node.tags = results[i].tags;
217
+ dispatchEmittedBlocks(results[i].blocks, depth + 1, node.children, nextRound, plan);
218
+ }
219
+ return runDeferredRounds(nextRound, plan);
220
+ });
221
+ }
222
+
223
+ // A node with children, or one whose merge descriptor names an outer slot,
224
+ // gives a nested container at that slot holding its own block first; a node
225
+ // whose tags are undefined contributes no block of its own.
226
+ function getMergeBlocks(nodes) {
227
+ const mergeBlocks = [];
228
+ for (let i = 0; i < nodes.length; i++) {
229
+ mergeBlocks.push.apply(mergeBlocks, getNodeMergeBlocks(nodes[i]));
230
+ }
231
+ return mergeBlocks;
232
+ }
233
+
234
+ function getNodeMergeBlocks(node) {
235
+ const merge = node.group.merge(node.block);
236
+ const own = node.tags === undefined ? [] : [objectAssign({group: node.group.key, tags: node.tags}, merge)];
237
+ const children = getMergeBlocks(node.children);
238
+ if (children.length === 0 && merge.outerSlot === undefined) {
239
+ return own;
240
+ }
241
+ return [{slot: merge.outerSlot || merge.slot, mode: 'nested', blocks: own.concat(children)}];
242
+ }
243
+
244
+ /**
245
+ * Builds the per-load state the groups share: the input, the options, the
246
+ * value budget, the entry's helpers and the facts about what is composed. A
247
+ * group keeps any state of its own on the context, created when it first needs
248
+ * it.
249
+ *
250
+ * @param {{dataView: DataView, options: object, tagFilter: object, decompressConfig: (object|undefined), getBase64Image: function, getDomParser: function, composed: object, decompression: (object|undefined)}} parts
251
+ * `composed` is the composition's `{formats, groups, kinds}` maps and its
252
+ * `fromExif` extractors, which the readers consult instead of the build
253
+ * flags. `decompression` is the pooled decompression the png and jxl
254
+ * formats bring; without it `decompressConfig` is undefined too.
255
+ * @returns {object} The context, with `decompress` running through a pool of at
256
+ * most four tasks when `decompression` is given, else undefined, and
257
+ * `valueBudget` holding the load's one value budget, which
258
+ * `getSharedValueBudget` in `composable/value-budget.js` creates on first
259
+ * use.
260
+ */
261
+ export function createContext({dataView, options, tagFilter, decompressConfig, getBase64Image, getDomParser, composed, decompression}) {
262
+ // No prototype, so a group's state is absent until the group sets it even if
263
+ // Object.prototype has that property; objectAssign would copy it from there.
264
+ const context = Object.create(null);
265
+ context.dataView = dataView;
266
+ context.options = options;
267
+ context.tagFilter = tagFilter;
268
+ context.decompressConfig = decompressConfig;
269
+ context.getBase64Image = getBase64Image;
270
+ context.getDomParser = getDomParser;
271
+ context.composed = composed;
272
+ context.valueBudget = undefined;
273
+ context.decompress = decompression ? decompression.createPooledDecompress(decompressConfig) : undefined;
274
+ return context;
275
+ }
276
+
277
+ /**
278
+ * Throws when the groups' static emission graph has a cycle (a kind that,
279
+ * through the groups consuming it and what they emit, leads back to itself) or
280
+ * a chain of consumed kinds longer than MAX_BLOCK_DEPTH. Only the unit tests
281
+ * call it, over every format and group, the union of every composition.
282
+ *
283
+ * @param {{groups: Array<object>}} composition
284
+ */
285
+ export function validateComposition(composition) {
286
+ const edges = Object.create(null);
287
+ const groups = composition.groups;
288
+ for (let i = 0; i < groups.length; i++) {
289
+ for (let j = 0; j < groups[i].consumes.length; j++) {
290
+ const kind = groups[i].consumes[j];
291
+ edges[kind] = (edges[kind] || []).concat(groups[i].emits);
292
+ }
293
+ }
294
+
295
+ const states = Object.create(null);
296
+ for (const kind in edges) {
297
+ visit(kind);
298
+ }
299
+
300
+ // Runs after the cycle check, so the recursion ends.
301
+ const depths = Object.create(null);
302
+ for (const kind in edges) {
303
+ if (getDepth(kind) > MAX_BLOCK_DEPTH) {
304
+ throw new Error('The group emission graph is deeper than ' + MAX_BLOCK_DEPTH + ' blocks through ' + kind);
305
+ }
306
+ }
307
+
308
+ function visit(kind) {
309
+ if (states[kind] === 'done') {
310
+ return;
311
+ }
312
+ if (states[kind] === 'visiting') {
313
+ throw new Error('The group emission graph has a cycle through ' + kind);
314
+ }
315
+ states[kind] = 'visiting';
316
+ const emitted = edges[kind] || [];
317
+ for (let i = 0; i < emitted.length; i++) {
318
+ visit(emitted[i]);
319
+ }
320
+ states[kind] = 'done';
321
+ }
322
+
323
+ // A kind no group consumes is dropped at run time, so it adds no depth.
324
+ function getDepth(kind) {
325
+ if (depths[kind] === undefined) {
326
+ depths[kind] = 1 + edges[kind].reduce((deepest, emitted) => (
327
+ edges[emitted] === undefined ? deepest : Math.max(deepest, getDepth(emitted))
328
+ ), 0);
329
+ }
330
+ return depths[kind];
331
+ }
332
+ }
package/src/errors.js CHANGED
@@ -2,6 +2,8 @@
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 {UnsupportedFormatError} from './unsupported-format-error.js';
6
+
5
7
  /**
6
8
  * Thrown when no Exif metadata was found for the given image.
7
9
  *
@@ -10,11 +12,15 @@
10
12
  function MetadataMissingError(message) {
11
13
  this.name = 'MetadataMissingError';
12
14
  this.message = message || 'No Exif data';
13
- this.stack = (new Error()).stack;
15
+ // Defined, not assigned, to keep stack out of the enumerable keys.
16
+ Object.defineProperty(this, 'stack', {value: (new Error()).stack, writable: true, configurable: true});
14
17
  }
15
18
 
16
- MetadataMissingError.prototype = new Error;
19
+ MetadataMissingError.prototype = Object.create(Error.prototype, {
20
+ constructor: {value: MetadataMissingError, writable: true, configurable: true}
21
+ });
17
22
 
18
23
  export default {
19
24
  MetadataMissingError,
25
+ UnsupportedFormatError,
20
26
  };
@@ -0,0 +1,8 @@
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 * as ExifReader from '../exif-reader.js';
6
+
7
+ export * from '../exif-reader.js';
8
+ export default ExifReader;