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/** * A heuristic that applies CSS to tablet * viewports. * * Usage: * @include tablet-viewport() { * :host { * background-color: green; * } * } */ @mixin tablet-viewport() { @media screen and (min-width: 768px) { @content; } } /** * A heuristic that applies CSS to mobile * viewports (i.e. phones, not tablets). * * Usage: * @include mobile-viewport() { * :host { * background-color: blue; * } * } */ @mixin mobile-viewport() { @media screen and (max-width: 767px) { @content; } } @mixin input-cover() { @include position(0, null, null, 0); @include margin(0); position: absolute; width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; appearance: none; outline: none; &::-moz-focus-inner { border: 0; } } @mixin visually-hidden() { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; outline: 0; clip: rect(0 0 0 0); opacity: 0; overflow: hidden; -webkit-appearance: none; -moz-appearance: none; } @mixin text-inherit() { font-family: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; letter-spacing: inherit; text-decoration: inherit; text-indent: inherit; text-overflow: inherit; text-transform: inherit; text-align: inherit; white-space: inherit; color: inherit; } @mixin button-state() { @include position(0, 0, 0, 0); position: absolute; content: ""; opacity: 0; } // Font smoothing // -------------------------------------------------- @mixin font-smoothing() { -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; } // Get the key from a map based on the index @function index-to-key($map, $index) { $keys: map-keys($map); @return nth($keys, $index); } // Breakpoint Mixins // --------------------------------------------------------------------------------- // Breakpoint viewport sizes and media queries. // // Breakpoints are defined as a map of (name: minimum width), order from small to large: // // (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px) // // The map defined in the `$screen-breakpoints` global variable is used as the `$breakpoints` argument by default. // --------------------------------------------------------------------------------- // Minimum breakpoint width. Null for the smallest (first) breakpoint. // // >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // 576px @function breakpoint-min($name, $breakpoints: $screen-breakpoints) { $min: map-get($breakpoints, $name); @return if($name != index-to-key($breakpoints, 1), $min, null); } // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront. // Useful for making responsive utilities. // // >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // "" (Returns a blank string) // >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // "-sm" @function breakpoint-infix($name, $breakpoints: $screen-breakpoints) { @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}"); } // Media of at least the minimum breakpoint width. No query for the smallest breakpoint. // Makes the @content apply to the given breakpoint and wider. @mixin media-breakpoint-up($name, $breakpoints: $screen-breakpoints) { $min: breakpoint-min($name, $breakpoints); @if $min { @media (min-width: $min) { @content; } } @else { @content; } } // Name of the next breakpoint, or null for the last breakpoint. // // >> breakpoint-next(sm) // md // >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // md // >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl)) // md @function breakpoint-next($name, $breakpoints: $screen-breakpoints, $breakpoint-names: map-keys($breakpoints)) { $n: index($breakpoint-names, $name); @return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null); } // Maximum breakpoint width. Null for the smallest (first) breakpoint. // The maximum value is reduced by 0.02px to work around the limitations of // `min-` and `max-` prefixes and viewports with fractional widths. // // See https://www.w3.org/TR/mediaqueries-4/#mq-min-max // Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari. // Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari. // See https://bugs.webkit.org/show_bug.cgi?id=178261 // See https://bugs.webkit.org/show_bug.cgi?id=178261 // // >> breakpoint-max(md, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)) // 767.98px @function breakpoint-max($name, $breakpoints: $screen-breakpoints) { $max: map-get($breakpoints, $name); @return if($max and $max > 0, $max - .02, null); } // Media of at most the maximum breakpoint width. No query for the largest breakpoint. // Makes the @content apply to the given breakpoint and narrower. @mixin media-breakpoint-down($name, $breakpoints: $screen-breakpoints) { $max: breakpoint-max($name, $breakpoints); @if $max { @media (max-width: $max) { @content; } } @else { @content; } } // Text Direction - ltr / rtl // // CSS defaults to use the ltr css, and adds [dir=rtl] selectors // to override ltr defaults. // ---------------------------------------------------------- @mixin multi-dir() { @content; // $root: #{&}; // @at-root [dir] { // #{$root} { // @content; // } // } } @mixin rtl() { $root: #{&}; $rootSplit: str-split($root, ","); $selectors: #{add-root-selector($root, "[dir=rtl]")}; $selectorsSplit: str-split($selectors, ","); $hostContextSelectors: (); $restSelectors: (); $dirSelectors: (); // Selectors must be split into individual selectors in case the browser // doesn't support a specific selector. // For example, Firefox and Safari doesn't support `:host-context()`. // If an invalid selector is used, then the entire group of selectors // will be ignored. // @link https://www.w3.org/TR/selectors-3/#grouping @each $selector in $selectorsSplit { // Group the selectors back into a single selector to optimize the output. @if str-index($selector, ":host-context") { $hostContextSelectors: append($hostContextSelectors, $selector, comma); } @else { // Group the selectors back into a single selector to optimize the output. $restSelectors: append($restSelectors, $selector, comma); } } // Supported by Chrome. @if length($hostContextSelectors) > 0 { @at-root #{$hostContextSelectors} { @content; } } // Supported by all browsers. @if length($restSelectors) > 0 { @at-root #{$restSelectors} { @content; } } // If browser can support `:dir()`, then add the `:dir()` selectors. @supports selector(:dir(rtl)) { // Adding :dir() in case the browser doesn't support `:host-context()` and does support `:dir()`. // `:host-context()` is added: // - through the `add-root-selector()` function. // - first so that it takes precedence over `:dir()`. // For example, // - Firefox doesn't support `:host-context()`, but does support `:dir()`. // - Safari doesn't support `:host-context()`, but Safari 16.4+ supports `:dir()` // @link https://webkit.org/blog/13966/webkit-features-in-safari-16-4/ // -- However, there is a Webkit bug on v16 that prevents `:dir()` from working when // -- the app direction is changed dynamically. v17+ works fine. // -- @link https://bugs.webkit.org/show_bug.cgi?id=257133 // Supported by Firefox. @at-root #{add-root-selector($root, ":dir(rtl)", false)} { @content; } } } @mixin ltr() { @content; } // SVG Background Image Mixin // @param {string} $svg // ---------------------------------------------------------- @mixin svg-background-image($svg, $flip-rtl: false) { $url: url-encode($svg); $viewBox: str-split(str-extract($svg, "viewBox='", "'"), " "); @if $flip-rtl != true or $viewBox == null { @include multi-dir() { background-image: url("data:image/svg+xml;charset=utf-8,#{$url}"); } } @else { $transform: "transform='translate(#{nth($viewBox, 3)}, 0) scale(-1, 1)'"; $flipped-url: $svg; $flipped-url: str-replace($flipped-url, "<path", "<path #{$transform}"); $flipped-url: str-replace($flipped-url, "<line", "<line #{$transform}"); $flipped-url: str-replace($flipped-url, "<polygon", "<polygon #{$transform}"); $flipped-url: url-encode($flipped-url); @include ltr () { background-image: url("data:image/svg+xml;charset=utf-8,#{$url}"); } @include rtl() { background-image: url("data:image/svg+xml;charset=utf-8,#{$flipped-url}"); } } } // Add property horizontal // @param {string} $start // @param {string} $end // ---------------------------------------------------------- @mixin property-horizontal($prop, $start, $end: $start) { @if $start == 0 and $end == 0 { #{$prop}-left: $start; #{$prop}-right: $end; } @else { -webkit-#{$prop}-start: $start; #{$prop}-inline-start: $start; -webkit-#{$prop}-end: $end; #{$prop}-inline-end: $end; } } // Add property for all directions // @param {string} $prop // @param {string} $top // @param {string} $end // @param {string} $bottom // @param {string} $start // @param {boolean} $content include content or use default // ---------------------------------------------------------- @mixin property($prop, $top, $end: $top, $bottom: $top, $start: $end) { @include property-horizontal($prop, $start, $end); #{$prop}-top: $top; #{$prop}-bottom: $bottom; } // Add padding horizontal // @param {string} $start // @param {string} $end // ---------------------------------------------------------- @mixin padding-horizontal($start, $end: $start) { @include property-horizontal(padding, $start, $end); } // Add padding for all directions // @param {string} $top // @param {string} $end // @param {string} $bottom // @param {string} $start // ---------------------------------------------------------- @mixin padding($top, $end: $top, $bottom: $top, $start: $end) { @include property(padding, $top, $end, $bottom, $start); } // Add margin horizontal // @param {string} $start // @param {string} $end // ---------------------------------------------------------- @mixin margin-horizontal($start, $end: $start) { @include property-horizontal(margin, $start, $end); } // Add margin for all directions // @param {string} $top // @param {string} $end // @param {string} $bottom // @param {string} $start // ---------------------------------------------------------- @mixin margin($top, $end: $top, $bottom: $top, $start: $end) { @include property(margin, $top, $end, $bottom, $start); } // Add position horizontal // @param {string} $start - amount to position start // @param {string} $end - amount to left: 0; end // ---------------------------------------------------------- @mixin position-horizontal($start: null, $end: null) { @if $start == $end { @include multi-dir() { left: $start; right: $end; } } @else { @at-root { & { inset-inline-start: $start; inset-inline-end: $end; } } } } // Add position for all directions // @param {string} $top // @param {string} $end // @param {string} $bottom // @param {string} $start // ---------------------------------------------------------- @mixin position($top: null, $end: null, $bottom: null, $start: null) { @include position-horizontal($start, $end); top: $top; bottom: $bottom; } // Add border for all directions // @param {string} $top // @param {string} $end // @param {string} $bottom // @param {string} $start // ---------------------------------------------------------- @mixin border($top, $end: $top, $bottom: $top, $start: $end) { @include property(border, $top, $end, $bottom, $start); } // Add border radius for all directions // @param {string} $top-start // @param {string} $top-end // @param {string} $bottom-end // @param {string} $bottom-start // ---------------------------------------------------------- @mixin border-radius($top-start, $top-end: $top-start, $bottom-end: $top-start, $bottom-start: $top-end) { @if $top-start == $top-end and $top-start == $bottom-end and $top-start == $bottom-start { border-radius: $top-start; } @else { border-start-start-radius: $top-start; border-start-end-radius: $top-end; border-end-end-radius: $bottom-end; border-end-start-radius: $bottom-start; } } // Add direction for all directions // @param {string} $dir - Direction on LTR @mixin direction($dir) { $other-dir: null; @if $dir == ltr { $other-dir: rtl; } @else { $other-dir: ltr; } @include ltr() { direction: $dir; } @include rtl() { direction: $other-dir; } } // Add float for all directions // @param {string} $side // @param {string} $decorator - !important @mixin float($side, $decorator: null) { @if $side == start { @include ltr() { float: left $decorator; } @include rtl() { float: right $decorator; } } @else if $side == end { @include ltr() { float: right $decorator; } @include rtl() { float: left $decorator; } } @else { @include multi-dir() { float: $side $decorator; } } } @mixin background-position($horizontal, $horizontal-amount: null, $vertical: null, $vertical-amount: null) { @if $horizontal == start or $horizontal == end { $horizontal-ltr: null; $horizontal-rtl: null; @if $horizontal == start { $horizontal-ltr: left; $horizontal-rtl: right; } @else { $horizontal-ltr: right; $horizontal-rtl: left; } @include ltr() { background-position: $horizontal-ltr $horizontal-amount $vertical $vertical-amount; } @include rtl() { background-position: $horizontal-rtl $horizontal-amount $vertical $vertical-amount; } } @else { @include multi-dir() { background-position: $horizontal $horizontal-amount $vertical $vertical-amount; } } } @mixin transform-origin($x-axis, $y-axis: null) { @if $x-axis == start { @include ltr() { transform-origin: left $y-axis; } @include rtl() { transform-origin: right $y-axis; } } @else if $x-axis == end { @include ltr() { transform-origin: right $y-axis; } @include rtl() { transform-origin: left $y-axis; } } @else if $x-axis == left or $x-axis == right { @include multi-dir() { transform-origin: $x-axis $y-axis; } } @else { @include ltr() { transform-origin: $x-axis $y-axis; } @include rtl() { transform-origin: calc(100% - #{$x-axis}) $y-axis; } } } // Add transform for all directions // @param {string} $transforms - comma separated list of transforms @mixin transform($transforms...) { $extra: null; $x: null; $ltr-translate: null; $rtl-translate: null; @each $transform in $transforms { @if (str-index($transform, translate3d)) { $transform: str-replace($transform, 'translate3d('); $transform: str-replace($transform, ')'); $coordinates: str-split($transform, ','); $x: nth($coordinates, 1); $y: nth($coordinates, 2); $z: nth($coordinates, 3); $ltr-translate: translate3d($x, $y, $z); $rtl-translate: translate3d(calc(-1 * #{$x}), $y, $z); } @else { @if $extra == null { $extra: $transform; } @else { $extra: $extra $transform; } } } @if $x == '0' or $x == null { @include multi-dir() { transform: $ltr-translate $extra; } } @else { @include ltr() { transform: $ltr-translate $extra; } @include rtl() { transform: $rtl-translate $extra; } } }