mirror of
https://github.com/LinwoodDev/Butterfly.git
synced 2025-08-26 10:51:41 +08:00
Wrap stylesheet with named
This commit is contained in:
@ -179,10 +179,10 @@ Uint8List xoppExporter(NoteData document) {
|
||||
case LabelElement e:
|
||||
final styleSheet = e.styleSheet;
|
||||
final style = e is TextElement
|
||||
? styleSheet
|
||||
?.resolveParagraphProperty(e.area.paragraph.property)
|
||||
? styleSheet?.item
|
||||
.resolveParagraphProperty(e.area.paragraph.property)
|
||||
?.span
|
||||
: styleSheet?.getParagraphProperty('p')?.span;
|
||||
: styleSheet?.item.getParagraphProperty('p')?.span;
|
||||
builder.element('text', attributes: {
|
||||
'color': _exportColor(style?.color ?? SRGBColor.black),
|
||||
'size': (style?.size ?? 12).toString(),
|
||||
|
@ -7,6 +7,7 @@ import '../converter/core.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../converter/id.dart';
|
||||
import 'pack.dart';
|
||||
import 'point.dart';
|
||||
import 'property.dart';
|
||||
import 'text.dart';
|
||||
@ -59,7 +60,7 @@ mixin LabelElement {
|
||||
String get collection;
|
||||
Point<double> get position;
|
||||
double get scale;
|
||||
TextStyleSheet? get styleSheet;
|
||||
NamedItem<TextStyleSheet>? get styleSheet;
|
||||
ElementConstraint get constraint;
|
||||
SRGBColor get foreground;
|
||||
|
||||
@ -100,7 +101,7 @@ sealed class PadElement with _$PadElement {
|
||||
@Default(Point(0.0, 0.0))
|
||||
Point<double> position,
|
||||
@Default(1.0) double scale,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
required TextArea area,
|
||||
@Default(ElementConstraint(size: 1000)) ElementConstraint constraint,
|
||||
@Default(SRGBColor.black) @ColorJsonConverter() SRGBColor foreground,
|
||||
@ -116,7 +117,7 @@ sealed class PadElement with _$PadElement {
|
||||
@Default(Point(0.0, 0.0))
|
||||
Point<double> position,
|
||||
@Default(1.0) double scale,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
@Default(AreaProperty()) AreaProperty areaProperty,
|
||||
required String text,
|
||||
@Default(ElementConstraint(size: 1000)) ElementConstraint constraint,
|
||||
|
@ -799,7 +799,7 @@ class TextElement extends PadElement with LabelElement {
|
||||
final Point<double> position;
|
||||
@JsonKey()
|
||||
final double scale;
|
||||
final TextStyleSheet? styleSheet;
|
||||
final NamedItem<TextStyleSheet>? styleSheet;
|
||||
final TextArea area;
|
||||
@JsonKey()
|
||||
final ElementConstraint constraint;
|
||||
@ -853,13 +853,13 @@ abstract mixin class $TextElementCopyWith<$Res>
|
||||
@IdJsonConverter() String? id,
|
||||
@DoublePointJsonConverter() Point<double> position,
|
||||
double scale,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
TextArea area,
|
||||
ElementConstraint constraint,
|
||||
@ColorJsonConverter() SRGBColor foreground,
|
||||
Map<String, dynamic> extra});
|
||||
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet;
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet;
|
||||
$TextAreaCopyWith<$Res> get area;
|
||||
$ElementConstraintCopyWith<$Res> get constraint;
|
||||
}
|
||||
@ -911,7 +911,7 @@ class _$TextElementCopyWithImpl<$Res> implements $TextElementCopyWith<$Res> {
|
||||
styleSheet: freezed == styleSheet
|
||||
? _self.styleSheet
|
||||
: styleSheet // ignore: cast_nullable_to_non_nullable
|
||||
as TextStyleSheet?,
|
||||
as NamedItem<TextStyleSheet>?,
|
||||
area: null == area
|
||||
? _self.area
|
||||
: area // ignore: cast_nullable_to_non_nullable
|
||||
@ -935,12 +935,12 @@ class _$TextElementCopyWithImpl<$Res> implements $TextElementCopyWith<$Res> {
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet {
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet {
|
||||
if (_self.styleSheet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TextStyleSheetCopyWith<$Res>(_self.styleSheet!, (value) {
|
||||
return $NamedItemCopyWith<TextStyleSheet, $Res>(_self.styleSheet!, (value) {
|
||||
return _then(_self.copyWith(styleSheet: value));
|
||||
});
|
||||
}
|
||||
@ -1002,7 +1002,7 @@ class MarkdownElement extends PadElement with LabelElement {
|
||||
final Point<double> position;
|
||||
@JsonKey()
|
||||
final double scale;
|
||||
final TextStyleSheet? styleSheet;
|
||||
final NamedItem<TextStyleSheet>? styleSheet;
|
||||
@JsonKey()
|
||||
final AreaProperty areaProperty;
|
||||
final String text;
|
||||
@ -1058,14 +1058,14 @@ abstract mixin class $MarkdownElementCopyWith<$Res>
|
||||
@IdJsonConverter() String? id,
|
||||
@DoublePointJsonConverter() Point<double> position,
|
||||
double scale,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
AreaProperty areaProperty,
|
||||
String text,
|
||||
ElementConstraint constraint,
|
||||
@ColorJsonConverter() SRGBColor foreground,
|
||||
Map<String, dynamic> extra});
|
||||
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet;
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet;
|
||||
$AreaPropertyCopyWith<$Res> get areaProperty;
|
||||
$ElementConstraintCopyWith<$Res> get constraint;
|
||||
}
|
||||
@ -1119,7 +1119,7 @@ class _$MarkdownElementCopyWithImpl<$Res>
|
||||
styleSheet: freezed == styleSheet
|
||||
? _self.styleSheet
|
||||
: styleSheet // ignore: cast_nullable_to_non_nullable
|
||||
as TextStyleSheet?,
|
||||
as NamedItem<TextStyleSheet>?,
|
||||
areaProperty: null == areaProperty
|
||||
? _self.areaProperty
|
||||
: areaProperty // ignore: cast_nullable_to_non_nullable
|
||||
@ -1147,12 +1147,12 @@ class _$MarkdownElementCopyWithImpl<$Res>
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet {
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet {
|
||||
if (_self.styleSheet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TextStyleSheetCopyWith<$Res>(_self.styleSheet!, (value) {
|
||||
return $NamedItemCopyWith<TextStyleSheet, $Res>(_self.styleSheet!, (value) {
|
||||
return _then(_self.copyWith(styleSheet: value));
|
||||
});
|
||||
}
|
||||
|
@ -111,8 +111,10 @@ TextElement _$TextElementFromJson(Map json) => TextElement(
|
||||
scale: (json['scale'] as num?)?.toDouble() ?? 1.0,
|
||||
styleSheet: json['styleSheet'] == null
|
||||
? null
|
||||
: TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map)),
|
||||
: NamedItem<TextStyleSheet>.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map),
|
||||
(value) => TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(value as Map))),
|
||||
area: TextArea.fromJson(Map<String, dynamic>.from(json['area'] as Map)),
|
||||
constraint: json['constraint'] == null
|
||||
? const ElementConstraint(size: 1000)
|
||||
@ -136,7 +138,9 @@ Map<String, dynamic> _$TextElementToJson(TextElement instance) =>
|
||||
'id': const IdJsonConverter().toJson(instance.id),
|
||||
'position': const DoublePointJsonConverter().toJson(instance.position),
|
||||
'scale': instance.scale,
|
||||
'styleSheet': instance.styleSheet?.toJson(),
|
||||
'styleSheet': instance.styleSheet?.toJson(
|
||||
(value) => value.toJson(),
|
||||
),
|
||||
'area': instance.area.toJson(),
|
||||
'constraint': instance.constraint.toJson(),
|
||||
'foreground': const ColorJsonConverter().toJson(instance.foreground),
|
||||
@ -154,8 +158,10 @@ MarkdownElement _$MarkdownElementFromJson(Map json) => MarkdownElement(
|
||||
scale: (json['scale'] as num?)?.toDouble() ?? 1.0,
|
||||
styleSheet: json['styleSheet'] == null
|
||||
? null
|
||||
: TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map)),
|
||||
: NamedItem<TextStyleSheet>.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map),
|
||||
(value) => TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(value as Map))),
|
||||
areaProperty: json['areaProperty'] == null
|
||||
? const AreaProperty()
|
||||
: AreaProperty.fromJson(
|
||||
@ -183,7 +189,9 @@ Map<String, dynamic> _$MarkdownElementToJson(MarkdownElement instance) =>
|
||||
'id': const IdJsonConverter().toJson(instance.id),
|
||||
'position': const DoublePointJsonConverter().toJson(instance.position),
|
||||
'scale': instance.scale,
|
||||
'styleSheet': instance.styleSheet?.toJson(),
|
||||
'styleSheet': instance.styleSheet?.toJson(
|
||||
(value) => value.toJson(),
|
||||
),
|
||||
'areaProperty': instance.areaProperty.toJson(),
|
||||
'text': instance.text,
|
||||
'constraint': instance.constraint.toJson(),
|
||||
|
@ -115,4 +115,6 @@ final class PackItem<T extends PackAsset> implements PackAssetLocation {
|
||||
String get namespace => location.namespace;
|
||||
@override
|
||||
String get key => location.key;
|
||||
|
||||
NamedItem<T> toNamed() => NamedItem(name: key, item: item);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ sealed class Tool with _$Tool {
|
||||
@Default(LabelMode.text) LabelMode mode,
|
||||
@Default(false) bool zoomDependent,
|
||||
@Default(SRGBColor.black) @ColorJsonConverter() SRGBColor foreground,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
@Default(2.0) double scale,
|
||||
}) = LabelTool;
|
||||
|
||||
|
@ -588,7 +588,7 @@ class LabelTool extends Tool {
|
||||
@JsonKey()
|
||||
@ColorJsonConverter()
|
||||
final SRGBColor foreground;
|
||||
final TextStyleSheet? styleSheet;
|
||||
final NamedItem<TextStyleSheet>? styleSheet;
|
||||
@JsonKey()
|
||||
final double scale;
|
||||
|
||||
@ -628,10 +628,10 @@ abstract mixin class $LabelToolCopyWith<$Res> implements $ToolCopyWith<$Res> {
|
||||
LabelMode mode,
|
||||
bool zoomDependent,
|
||||
@ColorJsonConverter() SRGBColor foreground,
|
||||
TextStyleSheet? styleSheet,
|
||||
NamedItem<TextStyleSheet>? styleSheet,
|
||||
double scale});
|
||||
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet;
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -678,7 +678,7 @@ class _$LabelToolCopyWithImpl<$Res> implements $LabelToolCopyWith<$Res> {
|
||||
styleSheet: freezed == styleSheet
|
||||
? _self.styleSheet
|
||||
: styleSheet // ignore: cast_nullable_to_non_nullable
|
||||
as TextStyleSheet?,
|
||||
as NamedItem<TextStyleSheet>?,
|
||||
scale: null == scale
|
||||
? _self.scale
|
||||
: scale // ignore: cast_nullable_to_non_nullable
|
||||
@ -690,12 +690,12 @@ class _$LabelToolCopyWithImpl<$Res> implements $LabelToolCopyWith<$Res> {
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TextStyleSheetCopyWith<$Res>? get styleSheet {
|
||||
$NamedItemCopyWith<TextStyleSheet, $Res>? get styleSheet {
|
||||
if (_self.styleSheet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TextStyleSheetCopyWith<$Res>(_self.styleSheet!, (value) {
|
||||
return $NamedItemCopyWith<TextStyleSheet, $Res>(_self.styleSheet!, (value) {
|
||||
return _then(_self.copyWith(styleSheet: value));
|
||||
});
|
||||
}
|
||||
|
@ -96,8 +96,10 @@ LabelTool _$LabelToolFromJson(Map json) => LabelTool(
|
||||
.fromJson((json['foreground'] as num).toInt()),
|
||||
styleSheet: json['styleSheet'] == null
|
||||
? null
|
||||
: TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map)),
|
||||
: NamedItem<TextStyleSheet>.fromJson(
|
||||
Map<String, dynamic>.from(json['styleSheet'] as Map),
|
||||
(value) => TextStyleSheet.fromJson(
|
||||
Map<String, dynamic>.from(value as Map))),
|
||||
scale: (json['scale'] as num?)?.toDouble() ?? 2.0,
|
||||
$type: json['type'] as String?,
|
||||
);
|
||||
@ -108,7 +110,9 @@ Map<String, dynamic> _$LabelToolToJson(LabelTool instance) => <String, dynamic>{
|
||||
'mode': _$LabelModeEnumMap[instance.mode]!,
|
||||
'zoomDependent': instance.zoomDependent,
|
||||
'foreground': const ColorJsonConverter().toJson(instance.foreground),
|
||||
'styleSheet': instance.styleSheet?.toJson(),
|
||||
'styleSheet': instance.styleSheet?.toJson(
|
||||
(value) => value.toJson(),
|
||||
),
|
||||
'scale': instance.scale,
|
||||
'type': instance.$type,
|
||||
};
|
||||
|
Reference in New Issue
Block a user