aboutsummaryrefslogtreecommitdiffstats
path: root/src/_functions.scss
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2025-08-13 12:01:46 +0200
committerVolpeon <git@volpeon.ink>2025-08-13 12:01:46 +0200
commitf0f84513f8efe533b6ee670a6f1a0c074387b2ec (patch)
tree845bc4bacf1bd99acb0dfcc7e4545a36b544d2f8 /src/_functions.scss
parentMore fix (diff)
downloadiro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.tar.gz
iro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.tar.bz2
iro-sass-f0f84513f8efe533b6ee670a6f1a0c074387b2ec.zip
Make use of SASS modulesHEADmaster
Diffstat (limited to 'src/_functions.scss')
-rw-r--r--src/_functions.scss320
1 files changed, 160 insertions, 160 deletions
diff --git a/src/_functions.scss b/src/_functions.scss
index 0d139b4..74cc1b5 100644
--- a/src/_functions.scss
+++ b/src/_functions.scss
@@ -19,21 +19,21 @@
19$numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9); 19$numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9);
20 20
21$units: ( 21$units: (
22 'px': 1px, 22 'px': 1px,
23 'cm': 1cm, 23 'cm': 1cm,
24 'mm': 1mm, 24 'mm': 1mm,
25 '%': 1%, 25 '%': 1%,
26 'ch': 1ch, 26 'ch': 1ch,
27 'pc': 1pc, 27 'pc': 1pc,
28 'in': 1in, 28 'in': 1in,
29 'em': 1em, 29 'em': 1em,
30 'rem': 1rem, 30 'rem': 1rem,
31 'pt': 1pt, 31 'pt': 1pt,
32 'ex': 1ex, 32 'ex': 1ex,
33 'vw': 1vw, 33 'vw': 1vw,
34 'vh': 1vh, 34 'vh': 1vh,
35 'vmin': 1vmin, 35 'vmin': 1vmin,
36 'vmax': 1vmax 36 'vmax': 1vmax
37); 37);
38 38
39/// 39///
@@ -46,13 +46,13 @@ $units: (
46/// @return {string} A string with all instances of $search replaced with $replace 46/// @return {string} A string with all instances of $search replaced with $replace
47/// 47///
48@function str-replace($string, $search, $replace) { 48@function str-replace($string, $search, $replace) {
49 $index: string.index($string, $search); 49 $index: string.index($string, $search);
50 50
51 @if $index { 51 @if $index {
52 @return string.slice($string, 1, $index - 1) + $replace + str-replace(string.slice($string, $index + string.length($search)), $search, $replace); 52 @return string.slice($string, 1, $index - 1) + $replace + str-replace(string.slice($string, $index + string.length($search)), $search, $replace);
53 } 53 }
54 54
55 @return $string; 55 @return $string;
56} 56}
57 57
58/// 58///
@@ -64,17 +64,17 @@ $units: (
64/// @return {string} 64/// @return {string}
65/// 65///
66@function str-implode($list, $glue: '') { 66@function str-implode($list, $glue: '') {
67 $result: ''; 67 $result: '';
68 68
69 @each $item in $list { 69 @each $item in $list {
70 $result: $result + if(list.length($item) > 1, str-implode($item, $glue), $item); 70 $result: $result + if(list.length($item) > 1, str-implode($item, $glue), $item);
71 71
72 @if $item != list.nth($list, list.length($list)) { 72 @if $item != list.nth($list, list.length($list)) {
73 $result: $result + $glue; 73 $result: $result + $glue;
74 } 74 }
75 } 75 }
76 76
77 @return $result; 77 @return $result;
78} 78}
79 79
80/// 80///
@@ -87,17 +87,17 @@ $units: (
87/// @return {list} A slice of the list 87/// @return {list} A slice of the list
88/// 88///
89@function list-slice($list, $start: 1, $end: list.length($list)) { 89@function list-slice($list, $start: 1, $end: list.length($list)) {
90 $result: (); 90 $result: ();
91 91
92 @if $end >= $start { 92 @if $end >= $start {
93 @for $i from $start through $end { 93 @for $i from $start through $end {
94 @if $i != 0 { 94 @if $i != 0 {
95 $result: list.append($result, list.nth($list, $i), list.separator($list)); 95 $result: list.append($result, list.nth($list, $i), list.separator($list));
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 @return $result; 100 @return $result;
101} 101}
102 102
103/// 103///
@@ -109,15 +109,15 @@ $units: (
109/// @return {list} A list with $value at the beginning, followed by the other items 109/// @return {list} A list with $value at the beginning, followed by the other items
110/// 110///
111@function list-prepend($list, $value) { 111@function list-prepend($list, $value) {
112 $result: list.append((), $value, list.separator($list)); 112 $result: list.append((), $value, list.separator($list));
113 113
114 @if list.length($list) > 0 { 114 @if list.length($list) > 0 {
115 @for $i from 1 through list.length($list) { 115 @for $i from 1 through list.length($list) {
116 $result: list.append($result, list.nth($list, $i), list.separator($list)); 116 $result: list.append($result, list.nth($list, $i), list.separator($list));
117 } 117 }
118 } 118 }
119 119
120 @return $result; 120 @return $result;
121} 121}
122 122
123/// 123///
@@ -128,15 +128,15 @@ $units: (
128/// @return {list} Teh reversed list 128/// @return {list} Teh reversed list
129/// 129///
130@function list-reverse($list) { 130@function list-reverse($list) {
131 @if list.length($list) == 0 { 131 @if list.length($list) == 0 {
132 @return $list; 132 @return $list;
133 } 133 }
134 134
135 $result: (); 135 $result: ();
136 @for $i from list.length($list) * -1 through -1 { 136 @for $i from list.length($list) * -1 through -1 {
137 $result: list.append($result, list.nth($list, math.abs($i))); 137 $result: list.append($result, list.nth($list, math.abs($i)));
138 } 138 }
139 @return $result; 139 @return $result;
140} 140}
141 141
142/// 142///
@@ -150,51 +150,51 @@ $units: (
150/// @return {list} Sorted list 150/// @return {list} Sorted list
151/// 151///
152@function quicksort($l, $left: 1, $right: list.length($l)) { 152@function quicksort($l, $left: 1, $right: list.length($l)) {
153 @if $left < $right { 153 @if $left < $right {
154 $pvr: quicksort-partition($l, $left, $right); 154 $pvr: quicksort-partition($l, $left, $right);
155 $pivot: list.nth($pvr, 1); 155 $pivot: list.nth($pvr, 1);
156 $l: list.nth($pvr, 2); 156 $l: list.nth($pvr, 2);
157 $l: quicksort($l, $left, $pivot); 157 $l: quicksort($l, $left, $pivot);
158 $l: quicksort($l, $pivot + 1, $right); 158 $l: quicksort($l, $pivot + 1, $right);
159 } 159 }
160 160
161 @return $l; 161 @return $l;
162} 162}
163 163
164/// 164///
165/// @access private 165/// @access private
166/// 166///
167@function quicksort-partition($l, $left, $right) { 167@function quicksort-partition($l, $left, $right) {
168 $start: true; 168 $start: true;
169 $i: $left; 169 $i: $left;
170 $j: $right - 1; 170 $j: $right - 1;
171 $pivot: list.nth($l, $right); 171 $pivot: list.nth($l, $right);
172 172
173 @while ($i < $j) or $start { 173 @while ($i < $j) or $start {
174 @while (list.nth($l, $i) < $pivot) and ($i < $right - 1) { 174 @while (list.nth($l, $i) < $pivot) and ($i < $right - 1) {
175 $i: $i + 1; 175 $i: $i + 1;
176 } 176 }
177 177
178 @while (list.nth($l, $j)>= $pivot) and ($j > $left) { 178 @while (list.nth($l, $j)>= $pivot) and ($j > $left) {
179 $j: $j - 1; 179 $j: $j - 1;
180 } 180 }
181 181
182 @if $i < $j { 182 @if $i < $j {
183 $i-val: list.nth($l, $i); 183 $i-val: list.nth($l, $i);
184 $l: list.set-nth($l, $i, list.nth($l, $j)); 184 $l: list.set-nth($l, $i, list.nth($l, $j));
185 $l: list.set-nth($l, $j, $i-val); 185 $l: list.set-nth($l, $j, $i-val);
186 } 186 }
187 187
188 $start: false; 188 $start: false;
189 } 189 }
190 190
191 @if list.nth($l, $i) > $pivot { 191 @if list.nth($l, $i) > $pivot {
192 $i-val: list.nth($l, $i); 192 $i-val: list.nth($l, $i);
193 $l: list.set-nth($l, $i, list.nth($l, $right)); 193 $l: list.set-nth($l, $i, list.nth($l, $right));
194 $l: list.set-nth($l, $right, $i-val); 194 $l: list.set-nth($l, $right, $i-val);
195 } 195 }
196 196
197 @return $i $l; 197 @return $i $l;
198} 198}
199 199
200/// 200///
@@ -208,10 +208,10 @@ $units: (
208/// @return {any} Either the value assigned to $key or $default 208/// @return {any} Either the value assigned to $key or $default
209/// 209///
210@function map-get-default($map, $key, $keys...) { 210@function map-get-default($map, $key, $keys...) {
211 $default: list.nth($keys, list.length($keys)); 211 $default: list.nth($keys, list.length($keys));
212 $keys: list-slice($keys, 1, list.length($keys) - 1); 212 $keys: list-slice($keys, 1, list.length($keys) - 1);
213 213
214 @return if(map.has-key($map, $key, $keys...), map.get($map, $key, $keys...), $default); 214 @return if(map.has-key($map, $key, $keys...), map.get($map, $key, $keys...), $default);
215} 215}
216 216
217/// 217///
@@ -222,29 +222,29 @@ $units: (
222/// @return {string} 222/// @return {string}
223/// 223///
224@function map-print($map) { 224@function map-print($map) {
225 $output: ''; 225 $output: '';
226 226
227 @each $key, $value in $map { 227 @each $key, $value in $map {
228 $value-str: ''; 228 $value-str: '';
229 229
230 @if meta.type-of($value) == map { 230 @if meta.type-of($value) == map {
231 $value-str: '[ ' + map-print($value) + ' ]'; 231 $value-str: '[ ' + map-print($value) + ' ]';
232 } @else if meta.type-of($value) == list { 232 } @else if meta.type-of($value) == list {
233 $value-str: '[ ' + str-implode($value, ', ') + ' ]'; 233 $value-str: '[ ' + str-implode($value, ', ') + ' ]';
234 } @else if meta.type-of($value) == string { 234 } @else if meta.type-of($value) == string {
235 $value-str: '\'' + $value + '\''; 235 $value-str: '\'' + $value + '\'';
236 } @else { 236 } @else {
237 $value-str: $value; 237 $value-str: $value;
238 } 238 }
239 239
240 @if $output == '' { 240 @if $output == '' {
241 $output: $key + ': ' + $value-str; 241 $output: $key + ': ' + $value-str;
242 } @else { 242 } @else {
243 $output: $output + ', ' + $key + ': ' + $value-str; 243 $output: $output + ', ' + $key + ': ' + $value-str;
244 } 244 }
245 } 245 }
246 246
247 @return $output; 247 @return $output;
248} 248}
249 249
250/// 250///
@@ -256,35 +256,35 @@ $units: (
256/// @return {bool} `true` if the selector matches at least one suffix, otherwise `false`. 256/// @return {bool} `true` if the selector matches at least one suffix, otherwise `false`.
257/// 257///
258@function selector-suffix-match($selector, $suffixes) { 258@function selector-suffix-match($selector, $suffixes) {
259 $match: true; 259 $match: true;
260 260
261 @each $sel in $selector { 261 @each $sel in $selector {
262 @if $match { 262 @if $match {
263 $sel-match: false; 263 $sel-match: false;
264 264
265 @each $suffix in $suffixes { 265 @each $suffix in $suffixes {
266 @if not $sel-match { 266 @if not $sel-match {
267 $suf-match: true; 267 $suf-match: true;
268 268
269 @for $i from 1 through list.length($suffix) { 269 @for $i from 1 through list.length($suffix) {
270 @if $suf-match and (list.nth($sel, -$i) != list.nth($suffix, -$i)) { 270 @if $suf-match and (list.nth($sel, -$i) != list.nth($suffix, -$i)) {
271 $suf-match: false; 271 $suf-match: false;
272 } 272 }
273 } 273 }
274 274
275 @if $suf-match { 275 @if $suf-match {
276 $sel-match: true; 276 $sel-match: true;
277 } 277 }
278 } 278 }
279 } 279 }
280 280
281 @if not $sel-match { 281 @if not $sel-match {
282 $match: false; 282 $match: false;
283 } 283 }
284 } 284 }
285 } 285 }
286 286
287 @return $match; 287 @return $match;
288} 288}
289 289
290/// 290///
@@ -295,7 +295,7 @@ $units: (
295/// @return {number} Unit-less variable 295/// @return {number} Unit-less variable
296/// 296///
297@function strip-unit($n) { 297@function strip-unit($n) {
298 @return math.div($n, $n * 0 + 1); 298 @return math.div($n, $n * 0 + 1);
299} 299}
300 300
301/// 301///
@@ -307,7 +307,7 @@ $units: (
307/// @return {number} Pixel value converted to rem 307/// @return {number} Pixel value converted to rem
308/// 308///
309@function px-to-rem($size, $base: vars.$root-size) { 309@function px-to-rem($size, $base: vars.$root-size) {
310 @return math.div($size, $base) * 1rem; 310 @return math.div($size, $base) * 1rem;
311} 311}
312 312
313/// 313///
@@ -318,35 +318,35 @@ $units: (
318/// @return {number} 318/// @return {number}
319/// 319///
320@function to-number($value) { 320@function to-number($value) {
321 @if meta.type-of($value) == 'number' { 321 @if meta.type-of($value) == 'number' {
322 @return $value; 322 @return $value;
323 } 323 }
324 @if meta.type-of($value) != 'string' { 324 @if meta.type-of($value) != 'string' {
325 @error 'Value for `to-number` should be a number or a string.'; 325 @error 'Value for `to-number` should be a number or a string.';
326 } 326 }
327 327
328 $result: 0; 328 $result: 0;
329 $digits: 0; 329 $digits: 0;
330 $minus: string.slice($value, 1, 1) == '-'; 330 $minus: string.slice($value, 1, 1) == '-';
331 331
332 @for $i from if($minus, 2, 1) through string.length($value) { 332 @for $i from if($minus, 2, 1) through string.length($value) {
333 $character: string.slice($value, $i, $i); 333 $character: string.slice($value, $i, $i);
334 334
335 @if not list.index(map.keys($numbers), $character) and $character != '.' { 335 @if not list.index(map.keys($numbers), $character) and $character != '.' {
336 @return to-length(if($minus, -$result, $result), string.slice($value, $i)); 336 @return to-length(if($minus, -$result, $result), string.slice($value, $i));
337 } 337 }
338 338
339 @if $character == '.' { 339 @if $character == '.' {
340 $digits: 1; 340 $digits: 1;
341 } @else if $digits == 0 { 341 } @else if $digits == 0 {
342 $result: $result * 10 + map.get($numbers, $character); 342 $result: $result * 10 + map.get($numbers, $character);
343 } @else { 343 } @else {
344 $digits: $digits * 10; 344 $digits: $digits * 10;
345 $result: $result + math.div(map.get($numbers, $character), $digits); 345 $result: $result + math.div(map.get($numbers, $character), $digits);
346 } 346 }
347 } 347 }
348 348
349 @return if($minus, -$result, $result); 349 @return if($minus, -$result, $result);
350} 350}
351 351
352/// 352///
@@ -358,11 +358,11 @@ $units: (
358/// @return {number} $value expressed in $unit 358/// @return {number} $value expressed in $unit
359/// 359///
360@function to-length($value, $unit) { 360@function to-length($value, $unit) {
361 @if not list.index(map.keys($units), $unit) { 361 @if not list.index(map.keys($units), $unit) {
362 @error 'Invalid unit `#{$unit}`.'; 362 @error 'Invalid unit `#{$unit}`.';
363 } 363 }
364 364
365 @return $value * map.get($units, $unit); 365 @return $value * map.get($units, $unit);
366} 366}
367 367
368/// 368///
@@ -371,5 +371,5 @@ $units: (
371/// @content 371/// @content
372/// 372///
373@mixin execute { 373@mixin execute {
374 @content; 374 @content;
375} 375}