7f0838156b
Sidecars and JPEG exports now carry xmp:Rating, xmp:Label, dc:subject and lr:hierarchicalSubject plus the IPTC core, and importing a sidecar applies its cataloguing fields independently of its develop settings. Hierarchical keywords keep leaf terms in the flat list, so search and filters are unchanged.
133 lines
5.8 KiB
TypeScript
133 lines
5.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { defaultEdits, defaultLocalLayer, normalizeEdits } from './edits';
|
|
import { editsToXmp, xmpFileName, xmpToEdits, xmpToMetadata } from './xmp';
|
|
|
|
describe('xmp sidecars', () => {
|
|
it('round-trips every develop field exactly', () => {
|
|
const edits = defaultEdits();
|
|
edits.exposure = 0.65;
|
|
edits.temp = -14;
|
|
edits.kelvin = 4200;
|
|
edits.contrast = 22;
|
|
edits.parametric.darks = -17;
|
|
edits.hsl.hue[3] = 12;
|
|
edits.grain.roughness = 71;
|
|
const mask = defaultLocalLayer('linear', 0);
|
|
if (mask.components[0]) mask.components[0].linear = { x1: 0.1, y1: 0.2, x2: 0.8, y2: 0.9 };
|
|
edits.local = [mask];
|
|
|
|
const xml = editsToXmp(edits);
|
|
const back = xmpToEdits(xml, defaultEdits());
|
|
expect(back.source).toBe('luminary');
|
|
// Sanitising on the way in is allowed; it must not change any value.
|
|
expect(back.edits).toEqual(normalizeEdits(edits));
|
|
});
|
|
|
|
it('reads crs fields written by Lightroom', () => {
|
|
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" crs:Exposure2012="1.25" crs:Contrast2012="-18" crs:Clarity2012="34" crs:GrainAmount="40" crs:ConvertToGrayscale="True"/></rdf:RDF></x:xmpmeta>`;
|
|
const base = defaultEdits();
|
|
base.saturation = 9;
|
|
const result = xmpToEdits(xml, base);
|
|
expect(result.source).toBe('lightroom');
|
|
expect(result.edits.exposure).toBe(1.25);
|
|
expect(result.edits.contrast).toBe(-18);
|
|
expect(result.edits.clarity).toBe(34);
|
|
expect(result.edits.grain.amount).toBe(40);
|
|
expect(result.edits.bw).toBe(true);
|
|
// Fields the sidecar does not mention keep the photo's own settings.
|
|
expect(result.edits.saturation).toBe(9);
|
|
});
|
|
|
|
it('reads an absolute Kelvin temperature written by Lightroom', () => {
|
|
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/" crs:Temperature="3800" crs:Tint="12" crs:Exposure2012="0.4"/></rdf:RDF></x:xmpmeta>`;
|
|
const result = xmpToEdits(xml, defaultEdits());
|
|
expect(result.edits.kelvin).toBe(3800);
|
|
expect(result.edits.tint).toBe(12);
|
|
expect(result.applied).toContain('Temperature');
|
|
});
|
|
|
|
it('rejects a file that is not a sidecar', () => {
|
|
expect(() => xmpToEdits('<html></html>', defaultEdits())).toThrow(/not an XMP/);
|
|
});
|
|
|
|
it('names the sidecar after the photo', () => {
|
|
expect(xmpFileName('DSC0123.ARW')).toBe('DSC0123.xmp');
|
|
expect(xmpFileName('no-extension')).toBe('no-extension.xmp');
|
|
});
|
|
});
|
|
|
|
describe('xmp metadata', () => {
|
|
const photo = {
|
|
name: 'DSC0123.ARW',
|
|
meta: {},
|
|
rating: 4,
|
|
color: 'green' as const,
|
|
keywords: ['Birds', 'Robin'],
|
|
keywordPaths: ['Nature', 'Nature > Birds', 'Nature > Birds > Robin'],
|
|
iptc: {
|
|
headline: 'Dawn chorus',
|
|
credit: 'B. Hursey',
|
|
source: 'Field notes',
|
|
city: 'Bristol',
|
|
state: 'Somerset',
|
|
country: 'UK',
|
|
location: 'Ashton Court',
|
|
},
|
|
title: 'Robin at dawn',
|
|
caption: 'First light, heavy frost',
|
|
creator: 'Brian Hursey',
|
|
copyright: '© 2026 Brian Hursey',
|
|
};
|
|
|
|
it('writes rating, label, keywords, hierarchy and IPTC, and reads them back', () => {
|
|
const xml = editsToXmp(defaultEdits(), photo);
|
|
expect(xml).toContain('xmp:Rating="4"');
|
|
expect(xml).toContain('xmp:Label="Green"');
|
|
expect(xml).toContain('<lr:hierarchicalSubject>');
|
|
expect(xml).toContain('photoshop:City="Bristol"');
|
|
expect(xml).toContain('Iptc4xmpCore:Location="Ashton Court"');
|
|
|
|
const meta = xmpToMetadata(xml);
|
|
expect(meta.rating).toBe(4);
|
|
expect(meta.label).toBe('green');
|
|
expect(meta.keywords).toEqual(['Birds', 'Robin']);
|
|
expect(meta.keywordPaths).toEqual([
|
|
'Nature',
|
|
'Nature > Birds',
|
|
'Nature > Birds > Robin',
|
|
]);
|
|
expect(meta.iptc).toEqual(photo.iptc);
|
|
expect(meta.title).toBe('Robin at dawn');
|
|
expect(meta.caption).toBe('First light, heavy frost');
|
|
expect(meta.creator).toBe('Brian Hursey');
|
|
expect(meta.copyright).toBe('© 2026 Brian Hursey');
|
|
});
|
|
|
|
it('reads a sidecar written by Lightroom', () => {
|
|
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:lr="http://ns.adobe.com/lightroom/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmp:Rating="2" xmp:Label="Red" photoshop:Headline="Press day" photoshop:Country="Ireland"><dc:subject><rdf:Bag><rdf:li>Portrait</rdf:li><rdf:li>Maya</rdf:li></rdf:Bag></dc:subject><lr:hierarchicalSubject><rdf:Bag><rdf:li>People > Portrait</rdf:li></rdf:Bag></lr:hierarchicalSubject></rdf:Description></rdf:RDF></x:xmpmeta>`;
|
|
const meta = xmpToMetadata(xml);
|
|
expect(meta.rating).toBe(2);
|
|
expect(meta.label).toBe('red');
|
|
expect(meta.keywords).toEqual(['Portrait', 'Maya']);
|
|
expect(meta.keywordPaths).toEqual(['People > Portrait']);
|
|
expect(meta.iptc.headline).toBe('Press day');
|
|
expect(meta.iptc.country).toBe('Ireland');
|
|
// Nothing the file does not carry is invented.
|
|
expect(meta.iptc.city).toBeUndefined();
|
|
expect(meta.caption).toBeUndefined();
|
|
});
|
|
|
|
it('stays quiet when the file has no metadata', () => {
|
|
const meta = xmpToMetadata(editsToXmp(defaultEdits()));
|
|
expect(meta.rating).toBeUndefined();
|
|
expect(meta.label).toBeUndefined();
|
|
expect(meta.keywords).toEqual([]);
|
|
expect(meta.keywordPaths).toEqual([]);
|
|
expect(meta.iptc).toEqual({});
|
|
});
|
|
|
|
it('rejects a file that is not a sidecar', () => {
|
|
expect(() => xmpToMetadata('<html></html>')).toThrow(/not an XMP/);
|
|
});
|
|
});
|