Skip to content

Commit

Permalink
replace old wasm with the new cleaner stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
knzai committed Aug 11, 2024
1 parent 3980932 commit 511b7ae
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 522 deletions.
14 changes: 3 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@ name = 'cega-wasm'
path = "src/wasm/main.rs"
required-features = ["wasm"]

[[bin]]
name = 'cega-webc'
path = "src/webc/main.rs"
required-features = ["webc"]

[features]
default = ["terminal", "png", "webc"]
default = ["terminal", "png", "wasm"]
png = ["dep:image"]
#terminal related features
terminal = ["dep:clap"]
#Preview window popup for the terminal
gui = ["dep:sdl2"]
#Web usage, may want to build with no-default-features to skip irrelevant terminal stuff
wasm = ["png", "dep:base64", "dep:gloo", "dep:js-sys", "dep:web-sys", "dep:yew"]
#Web component, may want to build with no-default-features to skip irrelevant terminal stuff
webc = ["png", "dep:base64", "dep:gloo", "gloo-utils", "dep:js-sys", "dep:wasm-bindgen", "dep:web-sys"]

#Web assembly components, may want to build with no-default-features to skip irrelevant terminal stuff
wasm = ["png", "dep:base64", "dep:gloo", "gloo-utils", "dep:js-sys", "dep:wasm-bindgen", "dep:web-sys"]

[dev-dependencies]
rusty-hook = "^0.11.2"
Expand Down
2 changes: 1 addition & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build]
target = "src/webc/index.html"
target = "src/wasm/index.html"
dist = "target/dist"
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub mod terminal;
#[cfg(feature = "png")]
pub mod png;

#[cfg(feature = "wasm")]
pub mod wasm;

pub type RawGrid = Vec<Vec<u8>>;
pub type Grid<T> = Vec<Vec<T>>;

Expand Down
File renamed without changes.
112 changes: 0 additions & 112 deletions src/wasm/file_input.rs

This file was deleted.

116 changes: 0 additions & 116 deletions src/wasm/image.rs

This file was deleted.

65 changes: 51 additions & 14 deletions src/wasm/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
<!doctype html>
<html lang="en">
<head>
<link data-trunk rel="css" href="./styles.css" />
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"
/>
<link
data-trunk
rel="rust" href="../../Cargo.toml"
data-bin="cega-wasm"
data-cargo-no-default-features
data-cargo-features="wasm"
/>
</head>
<body></body>
<head>
<link data-trunk rel="css" href="./styles.css" />
<link
data-trunk
rel="rust" href="../../Cargo.toml"
data-bin="cega-wasm"
data-cargo-no-default-features
data-cargo-features="wasm"
/>
<script data-trunk src="./file-byte-reader.js"></script>
<script>
let $ = (query) => document.querySelector(query);

function fileLoaded(array) {
let hash = new Map(Object.entries(window.wasmBindings.previews(array)));
hash.forEach((images, key) => {
const container = document.createElement("preview-area");
images.forEach(src => container.appendChild(new PreviewItem(src)));
$('preview-wrapper').appendChild(container);
})
}

document.addEventListener("DOMContentLoaded", () => {
$('#file-input').addEventListener("file-byte-reader:loaded",
e => fileLoaded(e.detail)
);
});

class PreviewItem extends HTMLElement {
constructor(src) {
super();
const shadow = this.attachShadow({mode: "open"});
const fragment = document.createRange().createContextualFragment('<h3></h3><img/>');
const h3 = fragment.querySelector('h3');
this.img = fragment.querySelector("img");

this.img.onload = function () {
h3.innerText = this.width;
}
this.img.src = src
shadow.appendChild(fragment);
}
}
customElements.define("preview-item", PreviewItem);
</script>
</head>
<body>
<h1>Process your CGA/EGAs</h1>
<input is="file-byte-reader" id="file-input" multiple="true" accept=".bin,.cga,.ega,.cega" />
<preview-wrapper></preview-wrapper>
</body>
</html>
Loading

0 comments on commit 511b7ae

Please sign in to comment.