over.dart
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'package:flutter/widgets.dart';
import '../../render/layout/min_dimension.dart';
import '../../render/layout/vlist.dart';
import '../options.dart';
import '../size.dart';
import '../style.dart';
import '../syntax_tree.dart';
/// Over node.
///
/// Examples: `\underset`
class OverNode extends SlotableNode<EquationRowNode> {
/// Base where the over node is applied upon.
final EquationRowNode base;
/// Argument above the base.
final EquationRowNode above;
/// Special flag for `\stackrel`
final bool stackRel;
OverNode({
required this.base,
required this.above,
this.stackRel = false,
});
// KaTeX's corresponding code is in /src/functions/utils/assembleSubSup.js
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) {
final spacing = options.fontMetrics.bigOpSpacing5.cssEm.toLpUnder(options);
return BuildResult(
options: options,
widget: Padding(
padding: EdgeInsets.only(top: spacing),
child: VList(
baselineReferenceWidgetIndex: 1,
children: <Widget>[
// TexBook Rule 13a
MinDimension(
minDepth:
options.fontMetrics.bigOpSpacing3.cssEm.toLpUnder(options),
bottomPadding:
options.fontMetrics.bigOpSpacing1.cssEm.toLpUnder(options),
child: childBuildResults[1]!.widget,
),
childBuildResults[0]!.widget,
],
),
),
);
}
@override
List<MathOptions> computeChildOptions(MathOptions options) => [
options,
options.havingStyle(options.style.sup()),
];
@override
List<EquationRowNode> computeChildren() => [base, above];
@override
AtomType get leftType => stackRel
? AtomType.rel
: AtomType.ord; // TODO: they should align with binrelclass with base
@override
AtomType get rightType => stackRel
? AtomType.rel
: AtomType.ord; // TODO: they should align with binrelclass with base
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
false;
@override
OverNode updateChildren(List<EquationRowNode> newChildren) =>
copyWith(base: newChildren[0], above: newChildren[1]);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'base': base.toJson(),
'above': above.toJson(),
if (stackRel != false) 'stackRel': stackRel,
});
OverNode copyWith({
EquationRowNode? base,
EquationRowNode? above,
bool? stackRel,
}) =>
OverNode(
base: base ?? this.base,
above: above ?? this.above,
stackRel: stackRel ?? this.stackRel,
);
}