Skip to content

Commit

Permalink
feat(wasm): add Catwalk.version, distribute node target, fix outp…
Browse files Browse the repository at this point in the history
…ut size (#64)
  • Loading branch information
nekowinston authored Nov 4, 2023
1 parent 0840e14 commit 6833066
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion catwalk/.justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ build-wasm:
rm -rf ./pkg || true
mkdir -p ./pkg
@just wasm-pack-build \
--target bundler \
--target nodejs \
--out-dir ./pkg \
--out-name catwalk
sed -i 's/@catppuccin\/catppuccin-catwalk/@catppuccin\/catwalk/g' ./pkg/package.json
@just wasm-pack-build \
--target deno \
--out-dir ./pkg/deno \
Expand Down
2 changes: 1 addition & 1 deletion catwalk/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

const { args, options } = await new Command()
.name("catwalk")
.version("1.0.3")
.version(Catwalk.version)
.description(
"A sweet program that takes in four showcase images and displays them all at once. (JS port)",
)
Expand Down
21 changes: 14 additions & 7 deletions catwalk/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,23 @@ impl Catwalk {
pub fn build_buffer(self) -> Result<CatwalkBuffer, CatwalkError> {
Ok(self.prepare()?.result_buffer())
}

/// Returns the version of the Catwalk library.
#[must_use]
#[wasm_bindgen(getter)]
pub fn version() -> String {
env!("CARGO_PKG_VERSION").to_string()
}
}

impl Magic {
/// Calculate the Catwalk image & return an `ImageData` object.
/// # Errors
/// Returns an error if the `ImageData` cannot be created.
pub fn result(self) -> Result<ImageData, JsValue> {
let width = self.width;
let data = self
.process()
let img = self.process();
let width = img.width();
let data = img
.data
.iter()
.flat_map(|rgba| vec![rgba.r, rgba.g, rgba.b, rgba.a])
Expand All @@ -150,11 +157,11 @@ impl Magic {

#[must_use]
pub fn result_buffer(self) -> CatwalkBuffer {
let height = self.height;
let width = self.width;
let img = self.process();
let width = img.width();
let height = img.height();
// collect a Vec<u8> from the rgba pixels
let data: Vec<u8> = self
.process()
let data: Vec<u8> = img
.data
.into_iter()
.flat_map(|rgba| vec![rgba.r, rgba.g, rgba.b, rgba.a])
Expand Down

0 comments on commit 6833066

Please sign in to comment.