-
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.
feat: Basic web interface functionality
- Loading branch information
Showing
11 changed files
with
181 additions
and
14 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,12 @@ | ||
import * as bwip from "@metafloor/bwip-js"; | ||
|
||
export function createBarcodeSVG(data: string, embedded = false): string { | ||
return bwip.toSVG({ | ||
bcid: 'code128', // Barcode type | ||
text: data, // Text to encode | ||
scale: 3, // 3x scaling factor | ||
height: 10, // Bar height, in millimeters | ||
includetext: !embedded, // Show human-readable text | ||
textxalign: 'center', // Always good to set this | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,37 @@ | ||
export function IndexPage() { | ||
return <h1>Test</h1> | ||
import { css, cx } from "@hono/hono/css"; | ||
import { generateASN } from "$common/asn.ts"; | ||
|
||
const hideOnPrint = css` | ||
@media print { | ||
display: none; | ||
} | ||
` | ||
|
||
const mainClass = css` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0rem; | ||
justify-content: center; | ||
align-items: center; | ||
` | ||
|
||
export async function IndexPage() { | ||
const asn = await generateASN(); | ||
const script = {__html: `globalThis.asn = ${JSON.stringify(asn)};`}; | ||
return <> | ||
<script dangerouslySetInnerHTML={script}></script> | ||
<header class={cx(hideOnPrint)}> | ||
<button onclick={'globalThis.copy()'}>Copy</button> | ||
<button onclick={'globalThis.location.reload()'}>Reload</button> | ||
<button onclick={'globalThis.print()'}>Print</button> | ||
<a href={`/svg/${asn.asn}`} download>Download</a> | ||
</header> | ||
<main class={mainClass}> | ||
<img src={`/svg/${asn.asn}?embed=true`} alt="Barcode" /> | ||
<p>{asn.asn}</p> | ||
</main> | ||
<footer class={cx(hideOnPrint)}> | ||
<a href="/about">About</a> | ||
</footer> | ||
</> | ||
} |
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,36 @@ | ||
/** | ||
* The ASN rendered by the current page | ||
* @type {import("$common/asn.ts").ASNData | undefined} | ||
*/ | ||
const asn = globalThis.asn; | ||
|
||
init() | ||
.then(() => console.log("✅ Interactive Elements initialized")) | ||
.catch((err) => | ||
console.error( | ||
"🛑 An error occured while initializing Interactive Elements", | ||
err | ||
) | ||
); | ||
|
||
async function init() { | ||
console.log("⌚️ Initializing Interactive Elements..."); | ||
if (!asn) { | ||
console.warn("ASN not found"); | ||
return; | ||
} | ||
|
||
console.debug("ASN found:", asn); | ||
|
||
globalThis.copy = () => { | ||
navigator.clipboard.writeText(asn.asn).then(() => { | ||
console.log("✅ Copied ASN to clipboard"); | ||
}); | ||
}; | ||
|
||
globalThis.downloadBarcode = () => { | ||
// TODO: Implement barcode download | ||
} | ||
|
||
await Promise.resolve(); | ||
} |
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,4 +1,12 @@ | ||
:root { | ||
--primary-color: #452897; | ||
--font-family: 'Roboto', Arial, sans-serif; | ||
} | ||
} | ||
|
||
body { | ||
font-family: var(--font-family); | ||
} | ||
|
||
a { | ||
color: var(--primary-color); | ||
} |