X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/3ab778af0d83ec94a63bccd029132166ea08bcd8..1fce3b7a43db2a10c3dbab2b3bc89dc7a90c3bad:/browser.plp diff --git a/browser.plp b/browser.plp index 741868b..27dcb1b 100644 --- a/browser.plp +++ b/browser.plp @@ -8,39 +8,17 @@ Html({ version => 'v1.0', description => "caniuse.", - keywords => [qw'html css browser feature'], + keywords => [qw' + web browser support compatibility usage available feature + html html5 css css3 svg javascript js dom mobile + ie internet explorer firefox chrome safari webkit opera + '], stylesheet => [qw'circus dark mono red light'], data => ['browser-support.inc.pl'], }); -:> -

Browser compatibility

- -

Alternate view 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"; -} -:>. -

+say "

Browser compatibility

\n"; -
-<: my $caniuse = do 'browser-support.inc.pl' or die $! || $@; $_->{verrelease} = { # mark last two (future) versions as unreleased, ensure current isn't @@ -59,6 +37,20 @@ my %CSTATS = ( 'p p' => 'l2', 'u' => 'l0', ); +my %DSTATS = ( + u => 'unknown', + n => 'unsupported', + p => 'plugin required', + j => 'javascript required', + a => 'partial', + y => 'supported', + x => sub { + join(' ', + 'requires prefix', + (map "-$_-", $caniuse->{agents}->{$_[0]}->{prefix} // ()), + ); + }, +); my %CSTATUS = ( unoff => 'l1', # unofficial wd => 'l3', # draft @@ -77,6 +69,32 @@ 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"; +} +:>. +

+ +<: $canihas ||= { map { $_ => +{ @@ -94,17 +112,20 @@ $canihas ||= { my $scorediv = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100; print ''; -print '' x 3; +print ''; # should match first thead row printf '', scalar @{ $versions{$_} } for @browsers; -print "\n"; +say ''; my $header = join('', '', '', $header; print "\n"; print '\n"; +say ''; +say '', $header, ''; sub featurescore { # relative amount of support for given feature @@ -172,6 +197,7 @@ sub saytitlecol { for ($row->{categories}) { my $cell = $_ ? lc $_->[0] : '-'; + $cell =~ s/ api$//; # trim unessential fluff in 'js api' printf ''; for my $id (sort { featurescore($caniuse->{data}->{$b}->{stats}) <=> featurescore($caniuse->{data}->{$a}->{stats}) @@ -254,8 +286,18 @@ for my $id (sort { sayusagecol($id); say ''; } -print '', $header; -print '
feature', (map { my $name = $caniuse->{agents}->{$_}->{browser}; - sprintf('%s', + sprintf('%s', scalar @{ $versions{$_} }, + join(' ', map {"b-a-$_"} grep {$_} + $_, @{ $caniuse->{agents}->{$_} }{'prefix', 'type'}, + ), join(' ', sprintf('%.1f%%', sum(values %{ $canihas->{$_} })), $name, @@ -122,8 +143,11 @@ print '
' x 3; for my $browser (@browsers) { - printf('%s', - $canihas->{$browser}->{$_}, + printf('%s', + join(' ', + sprintf('%.1f%%', $canihas->{$browser}->{$_}), + "version $_", + ), (map { defined $_ && !$_ && ' class="ex"' } $caniuse->{agents}->{$browser}->{verrelease}->{$_}), @@ -131,7 +155,8 @@ for my $browser (@browsers) { ) for @{ $versions{$browser} }; } print '' x 1; -print "
%s', join(' + ', @$_), $cell; } @@ -181,15 +207,15 @@ sub saytitlecol { sprintf("try { %s; return false } catch(err) { return true }", "document.getElementById('$id').classList.toggle('target')", ), - $_, + Entity($_), ); } $row->{title}; print '
'; s/\.?$/./, print "

$_

" for map { ref $_ ? @$_ : $_ || () } - $row->{description}, $row->{notes}; - printf 'Resources: %s.', join(', ', - map { qq($_->{title}) } @$_ - ) for grep { @$_ } $row->{links} // (); + Entity($row->{description}), formathtml($row->{notes}); # sic + printf 'Resources: %s.', join(', ', map { + sprintf '%s', EscapeHTML($_->{url}), $_->{title} + } @$_) for grep { @$_ } $row->{links} // (); print '
'; } @@ -214,7 +240,7 @@ sub saybrowsercols { unless (!defined $prev or ref $data eq 'HASH' && $data->{$prev} ~~ $data->{$ver}) { my $usage = sum(map { $canihas->{$browser}->{$_} } @span); - printf '
%s', + printf '%s', join(' ', X => $CSTATS{ ref $data eq 'HASH' && $data->{$prev} || 'u' }, !$usage ? ('p0') : ('p', @@ -224,7 +250,12 @@ sub saybrowsercols { sprintf('pp%02d', $usage / $scorediv), ), scalar @span, - $usage, + sprintf('%.1f%% %s', $usage, join(', ', + map { ref $_ eq 'CODE' ? $_->($browser) : $_ } + map { $DSTATS{$_} // () } + map { split / /, $_ } + ref $data eq 'HASH' && $data->{$prev} || 'u' + )), showversions(@span), undef $prev; @span = (); @@ -242,6 +273,7 @@ sub sayusagecol { print '', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100; } +say '
'; +say ''; +say ''; + +sub formathtml { + my $ref = defined wantarray ? [@_] : \@_; + for (@$ref) { + s/& (?!\w)/&/gx; + s/< \s/</gx; + s/\n\K\n/
/g; + } + return @$ref; +} sub paddedver { # normalised version number comparable as string (cmp) @@ -272,8 +314,7 @@ sub showversions { return join('‒', @span); } -:>
- +:>
@@ -313,6 +354,6 @@ sub showversions {
- - + +