1212library browser_api;
1313
1414import 'dart:async' ;
15+ import 'dart:js_interop' ;
1516import 'dart:js_util' as js_util;
1617import 'dart:math' as math;
1718import 'dart:typed_data' ;
@@ -201,7 +202,9 @@ DomCanvasElement? tryCreateCanvasElement(int width, int height) {
201202}
202203
203204@JS ('window.ImageDecoder' )
204- external Object ? get _imageDecoderConstructor;
205+ external JSAny ? get __imageDecoderConstructor;
206+ Object ? get _imageDecoderConstructor =>
207+ __imageDecoderConstructor? .toObjectShallow;
205208
206209/// Environment variable that allows the developer to opt out of using browser's
207210/// `ImageDecoder` API, and use the WASM codecs bundled with CanvasKit.
@@ -265,9 +268,13 @@ class ImageDecoder {
265268
266269extension ImageDecoderExtension on ImageDecoder {
267270 external ImageTrackList get tracks;
268- external bool get complete;
271+
272+ @JS ('complete' )
273+ external JSBoolean get _complete;
274+ bool get complete => _complete.toDart;
275+
269276 external JsPromise decode (DecodeOptions options);
270- external void close ();
277+ external JSVoid close ();
271278}
272279
273280/// Options passed to the `ImageDecoder` constructor.
@@ -280,13 +287,13 @@ extension ImageDecoderExtension on ImageDecoder {
280287@staticInterop
281288class ImageDecoderOptions {
282289 external factory ImageDecoderOptions ({
283- required String type,
284- required Uint8List data,
285- required String premultiplyAlpha,
286- int ? desiredWidth,
287- int ? desiredHeight,
288- required String colorSpaceConversion,
289- required bool preferAnimation,
290+ required JSString type,
291+ required JSUint8Array data,
292+ required JSString premultiplyAlpha,
293+ JSNumber ? desiredWidth,
294+ JSNumber ? desiredHeight,
295+ required JSString colorSpaceConversion,
296+ required JSBoolean preferAnimation,
290297 });
291298}
292299
@@ -302,7 +309,10 @@ class DecodeResult {}
302309
303310extension DecodeResultExtension on DecodeResult {
304311 external VideoFrame get image;
305- external bool get complete;
312+
313+ @JS ('complete' )
314+ external JSBoolean get _complete;
315+ bool get complete => _complete.toDart;
306316}
307317
308318/// Options passed to [ImageDecoder.decode] .
@@ -315,7 +325,7 @@ extension DecodeResultExtension on DecodeResult {
315325@staticInterop
316326class DecodeOptions {
317327 external factory DecodeOptions ({
318- required double frameIndex,
328+ required JSNumber frameIndex,
319329 });
320330}
321331
@@ -332,16 +342,40 @@ class DecodeOptions {
332342class VideoFrame implements DomCanvasImageSource {}
333343
334344extension VideoFrameExtension on VideoFrame {
335- external double allocationSize ();
336- external JsPromise copyTo (Object destination);
337- external String ? get format;
338- external double get codedWidth;
339- external double get codedHeight;
340- external double get displayWidth;
341- external double get displayHeight;
342- external double ? get duration;
345+ @JS ('allocationSize' )
346+ external JSNumber _allocationSize ();
347+ double allocationSize () => _allocationSize ().toDart;
348+
349+ @JS ('copyTo' )
350+ external JsPromise _copyTo (JSAny destination);
351+ JsPromise copyTo (Object destination) => _copyTo (destination.toJSAnyShallow);
352+
353+ @JS ('format' )
354+ external JSString ? get _format;
355+ String ? get format => _format? .toDart;
356+
357+ @JS ('codedWidth' )
358+ external JSNumber get _codedWidth;
359+ double get codedWidth => _codedWidth.toDart;
360+
361+ @JS ('codedHeight' )
362+ external JSNumber get _codedHeight;
363+ double get codedHeight => _codedHeight.toDart;
364+
365+ @JS ('displayWidth' )
366+ external JSNumber get _displayWidth;
367+ double get displayWidth => _displayWidth.toDart;
368+
369+ @JS ('displayHeight' )
370+ external JSNumber get _displayHeight;
371+ double get displayHeight => _displayHeight.toDart;
372+
373+ @JS ('duration' )
374+ external JSNumber ? get _duration;
375+ double ? get duration => _duration? .toDart;
376+
343377 external VideoFrame clone ();
344- external void close ();
378+ external JSVoid close ();
345379}
346380
347381/// Corresponds to the browser's `ImageTrackList` type.
@@ -370,8 +404,13 @@ extension ImageTrackListExtension on ImageTrackList {
370404class ImageTrack {}
371405
372406extension ImageTrackExtension on ImageTrack {
373- external double get repetitionCount;
374- external double get frameCount;
407+ @JS ('repetitionCount' )
408+ external JSNumber get _repetitionCount;
409+ double get repetitionCount => _repetitionCount.toDart;
410+
411+ @JS ('frameCount' )
412+ external JSNumber get _frameCount;
413+ double get frameCount => _frameCount.toDart;
375414}
376415
377416void scaleCanvas2D (Object context2d, num x, num y) {
0 commit comments