@@ -78,7 +78,8 @@ class DomRenderer {
78
78
/// This getter calls the `hasFocus` method of the `Document` interface.
79
79
/// See for more details:
80
80
/// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus
81
- bool ? get windowHasFocus => js_util.callMethod (html.document, 'hasFocus' , < dynamic > []);
81
+ bool ? get windowHasFocus =>
82
+ js_util.callMethod (html.document, 'hasFocus' , < dynamic > []);
82
83
83
84
void _setupHotRestart () {
84
85
// This persists across hot restarts to clear stale DOM.
@@ -172,7 +173,8 @@ class DomRenderer {
172
173
js_util.setProperty (element, name, value);
173
174
}
174
175
175
- static void setElementStyle (html.Element element, String name, String ? value) {
176
+ static void setElementStyle (
177
+ html.Element element, String name, String ? value) {
176
178
if (value == null ) {
177
179
element.style.removeProperty (name);
178
180
} else {
@@ -181,8 +183,8 @@ class DomRenderer {
181
183
}
182
184
183
185
static void setElementTransform (html.Element element, String transformValue) {
184
- js_util.setProperty (js_util. getProperty (element, 'style' ), 'transform' ,
185
- transformValue);
186
+ js_util.setProperty (
187
+ js_util. getProperty (element, 'style' ), 'transform' , transformValue);
186
188
}
187
189
188
190
void setText (html.Element element, String text) {
@@ -200,7 +202,8 @@ class DomRenderer {
200
202
}
201
203
202
204
void setThemeColor (ui.Color color) {
203
- html.MetaElement ? theme = html.document.querySelector ('#flutterweb-theme' ) as html.MetaElement ? ;
205
+ html.MetaElement ? theme =
206
+ html.document.querySelector ('#flutterweb-theme' ) as html.MetaElement ? ;
204
207
if (theme == null ) {
205
208
theme = html.MetaElement ()
206
209
..id = 'flutterweb-theme'
@@ -315,8 +318,8 @@ flt-glass-pane * {
315
318
// This css prevents an autofill overlay brought by the browser during
316
319
// text field autofill by delaying the transition effect.
317
320
// See: https://github.com/flutter/flutter/issues/61132.
318
- if (browserHasAutofillOverlay ()) {
319
- sheet.insertRule ('''
321
+ if (browserHasAutofillOverlay ()) {
322
+ sheet.insertRule ('''
320
323
.transparentTextEditing:-webkit-autofill,
321
324
.transparentTextEditing:-webkit-autofill:hover,
322
325
.transparentTextEditing:-webkit-autofill:focus,
@@ -326,7 +329,6 @@ flt-glass-pane * {
326
329
''' , sheet.cssRules.length);
327
330
}
328
331
329
-
330
332
final html.BodyElement bodyElement = html.document.body! ;
331
333
setElementStyle (bodyElement, 'position' , 'fixed' );
332
334
setElementStyle (bodyElement, 'top' , '0' );
@@ -416,8 +418,7 @@ flt-glass-pane * {
416
418
// pointer events through to the semantics tree. However, for platform
417
419
// views, the pointer events will not pass through, and will be handled
418
420
// by the platform view.
419
- glassPaneElement
420
- .insertBefore (_accesibilityPlaceholder, _sceneHostElement);
421
+ glassPaneElement.insertBefore (_accesibilityPlaceholder, _sceneHostElement);
421
422
422
423
PointerBinding .initInstance (glassPaneElement);
423
424
@@ -460,6 +461,66 @@ flt-glass-pane * {
460
461
_canvasKitScript? .remove ();
461
462
_canvasKitScript = html.ScriptElement ();
462
463
_canvasKitScript! .src = canvasKitBaseUrl + 'canvaskit.js' ;
464
+
465
+ // TODO(hterkelsen): Rather than this monkey-patch hack, we should
466
+ // build CanvasKit ourselves. See:
467
+ // https://github.com/flutter/flutter/issues/52588
468
+
469
+ // Monkey-patch the top-level `module` and `exports` objects so that
470
+ // CanvasKit doesn't attempt to register itself as an anonymous module.
471
+ //
472
+ // The idea behind making these fake `exports` and `module` objects is
473
+ // that `canvaskit.js` contains the following lines of code:
474
+ //
475
+ // if (typeof exports === 'object' && typeof module === 'object')
476
+ // module.exports = CanvasKitInit;
477
+ // else if (typeof define === 'function' && define['amd'])
478
+ // define([], function() { return CanvasKitInit; });
479
+ //
480
+ // We need to avoid hitting the case where CanvasKit defines an anonymous
481
+ // module, since this breaks RequireJS, which DDC and some plugins use.
482
+ // Temporarily removing the `define` function won't work because RequireJS
483
+ // could load in between this code running and the CanvasKit code running.
484
+ // Also, we cannot monkey-patch the `define` function because it is
485
+ // non-configurable (it is a top-level 'var').
486
+
487
+ // First check if `exports` and `module` are already defined. If so, then
488
+ // CommonJS is being used, and we shouldn't have any problems.
489
+ js.JsFunction objectConstructor = js.context['Object' ];
490
+ if (js.context['exports' ] == null ) {
491
+ js.JsObject exportsAccessor = js.JsObject .jsify ({
492
+ 'get' : js.allowInterop (() {
493
+ if (html.document.currentScript == _canvasKitScript) {
494
+ return js.JsObject (objectConstructor);
495
+ } else {
496
+ return js.context['_flutterWebCachedExports' ];
497
+ }
498
+ }),
499
+ 'set' : js.allowInterop ((dynamic value) {
500
+ js.context['_flutterWebCachedExports' ] = value;
501
+ }),
502
+ 'configurable' : true ,
503
+ });
504
+ objectConstructor.callMethod ('defineProperty' ,
505
+ < dynamic > [js.context, 'exports' , exportsAccessor]);
506
+ }
507
+ if (js.context['module' ] == null ) {
508
+ js.JsObject moduleAccessor = js.JsObject .jsify ({
509
+ 'get' : js.allowInterop (() {
510
+ if (html.document.currentScript == _canvasKitScript) {
511
+ return js.JsObject (objectConstructor);
512
+ } else {
513
+ return js.context['_flutterWebCachedModule' ];
514
+ }
515
+ }),
516
+ 'set' : js.allowInterop ((dynamic value) {
517
+ js.context['_flutterWebCachedModule' ] = value;
518
+ }),
519
+ 'configurable' : true ,
520
+ });
521
+ objectConstructor.callMethod (
522
+ 'defineProperty' , < dynamic > [js.context, 'module' , moduleAccessor]);
523
+ }
463
524
html.document.head! .append (_canvasKitScript! );
464
525
}
465
526
@@ -469,8 +530,8 @@ flt-glass-pane * {
469
530
} else {
470
531
_resizeSubscription = html.window.onResize.listen (_metricsDidChange);
471
532
}
472
- _localeSubscription = languageChangeEvent. forTarget (html.window)
473
- .listen (_languageDidChange);
533
+ _localeSubscription =
534
+ languageChangeEvent. forTarget (html.window) .listen (_languageDidChange);
474
535
EnginePlatformDispatcher .instance._updateLocales ();
475
536
}
476
537
@@ -484,7 +545,7 @@ flt-glass-pane * {
484
545
/// Note: always check for rotations for a mobile device. Update the physical
485
546
/// size if the change is caused by a rotation.
486
547
void _metricsDidChange (html.Event ? event) {
487
- if (isMobile && ! window.isRotation () && textEditing.isEditing) {
548
+ if (isMobile && ! window.isRotation () && textEditing.isEditing) {
488
549
window.computeOnScreenKeyboardInsets ();
489
550
EnginePlatformDispatcher .instance.invokeOnMetricsChanged ();
490
551
} else {
@@ -517,13 +578,20 @@ flt-glass-pane * {
517
578
static bool ? _ellipseFeatureDetected;
518
579
519
580
/// Draws CanvasElement ellipse with fallback.
520
- static void ellipse (html.CanvasRenderingContext2D context,
521
- double centerX, double centerY, double radiusX, double radiusY,
522
- double rotation, double startAngle, double endAngle, bool antiClockwise) {
581
+ static void ellipse (
582
+ html.CanvasRenderingContext2D context,
583
+ double centerX,
584
+ double centerY,
585
+ double radiusX,
586
+ double radiusY,
587
+ double rotation,
588
+ double startAngle,
589
+ double endAngle,
590
+ bool antiClockwise) {
523
591
_ellipseFeatureDetected ?? = js_util.getProperty (context, 'ellipse' ) != null ;
524
592
if (_ellipseFeatureDetected! ) {
525
- context.ellipse (centerX, centerY, radiusX, radiusY,
526
- rotation, startAngle, endAngle, antiClockwise);
593
+ context.ellipse (centerX, centerY, radiusX, radiusY, rotation, startAngle,
594
+ endAngle, antiClockwise);
527
595
} else {
528
596
context.save ();
529
597
context.translate (centerX, centerY);
@@ -539,9 +607,11 @@ flt-glass-pane * {
539
607
static const String orientationLockTypeLandscape = 'landscape' ;
540
608
static const String orientationLockTypePortrait = 'portrait' ;
541
609
static const String orientationLockTypePortraitPrimary = 'portrait-primary' ;
542
- static const String orientationLockTypePortraitSecondary = 'portrait-secondary' ;
610
+ static const String orientationLockTypePortraitSecondary =
611
+ 'portrait-secondary' ;
543
612
static const String orientationLockTypeLandscapePrimary = 'landscape-primary' ;
544
- static const String orientationLockTypeLandscapeSecondary = 'landscape-secondary' ;
613
+ static const String orientationLockTypeLandscapeSecondary =
614
+ 'landscape-secondary' ;
545
615
546
616
/// Sets preferred screen orientation.
547
617
///
@@ -556,8 +626,7 @@ flt-glass-pane * {
556
626
Future <bool > setPreferredOrientation (List <dynamic >? orientations) {
557
627
final html.Screen screen = html.window.screen! ;
558
628
if (! _unsafeIsNull (screen)) {
559
- final html.ScreenOrientation ? screenOrientation =
560
- screen.orientation;
629
+ final html.ScreenOrientation ? screenOrientation = screen.orientation;
561
630
if (! _unsafeIsNull (screenOrientation)) {
562
631
if (orientations! .isEmpty) {
563
632
screenOrientation! .unlock ();
@@ -588,7 +657,7 @@ flt-glass-pane * {
588
657
589
658
// Converts device orientation to w3c OrientationLockType enum.
590
659
static String ? _deviceOrientationToLockType (String deviceOrientation) {
591
- switch (deviceOrientation) {
660
+ switch (deviceOrientation) {
592
661
case 'DeviceOrientation.portraitUp' :
593
662
return orientationLockTypePortraitPrimary;
594
663
case 'DeviceOrientation.landscapeLeft' :
0 commit comments