package cascade
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=3315f94068943b3655bf530c1d82b68655524ff3601efedfbaf0a7f886fbf5a1
sha512=0f187c8e17fcbddaa0ad2760930956451062e476b678e1e60daf6ad9e7414fad99a2d70534dfdf8bca0a1092e374d009051f06b0ce9da33f2742cdde0187e75c
doc/cascade.diff/Cascade_diff/Tree_diff/index.html
Module Cascade_diff.Tree_diffSource
CSS tree difference analysis for structural comparison.
Declaration diff information.
type rule_diff = | Added of {selector : string;declarations : Cascade.Css.declaration list;
}| Removed of {selector : string;declarations : Cascade.Css.declaration list;
}| Content_changed of {selector : string;old_declarations : Cascade.Css.declaration list;new_declarations : Cascade.Css.declaration list;property_changes : declaration list;added_properties : (string * string) list;removed_properties : (string * string) list;
}| Selector_changed of {old_selector : string;new_selector : string;declarations : Cascade.Css.declaration list;
}| Reordered of {selector : string;expected_pos : int;actual_pos : int;swapped_with : string option;(*When only declaration order changed inside the rule, positions may be irrelevant; in that case
*)old_declarations/new_declarationscarry the before/after declarations to allow detailed pretty-printing.old_declarations : Cascade.Css.declaration list option;new_declarations : Cascade.Css.declaration list option;
}| Rearranged of {selector : string;declarations : Cascade.Css.declaration list;
}(*Every declaration the selector carries survives on both sides, spread differently over the rules that write it. An element that also matches an overlapping selector can resolve differently, since which rule carries a declaration decides where it sits relative to the other selector's rules.
*)| Regrouped of {}(*A comma group merged or split across rules with identical declarations: the same selectors survive, only the grouping differs.
*)from_selectors/to_selectorsare the rule selectors in expected and actual.
Individual rule changes.
type container_info = {container_type : [ `Media | `Layer | `Supports | `Container | `Property | `Nesting | `At_rule ];condition : string;rules : Cascade.Css.statement list;
}Container rule information. `At_rule covers the at-rules that carry no selector and no condition of their own (@page, @font-face, @counter-style, @scope, @starting-style, ...); their condition is the at-rule text up to the block.
type container_diff = | Added of container_info| Removed of container_info| Modified of {info : container_info;actual_rules : Cascade.Css.statement list;rule_changes : rule_diff list;container_changes : container_diff list;
}| Reordered of {info : container_info;expected_pos : int;actual_pos : int;
}| Block_structure_changed of {container_type : [ `Media | `Layer | `Supports | `Container | `Property | `Nesting | `At_rule ];condition : string;expected_blocks : (int * Cascade.Css.statement list) list;(*(position, rules) for each block in expected
*)actual_blocks : (int * Cascade.Css.statement list) list;(*(position, rules) for each block in actual
*)
}
Container changes.
The cascade layer order the two sheets declare, when they declare it differently. Layers are named by the dotted paths of Cascade.Resolve.layer_order, weakest first, restricted to the layers both sheets declare: one side declaring a layer the other does not is reported as the @layer block that came or went, not as an order change.
swapped holds the pairs (weaker, stronger) that expected_order declares in that order and actual_order the other way round - the layers whose conflicts the two sheets resolve differently. It is never empty.
The order compared is the sheet's own, so a layer declared inside a conditional group rule, @starting-style, @scope or an origin wrapper is not part of it, as in Cascade.Resolve.layer_order.
type t = {rules : rule_diff list;containers : container_diff list;layer_order : layer_order_diff option;
}Structured CSS differences.
val reorder_is_significant :
Cascade.Css.declaration list ->
Cascade.Css.declaration list ->
boolreorder_is_significant d1 d2 is true when reordering the declarations changes the cascade, i.e. two overlapping declarations swap relative order. A reorder of disjoint declarations is no difference.
diff ~expected ~actual computes structural differences between two CSS ASTs.
val pp :
?expected:string ->
?actual:string ->
?color:bool ->
?depth:int ->
?entries:int ->
Buffer.t ->
t ->
unitpp ?expected ?actual ?color ?depth ?entries buf t pretty-prints a tree diff with optional labels. Default labels are "Expected" and "Actual". color (default false) wraps diff markers in ANSI escapes; the printer writes into a buffer, so the caller decides whether the destination supports colour.
depth bounds how many tree levels are rendered, the top-level entries being level 1 (default: unbounded). A node whose children are cut off is followed by a "... N more lines" marker, so the report never reads as if the elided subtree were empty.
entries bounds how many top-level entries the whole report renders (default: unbounded), the budget being spent in printing order: the cascade layer order, then the rules, then the reordered rules, then the containers. Each entry that is printed is printed whole, and the report ends with a "... N more differences" line counting the rest.
pp_rule_diff_simple buf rule pretty-prints a rule diff in a simple format suitable for tests.
Query functions
single_rule_diff diff returns Some rule if diff contains exactly one rule change, None otherwise.
val count_containers_by_type :
[ `At_rule
| `Container
| `Layer
| `Media
| `Nesting
| `Property
| `Supports ] ->
t ->
intcount_containers_by_type container_type diff counts the containers of the given type in diff, at its top level and inside every container it reports as modified.
val has_container_added_of_type :
[ `At_rule
| `Container
| `Layer
| `Media
| `Nesting
| `Property
| `Supports ] ->
t ->
boolhas_container_added_of_type container_type diff is whether diff reports a container of the given type as added, at its top level or inside a container it reports as modified. It answers about the same containers count_containers_by_type counts.
val has_container_removed_of_type :
[ `At_rule
| `Container
| `Layer
| `Media
| `Nesting
| `Property
| `Supports ] ->
t ->
boolhas_container_removed_of_type container_type diff is whether diff reports a container of the given type as removed, at its top level or inside a container it reports as modified. It answers about the same containers count_containers_by_type counts.