Skip to content

Commit

Permalink
wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
rsuu committed Jun 8, 2024
1 parent 936b625 commit c223af7
Show file tree
Hide file tree
Showing 32 changed files with 1,061 additions and 800 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 28 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ image = { version = "0.25.1", default-features = false, features = [
"gif",
] }
fir = { version = "3.0.4", package = "fast_image_resize" }
rgb = { version = "0.8.37", features = ["argb"] }
rgb = { version = "0.8.37" }
infer = "0.15.0"
imagesize = "0.12.0"
# line_drawing = "1.0.0"
line_drawing = "1.0.0"
asefile = { version = "0.3.8", optional = true }
libheif-rs = { version = "1.0.0", optional = true }
# jxl-oxide = "0.8.0"
Expand All @@ -76,9 +76,7 @@ resvg = { version = "0.41.0", optional = true, default-features = false, feature

# archive
tar = { version = "0.4.40", default-features = false, optional = true }
zip = { version = "0.6.6", default-features = false, features = [
"deflate",
] }
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }

# config
dirs-next = "2.0.0"
Expand Down Expand Up @@ -126,11 +124,33 @@ ex_full = ["ex_tar"]
ex_tar = ["dep:tar"]

[target.'cfg(target_family = "wasm")'.dependencies]
console_log = "1.0"
console_error_panic_hook = "0.1.7"
#wasm-bindgen-futures = "0.4.30"
console_log = "1.0"
js-sys = "0.3.69"
wasm-bindgen = "0.2.92"
web-sys = { version = "0.3.69", features = ["Document", "Window", "Element"] }
wasm-bindgen-futures = "0.4.42"
web-sys = { version = "0.3.69", features = [
"Document",
"Element",
"Window",
'CanvasRenderingContext2d',
'DedicatedWorkerGlobalScope',
'ErrorEvent',
'Event',
'Headers',
'ImageData',
'MessageEvent',
'Navigator',
'Request',
'RequestInit',
'RequestMode',
'Response',
'Window',
'Worker',
'WorkerOptions',
'WorkerType',
] }
# wasm_thread = "0.3.0" # nightly only

# [target.'cfg(target_family = "wasm")'.features]
# default = []
Expand Down
76 changes: 37 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,37 @@ rmg file.zip

# rmg file.gif

rmg --canvas-size 600x600 file.zip
rmg --page-size 600x600 file.zip

rmg --canvas-size 600x600 --config ./assets/config.rs file.zip
rmg --page-size 600x600 --config ./assets/config.rs file.zip
```

## Keymap

|Key | Action |
|:- |:- |
|k/Up | move up |
|j/Down | move down |
|h/Left | move left |
|r/Right | move right |
|g | toggle gesture mode |
|q | quit |
|Key | Action |
|:- |:- |
|`k/Up` | move up |
|`j/Down` | move down |
|`h/Left` | move left |
|`r/Right`| move right |
|`g` | toggle gesture mode |
|`q` | quit |

|Key | Action | Layout |
|:- |:- |:- |
| scroll up | move up | Vertical |
| scroll down | move down | Vertical |
| scroll up | zoom out | Single |
| scroll down | zoom in | Single |
|`scroll up `| move up | Vertical |
|`scroll down`| move down | Vertical |
|`scroll up `| zoom out | Single |
|`scroll down`| zoom in | Single |

|Gesture| Action |
|:- |:- |
|rect | |
|ring | |
|Gesture | Action |
|:- |:- |
|`rect` | |
|`ring` | |

## Config

> config: https://raw.githubusercontent.com/rsuu/rmg/main/assets/config.rs
NOTE: You must create the file first.
First copy [config.rs](https://raw.githubusercontent.com/rsuu/rmg/main/assets/config.rs) into `<config_path>`.

+ Linux: `$HOME/.config/rmg/config.rs`
+ Mac: `$HOME/Library/Application Support/rmg/config.rs`
Expand All @@ -81,26 +79,26 @@ see more: https://docs.rs/dirs-next/

## Supported Formats

| Format | Supported | Default | Dependency|
|:- |:- |:- |:- |
|`.jpg` | + | + | |
|`.png` | + | + | |
|`.webp` | + | + | |
|`.heic/avif`| + | | libheif |
|`.gif` | (dev) | + | |
|`.aseprite` | (dev) | | |
|`.svg` | (dev) | | |

| Format | Supported | Default | Dependency|
|:- |:- |:- |:- |
|.jpg | + | + | |
|.png | + | + | |
|.webp | + | + | |
|.heic/avif | + | | libheif |
|.gif | (dev) | + | |
|.aseprite | (dev) | | |
|.svg | (dev) | | |

| Format | Supported | Default | Dependency|
|:- |:- |:- |:- |
|directory | + | + | |
|.tar | + | | |
|.zip/cbz | + | + | |
|.7z | | | |
|.rar | | | |
|.zst | | | |

## Features
|`directory`| + | + | |
|`.tar` | + | | |
|`.zip/cbz` | + | + | |
|`.7z` | | | |
|`.rar` | | | |
|`.zst` | | | |

## Optional Features

```bash
# HEIF/HEIC
Expand Down
47 changes: 30 additions & 17 deletions assets/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
fn main() {}

fn app() -> Any {
Any {
target: "./",
gestures_zip: "./assets/gestures.zip",
gesture_min_score: 0.9,
}
Any { target: "./" }
}

fn window() -> Any {
Expand All @@ -19,30 +15,26 @@ fn window() -> Any {

fn canvas() -> Any {
Any {
size: Size {
width: 800,
height: 600,
},

layout: Layout::Vertical {
align: Align::Center,
},

step_x: 100.0,
step_y: 100.0,

cache_limit: 2,
page_dire: PageDirection::Manga,
pre_load_nums: 4,

// RGBA
/// RGBA
bg: 0x00_00_00_00,
}
}

fn page() -> Any {
Any {
image_resize_algo: WrapResizeAlg::Lanczos3,
anime_resize_algo: WrapResizeAlg::Nearest,
size: Size {
width: 800,
height: 600,
},
img_resize_algo: WrapResizeAlg::Lanczos3,
anim_resize_algo: WrapResizeAlg::Nearest,
}
}

Expand All @@ -57,3 +49,24 @@ fn once() -> Any {
record_gesture_name: None,
}
}

fn gestures() -> Any {
Any {
data_path: "./assets/gestures.zip",
min_score: 0.9,
}
}

fn layout_double() -> Any {
Any {
/// right to left
reading_dire: Direction::Rtl,
}
}

fn on_scroll() -> Any {
Any {
step_x: 100.0,
step_y: 100.0,
}
}
38 changes: 36 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub mod window;

pub mod buffer;
pub mod canvas;
pub mod draw;
Expand All @@ -8,3 +6,39 @@ pub mod layout;
pub mod page;
pub mod state;
pub mod task;
pub mod view;
pub mod window;

// #[cfg(target_arch = "wasm32")]
mod web;

use crate::{Element, ElementArgs, Frame, Page, State, Style};

pub type Elem = Box<dyn Element<Res = eyre::Result<()>>>;
pub type Elems = Vec<Elem>;

pub struct World {
elems: Elems,
// TODO: center by default
// global value
// offset: Vec2,
}

impl World {
pub fn new(elems: Vec<Page>) -> Self {
let elems = elems
.into_iter()
.map(|elem| Box::new(elem) as Box<dyn Element<Res = eyre::Result<()>>>)
.collect();

Self { elems }
}

pub fn render<'a>(&mut self, args: &'a mut ElementArgs) -> eyre::Result<()> {
for elem in self.elems.iter() {
elem.as_ref().draw(args)?;
}

Ok(())
}
}
Loading

0 comments on commit c223af7

Please sign in to comment.