@open-file-viewer/core 0.1.3 → 0.1.4
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 +24 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5036,6 +5036,7 @@ async function renderDocx(panel, arrayBuffer) {
|
|
|
5036
5036
|
experimental: true,
|
|
5037
5037
|
useBase64URL: true
|
|
5038
5038
|
});
|
|
5039
|
+
normalizeDocxLayout(content);
|
|
5039
5040
|
return fitDocxPages(content);
|
|
5040
5041
|
} catch (error) {
|
|
5041
5042
|
content.replaceChildren();
|
|
@@ -5053,6 +5054,29 @@ async function renderDocx(panel, arrayBuffer) {
|
|
|
5053
5054
|
}
|
|
5054
5055
|
return () => void 0;
|
|
5055
5056
|
}
|
|
5057
|
+
function normalizeDocxLayout(container) {
|
|
5058
|
+
const pages = container.querySelectorAll("section.ofv-docx");
|
|
5059
|
+
for (const page of pages) {
|
|
5060
|
+
for (const element of page.querySelectorAll("[style*='line-height']")) {
|
|
5061
|
+
const lineHeight = parseCssLineHeight(element.style.lineHeight);
|
|
5062
|
+
if (lineHeight > 0 && lineHeight < 1) {
|
|
5063
|
+
element.style.lineHeight = "1.2";
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
function parseCssLineHeight(value) {
|
|
5069
|
+
const trimmed = value.trim();
|
|
5070
|
+
if (!trimmed || trimmed === "normal") {
|
|
5071
|
+
return 0;
|
|
5072
|
+
}
|
|
5073
|
+
if (trimmed.endsWith("%")) {
|
|
5074
|
+
const parsedPercent = Number.parseFloat(trimmed);
|
|
5075
|
+
return Number.isFinite(parsedPercent) ? parsedPercent / 100 : 0;
|
|
5076
|
+
}
|
|
5077
|
+
const parsed = Number.parseFloat(trimmed);
|
|
5078
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
5079
|
+
}
|
|
5056
5080
|
function fitDocxPages(container) {
|
|
5057
5081
|
const wrapper = container.querySelector(".ofv-docx-wrapper");
|
|
5058
5082
|
if (!wrapper) {
|