| 1 |
// Common LESS mixin library for MediaWiki |
| 2 |
// |
| 3 |
// By default the folder containing this file is included in the LESS import paths, |
| 4 |
// which makes this file importable by all less files via `@import 'mediawiki.mixins.less';`. |
| 5 |
// |
| 6 |
// The mixins included below are considered a public interface for MediaWiki extensions. |
| 7 |
// The signatures of parameterized mixins should be kept as stable as possible. |
| 8 |
// |
| 9 |
// See <http://lesscss.org/#-mixins> for more information about how to write mixins. |
| 10 |
|
| 11 |
/* stylelint-disable selector-class-pattern */ |
| 12 |
|
| 13 |
// Deprecated in MW v1.43, use linear-gradient directly |
| 14 |
.horizontal-gradient( @startColor: #808080, @endColor: #fff, @startPos: 0, @endPos: 100% ) { |
| 15 |
background-color: average( @startColor, @endColor ); |
| 16 |
background-image: linear-gradient( to right, @startColor @startPos, @endColor @endPos ); |
| 17 |
} |
| 18 |
|
| 19 |
// Deprecated in MW v1.43, use linear-gradient directly |
| 20 |
.vertical-gradient( @startColor: #808080, @endColor: #fff, @startPos: 0, @endPos: 100% ) { |
| 21 |
background-color: average( @startColor, @endColor ); |
| 22 |
background-image: linear-gradient( to bottom, @startColor @startPos, @endColor @endPos ); |
| 23 |
} |
| 24 |
|
| 25 |
.hyphens( @value: auto ) { |
| 26 |
& when ( @value = auto ) { |
| 27 |
// Legacy `word-wrap`; Edge 12+, Firefox 3.5+, Chrome 4+, Safari 3.1+, |
| 28 |
// Opera 11.5+, iOS 3.2+, Android 2.1+ |
| 29 |
// `overflow-wrap` is W3 standard, but it doesn't seem as if browser vendors |
| 30 |
// will abandon `word-wrap` (it has wider support), therefore no duplication. |
| 31 |
word-wrap: break-word; |
| 32 |
} |
| 33 |
& when ( @value = none ) { |
| 34 |
word-wrap: normal; |
| 35 |
} |
| 36 |
|
| 37 |
// CSS3 hyphenation |
| 38 |
// Chrome < 55 support "-webkit-hyphens: none", |
| 39 |
// but not the "auto" property. It is advisable to set the @lang attribute |
| 40 |
// on the HTML element to enable hyphenation support and improve accessibility. |
| 41 |
// Chrome 55-87 only supports `auto` exclusively on Mac platform. |
| 42 |
/* stylelint-disable plugin/no-unsupported-browser-features */ |
| 43 |
-webkit-hyphens: @value; // Safari 5.1+, iOS 4.2+ |
| 44 |
hyphens: @value; // Firefox 43+, Chrome 55+, Safari 17+, iOS 17+, Android 62+, UC Browser 11.8+, Samsung 6.2+ |
| 45 |
/* stylelint-enable plugin/no-unsupported-browser-features */ |
| 46 |
} |
| 47 |
|
| 48 |
// Use to truncate overflow text with value of `ellipsis` (mixin default) |
| 49 |
// a custom string (Firefox 9+ only). |
| 50 |
// Recommended usage: `text-overflow( @visible: false )` for best readability. |
| 51 |
.text-overflow( @visible: false, @value: ellipsis ) { |
| 52 |
& when ( @visible = true ) { |
| 53 |
overflow: visible; |
| 54 |
text-overflow: clip; |
| 55 |
white-space: normal; |
| 56 |
} |
| 57 |
& when ( @visible = false ) { |
| 58 |
overflow: hidden; |
| 59 |
text-overflow: @value; |
| 60 |
white-space: nowrap; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
// Enable (`text` or `element`) or prevent (`none`) text/element selection. |
| 65 |
// Since MW 1.38 |
| 66 |
.user-select( @value ) { |
| 67 |
-webkit-user-select: @value; // Chrome 4-53, Safari 3.1-, Opera 15-40 |
| 68 |
-moz-user-select: @value; // Firefox 2-68 |
| 69 |
user-select: @value; |
| 70 |
} |
| 71 |
|
| 72 |
// In the future this can be simply migrated to `margin-inline: @start @end;` |
| 73 |
// Since MW 1.43 |
| 74 |
.margin-inline( @start, @end ) { |
| 75 |
margin-left: @start; |
| 76 |
margin-right: @end; |
| 77 |
-webkit-margin-start: @start; // Archaic WebKit/Chrome versions |
| 78 |
-webkit-margin-end: @end; |
| 79 |
/* stylelint-disable declaration-block-no-redundant-longhand-properties */ |
| 80 |
margin-inline-start: @start; // Firefox 41, Safari 12.1, Chrome 69, Opera 56 |
| 81 |
margin-inline-end: @end; |
| 82 |
/* stylelint-enable declaration-block-no-redundant-longhand-properties */ |
| 83 |
} |
| 84 |
|
| 85 |
// In the future this can be simply migrated to `padding-inline: @start @end;` |
| 86 |
// Since MW 1.43 |
| 87 |
.padding-inline( @start, @end ) { |
| 88 |
padding-left: @start; |
| 89 |
padding-right: @end; |
| 90 |
-webkit-padding-start: @start; // Archaic WebKit/Chrome versions |
| 91 |
-webkit-padding-end: @end; |
| 92 |
/* stylelint-disable declaration-block-no-redundant-longhand-properties */ |
| 93 |
padding-inline-start: @start; // Firefox 41, Safari 12.1, Chrome 69, Opera 56 |
| 94 |
padding-inline-end: @end; |
| 95 |
/* stylelint-enable declaration-block-no-redundant-longhand-properties */ |
| 96 |
} |
| 97 |
|
| 98 |
// Not supported in Chrome <= 55, Firefox <= 31, Opera <= 41 |
| 99 |
.position-sticky() { |
| 100 |
-webkit-position: sticky; // Support: Safari < 13 |
| 101 |
/* stylelint-disable-next-line plugin/no-unsupported-browser-features */ |
| 102 |
position: sticky; |
| 103 |
} |
| 104 |
|
| 105 |
.column-count( @value ) { |
| 106 |
-moz-column-count: @value; // Firefox 2-51 |
| 107 |
column-count: @value; // Chrome 50+, Firefox 52+, Edge, Opera 11.5+, Android 90+ |
| 108 |
} |
| 109 |
|
| 110 |
.column-width( @value ) { |
| 111 |
-moz-column-width: @value; // Firefox 1.5-49 |
| 112 |
column-width: @value; // Chrome 50+, Firefox 50+, Edge, Opera 11.5+, Safari 9+ |
| 113 |
} |
| 114 |
|
| 115 |
.column-break-inside-avoid() { |
| 116 |
page-break-inside: avoid; // Firefox 1.5-91 |
| 117 |
break-inside: avoid-column; // Chrome 80+, Firefox 92+, Edge 80+, Safari 13.1+, Opera 67+ |
| 118 |
} |
| 119 |
|
| 120 |
// Deprecated in MW v1.43.0, use just CSS property now. |
| 121 |
.column-break-after-avoid() { |
| 122 |
// Not supported by Firefox |
| 123 |
break-after: avoid-column; // Chrome 80+, Firefox 92+, Edge 80+, Safari 13.1+, Opera 67+ |
| 124 |
} |
| 125 |
|
| 126 |
.flex-display( @display: flex ) { |
| 127 |
display: @display; |
| 128 |
} |
| 129 |
|
| 130 |
.flex-wrap( @wrap: wrap ) { |
| 131 |
flex-wrap: @wrap; |
| 132 |
} |
| 133 |
|
| 134 |
.flex( @grow: 1, @shrink: 1, @width: auto, @order: 1 ) { |
| 135 |
// Current spec |
| 136 |
justify-content: space-between; |
| 137 |
width: @width; // Fallback for flex-basis |
| 138 |
flex: @grow @shrink @width; |
| 139 |
order: @order; |
| 140 |
} |
| 141 |
|
| 142 |
// “Clearfix Reloaded” Mixin |
| 143 |
// The mixin is used on a container with floating children. |
| 144 |
// Margin collapsing is a feature, not a bug, hence relying on `display: block` as default. |
| 145 |
// With `.mixin-clearfix( @collapse: false; );` you call it to let `margin`s not collapse. |
| 146 |
// See https://www.cssmojo.com/the-very-latest-clearfix-reloaded/ |
| 147 |
// In future we might replace the `&:after` pseudo-element with |
| 148 |
// `display: flow-root;` altogether. |
| 149 |
// Support: Firefox 3.5+, Safari 4+, Chrome, Opera 15+ |
| 150 |
.mixin-clearfix( @collapse: true ) { |
| 151 |
&::after { |
| 152 |
clear: both; |
| 153 |
|
| 154 |
// Margin collapsing as feature. Apply it. |
| 155 |
& when ( @collapse ) { |
| 156 |
content: ''; |
| 157 |
display: block; |
| 158 |
} |
| 159 |
} |
| 160 |
// Margin collapsing as bug. Prevent it. |
| 161 |
& when not ( @collapse ) { |
| 162 |
&::before, |
| 163 |
&::after { |
| 164 |
content: ''; |
| 165 |
display: table; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
/* stylelint-disable selector-no-vendor-prefix */ |
| 171 |
.mixin-placeholder( @rules ) { |
| 172 |
// Chrome 4-56, WebKit, Blink, Edge 12-18 |
| 173 |
&::-webkit-input-placeholder { |
| 174 |
@rules(); |
| 175 |
} |
| 176 |
// W3C Standard Selectors Level 4 |
| 177 |
&::placeholder { |
| 178 |
@rules(); |
| 179 |
} |
| 180 |
} |
| 181 |
/* stylelint-enable selector-no-vendor-prefix */ |
| 182 |
|
| 183 |
// Screen Reader Helper Mixin |
| 184 |
.mixin-screen-reader-text() { |
| 185 |
display: block; |
| 186 |
position: absolute !important; /* stylelint-disable-line declaration-no-important */ |
| 187 |
clip: rect( 1px, 1px, 1px, 1px ); |
| 188 |
width: 1px; |
| 189 |
height: 1px; |
| 190 |
margin: -1px; |
| 191 |
border: 0; |
| 192 |
padding: 0; |
| 193 |
overflow: hidden; |
| 194 |
} |