mirror of
https://github.com/zhigang1992/sass-layout.git
synced 2026-01-12 16:42:48 +08:00
66 lines
2.2 KiB
SCSS
66 lines
2.2 KiB
SCSS
@function is-percentage($number) {
|
|
$string: inspect($number);
|
|
$last-letter: str-slice($string, str-length($string), str-length($string));
|
|
@return $last-letter == '%';
|
|
}
|
|
|
|
@function map-set($map, $key, $value) {
|
|
$new: ($key: $value);
|
|
@return map-merge($map, $new);
|
|
}
|
|
|
|
@mixin save-layout($node) {
|
|
$node: save-layout($node);
|
|
}
|
|
|
|
@function save-layout($node) {
|
|
$selector: map-get($node, selector);
|
|
$global-frame-map: map-set($global-frame-map, $selector, $node) !global;
|
|
@return $node;
|
|
}
|
|
|
|
@function get-layout($node) {
|
|
@return map-get($global-frame-map, $node);
|
|
}
|
|
|
|
@function render-node($node) {
|
|
$layout: map-get($global-frame-map, $node);
|
|
@return (
|
|
map-get($layout, width),
|
|
map-get($layout, height),
|
|
map-get($layout, top),
|
|
map-get($layout, left)
|
|
);
|
|
}
|
|
|
|
@function layout-property($property-name, $layout) {
|
|
@if map-get($layout, #{$property-name}) == null {
|
|
$layout: map-set($layout, #{$property-name}, 0);
|
|
}
|
|
$property: map-get($layout, #{$property-name});
|
|
@if length($property) == 1 { $property: ($property, $property, $property, $property); }
|
|
@if length($property) == 2 { $property: join($property, $property); }
|
|
@if length($property) == 3 { $property: join($property, nth($property, 2)); }
|
|
@if map-get($layout, #{$property-name}-top) == null { $layout: map-set($layout, #{$property-name}-top, nth($property, 1)); }
|
|
@if map-get($layout, #{$property-name}-right) == null { $layout: map-set($layout, #{$property-name}-right, nth($property, 2)); }
|
|
@if map-get($layout, #{$property-name}-bottom) == null { $layout: map-set($layout, #{$property-name}-bottom, nth($property, 3)); }
|
|
@if map-get($layout, #{$property-name}-left) == null { $layout: map-set($layout, #{$property-name}-left, nth($property, 4)); }
|
|
@return $layout;
|
|
}
|
|
|
|
@function parent-selector($current-node) {
|
|
$selector-list: nth(selector-parse($current-node), 1);
|
|
$selector-length: length($selector-list);
|
|
@if $selector-length < 2 {
|
|
@return "";
|
|
}
|
|
$parent-selector: nth($selector-list, 1);
|
|
@if $selector-length == 2 {
|
|
@return $parent-selector;
|
|
}
|
|
@for $i from 2 through ($selector-length - 1){
|
|
$parent-selector: selector-nest($parent-selector, nth($selector-list, $i));
|
|
}
|
|
@return #{$parent-selector};
|
|
}
|