1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889(** CSS tree difference analysis for structural comparison. *)openCascadeincludeTree_diff_intfletis_emptyd=d.rules=[]&&d.containers=[]&&Option.is_noned.layer_orderletreorder_is_significant=Tree_diff_rules.reorder_is_significantletpp=Tree_diff_render.ppletpp_rule_diff_simple=Tree_diff_render.pp_rule_diff_simple(** Query functions *)letsingle_rule_diff(diff:t)=matchdiff.ruleswith[rule]->Somerule|_->Noneletreccount_containers_in_listcontainer_typecontainers=List.fold_left(funcountcont->letthis_count=matchcontwith|Added{container_type=ct;_}|Removed{container_type=ct;_}|Reordered{info={container_type=ct;_};_}|Block_structure_changed{container_type=ct;_}->ifct=container_typethen1else0|Modified{info={container_type=ct;_};container_changes;_}->letnested_count=count_containers_in_listcontainer_typecontainer_changesin(ifct=container_typethen1else0)+nested_countincount+this_count)0containersletcount_containers_by_typecontainer_type(diff:t)=count_containers_in_list container_typediff.containers(* [Modified] holds the containers that came and went inside a container that
survived, so an existence query reads the same tree
[count_containers_in_list] counts: a flat [List.exists] would answer no about
a container the count reports, which is an answer about the shape of the diff
rather than about the stylesheets. *)letrecexists_containerherecontainers=List.exists(funcont->herecont||matchcontwith|Modified{container_changes;_}->exists_containerherecontainer_changes|Added_|Removed_|Reordered_|Block_structure_changed_->false)containerslethas_container_added_of_typecontainer_type(diff:t)=exists_container(function|Added{container_type=ct;_}->ct=container_type|Removed_|Modified_|Reordered_|Block_structure_changed_->false)diff.containerslethas_container_removed_of_typecontainer_type(diff:t)=exists_container(function|Removed{container_type=ct;_}->ct=container_type|Added_|Modified_|Reordered_|Block_structure_changed _->false)diff.containersopenTree_diff_rulesopenTree_diff_containersletdiff~(expected:Css.t)~(actual:Css.t):t=letall1=Css.statementsexpectedinletall2=Css.statementsactualin(* Imports are diffed separately ([process_imports]); excluding them here
keeps [rule_diffs] from matching every import on the universal key. *)letrules1=List.filter(funs->Css.as_imports=None)all1inletrules2=List.filter(funs->Css.as_imports=None)all2in(* Same assembly as inside a container, so a difference reports the same way
at either depth. *)letrule_changes=to_rule_changesrules1rules2@process_importsall1all2in(* Delegate all container and nested-container diffs to the generic walker *)letcontainers=nested_differencesall1all2in{rules=rule_changes;containers;layer_order=layer_order_diffall1all2}