-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added print styles and js for plugins
- Loading branch information
1 parent
b7ca82d
commit 4bc6ad7
Showing
12 changed files
with
201 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './table'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const Selector = { | ||
WRAPPED_TABLE: '.pdf .yfm-table-container table', | ||
TABLE: '.pdf table', | ||
}; | ||
const Padding = { | ||
BOTTOM: 20, | ||
}; | ||
|
||
function resizeElement(element: HTMLElement) { | ||
const availableWidth = element.parentElement?.offsetWidth; | ||
const contentWidth = (element.firstElementChild as HTMLElement).offsetWidth; | ||
|
||
if (!availableWidth) { | ||
return; | ||
} | ||
|
||
const needScale = contentWidth > availableWidth; | ||
|
||
if (needScale) { | ||
const scale = availableWidth / contentWidth; | ||
|
||
element.style.transform = `scale(${scale})`; | ||
} | ||
|
||
element.parentElement.style.height = `${ | ||
element.getBoundingClientRect().height + Padding.BOTTOM | ||
}px`; | ||
} | ||
|
||
function resizeElements() { | ||
document.querySelectorAll(Selector.WRAPPED_TABLE).forEach((element) => { | ||
resizeElement(element as HTMLElement); | ||
}); | ||
} | ||
|
||
function wrapTables() { | ||
const tables = document.querySelectorAll(Selector.TABLE); | ||
|
||
for (let i = 0; i < tables.length; i++) { | ||
const table = tables[i]; | ||
|
||
const parent = table.parentNode; | ||
|
||
if (!parent) { | ||
continue; | ||
} | ||
|
||
const wrapper = document.createElement('div'); | ||
parent.insertBefore(wrapper, table); | ||
wrapper.appendChild(table); | ||
wrapper.classList.add('yfm-table-container'); | ||
} | ||
} | ||
|
||
if (typeof document !== 'undefined') { | ||
window.addEventListener('load', () => { | ||
wrapTables(); | ||
resizeElements(); | ||
}); | ||
} | ||
|
||
export {}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import 'print/code'; | ||
@import 'print/common'; | ||
@import 'print/cut'; | ||
@import 'print/note'; | ||
@import 'print/table'; | ||
@import 'print/tabs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@media print { | ||
.yfm { | ||
.yfm-clipboard { | ||
& > pre > code { | ||
white-space: pre-wrap; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@media print { | ||
.yfm { | ||
.yfm-page__delimeter { | ||
display: none; | ||
} | ||
|
||
h1, h2 { | ||
&[data-original-article] { | ||
page-break-before: always; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@media print { | ||
.yfm { | ||
.yfm-cut { | ||
&-title { | ||
padding-left: 0; | ||
|
||
&:before { | ||
display: none; | ||
} | ||
} | ||
|
||
&-content { | ||
height: auto; | ||
padding: 5px 0 15px 30px; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@media print { | ||
.yfm { | ||
.yfm-note { | ||
page-break-inside: avoid; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.yfm { | ||
.yfm-table-container { | ||
position: relative; | ||
|
||
& > table { | ||
overflow: initial; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
max-width: initial; | ||
transform-origin: top left; | ||
|
||
thead { | ||
display: table-row-group; | ||
} | ||
|
||
th, td { | ||
page-break-inside: avoid; | ||
white-space: pre-wrap; | ||
text-overflow: initial; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@media print { | ||
.yfm { | ||
.yfm-tab { | ||
&-list { | ||
display: none; | ||
} | ||
|
||
&-panel:before { | ||
content: attr(data-title); | ||
margin-bottom: -1px; | ||
margin-right: 20px; | ||
border-bottom: 2px solid transparent; | ||
line-height: 33px; | ||
font-weight: 700; | ||
outline: 0; | ||
cursor: pointer; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters