Skip to content

Commit

Permalink
feat: bump gleam and deps (#11)
Browse files Browse the repository at this point in the history
* feat: bump gleam and deps

* fix: update workflows

* fix: format
  • Loading branch information
brettkolodny authored Dec 22, 2023
1 parent 4b6dd94 commit 58c97e3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "26.1"
gleam-version: "0.32.4"
gleam-version: "0.33.0"

- run: |
version="v$(cat gleam.toml | grep -m 1 "version" | sed -r "s/version *= *\"([[:digit:].]+)\"/\1/")"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "25.2"
gleam-version: "0.32.0"
gleam-version: "0.33.0"

- run: gleam format --check

Expand Down
7 changes: 4 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name = "gleam_community_colour"
version = "1.2.0"
version = "1.3.0"
licences = ["Apache-2.0"]
description = "Colour types, conversions, and other utilities"
repository = { type = "github", user = "gleam-community", repo = "colour" }
gleam = ">= 0.33.0"

[dependencies]
gleam_stdlib = "~> 0.32"
gleam_stdlib = "~> 0.34"

[dev-dependencies]
gleeunit = "~> 0.11"
gleeunit = "~> 1.0"
8 changes: 4 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]

[requirements]
gleam_stdlib = { version = "~> 0.32" }
gleeunit = { version = "~> 0.11" }
gleam_stdlib = { version = "~> 0.34" }
gleeunit = { version = "~> 1.0" }
70 changes: 39 additions & 31 deletions src/gleam_community/colour.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,24 @@ fn hex_string_to_int(hex_string: String) -> Result(Int, Nil) {
|> string.lowercase()
|> string.to_graphemes()
|> list.reverse()
|> list.index_fold(
Ok(0),
fn(total, char, index) {
case total {
Error(Nil) -> Error(Nil)
Ok(v) -> {
use num <- result.then(case char {
"a" -> Ok(10)
"b" -> Ok(11)
"c" -> Ok(12)
"d" -> Ok(13)
"e" -> Ok(14)
"f" -> Ok(15)
_ -> int.parse(char)
})
use base <- result.then(int.power(16, int.to_float(index)))
Ok(v + float.round(int.to_float(num) *. base))
}
|> list.index_fold(Ok(0), fn(total, char, index) {
case total {
Error(Nil) -> Error(Nil)
Ok(v) -> {
use num <- result.then(case char {
"a" -> Ok(10)
"b" -> Ok(11)
"c" -> Ok(12)
"d" -> Ok(13)
"e" -> Ok(14)
"f" -> Ok(15)
_ -> int.parse(char)
})
use base <- result.then(int.power(16, int.to_float(index)))
Ok(v + float.round(int.to_float(num) *. base))
}
},
)
}
})
}

fn hsla_to_rgba(
Expand Down Expand Up @@ -263,7 +260,8 @@ fn rgba_to_hsla(
let s = case True {
_ if min_colour == max_colour -> 0.0
_ if l <. 0.5 ->
{ max_colour -. min_colour } /. { max_colour +. min_colour }
{ max_colour -. min_colour }
/. { max_colour +. min_colour }
_ -> { max_colour -. min_colour } /. { 2.0 -. max_colour -. min_colour }
}

Expand Down Expand Up @@ -726,9 +724,12 @@ pub fn to_css_rgba_string(colour: Colour) -> String {
string.join(
[
"rgba(",
float.to_string(percent(r)) <> "%,",
float.to_string(percent(g)) <> "%,",
float.to_string(percent(b)) <> "%,",
float.to_string(percent(r))
<> "%,",
float.to_string(percent(g))
<> "%,",
float.to_string(percent(b))
<> "%,",
float.to_string(round_to(a)),
")",
],
Expand Down Expand Up @@ -816,22 +817,26 @@ pub fn to_rgba_hex(colour: Colour) -> Int {
let #(r, g, b, a) = to_rgba(colour)

let red =
r *. 255.0
r
*. 255.0
|> float.round()
|> int.bitwise_shift_left(24)

let green =
g *. 255.0
g
*. 255.0
|> float.round()
|> int.bitwise_shift_left(16)

let blue =
b *. 255.0
b
*. 255.0
|> float.round()
|> int.bitwise_shift_left(8)

let alpha =
a *. 255.0
a
*. 255.0
|> float.round()

red + green + blue + alpha
Expand Down Expand Up @@ -863,17 +868,20 @@ pub fn to_rgb_hex(colour: Colour) -> Int {
let #(r, g, b, _) = to_rgba(colour)

let red =
r *. 255.0
r
*. 255.0
|> float.round()
|> int.bitwise_shift_left(16)

let green =
g *. 255.0
g
*. 255.0
|> float.round()
|> int.bitwise_shift_left(8)

let blue =
b *. 255.0
b
*. 255.0
|> float.round()

red + green + blue
Expand Down
9 changes: 5 additions & 4 deletions test/colour/accessibility.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ pub fn luminance_test() {
}

pub fn maximum_contrast_test() {
accessibility.maximum_contrast(
colour.yellow,
[colour.white, colour.dark_blue, colour.green],
)
accessibility.maximum_contrast(colour.yellow, [
colour.white,
colour.dark_blue,
colour.green,
])
|> should.equal(Ok(colour.dark_blue))
}

0 comments on commit 58c97e3

Please sign in to comment.