forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefix_handler.rs
More file actions
97 lines (88 loc) · 2.63 KB
/
prefix_handler.rs
File metadata and controls
97 lines (88 loc) · 2.63 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
#![allow(non_snake_case)]
use crate::targets::Browsers;
use crate::prefixes::Feature;
use super::Property;
use crate::vendor_prefix::VendorPrefix;
use crate::traits::{PropertyHandler};
use crate::declaration::DeclarationList;
macro_rules! define_prefixes {
(
$( $name: ident, )+
) => {
#[derive(Default)]
pub(crate) struct PrefixHandler {
targets: Option<Browsers>,
$(
$name: Option<usize>,
)+
}
impl PrefixHandler {
pub fn new(targets: Option<Browsers>) -> PrefixHandler {
PrefixHandler {
targets,
..PrefixHandler::default()
}
}
}
impl PropertyHandler for PrefixHandler {
fn handle_property(&mut self, property: &Property, dest: &mut DeclarationList) -> bool {
match property {
$(
Property::$name(val, prefix) => {
if let Some(i) = self.$name {
if let Some(decl) = dest.declarations.get_mut(i) {
if let Property::$name(cur, prefixes) = &mut decl.property {
// If the value is the same, update the prefix.
// If the prefix is the same, then update the value.
if val == cur || prefixes.contains(*prefix) {
*cur = val.clone();
*prefixes |= *prefix;
if prefixes.contains(VendorPrefix::None) {
if let Some(targets) = self.targets {
*prefixes = Feature::$name.prefixes_for(targets);
}
}
return true
}
}
}
}
// Update the prefixes based on the targets.
let prefixes = if prefix.contains(VendorPrefix::None) {
if let Some(targets) = self.targets {
Feature::$name.prefixes_for(targets)
} else {
*prefix
}
} else {
*prefix
};
// Store the index of the property, so we can update it later.
self.$name = Some(dest.declarations.len());
dest.push(Property::$name(val.clone(), prefixes))
}
)+
_ => return false
}
true
}
fn finalize(&mut self, _: &mut DeclarationList) {}
}
};
}
define_prefixes! {
TransformOrigin,
TransformStyle,
BackfaceVisibility,
Perspective,
PerspectiveOrigin,
BoxShadow,
BoxSizing,
TabSize,
Hyphens,
TextAlignLast,
TextDecorationSkipInk,
TextOverflow,
UserSelect,
Appearance,
}