Skip to content

Commit

Permalink
added: hideWrapperOnPrint option
Browse files Browse the repository at this point in the history
  • Loading branch information
VolodymyrBaydalkaDevessence committed Jan 17, 2025
1 parent cbe1fe8 commit dac6be3
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 16 deletions.
9 changes: 7 additions & 2 deletions dist/docx-preview.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/docx-preview.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.mjs.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/docx-preview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3147,9 +3147,13 @@ class HtmlRenderer {
}
renderDefaultStyle() {
var c = this.className;
var styleText = `
var wrapperStyle = `
.${c}-wrapper { background: gray; padding: 30px; padding-bottom: 0px; display: flex; flex-flow: column; align-items: center; }
.${c}-wrapper>section.${c} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }
.${c}-wrapper>section.${c} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }`;
if (this.options.hideWrapperOnPrint) {
wrapperStyle = `@media not print { ${wrapperStyle} }`;
}
var styleText = `${wrapperStyle}
.${c} { color: black; hyphens: auto; text-underline-position: from-font; }
section.${c} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: hidden; }
section.${c}>article { margin-bottom: auto; z-index: 1; }
Expand Down Expand Up @@ -3865,6 +3869,7 @@ const defaultOptions = {
experimental: false,
className: "docx",
inWrapper: true,
hideWrapperOnPrint: false,
trimXmlDeclaration: true,
ignoreLastRenderedPageBreak: true,
renderHeaders: true,
Expand Down
2 changes: 1 addition & 1 deletion dist/docx-preview.mjs.map

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@
<link href="./demo/thumbnail.example.css" rel="stylesheet">
<script crossorigin src="https://unpkg.com/tiff.js@1.0.0/tiff.min.js"></script>
<script src="./demo/tiff-preprocessor.js"></script>

<style>
@media print {
.no-print {
display: none;
}

.overflow-auto {
overflow: initial !important;
}
}
</style>
</head>

<body class="vh-100 d-flex flex-column">
<div class="hstack bg-black">
<div class="hstack bg-black no-print">
<a class="mx-auto p-2 text-white" href="https://war.ukraine.ua">Support Ukraine 🇺🇦</a>
</div>

<div class="hstack p-2 gap-2 bg-light">
<div class="hstack p-2 gap-2 bg-light no-print">

<input id="files" type="file" class="form-control" style="width: 50ch;" accept=".docx" />
<div class="col-2">
Expand All @@ -46,7 +58,7 @@
</div>

<div class="flex-grow-1 d-flex flex-row" style="height: 0;">
<details class="docx-thumbnails h-100">
<details class="docx-thumbnails h-100 no-print">
<summary></summary>
<div id="thumbnails-container" class="docx-thumbnails-container"></div>
</details>
Expand All @@ -57,7 +69,8 @@
let currentDocument = null;
const docxOptions = Object.assign(docx.defaultOptions, {
debug: true,
experimental: true
experimental: true,
hideWrapperOnPrint: true
});

const container = document.querySelector("#document-container");
Expand Down
2 changes: 2 additions & 0 deletions src/docx-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HtmlRenderer } from './html-renderer';

export interface Options {
inWrapper: boolean;
hideWrapperOnPrint: boolean;
ignoreWidth: boolean;
ignoreHeight: boolean;
ignoreFonts: boolean;
Expand Down Expand Up @@ -31,6 +32,7 @@ export const defaultOptions: Options = {
experimental: false,
className: "docx",
inWrapper: true,
hideWrapperOnPrint: false,
trimXmlDeclaration: true,
ignoreLastRenderedPageBreak: true,
renderHeaders: true,
Expand Down
8 changes: 6 additions & 2 deletions src/html-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,13 @@ export class HtmlRenderer {

renderDefaultStyle() {
var c = this.className;
var styleText = `
var wrapperStyle = `
.${c}-wrapper { background: gray; padding: 30px; padding-bottom: 0px; display: flex; flex-flow: column; align-items: center; }
.${c}-wrapper>section.${c} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }
.${c}-wrapper>section.${c} { background: white; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); margin-bottom: 30px; }`;
if (this.options.hideWrapperOnPrint) {
wrapperStyle = `@media not print { ${wrapperStyle} }`;
}
var styleText = `${wrapperStyle}
.${c} { color: black; hyphens: auto; text-underline-position: from-font; }
section.${c} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: hidden; }
section.${c}>article { margin-bottom: auto; z-index: 1; }
Expand Down

0 comments on commit dac6be3

Please sign in to comment.