12
12
library browser_api;
13
13
14
14
import 'dart:async' ;
15
+ import 'dart:js_interop' ;
15
16
import 'dart:js_util' as js_util;
16
17
import 'dart:math' as math;
17
18
import 'dart:typed_data' ;
@@ -201,7 +202,9 @@ DomCanvasElement? tryCreateCanvasElement(int width, int height) {
201
202
}
202
203
203
204
@JS ('window.ImageDecoder' )
204
- external Object ? get _imageDecoderConstructor;
205
+ external JSAny ? get __imageDecoderConstructor;
206
+ Object ? get _imageDecoderConstructor =>
207
+ __imageDecoderConstructor? .toObjectShallow;
205
208
206
209
/// Environment variable that allows the developer to opt out of using browser's
207
210
/// `ImageDecoder` API, and use the WASM codecs bundled with CanvasKit.
@@ -265,9 +268,13 @@ class ImageDecoder {
265
268
266
269
extension ImageDecoderExtension on ImageDecoder {
267
270
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
+
269
276
external JsPromise decode (DecodeOptions options);
270
- external void close ();
277
+ external JSVoid close ();
271
278
}
272
279
273
280
/// Options passed to the `ImageDecoder` constructor.
@@ -280,13 +287,13 @@ extension ImageDecoderExtension on ImageDecoder {
280
287
@staticInterop
281
288
class ImageDecoderOptions {
282
289
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,
290
297
});
291
298
}
292
299
@@ -302,7 +309,10 @@ class DecodeResult {}
302
309
303
310
extension DecodeResultExtension on DecodeResult {
304
311
external VideoFrame get image;
305
- external bool get complete;
312
+
313
+ @JS ('complete' )
314
+ external JSBoolean get _complete;
315
+ bool get complete => _complete.toDart;
306
316
}
307
317
308
318
/// Options passed to [ImageDecoder.decode] .
@@ -315,7 +325,7 @@ extension DecodeResultExtension on DecodeResult {
315
325
@staticInterop
316
326
class DecodeOptions {
317
327
external factory DecodeOptions ({
318
- required double frameIndex,
328
+ required JSNumber frameIndex,
319
329
});
320
330
}
321
331
@@ -332,16 +342,40 @@ class DecodeOptions {
332
342
class VideoFrame implements DomCanvasImageSource {}
333
343
334
344
extension 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
+
343
377
external VideoFrame clone ();
344
- external void close ();
378
+ external JSVoid close ();
345
379
}
346
380
347
381
/// Corresponds to the browser's `ImageTrackList` type.
@@ -370,8 +404,13 @@ extension ImageTrackListExtension on ImageTrackList {
370
404
class ImageTrack {}
371
405
372
406
extension 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;
375
414
}
376
415
377
416
void scaleCanvas2D (Object context2d, num x, num y) {
0 commit comments