This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
/
_sunglass.scss
703 lines (564 loc) · 15.3 KB
/
_sunglass.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/*!
* Sunglass - A mixin and functions library for Sass
* v3.0.5
* https://github.com/devatrox/Sunglass
*/
$defaults: (
base-grid: 12,
base-gap: 20px,
global-light: 90deg,
base-img-path: "../images/",
base-icon-path: "../icons/",
base-font-size: 16px,
rem-fallback: true
);
$sunglass: () !default;
$settings: map-merge($defaults, $sunglass);
@if (variable-exists(base-grid)) {
$settings: map-merge($defaults, (base-grid: $base-grid)) !global;
}
@if (variable-exists(base-gap)) {
$settings: map-merge($defaults, (base-gap: $base-gap)) !global;
}
@if (variable-exists(global-light)) {
$settings: map-merge($defaults, (global-light: $global-light)) !global;
}
@if (variable-exists(base-img-path)) {
$settings: map-merge($defaults, (base-img-path: $base-img-path)) !global;
}
@if (variable-exists(base-icon-path)) {
$settings: map-merge($defaults, (base-icon-path: $base-icon-path)) !global;
}
@if (variable-exists(base-font-size)) {
$settings: map-merge($defaults, (base-font-size: $base-font-size)) !global;
}
@if (variable-exists(rem-fallback)) {
$settings: map-merge($defaults, (rem-fallback: $rem-fallback)) !global;
}
$_base-grid: map-get($settings, base-grid);
$_base-gap: map-get($settings, base-gap);
$_global-light: map-get($settings, global-light);
$_base-img-path: map-get($settings, base-img-path);
$_base-icon-path: map-get($settings, base-icon-path);
$_base-font-size: map-get($settings, base-font-size);
$_rem-fallback: map-get($settings, rem-fallback);
// Formulars provided by easyrgb.com and rapidtables.com
@function _cmy($cyan, $magenta, $yellow) {
$red: (1 - ($cyan / 100)) * 255;
$green: (1 - ($magenta / 100)) * 255;
$blue: (1 - ($yellow / 100)) * 255;
@return rgb($red, $green, $blue);
}
@function _cmya($cyan, $magenta, $yellow, $alpha) {
@return rgba(_cmy($cyan, $magenta, $yellow), $alpha);
}
@function _cmyk($cyan, $magenta, $yellow, $key) {
$red: (1 - ($key / 100)) * (1 - ($cyan / 100)) * 255;
$green: (1 - ($key / 100)) * (1 - ($magenta / 100)) * 255;
$blue: (1 - ($key / 100)) * (1 - ($yellow / 100)) * 255;
@return rgb($red, $green, $blue);
}
@function _cmyka($cyan, $magenta, $yellow, $key, $alpha) {
@return rgba(_cmyk($cyan, $magenta, $yellow, $key), $alpha);
}
// Formular provided by easyrgb.com
@function _hsv($hue, $saturation, $value) {
$hue: ($hue * 100 / 360) / 100;
$saturation: $saturation / 100;
$value: $value / 100;
$red: null;
$green: null;
$blue: null;
$var_1: null;
$var_2: null;
$var_3: null;
$var_b: null;
$var_g: null;
$var_h: null;
$var_i: null;
$var_r: null;
@if ($saturation == 0) {
$red: $value * 255;
$green: $value * 255;
$blue: $value * 255;
}
@else {
$var_h: $hue * 6;
@if ( $var_h == 6 ) {
$var_h: 0;
}
$var_i: floor( $var_h );
$var_1: $value * ( 1 - $saturation );
$var_2: $value * ( 1 - $saturation * ( $var_h - $var_i ) );
$var_3: $value * ( 1 - $saturation * ( 1 - ( $var_h - $var_i ) ) );
@if ( $var_i == 0 ) {
$var_r: $value;
$var_g: $var_3;
$var_b: $var_1;
}
@else if ( $var_i == 1 ) {
$var_r: $var_2;
$var_g: $value;
$var_b: $var_1;
}
@else if ( $var_i == 2 ) {
$var_r: $var_1;
$var_g: $value;
$var_b: $var_3;
}
@else if ( $var_i == 3 ) {
$var_r: $var_1;
$var_g: $var_2;
$var_b: $value;
}
@else if ( $var_i == 4 ) {
$var_r: $var_3;
$var_g: $var_1;
$var_b: $value;
}
@else {
$var_r: $value;
$var_g: $var_1;
$var_b: $var_2;
}
$red: $var_r * 255;
$green: $var_g * 255;
$blue: $var_b * 255;
}
@return rgb($red, $green, $blue);
}
@function _hsva($hue, $saturation, $value, $alpha) {
@return rgba(_hsv($hue, $saturation, $value), $alpha);
}
// HSB - because Photoshop
@function _hsb($hue, $saturation, $brightness) {
@return _hsv($hue, $saturation, $brightness);
}
@function _hsba($hue, $saturation, $brightness, $alpha) {
@return _hsva($hue, $saturation, $brightness, $alpha);
}
@function _random-color($palette: false) {
$rgb: "";
@if $palette {
@if type-of($palette) == string {
@if $palette == monochrome {
$rgb: if(round(random()) == 1, #000, #fff);
}
@else if $palette == grayscale or $palette == greyscale {
$rgb: hsl(0, 0, random(100) + 0%);
}
@else {
@warn "Invalid keywords (#{$palette})";
}
}
@else {
@warn "#{$palette} not a string";
}
}
@else {
$red: random(255);
$green: random(255);
$blue: random(255);
$rgb: rgb($red, $green, $blue);
}
@return $rgb;
}
// todo: pastel, gradient (hue value)
@function _shade($color, $percent){
@return mix(black, $color, $percent);
}
@function _tint($color, $percent){
@return mix(white, $color, $percent);
}
@function _filter($list, $filters...) {
$output: ();
@each $item in $list {
@if index($filters, $item) {
// silence
}
@else {
$output: append($output, $item, list-separator($list));
}
}
@return $output;
}
@function _compact($list) {
@return _filter($list, false, "");
}
@function _split($string, $substr: false, $limit: str-length($string)) {
$list: ();
@if $substr == false {
$list: append($list, $string);
}
@else if $substr == '' {
@while str-length($string) > 0 {
$list: append($list, str-slice($string, 0, 1));
$string: str-slice($string, 2);
}
}
@else if $substr {
@if _str-contains($string, $substr) {
$l: true;
$c: _str-count($string, $substr);
@for $i from 1 through $c {
$start: str-index($string, $substr);
$end: $start + str-length($substr) - 1;
@if $start != 1 {
$list: append($list, str-slice($string, 0, $start - 1));
$string: str-slice($string, $end + 1, str-length($string));
}
@else {
$string: str-slice($string, $end + 1, str-length($string));
}
}
@if str-length($string) > 0 {
$list: append($list, str-slice($string, 0));
}
}
@else {
@warn '"#{$string}" does not contain "#{$substr}"!';
$list: append($list, $string);
}
}
@return $list;
}
@function _coordinates($angle, $length: 1px) {
$aliases: (
n: 90deg,
ne: 45deg,
e: 0deg,
se: 315deg,
s: 270deg,
sw: 225deg,
w: 180deg,
nw: 135deg
);
@if map-has-key($aliases, $angle) {
$angle: to-lower-case($angle);
$angle: map-get($aliases, $angle);
}
@if type-of($angle) != number {
@warn "#{$angle} NaN";
}
@if type-of($length) != number {
@warn "#{$length} NaN";
}
@if unit($length) != "px" {
@warn "#{$length}; Unit must be px";
}
$x: _strip-unit($length) * _cos($angle);
$y: _strip-unit($length) * _sin($angle);
$y: _opposite($y);
@return ($x + 0px) ($y + 0px);
}
@function _coords($angle, $length: 1px) {
@return _coordinates($angle, $length);
}
@function _opposite($numbers) {
$output: ();
@if type-of($numbers) == number {
$output: $numbers * -1;
}
@else if type-of($numbers) == list {
@each $number in $numbers {
@if type-of($number) == number {
$output: append($output, $number * -1);
}
@else {
@warn "#{$number} NaN";
}
}
}
@else {
@warn "#{$numbers} NaN";
}
@return $output;
}
@function _rem-to-px($size) {
@return (_strip-unit($size) * _strip-unit($_base-font-size)) + 0px;
}
// SASSY MATH
// https://github.com/Team-Sass/Sassy-math
// My light functions depend on these so I stole it
// Prefixed functions to avoid conflicts
$sg-pi: 3.1415926535897932384626433832795028841971693993751;
$sg-iter: 50;
@function _exponent($base, $exponent) {
// reset value
$value: $base;
// positive intergers get multiplied
@if $exponent > 1 {
@for $i from 2 through $exponent {
$value: $value * $base; } }
// negitive intergers get divided. A number divided by itself is 1
@if $exponent < 1 {
@for $i from 0 through -$exponent {
$value: $value / $base; } }
// return the last value written
@return $value;
}
@function _factorial($number) {
// reset value
$value: 1;
// positive intergers get multiplied
@if $number > 0 {
@for $i from 1 through $number {
$value: $value * $i;
}
}
@return $value;
}
@function _maclaurin($start, $key, $number) {
$value: $start;
$add: 0;
@for $i from 1 through $sg-iter {
@if $add == 0 {
$value: $value - ( _exponent($number, $key) / -factorial($key) );
$add: 1;
}
@else {
$value: $value + ( _exponent($number, $key) / -factorial($key) );
$add: 0;
}
$key: $key + 2;
}
@return $value;
}
@function _deg-to-rad($number) {
@return $number * $sg-pi / 180deg;
}
@function _rad-to-deg($number) {
@return $number * 180deg / $sg-pi;
}
@function _sin($number, $unit: "deg") {
@if $unit == "deg" {
$number: _deg-to-rad($number);
}
@return _maclaurin($number, 3, $number);
}
@function _cos($number, $unit: "deg") {
@if $unit == "deg" {
$number: _deg-to-rad($number);
}
@return _maclaurin(1, 2, $number);
}
@function _strip-unit($number) {
@if type-of($number) != number {
@warn "#{$number} NaN";
}
@return $number / ($number * 0 + 1)
}
@function _str-append($string, $insert) {
$string: if($string == null, "", $string);
@return str-insert($string, $insert, str-length($string) + 1);
}
@function _str-contains($string, $substr, $pos: 0) {
$string: str-slice($string, $pos);
@if str-index($string, $substr) != null {
@return true;
}
@else {
@return false;
}
}
@function _str-count($string, $substring) {
$counter: 0;
@for $i from 1 through str-length($string) {
$index: str-index($string, $substring);
@if $index and $index > 0 {
$counter: $counter + 1;
$string: str-slice($string, $index + 1, str-length($string));
}
}
@return $counter;
}
@function _str-join($list, $separator: ",") {
$string: "";
@for $i from 1 through length($list) {
$string: _str-append($string, #{nth($list, $i)});
@if $i != length($list) {
$string: _str-append($string, $separator);
}
}
@return $string;
}
@function _str-prepend($string, $insert) {
$string: if($string == null, "", $string);
@return str-insert($string, $insert, 1);
}
@function _global-light($length: 1px) {
@return _light-source($_global-light, $length);
}
@function _global-light-inset($length: 1px) {
@return _opposite(_global-light($length));
}
// Shorthands
@function _g($length: 1px) {
@return _global-light($length);
}
@function _gi($length: 1px) {
@return _global-light-inset($length);
}
@mixin _letterpress($background, $alpha: 0.6, $light-source: $_global-light) {
@if lightness($background) > 50% {
text-shadow: rgba(white, $alpha) _light-source($light-source) 0;
} @else {
text-shadow: rgba(black, $alpha) _light-source-inset($light-source) 0;
}
color: _readable($background, 10%);
}
@function _light-source($source, $length: 1px) {
@return _opposite(_coordinates($source, $length));
}
@function _local-light($string, $length: 1px) {
@return _light-source($string, $length);
}
@function _local-light-inset($string, $length: 1px) {
@return _opposite(_local-light($string, $length));
}
@function _long-shadow($bgcolor: #fff, $length: 100px, $opacity: 0.1, $strength: 0, $light: $_global-light) {
@if unit($length) == "px" or unitless($length) {
$length: _strip-unit($length);
}
@else {
@warn "Invalid unit #{$length}! Please use pixels";
}
$shadow-list: null;
$x: 1;
$y: 1;
$l: _light-source($light);
@for $i from 1 through $length {
$o: ($opacity - (($opacity - ($opacity * $strength)) * ($i * 100 / $length) / 100)) * 100%;
$x: nth($l, 1) * $i;
$y: nth($l, 2) * $i;
$shadow-list: append($shadow-list, mix(black, $bgcolor, $o) $x $y 0, comma);
}
@if alpha($bgcolor) < 1 {
@warn "No alpha allowed (#{$bgcolor})!";
@return null;
}
@else {
@return $shadow-list;
}
}
// For when you don't need any other shadows on the element
@mixin _long-box-shadow($bgcolor: #fff, $length: 100px, $opacity: 0.1, $strength: 0, $light: $_global-light) {
box-shadow: _long-shadow($bgcolor, $length, $opacity, $strength, $light);
}
@mixin _long-text-shadow($bgcolor: #fff, $length: 100px, $opacity: 0.1, $strength: 0, $light: $_global-light) {
text-shadow: _long-shadow($bgcolor, $length, $opacity, $strength, $light);
}
@function _readable($background, $alpha: 10%) {
@if lightness($background) > 50% {
@return mix($background, black, $alpha);
} @else {
@return mix($background, white, $alpha);
}
}
// This is just a silly named CSS3 "filter" mixin and it only works in Webkit-based browsers as of now
// See http://caniuse.com/#feat=css-filters for compatibility
@mixin _sunglass($filter: brightness(50%)) {
-webkit-filter: $filter;
-moz-filter: $filter;
filter: $filter;
}
@mixin _column($span: 1, $push: 0, $gap: $_base-gap, $grid: $_base-grid) {
position: relative;
min-height: 1px;
padding-right: $gap/2;
padding-left: $gap/2;
float: left;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
@include _span($span, $grid);
@if $push >= 0 {
@include _push($push, $grid);
}
}
@mixin _first-column {
clear: left;
}
@mixin _generate-grid($grid-class, $span-class, $push-class: null, $grid: $_base-grid, $gap: $_base-gap) {
.#{$grid-class} {
@include _grid-container($gap);
> [class*="#{$span-class}"] {
@include _column(1, 0, $gap);
}
@for $i from 1 through $grid {
& > .#{$span-class}#{$i} {
@include _span($i, $grid);
}
}
@if $push-class != null {
@for $i from 0 through ($grid - 1) {
& > .#{$push-class}#{$i} {
@include _push($i, $grid);
}
}
}
}
}
@mixin _grid-container($gap: $_base-gap) {
margin-right: -($gap/2);
margin-left: -($gap/2);
@include _clearfix;
}
@mixin _push($i, $grid: $_base-grid) {
margin-left: _span($i, $grid);
}
@function _span($i, $grid: $_base-grid) {
@return (100% / $grid) * $i;
}
@mixin _span($i, $grid: $_base-grid) {
width: _span($i, $grid);
}
// Micro Clearfix by Nicolas Gallagher.
// http://nicolasgallagher.com/micro-clearfix-hack/
@mixin _clearfix {
*zoom: 1;
&:before,
&:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
}
@function _img($filename) {
@return url(#{$_base-img-path}#{$filename});
}
@function _icon($filename) {
@return url(#{$_base-icon-path}#{$filename});
}
@mixin _google-font($family, $styles: (), $protocol: null) {
$url: "//fonts.googleapis.com/css?family=";
@if $protocol {
$url: _str-prepend($url, $protocol + ":");
}
@if type-of($family) == string and _str-contains($family, " ") {
$family: _split($family, " ");
}
$family: _str-join($family, "+");
$url: _str-append($url, $family);
@if length($styles) != 0 {
$url: _str-append($url, ":");
$url: _str-append($url, _str-join($styles));
}
@import url(quote($url));
}
@mixin _rem($property, $value) {
@if ($_rem-fallback == true) {
#{$property}: _rem-to-px($value);
}
#{$property}: $value;
}
@mixin _font-size($value) {
@if unit($value) == rem {
@include _rem(font-size, $value);
}
@else {
font-size: $value;
}
}