Skip to content

Commit

Permalink
Adds a few APIs such as Worker (issue #36) and fixes some nullability…
Browse files Browse the repository at this point in the history
… suffixes in some APIs.
  • Loading branch information
terrier989 committed Apr 2, 2021
1 parent 984164c commit bf32d27
Show file tree
Hide file tree
Showing 29 changed files with 1,453 additions and 428 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.8
* Adds missing APIs: Worker ([issue #36](https://github.com/dint-dev/universal_html/issues/36))
and a few others.
* Fixes issues with nullability suffixes in Window, Navigator, and others.

## 2.0.7
* Fixes documentation issues and other small issues.
* WindowController can now load (fake) `Window` instances in browser just like in VM.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ documented in the relevant files.
In `pubspec.yaml`:
```yaml
dependencies:
universal_html: ^2.0.7
universal_html: ^2.0.8
```
## 2. Use
Expand Down
32 changes: 32 additions & 0 deletions lib/src/_sdk/web_audio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019 [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// -----------------------------------------------------------------------------
// PURPOSE OF THIS FILE
// -----------------------------------------------------------------------------
//
// When 'universal_html/X.dart' had a conditional export:
// export 'src/X.dart' if (dart.library.X) 'dart:X'
//
// We observed 'package:build' throwing:
// Invalid argument(s): Unsupported conditional import of `dart:X` found in
// universal_html|lib/X.dart.
//
// See:
// * Source code: https://github.com/dart-lang/build/blob/master/build_modules/lib/src/module_library.dart
// * Commit code review: https://github.com/dart-lang/build/pull/1793
//
// This file solves the problem.
//
export 'dart:web_audio';
9 changes: 4 additions & 5 deletions lib/src/controller/window_behavior_impl_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import 'dart:html';
import 'dart:indexed_db';
import 'dart:web_sql';

import 'package:universal_html/parsing.dart';

import 'window_controller.dart';

Document newDocument({
Expand All @@ -32,8 +30,8 @@ HtmlDocument newHtmlDocument({
required Window window,
required String? contentType,
}) {
return DomParser().parseFromString('<html></html>', contentType ?? 'text/html')
as HtmlDocument;
return DomParser().parseFromString(
'<html></html>', contentType ?? 'text/html') as HtmlDocument;
}

Navigator newNavigator({
Expand Down Expand Up @@ -68,7 +66,8 @@ class _FakeWindow implements Window {
String? status;

@override
late final Document document = newHtmlDocument(window: this, contentType: 'text/html');
late final Document document =
newHtmlDocument(window: this, contentType: 'text/html');

@override
// TODO: implement animationFrame
Expand Down
3 changes: 2 additions & 1 deletion lib/src/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import 'indexed_db.dart';
import 'internal/event_stream_decoder.dart';
import 'internal/multipart_form_writer.dart';
import 'svg.dart' as svg;
import 'web_audio.dart';
import 'web_gl.dart' as gl;

export 'dart:math' show Point, Rectangle;
Expand Down Expand Up @@ -79,13 +80,13 @@ part 'html/api/payment.dart';
part 'html/api/performance.dart';
part 'html/api/permissions.dart';
part 'html/api/scroll.dart';
part 'html/api/service_worker.dart';
part 'html/api/speech_synthesis.dart';
part 'html/api/storage.dart';
part 'html/api/web_rtc.dart';
part 'html/api/web_socket.dart';
part 'html/api/window.dart';
part 'html/api/window_misc.dart';
part 'html/api/workers.dart';
part 'html/dom/css.dart';
part 'html/dom/css_computed_style.dart';
part 'html/dom/css_rect.dart';
Expand Down
21 changes: 21 additions & 0 deletions lib/src/html/api/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ abstract class Animation extends EventTarget {
void reverse();
}

@Native('AnimationEffectReadOnly')
class AnimationEffectReadOnly {
AnimationEffectReadOnly._();

AnimationEffectTimingReadOnly? get timing {
throw UnimplementedError();
}

Map getComputedTiming() {
throw UnimplementedError();
}
}

abstract class AnimationEffectTiming extends AnimationEffectTimingReadOnly {
num? delay;
String? direction;
Expand Down Expand Up @@ -111,6 +124,14 @@ abstract class DocumentTimeline extends AnimationTimeline {
num get currentTime;
}

@Native('KeyframeEffectReadOnly')
class KeyframeEffectReadOnly extends AnimationEffectReadOnly {
factory KeyframeEffectReadOnly(Element? target, Object? effect,
[Object? options]) {
throw UnimplementedError();
}
}

abstract class ScrollTimeline extends AnimationTimeline {
factory ScrollTimeline([Map? options]) {
throw UnimplementedError();
Expand Down
72 changes: 39 additions & 33 deletions lib/src/html/api/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,64 +47,70 @@ The source code adopted from 'dart:html' had the following license:
part of universal_html.internal;

class Console {
/// Internal constructor. __Not part of dart:html__.
Console.internal();

MemoryInfo? get memory => null;

void assertCondition(bool condition, Object arg) {
if (!condition) {
log(arg);
// Even though many of the following JS methods can take in multiple
// arguments, we historically and currently limit the number of variable
// arguments to 1. Depending on the need, these methods may be updated to
// allow for more.

// We rename assert to assertCondition here.
void assertCondition([bool? condition, Object? arg]) {
if (condition != true) {
debug(arg);
}
}

void clear(Object arg) {}
// clear no longer takes in an argument, but we keep this as optional to
// maintain backwards compatibility.
void clear([Object? arg]) {}

void count(Object arg) {}
// count takes in a String instead, but we keep this as an Object for
// backwards compatibility.
void count([Object? arg]) {}

void debug(Object arg) {
log(arg);
}
void countReset([String? arg]) {}

void dir(Object arg) {}
void debug(Object? arg) {}

void dirxml(Object arg) {}
void dir([Object? item, Object? options]) {}

void error(Object arg) {
log(arg);
}
void dirxml(Object? arg) {}

void error(Object? arg) {}

void group(Object arg) {}
void group(Object? arg) {}

void groupCollapsed(Object arg) {}
void groupCollapsed(Object? arg) {}

void groupEnd() {}

void info(Object arg) {
log(arg);
}
void info(Object? arg) {}

void log(Object arg) {
print(arg);
}
void log(Object? arg) {}

void markTimeline(Object arg) {}
void table([Object? tabularData, List<String>? properties]) {}

void profile(String title) {}
void time([String? label]) {}

void profileEnd(String title) {}
void timeEnd([String? label]) {}

void table(Object arg) {}
void timeLog([String? label, Object? arg]) {}

void time(String title) {}
void trace(Object? arg) {}

void timeEnd(String title) {}
void warn(Object? arg) {}

void timeStamp(Object arg) {}
// The following are non-standard methods.
void profile([String? title]) {}

void trace(Object arg) {}
void profileEnd([String? title]) {}

void warn(Object arg) {
log(arg);
}
void timeStamp([Object? arg]) {}

// The following is deprecated and should be removed once we drop support for
// older Safari browsers.
void markTimeline(Object? arg) {}
}
33 changes: 23 additions & 10 deletions lib/src/html/api/data_transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,46 @@ part of universal_html.internal;

abstract class DataTransfer {
String? dropEffect;

String? effectAllowed;

List<File> get files;
final List<File>? files = [];

DataTransferItemList get items;
List<DataTransferItem>? items = [];

List<String> get types;
final List<String>? types = [];

void clearData([String format]);
void clearData([String? format]) {
throw UnimplementedError();
}

String getData(String format);
String getData(String format) {
throw UnimplementedError();
}

void setData(String format, String data);
void setData(String format, String data) {
throw UnimplementedError();
}

void setDragImage(Element image, int x, int y);
void setDragImage(Element image, int x, int y) {}
}

abstract class DataTransferItem {
DataTransferItem._();

String get kind;
String? get kind {
throw UnimplementedError();
}

String get type;
String? get type {
throw UnimplementedError();
}

Entry getAsEntry();

File getAsFile();
File? getAsFile() {
throw UnimplementedError();
}
}

abstract class DataTransferItemList {
Expand Down
Loading

0 comments on commit bf32d27

Please sign in to comment.