/** * Calculate width * * @param {String} $key - key of breakpoint * @param {Number} $span - span value of element * @param {Number | String} $context (null) - context value of element * @param {Number} $deduct (null) - subtract value out of final width * * @return {Map | False} - map of target and context result */ @function flint-calc-width($key, $span, $context: null, $deduct: null) { $result: (); // Check to see if value has been cached @if map-has-key($flint__cached-values, "#{$key, $span, $context}::width") and $context != "auto" { @return map-get($flint__cached-values, "#{$key, $span, $context}::width"); } @if $span == "container" { $result: flint-get-value("breakpoints", $key, "breakpoint"); } @else if $context == "auto" { /* * Check if instance maps are enabled */ @if not flint-get-value("settings", "instance-maps") { @if not $flint__development-mode { @error "Instance maps are disabled. Automatic context is not available. Enable `instance-maps` in the config to continue."; } @else { @warn "Instance maps are disabled. Automatic context is not available. Enable `instance-maps` in the config to continue."; } } @if flint-has-family-instance($key) { $result: map-merge($result, ("target": ((flint-get-instance-value($key, "internal", "width") / flint-get-instance-value($key, "span") * $span) - if($deduct, $deduct, 0)))); $result: map-merge($result, ("context": flint-get-instance-value($key, "internal", "width"))); } @else { @if not $flint__development-mode { @error "You set context to `#{$context}`, but a parent instance could not be found for `#{nth(&, 1) + '::' + $key}`"; } @else { @return false; } } } @else { $result: map-merge($result, ("target": ((flint-get-value("breakpoints", $key, "breakpoint") / flint-get-value("breakpoints", $key, "columns") * $span) - if($deduct, $deduct, 0)))); @if $context { $result: map-merge($result, ("context": flint-get-value("breakpoints", $key, "breakpoint") / flint-get-value("breakpoints", $key, "columns") * $context)); } @else { $result: map-merge($result, ("context": flint-get-value("breakpoints", $key, "breakpoint"))); } } // Save result to cache @if $context != "auto" { $flint__cached-values: map-merge($flint__cached-values, ("#{$key, $span, $context}::width": $result)); } // Return result @return $result; }