陶杰
2024-08-22 4aa0bd47801606b4d0e0a6a2ed8fe92a7e5f2444
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 合并 map
@function map-deep-merge($parent-map, $child-map){
    $result: $parent-map;
    @each $key, $child in $child-map {
        $parent-has-key: map-has-key($result, $key);
        $parent-value: map-get($result, $key);
        $parent-type: type-of($parent-value);
        $child-type: type-of($child);
        $parent-is-map: $parent-type == map;
        $child-is-map: $child-type == map;
            
        @if (not $parent-has-key) or ($parent-type != $child-type) or (not ($parent-is-map and $child-is-map)){
            $result: map-merge($result, ( $key: $child ));
        }@else {
            $result: map-merge($result, ( $key: map-deep-merge($parent-value, $child) ));
        }
    }
    @return $result;
};