diff options
Diffstat (limited to 'src/_props.scss')
-rw-r--r-- | src/_props.scss | 127 |
1 files changed, 65 insertions, 62 deletions
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 @@ | |||
10 | /// @access public | 10 | /// @access public |
11 | //// | 11 | //// |
12 | 12 | ||
13 | @use './functions'; | ||
14 | @use './contexts'; | ||
15 | |||
13 | /// | 16 | /// |
14 | /// The maximum depth of resolved iro-prop-ref() references. | 17 | /// The maximum depth of resolved iro-prop-ref() references. |
15 | /// | 18 | /// |
16 | /// @type number | 19 | /// @type number |
17 | /// | 20 | /// |
18 | $iro-props-native-assing-max-depth: 2 !default; | 21 | $native-assign-max-depth: 2 !default; |
19 | 22 | ||
20 | /// | 23 | /// |
21 | /// Indicate if property names must start with two dashes (--). | 24 | /// Indicate if property names must start with two dashes (--). |
@@ -23,14 +26,14 @@ $iro-props-native-assing-max-depth: 2 !default; | |||
23 | /// | 26 | /// |
24 | /// @type bool | 27 | /// @type bool |
25 | /// | 28 | /// |
26 | $iro-props-enforce-double-dashes: true !default; | 29 | $enforce-double-dashes: true !default; |
27 | 30 | ||
28 | /// | 31 | /// |
29 | /// Default tree name to use if no name is specified. | 32 | /// Default tree name to use if no name is specified. |
30 | /// | 33 | /// |
31 | /// @type string | 34 | /// @type string |
32 | /// | 35 | /// |
33 | $iro-props-default-tree: 'default' !default; | 36 | $default-tree: 'default' !default; |
34 | 37 | ||
35 | /// | 38 | /// |
36 | /// List of all created property trees. | 39 | /// List of all created property trees. |
@@ -39,24 +42,24 @@ $iro-props-default-tree: 'default' !default; | |||
39 | /// | 42 | /// |
40 | /// @access private | 43 | /// @access private |
41 | /// | 44 | /// |
42 | $iro-props-trees: (); | 45 | $trees: (); |
43 | 46 | ||
44 | /// | 47 | /// |
45 | /// Default context name used for the namespace context. | 48 | /// Default context name used for the namespace context. |
46 | /// | 49 | /// |
47 | /// @type string | 50 | /// @type string |
48 | /// | 51 | /// |
49 | $iro-props-namespace-context-id: 'namespace' !default; | 52 | $namespace-context-id: 'namespace' !default; |
50 | 53 | ||
51 | /// | 54 | /// |
52 | /// Declare a namespace, meaning that all variables declared and accessed. | 55 | /// Declare a namespace, meaning that all variables declared and accessed. |
53 | /// | 56 | /// |
54 | /// @param {string} $name - Name of the namespace | 57 | /// @param {string} $name - Name of the namespace |
55 | /// | 58 | /// |
56 | @mixin iro-props-namespace($name) { | 59 | @mixin namespace($name) { |
57 | $key: '--#{$name}'; | 60 | $key: '--#{$name}'; |
58 | 61 | ||
59 | $ns-key: iro-props-get-ns-key(); | 62 | $ns-key: get-ns-key(); |
60 | 63 | ||
61 | @if $ns-key != null { | 64 | @if $ns-key != null { |
62 | $key: append($ns-key, $key); | 65 | $key: append($ns-key, $key); |
@@ -64,23 +67,23 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
64 | $key: ($key); | 67 | $key: ($key); |
65 | } | 68 | } |
66 | 69 | ||
67 | @include iro-context-push($iro-props-namespace-context-id, 'namespace', ( | 70 | @include contexts.push($namespace-context-id, 'namespace', ( |
68 | 'name': $name, | 71 | 'name': $name, |
69 | 'key': $key | 72 | 'key': $key |
70 | )); | 73 | )); |
71 | 74 | ||
72 | @content; | 75 | @content; |
73 | 76 | ||
74 | @include iro-context-pop($iro-props-namespace-context-id); | 77 | @include contexts.pop($namespace-context-id); |
75 | } | 78 | } |
76 | 79 | ||
77 | /// | 80 | /// |
78 | /// Get the current namespace name. | 81 | /// Get the current namespace name. |
79 | /// | 82 | /// |
80 | @function iro-props-namespace() { | 83 | @function namespace() { |
81 | $noop: iro-context-assert-stack-must-contain($iro-props-namespace-context-id, 'namespace'); | 84 | $noop: contexts.assert-stack-must-contain($namespace-context-id, 'namespace'); |
82 | 85 | ||
83 | $data: nth(iro-context-get($iro-props-namespace-context-id, 'namespace'), 2); | 86 | $data: nth(contexts.get($namespace-context-id, 'namespace'), 2); |
84 | $name: map-get($data, 'name'); | 87 | $name: map-get($data, 'name'); |
85 | 88 | ||
86 | @return $name; | 89 | @return $name; |
@@ -91,46 +94,46 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
91 | /// will be merged. | 94 | /// will be merged. |
92 | /// | 95 | /// |
93 | /// @param {map} $map - Map containing properties | 96 | /// @param {map} $map - Map containing properties |
94 | /// @param {string} $tree [$iro-props-default-tree] - ID the map is saved as | 97 | /// @param {string} $tree [$default-tree] - ID the map is saved as |
95 | /// @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. | 98 | /// @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. |
96 | /// | 99 | /// |
97 | @mixin iro-props-store($map, $tree: $iro-props-default-tree, $merge: true, $global: false) { | 100 | @mixin store($map, $tree: $default-tree, $merge: true, $global: false) { |
98 | $noop: iro-props-store($map, $tree, $merge, $global); | 101 | $noop: store($map, $tree, $merge, $global); |
99 | } | 102 | } |
100 | 103 | ||
101 | /// | 104 | /// |
102 | /// Save a property tree. | 105 | /// Save a property tree. |
103 | /// | 106 | /// |
104 | /// @param {map} $map - Map containing properties | 107 | /// @param {map} $map - Map containing properties |
105 | /// @param {string} $tree [$iro-props-default-tree] - ID the map is saved as | 108 | /// @param {string} $tree [$default-tree] - ID the map is saved as |
106 | /// @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. | 109 | /// @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. |
107 | /// | 110 | /// |
108 | @function iro-props-store($map, $tree: $iro-props-default-tree, $merge: true, $global: false) { | 111 | @function store($map, $tree: $default-tree, $merge: true, $global: false) { |
109 | $prop-map: null; | 112 | $prop-map: null; |
110 | 113 | ||
111 | @if $iro-props-enforce-double-dashes { | 114 | @if $enforce-double-dashes { |
112 | @if not iro-props-validate($map) { | 115 | @if not validate($map) { |
113 | @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.'; | 116 | @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.'; |
114 | } | 117 | } |
115 | } | 118 | } |
116 | 119 | ||
117 | @if not $global { | 120 | @if not $global { |
118 | $ns-key: iro-props-get-ns-key(); | 121 | $ns-key: get-ns-key(); |
119 | 122 | ||
120 | @if $ns-key != null { | 123 | @if $ns-key != null { |
121 | $map: ($ns-key: $map) | 124 | $map: ($ns-key: $map) |
122 | } | 125 | } |
123 | } | 126 | } |
124 | 127 | ||
125 | @if map-has-key($iro-props-trees, $tree) { | 128 | @if map-has-key($trees, $tree) { |
126 | @if $merge { | 129 | @if $merge { |
127 | $map: iro-map-merge-recursive(map-get($iro-props-trees, $tree), $map); | 130 | $map: functions.map-merge-recursive(map-get($trees, $tree), $map); |
128 | } @else { | 131 | } @else { |
129 | @error 'Property tree #{inspect($tree)} does already exist.'; | 132 | @error 'Property tree #{inspect($tree)} does already exist.'; |
130 | } | 133 | } |
131 | } | 134 | } |
132 | 135 | ||
133 | $iro-props-trees: map-merge($iro-props-trees, ($tree: $map)) !global; | 136 | $trees: map-merge($trees, ($tree: $map)) !global; |
134 | 137 | ||
135 | @return null; | 138 | @return null; |
136 | } | 139 | } |
@@ -138,25 +141,25 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
138 | /// | 141 | /// |
139 | /// Delete a property tree. | 142 | /// Delete a property tree. |
140 | /// | 143 | /// |
141 | /// @param {string} $tree [$iro-props-default-tree] - ID of the tree to be deleted | 144 | /// @param {string} $tree [$default-tree] - ID of the tree to be deleted |
142 | /// | 145 | /// |
143 | @mixin iro-props-clear($tree: $iro-props-default-tree) { | 146 | @mixin clear($tree: $default-tree) { |
144 | $noop: iro-props-clear($tree); | 147 | $noop: clear($tree); |
145 | } | 148 | } |
146 | 149 | ||
147 | /// | 150 | /// |
148 | /// Delete a property tree. | 151 | /// Delete a property tree. |
149 | /// | 152 | /// |
150 | /// @param {string} $tree [$iro-props-default-tree] - ID of the tree to be deleted | 153 | /// @param {string} $tree [$default-tree] - ID of the tree to be deleted |
151 | /// | 154 | /// |
152 | /// @throw If the property tree does not exist | 155 | /// @throw If the property tree does not exist |
153 | /// | 156 | /// |
154 | @function iro-props-clear($tree: $iro-props-default-tree) { | 157 | @function clear($tree: $default-tree) { |
155 | @if not map-has-key($iro-props-trees, $tree) { | 158 | @if not map-has-key($trees, $tree) { |
156 | @error 'Property tree "#{inspect($tree)}" does not exist.'; | 159 | @error 'Property tree "#{inspect($tree)}" does not exist.'; |
157 | } | 160 | } |
158 | 161 | ||
159 | $iro-props-trees: map-remove($iro-props-trees, $tree) !global; | 162 | $trees: map-remove($trees, $tree) !global; |
160 | 163 | ||
161 | @return null; | 164 | @return null; |
162 | } | 165 | } |
@@ -165,22 +168,22 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
165 | /// Access a whole property or a subsection (i.e. value) of it. | 168 | /// Access a whole property or a subsection (i.e. value) of it. |
166 | /// | 169 | /// |
167 | /// @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. | 170 | /// @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. |
168 | /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use | 171 | /// @param {string} $tree [$default-tree] - ID of the property tree to use |
169 | /// @param {any} $default [null] - Default value to return of no match was found. If null, this function will throw an error instead. | 172 | /// @param {any} $default [null] - Default value to return of no match was found. If null, this function will throw an error instead. |
170 | /// | 173 | /// |
171 | /// @return {any} Value assigned to property or $default | 174 | /// @return {any} Value assigned to property or $default |
172 | /// | 175 | /// |
173 | /// @throw If there was no match for $key and $default is null | 176 | /// @throw If there was no match for $key and $default is null |
174 | /// | 177 | /// |
175 | @function iro-props-get-static($key: (), $tree: $iro-props-default-tree, $default: null, $global: false) { | 178 | @function get-static($key: (), $tree: $default-tree, $default: null, $global: false) { |
176 | @if not map-has-key($iro-props-trees, $tree) { | 179 | @if not map-has-key($trees, $tree) { |
177 | @error 'Unknown tree "#{$tree}".'; | 180 | @error 'Unknown tree "#{$tree}".'; |
178 | } | 181 | } |
179 | 182 | ||
180 | $result: map-get($iro-props-trees, $tree); | 183 | $result: map-get($trees, $tree); |
181 | 184 | ||
182 | @if not $global { | 185 | @if not $global { |
183 | $ns-key: iro-props-get-ns-key(); | 186 | $ns-key: get-ns-key(); |
184 | 187 | ||
185 | @if $ns-key != null { | 188 | @if $ns-key != null { |
186 | $orig-key: $key; | 189 | $orig-key: $key; |
@@ -205,9 +208,9 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
205 | 208 | ||
206 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 209 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { |
207 | @if length($result) == 2 { | 210 | @if length($result) == 2 { |
208 | $result: iro-props-get-static($tree: nth($result, 2), $global: true); | 211 | $result: get-static($tree: nth($result, 2), $global: true); |
209 | } @else { | 212 | } @else { |
210 | $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); | 213 | $result: get-static(nth($result, 3), nth($result, 2), $global: true); |
211 | } | 214 | } |
212 | } | 215 | } |
213 | } @else { | 216 | } @else { |
@@ -223,9 +226,9 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
223 | 226 | ||
224 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { | 227 | @if type-of($result) == list and nth($result, 1) == 'iro-prop-ref' { |
225 | @if length($result) == 2 { | 228 | @if length($result) == 2 { |
226 | $result: iro-props-get-static($tree: nth($result, 2), $global: true); | 229 | $result: get-static($tree: nth($result, 2), $global: true); |
227 | } @else { | 230 | } @else { |
228 | $result: iro-props-get-static(nth($result, 3), nth($result, 2), $global: true); | 231 | $result: get-static(nth($result, 3), nth($result, 2), $global: true); |
229 | } | 232 | } |
230 | } | 233 | } |
231 | } | 234 | } |
@@ -250,13 +253,13 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
250 | /// | 253 | /// |
251 | /// @return {string} var() | 254 | /// @return {string} var() |
252 | /// | 255 | /// |
253 | @function iro-props-get($key, $tree: $iro-props-default-tree, $default: null, $global: false) { | 256 | @function get($key, $tree: $default-tree, $default: null, $global: false) { |
254 | @if $tree != null { | 257 | @if $tree != null { |
255 | $noop: iro-props-get-static($key, $tree, $default, $global); | 258 | $noop: get-static($key, $tree, $default, $global); |
256 | } | 259 | } |
257 | 260 | ||
258 | @if not $global { | 261 | @if not $global { |
259 | $ns-key: iro-props-get-ns-key(); | 262 | $ns-key: get-ns-key(); |
260 | 263 | ||
261 | @if $ns-key != null { | 264 | @if $ns-key != null { |
262 | $orig-key: $key; | 265 | $orig-key: $key; |
@@ -292,41 +295,41 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
292 | /// | 295 | /// |
293 | /// Generate assignments for native CSS custom properties with the values from the specified tree. | 296 | /// Generate assignments for native CSS custom properties with the values from the specified tree. |
294 | /// | 297 | /// |
295 | /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use | 298 | /// @param {string} $tree [$default-tree] - ID of the property tree to use |
296 | /// @param {string} $root [()] - Sub-tree to use for assignment | 299 | /// @param {string} $root [()] - Sub-tree to use for assignment |
297 | /// | 300 | /// |
298 | @mixin iro-props-assign($tree: $iro-props-default-tree, $root: (), $skip: (), $prefix: '', $global: false) { | 301 | @mixin assign($tree: $default-tree, $root: (), $skip: (), $prefix: '', $global: false) { |
299 | $map: iro-props-get-static($root, $tree); | 302 | $map: get-static($root, $tree); |
300 | $map: map-remove($map, $skip...); | 303 | $map: map-remove($map, $skip...); |
301 | 304 | ||
302 | @if type-of($prefix) == list { | 305 | @if type-of($prefix) == list { |
303 | $prefix: iro-str-implode($prefix) | 306 | $prefix: functions.str-implode($prefix) |
304 | } | 307 | } |
305 | 308 | ||
306 | @if not $global { | 309 | @if not $global { |
307 | $ns-key: iro-props-get-ns-key(); | 310 | $ns-key: get-ns-key(); |
308 | 311 | ||
309 | @if $ns-key != null { | 312 | @if $ns-key != null { |
310 | $prefix: $prefix + iro-str-implode($ns-key); | 313 | $prefix: $prefix + functions.str-implode($ns-key); |
311 | } | 314 | } |
312 | } | 315 | } |
313 | 316 | ||
314 | @include iro-props-assign-internal($map, $prefix); | 317 | @include assign-internal($map, $prefix); |
315 | } | 318 | } |
316 | 319 | ||
317 | /// | 320 | /// |
318 | /// @access private | 321 | /// @access private |
319 | /// | 322 | /// |
320 | @mixin iro-props-assign-internal($map, $prefix: '', $ref-depth: $iro-props-native-assing-max-depth) { | 323 | @mixin assign-internal($map, $prefix: '', $ref-depth: $native-assign-max-depth) { |
321 | @each $key, $value in $map { | 324 | @each $key, $value in $map { |
322 | $rd: $ref-depth; | 325 | $rd: $ref-depth; |
323 | @if type-of($value) == list and length($value) > 0 and nth($value, 1) == 'iro-prop-ref' { | 326 | @if type-of($value) == list and length($value) > 0 and nth($value, 1) == 'iro-prop-ref' { |
324 | @if $ref-depth != 0 { | 327 | @if $ref-depth != 0 { |
325 | $rd: $rd - 1; | 328 | $rd: $rd - 1; |
326 | @if length($value) == 2 { | 329 | @if length($value) == 2 { |
327 | $value: iro-props-get-static($tree: nth($value, 2)); | 330 | $value: get-static($tree: nth($value, 2)); |
328 | } @else { | 331 | } @else { |
329 | $value: iro-props-get-static(nth($value, 3), nth($value, 2)); | 332 | $value: get-static(nth($value, 3), nth($value, 2)); |
330 | } | 333 | } |
331 | } @else { | 334 | } @else { |
332 | $value: null; | 335 | $value: null; |
@@ -335,7 +338,7 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
335 | @if type-of($value) != map and $value != () { | 338 | @if type-of($value) != map and $value != () { |
336 | #{$prefix + $key}: #{$value}; | 339 | #{$prefix + $key}: #{$value}; |
337 | } @else { | 340 | } @else { |
338 | @include iro-props-assign-internal($value, $prefix + $key, $rd); | 341 | @include assign-internal($value, $prefix + $key, $rd); |
339 | } | 342 | } |
340 | } | 343 | } |
341 | } | 344 | } |
@@ -345,14 +348,14 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
345 | /// | 348 | /// |
346 | /// @access private | 349 | /// @access private |
347 | /// | 350 | /// |
348 | @function iro-props-validate($map) { | 351 | @function validate($map) { |
349 | @each $key, $value in $map { | 352 | @each $key, $value in $map { |
350 | @if str-index($key, '--') != 1 { | 353 | @if str-index($key, '--') != 1 { |
351 | @return false; | 354 | @return false; |
352 | } | 355 | } |
353 | 356 | ||
354 | @if type-of($value) == map { | 357 | @if type-of($value) == map { |
355 | @if not iro-props-validate($value) { | 358 | @if not validate($value) { |
356 | @return false; | 359 | @return false; |
357 | } | 360 | } |
358 | } | 361 | } |
@@ -364,16 +367,16 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
364 | /// | 367 | /// |
365 | /// Generate a reference to another tree. Dereferencing is lazy, so you may specify a tree that hasn't been created yet. | 368 | /// Generate a reference to another tree. Dereferencing is lazy, so you may specify a tree that hasn't been created yet. |
366 | /// | 369 | /// |
367 | /// @param {string} $tree [$iro-props-default-tree] - ID of the property tree to use | 370 | /// @param {string} $tree [$default-tree] - ID of the property tree to use |
368 | /// @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. | 371 | /// @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. |
369 | /// | 372 | /// |
370 | /// @return {list} A special list that let's Ignis know that this is a lazy value. | 373 | /// @return {list} A special list that let's Ignis know that this is a lazy value. |
371 | /// | 374 | /// |
372 | /// @throw If there was no match for $key and $default is null | 375 | /// @throw If there was no match for $key and $default is null |
373 | /// | 376 | /// |
374 | @function iro-props-ref($tree: $iro-props-default-tree, $key: null, $global: false) { | 377 | @function ref($tree: $default-tree, $key: null, $global: false) { |
375 | @if not $global { | 378 | @if not $global { |
376 | $ns-key: iro-props-get-ns-key(); | 379 | $ns-key: get-ns-key(); |
377 | 380 | ||
378 | @if $ns-key != null { | 381 | @if $ns-key != null { |
379 | $orig-key: $key; | 382 | $orig-key: $key; |
@@ -403,8 +406,8 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
403 | /// | 406 | /// |
404 | /// @access private | 407 | /// @access private |
405 | /// | 408 | /// |
406 | @function iro-props-get-ns-key() { | 409 | @function get-ns-key() { |
407 | $ctx: iro-context-get($iro-props-namespace-context-id, 'namespace'); | 410 | $ctx: contexts.get($namespace-context-id, 'namespace'); |
408 | 411 | ||
409 | @if $ctx == null { | 412 | @if $ctx == null { |
410 | @return null; | 413 | @return null; |
@@ -416,4 +419,4 @@ $iro-props-namespace-context-id: 'namespace' !default; | |||
416 | @return $key; | 419 | @return $key; |
417 | } | 420 | } |
418 | 421 | ||
419 | @include iro-context-stack-create($iro-props-namespace-context-id); | 422 | @include contexts.create($namespace-context-id); |