From dd5f3c463fab336d694f426dcad11a1783590fc9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 5 Feb 2022 07:52:13 +0100 Subject: Ported from import syntax to modules --- src/_props.scss | 127 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 62 deletions(-) (limited to 'src/_props.scss') diff --git a/src/_props.scss b/src/_props.scss index efc3eea..cdb96c2 100644 --- a/src/_props.scss +++ b/src/_props.scss @@ -10,12 +10,15 @@ /// @access public //// +@use './functions'; +@use './contexts'; + /// /// The maximum depth of resolved iro-prop-ref() references. /// /// @type number /// -$iro-props-native-assing-max-depth: 2 !default; +$native-assign-max-depth: 2 !default; /// /// Indicate if property names must start with two dashes (--). @@ -23,14 +26,14 @@ $iro-props-native-assing-max-depth: 2 !default; /// /// @type bool /// -$iro-props-enforce-double-dashes: true !default; +$enforce-double-dashes: true !default; /// /// Default tree name to use if no name is specified. /// /// @type string /// -$iro-props-default-tree: 'default' !default; +$default-tree: 'default' !default; /// /// List of all created property trees. @@ -39,24 +42,24 @@ $iro-props-default-tree: 'default' !default; /// /// @access private /// -$iro-props-trees: (); +$trees: (); /// /// Default context name used for the namespace context. /// /// @type string /// -$iro-props-namespace-context-id: 'namespace' !default; +$namespace-context-id: 'namespace' !default; /// /// Declare a namespace, meaning that all variables declared and accessed. /// /// @param {string} $name - Name of the namespace /// -@mixin iro-props-namespace($name) { +@mixin namespace($name) { $key: '--#{$name}'; - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { $key: append($ns-key, $key); @@ -64,23 +67,23 @@ $iro-props-namespace-context-id: 'namespace' !default; $key: ($key); } - @include iro-context-push($iro-props-namespace-context-id, 'namespace', ( + @include contexts.push($namespace-context-id, 'namespace', ( 'name': $name, 'key': $key )); @content; - @include iro-context-pop($iro-props-namespace-context-id); + @include contexts.pop($namespace-context-id); } /// /// Get the current namespace name. /// -@function iro-props-namespace() { - $noop: iro-context-assert-stack-must-contain($iro-props-namespace-context-id, 'namespace'); +@function namespace() { + $noop: contexts.assert-stack-must-contain($namespace-context-id, 'namespace'); - $data: nth(iro-context-get($iro-props-namespace-context-id, 'namespace'), 2); + $data: nth(contexts.get($namespace-context-id, 'namespace'), 2); $name: map-get($data, 'name'); @return $name; @@ -91,46 +94,46 @@ $iro-props-namespace-context-id: 'namespace' !default; /// will be merged. /// /// @param {map} $map - Map containing properties -/// @param {string} $tree [$iro-props-default-tree] - ID the map is saved as +/// @param {string} $tree [$default-tree] - ID the map is saved as /// @param {bool} $merge [true] - If a tree named $tree already exists and this value is set to true, they will be merged. Otherwise an error will be emitted. /// -@mixin iro-props-store($map, $tree: $iro-props-default-tree, $merge: true, $global: false) { - $noop: iro-props-store($map, $tree, $merge, $global); +@mixin store($map, $tree: $default-tree, $merge: true, $global: false) { + $noop: store($map, $tree, $merge, $global); } /// /// Save a property tree. /// /// @param {map} $map - Map containing properties -/// @param {string} $tree [$iro-props-default-tree] - ID the map is saved as +/// @param {string} $tree [$default-tree] - ID the map is saved as /// @param {bool} $merge [true] - If a tree named $tree already exists and this value is set to true, they will be merged. Otherwise an error will be emitted. /// -@function iro-props-store($map, $tree: $iro-props-default-tree, $merge: true, $global: false) { +@function store($map, $tree: $default-tree, $merge: true, $global: false) { $prop-map: null; - @if $iro-props-enforce-double-dashes { - @if not iro-props-validate($map) { - @error 'Property tree keys must start with two dashes (--). If you don\'t use property trees for native CSS custom properties, set $iro-props-enforce-double-dashes to false.'; + @if $enforce-double-dashes { + @if not validate($map) { + @error 'Property tree keys must start with two dashes (--). If you don\'t use property trees for native CSS custom properties, set $enforce-double-dashes to false.'; } } @if not $global { - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { $map: ($ns-key: $map) } } - @if map-has-key($iro-props-trees, $tree) { + @if map-has-key($trees, $tree) { @if $merge { - $map: iro-map-merge-recursive(map-get($iro-props-trees, $tree), $map); + $map: functions.map-merge-recursive(map-get($trees, $tree), $map); } @else { @error 'Property tree #{inspect($tree)} does already exist.'; } } - $iro-props-trees: map-merge($iro-props-trees, ($tree: $map)) !global; + $trees: map-merge($trees, ($tree: $map)) !global; @return null; } @@ -138,25 +141,25 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// Delete a property tree. /// -/// @param {string} $tree [$iro-props-default-tree] - ID of the tree to be deleted +/// @param {string} $tree [$default-tree] - ID of the tree to be deleted /// -@mixin iro-props-clear($tree: $iro-props-default-tree) { - $noop: iro-props-clear($tree); +@mixin clear($tree: $default-tree) { + $noop: clear($tree); } /// /// Delete a property tree. /// -/// @param {string} $tree [$iro-props-default-tree] - ID of the tree to be deleted +/// @param {string} $tree [$default-tree] - ID of the tree to be deleted /// /// @throw If the property tree does not exist /// -@function iro-props-clear($tree: $iro-props-default-tree) { - @if not map-has-key($iro-props-trees, $tree) { +@function clear($tree: $default-tree) { + @if not map-has-key($trees, $tree) { @error 'Property tree "#{inspect($tree)}" does not exist.'; } - $iro-props-trees: map-remove($iro-props-trees, $tree) !global; + $trees: map-remove($trees, $tree) !global; @return null; } @@ -165,22 +168,22 @@ $iro-props-namespace-context-id: 'namespace' !default; /// Access a whole property or a subsection (i.e. value) of it. /// /// @param {string | list} $key [null] - Key of the property to read. If this is a list of keys, the map will be traversed in that order. -/// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use +/// @param {string} $tree [$default-tree] - ID of the property tree to use /// @param {any} $default [null] - Default value to return of no match was found. If null, this function will throw an error instead. /// /// @return {any} Value assigned to property or $default /// /// @throw If there was no match for $key and $default is null /// -@function iro-props-get-static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { - @if not map-has-key($iro-props-trees, $tree) { +@function get-static($key: (), $tree: $default-tree, $default: null, $global: false) { + @if not map-has-key($trees, $tree) { @error 'Unknown tree "#{$tree}".'; } - $result: map-get($iro-props-trees, $tree); + $result: map-get($trees, $tree); @if not $global { - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { $orig-key: $key; @@ -205,9 +208,9 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { @if length($result) == 2 { - $result: iro-props-get-static($tree: nth($result, 2), $global: true); + $result: get-static($tree: nth($result, 2), $global: true); } @else { - $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); + $result: get-static(nth($result, 3), nth($result, 2), $global: true); } } } @else { @@ -223,9 +226,9 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { @if length($result) == 2 { - $result: iro-props-get-static($tree: nth($result, 2), $global: true); + $result: get-static($tree: nth($result, 2), $global: true); } @else { - $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); + $result: get-static(nth($result, 3), nth($result, 2), $global: true); } } } @@ -250,13 +253,13 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// @return {string} var() /// -@function iro-props-get($key, $tree: $iro-props-default-tree, $default: null, $global: false) { +@function get($key, $tree: $default-tree, $default: null, $global: false) { @if $tree != null { - $noop: iro-props-get-static($key, $tree, $default, $global); + $noop: get-static($key, $tree, $default, $global); } @if not $global { - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { $orig-key: $key; @@ -292,41 +295,41 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// Generate assignments for native CSS custom properties with the values from the specified tree. /// -/// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use +/// @param {string} $tree [$default-tree] - ID of the property tree to use /// @param {string} $root [()] - Sub-tree to use for assignment /// -@mixin iro-props-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { - $map: iro-props-get-static($root, $tree); +@mixin assign($tree: $default-tree, $root: (), $skip: (), $prefix: '', $global: false) { + $map: get-static($root, $tree); $map: map-remove($map, $skip...); @if type-of($prefix) == list { - $prefix: iro-str-implode($prefix) + $prefix: functions.str-implode($prefix) } @if not $global { - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { - $prefix: $prefix + iro-str-implode($ns-key); + $prefix: $prefix + functions.str-implode($ns-key); } } - @include iro-props-assign-internal($map, $prefix); + @include assign-internal($map, $prefix); } /// /// @access private /// -@mixin iro-props-assign-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { +@mixin assign-internal($map, $prefix: '', $ref-depth: $native-assign-max-depth) { @each $key, $value in $map { $rd: $ref-depth; @if type-of($value) == list and length($value) > 0 and nth($value, 1) == 'iro-prop-ref' { @if $ref-depth != 0 { $rd: $rd - 1; @if length($value) == 2 { - $value: iro-props-get-static($tree: nth($value, 2)); + $value: get-static($tree: nth($value, 2)); } @else { - $value: iro-props-get-static(nth($value, 3), nth($value, 2)); + $value: get-static(nth($value, 3), nth($value, 2)); } } @else { $value: null; @@ -335,7 +338,7 @@ $iro-props-namespace-context-id: 'namespace' !default; @if type-of($value) != map and $value != () { #{$prefix + $key}: #{$value}; } @else { - @include iro-props-assign-internal($value, $prefix + $key, $rd); + @include assign-internal($value, $prefix + $key, $rd); } } } @@ -345,14 +348,14 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// @access private /// -@function iro-props-validate($map) { +@function validate($map) { @each $key, $value in $map { @if str-index($key, '--') != 1 { @return false; } @if type-of($value) == map { - @if not iro-props-validate($value) { + @if not validate($value) { @return false; } } @@ -364,16 +367,16 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// Generate a reference to another tree. Dereferencing is lazy, so you may specify a tree that hasn't been created yet. /// -/// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use +/// @param {string} $tree [$default-tree] - ID of the property tree to use /// @param {string | list} $key - Key of the property to read. If this is a list of keys, the map will be traversed in that order. /// /// @return {list} A special list that let's Ignis know that this is a lazy value. /// /// @throw If there was no match for $key and $default is null /// -@function iro-props-ref($tree: $iro-props-default-tree, $key: null, $global: false) { +@function ref($tree: $default-tree, $key: null, $global: false) { @if not $global { - $ns-key: iro-props-get-ns-key(); + $ns-key: get-ns-key(); @if $ns-key != null { $orig-key: $key; @@ -403,8 +406,8 @@ $iro-props-namespace-context-id: 'namespace' !default; /// /// @access private /// -@function iro-props-get-ns-key() { - $ctx: iro-context-get($iro-props-namespace-context-id, 'namespace'); +@function get-ns-key() { + $ctx: contexts.get($namespace-context-id, 'namespace'); @if $ctx == null { @return null; @@ -416,4 +419,4 @@ $iro-props-namespace-context-id: 'namespace' !default; @return $key; } -@include iro-context-stack-create($iro-props-namespace-context-id); +@include contexts.create($namespace-context-id); -- cgit v1.2.3-70-g09d2