Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for calc-size() #2446

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.82.0-dev

* Parse the `calc-size()` function as a calculation now that it's supported in
some browsers.

### Dart API

* Add a `SassCalculation.calcSize()` function.

## 1.81.1

* No user-visible changes.
Expand Down
15 changes: 15 additions & 0 deletions lib/src/value/calculation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,21 @@ final class SassCalculation extends Value {
}
}

/// Creates an `calc-size()` calculation with the given [basis] and [value].
///
/// The [basis] and [value] must be either a [SassNumber], a
pamelalozano16 marked this conversation as resolved.
Show resolved Hide resolved
/// [SassCalculation], an unquoted [SassString], or a [CalculationOperation].
///
/// This automatically simplifies the calculation. It throws an exception if
/// it can determine that the calculation will definitely produce invalid CSS.
static SassCalculation calcSize(Object basis, Object? value) {
var args = [basis, if (value != null) value];
pamelalozano16 marked this conversation as resolved.
Show resolved Hide resolved
_verifyLength(args, 2);
basis = _simplify(basis);
value = value.andThen(_simplify);
return SassCalculation._("calc-size", [basis, if (value != null) value]);
}

/// Creates and simplifies a [CalculationOperation] with the given [operator],
/// [left], and [right].
///
Expand Down
10 changes: 7 additions & 3 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,8 @@ final class _EvaluateVisitor
(node.namespace == null &&
const {
"calc", "clamp", "hypot", "sin", "cos", "tan", "asin", "acos", //
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", "log"
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", //
"log", "calc-size"
}.contains(node.name.toLowerCase()) &&
_environment.getFunction(node.name) == null);

Expand Down Expand Up @@ -2578,7 +2579,8 @@ final class _EvaluateVisitor
"rem" ||
"atan2" ||
"pow" ||
"log":
"log" ||
"calc-size":
return await _visitCalculation(node);
}

Expand Down Expand Up @@ -2671,6 +2673,8 @@ final class _EvaluateVisitor
_warn(message, node.span, deprecation)),
"clamp" => SassCalculation.clamp(arguments[0],
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
"calc-size" =>
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
};
} on SassScriptException catch (error, stackTrace) {
Expand Down Expand Up @@ -2718,7 +2722,7 @@ final class _EvaluateVisitor
check(1);
case "min" || "max" || "hypot":
check();
case "pow" || "atan2" || "log" || "mod" || "rem":
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
check(2);
case "round" || "clamp":
check(3);
Expand Down
12 changes: 8 additions & 4 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: fbffa0dbe5a1af846dc83752457d39fb2984d280
// Checksum: afc541c7e8bbec53a7a076341b1afff290cb0e45
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -2437,7 +2437,8 @@ final class _EvaluateVisitor
(node.namespace == null &&
const {
"calc", "clamp", "hypot", "sin", "cos", "tan", "asin", "acos", //
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", "log"
"atan", "sqrt", "exp", "sign", "mod", "rem", "atan2", "pow", //
"log", "calc-size"
}.contains(node.name.toLowerCase()) &&
_environment.getFunction(node.name) == null);

Expand Down Expand Up @@ -2556,7 +2557,8 @@ final class _EvaluateVisitor
"rem" ||
"atan2" ||
"pow" ||
"log":
"log" ||
"calc-size":
return _visitCalculation(node);
}

Expand Down Expand Up @@ -2649,6 +2651,8 @@ final class _EvaluateVisitor
_warn(message, node.span, deprecation)),
"clamp" => SassCalculation.clamp(arguments[0],
arguments.elementAtOrNull(1), arguments.elementAtOrNull(2)),
"calc-size" =>
SassCalculation.calcSize(arguments[0], arguments.elementAtOrNull(1)),
_ => throw UnsupportedError('Unknown calculation name "${node.name}".')
};
} on SassScriptException catch (error, stackTrace) {
Expand Down Expand Up @@ -2696,7 +2700,7 @@ final class _EvaluateVisitor
check(1);
case "min" || "max" || "hypot":
check();
case "pow" || "atan2" || "log" || "mod" || "rem":
case "pow" || "atan2" || "log" || "mod" || "rem" || "calc-size":
check(2);
case "round" || "clamp":
check(3);
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.7-dev

* No user-visible changes.

## 0.4.6

* No user-visible changes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-parser",
"version": "0.4.6",
"version": "0.4.7-dev",
"description": "A PostCSS-compatible wrapper of the official Sass parser",
"repository": "sass/sass",
"author": "Google Inc.",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.4.0-dev

* No user-visible changes.

## 14.3.0

* Add `NodePackageImporter`, which loads `pkg:` URLs from `node_modules` within
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 14.3.0
version: 14.4.0-dev
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.3.0 <4.0.0"

dependencies:
sass: 1.81.1
sass: 1.82.0

dev_dependencies:
dartdoc: ^8.0.14
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.81.1
version: 1.82.0-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down
Loading