Skip to content

Commit 9634d44

Browse files
committed
Compile logical properties
1 parent 9f93ab0 commit 9634d44

36 files changed

+870
-164
lines changed

build-prefixes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ let mdnFeatures = {
195195
placeItems: mdn.css.properties['place-items'].__compat.support,
196196
overflowShorthand: mdn.css.properties['overflow'].multiple_keywords.__compat.support,
197197
mediaRangeSyntax: mdn.css['at-rules'].media.range_syntax.__compat.support,
198-
mediaIntervalSyntax: {} // currently no browsers
198+
mediaIntervalSyntax: {}, // currently no browsers
199+
logicalBorders: mdn.css.properties['border-inline-start'].__compat.support
199200
};
200201

201202
for (let feature in mdnFeatures) {

src/compat.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum Feature {
3232
DoublePositionGradients,
3333
FormValidation,
3434
Fullscreen,
35+
LogicalBorders,
3536
MediaIntervalSyntax,
3637
MediaRangeSyntax,
3738
OverflowShorthand,
@@ -1287,6 +1288,48 @@ impl Feature {
12871288
}
12881289
}
12891290
}
1291+
Feature::LogicalBorders => {
1292+
if let Some(version) = browsers.chrome {
1293+
if version >= 4521984 {
1294+
return true
1295+
}
1296+
}
1297+
if let Some(version) = browsers.edge {
1298+
if version >= 5177344 {
1299+
return true
1300+
}
1301+
}
1302+
if let Some(version) = browsers.firefox {
1303+
if version >= 2686976 {
1304+
return true
1305+
}
1306+
}
1307+
if let Some(version) = browsers.opera {
1308+
if version >= 3145728 {
1309+
return true
1310+
}
1311+
}
1312+
if let Some(version) = browsers.safari {
1313+
if version >= 786688 {
1314+
return true
1315+
}
1316+
}
1317+
if let Some(version) = browsers.ios_saf {
1318+
if version >= 786944 {
1319+
return true
1320+
}
1321+
}
1322+
if let Some(version) = browsers.samsung {
1323+
if version >= 655360 {
1324+
return true
1325+
}
1326+
}
1327+
if let Some(version) = browsers.android {
1328+
if version >= 4521984 {
1329+
return true
1330+
}
1331+
}
1332+
}
12901333
}
12911334
false
12921335
}

src/declaration.rs

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::properties::{
2424
use crate::targets::Browsers;
2525
use crate::parser::ParserOptions;
2626
use crate::error::{ParserError, PrinterError};
27+
use crate::logical::LogicalProperties;
2728

2829
#[derive(Debug, PartialEq)]
2930
pub struct DeclarationBlock {
@@ -67,20 +68,25 @@ impl ToCss for DeclarationBlock {
6768
}
6869

6970
impl DeclarationBlock {
70-
pub(crate) fn minify(&mut self, handler: &mut DeclarationHandler, important_handler: &mut DeclarationHandler) {
71+
pub(crate) fn minify(
72+
&mut self,
73+
handler: &mut DeclarationHandler,
74+
important_handler: &mut DeclarationHandler,
75+
logical_properties: &mut LogicalProperties
76+
) {
7177
let mut decls: Vec<Declaration> = vec![];
7278
for decl in self.declarations.iter() {
7379
let handled =
74-
(decl.important && important_handler.handle_property(decl)) ||
75-
(!decl.important && handler.handle_property(decl));
80+
(decl.important && important_handler.handle_property(decl, logical_properties)) ||
81+
(!decl.important && handler.handle_property(decl, logical_properties));
7682

7783
if !handled {
7884
decls.push(decl.clone());
7985
}
8086
}
8187

82-
decls.extend(handler.finalize());
83-
decls.extend(important_handler.finalize());
88+
decls.extend(handler.finalize(logical_properties));
89+
decls.extend(important_handler.finalize(logical_properties));
8490
self.declarations = decls;
8591
}
8692
}
@@ -157,7 +163,6 @@ impl DeclarationList {
157163
}
158164
}
159165

160-
#[derive(Default)]
161166
pub(crate) struct DeclarationHandler {
162167
background: BackgroundHandler,
163168
border: BorderHandler,
@@ -188,68 +193,76 @@ impl DeclarationHandler {
188193
DeclarationHandler {
189194
background: BackgroundHandler::new(targets),
190195
border: BorderHandler::new(targets),
196+
outline: OutlineHandler::default(),
191197
flex: FlexHandler::new(targets),
198+
grid: GridHandler::default(),
192199
align: AlignHandler::new(targets),
200+
margin: MarginHandler::default(),
201+
padding: PaddingHandler::default(),
202+
scroll_margin: ScrollMarginHandler::default(),
203+
scroll_padding: ScrollPaddingHandler::default(),
204+
font: FontHandler::default(),
205+
text: TextDecorationHandler::new(targets),
206+
list: ListStyleHandler::default(),
193207
transition: TransitionHandler::new(targets),
194208
animation: AnimationHandler::new(targets),
195209
display: DisplayHandler::new(targets),
196210
position: PositionHandler::new(targets),
211+
inset: InsetHandler::default(),
197212
overflow: OverflowHandler::new(targets),
198213
transform: TransformHandler::new(targets),
199-
text: TextDecorationHandler::new(targets),
200214
prefix: PrefixHandler::new(targets),
201-
decls: DeclarationList::new(important),
202-
..DeclarationHandler::default()
215+
decls: DeclarationList::new(important)
203216
}
204217
}
205218

206-
pub fn handle_property(&mut self, decl: &Declaration) -> bool {
219+
pub fn handle_property(&mut self, decl: &Declaration, logical_properties: &mut LogicalProperties) -> bool {
207220
let property = &decl.property;
208-
self.background.handle_property(property, &mut self.decls) ||
209-
self.border.handle_property(property, &mut self.decls) ||
210-
self.outline.handle_property(property, &mut self.decls) ||
211-
self.flex.handle_property(property, &mut self.decls) ||
212-
self.grid.handle_property(property, &mut self.decls) ||
213-
self.align.handle_property(property, &mut self.decls) ||
214-
self.margin.handle_property(property, &mut self.decls) ||
215-
self.padding.handle_property(property, &mut self.decls) ||
216-
self.scroll_margin.handle_property(property, &mut self.decls) ||
217-
self.scroll_padding.handle_property(property, &mut self.decls) ||
218-
self.font.handle_property(property, &mut self.decls) ||
219-
self.text.handle_property(property, &mut self.decls) ||
220-
self.list.handle_property(property, &mut self.decls) ||
221-
self.transition.handle_property(property, &mut self.decls) ||
222-
self.animation.handle_property(property, &mut self.decls) ||
223-
self.display.handle_property(property, &mut self.decls) ||
224-
self.position.handle_property(property, &mut self.decls) ||
225-
self.inset.handle_property(property, &mut self.decls) ||
226-
self.overflow.handle_property(property, &mut self.decls) ||
227-
self.transform.handle_property(property, &mut self.decls) ||
228-
self.prefix.handle_property(property, &mut self.decls)
221+
self.background.handle_property(property, &mut self.decls, logical_properties) ||
222+
self.border.handle_property(property, &mut self.decls, logical_properties) ||
223+
self.outline.handle_property(property, &mut self.decls, logical_properties) ||
224+
self.flex.handle_property(property, &mut self.decls, logical_properties) ||
225+
self.grid.handle_property(property, &mut self.decls, logical_properties) ||
226+
self.align.handle_property(property, &mut self.decls, logical_properties) ||
227+
self.margin.handle_property(property, &mut self.decls, logical_properties) ||
228+
self.padding.handle_property(property, &mut self.decls, logical_properties) ||
229+
self.scroll_margin.handle_property(property, &mut self.decls, logical_properties) ||
230+
self.scroll_padding.handle_property(property, &mut self.decls, logical_properties) ||
231+
self.font.handle_property(property, &mut self.decls, logical_properties) ||
232+
self.text.handle_property(property, &mut self.decls, logical_properties) ||
233+
self.list.handle_property(property, &mut self.decls, logical_properties) ||
234+
self.transition.handle_property(property, &mut self.decls, logical_properties) ||
235+
self.animation.handle_property(property, &mut self.decls, logical_properties) ||
236+
self.display.handle_property(property, &mut self.decls, logical_properties) ||
237+
self.position.handle_property(property, &mut self.decls, logical_properties) ||
238+
self.inset.handle_property(property, &mut self.decls, logical_properties) ||
239+
self.overflow.handle_property(property, &mut self.decls, logical_properties) ||
240+
self.transform.handle_property(property, &mut self.decls, logical_properties) ||
241+
self.prefix.handle_property(property, &mut self.decls, logical_properties)
229242
}
230243

231-
pub fn finalize(&mut self) -> Vec<Declaration> {
232-
self.background.finalize(&mut self.decls);
233-
self.border.finalize(&mut self.decls);
234-
self.outline.finalize(&mut self.decls);
235-
self.flex.finalize(&mut self.decls);
236-
self.grid.finalize(&mut self.decls);
237-
self.align.finalize(&mut self.decls);
238-
self.margin.finalize(&mut self.decls);
239-
self.padding.finalize(&mut self.decls);
240-
self.scroll_margin.finalize(&mut self.decls);
241-
self.scroll_padding.finalize(&mut self.decls);
242-
self.font.finalize(&mut self.decls);
243-
self.text.finalize(&mut self.decls);
244-
self.list.finalize(&mut self.decls);
245-
self.transition.finalize(&mut self.decls);
246-
self.animation.finalize(&mut self.decls);
247-
self.display.finalize(&mut self.decls);
248-
self.position.finalize(&mut self.decls);
249-
self.inset.finalize(&mut self.decls);
250-
self.overflow.finalize(&mut self.decls);
251-
self.transform.finalize(&mut self.decls);
252-
self.prefix.finalize(&mut self.decls);
244+
pub fn finalize(&mut self, logical_properties: &mut LogicalProperties) -> Vec<Declaration> {
245+
self.background.finalize(&mut self.decls, logical_properties);
246+
self.border.finalize(&mut self.decls, logical_properties);
247+
self.outline.finalize(&mut self.decls, logical_properties);
248+
self.flex.finalize(&mut self.decls, logical_properties);
249+
self.grid.finalize(&mut self.decls, logical_properties);
250+
self.align.finalize(&mut self.decls, logical_properties);
251+
self.margin.finalize(&mut self.decls, logical_properties);
252+
self.padding.finalize(&mut self.decls, logical_properties);
253+
self.scroll_margin.finalize(&mut self.decls, logical_properties);
254+
self.scroll_padding.finalize(&mut self.decls, logical_properties);
255+
self.font.finalize(&mut self.decls, logical_properties);
256+
self.text.finalize(&mut self.decls, logical_properties);
257+
self.list.finalize(&mut self.decls, logical_properties);
258+
self.transition.finalize(&mut self.decls, logical_properties);
259+
self.animation.finalize(&mut self.decls, logical_properties);
260+
self.display.finalize(&mut self.decls, logical_properties);
261+
self.position.finalize(&mut self.decls, logical_properties);
262+
self.inset.finalize(&mut self.decls, logical_properties);
263+
self.overflow.finalize(&mut self.decls, logical_properties);
264+
self.transform.finalize(&mut self.decls, logical_properties);
265+
self.prefix.finalize(&mut self.decls, logical_properties);
253266
std::mem::take(&mut self.decls.declarations)
254267
}
255268
}

0 commit comments

Comments
 (0)