Skip to content

Commit

Permalink
Scale text inscriptions to fit preview (ordinals#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Jan 16, 2023
1 parent b585240 commit 0926da1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/templates/iframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod tests {
use super::*;

#[test]
fn preview() {
fn thumbnail() {
assert_regex_match!(
Iframe::thumbnail(inscription_id(1))
.0.to_string(),
Expand Down
20 changes: 20 additions & 0 deletions static/preview-text.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
html {
background-color: #131516;
color: white;
font-size: 16px;
height: 100%;
line-height: 1;
}

body {
display: grid;
grid-template: 1fr / 1fr;
height: 100%;
margin: 0;
place-items: center;
}

pre {
margin: 0;
}

body > * {
grid-column: 1 / 1;
grid-row: 1 / 1;
}

body > pre {
opacity: 0;
}
6 changes: 6 additions & 0 deletions static/preview-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let pre = document.querySelector('body > pre');
let { width, height } = pre.getBoundingClientRect();
let columns = width / 16;
let rows = height / 16;
pre.style.fontSize = `min(${95/columns}vw, ${95/rows}vh)`;
pre.style.opacity = 1;
4 changes: 4 additions & 0 deletions templates/preview-text.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<meta charset=utf-8>
<meta name=format-detection content='telephone=no'>
<link href=/static/preview-text.css rel=stylesheet>
<script src=/static/preview-text.js defer></script>
</head>
<body>
<pre>{{self.text}}</pre>
<noscript>
<pre>{{self.text}}</pre>
</noscript>
</body>
</html>

0 comments on commit 0926da1

Please sign in to comment.