This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
_polyfills.scss
139 lines (131 loc) · 3.67 KB
/
_polyfills.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
// Polyfills of Compass builtin functions for SassC compatibility.
//
// (SassC is a C++ port of Ruby Sass, roughly 20x faster)
//
// Note: unfortunately, we cannot define a function inside a
// `@if not function-exists(prefix-usage)` branch, which means we can't have
// transparently-defined polyfills included in both Compass & SassC contexts.
/// Whether a given capability should be prefixed for evergreen browsers.
$_capability-needs-prefixing: (
// http://shouldiprefix.com/#animations
css-animation: (
-moz: true,
-webkit: true,
),
// http://shouldiprefix.com/#transitions
css-transitions: (
-moz: true,
-o: true,
-webkit: true,
),
// http://shouldiprefix.com/#box-sizing
css3-boxsizing: (
-moz: true,
-webkit: true,
),
// http://shouldiprefix.com/#flexbox
flexbox: (
-webkit: true,
),
// http://shouldiprefix.com/#transforms
transforms2d: (
-moz: true,
-ms: true,
-webkit: true,
),
transforms3d: (
-moz: true,
-webkit: true,
),
// http://caniuse.com/#feat=user-select-none
user-select-none: (
-moz: true,
-ms: true,
-webkit: true,
),
);
/// The percent of users relying on a particular prefix (between 0 and 1).
///
/// This is used by Compass' vendor-specific prefix heuristics.
///
/// (see compass/core/sass_extensions/functions/cross_browser_support.rb)
@function prefix-usage($prefix, $capability, $capability-options) {
$needs: map-get($_capability-needs-prefixing, $capability);
@if not $needs {
@error 'TODO: please hard-code prefix-usage for #{$capability}.';
}
@return if(map-get($needs, $prefix), 1, 0);
}
$_prefixes-by-browser: (
android: -webkit,
android-chrome: -webkit,
android-firefox: -moz,
blackberry: -webkit,
chrome: -webkit,
firefox: -moz,
ie: -ms,
ie-mobile: -ms,
ios-safari: -webkit,
opera: (-o, -webkit),
opera-mini: -o,
opera-mobile: (-o, -webkit),
safari: -webkit,
);
/// Note: this is trivial to get from $_prefixes-by-browser, but we try and keep
/// the computational cost of these polyfills to a minimum.
$browsers-by-prefix: (
-moz: (android-firefox, firefox),
-ms: (ie, ie-mobile),
-o: (opera, opera-mini, opera-mobile),
-webkit: (android, android-chrome, blackberry, chrome, ios-safari, opera, opera-mobile, safari),
);
/// The known browsers.
///
/// If prefix is given, limits the returned browsers to those using the specified prefix.
///
/// (see compass/core/sass_extensions/functions/cross_browser_support.rb)
@function browsers($prefix: '') {
@if $prefix == '' {
@return map-keys($_prefixes-by-browser);
} @else {
@return map-get($browsers-by-prefix, $prefix);
}
}
@function _unique-values($list, $sorting-order: ()) {
$set: ();
@each $value in $list {
$set: map-merge($set, ($value: true));
}
$result: ();
@each $value in $sorting-order {
@if map-has-key($set, $value) {
$result: append($result, $value, comma);
$set: map-remove($set, $value);
}
}
@return join($result, map-keys($set), comma);
}
/// The prefixes used by the given browsers.
///
/// We sort the resulting prefixes to make testing easier
///
/// (see compass/core/sass_extensions/functions/cross_browser_support.rb)
@function browser-prefixes($browsers) {
$values: ();
@each $browser in $browsers {
$values: join($values, map-get($_prefixes-by-browser, $browser), comma);
}
@return _unique-values($values, map-keys($browsers-by-prefix));
}
/// Returns a new list after removing any non-true values.
///
/// (see compass/core/sass_extensions/functions/lists.rb)
@function compact($args...) {
$result: ();
@each $arg in $args {
@if $arg {
$result: append($result, $arg, comma);
}
}
@return $result;
}