@open-file-viewer/core 0.1.21 → 0.1.22
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/index.cjs +123 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +123 -70
- package/dist/index.js.map +1 -1
- package/dist/style.css +17 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -756,12 +756,17 @@ function createViewer(options) {
|
|
|
756
756
|
currentIndex = clampIndex(index, queue.length);
|
|
757
757
|
await renderQueueItem(currentIndex);
|
|
758
758
|
};
|
|
759
|
-
const toolbar = createToolbar(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
759
|
+
const toolbar = createToolbar(
|
|
760
|
+
options.toolbar,
|
|
761
|
+
viewport,
|
|
762
|
+
{
|
|
763
|
+
getLength: () => queue.length,
|
|
764
|
+
next: () => goTo(currentIndex + 1),
|
|
765
|
+
previous: () => goTo(currentIndex - 1),
|
|
766
|
+
command: (command) => currentInstance?.command?.(command)
|
|
767
|
+
},
|
|
768
|
+
options.locale || "en-US"
|
|
769
|
+
);
|
|
765
770
|
if (toolbar) {
|
|
766
771
|
host.append(toolbar.element);
|
|
767
772
|
}
|
|
@@ -998,7 +1003,7 @@ function removeMediaListener(media, listener) {
|
|
|
998
1003
|
}
|
|
999
1004
|
media.removeListener?.(listener);
|
|
1000
1005
|
}
|
|
1001
|
-
function createToolbar(toolbar, viewport, queue) {
|
|
1006
|
+
function createToolbar(toolbar, viewport, queue, locale) {
|
|
1002
1007
|
if (!toolbar) {
|
|
1003
1008
|
return void 0;
|
|
1004
1009
|
}
|
|
@@ -1006,7 +1011,7 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1006
1011
|
const element = document.createElement("div");
|
|
1007
1012
|
element.className = "ofv-toolbar";
|
|
1008
1013
|
element.setAttribute("role", "toolbar");
|
|
1009
|
-
element.setAttribute("aria-label",
|
|
1014
|
+
element.setAttribute("aria-label", defaultToolbarText[locale].ariaLabel);
|
|
1010
1015
|
let file;
|
|
1011
1016
|
let currentIndex = 0;
|
|
1012
1017
|
let currentLength = queue.getLength();
|
|
@@ -1067,8 +1072,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1067
1072
|
}
|
|
1068
1073
|
if (id === "previous" && queue.getLength() > 1) {
|
|
1069
1074
|
previousButton = addButton(
|
|
1070
|
-
getToolbarLabel(options, "previous"),
|
|
1071
|
-
getToolbarTitle(options, "previous"),
|
|
1075
|
+
getToolbarLabel(options, locale, "previous"),
|
|
1076
|
+
getToolbarTitle(options, locale, "previous"),
|
|
1072
1077
|
() => void queue.previous(),
|
|
1073
1078
|
void 0,
|
|
1074
1079
|
options.icons?.previous
|
|
@@ -1077,8 +1082,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1077
1082
|
}
|
|
1078
1083
|
if (id === "next" && queue.getLength() > 1) {
|
|
1079
1084
|
nextButton = addButton(
|
|
1080
|
-
getToolbarLabel(options, "next"),
|
|
1081
|
-
getToolbarTitle(options, "next"),
|
|
1085
|
+
getToolbarLabel(options, locale, "next"),
|
|
1086
|
+
getToolbarTitle(options, locale, "next"),
|
|
1082
1087
|
() => void queue.next(),
|
|
1083
1088
|
void 0,
|
|
1084
1089
|
options.icons?.next
|
|
@@ -1092,27 +1097,27 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1092
1097
|
return;
|
|
1093
1098
|
}
|
|
1094
1099
|
if (id === "zoom-out" && options.zoom) {
|
|
1095
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-out");
|
|
1100
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-out");
|
|
1096
1101
|
return;
|
|
1097
1102
|
}
|
|
1098
1103
|
if (id === "zoom-in" && options.zoom) {
|
|
1099
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-in");
|
|
1104
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-in");
|
|
1100
1105
|
return;
|
|
1101
1106
|
}
|
|
1102
1107
|
if (id === "zoom-reset" && options.zoom) {
|
|
1103
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-reset");
|
|
1108
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-reset");
|
|
1104
1109
|
zoomResetButton = commandButtons[commandButtons.length - 1]?.button;
|
|
1105
1110
|
updateZoomLabel();
|
|
1106
1111
|
return;
|
|
1107
1112
|
}
|
|
1108
1113
|
if (id === "rotate-right" && options.rotate) {
|
|
1109
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "rotate-right");
|
|
1114
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "rotate-right");
|
|
1110
1115
|
return;
|
|
1111
1116
|
}
|
|
1112
1117
|
if (id === "download" && options.download !== false) {
|
|
1113
1118
|
addButton(
|
|
1114
|
-
getToolbarLabel(options, id),
|
|
1115
|
-
getToolbarTitle(options, id),
|
|
1119
|
+
getToolbarLabel(options, locale, id),
|
|
1120
|
+
getToolbarTitle(options, locale, id),
|
|
1116
1121
|
() => getContext().download(),
|
|
1117
1122
|
void 0,
|
|
1118
1123
|
options.icons?.download
|
|
@@ -1121,8 +1126,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1121
1126
|
}
|
|
1122
1127
|
if (id === "fullscreen" && options.fullscreen !== false) {
|
|
1123
1128
|
fullscreenButton = addButton(
|
|
1124
|
-
getToolbarLabel(options, id),
|
|
1125
|
-
getToolbarTitle(options, id),
|
|
1129
|
+
getToolbarLabel(options, locale, id),
|
|
1130
|
+
getToolbarTitle(options, locale, id),
|
|
1126
1131
|
() => getContext().fullscreen(),
|
|
1127
1132
|
void 0,
|
|
1128
1133
|
options.icons?.fullscreen
|
|
@@ -1132,8 +1137,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1132
1137
|
}
|
|
1133
1138
|
if (id === "print" && options.print) {
|
|
1134
1139
|
addButton(
|
|
1135
|
-
getToolbarLabel(options, id),
|
|
1136
|
-
getToolbarTitle(options, id),
|
|
1140
|
+
getToolbarLabel(options, locale, id),
|
|
1141
|
+
getToolbarTitle(options, locale, id),
|
|
1137
1142
|
() => getContext().print(),
|
|
1138
1143
|
void 0,
|
|
1139
1144
|
options.icons?.print
|
|
@@ -1159,11 +1164,11 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1159
1164
|
const renderSearchControl = () => {
|
|
1160
1165
|
const searchGroup = document.createElement("div");
|
|
1161
1166
|
searchGroup.className = "ofv-toolbar-search";
|
|
1162
|
-
searchGroup.title = getToolbarTitle(options, "search");
|
|
1167
|
+
searchGroup.title = getToolbarTitle(options, locale, "search");
|
|
1163
1168
|
const nextSearchInput = document.createElement("input");
|
|
1164
1169
|
nextSearchInput.type = "search";
|
|
1165
|
-
nextSearchInput.placeholder = getToolbarLabel(options, "search");
|
|
1166
|
-
nextSearchInput.setAttribute("aria-label", getToolbarTitle(options, "search"));
|
|
1170
|
+
nextSearchInput.placeholder = getToolbarLabel(options, locale, "search");
|
|
1171
|
+
nextSearchInput.setAttribute("aria-label", getToolbarTitle(options, locale, "search"));
|
|
1167
1172
|
const nextSearchCount = document.createElement("span");
|
|
1168
1173
|
nextSearchCount.className = "ofv-toolbar-search-count";
|
|
1169
1174
|
searchInput = nextSearchInput;
|
|
@@ -1218,7 +1223,7 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1218
1223
|
}
|
|
1219
1224
|
setToolbarButtonContent(
|
|
1220
1225
|
zoomResetButton,
|
|
1221
|
-
currentZoom === void 0 ? getToolbarLabel(options, "zoom-reset") : formatToolbarZoom(currentZoom),
|
|
1226
|
+
currentZoom === void 0 ? getToolbarLabel(options, locale, "zoom-reset") : formatToolbarZoom(currentZoom),
|
|
1222
1227
|
options.icons?.["zoom-reset"]
|
|
1223
1228
|
);
|
|
1224
1229
|
}
|
|
@@ -1241,8 +1246,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1241
1246
|
const active = isFullscreenActive();
|
|
1242
1247
|
const id = active ? "exit-fullscreen" : "fullscreen";
|
|
1243
1248
|
const icon = active ? options.icons?.["exit-fullscreen"] ?? options.icons?.fullscreen : options.icons?.fullscreen;
|
|
1244
|
-
setToolbarButtonContent(fullscreenButton, getToolbarLabel(options, id), icon);
|
|
1245
|
-
const title = getToolbarTitle(options, id);
|
|
1249
|
+
setToolbarButtonContent(fullscreenButton, getToolbarLabel(options, locale, id), icon);
|
|
1250
|
+
const title = getToolbarTitle(options, locale, id);
|
|
1246
1251
|
fullscreenButton.title = title;
|
|
1247
1252
|
fullscreenButton.setAttribute("aria-label", title);
|
|
1248
1253
|
fullscreenButton.setAttribute("aria-pressed", String(active));
|
|
@@ -1366,39 +1371,75 @@ function createToolbarContext({
|
|
|
1366
1371
|
clearSearch: search.clear
|
|
1367
1372
|
};
|
|
1368
1373
|
}
|
|
1369
|
-
var
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1374
|
+
var defaultToolbarText = {
|
|
1375
|
+
"zh-CN": {
|
|
1376
|
+
ariaLabel: "\u6587\u4EF6\u9884\u89C8\u5DE5\u5177\u680F",
|
|
1377
|
+
labels: {
|
|
1378
|
+
previous: "\u4E0A\u4E00\u4E2A",
|
|
1379
|
+
next: "\u4E0B\u4E00\u4E2A",
|
|
1380
|
+
queue: "",
|
|
1381
|
+
"zoom-out": "-",
|
|
1382
|
+
"zoom-in": "+",
|
|
1383
|
+
"zoom-reset": "100%",
|
|
1384
|
+
"rotate-right": "\u65CB\u8F6C",
|
|
1385
|
+
download: "\u4E0B\u8F7D",
|
|
1386
|
+
fullscreen: "\u5168\u5C4F",
|
|
1387
|
+
"exit-fullscreen": "\u9000\u51FA\u5168\u5C4F",
|
|
1388
|
+
print: "\u6253\u5370",
|
|
1389
|
+
search: "\u641C\u7D22"
|
|
1390
|
+
},
|
|
1391
|
+
titles: {
|
|
1392
|
+
previous: "\u4E0A\u4E00\u4E2A\u6587\u4EF6",
|
|
1393
|
+
next: "\u4E0B\u4E00\u4E2A\u6587\u4EF6",
|
|
1394
|
+
queue: "\u5F53\u524D\u6587\u4EF6\u4F4D\u7F6E",
|
|
1395
|
+
"zoom-out": "\u7F29\u5C0F",
|
|
1396
|
+
"zoom-in": "\u653E\u5927",
|
|
1397
|
+
"zoom-reset": "\u91CD\u7F6E\u7F29\u653E",
|
|
1398
|
+
"rotate-right": "\u5411\u53F3\u65CB\u8F6C",
|
|
1399
|
+
download: "\u4E0B\u8F7D\u6587\u4EF6",
|
|
1400
|
+
fullscreen: "\u5168\u5C4F\u67E5\u770B\u9884\u89C8",
|
|
1401
|
+
"exit-fullscreen": "\u9000\u51FA\u5168\u5C4F",
|
|
1402
|
+
print: "\u6253\u5370\u9884\u89C8",
|
|
1403
|
+
search: "\u641C\u7D22\u9884\u89C8\u6587\u672C"
|
|
1404
|
+
}
|
|
1405
|
+
},
|
|
1406
|
+
"en-US": {
|
|
1407
|
+
ariaLabel: "File preview toolbar",
|
|
1408
|
+
labels: {
|
|
1409
|
+
previous: "Prev",
|
|
1410
|
+
next: "Next",
|
|
1411
|
+
queue: "",
|
|
1412
|
+
"zoom-out": "-",
|
|
1413
|
+
"zoom-in": "+",
|
|
1414
|
+
"zoom-reset": "100%",
|
|
1415
|
+
"rotate-right": "Rotate",
|
|
1416
|
+
download: "Download",
|
|
1417
|
+
fullscreen: "Fullscreen",
|
|
1418
|
+
"exit-fullscreen": "Exit fullscreen",
|
|
1419
|
+
print: "Print",
|
|
1420
|
+
search: "Search"
|
|
1421
|
+
},
|
|
1422
|
+
titles: {
|
|
1423
|
+
previous: "Previous file",
|
|
1424
|
+
next: "Next file",
|
|
1425
|
+
queue: "Current file position",
|
|
1426
|
+
"zoom-out": "Zoom out",
|
|
1427
|
+
"zoom-in": "Zoom in",
|
|
1428
|
+
"zoom-reset": "Reset zoom",
|
|
1429
|
+
"rotate-right": "Rotate right",
|
|
1430
|
+
download: "Download file",
|
|
1431
|
+
fullscreen: "Open preview fullscreen",
|
|
1432
|
+
"exit-fullscreen": "Exit fullscreen",
|
|
1433
|
+
print: "Print preview",
|
|
1434
|
+
search: "Search preview text"
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1396
1437
|
};
|
|
1397
|
-
function getToolbarLabel(options, id) {
|
|
1398
|
-
return options.labels?.[id] ??
|
|
1438
|
+
function getToolbarLabel(options, locale, id) {
|
|
1439
|
+
return options.labels?.[id] ?? defaultToolbarText[locale].labels[id];
|
|
1399
1440
|
}
|
|
1400
|
-
function getToolbarTitle(options, id) {
|
|
1401
|
-
return options.titles?.[id] ?? options.labels?.[id] ??
|
|
1441
|
+
function getToolbarTitle(options, locale, id) {
|
|
1442
|
+
return options.titles?.[id] ?? options.labels?.[id] ?? defaultToolbarText[locale].titles[id];
|
|
1402
1443
|
}
|
|
1403
1444
|
function formatToolbarZoom(zoom) {
|
|
1404
1445
|
return `${Math.round(zoom * 100)}%`;
|
|
@@ -1550,7 +1591,7 @@ function isSafeToolbarIconAttribute(name, value) {
|
|
|
1550
1591
|
return !/^\s*(?:javascript|data:text\/html|vbscript):/i.test(value);
|
|
1551
1592
|
}
|
|
1552
1593
|
function isBuiltInToolbarAction(id) {
|
|
1553
|
-
return id in
|
|
1594
|
+
return id in defaultToolbarText["en-US"].labels;
|
|
1554
1595
|
}
|
|
1555
1596
|
function createSearchController(root) {
|
|
1556
1597
|
const markerClass = "ofv-search-match";
|
|
@@ -9414,6 +9455,9 @@ function renderChartCard(chart) {
|
|
|
9414
9455
|
function renderChartSvg(chart) {
|
|
9415
9456
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
9416
9457
|
svg.setAttribute("viewBox", "0 0 640 380");
|
|
9458
|
+
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
|
|
9459
|
+
svg.setAttribute("text-rendering", "geometricPrecision");
|
|
9460
|
+
svg.setAttribute("shape-rendering", "geometricPrecision");
|
|
9417
9461
|
svg.setAttribute("role", "img");
|
|
9418
9462
|
svg.setAttribute("aria-label", chart.title);
|
|
9419
9463
|
svg.classList.add("ofv-chart-svg");
|
|
@@ -9459,16 +9503,7 @@ function renderChartSvg(chart) {
|
|
|
9459
9503
|
const clusterWidth = groupWidth * 0.58;
|
|
9460
9504
|
const barWidth = Math.max(5, Math.min(28, clusterWidth / Math.max(1, chart.series.length)));
|
|
9461
9505
|
const zeroY = plot.y + plot.height - (0 - axisMin) / (axisMax - axisMin || 1) * plot.height;
|
|
9462
|
-
|
|
9463
|
-
const x = plot.x + groupWidth * (index + 0.5);
|
|
9464
|
-
const label = appendSvg(svg, "text", {
|
|
9465
|
-
x: Number(x.toFixed(1)),
|
|
9466
|
-
y: plot.y + plot.height + 22,
|
|
9467
|
-
class: "ofv-chart-label",
|
|
9468
|
-
"text-anchor": "middle"
|
|
9469
|
-
});
|
|
9470
|
-
label.textContent = truncateChartLabel(category);
|
|
9471
|
-
});
|
|
9506
|
+
appendChartCategoryLabels(svg, categories, plot, (index) => plot.x + groupWidth * (index + 0.5));
|
|
9472
9507
|
chart.series.forEach((series, seriesIndex) => {
|
|
9473
9508
|
const color = series.color || colors[seriesIndex % colors.length];
|
|
9474
9509
|
series.values.forEach((value, index) => {
|
|
@@ -9486,6 +9521,8 @@ function renderChartSvg(chart) {
|
|
|
9486
9521
|
});
|
|
9487
9522
|
});
|
|
9488
9523
|
} else {
|
|
9524
|
+
const categoryStep = categories.length > 1 ? plot.width / (categories.length - 1) : plot.width;
|
|
9525
|
+
appendChartCategoryLabels(svg, categories, plot, (index) => plot.x + index * categoryStep);
|
|
9489
9526
|
chart.series.forEach((series, seriesIndex) => {
|
|
9490
9527
|
const color = series.color || colors[seriesIndex % colors.length];
|
|
9491
9528
|
const step = series.values.length > 1 ? plot.width / (series.values.length - 1) : plot.width;
|
|
@@ -9510,6 +9547,22 @@ function renderChartSvg(chart) {
|
|
|
9510
9547
|
appendChartLegend(svg, chart, colors, 348);
|
|
9511
9548
|
return svg;
|
|
9512
9549
|
}
|
|
9550
|
+
function appendChartCategoryLabels(svg, categories, plot, getX) {
|
|
9551
|
+
const interval = Math.max(1, Math.ceil(categories.length / 14));
|
|
9552
|
+
categories.forEach((category, index) => {
|
|
9553
|
+
if (index % interval !== 0 && index !== categories.length - 1) {
|
|
9554
|
+
return;
|
|
9555
|
+
}
|
|
9556
|
+
const label = appendSvg(svg, "text", {
|
|
9557
|
+
x: Number(getX(index).toFixed(1)),
|
|
9558
|
+
y: plot.y + plot.height + 22,
|
|
9559
|
+
class: "ofv-chart-label ofv-chart-category-label",
|
|
9560
|
+
"data-axis": "category",
|
|
9561
|
+
"text-anchor": "middle"
|
|
9562
|
+
});
|
|
9563
|
+
label.textContent = truncateChartLabel(category);
|
|
9564
|
+
});
|
|
9565
|
+
}
|
|
9513
9566
|
function appendChartLegend(svg, chart, colors, y) {
|
|
9514
9567
|
const itemWidth = 86;
|
|
9515
9568
|
const startX = 320 - chart.series.length * itemWidth / 2;
|