@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.cjs
CHANGED
|
@@ -809,12 +809,17 @@ function createViewer(options) {
|
|
|
809
809
|
currentIndex = clampIndex(index, queue.length);
|
|
810
810
|
await renderQueueItem(currentIndex);
|
|
811
811
|
};
|
|
812
|
-
const toolbar = createToolbar(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
812
|
+
const toolbar = createToolbar(
|
|
813
|
+
options.toolbar,
|
|
814
|
+
viewport,
|
|
815
|
+
{
|
|
816
|
+
getLength: () => queue.length,
|
|
817
|
+
next: () => goTo(currentIndex + 1),
|
|
818
|
+
previous: () => goTo(currentIndex - 1),
|
|
819
|
+
command: (command) => currentInstance?.command?.(command)
|
|
820
|
+
},
|
|
821
|
+
options.locale || "en-US"
|
|
822
|
+
);
|
|
818
823
|
if (toolbar) {
|
|
819
824
|
host.append(toolbar.element);
|
|
820
825
|
}
|
|
@@ -1051,7 +1056,7 @@ function removeMediaListener(media, listener) {
|
|
|
1051
1056
|
}
|
|
1052
1057
|
media.removeListener?.(listener);
|
|
1053
1058
|
}
|
|
1054
|
-
function createToolbar(toolbar, viewport, queue) {
|
|
1059
|
+
function createToolbar(toolbar, viewport, queue, locale) {
|
|
1055
1060
|
if (!toolbar) {
|
|
1056
1061
|
return void 0;
|
|
1057
1062
|
}
|
|
@@ -1059,7 +1064,7 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1059
1064
|
const element = document.createElement("div");
|
|
1060
1065
|
element.className = "ofv-toolbar";
|
|
1061
1066
|
element.setAttribute("role", "toolbar");
|
|
1062
|
-
element.setAttribute("aria-label",
|
|
1067
|
+
element.setAttribute("aria-label", defaultToolbarText[locale].ariaLabel);
|
|
1063
1068
|
let file;
|
|
1064
1069
|
let currentIndex = 0;
|
|
1065
1070
|
let currentLength = queue.getLength();
|
|
@@ -1120,8 +1125,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1120
1125
|
}
|
|
1121
1126
|
if (id === "previous" && queue.getLength() > 1) {
|
|
1122
1127
|
previousButton = addButton(
|
|
1123
|
-
getToolbarLabel(options, "previous"),
|
|
1124
|
-
getToolbarTitle(options, "previous"),
|
|
1128
|
+
getToolbarLabel(options, locale, "previous"),
|
|
1129
|
+
getToolbarTitle(options, locale, "previous"),
|
|
1125
1130
|
() => void queue.previous(),
|
|
1126
1131
|
void 0,
|
|
1127
1132
|
options.icons?.previous
|
|
@@ -1130,8 +1135,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1130
1135
|
}
|
|
1131
1136
|
if (id === "next" && queue.getLength() > 1) {
|
|
1132
1137
|
nextButton = addButton(
|
|
1133
|
-
getToolbarLabel(options, "next"),
|
|
1134
|
-
getToolbarTitle(options, "next"),
|
|
1138
|
+
getToolbarLabel(options, locale, "next"),
|
|
1139
|
+
getToolbarTitle(options, locale, "next"),
|
|
1135
1140
|
() => void queue.next(),
|
|
1136
1141
|
void 0,
|
|
1137
1142
|
options.icons?.next
|
|
@@ -1145,27 +1150,27 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1145
1150
|
return;
|
|
1146
1151
|
}
|
|
1147
1152
|
if (id === "zoom-out" && options.zoom) {
|
|
1148
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-out");
|
|
1153
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-out");
|
|
1149
1154
|
return;
|
|
1150
1155
|
}
|
|
1151
1156
|
if (id === "zoom-in" && options.zoom) {
|
|
1152
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-in");
|
|
1157
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-in");
|
|
1153
1158
|
return;
|
|
1154
1159
|
}
|
|
1155
1160
|
if (id === "zoom-reset" && options.zoom) {
|
|
1156
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "zoom-reset");
|
|
1161
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "zoom-reset");
|
|
1157
1162
|
zoomResetButton = commandButtons[commandButtons.length - 1]?.button;
|
|
1158
1163
|
updateZoomLabel();
|
|
1159
1164
|
return;
|
|
1160
1165
|
}
|
|
1161
1166
|
if (id === "rotate-right" && options.rotate) {
|
|
1162
|
-
addCommandButton(id, getToolbarLabel(options, id), getToolbarTitle(options, id), "rotate-right");
|
|
1167
|
+
addCommandButton(id, getToolbarLabel(options, locale, id), getToolbarTitle(options, locale, id), "rotate-right");
|
|
1163
1168
|
return;
|
|
1164
1169
|
}
|
|
1165
1170
|
if (id === "download" && options.download !== false) {
|
|
1166
1171
|
addButton(
|
|
1167
|
-
getToolbarLabel(options, id),
|
|
1168
|
-
getToolbarTitle(options, id),
|
|
1172
|
+
getToolbarLabel(options, locale, id),
|
|
1173
|
+
getToolbarTitle(options, locale, id),
|
|
1169
1174
|
() => getContext().download(),
|
|
1170
1175
|
void 0,
|
|
1171
1176
|
options.icons?.download
|
|
@@ -1174,8 +1179,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1174
1179
|
}
|
|
1175
1180
|
if (id === "fullscreen" && options.fullscreen !== false) {
|
|
1176
1181
|
fullscreenButton = addButton(
|
|
1177
|
-
getToolbarLabel(options, id),
|
|
1178
|
-
getToolbarTitle(options, id),
|
|
1182
|
+
getToolbarLabel(options, locale, id),
|
|
1183
|
+
getToolbarTitle(options, locale, id),
|
|
1179
1184
|
() => getContext().fullscreen(),
|
|
1180
1185
|
void 0,
|
|
1181
1186
|
options.icons?.fullscreen
|
|
@@ -1185,8 +1190,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1185
1190
|
}
|
|
1186
1191
|
if (id === "print" && options.print) {
|
|
1187
1192
|
addButton(
|
|
1188
|
-
getToolbarLabel(options, id),
|
|
1189
|
-
getToolbarTitle(options, id),
|
|
1193
|
+
getToolbarLabel(options, locale, id),
|
|
1194
|
+
getToolbarTitle(options, locale, id),
|
|
1190
1195
|
() => getContext().print(),
|
|
1191
1196
|
void 0,
|
|
1192
1197
|
options.icons?.print
|
|
@@ -1212,11 +1217,11 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1212
1217
|
const renderSearchControl = () => {
|
|
1213
1218
|
const searchGroup = document.createElement("div");
|
|
1214
1219
|
searchGroup.className = "ofv-toolbar-search";
|
|
1215
|
-
searchGroup.title = getToolbarTitle(options, "search");
|
|
1220
|
+
searchGroup.title = getToolbarTitle(options, locale, "search");
|
|
1216
1221
|
const nextSearchInput = document.createElement("input");
|
|
1217
1222
|
nextSearchInput.type = "search";
|
|
1218
|
-
nextSearchInput.placeholder = getToolbarLabel(options, "search");
|
|
1219
|
-
nextSearchInput.setAttribute("aria-label", getToolbarTitle(options, "search"));
|
|
1223
|
+
nextSearchInput.placeholder = getToolbarLabel(options, locale, "search");
|
|
1224
|
+
nextSearchInput.setAttribute("aria-label", getToolbarTitle(options, locale, "search"));
|
|
1220
1225
|
const nextSearchCount = document.createElement("span");
|
|
1221
1226
|
nextSearchCount.className = "ofv-toolbar-search-count";
|
|
1222
1227
|
searchInput = nextSearchInput;
|
|
@@ -1271,7 +1276,7 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1271
1276
|
}
|
|
1272
1277
|
setToolbarButtonContent(
|
|
1273
1278
|
zoomResetButton,
|
|
1274
|
-
currentZoom === void 0 ? getToolbarLabel(options, "zoom-reset") : formatToolbarZoom(currentZoom),
|
|
1279
|
+
currentZoom === void 0 ? getToolbarLabel(options, locale, "zoom-reset") : formatToolbarZoom(currentZoom),
|
|
1275
1280
|
options.icons?.["zoom-reset"]
|
|
1276
1281
|
);
|
|
1277
1282
|
}
|
|
@@ -1294,8 +1299,8 @@ function createToolbar(toolbar, viewport, queue) {
|
|
|
1294
1299
|
const active = isFullscreenActive();
|
|
1295
1300
|
const id = active ? "exit-fullscreen" : "fullscreen";
|
|
1296
1301
|
const icon = active ? options.icons?.["exit-fullscreen"] ?? options.icons?.fullscreen : options.icons?.fullscreen;
|
|
1297
|
-
setToolbarButtonContent(fullscreenButton, getToolbarLabel(options, id), icon);
|
|
1298
|
-
const title = getToolbarTitle(options, id);
|
|
1302
|
+
setToolbarButtonContent(fullscreenButton, getToolbarLabel(options, locale, id), icon);
|
|
1303
|
+
const title = getToolbarTitle(options, locale, id);
|
|
1299
1304
|
fullscreenButton.title = title;
|
|
1300
1305
|
fullscreenButton.setAttribute("aria-label", title);
|
|
1301
1306
|
fullscreenButton.setAttribute("aria-pressed", String(active));
|
|
@@ -1419,39 +1424,75 @@ function createToolbarContext({
|
|
|
1419
1424
|
clearSearch: search.clear
|
|
1420
1425
|
};
|
|
1421
1426
|
}
|
|
1422
|
-
var
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1427
|
+
var defaultToolbarText = {
|
|
1428
|
+
"zh-CN": {
|
|
1429
|
+
ariaLabel: "\u6587\u4EF6\u9884\u89C8\u5DE5\u5177\u680F",
|
|
1430
|
+
labels: {
|
|
1431
|
+
previous: "\u4E0A\u4E00\u4E2A",
|
|
1432
|
+
next: "\u4E0B\u4E00\u4E2A",
|
|
1433
|
+
queue: "",
|
|
1434
|
+
"zoom-out": "-",
|
|
1435
|
+
"zoom-in": "+",
|
|
1436
|
+
"zoom-reset": "100%",
|
|
1437
|
+
"rotate-right": "\u65CB\u8F6C",
|
|
1438
|
+
download: "\u4E0B\u8F7D",
|
|
1439
|
+
fullscreen: "\u5168\u5C4F",
|
|
1440
|
+
"exit-fullscreen": "\u9000\u51FA\u5168\u5C4F",
|
|
1441
|
+
print: "\u6253\u5370",
|
|
1442
|
+
search: "\u641C\u7D22"
|
|
1443
|
+
},
|
|
1444
|
+
titles: {
|
|
1445
|
+
previous: "\u4E0A\u4E00\u4E2A\u6587\u4EF6",
|
|
1446
|
+
next: "\u4E0B\u4E00\u4E2A\u6587\u4EF6",
|
|
1447
|
+
queue: "\u5F53\u524D\u6587\u4EF6\u4F4D\u7F6E",
|
|
1448
|
+
"zoom-out": "\u7F29\u5C0F",
|
|
1449
|
+
"zoom-in": "\u653E\u5927",
|
|
1450
|
+
"zoom-reset": "\u91CD\u7F6E\u7F29\u653E",
|
|
1451
|
+
"rotate-right": "\u5411\u53F3\u65CB\u8F6C",
|
|
1452
|
+
download: "\u4E0B\u8F7D\u6587\u4EF6",
|
|
1453
|
+
fullscreen: "\u5168\u5C4F\u67E5\u770B\u9884\u89C8",
|
|
1454
|
+
"exit-fullscreen": "\u9000\u51FA\u5168\u5C4F",
|
|
1455
|
+
print: "\u6253\u5370\u9884\u89C8",
|
|
1456
|
+
search: "\u641C\u7D22\u9884\u89C8\u6587\u672C"
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
"en-US": {
|
|
1460
|
+
ariaLabel: "File preview toolbar",
|
|
1461
|
+
labels: {
|
|
1462
|
+
previous: "Prev",
|
|
1463
|
+
next: "Next",
|
|
1464
|
+
queue: "",
|
|
1465
|
+
"zoom-out": "-",
|
|
1466
|
+
"zoom-in": "+",
|
|
1467
|
+
"zoom-reset": "100%",
|
|
1468
|
+
"rotate-right": "Rotate",
|
|
1469
|
+
download: "Download",
|
|
1470
|
+
fullscreen: "Fullscreen",
|
|
1471
|
+
"exit-fullscreen": "Exit fullscreen",
|
|
1472
|
+
print: "Print",
|
|
1473
|
+
search: "Search"
|
|
1474
|
+
},
|
|
1475
|
+
titles: {
|
|
1476
|
+
previous: "Previous file",
|
|
1477
|
+
next: "Next file",
|
|
1478
|
+
queue: "Current file position",
|
|
1479
|
+
"zoom-out": "Zoom out",
|
|
1480
|
+
"zoom-in": "Zoom in",
|
|
1481
|
+
"zoom-reset": "Reset zoom",
|
|
1482
|
+
"rotate-right": "Rotate right",
|
|
1483
|
+
download: "Download file",
|
|
1484
|
+
fullscreen: "Open preview fullscreen",
|
|
1485
|
+
"exit-fullscreen": "Exit fullscreen",
|
|
1486
|
+
print: "Print preview",
|
|
1487
|
+
search: "Search preview text"
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1449
1490
|
};
|
|
1450
|
-
function getToolbarLabel(options, id) {
|
|
1451
|
-
return options.labels?.[id] ??
|
|
1491
|
+
function getToolbarLabel(options, locale, id) {
|
|
1492
|
+
return options.labels?.[id] ?? defaultToolbarText[locale].labels[id];
|
|
1452
1493
|
}
|
|
1453
|
-
function getToolbarTitle(options, id) {
|
|
1454
|
-
return options.titles?.[id] ?? options.labels?.[id] ??
|
|
1494
|
+
function getToolbarTitle(options, locale, id) {
|
|
1495
|
+
return options.titles?.[id] ?? options.labels?.[id] ?? defaultToolbarText[locale].titles[id];
|
|
1455
1496
|
}
|
|
1456
1497
|
function formatToolbarZoom(zoom) {
|
|
1457
1498
|
return `${Math.round(zoom * 100)}%`;
|
|
@@ -1603,7 +1644,7 @@ function isSafeToolbarIconAttribute(name, value) {
|
|
|
1603
1644
|
return !/^\s*(?:javascript|data:text\/html|vbscript):/i.test(value);
|
|
1604
1645
|
}
|
|
1605
1646
|
function isBuiltInToolbarAction(id) {
|
|
1606
|
-
return id in
|
|
1647
|
+
return id in defaultToolbarText["en-US"].labels;
|
|
1607
1648
|
}
|
|
1608
1649
|
function createSearchController(root) {
|
|
1609
1650
|
const markerClass = "ofv-search-match";
|
|
@@ -9467,6 +9508,9 @@ function renderChartCard(chart) {
|
|
|
9467
9508
|
function renderChartSvg(chart) {
|
|
9468
9509
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
9469
9510
|
svg.setAttribute("viewBox", "0 0 640 380");
|
|
9511
|
+
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
|
|
9512
|
+
svg.setAttribute("text-rendering", "geometricPrecision");
|
|
9513
|
+
svg.setAttribute("shape-rendering", "geometricPrecision");
|
|
9470
9514
|
svg.setAttribute("role", "img");
|
|
9471
9515
|
svg.setAttribute("aria-label", chart.title);
|
|
9472
9516
|
svg.classList.add("ofv-chart-svg");
|
|
@@ -9512,16 +9556,7 @@ function renderChartSvg(chart) {
|
|
|
9512
9556
|
const clusterWidth = groupWidth * 0.58;
|
|
9513
9557
|
const barWidth = Math.max(5, Math.min(28, clusterWidth / Math.max(1, chart.series.length)));
|
|
9514
9558
|
const zeroY = plot.y + plot.height - (0 - axisMin) / (axisMax - axisMin || 1) * plot.height;
|
|
9515
|
-
|
|
9516
|
-
const x = plot.x + groupWidth * (index + 0.5);
|
|
9517
|
-
const label = appendSvg(svg, "text", {
|
|
9518
|
-
x: Number(x.toFixed(1)),
|
|
9519
|
-
y: plot.y + plot.height + 22,
|
|
9520
|
-
class: "ofv-chart-label",
|
|
9521
|
-
"text-anchor": "middle"
|
|
9522
|
-
});
|
|
9523
|
-
label.textContent = truncateChartLabel(category);
|
|
9524
|
-
});
|
|
9559
|
+
appendChartCategoryLabels(svg, categories, plot, (index) => plot.x + groupWidth * (index + 0.5));
|
|
9525
9560
|
chart.series.forEach((series, seriesIndex) => {
|
|
9526
9561
|
const color = series.color || colors[seriesIndex % colors.length];
|
|
9527
9562
|
series.values.forEach((value, index) => {
|
|
@@ -9539,6 +9574,8 @@ function renderChartSvg(chart) {
|
|
|
9539
9574
|
});
|
|
9540
9575
|
});
|
|
9541
9576
|
} else {
|
|
9577
|
+
const categoryStep = categories.length > 1 ? plot.width / (categories.length - 1) : plot.width;
|
|
9578
|
+
appendChartCategoryLabels(svg, categories, plot, (index) => plot.x + index * categoryStep);
|
|
9542
9579
|
chart.series.forEach((series, seriesIndex) => {
|
|
9543
9580
|
const color = series.color || colors[seriesIndex % colors.length];
|
|
9544
9581
|
const step = series.values.length > 1 ? plot.width / (series.values.length - 1) : plot.width;
|
|
@@ -9563,6 +9600,22 @@ function renderChartSvg(chart) {
|
|
|
9563
9600
|
appendChartLegend(svg, chart, colors, 348);
|
|
9564
9601
|
return svg;
|
|
9565
9602
|
}
|
|
9603
|
+
function appendChartCategoryLabels(svg, categories, plot, getX) {
|
|
9604
|
+
const interval = Math.max(1, Math.ceil(categories.length / 14));
|
|
9605
|
+
categories.forEach((category, index) => {
|
|
9606
|
+
if (index % interval !== 0 && index !== categories.length - 1) {
|
|
9607
|
+
return;
|
|
9608
|
+
}
|
|
9609
|
+
const label = appendSvg(svg, "text", {
|
|
9610
|
+
x: Number(getX(index).toFixed(1)),
|
|
9611
|
+
y: plot.y + plot.height + 22,
|
|
9612
|
+
class: "ofv-chart-label ofv-chart-category-label",
|
|
9613
|
+
"data-axis": "category",
|
|
9614
|
+
"text-anchor": "middle"
|
|
9615
|
+
});
|
|
9616
|
+
label.textContent = truncateChartLabel(category);
|
|
9617
|
+
});
|
|
9618
|
+
}
|
|
9566
9619
|
function appendChartLegend(svg, chart, colors, y) {
|
|
9567
9620
|
const itemWidth = 86;
|
|
9568
9621
|
const startX = 320 - chart.series.length * itemWidth / 2;
|