-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
326 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,83 @@ | ||
<html> | ||
<head> | ||
<script type="text/javascript" src="main.js"></script> | ||
<style> | ||
body { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
} | ||
|
||
input, | ||
textarea, | ||
button { | ||
width: 300px; | ||
} | ||
|
||
textarea, | ||
input, | ||
button { | ||
margin-bottom: 20px; | ||
} | ||
|
||
wanted-print-form { | ||
height: 0; | ||
overflow: hidden; | ||
} | ||
|
||
@media print { | ||
input, | ||
textarea, | ||
button { | ||
display: none; | ||
} | ||
|
||
wanted-print-form { | ||
height: unset; | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<wanted-print-form></wanted-print-form> | ||
<input placeholder="Input name" type="text" id="wanted-name" /> | ||
<input type="file" accept="image/*" id="wanted-image" /> | ||
<textarea rows="10" placeholder="Input his atrocity crimes" id="atrocity-crimes"></textarea> | ||
<input placeholder="Reward" type="text" id="reward" /> | ||
<button onclick="printWanted()">Print Wanted!</button> | ||
|
||
<script type="text/javascript"> | ||
function printWanted() { | ||
const name = document.getElementById('wanted-name').value; | ||
const images = document.getElementById('wanted-image').files; | ||
const atrocityCrimes = document.getElementById('atrocity-crimes').value; | ||
const reward = document.getElementById('reward').value; | ||
|
||
const printForm = document.createElement('wanted-print-form'); | ||
printForm.wantedName = name; | ||
printForm.image = images[0]; | ||
printForm.atrocityCrimes = atrocityCrimes; | ||
printForm.reward = reward; | ||
|
||
window.onafterprint = function () { | ||
printForm.remove(); | ||
}; | ||
|
||
printForm.addEventListener(printForm.readyEventName, () => { | ||
printForm.removeEventListener(printForm.readyEventName, null); | ||
printForm.removeEventListener(printForm.errorEventName, null); | ||
window.print(); | ||
}); | ||
|
||
printForm.addEventListener(printForm.errorEventName, (event) => { | ||
printForm.removeEventListener(printForm.readyEventName, null); | ||
printForm.removeEventListener(printForm.errorEventName, null); | ||
printForm.remove(); | ||
console.error('Wanted form error:', event.detail); | ||
}); | ||
|
||
document.body.appendChild(printForm); | ||
} | ||
</script> | ||
</body> | ||
</html> |
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,38 @@ | ||
export class FontLoader { | ||
public static async loadAllFonts(fonts: string[], text: string[]): Promise<void> { | ||
const fontRequest = fonts.map((font) => `family=${font}`); | ||
const normalizeFontText = this.normalizeFontText(text); | ||
|
||
const fontResponse = await fetch(`https://fonts.googleapis.com/css2?${fontRequest.join('&')}&display=swap&text=${normalizeFontText}`); | ||
if (!fontResponse.ok) { | ||
return; | ||
} | ||
|
||
const rawText = (await fontResponse.text()).replace(/\n/g, ''); | ||
const fontSections = rawText.match(/@font-face \{.+?\}/g); | ||
|
||
if (!fontSections) { | ||
return; | ||
} | ||
|
||
await Promise.all(fontSections.map(this.loadFont)); | ||
} | ||
|
||
private static normalizeFontText(strings: string[]): string { | ||
const uniqueChars = new Set(strings.join('').split('')); | ||
return Array.from(uniqueChars).join('').replace(/\s+/, ''); | ||
} | ||
|
||
private static async loadFont(fontSection: string) { | ||
const fontUrl = fontSection.match(/url\(.+?\)/)?.[0]; | ||
const fontName = fontSection.match(/font-family:\s*'(.+?)';/)?.[1]; | ||
|
||
if (!fontUrl || !fontName) { | ||
return; | ||
} | ||
|
||
const font = new FontFace(fontName, fontUrl); | ||
await font.load(); | ||
document.fonts.add(font); | ||
} | ||
} |
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,4 @@ | ||
declare module '*.html' { | ||
const value: string; | ||
export default value; | ||
} |
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,93 @@ | ||
<section id="page"> | ||
<div class="header"> | ||
<div class="star">⍟</div> | ||
WANTED! | ||
</div> | ||
|
||
<div class="atrocity-crimes"> | ||
For the following atrocity crimes: | ||
<div id="atrocity-crimes"></div> | ||
</div> | ||
|
||
<img id="face" /> | ||
|
||
<div class="wanted-name"> | ||
😈 | ||
<div id="wanted-name"></div> | ||
😈 | ||
</div> | ||
|
||
<div class="alive">PREFERABLE ALIVE WITH ALL OF LIMBS</div> | ||
|
||
<div class="reward"> | ||
Reward from friends: | ||
<div id="reward"></div> | ||
</div> | ||
</section> | ||
|
||
<style> | ||
#page { | ||
display: block; | ||
width: 190mm; | ||
height: 270mm; | ||
font-family: Kalam; | ||
overflow: hidden; | ||
} | ||
|
||
.header { | ||
font-family: 'Patua One'; | ||
font-size: 36pt; | ||
text-align: center; | ||
font-weight: 800; | ||
line-height: 2; | ||
border-top: 2pt solid; | ||
border-bottom: 2pt solid; | ||
margin-top: 15pt; | ||
} | ||
|
||
.star { | ||
width: 50pt; | ||
line-height: 30pt; | ||
background: white; | ||
margin: 0 auto; | ||
margin-top: -20pt; | ||
} | ||
|
||
.atrocity-crimes { | ||
font-size: 18pt; | ||
text-align: center; | ||
padding: 10pt; | ||
} | ||
|
||
#face { | ||
width: 100%; | ||
height: auto; | ||
} | ||
|
||
.wanted-name { | ||
display: flex; | ||
justify-content: center; | ||
font-size: 28pt; | ||
padding: 10pt; | ||
} | ||
|
||
#wanted-name { | ||
padding: 0 10pt; | ||
} | ||
|
||
.alive { | ||
font-family: 'Patua One'; | ||
font-size: 26pt; | ||
font-weight: 600; | ||
text-align: center; | ||
line-height: 2; | ||
border-top: 2pt solid; | ||
border-bottom: 2pt solid; | ||
} | ||
|
||
.reward { | ||
font-size: 18pt; | ||
text-align: center; | ||
padding: 10pt; | ||
} | ||
</style> |
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
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