From 63ebf160282f0c03912ad26c69a52c6302d3c701 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Mon, 2 Dec 2024 17:31:08 -0800 Subject: [PATCH] Add support for `calc-size()` (#2446) See sass/sass#3989 --- CHANGELOG.md | 9 +++++++++ lib/src/value/calculation.dart | 15 +++++++++++++++ lib/src/visitor/async_evaluate.dart | 10 +++++++--- lib/src/visitor/evaluate.dart | 12 ++++++++---- pkg/sass-parser/CHANGELOG.md | 4 ++++ pkg/sass-parser/package.json | 2 +- pkg/sass_api/CHANGELOG.md | 4 ++++ pkg/sass_api/pubspec.yaml | 4 ++-- pubspec.yaml | 2 +- 9 files changed, 51 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bcadf449..7a3cc8fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/value/calculation.dart b/lib/src/value/calculation.dart index c59bc893f..14e862762 100644 --- a/lib/src/value/calculation.dart +++ b/lib/src/value/calculation.dart @@ -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 + /// [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]; + _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]. /// diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index c06b45484..803d60fe8 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -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); @@ -2578,7 +2579,8 @@ final class _EvaluateVisitor "rem" || "atan2" || "pow" || - "log": + "log" || + "calc-size": return await _visitCalculation(node); } @@ -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) { @@ -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); diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 792326ecc..c06185708 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -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 @@ -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); @@ -2556,7 +2557,8 @@ final class _EvaluateVisitor "rem" || "atan2" || "pow" || - "log": + "log" || + "calc-size": return _visitCalculation(node); } @@ -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) { @@ -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); diff --git a/pkg/sass-parser/CHANGELOG.md b/pkg/sass-parser/CHANGELOG.md index a0c6f2930..a8d43624c 100644 --- a/pkg/sass-parser/CHANGELOG.md +++ b/pkg/sass-parser/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.7-dev + +* No user-visible changes. + ## 0.4.6 * No user-visible changes. diff --git a/pkg/sass-parser/package.json b/pkg/sass-parser/package.json index 46ac7f788..fa9bebc8f 100644 --- a/pkg/sass-parser/package.json +++ b/pkg/sass-parser/package.json @@ -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.", diff --git a/pkg/sass_api/CHANGELOG.md b/pkg/sass_api/CHANGELOG.md index 3ed6f24a0..a2d14f2e6 100644 --- a/pkg/sass_api/CHANGELOG.md +++ b/pkg/sass_api/CHANGELOG.md @@ -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 diff --git a/pkg/sass_api/pubspec.yaml b/pkg/sass_api/pubspec.yaml index d75b7843e..068bab853 100644 --- a/pkg/sass_api/pubspec.yaml +++ b/pkg/sass_api/pubspec.yaml @@ -2,7 +2,7 @@ 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 @@ -10,7 +10,7 @@ environment: sdk: ">=3.3.0 <4.0.0" dependencies: - sass: 1.81.1 + sass: 1.82.0 dev_dependencies: dartdoc: ^8.0.14 diff --git a/pubspec.yaml b/pubspec.yaml index b5b6f6721..a6873d61c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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