X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/bc5de8de28f6cb4910a0167bfd74133a884dc8f0..0466f0c92a59e94455c8d149c3c84c39b315e2c6:/browser.plp?ds=inline diff --git a/browser.plp b/browser.plp index b052863..fbbddde 100644 --- a/browser.plp +++ b/browser.plp @@ -1,13 +1,15 @@ <(common.inc.plp)><: use 5.010; use utf8; -use List::Util qw(sum max); +use List::Util qw(sum max first); Html({ title => 'browser compatibility cheat sheet', version => 'v1.0', - description => - "caniuse.", + description => [ + "Compatibility table of new web features (HTML5, CSS3, SVG, Javascript)", + "comparing support and usage share for all popular browser versions.", + ], keywords => [qw' web browser support compatibility usage available feature html html5 css css3 svg javascript js dom mobile @@ -17,33 +19,8 @@ Html({ data => ['browser-support.inc.pl'], }); -:> -
Alternate rendition of Fyrd's when can I use... page<: -my ($canihas, $usage); -given ($get{usage} // 'wm') { - when (!$_) { - # none - } - when (!/^\w+$/) { - printf "
Invalid browser usage data request: %s",
- 'identifier must be alphanumeric name or 0
';
- }
- $canihas = do "browser-usage-$_.inc.pl" or do {
- printf "
Browser usage data not found: %s", $! || $@; - break; - }; - $usage = $_; - my $ref = $canihas->{-source} || 'unknown'; - $ref = sprintf '%s', $_, $ref for $canihas->{-url} || (); - $ref .= " $_" for $canihas->{-date} || (); - print "\nwith $ref browser usage statistics"; -} -:>. -
- -<: my $caniuse = do 'browser-support.inc.pl' or die $! || $@; $_->{verrelease} = { # mark last two (future) versions as unreleased, ensure current isn't @@ -94,6 +71,47 @@ if (my ($somerow) = values %{ $caniuse->{data} }) { my @browsers = grep { $versions{$_} } qw(trident gecko webkit_saf ios_saf webkit_chr android presto op_mob op_mini); +print <<''; +Alternate rendition of Fyrd's when can I use... page + +my ($canihas, $usage); +given ($get{usage} // 'wm') { + when (!$_) { + # none + } + when (!/^\w+$/) { + printf "
Invalid browser usage data request: %s",
+ 'identifier must be alphanumeric name or 0
';
+ }
+ $canihas = do "browser-usage-$_.inc.pl" or do {
+ printf "
Browser usage data not found: %s", $! || $@; + break; + }; + $usage = $_; + my $ref = $canihas->{-source} || 'unknown'; + $ref = sprintf '%s', $_, $ref for $canihas->{-url} || (); + $ref .= " $_" for $canihas->{-date} || (); + print "\nwith $ref browser usage statistics"; +} +if ($usage) { + # first() does not work inside given >:( + while (my ($browser, $row) = each %$canihas) { + my $verlist = $versions{$browser} or next; + my %supported = map { $_ => 1 } @$verlist; + $row->{$_} //= undef for @$verlist; # ensure stable keys during iteration + while (my ($version, $usage) = each %$row) { + next if defined $supported{$version}; + my $next = first { paddedver($_) ge paddedver($version) } @$verlist + or warn("No fallback found for $browser v$version; $usage% ignored"), next; + $row->{$next} += $usage; + $row->{$version} = 0; # balance browser total + } + } +} +:>. +
+ +<: $canihas ||= { map { $_ => +{ @@ -108,7 +126,13 @@ $canihas ||= { } } @browsers }; # fallback hash based on release semantics -my $scorediv = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100; +my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100; + +my $usagepct = 1; # score multiplier for 0..100 result +# normalise usage percentage to only include shown browsers +$usagepct = 100 / featurescore({ # yes for every possible version + map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions +}); print '' x 3; for my $browser (@browsers) { - printf(' | %s', - join(' ', - sprintf('%.1f%%', $canihas->{$browser}->{$_}), - "version $_", - ), - (map { - defined $_ && !$_ && ' class="ex"' - } $caniuse->{agents}->{$browser}->{verrelease}->{$_}), - showversions($_), - ) for @{ $versions{$browser} }; + for my $_ (@{ $versions{$browser} }) { + my $release = $caniuse->{agents}->{$browser}->{verrelease}->{$_}; + my $future = defined $release; + printf(' | %s', + join(' ', + sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct), + $future ? 'development' : (), + "version $_", + ), + $future && ' class="ex"', + showversions($_), + ); + } } print ' | ' x 1; say ' | ', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100; + print ' | ', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct; } say ' | '; @@ -288,27 +316,20 @@ for my $id (sort { say ''; say '