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
break;
};
$usage = $_;
- my $ref = $canihas->{-source} || 'unknown';
- $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $canihas->{-url} || ();
+ my $ref = $canihas->{-title} || 'unknown';
+ $ref = sprintf '<a href="%s">%s</a>', $_, $ref
+ for $canihas->{-site} || $canihas->{-source} || ();
$ref .= " $_" for $canihas->{-date} || ();
print "\nwith $ref browser usage statistics";
}
$row->{$_} //= undef for @$verlist; # ensure stable keys during iteration
while (my ($version, $usage) = each %$row) {
next if defined $supported{$version};
- $_ = paddedver($_) for $version;
- my $next = first { paddedver($_) ge $version } @$verlist; # or next
+ 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
}
}
}
}
} @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 '<table class="mapped">';
print '<col span="3">'; # should match first thead row
$_, @{ $caniuse->{agents}->{$_} }{'prefix', 'type'},
),
join(' ',
- sprintf('%.1f%%', sum(values %{ $canihas->{$_} })),
+ sprintf('%.1f%%', sum(values %{ $canihas->{$_} }) * $usagepct),
$name,
),
do {
print "\n<tr>";
print '<td>' x 3;
for my $browser (@browsers) {
- printf('<td title="%s"%s>%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('<td title="%s"%s>%s',
+ join(' ',
+ sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct),
+ $future ? 'development' : (),
+ "version $_",
+ ),
+ $future && ' class="ex"',
+ showversions($_),
+ );
+ }
}
print '<td>' x 1;
say '</thead>';
sub featurescore {
# relative amount of support for given feature
- state $statspts = { y=>10, 'y x'=>10, a=>5, 'a x'=>5, j=>2, 'p j'=>2, 'p p'=>2, p=>1 };
+ state $statspts = { y=>1, 'y x'=>1, a=>.5, 'a x'=>.5, j=>.2, 'p j'=>.2, 'p p'=>.2, p=>.1 };
my $rank = 0;
if (my $row = shift) {
if ($canihas) {
} $row->{title};
print '<div class=aside>';
s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
- Entity($row->{description}), formathtml($row->{notes}); # sic
+ Entity($row->{description}),
+ map { s/\s*\n/\n<br>/g; $_ } $row->{notes};
printf 'Resources: %s.', join(', ', map {
sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), $_->{title}
} @$_) for grep { @$_ } $row->{links} // ();
+ printf '<br>Parent feature: %s.', join(', ', map {
+ sprintf '<a href="%s">%s</a>', EscapeHTML("#$_"), $caniuse->{data}->{$_}->{title}
+ } $_) for $row->{parent} || ();
print '</div>';
}
join(' ',
X => $CSTATS{ ref $data eq 'HASH' && $data->{$prev} || 'u' },
!$usage ? ('p0') : ('p',
- sprintf('p%01d', $usage / 10),
- sprintf('p%02d', $usage),
+ sprintf('p%01d', $usage * ($usagepct - .0001) / 10),
+ sprintf('p%02d', $usage * ($usagepct - .0001)),
),
- sprintf('pp%02d', $usage / $scorediv),
+ sprintf('pp%02d', $usage / $usagemax),
),
scalar @span,
- sprintf('%.1f%% %s', $usage, join(', ',
+ sprintf('%.1f%% %s', $usage * $usagepct, join(', ',
map { ref $_ eq 'CODE' ? $_->($browser) : $_ }
map { $DSTATS{$_} // () }
map { split / /, $_ }
sub sayusagecol {
my ($id) = @_;
- state $maxscore = featurescore({ # yes for every possible version
- map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
- });
- print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
+ print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct;
}
say '<tbody>';
say '</tbody>';
say '</table>';
-sub formathtml {
- my $ref = defined wantarray ? [@_] : \@_;
- for (@$ref) {
- s/& (?!\w)/&/gx;
- s/< \s/</gx;
- s/\n\K\n/<br>/g;
- }
- return @$ref;
-}
-
sub paddedver {
# normalised version number comparable as string (cmp)
shift =~ /(?:.*-|^)(\d*)(.*)/;
sub showversions {
my @span = ($_[0], @_>1 ? $_[-1] : ());
+ s/-.*// for $span[0];
for (@span) {
s/^\./0./;
s/x$/.*/;
- s/-.*//;
+ s/.*-//;
}
return join('‒', @span);
}