mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-31 16:18:22 +08:00
opt opus text
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -40,6 +40,7 @@ class OpusContent extends StatelessWidget {
|
|||||||
required Node item,
|
required Node item,
|
||||||
required ColorScheme colorScheme,
|
required ColorScheme colorScheme,
|
||||||
bool isQuote = false,
|
bool isQuote = false,
|
||||||
|
required double surfaceLuminance,
|
||||||
}) {
|
}) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'TEXT_NODE_TYPE_RICH' when (item.rich != null):
|
case 'TEXT_NODE_TYPE_RICH' when (item.rich != null):
|
||||||
@@ -101,7 +102,8 @@ class OpusContent extends StatelessWidget {
|
|||||||
default:
|
default:
|
||||||
return _getSpan(
|
return _getSpan(
|
||||||
item.word,
|
item.word,
|
||||||
isQuote ? colorScheme.onSurfaceVariant : null,
|
surfaceLuminance: surfaceLuminance,
|
||||||
|
defaultColor: isQuote ? colorScheme.onSurfaceVariant : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,14 +120,27 @@ class OpusContent extends StatelessWidget {
|
|||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
static TextSpan _getSpan(Word? word, [Color? defaultColor]) => TextSpan(
|
static TextSpan _getSpan(
|
||||||
text: word?.words,
|
Word? word, {
|
||||||
style: _getStyle(
|
Color? defaultColor,
|
||||||
word?.style,
|
required double surfaceLuminance,
|
||||||
word?.color != null ? Color(word!.color!) : defaultColor,
|
}) {
|
||||||
word?.fontSize,
|
Color? color;
|
||||||
),
|
if (word?.color case final c?) {
|
||||||
);
|
final tmpColor = Color(c);
|
||||||
|
if ((surfaceLuminance - tmpColor.computeLuminance()).abs() > 0.1) {
|
||||||
|
color = tmpColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TextSpan(
|
||||||
|
text: word?.words,
|
||||||
|
style: _getStyle(
|
||||||
|
word?.style,
|
||||||
|
color ?? defaultColor,
|
||||||
|
word?.fontSize,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -138,6 +153,9 @@ class OpusContent extends StatelessWidget {
|
|||||||
late final isDarkMode = context.isDarkMode;
|
late final isDarkMode = context.isDarkMode;
|
||||||
|
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
late final surfaceLuminance = colorScheme.surface.computeLuminance();
|
||||||
|
|
||||||
return SliverList.separated(
|
return SliverList.separated(
|
||||||
itemCount: opus.length,
|
itemCount: opus.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@@ -151,8 +169,11 @@ class OpusContent extends StatelessWidget {
|
|||||||
TextSpan(
|
TextSpan(
|
||||||
children: element.text?.nodes
|
children: element.text?.nodes
|
||||||
?.map(
|
?.map(
|
||||||
(item) =>
|
(item) => _node2Widget(
|
||||||
_node2Widget(item: item, colorScheme: colorScheme),
|
item: item,
|
||||||
|
colorScheme: colorScheme,
|
||||||
|
surfaceLuminance: surfaceLuminance,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
@@ -241,7 +262,10 @@ class OpusContent extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
...entry.$2.nodes!.map((item) {
|
...entry.$2.nodes!.map((item) {
|
||||||
if (item.word != null) {
|
if (item.word != null) {
|
||||||
return _getSpan(item.word);
|
return _getSpan(
|
||||||
|
item.word,
|
||||||
|
surfaceLuminance: surfaceLuminance,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (item.rich case final rich?) {
|
if (item.rich case final rich?) {
|
||||||
final hasUrl = rich.jumpUrl?.isNotEmpty == true;
|
final hasUrl = rich.jumpUrl?.isNotEmpty == true;
|
||||||
@@ -600,7 +624,11 @@ class OpusContent extends StatelessWidget {
|
|||||||
TextSpan(
|
TextSpan(
|
||||||
children: element.heading!.nodes!
|
children: element.heading!.nodes!
|
||||||
.map(
|
.map(
|
||||||
(e) => _node2Widget(item: e, colorScheme: colorScheme),
|
(e) => _node2Widget(
|
||||||
|
item: e,
|
||||||
|
colorScheme: colorScheme,
|
||||||
|
surfaceLuminance: surfaceLuminance,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
@@ -612,7 +640,12 @@ class OpusContent extends StatelessWidget {
|
|||||||
textAlign: element.align == 1 ? TextAlign.center : null,
|
textAlign: element.align == 1 ? TextAlign.center : null,
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: element.text!.nodes!
|
children: element.text!.nodes!
|
||||||
.map<TextSpan>((item) => _getSpan(item.word))
|
.map<TextSpan>(
|
||||||
|
(item) => _getSpan(
|
||||||
|
item.word,
|
||||||
|
surfaceLuminance: surfaceLuminance,
|
||||||
|
),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user