Skip to content

Commit

Permalink
support css minify
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Oct 24, 2024
1 parent 73348d9 commit 57a1540
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 245 deletions.
4 changes: 4 additions & 0 deletions ansi2-wasm/src-ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async function main() {
.option("-c, --compress [bool]", "compress", undefined)
.option("--light-bg [string eg.#FFFFFF]", "light-bg", undefined)
.option("--dark-bg [string eg.#000000]", "dark-bg", undefined)
.option("--font-size [number]", "font-size", undefined)
.version(version)

program.parse()
Expand All @@ -81,6 +82,7 @@ async function main() {
typeof options.font === "undefined" ? undefined : getFontUrl(options.font)

const compress = options.compress === "undefined" ? false : options.compress
const fontSize = options.fontSize === "undefined" ? 16 : options.fontSize

switch (format) {
case "svg": {
Expand All @@ -92,6 +94,7 @@ async function main() {
mode,
options.lightBg,
options.darkBg,
fontSize,
)
const result = compress
? optimize(s, {
Expand Down Expand Up @@ -120,6 +123,7 @@ async function main() {
mode,
options.lightBg,
options.darkBg,
fontSize,
),
)
break
Expand Down
6 changes: 6 additions & 0 deletions ansi2-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ansi2::{css::Mode, theme::Theme};
use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen]
#[allow(clippy::too_many_arguments)]
pub fn to_svg(
s: String,
theme: Theme,
Expand All @@ -10,6 +11,7 @@ pub fn to_svg(
mode: Option<Mode>,
light_bg: Option<String>,
dark_bg: Option<String>,
font_size: Option<usize>,
) -> String {
let mode = mode.map(|m| match m {
Mode::Dark => ansi2::css::Mode::Dark,
Expand All @@ -23,10 +25,12 @@ pub fn to_svg(
mode,
light_bg,
dark_bg,
font_size,
)
}

#[wasm_bindgen]
#[allow(clippy::too_many_arguments)]
pub fn to_html(
s: String,
theme: Theme,
Expand All @@ -35,6 +39,7 @@ pub fn to_html(
mode: Option<Mode>,
light_bg: Option<String>,
dark_bg: Option<String>,
font_size: Option<usize>,
) -> String {
let mode = mode.map(|m| match m {
Mode::Dark => ansi2::css::Mode::Dark,
Expand All @@ -48,6 +53,7 @@ pub fn to_html(
mode,
light_bg,
dark_bg,
font_size,
)
}

Expand Down
Loading

0 comments on commit 57a1540

Please sign in to comment.