Skip to content

Commit 58cf396

Browse files
Merge branch 'main' into css-background-image-13349251552222955557
2 parents 4ac45cf + f1e160a commit 58cf396

23 files changed

Lines changed: 2463 additions & 0 deletions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import 'css_value.dart';
2+
3+
/// CSS background-attachment property values.
4+
sealed class CssBackgroundAttachment implements CssValue {
5+
const CssBackgroundAttachment._();
6+
7+
// Keyword values
8+
static const CssBackgroundAttachment scroll = _CssBackgroundAttachmentKeyword(
9+
'scroll',
10+
);
11+
static const CssBackgroundAttachment fixed = _CssBackgroundAttachmentKeyword(
12+
'fixed',
13+
);
14+
static const CssBackgroundAttachment local = _CssBackgroundAttachmentKeyword(
15+
'local',
16+
);
17+
18+
/// Multiple background attachments.
19+
factory CssBackgroundAttachment.multiple(
20+
List<CssBackgroundAttachment> attachments,
21+
) = _CssBackgroundAttachmentMultiple;
22+
23+
/// CSS variable reference.
24+
factory CssBackgroundAttachment.variable(String varName) =
25+
_CssBackgroundAttachmentVariable;
26+
27+
/// Raw CSS value escape hatch.
28+
factory CssBackgroundAttachment.raw(String value) =
29+
_CssBackgroundAttachmentRaw;
30+
31+
/// Global keyword (inherit, initial, unset, revert).
32+
factory CssBackgroundAttachment.global(CssGlobal global) =
33+
_CssBackgroundAttachmentGlobal;
34+
}
35+
36+
final class _CssBackgroundAttachmentKeyword extends CssBackgroundAttachment {
37+
final String keyword;
38+
const _CssBackgroundAttachmentKeyword(this.keyword) : super._();
39+
40+
@override
41+
String toCss() => keyword;
42+
}
43+
44+
final class _CssBackgroundAttachmentMultiple extends CssBackgroundAttachment {
45+
final List<CssBackgroundAttachment> attachments;
46+
const _CssBackgroundAttachmentMultiple(this.attachments) : super._();
47+
48+
@override
49+
String toCss() => attachments.map((a) => a.toCss()).join(', ');
50+
}
51+
52+
final class _CssBackgroundAttachmentVariable extends CssBackgroundAttachment {
53+
final String varName;
54+
const _CssBackgroundAttachmentVariable(this.varName) : super._();
55+
56+
@override
57+
String toCss() => 'var(--$varName)';
58+
}
59+
60+
final class _CssBackgroundAttachmentRaw extends CssBackgroundAttachment {
61+
final String value;
62+
const _CssBackgroundAttachmentRaw(this.value) : super._();
63+
64+
@override
65+
String toCss() => value;
66+
}
67+
68+
final class _CssBackgroundAttachmentGlobal extends CssBackgroundAttachment {
69+
final CssGlobal global;
70+
const _CssBackgroundAttachmentGlobal(this.global) : super._();
71+
72+
@override
73+
String toCss() => global.toCss();
74+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import 'css_value.dart';
2+
3+
/// CSS background-clip property values.
4+
sealed class CssBackgroundClip implements CssValue {
5+
const CssBackgroundClip._();
6+
7+
/// The background extends to the outside edge of the border.
8+
static const CssBackgroundClip borderBox = _CssBackgroundClipKeyword(
9+
'border-box',
10+
);
11+
12+
/// The background extends to the outside edge of the padding.
13+
static const CssBackgroundClip paddingBox = _CssBackgroundClipKeyword(
14+
'padding-box',
15+
);
16+
17+
/// The background extends to the outside edge of the content.
18+
static const CssBackgroundClip contentBox = _CssBackgroundClipKeyword(
19+
'content-box',
20+
);
21+
22+
/// The background is clipped to the foreground text.
23+
static const CssBackgroundClip text = _CssBackgroundClipKeyword('text');
24+
25+
/// Multiple background-clip values for multiple background images.
26+
factory CssBackgroundClip.multiple(List<CssBackgroundClip> values) =
27+
_CssBackgroundClipMultiple;
28+
29+
/// CSS variable reference.
30+
factory CssBackgroundClip.variable(String varName) =
31+
_CssBackgroundClipVariable;
32+
33+
/// Raw CSS value escape hatch.
34+
factory CssBackgroundClip.raw(String value) = _CssBackgroundClipRaw;
35+
36+
/// Global keyword (inherit, initial, unset, revert).
37+
factory CssBackgroundClip.global(CssGlobal global) = _CssBackgroundClipGlobal;
38+
}
39+
40+
final class _CssBackgroundClipKeyword extends CssBackgroundClip {
41+
final String keyword;
42+
const _CssBackgroundClipKeyword(this.keyword) : super._();
43+
44+
@override
45+
String toCss() => keyword;
46+
}
47+
48+
final class _CssBackgroundClipMultiple extends CssBackgroundClip {
49+
final List<CssBackgroundClip> values;
50+
const _CssBackgroundClipMultiple(this.values) : super._();
51+
52+
@override
53+
String toCss() => values.map((e) => e.toCss()).join(', ');
54+
}
55+
56+
final class _CssBackgroundClipVariable extends CssBackgroundClip {
57+
final String varName;
58+
const _CssBackgroundClipVariable(this.varName) : super._();
59+
60+
@override
61+
String toCss() => 'var(--$varName)';
62+
}
63+
64+
final class _CssBackgroundClipRaw extends CssBackgroundClip {
65+
final String value;
66+
const _CssBackgroundClipRaw(this.value) : super._();
67+
68+
@override
69+
String toCss() => value;
70+
}
71+
72+
final class _CssBackgroundClipGlobal extends CssBackgroundClip {
73+
final CssGlobal global;
74+
const _CssBackgroundClipGlobal(this.global) : super._();
75+
76+
@override
77+
String toCss() => global.toCss();
78+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'css_value.dart';
2+
3+
/// CSS background-repeat property values.
4+
sealed class CssBackgroundRepeat implements CssValue {
5+
const CssBackgroundRepeat._();
6+
7+
// Keyword values
8+
static const CssBackgroundRepeat repeat = _CssBackgroundRepeatKeyword(
9+
'repeat',
10+
);
11+
static const CssBackgroundRepeat repeatX = _CssBackgroundRepeatKeyword(
12+
'repeat-x',
13+
);
14+
static const CssBackgroundRepeat repeatY = _CssBackgroundRepeatKeyword(
15+
'repeat-y',
16+
);
17+
static const CssBackgroundRepeat space = _CssBackgroundRepeatKeyword('space');
18+
static const CssBackgroundRepeat round = _CssBackgroundRepeatKeyword('round');
19+
static const CssBackgroundRepeat noRepeat = _CssBackgroundRepeatKeyword(
20+
'no-repeat',
21+
);
22+
23+
/// Creates a two-value syntax background-repeat (e.g. `repeat space`).
24+
factory CssBackgroundRepeat.xy(CssBackgroundRepeat x, CssBackgroundRepeat y) =
25+
_CssBackgroundRepeatTwoValue;
26+
27+
/// Creates a comma-separated list of background-repeat values for multiple background images.
28+
factory CssBackgroundRepeat.multiple(List<CssBackgroundRepeat> repeats) =
29+
_CssBackgroundRepeatMultiple;
30+
31+
/// CSS variable reference.
32+
factory CssBackgroundRepeat.variable(String varName) =
33+
_CssBackgroundRepeatVariable;
34+
35+
/// Raw CSS value escape hatch.
36+
factory CssBackgroundRepeat.raw(String value) = _CssBackgroundRepeatRaw;
37+
38+
/// Global keyword (inherit, initial, unset, revert).
39+
factory CssBackgroundRepeat.global(CssGlobal global) =
40+
_CssBackgroundRepeatGlobal;
41+
}
42+
43+
final class _CssBackgroundRepeatKeyword extends CssBackgroundRepeat {
44+
final String keyword;
45+
const _CssBackgroundRepeatKeyword(this.keyword) : super._();
46+
47+
@override
48+
String toCss() => keyword;
49+
}
50+
51+
final class _CssBackgroundRepeatTwoValue extends CssBackgroundRepeat {
52+
final CssBackgroundRepeat x;
53+
final CssBackgroundRepeat y;
54+
const _CssBackgroundRepeatTwoValue(this.x, this.y) : super._();
55+
56+
@override
57+
String toCss() => '${x.toCss()} ${y.toCss()}';
58+
}
59+
60+
final class _CssBackgroundRepeatMultiple extends CssBackgroundRepeat {
61+
final List<CssBackgroundRepeat> repeats;
62+
const _CssBackgroundRepeatMultiple(this.repeats) : super._();
63+
64+
@override
65+
String toCss() => repeats.map((r) => r.toCss()).join(', ');
66+
}
67+
68+
final class _CssBackgroundRepeatVariable extends CssBackgroundRepeat {
69+
final String varName;
70+
const _CssBackgroundRepeatVariable(this.varName) : super._();
71+
72+
@override
73+
String toCss() => 'var(--$varName)';
74+
}
75+
76+
final class _CssBackgroundRepeatRaw extends CssBackgroundRepeat {
77+
final String value;
78+
const _CssBackgroundRepeatRaw(this.value) : super._();
79+
80+
@override
81+
String toCss() => value;
82+
}
83+
84+
final class _CssBackgroundRepeatGlobal extends CssBackgroundRepeat {
85+
final CssGlobal global;
86+
const _CssBackgroundRepeatGlobal(this.global) : super._();
87+
88+
@override
89+
String toCss() => global.toCss();
90+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'css_length.dart';
2+
import 'css_value.dart';
3+
4+
/// CSS background-size property values.
5+
sealed class CssBackgroundSize implements CssValue {
6+
const CssBackgroundSize._();
7+
8+
/// Scales the image as large as possible without stretching the image.
9+
/// If the container is larger than the image, this will result in image tiling, unless the background-repeat property is set to no-repeat.
10+
static const CssBackgroundSize cover = _CssBackgroundSizeKeyword('cover');
11+
12+
/// Scales the image to the largest size such that both its width and its height can fit inside the content area.
13+
static const CssBackgroundSize contain = _CssBackgroundSizeKeyword('contain');
14+
15+
/// The `auto` keyword which scales the background image in the corresponding direction such that its intrinsic proportion is maintained.
16+
static const CssBackgroundSize auto = _CssBackgroundSizeKeyword('auto');
17+
18+
/// Creates a background size with width and optional height.
19+
/// If height is omitted, it defaults to auto.
20+
factory CssBackgroundSize.size(CssLength width, [CssLength? height]) =
21+
_CssBackgroundSizeDimensions;
22+
23+
/// Creates a background size with multiple values (comma-separated).
24+
factory CssBackgroundSize.multiple(List<CssBackgroundSize> sizes) =
25+
_CssBackgroundSizeMultiple;
26+
27+
/// CSS variable reference.
28+
factory CssBackgroundSize.variable(String varName) =
29+
_CssBackgroundSizeVariable;
30+
31+
/// Raw CSS value escape hatch.
32+
factory CssBackgroundSize.raw(String value) = _CssBackgroundSizeRaw;
33+
34+
/// Global keyword (inherit, initial, unset, revert).
35+
factory CssBackgroundSize.global(CssGlobal global) = _CssBackgroundSizeGlobal;
36+
}
37+
38+
final class _CssBackgroundSizeKeyword extends CssBackgroundSize {
39+
final String keyword;
40+
const _CssBackgroundSizeKeyword(this.keyword) : super._();
41+
42+
@override
43+
String toCss() => keyword;
44+
}
45+
46+
final class _CssBackgroundSizeDimensions extends CssBackgroundSize {
47+
final CssLength width;
48+
final CssLength? height;
49+
const _CssBackgroundSizeDimensions(this.width, [this.height]) : super._();
50+
51+
@override
52+
String toCss() {
53+
if (height != null) {
54+
return '${width.toCss()} ${height!.toCss()}';
55+
}
56+
return width.toCss();
57+
}
58+
}
59+
60+
final class _CssBackgroundSizeMultiple extends CssBackgroundSize {
61+
final List<CssBackgroundSize> sizes;
62+
const _CssBackgroundSizeMultiple(this.sizes) : super._();
63+
64+
@override
65+
String toCss() => sizes.map((s) => s.toCss()).join(', ');
66+
}
67+
68+
final class _CssBackgroundSizeVariable extends CssBackgroundSize {
69+
final String varName;
70+
const _CssBackgroundSizeVariable(this.varName) : super._();
71+
72+
@override
73+
String toCss() => 'var(--$varName)';
74+
}
75+
76+
final class _CssBackgroundSizeRaw extends CssBackgroundSize {
77+
final String value;
78+
const _CssBackgroundSizeRaw(this.value) : super._();
79+
80+
@override
81+
String toCss() => value;
82+
}
83+
84+
final class _CssBackgroundSizeGlobal extends CssBackgroundSize {
85+
final CssGlobal global;
86+
const _CssBackgroundSizeGlobal(this.global) : super._();
87+
88+
@override
89+
String toCss() => global.toCss();
90+
}

0 commit comments

Comments
 (0)