exifreader 4.46.0 → 4.47.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 +78 -12
- package/bin/TagFilterPlugin.js +23 -14
- package/bin/analyze.js +345 -0
- package/bin/build.js +10 -2
- package/bin/cli.js +449 -23
- package/bin/custom-build-marker.js +78 -0
- package/bin/verify-build.js +147 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +2 -2
- package/src/canon-tags.js +4 -2
- package/src/exif-reader.js +30 -11
- package/src/file-loaders.js +146 -14
- package/src/image-header-iso-bmff-iloc.js +5 -2
- package/src/image-header-iso-bmff.js +10 -0
- package/src/loadview-pipeline.js +54 -39
- package/src/mpf-tags.js +4 -2
- package/src/pentax-tags.js +4 -2
- package/src/photoshop-tags.js +2 -2
- package/src/png-text-tags.js +95 -62
- package/src/tag-decoder.js +10 -10
- package/src/tag-filter.js +2 -0
- package/src/tag-names-0th-ifd.js +13 -1
- package/src/tags-helpers.js +71 -22
- package/src/tags.js +12 -4
- package/src/types.js +0 -5
- package/src/utils.js +111 -17
- package/src/xmp-namespaces.js +20 -5
- package/src/xmp-tags.js +259 -162
package/src/xmp-namespaces.js
CHANGED
|
@@ -2,24 +2,39 @@
|
|
|
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
|
+
const CHROME_MESSAGE_START = 'Namespace prefix ';
|
|
6
|
+
const CHROME_MESSAGE_END = ' is not defined';
|
|
7
|
+
|
|
5
8
|
export function isMissingNamespaceError(error) {
|
|
9
|
+
const message = String(error.message);
|
|
6
10
|
const missingNamespaceStrings = [
|
|
7
11
|
// @xmldom/xmldom
|
|
8
12
|
'prefix is non-null and namespace is null',
|
|
9
13
|
// Firefox
|
|
10
14
|
'prefix not bound to a namespace', // en
|
|
11
|
-
'prefix inte bundet till en namnrymd'
|
|
12
|
-
// Chrome
|
|
13
|
-
/Namespace prefix .+ is not defined/
|
|
15
|
+
'prefix inte bundet till en namnrymd' // sv
|
|
14
16
|
];
|
|
15
17
|
|
|
16
18
|
for (let i = 0; i < missingNamespaceStrings.length; i++) {
|
|
17
|
-
|
|
18
|
-
if (regexp.test(error.message)) {
|
|
19
|
+
if (message.indexOf(missingNamespaceStrings[i]) !== -1) {
|
|
19
20
|
return true;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
return isChromeMissingNamespaceMessage(message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Same result as the former Chrome check /Namespace prefix .+ is not defined/,
|
|
28
|
+
// in linear time.
|
|
29
|
+
function isChromeMissingNamespaceMessage(message) {
|
|
30
|
+
const lines = message.split(/[\n\r\u2028\u2029]/);
|
|
31
|
+
for (let i = 0; i < lines.length; i++) {
|
|
32
|
+
const prefixIndex = lines[i].indexOf(CHROME_MESSAGE_START);
|
|
33
|
+
if (prefixIndex !== -1
|
|
34
|
+
&& lines[i].lastIndexOf(CHROME_MESSAGE_END) > prefixIndex + CHROME_MESSAGE_START.length) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
23
38
|
return false;
|
|
24
39
|
}
|
|
25
40
|
|
package/src/xmp-tags.js
CHANGED
|
@@ -12,6 +12,25 @@ export default {
|
|
|
12
12
|
read
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// Node names differ between parsers (#cdata-section vs #cdatasection), so
|
|
16
|
+
// nodes are told apart by their DOM nodeType.
|
|
17
|
+
const ELEMENT_NODE = 1;
|
|
18
|
+
const TEXT_NODE = 3;
|
|
19
|
+
const CDATA_SECTION_NODE = 4;
|
|
20
|
+
const PROCESSING_INSTRUCTION_NODE = 7;
|
|
21
|
+
const COMMENT_NODE = 8;
|
|
22
|
+
|
|
23
|
+
const PACKET_TRAILER_START = '<?xpacket end="';
|
|
24
|
+
const PACKET_TRAILER_END = '"?>';
|
|
25
|
+
|
|
26
|
+
// Each nested value repeats the descriptions of everything below it, so the
|
|
27
|
+
// description text grows with the square of the nesting depth.
|
|
28
|
+
const MAX_NESTING_DEPTH = 32;
|
|
29
|
+
|
|
30
|
+
// Parsing is synchronous and oneLevelDeeper always restores the counter, so
|
|
31
|
+
// one counter serves every read.
|
|
32
|
+
let nestingDepth = 0;
|
|
33
|
+
|
|
15
34
|
class ParseError extends Error {
|
|
16
35
|
constructor(message) {
|
|
17
36
|
super(message);
|
|
@@ -95,7 +114,9 @@ function readTags(tags, chunkDataView, domParser) {
|
|
|
95
114
|
tags._raw = (tags._raw || '') + raw;
|
|
96
115
|
const rdf = getRDF(doc);
|
|
97
116
|
|
|
98
|
-
|
|
117
|
+
const xmpTags = {};
|
|
118
|
+
parseXMPObject(convertToObject(rdf, true, decodeValue), xmpTags, Object.create(null));
|
|
119
|
+
objectAssign(tags, xmpTags);
|
|
99
120
|
return true;
|
|
100
121
|
} catch (error) {
|
|
101
122
|
return false;
|
|
@@ -157,7 +178,27 @@ function keepValue(value) {
|
|
|
157
178
|
}
|
|
158
179
|
|
|
159
180
|
function trimXmlSource(xmlSource) {
|
|
160
|
-
return xmlSource.replace(/^.+(<\?xpacket begin)/, '$1')
|
|
181
|
+
return trimAfterPacketTrailer(xmlSource.replace(/^.+(<\?xpacket begin)/, '$1'));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Gives the same result as the former /(<\?xpacket end=".*"\?>).+$/ in linear
|
|
185
|
+
// time: only text after a trailer on the last line is cut off.
|
|
186
|
+
function trimAfterPacketTrailer(xmlSource) {
|
|
187
|
+
const lastLineStart = Math.max(
|
|
188
|
+
xmlSource.lastIndexOf('\n'),
|
|
189
|
+
xmlSource.lastIndexOf('\r'),
|
|
190
|
+
xmlSource.lastIndexOf('\u2028'),
|
|
191
|
+
xmlSource.lastIndexOf('\u2029')
|
|
192
|
+
) + 1;
|
|
193
|
+
const trailerStart = xmlSource.indexOf(PACKET_TRAILER_START, lastLineStart);
|
|
194
|
+
if (trailerStart === -1) {
|
|
195
|
+
return xmlSource;
|
|
196
|
+
}
|
|
197
|
+
const trailerEnd = xmlSource.lastIndexOf(PACKET_TRAILER_END, xmlSource.length - PACKET_TRAILER_END.length - 1);
|
|
198
|
+
if (trailerEnd < trailerStart + PACKET_TRAILER_START.length) {
|
|
199
|
+
return xmlSource;
|
|
200
|
+
}
|
|
201
|
+
return xmlSource.slice(0, trailerEnd + PACKET_TRAILER_END.length);
|
|
161
202
|
}
|
|
162
203
|
|
|
163
204
|
function parseFromString(domParser, xmlString, isRetry = false) {
|
|
@@ -178,12 +219,14 @@ function parseFromString(domParser, xmlString, isRetry = false) {
|
|
|
178
219
|
}
|
|
179
220
|
|
|
180
221
|
function getRDF(node) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
222
|
+
const childNodes = node.childNodes;
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
225
|
+
if (childNodes[i].tagName === 'x:xmpmeta') {
|
|
226
|
+
return getRDF(childNodes[i]);
|
|
184
227
|
}
|
|
185
|
-
if (
|
|
186
|
-
return
|
|
228
|
+
if (childNodes[i].tagName === 'rdf:RDF') {
|
|
229
|
+
return childNodes[i];
|
|
187
230
|
}
|
|
188
231
|
}
|
|
189
232
|
|
|
@@ -197,28 +240,41 @@ function convertToObject(node, isTopNode, decodeValue) {
|
|
|
197
240
|
if (isTopNode) {
|
|
198
241
|
return {};
|
|
199
242
|
}
|
|
200
|
-
return decodeValue(getTextValue(childNodes
|
|
243
|
+
return decodeValue(getTextValue(childNodes));
|
|
201
244
|
}
|
|
202
245
|
|
|
203
246
|
return getElementsFromNodes(childNodes, decodeValue);
|
|
204
247
|
}
|
|
205
248
|
|
|
206
249
|
function getChildNodes(node) {
|
|
207
|
-
const
|
|
250
|
+
const childNodes = node.childNodes;
|
|
251
|
+
const nodes = [];
|
|
208
252
|
|
|
209
|
-
for (let i = 0; i <
|
|
210
|
-
|
|
253
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
254
|
+
if (!isCommentOrProcessingInstruction(childNodes[i])) {
|
|
255
|
+
nodes.push(childNodes[i]);
|
|
256
|
+
}
|
|
211
257
|
}
|
|
212
258
|
|
|
213
|
-
return
|
|
259
|
+
return nodes;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function isCommentOrProcessingInstruction(node) {
|
|
263
|
+
return node.nodeType === COMMENT_NODE || node.nodeType === PROCESSING_INSTRUCTION_NODE;
|
|
214
264
|
}
|
|
215
265
|
|
|
216
266
|
function hasTextOnlyContent(nodes) {
|
|
217
|
-
return
|
|
267
|
+
return nodes.length > 0 && nodes.every(isText);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function isText(node) {
|
|
271
|
+
return node.nodeType === TEXT_NODE || node.nodeType === CDATA_SECTION_NODE;
|
|
218
272
|
}
|
|
219
273
|
|
|
220
|
-
|
|
221
|
-
|
|
274
|
+
// linkedom splits text at every entity or character reference, and a CDATA
|
|
275
|
+
// section is a node of its own, so the text of an element can span several nodes.
|
|
276
|
+
function getTextValue(nodes) {
|
|
277
|
+
return nodes.map((node) => node.nodeValue).join('');
|
|
222
278
|
}
|
|
223
279
|
|
|
224
280
|
// The elements object must not have a prototype. The element names come from
|
|
@@ -246,7 +302,7 @@ function getElementsFromNodes(nodes, decodeValue) {
|
|
|
246
302
|
}
|
|
247
303
|
|
|
248
304
|
function isElement(node) {
|
|
249
|
-
return
|
|
305
|
+
return node.nodeType === ELEMENT_NODE;
|
|
250
306
|
}
|
|
251
307
|
|
|
252
308
|
function getElementFromNode(node, decodeValue) {
|
|
@@ -257,22 +313,17 @@ function getElementFromNode(node, decodeValue) {
|
|
|
257
313
|
}
|
|
258
314
|
|
|
259
315
|
function getAttributes(element, decodeValue) {
|
|
316
|
+
const elementAttributes = element.attributes;
|
|
260
317
|
const attributes = {};
|
|
261
318
|
|
|
262
|
-
for (let i = 0; i <
|
|
263
|
-
setProperty(attributes,
|
|
319
|
+
for (let i = 0; i < elementAttributes.length; i++) {
|
|
320
|
+
setProperty(attributes, elementAttributes[i].nodeName, decodeValue(elementAttributes[i].value));
|
|
264
321
|
}
|
|
265
322
|
|
|
266
323
|
return attributes;
|
|
267
324
|
}
|
|
268
325
|
|
|
269
|
-
function parseXMPObject(xmpObject) {
|
|
270
|
-
const tags = {};
|
|
271
|
-
|
|
272
|
-
if (typeof xmpObject === 'string') {
|
|
273
|
-
return xmpObject;
|
|
274
|
-
}
|
|
275
|
-
|
|
326
|
+
function parseXMPObject(xmpObject, tags, plainDescriptions) {
|
|
276
327
|
for (const nodeName in xmpObject) {
|
|
277
328
|
let nodes = xmpObject[nodeName];
|
|
278
329
|
|
|
@@ -281,34 +332,24 @@ function parseXMPObject(xmpObject) {
|
|
|
281
332
|
}
|
|
282
333
|
|
|
283
334
|
nodes.forEach((node) => {
|
|
284
|
-
|
|
335
|
+
parseNodeAttributesAsTags(node.attributes, tags, plainDescriptions);
|
|
285
336
|
if (typeof node.value === 'object') {
|
|
286
|
-
|
|
337
|
+
parseNodeChildrenAsTags(node.value, tags, plainDescriptions);
|
|
287
338
|
}
|
|
288
339
|
});
|
|
289
340
|
}
|
|
290
|
-
|
|
291
|
-
return tags;
|
|
292
341
|
}
|
|
293
342
|
|
|
294
|
-
function parseNodeAttributesAsTags(attributes) {
|
|
295
|
-
const tags = {};
|
|
296
|
-
|
|
343
|
+
function parseNodeAttributesAsTags(attributes, tags, plainDescriptions) {
|
|
297
344
|
for (const name in attributes) {
|
|
298
345
|
try {
|
|
299
346
|
if (isTagAttribute(name)) {
|
|
300
|
-
|
|
301
|
-
value: attributes[name],
|
|
302
|
-
attributes: {},
|
|
303
|
-
description: getDescription(attributes[name], name)
|
|
304
|
-
});
|
|
347
|
+
setParsedTag(tags, plainDescriptions, getLocalName(name), createParsedTag(attributes[name], attributes[name], {}, name));
|
|
305
348
|
}
|
|
306
349
|
} catch (error) {
|
|
307
350
|
// Keep going and try to parse the rest of the tags.
|
|
308
351
|
}
|
|
309
352
|
}
|
|
310
|
-
|
|
311
|
-
return tags;
|
|
312
353
|
}
|
|
313
354
|
|
|
314
355
|
function isTagAttribute(name) {
|
|
@@ -319,6 +360,11 @@ function isNamespaceDefinition(name) {
|
|
|
319
360
|
return name.split(':')[0] === 'xmlns';
|
|
320
361
|
}
|
|
321
362
|
|
|
363
|
+
function setParsedTag(tags, plainDescriptions, name, parsedTag) {
|
|
364
|
+
setProperty(tags, name, parsedTag.tag);
|
|
365
|
+
setProperty(plainDescriptions, name, parsedTag.plainDescription);
|
|
366
|
+
}
|
|
367
|
+
|
|
322
368
|
function getLocalName(name) {
|
|
323
369
|
if (/^MicrosoftPhoto(_\d+_)?:Rating$/i.test(name)) {
|
|
324
370
|
return 'RatingPercent';
|
|
@@ -326,45 +372,42 @@ function getLocalName(name) {
|
|
|
326
372
|
return name.split(':')[1];
|
|
327
373
|
}
|
|
328
374
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
} catch (error) {
|
|
342
|
-
// Fall back to the descriptions of the items.
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return arrayDescription;
|
|
346
|
-
}
|
|
347
|
-
if (typeof value === 'object') {
|
|
348
|
-
return getDescriptionOfObject(value);
|
|
349
|
-
}
|
|
375
|
+
// A parent describes its members without their description functions, so
|
|
376
|
+
// each parsed tag carries that plain description next to the tag itself.
|
|
377
|
+
function createParsedTag(value, plainDescription, attributes, name) {
|
|
378
|
+
return {
|
|
379
|
+
tag: {
|
|
380
|
+
value,
|
|
381
|
+
attributes,
|
|
382
|
+
description: getDescription(value, plainDescription, name)
|
|
383
|
+
},
|
|
384
|
+
plainDescription
|
|
385
|
+
};
|
|
386
|
+
}
|
|
350
387
|
|
|
351
|
-
|
|
388
|
+
function getDescription(value, plainDescription, name) {
|
|
389
|
+
if (!hasTagNameFunction(name) || isObject(value)) {
|
|
390
|
+
return plainDescription;
|
|
391
|
+
}
|
|
392
|
+
if (Array.isArray(value)) {
|
|
393
|
+
// A description is a string, so a description function written for
|
|
394
|
+
// a plain value is ignored when it throws on a list or returns
|
|
395
|
+
// something other than a string.
|
|
352
396
|
try {
|
|
353
|
-
|
|
397
|
+
const description = XmpTagNames[name](value, plainDescription);
|
|
398
|
+
if (typeof description === 'string') {
|
|
399
|
+
return description;
|
|
400
|
+
}
|
|
354
401
|
} catch (error) {
|
|
355
|
-
|
|
402
|
+
// Fall back to the descriptions of the items.
|
|
356
403
|
}
|
|
404
|
+
return plainDescription;
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
return XmpTagNames[name](value);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
return value;
|
|
357
410
|
}
|
|
358
|
-
return value;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function getDescriptionOfArray(value) {
|
|
362
|
-
return value.map((item) => {
|
|
363
|
-
if (item.value !== undefined) {
|
|
364
|
-
return getDescription(item.value);
|
|
365
|
-
}
|
|
366
|
-
return getDescription(item);
|
|
367
|
-
}).join(', ');
|
|
368
411
|
}
|
|
369
412
|
|
|
370
413
|
// The name comes from the image, so an inherited property of the tag name table
|
|
@@ -373,56 +416,36 @@ function hasTagNameFunction(name) {
|
|
|
373
416
|
return Object.prototype.hasOwnProperty.call(XmpTagNames, name) && (typeof XmpTagNames[name] === 'function');
|
|
374
417
|
}
|
|
375
418
|
|
|
376
|
-
function
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
for (const key in value) {
|
|
380
|
-
descriptions.push(`${getClearTextKey(key)}: ${getDescription(value[key].value)}`);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return descriptions.join('; ');
|
|
419
|
+
function isObject(value) {
|
|
420
|
+
return (typeof value === 'object') && !Array.isArray(value);
|
|
384
421
|
}
|
|
385
422
|
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
if (key === 'CiAdrRegion') {
|
|
400
|
-
return 'CreatorRegion';
|
|
401
|
-
}
|
|
402
|
-
if (key === 'CiEmailWork') {
|
|
403
|
-
return 'CreatorWorkEmail';
|
|
404
|
-
}
|
|
405
|
-
if (key === 'CiTelWork') {
|
|
406
|
-
return 'CreatorWorkPhone';
|
|
407
|
-
}
|
|
408
|
-
if (key === 'CiUrlWork') {
|
|
409
|
-
return 'CreatorWorkUrl';
|
|
410
|
-
}
|
|
411
|
-
return key;
|
|
423
|
+
function parseNodeChildrenAsTags(children, tags, plainDescriptions) {
|
|
424
|
+
oneLevelDeeper(() => {
|
|
425
|
+
for (const name in children) {
|
|
426
|
+
try {
|
|
427
|
+
if (!isNamespaceDefinition(name)) {
|
|
428
|
+
setParsedTag(tags, plainDescriptions, getLocalName(name), parseNodeAsTag(children[name], name));
|
|
429
|
+
}
|
|
430
|
+
} catch (error) {
|
|
431
|
+
// Keep going and try to parse the rest of the tags.
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
});
|
|
412
435
|
}
|
|
413
436
|
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
// Keep going and try to parse the rest of the tags.
|
|
437
|
+
function oneLevelDeeper(callback) {
|
|
438
|
+
nestingDepth++;
|
|
439
|
+
try {
|
|
440
|
+
if (nestingDepth > MAX_NESTING_DEPTH) {
|
|
441
|
+
// Lands in the catch of the nearest parseNodeChildrenAsTags, which
|
|
442
|
+
// drops the tag.
|
|
443
|
+
throw new ParseError(`XMP value nested deeper than ${MAX_NESTING_DEPTH} levels.`);
|
|
422
444
|
}
|
|
445
|
+
return callback();
|
|
446
|
+
} finally {
|
|
447
|
+
nestingDepth--;
|
|
423
448
|
}
|
|
424
|
-
|
|
425
|
-
return tags;
|
|
426
449
|
}
|
|
427
450
|
|
|
428
451
|
function parseNodeAsTag(node, name) {
|
|
@@ -430,7 +453,7 @@ function parseNodeAsTag(node, name) {
|
|
|
430
453
|
return parseNodeAsDuplicateTag(node, name);
|
|
431
454
|
}
|
|
432
455
|
if (isEmptyResourceTag(node)) {
|
|
433
|
-
return {value: '', attributes: {}, description: ''};
|
|
456
|
+
return {tag: {value: '', attributes: {}, description: ''}, plainDescription: ''};
|
|
434
457
|
}
|
|
435
458
|
if (hasNestedSimpleRdfDescription(node)) {
|
|
436
459
|
return parseNodeAsSimpleRdfDescription(node, name);
|
|
@@ -475,13 +498,9 @@ function parseNodeAsSimpleRdfDescription(node, name) {
|
|
|
475
498
|
|
|
476
499
|
objectAssign(attributes, parseNodeAttributes(node), parseNodeChildrenAsAttributes(node));
|
|
477
500
|
|
|
478
|
-
const value = parseRdfValue(node);
|
|
501
|
+
const {value, plainDescription} = parseRdfValue(node);
|
|
479
502
|
|
|
480
|
-
return
|
|
481
|
-
value,
|
|
482
|
-
attributes,
|
|
483
|
-
description: getDescription(value, name)
|
|
484
|
-
};
|
|
503
|
+
return createParsedTag(value, plainDescription, attributes, name);
|
|
485
504
|
}
|
|
486
505
|
|
|
487
506
|
function parseNodeAttributes(node) {
|
|
@@ -499,6 +518,10 @@ function parseNodeAttributes(node) {
|
|
|
499
518
|
function parseNodeChildrenAsAttributes(node) {
|
|
500
519
|
const attributes = {};
|
|
501
520
|
|
|
521
|
+
if (typeof node.value !== 'object') {
|
|
522
|
+
return attributes;
|
|
523
|
+
}
|
|
524
|
+
|
|
502
525
|
for (const name in node.value) {
|
|
503
526
|
if ((name !== 'rdf:value') && (!isNamespaceDefinition(name))) {
|
|
504
527
|
setProperty(attributes, getLocalName(name), node.value[name].value);
|
|
@@ -510,7 +533,11 @@ function parseNodeChildrenAsAttributes(node) {
|
|
|
510
533
|
|
|
511
534
|
function parseRdfValue(node) {
|
|
512
535
|
const rdfValueNode = getLastNode(node.value['rdf:value']);
|
|
513
|
-
|
|
536
|
+
const uri = getURIValue(rdfValueNode);
|
|
537
|
+
if (uri) {
|
|
538
|
+
return {value: uri, plainDescription: uri};
|
|
539
|
+
}
|
|
540
|
+
return parseRdfValueContent(rdfValueNode);
|
|
514
541
|
}
|
|
515
542
|
|
|
516
543
|
// Repeated elements are collected into an array, and the last one wins, which
|
|
@@ -526,14 +553,56 @@ function getLastNode(node) {
|
|
|
526
553
|
// the value of the tag rather than a tag of its own.
|
|
527
554
|
function parseRdfValueContent(rdfValueNode) {
|
|
528
555
|
if (isArray(rdfValueNode)) {
|
|
529
|
-
|
|
556
|
+
// Lists nested in rdf:value elements never pass parseNodeChildrenAsTags, so each one is a level.
|
|
557
|
+
return oneLevelDeeper(() => parseArrayItems(rdfValueNode));
|
|
530
558
|
}
|
|
531
559
|
if (typeof rdfValueNode.value === 'object') {
|
|
532
560
|
// The child names come from the image, so a child named __proto__ must
|
|
533
561
|
// not be able to replace this object's prototype.
|
|
534
|
-
|
|
562
|
+
const tags = Object.create(null);
|
|
563
|
+
const plainDescriptions = Object.create(null);
|
|
564
|
+
parseNodeChildrenAsTags(rdfValueNode.value, tags, plainDescriptions);
|
|
565
|
+
return {value: tags, plainDescription: getDescriptionOfObject(tags, plainDescriptions)};
|
|
566
|
+
}
|
|
567
|
+
return {value: rdfValueNode.value, plainDescription: rdfValueNode.value};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function getDescriptionOfObject(tags, plainDescriptions) {
|
|
571
|
+
const descriptions = [];
|
|
572
|
+
|
|
573
|
+
for (const key in tags) {
|
|
574
|
+
descriptions.push(`${getClearTextKey(key)}: ${plainDescriptions[key]}`);
|
|
535
575
|
}
|
|
536
|
-
|
|
576
|
+
|
|
577
|
+
return descriptions.join('; ');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function getClearTextKey(key) {
|
|
581
|
+
if (key === 'CiAdrCity') {
|
|
582
|
+
return 'CreatorCity';
|
|
583
|
+
}
|
|
584
|
+
if (key === 'CiAdrCtry') {
|
|
585
|
+
return 'CreatorCountry';
|
|
586
|
+
}
|
|
587
|
+
if (key === 'CiAdrExtadr') {
|
|
588
|
+
return 'CreatorAddress';
|
|
589
|
+
}
|
|
590
|
+
if (key === 'CiAdrPcode') {
|
|
591
|
+
return 'CreatorPostalCode';
|
|
592
|
+
}
|
|
593
|
+
if (key === 'CiAdrRegion') {
|
|
594
|
+
return 'CreatorRegion';
|
|
595
|
+
}
|
|
596
|
+
if (key === 'CiEmailWork') {
|
|
597
|
+
return 'CreatorWorkEmail';
|
|
598
|
+
}
|
|
599
|
+
if (key === 'CiTelWork') {
|
|
600
|
+
return 'CreatorWorkPhone';
|
|
601
|
+
}
|
|
602
|
+
if (key === 'CiUrlWork') {
|
|
603
|
+
return 'CreatorWorkUrl';
|
|
604
|
+
}
|
|
605
|
+
return key;
|
|
537
606
|
}
|
|
538
607
|
|
|
539
608
|
function hasNestedStructureRdfDescription(node) {
|
|
@@ -542,38 +611,44 @@ function hasNestedStructureRdfDescription(node) {
|
|
|
542
611
|
}
|
|
543
612
|
|
|
544
613
|
function parseNodeAsStructureRdfDescription(node, name) {
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
};
|
|
614
|
+
const value = {};
|
|
615
|
+
const plainDescriptions = Object.create(null);
|
|
616
|
+
const attributes = {};
|
|
549
617
|
|
|
550
618
|
if (node.value['rdf:Description'] !== undefined) {
|
|
551
|
-
|
|
552
|
-
objectAssign(
|
|
619
|
+
parseNodeAttributesAsTags(node.value['rdf:Description'].attributes, value, plainDescriptions);
|
|
620
|
+
objectAssign(attributes, parseNodeAttributes(node));
|
|
553
621
|
node = node.value['rdf:Description'];
|
|
554
622
|
}
|
|
555
623
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
624
|
+
if (typeof node.value === 'object') {
|
|
625
|
+
parseNodeChildrenAsTags(node.value, value, plainDescriptions);
|
|
626
|
+
}
|
|
559
627
|
|
|
560
|
-
return
|
|
628
|
+
return createParsedTag(value, getDescriptionOfObject(value, plainDescriptions), attributes, name);
|
|
561
629
|
}
|
|
562
630
|
|
|
563
631
|
function isCompactStructure(node) {
|
|
564
|
-
return (
|
|
632
|
+
return isEmptyValue(node.value)
|
|
565
633
|
&& (node.attributes['xml:lang'] === undefined)
|
|
566
634
|
&& (node.attributes['rdf:resource'] === undefined);
|
|
567
635
|
}
|
|
568
636
|
|
|
637
|
+
// A text-only element has a string value; enumerating it would visit every character.
|
|
638
|
+
function isEmptyValue(value) {
|
|
639
|
+
if (typeof value === 'string') {
|
|
640
|
+
return value === '';
|
|
641
|
+
}
|
|
642
|
+
return Object.keys(value).length === 0;
|
|
643
|
+
}
|
|
644
|
+
|
|
569
645
|
function parseNodeAsCompactStructure(node, name) {
|
|
570
|
-
const value =
|
|
646
|
+
const value = {};
|
|
647
|
+
const plainDescriptions = Object.create(null);
|
|
571
648
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
description: getDescription(value, name)
|
|
576
|
-
};
|
|
649
|
+
parseNodeAttributesAsTags(node.attributes, value, plainDescriptions);
|
|
650
|
+
|
|
651
|
+
return createParsedTag(value, getDescriptionOfObject(value, plainDescriptions), {}, name);
|
|
577
652
|
}
|
|
578
653
|
|
|
579
654
|
function isArray(node) {
|
|
@@ -585,9 +660,16 @@ function getArrayChild(value) {
|
|
|
585
660
|
}
|
|
586
661
|
|
|
587
662
|
function parseNodeAsArray(node, name) {
|
|
588
|
-
let items = getArrayChild(node.value).value['rdf:li'];
|
|
589
663
|
const attributes = parseNodeAttributes(node);
|
|
664
|
+
const {value, plainDescription} = parseArrayItems(node);
|
|
665
|
+
|
|
666
|
+
return createParsedTag(value, plainDescription, attributes, name);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function parseArrayItems(node) {
|
|
670
|
+
let items = getArrayChild(node.value).value['rdf:li'];
|
|
590
671
|
const value = [];
|
|
672
|
+
const itemDescriptions = [];
|
|
591
673
|
|
|
592
674
|
if (items === undefined) {
|
|
593
675
|
items = [];
|
|
@@ -596,38 +678,53 @@ function parseNodeAsArray(node, name) {
|
|
|
596
678
|
}
|
|
597
679
|
|
|
598
680
|
items.forEach((item) => {
|
|
599
|
-
|
|
681
|
+
const parsedItem = parseArrayValue(item);
|
|
682
|
+
value.push(parsedItem.value);
|
|
683
|
+
itemDescriptions.push(parsedItem.plainDescription);
|
|
600
684
|
});
|
|
601
685
|
|
|
602
|
-
return {
|
|
603
|
-
value,
|
|
604
|
-
attributes,
|
|
605
|
-
description: getDescription(value, name)
|
|
606
|
-
};
|
|
686
|
+
return {value, plainDescription: itemDescriptions.join(', ')};
|
|
607
687
|
}
|
|
608
688
|
|
|
609
689
|
function parseArrayValue(item) {
|
|
610
690
|
if (hasNestedSimpleRdfDescription(item)) {
|
|
611
|
-
return parseNodeAsSimpleRdfDescription(item);
|
|
691
|
+
return getParsedTagAsItem(parseNodeAsSimpleRdfDescription(item));
|
|
612
692
|
}
|
|
613
693
|
if (hasNestedStructureRdfDescription(item)) {
|
|
614
|
-
return parseNodeAsStructureRdfDescription(item)
|
|
694
|
+
return getParsedStructureAsItem(parseNodeAsStructureRdfDescription(item));
|
|
615
695
|
}
|
|
616
696
|
if (isCompactStructure(item)) {
|
|
617
|
-
return parseNodeAsCompactStructure(item)
|
|
697
|
+
return getParsedStructureAsItem(parseNodeAsCompactStructure(item));
|
|
618
698
|
}
|
|
619
699
|
|
|
620
|
-
return parseNodeAsSimpleValue(item);
|
|
700
|
+
return getParsedTagAsItem(parseNodeAsSimpleValue(item));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function getParsedTagAsItem(parsedTag) {
|
|
704
|
+
return {value: parsedTag.tag, plainDescription: parsedTag.plainDescription};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function getParsedStructureAsItem(parsedStructure) {
|
|
708
|
+
return {value: parsedStructure.tag.value, plainDescription: parsedStructure.plainDescription};
|
|
621
709
|
}
|
|
622
710
|
|
|
623
711
|
function parseNodeAsSimpleValue(node, name) {
|
|
624
|
-
const value =
|
|
712
|
+
const {value, plainDescription} = parseSimpleValue(node);
|
|
713
|
+
return createParsedTag(value, plainDescription, parseNodeAttributes(node), name);
|
|
714
|
+
}
|
|
625
715
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
716
|
+
function parseSimpleValue(node) {
|
|
717
|
+
const uri = getURIValue(node);
|
|
718
|
+
if (uri) {
|
|
719
|
+
return {value: uri, plainDescription: uri};
|
|
720
|
+
}
|
|
721
|
+
if (typeof node.value === 'string') {
|
|
722
|
+
return {value: node.value, plainDescription: node.value};
|
|
723
|
+
}
|
|
724
|
+
const tags = {};
|
|
725
|
+
const plainDescriptions = Object.create(null);
|
|
726
|
+
parseXMPObject(node.value, tags, plainDescriptions);
|
|
727
|
+
return {value: tags, plainDescription: getDescriptionOfObject(tags, plainDescriptions)};
|
|
631
728
|
}
|
|
632
729
|
|
|
633
730
|
function getURIValue(node) {
|