import { MultiMap } from "@opticss/util" ; import * as cssPropertyParser from "css-property-parser" ; import { SELF_SELECTOR } from "../BlockSyntax" ; import { Style } from "../BlockTree" ; export type Conflict = [ string , string ] ; /**
 * Contains Sets of properties for any two `Style`s and their associated
 * pseudo elements that are in conflict with each other.
 */ export class Conflicts < T > { conflicts : MultiMap < string , T > = new MultiMap ( ) ; getConflictSet ( pseudo = SELF_SELECTOR ) { return new Set ( this . conflicts . get ( pseudo ) ) ; } } param props1 param props2 returns function detectPropertyConflicts ( props1 , props2 ) { let conflicts = new Set < [ string , string ] > ( ) ; for ( let prop of props1 ) { let shortHands = cssPropertyParser . getShorthandsForProperty ( prop ) ; for ( let shortHand of shortHands ) { if ( props2 . has ( prop ) ) { conflicts . add ( [ prop , shortHand ] ) ; } } if ( cssPropertyParser . isShorthandProperty ( prop ) ) { let longHands = cssPropertyParser . getShorthandComputedProperties ( prop , true ) ; for ( let longHand of longHands ) { if ( longHand === prop ) continue ; if ( props2 . has ( longHand ) ) { conflicts . add ( [ prop , longHand ] ) ; } } } } return conflicts ; } param obj1 param obj2 returns export function detectConflicts ( obj1 , obj2 ) { let conflicts = new Conflicts < Conflict > ( ) ; let otherPseudos = obj2 . rulesets . getPseudos ( ) ; for ( let pseudo of obj1 . rulesets . getPseudos ( ) ) { if ( ! otherPseudos . has ( pseudo ) ) { continue ; } conflicts . conflicts . set ( pseudo , ... detectPropertyConflicts ( obj1 . rulesets . getProperties ( pseudo ) , obj2 . rulesets . getProperties ( pseudo ) ) ) ; } return conflicts ; }