mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 05:14:08 +08:00
6e522e4aad
This PR is a major change to Sass compilation in Discourse. The new version of sass-ruby moves to dart-sass putting we back on the supported version of Sass. It does so while keeping compatibility with the existing method signatures, so minimal change is needed in Discourse for this change. This moves us From: - sassc 2.0.1 (Feb 2019) - libsass 3.5.2 (May 2018) To: - dart-sass 1.58 This update applies the following breaking changes: > > These breaking changes are coming soon or have recently been released: > > [Functions are stricter about which units they allow](https://sass-lang.com/documentation/breaking-changes/function-units) beginning in Dart Sass 1.32.0. > > [Selectors with invalid combinators are invalid](https://sass-lang.com/documentation/breaking-changes/bogus-combinators) beginning in Dart Sass 1.54.0. > > [/ is changing from a division operation to a list separator](https://sass-lang.com/documentation/breaking-changes/slash-div) beginning in Dart Sass 1.33.0. > > [Parsing the special syntax of @-moz-document will be invalid](https://sass-lang.com/documentation/breaking-changes/moz-document) beginning in Dart Sass 1.7.2. > > [Compound selectors could not be extended](https://sass-lang.com/documentation/breaking-changes/extend-compound) in Dart Sass 1.0.0 and Ruby Sass 4.0.0. SCSS files have been migrated automatically using `sass-migrator division app/assets/stylesheets/**/*.scss`
167 lines
3.4 KiB
SCSS
167 lines
3.4 KiB
SCSS
// This file:
|
|
// Copyright (c) 2013 Takeru Suzuki
|
|
// Licensed under the MIT license.
|
|
// https://github.com/terkel/mathsass
|
|
|
|
// Constants
|
|
@use "sass:math";
|
|
|
|
$E: 2.718281828459045;
|
|
$PI: 3.141592653589793;
|
|
$LN2: 0.6931471805599453;
|
|
$SQRT2: 1.4142135623730951;
|
|
|
|
@function error($message) {
|
|
@warn "#{_error("The direction used does not exist")}";
|
|
@return null;
|
|
}
|
|
|
|
// Returns the factorial of a non-negative integer.
|
|
// @param {Number} $x A non-negative integer.
|
|
// @return {Number}
|
|
// @example
|
|
// fact(0) // 1
|
|
// fact(8) // 40320
|
|
@function fact($x) {
|
|
@if $x < 0 or $x != floor($x) {
|
|
@warn "Argument for `fact()` must be a positive integer.";
|
|
@return null;
|
|
}
|
|
$ret: 1;
|
|
@while $x > 0 {
|
|
$ret: $ret * $x;
|
|
$x: $x - 1;
|
|
}
|
|
@return $ret;
|
|
}
|
|
|
|
// Returns a two-element list containing the normalized fraction and exponent of number.
|
|
// @param {Number} $x
|
|
// @return {List} fraction, exponent
|
|
@function frexp($x) {
|
|
$exp: 0;
|
|
@if $x < 0 {
|
|
$x: $x * -1;
|
|
}
|
|
@if $x < 0.5 {
|
|
@while $x < 0.5 {
|
|
$x: $x * 2;
|
|
$exp: $exp - 1;
|
|
}
|
|
} @else if $x >= 1 {
|
|
@while $x >= 1 {
|
|
$x: $x * 0.5;
|
|
$exp: $exp + 1;
|
|
}
|
|
}
|
|
@return $x, $exp;
|
|
}
|
|
|
|
// Returns $x * 2^$exp
|
|
// @param {Number} $x
|
|
// @param {Number} $exp
|
|
@function ldexp($x, $exp) {
|
|
$b: if($exp >= 0, 2, 1 * 0.5);
|
|
@if $exp < 0 {
|
|
$exp: $exp * -1;
|
|
}
|
|
@while $exp > 0 {
|
|
@if $exp % 2 == 1 {
|
|
$x: $x * $b;
|
|
}
|
|
$b: $b * $b;
|
|
$exp: floor($exp * 0.5);
|
|
}
|
|
@return $x;
|
|
}
|
|
|
|
// Returns the natural logarithm of a number.
|
|
// @param {Number} $x
|
|
// @example
|
|
// log(2) // 0.69315
|
|
// log(10) // 2.30259
|
|
@function log($x) {
|
|
@if $x <= 0 {
|
|
@return math.div(0, 0);
|
|
}
|
|
$k: nth(frexp(math.div($x, $SQRT2)), 2);
|
|
$x: math.div($x, ldexp(1, $k));
|
|
$x: math.div($x - 1, $x + 1);
|
|
$x2: $x * $x;
|
|
$i: 1;
|
|
$s: $x;
|
|
$sp: null;
|
|
@while $sp != $s {
|
|
$x: $x * $x2;
|
|
$i: $i + 2;
|
|
$sp: $s;
|
|
$s: $s + math.div($x, $i);
|
|
}
|
|
@return $LN2 * $k + 2 * $s;
|
|
}
|
|
|
|
@function ipow($base, $exp) {
|
|
@if $exp != floor($exp) {
|
|
@return error("Exponent for `ipow()` must be an integer.");
|
|
}
|
|
$r: 1;
|
|
$s: 0;
|
|
@if $exp < 0 {
|
|
$exp: $exp * -1;
|
|
$s: 1;
|
|
}
|
|
@while $exp > 0 {
|
|
@if $exp % 2 == 1 {
|
|
$r: $r * $base;
|
|
}
|
|
$exp: floor($exp * 0.5);
|
|
$base: $base * $base;
|
|
}
|
|
@return if($s != 0, math.div(1, $r), $r);
|
|
}
|
|
|
|
// Returns E^x, where x is the argument, and E is Euler's constant, the base of the natural logarithms.
|
|
// @param {Number} $x
|
|
// @example
|
|
// exp(1) // 2.71828
|
|
// exp(-1) // 0.36788
|
|
@function exp($x) {
|
|
$ret: 0;
|
|
@for $n from 0 to 24 {
|
|
$ret: $ret + math.div(ipow($x, $n), fact($n));
|
|
}
|
|
@return $ret;
|
|
}
|
|
|
|
// Returns base to the exponent power.
|
|
// @param {Number} $base The base number
|
|
// @param {Number} $exp The exponent to which to raise base
|
|
// @return {Number}
|
|
// @example
|
|
// pow(4, 2) // 16
|
|
// pow(4, -2) // 0.0625
|
|
// pow(4, 0.2) // 1.31951
|
|
@function pow($base, $exp) {
|
|
@if $exp == floor($exp) {
|
|
@return ipow($base, $exp);
|
|
} @else {
|
|
@return exp(log($base) * $exp);
|
|
}
|
|
}
|
|
|
|
// Returns the square root of a number.
|
|
// @param {Number} $x
|
|
// @example
|
|
// sqrt(2) // 1.41421
|
|
// sqrt(5) // 2.23607
|
|
@function sqrt($x) {
|
|
@if $x < 0 {
|
|
@return error("Argument for `sqrt()` must be a positive number.");
|
|
}
|
|
$ret: 1;
|
|
@for $i from 1 through 24 {
|
|
$ret: $ret - math.div(pow($ret, 2) - $x, 2 * $ret);
|
|
}
|
|
@return $ret;
|
|
}
|