Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -40,16 +40,16 @@ class Animation {
final FrameData frame = frames[i];
if (size != frame.size) {
throw Exception(
'All animation frames must have the same size,\n'
'first frame size was: (${size.x}, ${size.y})\n'
'frame $i size was: (${frame.size.x}, ${frame.size.y})'
'All animation frames must have the same size,\n'
'first frame size was: (${size.x}, ${size.y})\n'
'frame $i size was: (${frame.size.x}, ${frame.size.y})',
);
}
if (numPaths != frame.paths.length) {
throw Exception(
'All animation frames must have the same number of paths,\n'
'first frame has $numPaths paths\n'
'frame $i has ${frame.paths.length} paths'
'All animation frames must have the same number of paths,\n'
'first frame has $numPaths paths\n'
'frame $i has ${frame.paths.length} paths',
);
}
}
@@ -79,18 +79,25 @@ class PathAnimation {
}
final List<PathCommandAnimation> commands = <PathCommandAnimation>[];
for (int commandIdx = 0; commandIdx < frames[0].paths[pathIdx].commands.length; commandIdx += 1) {
for (
int commandIdx = 0;
commandIdx < frames[0].paths[pathIdx].commands.length;
commandIdx += 1
) {
final int numPointsInCommand = frames[0].paths[pathIdx].commands[commandIdx].points.length;
final List<List<Point<double>>> points = List<List<Point<double>>>.filled(numPointsInCommand, <Point<double>>[]);
final List<List<Point<double>>> points = List<List<Point<double>>>.filled(
numPointsInCommand,
<Point<double>>[],
);
final String commandType = frames[0].paths[pathIdx].commands[commandIdx].type;
for (int i = 0; i < frames.length; i += 1) {
final FrameData frame = frames[i];
final String currentCommandType = frame.paths[pathIdx].commands[commandIdx].type;
if (commandType != currentCommandType) {
throw Exception(
'Paths must be built from the same commands in all frames '
"command $commandIdx at frame 0 was of type '$commandType' "
"command $commandIdx at frame $i was of type '$currentCommandType'"
'Paths must be built from the same commands in all frames '
"command $commandIdx at frame 0 was of type '$commandType' "
"command $commandIdx at frame $i was of type '$currentCommandType'",
);
}
for (int j = 0; j < numPointsInCommand; j += 1) {
@@ -101,13 +108,14 @@ class PathAnimation {
}
final List<double> opacities =
frames.map<double>((FrameData d) => d.paths[pathIdx].opacity).toList();
frames.map<double>((FrameData d) => d.paths[pathIdx].opacity).toList();
return PathAnimation(commands, opacities: opacities);
}
/// List of commands for drawing the path.
final List<PathCommandAnimation> commands;
/// The path opacity for each animation frame.
final List<double> opacities;
@@ -190,8 +198,7 @@ FrameData interpretSvg(String svgFilePath) {
final double width = parsePixels(_extractAttr(svgElement, 'width')).toDouble();
final double height = parsePixels(_extractAttr(svgElement, 'height')).toDouble();
final List<SvgPath> paths =
_interpretSvgGroup(svgElement.children, _Transform());
final List<SvgPath> paths = _interpretSvgGroup(svgElement.children, _Transform());
return FrameData(Point<double>(width, height), paths);
}
@@ -216,7 +223,8 @@ List<SvgPath> _interpretSvgGroup(List<XmlNode> children, _Transform transform) {
Matrix3 transformMatrix = transform.transformMatrix;
if (_hasAttr(element, 'transform')) {
transformMatrix = transformMatrix.multiplied(
_parseSvgTransform(_extractAttr(element, 'transform')));
_parseSvgTransform(_extractAttr(element, 'transform')),
);
}
final _Transform subtreeTransform = _Transform(
@@ -249,10 +257,7 @@ List<Point<double>> parsePoints(String points) {
final List<Point<double>> result = <Point<double>>[];
while (unParsed.isNotEmpty && _pointMatcher.hasMatch(unParsed)) {
final Match m = _pointMatcher.firstMatch(unParsed)!;
result.add(Point<double>(
double.parse(m.group(1)!),
double.parse(m.group(2)!),
));
result.add(Point<double>(double.parse(m.group(1)!), double.parse(m.group(2)!)));
unParsed = m.group(3)!;
}
return result;
@@ -271,9 +276,9 @@ class FrameData {
if (other.runtimeType != runtimeType) {
return false;
}
return other is FrameData
&& other.size == size
&& const ListEquality<SvgPath>().equals(other.paths, paths);
return other is FrameData &&
other.size == size &&
const ListEquality<SvgPath>().equals(other.paths, paths);
}
@override
@@ -317,7 +322,7 @@ class SvgPath {
SvgPath _applyTransform(_Transform transform) {
final List<SvgPathCommand> transformedCommands =
commands.map<SvgPathCommand>((SvgPathCommand c) => c._applyTransform(transform)).toList();
commands.map<SvgPathCommand>((SvgPathCommand c) => c._applyTransform(transform)).toList();
return SvgPath(id, transformedCommands, opacity: opacity * transform.opacity);
}
@@ -326,10 +331,10 @@ class SvgPath {
if (other.runtimeType != runtimeType) {
return false;
}
return other is SvgPath
&& other.id == id
&& other.opacity == opacity
&& const ListEquality<SvgPathCommand>().equals(other.commands, commands);
return other is SvgPath &&
other.id == id &&
other.opacity == opacity &&
const ListEquality<SvgPathCommand>().equals(other.commands, commands);
}
@override
@@ -339,7 +344,6 @@ class SvgPath {
String toString() {
return 'SvgPath(id: $id, opacity: $opacity, commands: $commands)';
}
}
/// Represents a single SVG path command from an SVG d element.
@@ -363,11 +367,8 @@ class SvgPathCommand {
final List<Point<double>> points;
SvgPathCommand _applyTransform(_Transform transform) {
final List<Point<double>> transformedPoints =
_vector3ArrayToPoints(
transform.transformMatrix.applyToVector3Array(
_pointsToVector3Array(points)
)
final List<Point<double>> transformedPoints = _vector3ArrayToPoints(
transform.transformMatrix.applyToVector3Array(_pointsToVector3Array(points)),
);
return SvgPathCommand(type, transformedPoints);
}
@@ -377,9 +378,9 @@ class SvgPathCommand {
if (other.runtimeType != runtimeType) {
return false;
}
return other is SvgPathCommand
&& other.type == type
&& const ListEquality<Point<double>>().equals(other.points, points);
return other is SvgPathCommand &&
other.type == type &&
const ListEquality<Point<double>>().equals(other.points, points);
}
@override
@@ -392,7 +393,7 @@ class SvgPathCommand {
}
class SvgPathCommandBuilder {
static const Map<String, void> kRelativeCommands = <String, void> {
static const Map<String, void> kRelativeCommands = <String, void>{
'c': null,
'l': null,
'm': null,
@@ -440,8 +441,7 @@ List<double> _pointsToVector3Array(List<Point<double>> points) {
List<Point<double>> _vector3ArrayToPoints(List<double> vector) {
final int numPoints = (vector.length / 3).floor();
final List<Point<double>> points = <Point<double>>[
for (int i = 0; i < numPoints; i += 1)
Point<double>(vector[i*3], vector[i*3 + 1]),
for (int i = 0; i < numPoints; i += 1) Point<double>(vector[i * 3], vector[i * 3 + 1]),
];
return points;
}
@@ -451,23 +451,21 @@ List<Point<double>> _vector3ArrayToPoints(List<double> vector) {
/// This includes more transforms than the ones described by the SVG transform
/// attribute, e.g opacity.
class _Transform {
/// Constructs a new _Transform, default arguments create a no-op transform.
_Transform({Matrix3? transformMatrix, this.opacity = 1.0}) :
transformMatrix = transformMatrix ?? Matrix3.identity();
_Transform({Matrix3? transformMatrix, this.opacity = 1.0})
: transformMatrix = transformMatrix ?? Matrix3.identity();
final Matrix3 transformMatrix;
final double opacity;
_Transform applyTransform(_Transform transform) {
return _Transform(
transformMatrix: transform.transformMatrix.multiplied(transformMatrix),
opacity: transform.opacity * opacity,
transformMatrix: transform.transformMatrix.multiplied(transformMatrix),
opacity: transform.opacity * opacity,
);
}
}
const String _transformCommandAtom = r' *([^(]+)\(([^)]*)\)';
final RegExp _transformValidator = RegExp('^($_transformCommandAtom)*\$');
final RegExp _transformCommand = RegExp(_transformCommandAtom);
@@ -476,7 +474,7 @@ Matrix3 _parseSvgTransform(String transform) {
if (!_transformValidator.hasMatch(transform)) {
throw Exception('illegal or unsupported transform: $transform');
}
final Iterable<Match> matches =_transformCommand.allMatches(transform).toList().reversed;
final Iterable<Match> matches = _transformCommand.allMatches(transform).toList().reversed;
Matrix3 result = Matrix3.identity();
for (final Match m in matches) {
final String command = m.group(1)!;
@@ -539,19 +537,19 @@ int parsePixels(String pixels) {
if (!_pixelsExp.hasMatch(pixels)) {
throw ArgumentError(
"illegal pixels expression: '$pixels'"
' (the tool currently only support pixel units).');
' (the tool currently only support pixel units).',
);
}
return int.parse(_pixelsExp.firstMatch(pixels)!.group(1)!);
}
String _extractAttr(XmlElement element, String name) {
try {
return element.attributes.singleWhere((XmlAttribute x) => x.name.local == name)
.value;
return element.attributes.singleWhere((XmlAttribute x) => x.name.local == name).value;
} catch (e) {
throw ArgumentError(
"Can't find a single '$name' attributes in ${element.name}, "
'attributes were: ${element.attributes}'
"Can't find a single '$name' attributes in ${element.name}, "
'attributes were: ${element.attributes}',
);
}
}
@@ -562,9 +560,10 @@ bool _hasAttr(XmlElement element, String name) {
XmlElement _extractSvgElement(XmlDocument document) {
return document.children.singleWhere(
(XmlNode node) => node.nodeType == XmlNodeType.ELEMENT &&
_asElement(node).name.local == 'svg'
) as XmlElement;
(XmlNode node) =>
node.nodeType == XmlNodeType.ELEMENT && _asElement(node).name.local == 'svg',
)
as XmlElement;
}
XmlElement _asElement(XmlNode node) => node as XmlElement;