@file-viewer/renderer-email 2.1.30 → 2.2.1
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/dist/email.js +17 -6
- package/package.json +2 -2
package/dist/email.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFileViewerTranslator, disposeFileViewerRendered, } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerTranslator, disposeFileViewerRendered, resolveFileViewerColorScheme, } from '@file-viewer/core';
|
|
2
2
|
const emailStyle = `
|
|
3
3
|
.email-viewer{position:relative;height:100%;min-height:0;display:flex;flex-direction:column;background:#f3f6f8;color:#172033;box-sizing:border-box}
|
|
4
4
|
.email-viewer *{box-sizing:border-box}
|
|
@@ -39,9 +39,14 @@ const emailStyle = `
|
|
|
39
39
|
.email-error{position:absolute;right:18px;bottom:18px;width:min(460px,calc(100% - 36px));padding:14px;border-radius:14px;background:#fff7e8;color:#8a4b00;box-shadow:0 16px 36px rgba(23,32,51,.14);z-index:3}
|
|
40
40
|
.email-error p{margin:6px 0 0}
|
|
41
41
|
@keyframes email-spin{to{transform:rotate(360deg)}}
|
|
42
|
-
@media (prefers-color-scheme:dark){[data-viewer-theme='system'] .email-viewer{background:#172033;color:#e5eef8}[data-viewer-theme='system'] .email-header,[data-viewer-theme='system'] .attachment-item,[data-viewer-theme='system'] .email-html,[data-viewer-theme='system'] .email-text{background:#fff;color:#172033}}
|
|
43
42
|
[data-viewer-theme='dark'] .email-viewer{background:#172033;color:#e5eef8}
|
|
44
|
-
[data-viewer-theme='dark'] .email-header,[data-viewer-theme='dark'] .attachment-item,[data-viewer-theme='dark'] .email-
|
|
43
|
+
[data-viewer-theme='dark'] .email-header,[data-viewer-theme='dark'] .email-sidebar,[data-viewer-theme='dark'] .attachment-item,[data-viewer-theme='dark'] .email-text,[data-viewer-theme='dark'] .attachment-preview-head{border-color:rgba(139,148,158,.2);background:#111827;color:#e5eef8}
|
|
44
|
+
[data-viewer-theme='dark'] .email-meta p,[data-viewer-theme='dark'] .attachment-item em,[data-viewer-theme='dark'] .attachment-title span,[data-viewer-theme='dark'] .attachment-empty{color:#94a3b8}
|
|
45
|
+
[data-viewer-theme='dark'] .email-meta strong,[data-viewer-theme='dark'] .attachment-title,[data-viewer-theme='dark'] .attachment-item strong{color:#f8fafc}
|
|
46
|
+
[data-viewer-theme='dark'] .body-tabs{background:rgba(139,148,158,.12)}[data-viewer-theme='dark'] .body-tabs button{color:#94a3b8}[data-viewer-theme='dark'] .body-tabs button.active{background:#1f2937;color:#f8fafc}
|
|
47
|
+
[data-viewer-theme='dark'] .email-html{background:#111827;color-scheme:dark}
|
|
48
|
+
[data-viewer-theme='dark'] .email-state{background:rgba(13,17,23,.9);color:#cbd5e1}
|
|
49
|
+
@media (prefers-color-scheme:dark){[data-viewer-theme='system'] .email-viewer{background:#172033;color:#e5eef8}[data-viewer-theme='system'] .email-header,[data-viewer-theme='system'] .email-sidebar,[data-viewer-theme='system'] .attachment-item,[data-viewer-theme='system'] .email-text,[data-viewer-theme='system'] .attachment-preview-head{border-color:rgba(139,148,158,.2);background:#111827;color:#e5eef8}[data-viewer-theme='system'] .email-meta p,[data-viewer-theme='system'] .attachment-item em,[data-viewer-theme='system'] .attachment-title span,[data-viewer-theme='system'] .attachment-empty{color:#94a3b8}[data-viewer-theme='system'] .email-meta strong,[data-viewer-theme='system'] .attachment-title,[data-viewer-theme='system'] .attachment-item strong{color:#f8fafc}[data-viewer-theme='system'] .body-tabs{background:rgba(139,148,158,.12)}[data-viewer-theme='system'] .body-tabs button{color:#94a3b8}[data-viewer-theme='system'] .body-tabs button.active{background:#1f2937;color:#f8fafc}[data-viewer-theme='system'] .email-html{background:#111827;color-scheme:dark}[data-viewer-theme='system'] .email-state{background:rgba(13,17,23,.9);color:#cbd5e1}}
|
|
45
50
|
@media (max-width:860px){.email-meta,.email-body{grid-template-columns:1fr}.email-body{grid-template-rows:auto minmax(0,1fr)}.email-sidebar{border-right:0;border-bottom:1px solid rgba(23,32,51,.08)}}
|
|
46
51
|
`;
|
|
47
52
|
const formatBytes = (value) => {
|
|
@@ -231,13 +236,16 @@ const getAttachmentExtension = (name) => {
|
|
|
231
236
|
const index = name.lastIndexOf('.');
|
|
232
237
|
return index >= 0 ? name.slice(index + 1).toLowerCase() : 'txt';
|
|
233
238
|
};
|
|
234
|
-
const createHtmlSrcdoc = (html, cidUrls) => {
|
|
239
|
+
const createHtmlSrcdoc = (html, cidUrls, darkMode = false) => {
|
|
235
240
|
let next = html;
|
|
236
241
|
cidUrls.forEach((url, cid) => {
|
|
237
242
|
const escaped = cid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
238
243
|
next = next.replace(new RegExp(`cid:${escaped}`, 'gi'), url);
|
|
239
244
|
});
|
|
240
|
-
|
|
245
|
+
const pageStyle = darkMode
|
|
246
|
+
? ':root{color-scheme:dark}body{background:#111827;color:#e5e7eb}'
|
|
247
|
+
: ':root{color-scheme:light}body{background:#fff;color:#172033}';
|
|
248
|
+
return `<!doctype html><html><head><meta charset="utf-8"><base target="_blank"><style>${pageStyle}body{margin:0;padding:18px;font-family:Aptos,"Segoe UI",sans-serif;line-height:1.6;word-break:break-word;}img{max-width:100%;height:auto;}</style></head><body>${next}</body></html>`;
|
|
241
249
|
};
|
|
242
250
|
const appendMeta = (meta, label, value) => {
|
|
243
251
|
const row = document.createElement('p');
|
|
@@ -247,11 +255,14 @@ const appendMeta = (meta, label, value) => {
|
|
|
247
255
|
meta.append(row);
|
|
248
256
|
};
|
|
249
257
|
export default async function renderEmail(buffer, target, type = 'eml', context) {
|
|
258
|
+
var _a, _b, _c, _d;
|
|
250
259
|
const normalizedType = type === 'msg' ? 'msg' : type === 'mbox' ? 'mbox' : 'eml';
|
|
251
260
|
const filename = (context === null || context === void 0 ? void 0 : context.filename) || `message.${normalizedType}`;
|
|
252
261
|
const objectUrls = [];
|
|
253
262
|
const cidUrls = new Map();
|
|
254
263
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
264
|
+
const systemDark = (_c = (_b = (_a = target.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.matchMedia) === null || _b === void 0 ? void 0 : _b.call(_a, '(prefers-color-scheme: dark)').matches) !== null && _c !== void 0 ? _c : false;
|
|
265
|
+
const darkMode = resolveFileViewerColorScheme((_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.theme, systemDark) === 'dark';
|
|
255
266
|
const cleanups = [];
|
|
256
267
|
let nestedRendered;
|
|
257
268
|
let overlay = null;
|
|
@@ -337,7 +348,7 @@ export default async function renderEmail(buffer, target, type = 'eml', context)
|
|
|
337
348
|
if (activeBody === 'html' && parsed.html) {
|
|
338
349
|
const iframe = createElement('iframe', 'email-html');
|
|
339
350
|
iframe.setAttribute('sandbox', '');
|
|
340
|
-
iframe.srcdoc = createHtmlSrcdoc(parsed.html, cidUrls);
|
|
351
|
+
iframe.srcdoc = createHtmlSrcdoc(parsed.html, cidUrls, darkMode);
|
|
341
352
|
messageContent.append(iframe);
|
|
342
353
|
return;
|
|
343
354
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-email",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone email renderer plugin for Flyfish File Viewer with EML, MSG, MBOX, attachments, and nested previews.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "2.1
|
|
58
|
+
"@file-viewer/core": "2.2.1",
|
|
59
59
|
"@kenjiuno/msgreader": "^1.28.0",
|
|
60
60
|
"postal-mime": "^2.7.4"
|
|
61
61
|
},
|