[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 // Remove the unit of a length 2 // @param {Number} $number - Number to remove unit from 3 // @return {Number} - Unitless number 4 @function strip-unit($number) { 5 @if type-of($number) == "number" and not unitless($number) { 6 @return $number / ($number * 0 + 1); 7 } 8 9 @return $number; 10 } 11 12 // ---- 13 // Sass (v3.3.14) 14 // Compass (v1.0.0.rc.1) 15 // ---- 16 17 @function pow($x, $y) { 18 $ret: 1; 19 20 @if $y > 0 { 21 @for $i from 1 through $y { 22 $ret: $ret * $x; 23 } 24 } @else { 25 @for $i from $y to 0 { 26 $ret: $ret / $x; 27 } 28 } 29 30 @return $ret; 31 } 32 33 // Map deep get 34 // @author Hugo Giraudel 35 // @access public 36 // @param {Map} $map - Map 37 // @param {Arglist} $keys - Key chain 38 // @return {*} - Desired value 39 // 40 // Example: 41 // $m-breakpoint: map-deep-get($__prefix-default-config, "layouts", "M"); 42 @function map-deep-get($map, $keys...) { 43 @each $key in $keys { 44 $map: map-get($map, $key); 45 } 46 @return $map; 47 } 48 49 // Deep set function to set a value in nested maps 50 // @author Hugo Giraudel 51 // @access public 52 // @param {Map} $map - Map 53 // @param {List} $keys - Key chaine 54 // @param {*} $value - Value to assign 55 // @return {Map} 56 // 57 // Example: 58 // $__prefix-default-config: map-deep-set($__prefix-default-config, "layouts" "M", 650px); 59 @function map-deep-set($map, $keys, $value) { 60 $maps: ($map); 61 $result: null; 62 63 // If the last key is a map already 64 // Warn the user we will be overriding it with $value 65 @if type-of(nth($keys, -1)) == "map" { 66 @warn "The last key you specified is a map; it will be overridden with `#{$value}`."; 67 } 68 69 // If $keys is a single key 70 // Just merge and return 71 @if length($keys) == 1 { 72 @return map-merge($map, ($keys: $value)); 73 } 74 75 // Loop from the first to the second to last key from $keys 76 // Store the associated map to this key in the $maps list 77 // If the key doesn't exist, throw an error 78 @for $i from 1 through length($keys) - 1 { 79 $current-key: nth($keys, $i); 80 $current-map: nth($maps, -1); 81 $current-get: map-get($current-map, $current-key); 82 @if $current-get == null { 83 @error "Key `#{$key}` doesn't exist at current level in map."; 84 } 85 $maps: append($maps, $current-get); 86 } 87 88 // Loop from the last map to the first one 89 // Merge it with the previous one 90 @for $i from length($maps) through 1 { 91 $current-map: nth($maps, $i); 92 $current-key: nth($keys, $i); 93 $current-val: if($i == length($maps), $value, $result); 94 $result: map-merge($current-map, ($current-key: $current-val)); 95 } 96 97 // Return result 98 @return $result; 99 } 100 101 // jQuery-style extend function 102 // - Child themes can use this function to `reset` the values in 103 // config maps without editing the `master` Sass files. 104 // - src: https://www.sitepoint.com/extra-map-functions-sass/ 105 // - About `map-merge()`: 106 // - - only takes 2 arguments 107 // - - is not recursive 108 // @param {Map} $map - first map 109 // @param {ArgList} $maps - other maps 110 // @param {Bool} $deep - recursive mode 111 // @return {Map} 112 113 // Examples: 114 115 // $grid-configuration-default: ( 116 // 'columns': 12, 117 // 'layouts': ( 118 // 'small': 800px, 119 // 'medium': 1000px, 120 // 'large': 1200px, 121 // ), 122 // ); 123 124 // $grid-configuration-custom: ( 125 // 'layouts': ( 126 // 'large': 1300px, 127 // 'huge': 1500px 128 // ), 129 // ); 130 131 // $grid-configuration-user: ( 132 // 'direction': 'ltr', 133 // 'columns': 16, 134 // 'layouts': ( 135 // 'large': 1300px, 136 // 'huge': 1500px 137 // ), 138 // ); 139 140 // $deep: false 141 // $grid-configuration: map-extend($grid-configuration-default, $grid-configuration-custom, $grid-configuration-user); 142 // --> ("columns": 16, "layouts": (("large": 1300px, "huge": 1500px)), "direction": "ltr") 143 144 // $deep: true 145 // $grid-configuration: map-extend($grid-configuration-default, $grid-configuration-custom, $grid-configuration-user, true); 146 // --> ("columns": 16, "layouts": (("small": 800px, "medium": 1000px, "large": 1300px, "huge": 1500px)), "direction": "ltr") 147 148 @function map-extend($map, $maps.../*, $deep */) { 149 $last: nth($maps, -1); 150 $deep: $last == true; 151 $max: if($deep, length($maps) - 1, length($maps)); 152 153 // Loop through all maps in $maps... 154 @for $i from 1 through $max { 155 // Store current map 156 $current: nth($maps, $i); 157 158 // If not in deep mode, simply merge current map with map 159 @if not $deep { 160 $map: map-merge($map, $current); 161 } @else { 162 // If in deep mode, loop through all tuples in current map 163 @each $key, $value in $current { 164 165 // If value is a nested map and same key from map is a nested map as well 166 @if type-of($value) == "map" and type-of(map-get($map, $key)) == "map" { 167 // Recursive extend 168 $value: map-extend(map-get($map, $key), $value, true); 169 } 170 171 // Merge current tuple with map 172 $map: map-merge($map, ($key: $value)); 173 } 174 } 175 } 176 177 @return $map; 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |