@molecule/app-exif-panel-vue 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +341 -2
- package/dist/ExifPanel.d.ts +65 -0
- package/dist/ExifPanel.d.ts.map +1 -0
- package/dist/ExifPanel.js +164 -0
- package/dist/ExifPanel.js.map +1 -0
- package/dist/format-parts.d.ts +47 -0
- package/dist/format-parts.d.ts.map +1 -0
- package/dist/format-parts.js +88 -0
- package/dist/format-parts.js.map +1 -0
- package/dist/format.d.ts +93 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +164 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue EXIF metadata panel.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-exif-panel-react`'s `ExifPanel` — the same
|
|
5
|
+
* props (React names), the same ClassMap tokens and the same DOM for the same
|
|
6
|
+
* input.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { defineComponent, h } from 'vue';
|
|
11
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
12
|
+
import { useLocale, useTranslation } from '@molecule/app-vue';
|
|
13
|
+
import { buildMapLink, formatCamera, formatGps, formatTimestamp } from './format.js';
|
|
14
|
+
import { formatApertureNumber, formatFocalLengthNumber, formatIsoNumber, formatShutterNumber, } from './format-parts.js';
|
|
15
|
+
/**
|
|
16
|
+
* Render parsed EXIF metadata as a structured panel — camera, lens,
|
|
17
|
+
* exposure (aperture + shutter + ISO + focal length), GPS (with optional
|
|
18
|
+
* map link), and capture timestamp.
|
|
19
|
+
*
|
|
20
|
+
* The component is purely presentational: callers parse the binary EXIF
|
|
21
|
+
* payload elsewhere and pass the normalized `exif` object in. Empty /
|
|
22
|
+
* undefined fields are silently skipped.
|
|
23
|
+
*
|
|
24
|
+
* All styling resolves through `getClassMap()`. Every string the panel
|
|
25
|
+
* writes goes through `useTranslation()` — the exposure notations as
|
|
26
|
+
* `exifPanel.value.*` keys around their digits — and the capture
|
|
27
|
+
* timestamp formats in the app's active locale (`useLocale()`), so a
|
|
28
|
+
* locale switch re-words and re-formats the panel at once. No hardcoded
|
|
29
|
+
* UI strings or styling-library class names.
|
|
30
|
+
*
|
|
31
|
+
* @param props - Component props (see {@link ExifPanelProps}).
|
|
32
|
+
* @returns The rendered panel component.
|
|
33
|
+
*/
|
|
34
|
+
export const ExifPanel = defineComponent({
|
|
35
|
+
name: 'ExifPanel',
|
|
36
|
+
props: {
|
|
37
|
+
exif: {
|
|
38
|
+
type: Object,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
compact: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: false,
|
|
44
|
+
},
|
|
45
|
+
showGps: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: true,
|
|
48
|
+
},
|
|
49
|
+
heading: String,
|
|
50
|
+
className: String,
|
|
51
|
+
},
|
|
52
|
+
setup(props) {
|
|
53
|
+
const cm = getClassMap();
|
|
54
|
+
const { t } = useTranslation();
|
|
55
|
+
// Re-renders on a locale switch, so the timestamp re-formats at once.
|
|
56
|
+
const activeLocale = useLocale();
|
|
57
|
+
return () => {
|
|
58
|
+
const { exif, compact = false, showGps = true, heading, className } = props;
|
|
59
|
+
const camera = formatCamera(exif.make, exif.model);
|
|
60
|
+
const lens = exif.lensModel?.trim() || null;
|
|
61
|
+
const apertureDigits = formatApertureNumber(exif.fNumber);
|
|
62
|
+
const shutterDigits = formatShutterNumber(exif.exposureTime);
|
|
63
|
+
const isoDigits = formatIsoNumber(exif.iso);
|
|
64
|
+
const focalDigits = formatFocalLengthNumber(exif.focalLength);
|
|
65
|
+
const focal35Digits = formatFocalLengthNumber(exif.focalLength35mm);
|
|
66
|
+
// Each notation's digits render through t() (`exifPanel.value.*`), so
|
|
67
|
+
// a locale re-words the unit around them; the ` · ` join is punctuation.
|
|
68
|
+
const apertureText = apertureDigits === null
|
|
69
|
+
? null
|
|
70
|
+
: t('exifPanel.value.aperture', { value: apertureDigits }, {
|
|
71
|
+
defaultValue: 'f/{{value}}',
|
|
72
|
+
});
|
|
73
|
+
const shutterText = shutterDigits === null
|
|
74
|
+
? null
|
|
75
|
+
: t('exifPanel.value.shutter', { value: shutterDigits }, { defaultValue: '{{value}} s' });
|
|
76
|
+
const isoText = isoDigits === null
|
|
77
|
+
? null
|
|
78
|
+
: t('exifPanel.value.iso', { value: isoDigits }, { defaultValue: 'ISO {{value}}' });
|
|
79
|
+
const focalText = focalDigits === null
|
|
80
|
+
? null
|
|
81
|
+
: t('exifPanel.value.focalLength', { value: focalDigits }, { defaultValue: '{{value}} mm' });
|
|
82
|
+
const focal35Text = focal35Digits === null
|
|
83
|
+
? null
|
|
84
|
+
: t('exifPanel.value.focalLength', { value: focal35Digits }, {
|
|
85
|
+
defaultValue: '{{value}} mm',
|
|
86
|
+
});
|
|
87
|
+
const exposureParts = [apertureText, shutterText, isoText, focalText].filter((v) => v !== null);
|
|
88
|
+
const gpsText = showGps ? formatGps(exif.gpsLatitude, exif.gpsLongitude) : null;
|
|
89
|
+
const mapHref = showGps ? buildMapLink(exif.gpsLatitude, exif.gpsLongitude) : null;
|
|
90
|
+
const timestamp = formatTimestamp(exif.dateTimeOriginal, activeLocale.value);
|
|
91
|
+
const software = exif.software?.trim() || null;
|
|
92
|
+
const copyright = exif.copyright?.trim() || null;
|
|
93
|
+
const headingText = heading ?? t('exifPanel.heading', {}, { defaultValue: 'EXIF' });
|
|
94
|
+
const eyebrowText = t('exifPanel.eyebrow', {}, { defaultValue: 'Frame metadata' });
|
|
95
|
+
const labelSize = compact ? 'xs' : 'sm';
|
|
96
|
+
const valueSize = compact ? 'sm' : 'base';
|
|
97
|
+
const rowGap = compact ? 'sm' : 'md';
|
|
98
|
+
const padScale = compact ? 3 : 4;
|
|
99
|
+
const rowClass = cm.cn(cm.flex({ align: 'start', justify: 'between', gap: rowGap }), cm.sp('px', padScale), cm.sp('py', compact ? 2 : 3), cm.borderB);
|
|
100
|
+
/**
|
|
101
|
+
* Render a single label/value row with the molecule ClassMap helpers.
|
|
102
|
+
*
|
|
103
|
+
* @param molId - Stable `data-mol-id` token for the row.
|
|
104
|
+
* @param label - Translated label text.
|
|
105
|
+
* @param value - Already-formatted value node.
|
|
106
|
+
* @returns The row element, or `null` when there is no value.
|
|
107
|
+
*/
|
|
108
|
+
const renderRow = (molId, label, value) => {
|
|
109
|
+
if (value === null || value === undefined || value === '')
|
|
110
|
+
return null;
|
|
111
|
+
return h('div', { 'data-mol-id': molId, class: rowClass }, [
|
|
112
|
+
h('dt', { class: cm.cn(cm.textSize(labelSize), cm.fontWeight('medium'), cm.textMuted) }, label),
|
|
113
|
+
h('dd', { class: cm.cn(cm.textSize(valueSize), cm.textRight) }, [value]),
|
|
114
|
+
]);
|
|
115
|
+
};
|
|
116
|
+
const gpsValue = gpsText
|
|
117
|
+
? mapHref
|
|
118
|
+
? h('a', {
|
|
119
|
+
href: mapHref,
|
|
120
|
+
target: '_blank',
|
|
121
|
+
rel: 'noreferrer noopener',
|
|
122
|
+
'data-mol-id': 'exif-panel-map-link',
|
|
123
|
+
class: cm.link,
|
|
124
|
+
}, gpsText)
|
|
125
|
+
: gpsText
|
|
126
|
+
: null;
|
|
127
|
+
const rows = [
|
|
128
|
+
renderRow('exif-panel-row-camera', t('exifPanel.camera', {}, { defaultValue: 'Camera' }), camera),
|
|
129
|
+
renderRow('exif-panel-row-lens', t('exifPanel.lens', {}, { defaultValue: 'Lens' }), lens),
|
|
130
|
+
renderRow('exif-panel-row-exposure', t('exifPanel.exposure', {}, { defaultValue: 'Exposure' }), exposureParts.length > 0 ? exposureParts.join(' · ') : null),
|
|
131
|
+
focal35Text && focal35Text !== focalText
|
|
132
|
+
? renderRow('exif-panel-row-focal35', t('exifPanel.focalLength35mm', {}, { defaultValue: '35 mm equivalent' }), focal35Text)
|
|
133
|
+
: null,
|
|
134
|
+
gpsText
|
|
135
|
+
? renderRow('exif-panel-row-gps', t('exifPanel.gps', {}, { defaultValue: 'GPS' }), gpsValue)
|
|
136
|
+
: null,
|
|
137
|
+
renderRow('exif-panel-row-timestamp', t('exifPanel.timestamp', {}, { defaultValue: 'Captured' }), timestamp),
|
|
138
|
+
renderRow('exif-panel-row-software', t('exifPanel.software', {}, { defaultValue: 'Software' }), software),
|
|
139
|
+
renderRow('exif-panel-row-copyright', t('exifPanel.copyright', {}, { defaultValue: 'Copyright' }), copyright),
|
|
140
|
+
].filter((row) => row !== null);
|
|
141
|
+
return h('aside', {
|
|
142
|
+
'data-mol-id': 'exif-panel',
|
|
143
|
+
'aria-label': t('exifPanel.aria.region', {}, { defaultValue: 'EXIF metadata' }),
|
|
144
|
+
class: cm.cn(cm.surface, className),
|
|
145
|
+
}, [
|
|
146
|
+
h('header', {
|
|
147
|
+
'data-mol-id': 'exif-panel-header',
|
|
148
|
+
class: cm.cn(cm.sp('px', padScale), cm.sp('py', padScale), cm.borderB),
|
|
149
|
+
}, [
|
|
150
|
+
h('p', {
|
|
151
|
+
'data-mol-id': 'exif-panel-eyebrow',
|
|
152
|
+
class: cm.cn(cm.textSize('xs'), cm.fontWeight('medium'), cm.textMuted),
|
|
153
|
+
}, eyebrowText),
|
|
154
|
+
h('h3', {
|
|
155
|
+
'data-mol-id': 'exif-panel-heading',
|
|
156
|
+
class: cm.cn(cm.textSize(compact ? 'sm' : 'base'), cm.fontWeight('bold')),
|
|
157
|
+
}, headingText),
|
|
158
|
+
]),
|
|
159
|
+
h('dl', { 'data-mol-id': 'exif-panel-list' }, rows),
|
|
160
|
+
]);
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
//# sourceMappingURL=ExifPanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExifPanel.js","sourceRoot":"","sources":["../src/ExifPanel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAA8C,MAAM,KAAK,CAAA;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAE7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,mBAAmB,GACpB,MAAM,mBAAmB,CAAA;AAG1B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC;IACvC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE;QACL,IAAI,EAAE;YACJ,IAAI,EAAE,MAA4B;YAClC,QAAQ,EAAE,IAAI;SACf;QACD,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,KAAK;SACf;QACD,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,IAAI;SACd;QACD,OAAO,EAAE,MAAM;QACf,SAAS,EAAE,MAAM;KAClB;IACD,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,GAAG,WAAW,EAAE,CAAA;QACxB,MAAM,EAAE,CAAC,EAAE,GAAG,cAAc,EAAE,CAAA;QAC9B,sEAAsE;QACtE,MAAM,YAAY,GAAG,SAAS,EAAE,CAAA;QAEhC,OAAO,GAAU,EAAE;YACjB,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,SAAS,EAA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,SAAS,CAAC;qBACvE,EACD,WAAW,CACZ;oBACD,CAAC,CACC,IAAI,EACJ;wBACE,aAAa,EAAE,oBAAoB;wBACnC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;qBAC1E,EACD,WAAW,CACZ;iBACF,CACF;gBACD,CAAC,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,IAAI,CAAC;aACpD,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The number part of each EXIF notation, without its prefix or unit.
|
|
3
|
+
*
|
|
4
|
+
* `format.ts` joins these digits with the canonical English prefix / unit
|
|
5
|
+
* (`f/`, `s`, `ISO`, `mm`) for callers that want the plain notation. The
|
|
6
|
+
* components instead pass them to `t()` as the `{{value}}` of an
|
|
7
|
+
* `exifPanel.value.*` key, so a locale re-words the unit around the digits
|
|
8
|
+
* (Japanese `{{value}}秒`) while the digits stay this helper's.
|
|
9
|
+
*
|
|
10
|
+
* Internal to the panel — not part of the package's public exports.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The f-number of an aperture as digits, without the `f/`.
|
|
16
|
+
*
|
|
17
|
+
* @param fNumber - The aperture value (e.g. `2.8`, `5.6`, `8`).
|
|
18
|
+
* @returns A digit string like `"2.8"` or `"8"`, or `null` when the input
|
|
19
|
+
* is missing / invalid.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatApertureNumber(fNumber: number | undefined): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* A shutter / exposure time as digits, without the `s`. Sub-second times
|
|
24
|
+
* render as a `1/x` reciprocal with the denominator rounded; longer
|
|
25
|
+
* exposures stay in seconds.
|
|
26
|
+
*
|
|
27
|
+
* @param seconds - Exposure time in seconds.
|
|
28
|
+
* @returns A digit string like `"1/125"`, `"2.5"` or `"30"`, or `null`
|
|
29
|
+
* when the input is missing / invalid.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatShutterNumber(seconds: number | undefined): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* An ISO sensitivity as digits, without the `ISO` prefix.
|
|
34
|
+
*
|
|
35
|
+
* @param iso - The ISO value (e.g. `100`, `1600`).
|
|
36
|
+
* @returns A digit string like `"1600"`, or `null` when missing.
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatIsoNumber(iso: number | undefined): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* A focal length as digits, without the `mm`.
|
|
41
|
+
*
|
|
42
|
+
* @param mm - Focal length in millimetres.
|
|
43
|
+
* @returns A digit string like `"50"` or `"35.5"`, or `null` when the
|
|
44
|
+
* input is missing / invalid.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatFocalLengthNumber(mm: number | undefined): string | null;
|
|
47
|
+
//# sourceMappingURL=format-parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-parts.d.ts","sourceRoot":"","sources":["../src/format-parts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0BH;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAM9E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAG7E"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The number part of each EXIF notation, without its prefix or unit.
|
|
3
|
+
*
|
|
4
|
+
* `format.ts` joins these digits with the canonical English prefix / unit
|
|
5
|
+
* (`f/`, `s`, `ISO`, `mm`) for callers that want the plain notation. The
|
|
6
|
+
* components instead pass them to `t()` as the `{{value}}` of an
|
|
7
|
+
* `exifPanel.value.*` key, so a locale re-words the unit around the digits
|
|
8
|
+
* (Japanese `{{value}}秒`) while the digits stay this helper's.
|
|
9
|
+
*
|
|
10
|
+
* Internal to the panel — not part of the package's public exports.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The digits of a quantity rounded to one decimal, a whole number's
|
|
16
|
+
* trailing `.0` dropped.
|
|
17
|
+
*
|
|
18
|
+
* @param value - A validated, positive quantity.
|
|
19
|
+
* @returns Its digit text, e.g. `"2.8"`, `"50"`.
|
|
20
|
+
*/
|
|
21
|
+
const digits = (value) => {
|
|
22
|
+
const rounded = Math.round(value * 10) / 10;
|
|
23
|
+
return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(1);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The guard every quantity shares: a finite number above zero.
|
|
27
|
+
*
|
|
28
|
+
* @param value - The raw EXIF quantity.
|
|
29
|
+
* @returns The number, or `null` when it is missing / invalid.
|
|
30
|
+
*/
|
|
31
|
+
const positive = (value) => {
|
|
32
|
+
if (value === undefined || value === null)
|
|
33
|
+
return null;
|
|
34
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
35
|
+
return null;
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The f-number of an aperture as digits, without the `f/`.
|
|
40
|
+
*
|
|
41
|
+
* @param fNumber - The aperture value (e.g. `2.8`, `5.6`, `8`).
|
|
42
|
+
* @returns A digit string like `"2.8"` or `"8"`, or `null` when the input
|
|
43
|
+
* is missing / invalid.
|
|
44
|
+
*/
|
|
45
|
+
export function formatApertureNumber(fNumber) {
|
|
46
|
+
const value = positive(fNumber);
|
|
47
|
+
return value === null ? null : digits(value);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A shutter / exposure time as digits, without the `s`. Sub-second times
|
|
51
|
+
* render as a `1/x` reciprocal with the denominator rounded; longer
|
|
52
|
+
* exposures stay in seconds.
|
|
53
|
+
*
|
|
54
|
+
* @param seconds - Exposure time in seconds.
|
|
55
|
+
* @returns A digit string like `"1/125"`, `"2.5"` or `"30"`, or `null`
|
|
56
|
+
* when the input is missing / invalid.
|
|
57
|
+
*/
|
|
58
|
+
export function formatShutterNumber(seconds) {
|
|
59
|
+
const value = positive(seconds);
|
|
60
|
+
if (value === null)
|
|
61
|
+
return null;
|
|
62
|
+
if (value >= 1)
|
|
63
|
+
return digits(value);
|
|
64
|
+
// Round the reciprocal denominator to nearest integer for sub-second.
|
|
65
|
+
return `1/${Math.round(1 / value)}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* An ISO sensitivity as digits, without the `ISO` prefix.
|
|
69
|
+
*
|
|
70
|
+
* @param iso - The ISO value (e.g. `100`, `1600`).
|
|
71
|
+
* @returns A digit string like `"1600"`, or `null` when missing.
|
|
72
|
+
*/
|
|
73
|
+
export function formatIsoNumber(iso) {
|
|
74
|
+
const value = positive(iso);
|
|
75
|
+
return value === null ? null : String(Math.round(value));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A focal length as digits, without the `mm`.
|
|
79
|
+
*
|
|
80
|
+
* @param mm - Focal length in millimetres.
|
|
81
|
+
* @returns A digit string like `"50"` or `"35.5"`, or `null` when the
|
|
82
|
+
* input is missing / invalid.
|
|
83
|
+
*/
|
|
84
|
+
export function formatFocalLengthNumber(mm) {
|
|
85
|
+
const value = positive(mm);
|
|
86
|
+
return value === null ? null : digits(value);
|
|
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,CAAC,KAAK,CAAC,CAAA;IACpC,sEAAsE;IACtE,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAA;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAuB;IACrD,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC3B,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,EAAsB;IAC5D,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC1B,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC9C,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure string-formatting helpers for EXIF values.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the React component so they can be unit-tested
|
|
5
|
+
* without a DOM and reused by callers that want the formatted strings
|
|
6
|
+
* for non-rendering purposes (alt text, share captions, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Format an aperture f-number as `f/N` with one decimal place dropped
|
|
12
|
+
* when whole.
|
|
13
|
+
*
|
|
14
|
+
* @param fNumber - The aperture value (e.g. `2.8`, `5.6`, `8`).
|
|
15
|
+
* @returns A display string like `"f/2.8"` or `"f/8"`, or `null` when
|
|
16
|
+
* the input is missing / invalid.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatAperture(fNumber: number | undefined): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Format a shutter / exposure time in seconds as a human-readable
|
|
21
|
+
* string. Sub-second times are rendered as a `1/x s` reciprocal with
|
|
22
|
+
* the denominator rounded; longer exposures stay in seconds.
|
|
23
|
+
*
|
|
24
|
+
* @param seconds - Exposure time in seconds.
|
|
25
|
+
* @returns A display string like `"1/125 s"` or `"2 s"`, or `null` when
|
|
26
|
+
* the input is missing / invalid.
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatShutter(seconds: number | undefined): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Format an ISO sensitivity as `ISO N`.
|
|
31
|
+
*
|
|
32
|
+
* @param iso - The ISO value (e.g. `100`, `1600`).
|
|
33
|
+
* @returns A display string like `"ISO 1600"`, or `null` when missing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatIso(iso: number | undefined): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Format a focal length value as `N mm`.
|
|
38
|
+
*
|
|
39
|
+
* @param mm - Focal length in millimetres.
|
|
40
|
+
* @returns A display string like `"50 mm"`, or `null` when missing.
|
|
41
|
+
*/
|
|
42
|
+
export declare function formatFocalLength(mm: number | undefined): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Format a single GPS coordinate (latitude or longitude) as
|
|
45
|
+
* deg/min/sec with a hemisphere suffix.
|
|
46
|
+
*
|
|
47
|
+
* @param value - Signed decimal degrees.
|
|
48
|
+
* @param axis - Which axis the value represents — picks `N`/`S` vs `E`/`W`.
|
|
49
|
+
* @returns A string like `"37° 25' 19.07" N"`, or `null` when missing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatDms(value: number | undefined, axis: 'lat' | 'lon'): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Format a GPS coordinate pair as a single deg/min/sec string.
|
|
54
|
+
*
|
|
55
|
+
* @param latitude - Latitude in signed decimal degrees.
|
|
56
|
+
* @param longitude - Longitude in signed decimal degrees.
|
|
57
|
+
* @returns A combined string like `"37° 25' 19.07" N, 122° 5' 4.16" W"`,
|
|
58
|
+
* or `null` if either value is missing.
|
|
59
|
+
*/
|
|
60
|
+
export declare function formatGps(latitude: number | undefined, longitude: number | undefined): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Build an OpenStreetMap link URL for a GPS coordinate pair.
|
|
63
|
+
*
|
|
64
|
+
* @param latitude - Latitude in signed decimal degrees.
|
|
65
|
+
* @param longitude - Longitude in signed decimal degrees.
|
|
66
|
+
* @returns An `https://www.openstreetmap.org/?...` URL, or `null` when
|
|
67
|
+
* either input is missing.
|
|
68
|
+
*/
|
|
69
|
+
export declare function buildMapLink(latitude: number | undefined, longitude: number | undefined): string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Format an EXIF capture timestamp. Accepts `Date`, ISO string, or
|
|
72
|
+
* epoch milliseconds and renders via `toLocaleString` so the result
|
|
73
|
+
* respects the given locale and the host environment's timezone — pass
|
|
74
|
+
* the app's active locale so the text follows a locale switch.
|
|
75
|
+
*
|
|
76
|
+
* @param value - The timestamp value pulled from EXIF.
|
|
77
|
+
* @param locale - The locale to format in (an `Intl` locale code); the
|
|
78
|
+
* host environment's locale when omitted.
|
|
79
|
+
* @returns A locale-formatted date/time string, or `null` when missing
|
|
80
|
+
* or unparseable.
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatTimestamp(value: Date | string | number | undefined, locale?: string): string | null;
|
|
83
|
+
/**
|
|
84
|
+
* Compose camera make + model into a single `"Make Model"` string,
|
|
85
|
+
* collapsing duplication when the model already starts with the make
|
|
86
|
+
* (Sony often does this).
|
|
87
|
+
*
|
|
88
|
+
* @param make - Camera manufacturer.
|
|
89
|
+
* @param model - Camera model.
|
|
90
|
+
* @returns The combined label, or `null` when both inputs are missing.
|
|
91
|
+
*/
|
|
92
|
+
export declare function formatCamera(make: string | undefined, model: string | undefined): string | null;
|
|
93
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH;;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EXIF values.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the React component so they can be unit-tested
|
|
5
|
+
* without a DOM and reused by callers that want the formatted strings
|
|
6
|
+
* for non-rendering purposes (alt text, share captions, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { formatApertureNumber, formatFocalLengthNumber, formatIsoNumber, formatShutterNumber, } from './format-parts.js';
|
|
11
|
+
/**
|
|
12
|
+
* Format an aperture f-number as `f/N` with one decimal place dropped
|
|
13
|
+
* when whole.
|
|
14
|
+
*
|
|
15
|
+
* @param fNumber - The aperture value (e.g. `2.8`, `5.6`, `8`).
|
|
16
|
+
* @returns A display string like `"f/2.8"` or `"f/8"`, or `null` when
|
|
17
|
+
* the input is missing / invalid.
|
|
18
|
+
*/
|
|
19
|
+
export function formatAperture(fNumber) {
|
|
20
|
+
const digits = formatApertureNumber(fNumber);
|
|
21
|
+
return digits === null ? null : `f/${digits}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Format a shutter / exposure time in seconds as a human-readable
|
|
25
|
+
* string. Sub-second times are rendered as a `1/x s` reciprocal with
|
|
26
|
+
* the denominator rounded; longer exposures stay in seconds.
|
|
27
|
+
*
|
|
28
|
+
* @param seconds - Exposure time in seconds.
|
|
29
|
+
* @returns A display string like `"1/125 s"` or `"2 s"`, or `null` when
|
|
30
|
+
* the input is missing / invalid.
|
|
31
|
+
*/
|
|
32
|
+
export function formatShutter(seconds) {
|
|
33
|
+
const digits = formatShutterNumber(seconds);
|
|
34
|
+
return digits === null ? null : `${digits} s`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Format an ISO sensitivity as `ISO N`.
|
|
38
|
+
*
|
|
39
|
+
* @param iso - The ISO value (e.g. `100`, `1600`).
|
|
40
|
+
* @returns A display string like `"ISO 1600"`, or `null` when missing.
|
|
41
|
+
*/
|
|
42
|
+
export function formatIso(iso) {
|
|
43
|
+
const digits = formatIsoNumber(iso);
|
|
44
|
+
return digits === null ? null : `ISO ${digits}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Format a focal length value as `N mm`.
|
|
48
|
+
*
|
|
49
|
+
* @param mm - Focal length in millimetres.
|
|
50
|
+
* @returns A display string like `"50 mm"`, or `null` when missing.
|
|
51
|
+
*/
|
|
52
|
+
export function formatFocalLength(mm) {
|
|
53
|
+
const digits = formatFocalLengthNumber(mm);
|
|
54
|
+
return digits === null ? null : `${digits} mm`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Format a single GPS coordinate (latitude or longitude) as
|
|
58
|
+
* deg/min/sec with a hemisphere suffix.
|
|
59
|
+
*
|
|
60
|
+
* @param value - Signed decimal degrees.
|
|
61
|
+
* @param axis - Which axis the value represents — picks `N`/`S` vs `E`/`W`.
|
|
62
|
+
* @returns A string like `"37° 25' 19.07" N"`, or `null` when missing.
|
|
63
|
+
*/
|
|
64
|
+
export function formatDms(value, axis) {
|
|
65
|
+
if (value === undefined || value === null)
|
|
66
|
+
return null;
|
|
67
|
+
if (!Number.isFinite(value))
|
|
68
|
+
return null;
|
|
69
|
+
const positiveLabel = axis === 'lat' ? 'N' : 'E';
|
|
70
|
+
const negativeLabel = axis === 'lat' ? 'S' : 'W';
|
|
71
|
+
const hemisphere = value >= 0 ? positiveLabel : negativeLabel;
|
|
72
|
+
const abs = Math.abs(value);
|
|
73
|
+
const deg = Math.floor(abs);
|
|
74
|
+
const minutesFloat = (abs - deg) * 60;
|
|
75
|
+
const min = Math.floor(minutesFloat);
|
|
76
|
+
const seconds = (minutesFloat - min) * 60;
|
|
77
|
+
const secText = (Math.round(seconds * 100) / 100).toFixed(2);
|
|
78
|
+
return `${deg}° ${min}' ${secText}" ${hemisphere}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Format a GPS coordinate pair as a single deg/min/sec string.
|
|
82
|
+
*
|
|
83
|
+
* @param latitude - Latitude in signed decimal degrees.
|
|
84
|
+
* @param longitude - Longitude in signed decimal degrees.
|
|
85
|
+
* @returns A combined string like `"37° 25' 19.07" N, 122° 5' 4.16" W"`,
|
|
86
|
+
* or `null` if either value is missing.
|
|
87
|
+
*/
|
|
88
|
+
export function formatGps(latitude, longitude) {
|
|
89
|
+
const lat = formatDms(latitude, 'lat');
|
|
90
|
+
const lon = formatDms(longitude, 'lon');
|
|
91
|
+
if (!lat || !lon)
|
|
92
|
+
return null;
|
|
93
|
+
return `${lat}, ${lon}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Build an OpenStreetMap link URL for a GPS coordinate pair.
|
|
97
|
+
*
|
|
98
|
+
* @param latitude - Latitude in signed decimal degrees.
|
|
99
|
+
* @param longitude - Longitude in signed decimal degrees.
|
|
100
|
+
* @returns An `https://www.openstreetmap.org/?...` URL, or `null` when
|
|
101
|
+
* either input is missing.
|
|
102
|
+
*/
|
|
103
|
+
export function buildMapLink(latitude, longitude) {
|
|
104
|
+
if (latitude === undefined || longitude === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
if (!Number.isFinite(latitude) || !Number.isFinite(longitude))
|
|
107
|
+
return null;
|
|
108
|
+
const lat = latitude.toFixed(6);
|
|
109
|
+
const lon = longitude.toFixed(6);
|
|
110
|
+
return `https://www.openstreetmap.org/?mlat=${lat}&mlon=${lon}#map=15/${lat}/${lon}`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Format an EXIF capture timestamp. Accepts `Date`, ISO string, or
|
|
114
|
+
* epoch milliseconds and renders via `toLocaleString` so the result
|
|
115
|
+
* respects the given locale and the host environment's timezone — pass
|
|
116
|
+
* the app's active locale so the text follows a locale switch.
|
|
117
|
+
*
|
|
118
|
+
* @param value - The timestamp value pulled from EXIF.
|
|
119
|
+
* @param locale - The locale to format in (an `Intl` locale code); the
|
|
120
|
+
* host environment's locale when omitted.
|
|
121
|
+
* @returns A locale-formatted date/time string, or `null` when missing
|
|
122
|
+
* or unparseable.
|
|
123
|
+
*/
|
|
124
|
+
export function formatTimestamp(value, locale) {
|
|
125
|
+
if (value === undefined || value === null)
|
|
126
|
+
return null;
|
|
127
|
+
let date;
|
|
128
|
+
if (value instanceof Date) {
|
|
129
|
+
date = value;
|
|
130
|
+
}
|
|
131
|
+
else if (typeof value === 'number') {
|
|
132
|
+
date = new Date(value);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
date = new Date(value);
|
|
136
|
+
}
|
|
137
|
+
if (Number.isNaN(date.getTime()))
|
|
138
|
+
return null;
|
|
139
|
+
return date.toLocaleString(locale);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Compose camera make + model into a single `"Make Model"` string,
|
|
143
|
+
* collapsing duplication when the model already starts with the make
|
|
144
|
+
* (Sony often does this).
|
|
145
|
+
*
|
|
146
|
+
* @param make - Camera manufacturer.
|
|
147
|
+
* @param model - Camera model.
|
|
148
|
+
* @returns The combined label, or `null` when both inputs are missing.
|
|
149
|
+
*/
|
|
150
|
+
export function formatCamera(make, model) {
|
|
151
|
+
const m = make?.trim();
|
|
152
|
+
const md = model?.trim();
|
|
153
|
+
if (!m && !md)
|
|
154
|
+
return null;
|
|
155
|
+
if (!md)
|
|
156
|
+
return m ?? null;
|
|
157
|
+
if (!m)
|
|
158
|
+
return md;
|
|
159
|
+
// Avoid "Sony Sony a7 III" when model already starts with make.
|
|
160
|
+
if (md.toLowerCase().startsWith(m.toLowerCase()))
|
|
161
|
+
return md;
|
|
162
|
+
return `${m} ${md}`;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,mBAAmB,GACpB,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC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AE,CAAA;IACjB,gEAAgE;IAChE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAAE,OAAO,EAAE,CAAA;IAC3D,OAAO,GAAG,CAAC,IAAI,EAAE,EAAE,CAAA;AACrB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue EXIF metadata panel for photo-sharing apps.
|
|
3
|
+
*
|
|
4
|
+
* Exports `<ExifPanel>` — a structured renderer for already-parsed EXIF
|
|
5
|
+
* data (camera, lens, aperture, shutter, ISO, focal length, GPS,
|
|
6
|
+
* timestamp, software, copyright). The caller is responsible for
|
|
7
|
+
* decoding the raw EXIF payload (e.g. via the `exifr` library); this
|
|
8
|
+
* package is a styling-agnostic, i18n-aware renderer only.
|
|
9
|
+
*
|
|
10
|
+
* Also exports the `ExifData` and `ExifPanelProps` types and the pure
|
|
11
|
+
* formatting helpers (`formatAperture`, `formatShutter`, `formatIso`,
|
|
12
|
+
* `formatFocalLength`, `formatGps`, `formatTimestamp`, `formatCamera`,
|
|
13
|
+
* `buildMapLink`, `formatDms`).
|
|
14
|
+
*
|
|
15
|
+
* It is the Vue counterpart of `@molecule/app-exif-panel-react`: the same
|
|
16
|
+
* props (React names), the same ClassMap tokens and the same DOM for the
|
|
17
|
+
* same input.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
22
|
+
* import { ExifPanel } from '@molecule/app-exif-panel-vue'
|
|
23
|
+
*
|
|
24
|
+
* const PhotoMetadata = defineComponent({
|
|
25
|
+
* props: { exif: { type: Object, required: true } },
|
|
26
|
+
* setup(props) {
|
|
27
|
+
* return () => h(ExifPanel, { exif: props.exif, showGps: true, compact: false })
|
|
28
|
+
* },
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* createApp(PhotoMetadata, { exif: parsedExif }).mount('#app')
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Requires a bonded ClassMap (`getClassMap()`) and the binding's i18n
|
|
36
|
+
* provider for `useTranslation()` — the same requirements as the React
|
|
37
|
+
* package. All user-facing text resolves through `t()` with React's keys
|
|
38
|
+
* and English `defaultValue`s.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
export * from './ExifPanel.js';
|
|
43
|
+
export * from './format.js';
|
|
44
|
+
export * from './types.js';
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|