line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MoreHTMLHelpers; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Some general helpers |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1476
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.02; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
2
|
|
|
2
|
1
|
1357
|
my ($self, $app, $config) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper( textcolor => sub { |
16
|
17
|
|
|
17
|
|
107962
|
my $c = shift; |
17
|
|
|
|
|
|
|
|
18
|
17
|
|
100
|
|
|
53
|
my $color = shift // '#000000'; |
19
|
|
|
|
|
|
|
|
20
|
17
|
|
|
|
|
25
|
my ($red, $green, $blue); |
21
|
|
|
|
|
|
|
|
22
|
17
|
100
|
|
|
|
60
|
if ( length $color == 7 ) { |
|
|
100
|
|
|
|
|
|
23
|
12
|
|
|
|
|
76
|
($red, $green, $blue) = $color =~ m{\#(..)(..)(..)}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ( length $color == 4 ) { |
26
|
3
|
|
|
|
|
20
|
($red, $green, $blue) = $color =~ m{\#(.)(.)(.)}; |
27
|
3
|
|
|
|
|
7
|
for ( $red, $green, $blue ) { |
28
|
9
|
|
|
|
|
16
|
$_ = $_ x 2; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
17
|
|
|
|
|
40
|
my $brightness = _perceived_brightness( $red, $green, $blue ); |
33
|
|
|
|
|
|
|
|
34
|
17
|
100
|
|
|
|
71
|
return $brightness > 130 ? '#000000' : '#ffffff'; |
35
|
2
|
|
|
|
|
20
|
} ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$app->helper( gradient => sub { |
38
|
3
|
|
|
3
|
|
1804
|
my ($c) = shift; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
100
|
|
|
14
|
my $color = shift // '#ffffff'; |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
37
|
return sprintf q~ |
43
|
|
|
|
|
|
|
background: %s !important; |
44
|
|
|
|
|
|
|
background: -moz-linear-gradient(top, %s 0%%,%s 100%%) !important; |
45
|
|
|
|
|
|
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%%, %s), color-stop(100%%,%s)) !important; |
46
|
|
|
|
|
|
|
background: -webkit-linear-gradient(top, %s 0%%,%s 100%%) !important; |
47
|
|
|
|
|
|
|
background: -o-linear-gradient(top, %s 0%%,%s 100%%) !important; |
48
|
|
|
|
|
|
|
background: -ms-linear-gradient(top, %s 0%%,%s 100%%) !important; |
49
|
|
|
|
|
|
|
background: linear-gradient(to bottom,%s 0%%,%s 100%%) !important; |
50
|
|
|
|
|
|
|
~, ($color) x 13; |
51
|
2
|
|
|
|
|
310
|
}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _perceived_brightness { |
55
|
17
|
|
|
17
|
|
30
|
my ($red, $green, $blue) = @_; |
56
|
|
|
|
|
|
|
|
57
|
17
|
100
|
|
|
|
65
|
if ( grep { !defined $_ || $_ =~ m{[^A-Fa-f0-9]} }($red, $green, $blue) ) { |
|
51
|
100
|
|
|
|
206
|
|
58
|
4
|
|
|
|
|
9
|
return 200; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
13
|
|
|
|
|
31
|
$red = hex $red; |
62
|
13
|
|
|
|
|
22
|
$green = hex $green; |
63
|
13
|
|
|
|
|
18
|
$blue = hex $blue; |
64
|
|
|
|
|
|
|
|
65
|
13
|
|
|
|
|
43
|
my $brightness = int ( sqrt ( |
66
|
|
|
|
|
|
|
( $red * $red * .299 ) + |
67
|
|
|
|
|
|
|
( $green * $green * .587 ) + |
68
|
|
|
|
|
|
|
( $blue * $blue * .114 ) |
69
|
|
|
|
|
|
|
)); |
70
|
|
|
|
|
|
|
|
71
|
13
|
|
|
|
|
22
|
return $brightness; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |