@@ -1008,6 +1008,44 @@ <h3 class="subtema" id="media-queries">Media queries</h3>
10081008// would be the same one
10091009</ code > </ pre >
10101010</ div >
1011+ < div class ="tema " id ="supports ">
1012+ < h2 > < code > @supports</ code > rules</ h2 >
1013+ < p > It is possible to use the object model to access the < code > @supports</ code > conditions, which work in a similar way to Media Queries (but with < a class ="codeitem "
1014+ href ="api/latest/io.sf.carte.css4j/io/sf/carte/doc/style/css/nsac/DeclarationCondition.html "> DeclarationCondition</ a >
1015+ instead of < a class ="codeitem " href ="api/latest/io.sf.carte.css4j/io/sf/carte/doc/style/css/MediaQueryPredicate.html "> MediaQueryPredicate</ a >
1016+ objects as predicates.</ p >
1017+ < p > For example:</ p >
1018+ < pre class ="code "> < code class ="language-java "> // Instantiate a css factory (we could also obtain it from a
1019+ // pre-existing css4j object)
1020+ AbstractCSSStyleSheetFactory cssFactory = new CSSDOMImplementation();
1021+
1022+ // Create a style sheet
1023+ AbstractCSSStyleSheet sheet = cssFactory.createStyleSheet(null, null);
1024+ // Create a @supports rule
1025+ SupportsRule supports = sheet.createSupportsRule("(display: flex)");
1026+
1027+ // Get the condition
1028+ BooleanCondition cond = supports.getCondition();
1029+
1030+ // Get the condition type
1031+ BooleanCondition.Type condType = cond.getType();
1032+ // It is a BooleanCondition.Type.PREDICATE
1033+
1034+ // So we cast it to DeclarationCondition
1035+ DeclarationCondition dCond = (DeclarationCondition) cond;
1036+ String predName = dCond.getName();
1037+ // It is "display"
1038+
1039+ // Now obtain the value
1040+ LexicalUnit value = dCond.getValue();
1041+ LexicalUnit.LexicalType luType = value.getLexicalUnitType();
1042+ // It is a IDENT
1043+
1044+ // Get the string value
1045+ String condValue = value.getStringValue();
1046+ // It is "flex"
1047+ </ code > </ pre >
1048+ </ div >
10111049< div class ="tema " id ="sheetsets ">
10121050< h2 > Style sheet sets</ h2 >
10131051< p > The library supports alternative style sheets: see CSSDocument's methods
0 commit comments