Skip to content

Commit

Permalink
[web] allows imports to line-break
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov committed Dec 13, 2024
1 parent ff8dfad commit b471224
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
34 changes: 22 additions & 12 deletions lib/web_ui/lib/src/engine/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'dart:math' as math;
import 'dart:typed_data';

import 'package:ui/src/engine.dart';
import 'package:ui/src/engine/skwasm/skwasm_impl.dart' if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart';
import 'package:ui/src/engine/skwasm/skwasm_impl.dart'
if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

Expand Down Expand Up @@ -43,11 +44,12 @@ abstract class Renderer {
if (!useCanvasKit) {
// The user requested 'html' or 'auto' either in the command-line or JS.
final String requested =
configuration.requestedRendererType ??
(FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html');
configuration.requestedRendererType ??
(FlutterConfiguration.flutterWebAutoDetect ? 'auto' : 'html');
printWarning(
'The HTML Renderer is being deprecated. Stop using the "$requested" renderer mode.'
'\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation');
'\nSee: https://docs.flutter.dev/to/web-html-renderer-deprecation',
);
}
return true;
}());
Expand Down Expand Up @@ -120,14 +122,18 @@ abstract class Renderer {
ui.ImageFilter createBlurImageFilter({
double sigmaX = 0.0,
double sigmaY = 0.0,
ui.TileMode? tileMode});
ui.ImageFilter createDilateImageFilter({ double radiusX = 0.0, double radiusY = 0.0});
ui.ImageFilter createErodeImageFilter({ double radiusX = 0.0, double radiusY = 0.0});
ui.TileMode? tileMode,
});
ui.ImageFilter createDilateImageFilter({double radiusX = 0.0, double radiusY = 0.0});
ui.ImageFilter createErodeImageFilter({double radiusX = 0.0, double radiusY = 0.0});
ui.ImageFilter createMatrixImageFilter(
Float64List matrix4, {
ui.FilterQuality filterQuality = ui.FilterQuality.low
ui.FilterQuality filterQuality = ui.FilterQuality.low,
});
ui.ImageFilter composeImageFilters({
required ui.ImageFilter outer,
required ui.ImageFilter inner,
});
ui.ImageFilter composeImageFilters({required ui.ImageFilter outer, required ui.ImageFilter inner});

Future<ui.Codec> instantiateImageCodec(
Uint8List list, {
Expand All @@ -143,8 +149,12 @@ abstract class Renderer {

FutureOr<ui.Image> createImageFromImageBitmap(DomImageBitmap imageSource);

FutureOr<ui.Image> createImageFromTextureSource(JSAny object,
{required int width, required int height, required bool transferOwnership});
FutureOr<ui.Image> createImageFromTextureSource(
JSAny object, {
required int width,
required int height,
required bool transferOwnership,
});

void decodeImageFromPixels(
Uint8List pixels,
Expand All @@ -155,7 +165,7 @@ abstract class Renderer {
int? rowBytes,
int? targetWidth,
int? targetHeight,
bool allowUpscaling = true
bool allowUpscaling = true,
});

ui.ImageShader createImageShader(
Expand Down
1 change: 1 addition & 0 deletions web_sdk/sdk_rewriter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ List<Replacer> generatePartsPatterns(String libraryName, bool isPublic) {
// Remove library directives.
AllReplacer(RegExp(r'\nlibrary .+;'), ''),
// Remove imports/exports from all part files.
AllReplacer(RegExp(r"\nimport '.+'\n\s*if \(dart.library.html\) '.*';"), ''),
AllReplacer(RegExp(r'\nimport\s*.*'), ''),
AllReplacer(RegExp(r'\nexport\s*.*'), ''),
AllReplacer(RegExp(r'\n@DefaultAsset(.*)'), ''),
Expand Down
28 changes: 28 additions & 0 deletions web_sdk/test/sdk_rewriter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,32 @@ void printSomething() {
expect(getExtraImportsForLibrary('web_test_fonts'), isEmpty);
expect(getExtraImportsForLibrary('web_locale_keymap'), isEmpty);
});

test('allows imports to line-break', () {
const String source = '''
import 'package:some_package/some_package.dart';
import 'package:ui/src/engine/skwasm/skwasm_impl.dart'
if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart';
import 'package:some_package/some_package' as some_package;
void printSomething() {
print('something');
}
''';

const String expected = '''
part of dart._engine;
void printSomething() {
print('something');
}
''';

final String result = processSource(
source,
(String source) => preprocessPartFile(source, 'engine'),
generatePartsPatterns('engine', false),
);
expect(result, expected);
});
}

0 comments on commit b471224

Please sign in to comment.