diff --git a/CHANGELOG.md b/CHANGELOG.md index 985e8ea..3c6c622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 31f93f2..9b99ded 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/src/_sdk/web_audio.dart b/lib/src/_sdk/web_audio.dart new file mode 100644 index 0000000..66d9827 --- /dev/null +++ b/lib/src/_sdk/web_audio.dart @@ -0,0 +1,32 @@ +// Copyright 2019 terrier989@gmail.com +// +// 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'; diff --git a/lib/src/controller/window_behavior_impl_browser.dart b/lib/src/controller/window_behavior_impl_browser.dart index 3d7d735..6d5ea27 100644 --- a/lib/src/controller/window_behavior_impl_browser.dart +++ b/lib/src/controller/window_behavior_impl_browser.dart @@ -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({ @@ -32,8 +30,8 @@ HtmlDocument newHtmlDocument({ required Window window, required String? contentType, }) { - return DomParser().parseFromString('', contentType ?? 'text/html') - as HtmlDocument; + return DomParser().parseFromString( + '', contentType ?? 'text/html') as HtmlDocument; } Navigator newNavigator({ @@ -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 diff --git a/lib/src/html.dart b/lib/src/html.dart index 8c119a7..bedd986 100644 --- a/lib/src/html.dart +++ b/lib/src/html.dart @@ -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; @@ -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'; diff --git a/lib/src/html/api/animation.dart b/lib/src/html/api/animation.dart index 60e72f5..ea53d1a 100644 --- a/lib/src/html/api/animation.dart +++ b/lib/src/html/api/animation.dart @@ -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; @@ -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(); diff --git a/lib/src/html/api/console.dart b/lib/src/html/api/console.dart index d09ce7d..50658c4 100644 --- a/lib/src/html/api/console.dart +++ b/lib/src/html/api/console.dart @@ -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? 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) {} } diff --git a/lib/src/html/api/data_transfer.dart b/lib/src/html/api/data_transfer.dart index 0c2aad3..906cfbf 100644 --- a/lib/src/html/api/data_transfer.dart +++ b/lib/src/html/api/data_transfer.dart @@ -48,33 +48,46 @@ part of universal_html.internal; abstract class DataTransfer { String? dropEffect; + String? effectAllowed; - List get files; + final List? files = []; - DataTransferItemList get items; + List? items = []; - List get types; + final List? 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 { diff --git a/lib/src/html/api/event_subclasses.dart b/lib/src/html/api/event_subclasses.dart index 311e797..c347e41 100644 --- a/lib/src/html/api/event_subclasses.dart +++ b/lib/src/html/api/event_subclasses.dart @@ -71,11 +71,19 @@ class AnimationPlaybackEvent extends Event { } class BackgroundFetchedEvent extends Event { - BackgroundFetchedEvent(String type) : super.internal(type); + BackgroundFetchedEvent(String type, Map init) : super.internal(type); + + final List? fetches = []; + + Future updateUI(String title) { + throw UnimplementedError(); + } } class BackgroundFetchEvent extends Event { - BackgroundFetchEvent(String type) : super.internal(type); + BackgroundFetchEvent(String type, Map init) : super.internal(type); + + String? get id => throw UnimplementedError(); } class BackgroundFetchFailEvent extends Event { @@ -114,13 +122,13 @@ abstract class CanMakePaymentEvent extends ExtendableEvent { throw UnimplementedError(); } - List get methodData; + List? get methodData => throw UnimplementedError(); - List get modifiers; + List? get modifiers => throw UnimplementedError(); - String get paymentRequestOrigin; + String? get paymentRequestOrigin => throw UnimplementedError(); - String get topLevelOrigin; + String? get topLevelOrigin => throw UnimplementedError(); void respondWith(Future canMakePaymentResponse) { throw UnimplementedError(); @@ -191,8 +199,11 @@ abstract class DeviceMotionEvent extends Event { factory DeviceMotionEvent(String type, [Map? eventInitDict]) { throw UnimplementedError(); } + DeviceAcceleration? get acceleration; + DeviceAcceleration? get accelerationIncludingGravity; + num? get interval; DeviceRotationRate? get rotationRate; @@ -310,40 +321,42 @@ class KeyboardEvent extends UIEvent { static const int DOM_KEY_LOCATION_STANDARD = 0x00; final bool altKey; - final int? charCode; + final int charCode; final String? code; final bool ctrlKey; - final bool isComposing; - final int? keyCode; + final bool? isComposing; + final int keyCode; final int? location; final bool metaKey; - final bool repeat; + final bool? repeat; final bool shiftKey; KeyboardEvent( String type, { + Window? view, this.altKey = false, - this.charCode, + int? charCode, this.code, this.ctrlKey = false, this.isComposing = false, - this.keyCode, + int? keyCode, this.location, this.metaKey = false, this.repeat = false, this.shiftKey = false, bool canBubble = true, bool cancelable = true, - Object? view, - }) : super( + }) : charCode = charCode ?? -1, + keyCode = keyCode ?? -1, + super( type, canBubble: canBubble, cancelable: cancelable, ); - String get key => throw UnimplementedError(); + String? get key => throw UnimplementedError(); - int get which => throw UnimplementedError(); + int? get which => throw UnimplementedError(); bool getModifierState(String keyArg) => false; } @@ -361,16 +374,13 @@ class KeyEvent extends KeyboardEvent { static EventStreamProvider get keyUpEvent => throw UnimplementedError(); - @override - final int charCode; - @override final EventTarget currentTarget; KeyEvent( String type, { required this.currentTarget, - this.charCode = 0, + int? charCode, bool altKey = false, bool canBubble = true, bool cancelable = true, @@ -385,6 +395,7 @@ class KeyEvent extends KeyboardEvent { view: view, canBubble: canBubble, cancelable: cancelable, + charCode: charCode, keyCode: keyCode, location: location, ctrlKey: ctrlKey, @@ -396,19 +407,21 @@ class KeyEvent extends KeyboardEvent { class MessageEvent extends Event { final dynamic? data; - final String? lastEventId; - final String? origin; + final String lastEventId; + final String origin; final EventTarget? source; - final List? ports; + final List ports; MessageEvent( String type, { this.data, - this.origin, + String? origin, String? lastEventId, this.source, - this.ports, + List? ports, }) : lastEventId = lastEventId ?? '', + origin = origin ?? '', + ports = ports ?? const [], super.internal(type); String? get suborigin => null; diff --git a/lib/src/html/api/history.dart b/lib/src/html/api/history.dart index 50e16c0..371e85d 100644 --- a/lib/src/html/api/history.dart +++ b/lib/src/html/api/history.dart @@ -46,7 +46,7 @@ The source code adopted from 'dart:html' had the following license: part of universal_html.internal; -class History { +class History extends HistoryBase { /// Checks if the State APIs are supported on the current platform. /// /// See also: @@ -72,14 +72,17 @@ class History { Object? get state => _state; + @override void back() { go(-1); } + @override void forward() { go(1); } + @override void go([int? delta]) { // The effect is is asynchronous scheduleMicrotask(() { @@ -126,7 +129,13 @@ class History { } } -class Location extends Object with _UrlBase { +abstract class HistoryBase { + void back(); + void forward(); + void go(int distance); +} + +class Location extends LocationBase with _UrlBase { String href; Location.internal({required this.href}); diff --git a/lib/src/html/api/media.dart b/lib/src/html/api/media.dart index 8a6a192..18f1ab0 100644 --- a/lib/src/html/api/media.dart +++ b/lib/src/html/api/media.dart @@ -85,17 +85,26 @@ abstract class MediaDeviceInfo { String? get label; } +@Native('MediaDevices') class MediaDevices extends EventTarget { - MediaDevices._() : super.internal(); + factory MediaDevices._() { + throw UnimplementedError(); + } + + Future> enumerateDevices() => throw UnimplementedError(); - Future> enumerateDevices() async { - return const []; + Map getSupportedConstraints() { + throw UnimplementedError(); } - Map getSupportedConstraints() => {}; + Future getUserMedia([Map? constraints]) { + throw UnimplementedError(); + } } -abstract class MediaError { +@Unstable() +@Native('MediaError') +class MediaError { static const int MEDIA_ERR_ABORTED = 1; static const int MEDIA_ERR_DECODE = 3; @@ -108,9 +117,13 @@ abstract class MediaError { throw UnimplementedError(); } - int? get code; + int get code { + throw UnimplementedError(); + } - String? get message; + String? get message { + throw UnimplementedError(); + } } abstract class MediaKeys { @@ -131,8 +144,8 @@ abstract class MediaKeysPolicy { String? get minHdcpVersion; } -abstract class MediaRecorder implements EventTarget { - // To suppress missing implicit constructor warnings. +@Native('MediaRecorder') +class MediaRecorder extends EventTarget { static const EventStreamProvider errorEvent = EventStreamProvider('error'); @@ -143,35 +156,82 @@ abstract class MediaRecorder implements EventTarget { throw UnimplementedError(); } - int get audioBitsPerSecond; + int? get audioBitsPerSecond { + throw UnimplementedError(); + } - String get mimeType; + String? get mimeType { + throw UnimplementedError(); + } Stream get onError => errorEvent.forTarget(this); Stream get onPause => pauseEvent.forTarget(this); - String get state; + String? get state { + throw UnimplementedError(); + } - MediaStream get stream; + MediaStream? get stream { + throw UnimplementedError(); + } - int get videoBitsPerSecond; + int? get videoBitsPerSecond { + throw UnimplementedError(); + } - void pause(); + void pause() { + throw UnimplementedError(); + } - void requestData(); + void requestData() { + throw UnimplementedError(); + } - void resume(); + void resume() { + throw UnimplementedError(); + } - void start([int timeslice]); + void start([int? timeslice]) { + throw UnimplementedError(); + } - void stop(); + void stop() { + throw UnimplementedError(); + } static bool isTypeSupported(String type) { throw UnimplementedError(); } } +@Native('MediaSession') +class MediaSession { + factory MediaSession._() { + throw UnimplementedError(); + } + + MediaMetadata? get metadata { + throw UnimplementedError(); + } + + set metadata(MediaMetadata? value) { + throw UnimplementedError(); + } + + String? get playbackState { + throw UnimplementedError(); + } + + set playbackState(String? value) { + throw UnimplementedError(); + } + + void setActionHandler(String action, MediaSessionActionHandler? handler) { + throw UnimplementedError(); + } +} + abstract class MediaSettingsRange { MediaSettingsRange._(); @@ -182,20 +242,59 @@ abstract class MediaSettingsRange { num get step; } -abstract class MediaSource extends EventTarget { +@SupportedBrowser(SupportedBrowser.CHROME) +@SupportedBrowser(SupportedBrowser.IE, '11') +@Native('MediaSource') +class MediaSource extends EventTarget { static bool get supported => false; - MediaSource._() : super.internal(); + factory MediaSource() { + throw UnimplementedError(); + } - List get activeSourceBuffers; + List? get activeSourceBuffers { + throw UnimplementedError(); + } - num get duration; + num? get duration { + throw UnimplementedError(); + } - String get readyState; + set duration(num? value) { + throw UnimplementedError(); + } + + String? get readyState { + throw UnimplementedError(); + } + + List? get sourceBuffers { + throw UnimplementedError(); + } + + SourceBuffer addSourceBuffer(String type) { + throw UnimplementedError(); + } + + void clearLiveSeekableRange() { + throw UnimplementedError(); + } + + void endOfStream([String? error]) { + throw UnimplementedError(); + } + + void removeSourceBuffer(SourceBuffer buffer) { + throw UnimplementedError(); + } - List get sourceBuffers; + void setLiveSeekableRange(num start, num end) { + throw UnimplementedError(); + } - static bool isTypeSupported(String type) => false; + static bool isTypeSupported(String type) { + return false; + } } abstract class MediaStream implements EventTarget { @@ -303,16 +402,94 @@ abstract class RemotePlayback extends EventTarget { Future watchAvailability(RemotePlaybackAvailabilityCallback callback); } -abstract class SourceBuffer { - SourceBuffer._(); +@Native('SourceBuffer') +class SourceBuffer extends EventTarget { + static const EventStreamProvider abortEvent = + EventStreamProvider('abort'); - void abort(); + static const EventStreamProvider errorEvent = + EventStreamProvider('error'); - void appendBuffer(ByteBuffer data); + factory SourceBuffer._() { + throw UnimplementedError(); + } - void appendTypedData(TypedData data); + num? get appendWindowEnd { + throw UnimplementedError(); + } - void remove(num start, num end); + set appendWindowEnd(num? value) { + throw UnimplementedError(); + } + + num? get appendWindowStart { + throw UnimplementedError(); + } + + set appendWindowStart(num? value) { + throw UnimplementedError(); + } + + List? get audioTracks { + throw UnimplementedError(); + } + + TimeRanges? get buffered { + throw UnimplementedError(); + } + + String? get mode { + throw UnimplementedError(); + } + + set mode(String? value) { + throw UnimplementedError(); + } + + Stream get onAbort => abortEvent.forTarget(this); + + Stream get onError => errorEvent.forTarget(this); + + num? get timestampOffset { + throw UnimplementedError(); + } + + set timestampOffset(num? value) { + throw UnimplementedError(); + } + + List? get trackDefaults { + throw UnimplementedError(); + } + + set trackDefaults(List? value) { + throw UnimplementedError(); + } + + bool? get updating { + throw UnimplementedError(); + } + + List? get videoTracks { + throw UnimplementedError(); + } + + void abort() { + throw UnimplementedError(); + } + + void appendBuffer(ByteBuffer data) { + throw UnimplementedError(); + } + + @JSName('appendBuffer') + void appendTypedData(TypedData data) { + throw UnimplementedError(); + } + + void remove(num start, num end) { + throw UnimplementedError(); + } } class TextTrack { @@ -331,6 +508,70 @@ abstract class TimeRanges { double start(int index); } +@Native('TrackDefault') +class TrackDefault { + factory TrackDefault( + String type, String language, String label, List kinds, + [String? byteStreamTrackID]) { + throw UnimplementedError(); + } + + String? get byteStreamTrackID { + throw UnimplementedError(); + } + + Object? get kinds { + throw UnimplementedError(); + } + + String? get label { + throw UnimplementedError(); + } + + String? get language { + throw UnimplementedError(); + } + + String? get type { + throw UnimplementedError(); + } +} + class VideoPlaybackQuality { VideoPlaybackQuality._(); } + +@Native('VideoTrack') +class VideoTrack { + factory VideoTrack._() { + throw UnimplementedError(); + } + + String? get id { + throw UnimplementedError(); + } + + String? get kind { + throw UnimplementedError(); + } + + String? get label { + throw UnimplementedError(); + } + + String? get language { + throw UnimplementedError(); + } + + bool? get selected { + throw UnimplementedError(); + } + + set selected(bool? value) { + throw UnimplementedError(); + } + + SourceBuffer? get sourceBuffer { + throw UnimplementedError(); + } +} diff --git a/lib/src/html/api/navigator.dart b/lib/src/html/api/navigator.dart index 77e05a1..deb5749 100644 --- a/lib/src/html/api/navigator.dart +++ b/lib/src/html/api/navigator.dart @@ -52,46 +52,59 @@ class Navigator extends NavigatorConcurrentHardware NavigatorOnLine, NavigatorAutomationInformation, NavigatorID { - final Permissions permissions = Permissions._(); + final num? deviceMemory; - /// Amount of memory in the device. - final int? deviceMemory; + @Unstable() + late Geolocation geolocation = Geolocation.internal(); + + @Unstable() + final String? productSub; final Window internalWindow; @override - final String? appName; + final String appName; + + @override + final String appVersion; @override - final String? appVersion; + final String appCodeName; - late final Geolocation geolocation = Geolocation.internal(); + @override + final String platform; + + @override + final String product; /// Internal constructor. NOT part of "dart:html". Navigator.internal({ required this.internalWindow, this.deviceMemory, + this.appCodeName = '', this.appName = 'Netscape', this.appVersion = '5.0', + this.platform = 'Win32', + this.product = 'Gecko', + this.productSub = '20030107', }) : super._(); - @override - String? get appCodeName => null; + _BudgetService? get budget => null; - _Clipboard? get clipboard => throw UnimplementedError(); + _Clipboard? get clipboard => null; - NetworkInformation get connection => throw UnimplementedError(); + NetworkInformation? get connection => null; @Unstable() @override bool? get cookieEnabled => false; - CredentialsContainer get credentials => throw UnimplementedError(); + CredentialsContainer? get credentials => null; @override bool get dartEnabled => false; - String get doNotTrack => throw UnimplementedError(); + String? get doNotTrack => null; @override String? get language { @@ -102,37 +115,29 @@ class Navigator extends NavigatorConcurrentHardware @override List get languages => throw UnimplementedError(); - int get maxTouchPoints => throw UnimplementedError(); + int? get maxTouchPoints => null; - MediaCapabilities get mediaCapabilities => throw UnimplementedError(); + MediaCapabilities? get mediaCapabilities => null; - MediaDevices get mediaDevices => MediaDevices._(); + MediaDevices? get mediaDevices => null; - MediaSession get mediaSession => throw UnimplementedError(); + MediaSession? get mediaSession => null; - List get mimeTypes => throw UnimplementedError(); + List? get mimeTypes => null; - Object? get nfc => null; + _NFC? get nfc => null; @override bool get onLine => false; + Permissions? get permissions => null; + @deprecated DeprecatedStorageQuota? get persistentStorage => null; - @override - String get platform => 'Win32'; - Presentation? get presentation => null; - @override - String get product => 'Gecko'; - - String get productSub => '20030107'; - - ServiceWorkerContainer get serviceWorker { - throw UnimplementedError(); - } + ServiceWorkerContainer? get serviceWorker => null; StorageManager? get storage => null; @@ -142,8 +147,10 @@ class Navigator extends NavigatorConcurrentHardware @override String get userAgent => '-'; + @Unstable() String get vendor => '-'; + @Unstable() String get vendorSub => ''; VR? get vr => null; diff --git a/lib/src/html/api/navigator_misc.dart b/lib/src/html/api/navigator_misc.dart index 6db7d4e..17625ad 100644 --- a/lib/src/html/api/navigator_misc.dart +++ b/lib/src/html/api/navigator_misc.dart @@ -54,6 +54,17 @@ typedef StorageQuotaCallback = void Function(int grantedQuotaInBytes); typedef StorageUsageCallback = void Function( int currentUsageInBytes, int currentQuotaInBytes); +@Native('BudgetState') +class BudgetState { + factory BudgetState._() { + throw UnimplementedError(); + } + + num? get budgetAt => throw UnimplementedError(); + + int? get time => throw UnimplementedError(); +} + abstract class Credential { Credential._(); @@ -174,20 +185,6 @@ abstract class MediaMetadata { } } -abstract class MediaSession { - MediaMetadata? metadata; - - String? playbackState; - - factory MediaSession._() { - throw UnimplementedError(); - } - - void setActionHandler(String action, MediaSessionActionHandler handler) { - throw UnimplementedError(); - } -} - abstract class MimeType { MimeType._(); @@ -221,19 +218,19 @@ abstract class NavigatorCookies { abstract class NavigatorID { NavigatorID._(); - String? get appCodeName; + String get appCodeName; - String? get appName; + String get appName; - String? get appVersion; + String get appVersion; bool? get dartEnabled; String? get platform; - String? get product; + String get product; - String? get userAgent; + String get userAgent; } abstract class NavigatorLanguage { @@ -408,6 +405,18 @@ abstract class VR implements EventTarget { Future getDevices(); } +class _BudgetService { + factory _BudgetService._() { + throw UnimplementedError(); + } + + Future getBudget() => throw UnimplementedError(); + + Future getCost(String operation) => throw UnimplementedError(); + + Future reserve(String operation) => throw UnimplementedError(); +} + abstract class _Clipboard implements EventTarget { _Clipboard._(); @@ -419,3 +428,10 @@ abstract class _Clipboard implements EventTarget { Future writeText(String data) => throw UnimplementedError(); } + +@Native('NFC') +abstract class _NFC { + factory _NFC._() { + throw UnimplementedError(); + } +} diff --git a/lib/src/html/api/payment.dart b/lib/src/html/api/payment.dart index 73f184e..33b09ca 100644 --- a/lib/src/html/api/payment.dart +++ b/lib/src/html/api/payment.dart @@ -72,40 +72,68 @@ abstract class PaymentAddress { String? get sortingCode; } -abstract class PaymentInstruments { - PaymentInstruments._(); +@Native('PaymentInstruments') +class PaymentInstruments { + factory PaymentInstruments._() { + throw UnimplementedError(); + } - Future clear(); + Future clear() => throw UnimplementedError(); - Future delete(String instrumentKey); + Future delete(String instrumentKey) => throw UnimplementedError(); - Future> get(String instrumentKey); + Future?> get(String instrumentKey) => + throw UnimplementedError(); - Future has(String instrumentKey); + Future has(String instrumentKey) => throw UnimplementedError(); - Future> keys(); + Future> keys() => throw UnimplementedError(); - Future set(String instrumentKey, Map details); + Future set(String instrumentKey, Map details) { + throw UnimplementedError(); + } } -abstract class PaymentManager { - String? userHint; +@Native('PaymentManager') +class PaymentManager { + factory PaymentManager._() { + throw UnimplementedError(); + } + + PaymentInstruments? get instruments { + throw UnimplementedError(); + } - PaymentManager._(); + String? get userHint { + throw UnimplementedError(); + } - PaymentInstruments get instruments; + set userHint(String? value) { + throw UnimplementedError(); + } } -abstract class PaymentRequest extends EventTarget { +@Native('PaymentRequest') +class PaymentRequest extends EventTarget { factory PaymentRequest(List methodData, Map details, [Map? options]) { throw UnimplementedError(); } - PaymentAddress? get shippingAddress; + String? get id { + throw UnimplementedError(); + } + + PaymentAddress? get shippingAddress { + throw UnimplementedError(); + } - String? get shippingOption; + String? get shippingOption { + throw UnimplementedError(); + } - String? get shippingType; + String? get shippingType { + throw UnimplementedError(); + } Future abort() => throw UnimplementedError(); @@ -114,26 +142,43 @@ abstract class PaymentRequest extends EventTarget { Future show() => throw UnimplementedError(); } -abstract class PaymentResponse { - PaymentResponse._(); - - Object? get details; +@Native('PaymentResponse') +class PaymentResponse { + factory PaymentResponse._() { + throw UnimplementedError(); + } - String? get methodName; + Object? get details { + throw UnimplementedError(); + } - String? get payerEmail; + String? get methodName { + throw UnimplementedError(); + } - String? get payerName; + String? get payerEmail { + throw UnimplementedError(); + } - String? get payerPhone; + String? get payerName { + throw UnimplementedError(); + } - String? get requestId; + String? get payerPhone { + throw UnimplementedError(); + } - PaymentAddress? get shippingAddress; + String? get requestId { + throw UnimplementedError(); + } - String? get shippingOption; + PaymentAddress? get shippingAddress { + throw UnimplementedError(); + } - Future complete([String? paymentResult]) { + String? get shippingOption { throw UnimplementedError(); } + + Future complete([String? paymentResult]) => throw UnimplementedError(); } diff --git a/lib/src/html/api/performance.dart b/lib/src/html/api/performance.dart index 31e6426..03f0a62 100644 --- a/lib/src/html/api/performance.dart +++ b/lib/src/html/api/performance.dart @@ -58,20 +58,32 @@ abstract class MemoryInfo { int get usedJSHeapSize; } +@SupportedBrowser(SupportedBrowser.CHROME) +@SupportedBrowser(SupportedBrowser.FIREFOX) +@SupportedBrowser(SupportedBrowser.IE) +@Native('Performance') class Performance extends EventTarget { - static bool get supported => false; + // To suppress missing implicit constructor warnings. + factory Performance._() { + throw UnimplementedError(); + } - final num timeOrigin = DateTime.now().microsecondsSinceEpoch / 10e6; + /// Checks if this type is supported on the current platform. + static bool get supported => false; - final MemoryInfo memory = MemoryInfo._(); + MemoryInfo? get memory { + throw UnimplementedError(); + } - Performance._() : super.internal(); + num? get timeOrigin { + throw UnimplementedError(); + } - void clearMarks(String markName) { + void clearMarks(String? markName) { throw UnimplementedError(); } - void clearMeasures(String measureName) { + void clearMeasures(String? measureName) { throw UnimplementedError(); } @@ -79,19 +91,55 @@ class Performance extends EventTarget { throw UnimplementedError(); } + List getEntries() { + throw UnimplementedError(); + } + + List getEntriesByName(String name, String? entryType) { + throw UnimplementedError(); + } + + List getEntriesByType(String entryType) { + throw UnimplementedError(); + } + void mark(String markName) { throw UnimplementedError(); } - void measure(String measureName, String startMark, String endMark) { + void measure(String measureName, String? startMark, String? endMark) { throw UnimplementedError(); } double now() { - return DateTime.now().microsecondsSinceEpoch / 10e6; + throw UnimplementedError(); } void setResourceTimingBufferSize(int maxSize) { throw UnimplementedError(); } } + +@Native('PerformanceEntry') +class PerformanceEntry { + // To suppress missing implicit constructor warnings. + factory PerformanceEntry._() { + throw UnimplementedError(); + } + + num get duration { + throw UnimplementedError(); + } + + String get entryType { + throw UnimplementedError(); + } + + String get name { + throw UnimplementedError(); + } + + num get startTime { + throw UnimplementedError(); + } +} diff --git a/lib/src/html/api/permissions.dart b/lib/src/html/api/permissions.dart index 441e651..a66c5c0 100644 --- a/lib/src/html/api/permissions.dart +++ b/lib/src/html/api/permissions.dart @@ -66,6 +66,15 @@ class Permissions { } } -class PermissionStatus { - PermissionStatus._(); +class PermissionStatus extends EventTarget { + static const EventStreamProvider changeEvent = + EventStreamProvider('change'); + + PermissionStatus() : super.internal(); + + Stream get onChange => changeEvent.forTarget(this); + + String? get state { + throw UnimplementedError(); + } } diff --git a/lib/src/html/api/scroll.dart b/lib/src/html/api/scroll.dart index ecb680b..a652591 100644 --- a/lib/src/html/api/scroll.dart +++ b/lib/src/html/api/scroll.dart @@ -51,29 +51,29 @@ abstract class ScrollState { throw UnimplementedError(); } - num get deltaGranularity; + num? get deltaGranularity; - num get deltaX; + num? get deltaX; - num get deltaY; + num? get deltaY; - bool get fromUserInput; + bool? get fromUserInput; - bool get inInertialPhase; + bool? get inInertialPhase; - bool get isBeginning; + bool? get isBeginning; - bool get isDirectManipulation; + bool? get isDirectManipulation; - bool get isEnding; + bool? get isEnding; - int get positionX; + int? get positionX; - int get positionY; + int? get positionY; - num get velocityX; + num? get velocityX; - num get velocityY; + num? get velocityY; void consumeDelta(num x, num y); diff --git a/lib/src/html/api/web_socket.dart b/lib/src/html/api/web_socket.dart index 8e765d3..300f8d1 100644 --- a/lib/src/html/api/web_socket.dart +++ b/lib/src/html/api/web_socket.dart @@ -46,7 +46,45 @@ The source code adopted from 'dart:html' had the following license: part of universal_html.internal; -abstract class WebSocket extends EventTarget { +/// Use the WebSocket interface to connect to a WebSocket, +/// and to send and receive data on that WebSocket. +/// +/// To use a WebSocket in your web app, first create a WebSocket object, +/// passing the WebSocket URL as an argument to the constructor. +/// +/// var webSocket = new WebSocket('ws://127.0.0.1:1337/ws'); +/// +/// To send data on the WebSocket, use the [send] method. +/// +/// if (webSocket != null && webSocket.readyState == WebSocket.OPEN) { +/// webSocket.send(data); +/// } else { +/// print('WebSocket not connected, message $data not sent'); +/// } +/// +/// To receive data on the WebSocket, register a listener for message events. +/// +/// webSocket.onMessage.listen((MessageEvent e) { +/// receivedData(e.data); +/// }); +/// +/// The message event handler receives a [MessageEvent] object +/// as its sole argument. +/// You can also define open, close, and error handlers, +/// as specified by [WebSocketEvents]. +/// +/// For more information, see the +/// [WebSockets](http://www.dartlang.org/docs/library-tour/#html-websockets) +/// section of the library tour and +/// [Introducing WebSockets](http://www.html5rocks.com/en/tutorials/websockets/basics/), +/// an HTML5Rocks.com tutorial. +@SupportedBrowser(SupportedBrowser.CHROME) +@SupportedBrowser(SupportedBrowser.FIREFOX) +@SupportedBrowser(SupportedBrowser.IE, '10') +@SupportedBrowser(SupportedBrowser.SAFARI) +@Unstable() +@Native('WebSocket') +class WebSocket extends EventTarget { /// Static factory designed to expose `close` events to event /// handlers that are not necessarily instances of [WebSocket]. /// @@ -75,6 +113,13 @@ abstract class WebSocket extends EventTarget { static const EventStreamProvider openEvent = EventStreamProvider('open'); + factory WebSocket(String url, [Object? protocols]) { + throw UnimplementedError(); + } + + /// Checks if this type is supported on the current platform. + static bool get supported => false; + static const int CLOSED = 3; static const int CLOSING = 2; @@ -83,36 +128,33 @@ abstract class WebSocket extends EventTarget { static const int OPEN = 1; - /// Checks if this type is supported on the current platform. - static bool get supported => false; - - String? binaryType; - - factory WebSocket(String url, [Object? protocols]) { + String? get binaryType { throw UnimplementedError(); } - int? get bufferedAmount; - - String? get extensions; - - /// Stream of `close` events handled by this [WebSocket]. - Stream get onClose => closeEvent.forTarget(this); - - /// Stream of `error` events handled by this [WebSocket]. - Stream get onError => errorEvent.forTarget(this); + set binaryType(String? value) { + throw UnimplementedError(); + } - /// Stream of `message` events handled by this [WebSocket]. - Stream get onMessage => messageEvent.forTarget(this); + int? get bufferedAmount { + throw UnimplementedError(); + } - /// Stream of `open` events handled by this [WebSocket]. - Stream get onOpen => openEvent.forTarget(this); + String? get extensions { + throw UnimplementedError(); + } - String? get protocol; + String? get protocol { + throw UnimplementedError(); + } - int get readyState; + int get readyState { + throw UnimplementedError(); + } - String get url; + String? get url { + throw UnimplementedError(); + } void close([int? code, String? reason]) { throw UnimplementedError(); @@ -127,6 +169,8 @@ abstract class WebSocket extends EventTarget { throw UnimplementedError(); } + @JSName('send') + /// Transmit data to the server over this connection. /// /// This method accepts data of type [Blob], [ByteBuffer], [String], or @@ -136,6 +180,8 @@ abstract class WebSocket extends EventTarget { throw UnimplementedError(); } + @JSName('send') + /// Transmit data to the server over this connection. /// /// This method accepts data of type [Blob], [ByteBuffer], [String], or @@ -145,6 +191,8 @@ abstract class WebSocket extends EventTarget { throw UnimplementedError(); } + @JSName('send') + /// Transmit data to the server over this connection. /// /// This method accepts data of type [Blob], [ByteBuffer], [String], or @@ -154,6 +202,8 @@ abstract class WebSocket extends EventTarget { throw UnimplementedError(); } + @JSName('send') + /// Transmit data to the server over this connection. /// /// This method accepts data of type [Blob], [ByteBuffer], [String], or @@ -162,4 +212,16 @@ abstract class WebSocket extends EventTarget { void sendTypedData(TypedData data) { throw UnimplementedError(); } + + /// Stream of `close` events handled by this [WebSocket]. + Stream get onClose => closeEvent.forTarget(this); + + /// Stream of `error` events handled by this [WebSocket]. + Stream get onError => errorEvent.forTarget(this); + + /// Stream of `message` events handled by this [WebSocket]. + Stream get onMessage => messageEvent.forTarget(this); + + /// Stream of `open` events handled by this [WebSocket]. + Stream get onOpen => openEvent.forTarget(this); } diff --git a/lib/src/html/api/window.dart b/lib/src/html/api/window.dart index 74458b6..07a2b66 100644 --- a/lib/src/html/api/window.dart +++ b/lib/src/html/api/window.dart @@ -49,6 +49,10 @@ part of universal_html.internal; /// Global window. Window get window => WindowController.topLevel.window as Window; +abstract class LocationBase { + set href(String val); +} + class Window extends EventTarget with WindowBase implements WindowEventHandlers { @@ -199,39 +203,6 @@ class Window extends EventTarget /// see http://dev.w3.org/csswg/cssom-view/#geometry static bool get supportsPointConversions => false; - bool _closed = false; - - /// The name of this window. - /// - /// ## Other resources - /// - /// * [Window.name](https://developer.mozilla.org/en-US/docs/Web/API/Window/name) - /// from MDN. - String name = ''; - - /// The height of this window including all user interface elements. - /// - /// ## Other resources - /// - /// * [Window.outerHeight](https://developer.mozilla.org/en-US/docs/Web/API/Window/outerHeight) - /// from MDN. - final int outerHeight; - - /// The width of the window including all user interface elements. - /// - /// ## Other resources - /// - /// * [Window.outerWidth](https://developer.mozilla.org/en-US/docs/Web/API/Window/outerWidth) - /// from MDN. - final int outerWidth; - - /// *Deprecated*. - String status = ''; - - final WindowController internalWindowController; - - final String _initialHref; - /// The application cache for this window. /// /// ## Other resources @@ -242,29 +213,29 @@ class Window extends EventTarget /// * [Application cache /// API](https://html.spec.whatwg.org/multipage/browsers.html#application-cache-api) /// from WHATWG. - late final ApplicationCache applicationCache = ApplicationCache.internal(); - /// The debugging console for this window. - late final Console console = Console.internal(); + late final ApplicationCache? applicationCache = ApplicationCache.internal(); - /// The newest document in this window. + late final CacheStorage? caches = CacheStorage._(); + + late final CookieStore? cookieStore = CookieStore._(); + + /// *Deprecated*. + + String? defaultStatus; + + /// *Deprecated*. + + String? defaultstatus; + + late final External? external = External.internal(); + + /// The current session history for this window's newest document. /// /// ## Other resources /// - /// * [Loading web - /// pages](https://html.spec.whatwg.org/multipage/browsers.html) + /// * [Loading web pages](https://html.spec.whatwg.org/multipage/browsers.html) /// from WHATWG. - late final Document document = () { - // Note that `as` expressions are required because of - // "dart:html OR universal_html" confusion by the analyzer. - final window = this as universal_html_in_browser_or_vm.Window; - final document = - internalWindowController.windowBehavior.newDocument(window: window); - return document as Document; - }(); - - late final External external = External.internal(); - @override late final History history = History.internal(); @@ -280,12 +251,14 @@ class Window extends EventTarget /// from W3C. late final Storage localStorage = Storage._(this); - /// The current location of this window. + /// The name of this window. /// - /// Location currentLocation = window.location; - /// print(currentLocation.href); // 'http://www.example.com:80/' - @override - late Location location = Location.internal(href: _initialHref); + /// ## Other resources + /// + /// * [Window.name](https://developer.mozilla.org/en-US/docs/Web/API/Window/name) + /// from MDN. + + String? name; /// The user agent accessing this window. /// @@ -294,6 +267,7 @@ class Window extends EventTarget /// * [The navigator /// object](https://html.spec.whatwg.org/multipage/webappapis.html#the-navigator-object) /// from WHATWG. + late final Navigator navigator = () { // Note that `as` expressions are required because of // "dart:html OR universal_html" confusion by the analyzer. @@ -303,6 +277,25 @@ class Window extends EventTarget return navigator as Navigator; }(); + @override + WindowBase? opener; + + /// The height of this window including all user interface elements. + /// + /// ## Other resources + /// + /// * [Window.outerHeight](https://developer.mozilla.org/en-US/docs/Web/API/Window/outerHeight) + /// from MDN. + final int outerHeight; + + /// The width of the window including all user interface elements. + /// + /// ## Other resources + /// + /// * [Window.outerWidth](https://developer.mozilla.org/en-US/docs/Web/API/Window/outerWidth) + /// from MDN. + final int outerWidth; + /// Timing and navigation data for this window. /// /// ## Other resources @@ -312,6 +305,9 @@ class Window extends EventTarget /// from HTML5Rocks. /// * [Navigation timing /// specification](http://www.w3.org/TR/navigation-timing/) from W3C. + @SupportedBrowser(SupportedBrowser.CHROME) + @SupportedBrowser(SupportedBrowser.FIREFOX) + @SupportedBrowser(SupportedBrowser.IE) late final Performance performance = Performance._(); /// Storage for this window that is cleared when this session ends. @@ -325,8 +321,42 @@ class Window extends EventTarget /// applications](http://diveintohtml5.info/storage.html) from Dive Into HTML5. /// * [Local storage /// specification](http://www.w3.org/TR/webstorage/#dom-sessionstorage) from W3C. + late final Storage sessionStorage = Storage._(this); + /// *Deprecated*. + String? status; + + final WindowController internalWindowController; + + final String _initialHref; + + /// The debugging console for this window. + late final Console console = Console.internal(); + + /// The newest document in this window. + /// + /// ## Other resources + /// + /// * [Loading web + /// pages](https://html.spec.whatwg.org/multipage/browsers.html) + /// from WHATWG. + late final Document document = () { + // Note that `as` expressions are required because of + // "dart:html OR universal_html" confusion by the analyzer. + final window = this as universal_html_in_browser_or_vm.Window; + final document = + internalWindowController.windowBehavior.newDocument(window: window); + return document as Document; + }(); + + /// The current location of this window. + /// + /// Location currentLocation = window.location; + /// print(currentLocation.href); // 'http://www.example.com:80/' + @override + late Location location = Location.internal(href: _initialHref); + @protected Selection? internalSelection; @@ -363,32 +393,23 @@ class Window extends EventTarget return completer.future; } - _Worklet get animationWorklet => throw UnimplementedError(); - - _Worklet get audioWorklet => throw UnimplementedError(); + _Worklet? get animationWorklet => null; - CacheStorage get caches => CacheStorage._(); + _Worklet? get audioWorklet => null; @override - bool get closed => _closed; - - CookieStore get cookieStore => CookieStore._(); + bool? get closed => null; /// Entrypoint for the browser's cryptographic functions. /// /// ## Other resources /// /// * [Web cryptography API](http://www.w3.org/TR/WebCryptoAPI/) from W3C. + Crypto? get crypto => null; CustomElementRegistry? get customElements => null; - /// *Deprecated*. - String? get defaultStatus => throw UnimplementedError(); - - /// *Deprecated*. - String? get defaultstatus => throw UnimplementedError(); - /// The ratio between physical pixels and logical CSS pixels. /// /// ## Other resources @@ -397,6 +418,7 @@ class Window extends EventTarget /// from quirksmode. /// * [More about devicePixelRatio](http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html) /// from quirksmode. + num get devicePixelRatio => 1; /// Gets an instance of the Indexed DB factory to being using Indexed DB. @@ -411,7 +433,8 @@ class Window extends EventTarget /// /// * [Window.innerHeight](https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight) /// from MDN. - int get innerHeight => outerHeight; + + int? get innerHeight => null; /// The width of the viewport including scrollbars. /// @@ -419,9 +442,10 @@ class Window extends EventTarget /// /// * [Window.innerWidth](https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth) /// from MDN. - int get innerWidth => outerWidth; - bool get isSecureContext => throw UnimplementedError(); + int? get innerWidth => null; + + bool? get isSecureContext => false; /// This window's location bar, which displays the URL. /// @@ -430,7 +454,8 @@ class Window extends EventTarget /// * [Browser interface /// elements](https://html.spec.whatwg.org/multipage/browsers.html#browser-interface-elements) /// from WHATWG. - _BarProp get locationbar => throw UnimplementedError(); + + BarProp? get locationbar => null; /// This window's menu bar, which displays menu commands. /// @@ -439,7 +464,8 @@ class Window extends EventTarget /// * [Browser interface /// elements](https://html.spec.whatwg.org/multipage/browsers.html#browser-interface-elements) /// from WHATWG. - _BarProp get menubar => throw UnimplementedError(); + + BarProp? get menubar => null; /// Whether objects are drawn offscreen before being displayed. /// @@ -447,7 +473,8 @@ class Window extends EventTarget /// /// * [offscreenBuffering](https://webplatform.github.io/docs/dom/HTMLElement/offscreenBuffering/) /// from WebPlatform.org. - bool get offscreenBuffering => false; + + bool? get offscreenBuffering => false; /// Stream of `abort` events handled by this [Window]. Stream get onAbort => Element.abortEvent.forTarget(this); @@ -541,6 +568,8 @@ class Window extends EventTarget /// Stream of `input` events handled by this [Window]. Stream get onInput => Element.inputEvent.forTarget(this); + // From WindowBase64 + /// Stream of `invalid` events handled by this [Window]. Stream get onInvalid => Element.invalidEvent.forTarget(this); @@ -578,8 +607,6 @@ class Window extends EventTarget Stream get onMouseLeave => Element.mouseLeaveEvent.forTarget(this); - // From WindowBase64 - /// Stream of `mousemove` events handled by this [Window]. Stream get onMouseMove => Element.mouseMoveEvent.forTarget(this); @@ -685,21 +712,16 @@ class Window extends EventTarget /// Stream of `wheel` events handled by this [Window]. Stream get onWheel => Element.wheelEvent.forTarget(this); - @override - WindowBase? get opener => null; - - set opener(WindowBase? value) { - throw UnimplementedError(); - } - int? get orientation => 0; - String? get origin => location.origin; + String? get origin => null; int get pageXOffset => 0; int get pageYOffset => 0; + // From WindowBase64 + @override WindowBase? get parent => null; @@ -709,7 +731,7 @@ class Window extends EventTarget /// /// * [The Screen interface specification](http://www.w3.org/TR/cssom-view/#screen) /// from W3C. - Screen get screen => Screen._(); + late final Screen? screen = Screen._(); /// The distance from the left side of the screen to the left side of this /// window. @@ -718,7 +740,8 @@ class Window extends EventTarget /// /// * [The Screen interface specification](http://www.w3.org/TR/cssom-view/#screen) /// from W3C. - int get screenLeft => 0; + + int? get screenLeft => null; /// The distance from the top of the screen to the top of this window. /// @@ -726,7 +749,8 @@ class Window extends EventTarget /// /// * [The Screen interface specification](http://www.w3.org/TR/cssom-view/#screen) /// from W3C. - int get screenTop => 0; + + int? get screenTop => null; /// The distance from the left side of the screen to the mouse pointer. /// @@ -734,7 +758,8 @@ class Window extends EventTarget /// /// * [The Screen interface specification](http://www.w3.org/TR/cssom-view/#screen) /// from W3C. - int get screenX => screenLeft; + + int? get screenX => null; /// The distance from the top of the screen to the mouse pointer. /// @@ -742,7 +767,8 @@ class Window extends EventTarget /// /// * [The Screen interface specification](http://www.w3.org/TR/cssom-view/#screen) /// from W3C. - int get screenY => screenTop; + + int? get screenY => null; /// This window's scroll bars. /// @@ -751,7 +777,7 @@ class Window extends EventTarget /// * [Browser interface /// elements](https://html.spec.whatwg.org/multipage/browsers.html#browser-interface-elements) /// from WHATWG. - _BarProp get scrollbars => throw UnimplementedError(); + BarProp? get scrollbars => null; /// The distance this window has been scrolled horizontally. /// @@ -779,7 +805,9 @@ class Window extends EventTarget /// /// * [Window.self](https://developer.mozilla.org/en-US/docs/Web/API/Window.self) /// from MDN. - WindowBase get self => this; + WindowBase? get self { + throw UnimplementedError(); + } /// Access to speech synthesis in the browser. /// @@ -788,7 +816,8 @@ class Window extends EventTarget /// * [Web speech /// specification](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#tts-section) /// from W3C. - SpeechSynthesis get speechSynthesis => throw UnimplementedError(); + + SpeechSynthesis? get speechSynthesis => null; /// This window's status bar. /// @@ -797,7 +826,8 @@ class Window extends EventTarget /// * [Browser interface /// elements](https://html.spec.whatwg.org/multipage/browsers.html#browser-interface-elements) /// from WHATWG. - _BarProp get statusbar => throw UnimplementedError(); + + BarProp? get statusbar => null; /// Access to CSS media queries. /// @@ -806,7 +836,8 @@ class Window extends EventTarget /// * [StyleMedia class /// reference](https://developer.apple.com/library/safari/documentation/SafariDOMAdditions/Reference/StyleMedia/) /// from Safari Developer Library. - StyleMedia get styleMedia => throw UnimplementedError(); + + StyleMedia? get styleMedia => null; /// This window's tool bar. /// @@ -815,12 +846,13 @@ class Window extends EventTarget /// * [Browser interface /// elements](https://html.spec.whatwg.org/multipage/browsers.html#browser-interface-elements) /// from WHATWG. - _BarProp get toolbar => throw UnimplementedError(); + + BarProp? get toolbar => null; @override WindowBase? get top => null; - VisualViewport get visualViewport => throw UnimplementedError(); + VisualViewport? get visualViewport => null; /// The current window. /// @@ -828,7 +860,7 @@ class Window extends EventTarget /// /// * [Window.window](https://developer.mozilla.org/en-US/docs/Web/API/Window.window) /// from MDN. - WindowBase get window => this; + WindowBase? get window => null; /// Displays a modal alert to the user. /// @@ -836,21 +868,21 @@ class Window extends EventTarget /// /// * [User prompts](https://html.spec.whatwg.org/multipage/webappapis.html#user-prompts) /// from WHATWG. - void alert([String? message]) {} - - String atob(String atob) { + void alert([String? message]) { throw UnimplementedError(); } - String btoa(String btoa) { + String atob(String atob) => throw UnimplementedError(); + + String btoa(String btoa) => throw UnimplementedError(); + + void cancelIdleCallback(int handle) { throw UnimplementedError(); } - void cancelIdleCallback(int handle) {} - @override void close() { - _closed = true; + throw UnimplementedError(); } /// Displays a modal OK/Cancel prompt to the user. @@ -873,17 +905,20 @@ class Window extends EventTarget /// /// * [Window.find](https://developer.mozilla.org/en-US/docs/Web/API/Window.find) /// from MDN. - bool find(String string, bool caseSensitive, bool backwards, bool wrap, - bool wholeWord, bool searchInFrames, bool showDialog) { - return false; + bool find(String? string, bool? caseSensitive, bool? backwards, bool? wrap, + bool? wholeWord, bool? searchInFrames, bool? showDialog) { + throw UnimplementedError(); } StylePropertyMapReadonly getComputedStyleMap( - Element element, String pseudoElement) { + Element element, String? pseudoElement) { throw UnimplementedError(); } - List getMatchedCssRules(Element element, String pseudoElement) { + @JSName('getMatchedCSSRules') + + /// Returns all CSS rules that apply to the element's pseudo-element. + List getMatchedCssRules(Element? element, String? pseudoElement) { throw UnimplementedError(); } @@ -942,7 +977,7 @@ class Window extends EventTarget } @override - void postMessage(dynamic message, String targetOrigin, + void postMessage(/*any*/ message, String targetOrigin, [List? transfer]) { throw UnimplementedError(); } @@ -1009,6 +1044,8 @@ class Window extends EventTarget /// from MDN. void resizeTo(int x, int y) {} + @JSName('webkitResolveLocalFileSystemURL') + /// Asynchronously retrieves a local filesystem entry. /// /// ## Other resources @@ -1016,6 +1053,7 @@ class Window extends EventTarget /// * [Obtaining access to file system entry /// points](http://www.w3.org/TR/file-system-api/#obtaining-access-to-file-system-entry-points) /// from W3C. + @SupportedBrowser(SupportedBrowser.CHROME) Future resolveLocalFileSystemUrl(String url) { throw UnimplementedError(); } @@ -1059,28 +1097,112 @@ class Window extends EventTarget } mixin WindowBase implements EventTarget { - bool get closed; + // Fields. - /// The current session history for this window's newest document. + /// Indicates whether this window has been closed. + /// + /// print(window.closed); // 'false' + /// window.close(); + /// print(window.closed); // 'true' + /// + /// MDN does not have compatibility info on this attribute, and therefore is + /// marked nullable. + bool? get closed; + + /// The current session history for this window. /// /// ## Other resources /// - /// * [Loading web pages](https://html.spec.whatwg.org/multipage/browsers.html) + /// * [Session history and navigation + /// specification](https://html.spec.whatwg.org/multipage/browsers.html#history) /// from WHATWG. - History get history; + HistoryBase get history; - Location get location; + /// The current location of this window. + /// + /// Location currentLocation = window.location; + /// print(currentLocation.href); // 'http://www.example.com:80/' + LocationBase get location; - WindowBase? get opener => null; + /// A reference to the window that opened this one. + /// + /// Window thisWindow = window; + /// WindowBase otherWindow = thisWindow.open('http://www.example.com/', 'foo'); + /// print(otherWindow.opener == thisWindow); // 'true' + WindowBase? get opener; - WindowBase? get parent => null; + /// A reference to the parent of this window. + /// + /// If this [WindowBase] has no parent, [parent] will return a reference to + /// the [WindowBase] itself. + /// + /// IFrameElement myIFrame = new IFrameElement(); + /// window.document.body.elements.add(myIFrame); + /// print(myIframe.contentWindow.parent == window) // 'true' + /// + /// print(window.parent == window) // 'true' + WindowBase? get parent; - WindowBase? get top => null; + /// A reference to the topmost window in the window hierarchy. + /// + /// If this [WindowBase] is the topmost [WindowBase], [top] will return a + /// reference to the [WindowBase] itself. + /// + /// // Add an IFrame to the current window. + /// IFrameElement myIFrame = new IFrameElement(); + /// window.document.body.elements.add(myIFrame); + /// + /// // Add an IFrame inside of the other IFrame. + /// IFrameElement innerIFrame = new IFrameElement(); + /// myIFrame.elements.add(innerIFrame); + /// + /// print(myIframe.contentWindow.top == window) // 'true' + /// print(innerIFrame.contentWindow.top == window) // 'true' + /// + /// print(window.top == window) // 'true' + WindowBase? get top; + // Methods. + /// Closes the window. + /// + /// This method should only succeed if the [WindowBase] object is + /// **script-closeable** and the window calling [close] is allowed to navigate + /// the window. + /// + /// A window is script-closeable if it is either a window + /// that was opened by another window, or if it is a window with only one + /// document in its history. + /// + /// A window might not be allowed to navigate, and therefore close, another + /// window due to browser security features. + /// + /// var other = window.open('http://www.example.com', 'foo'); + /// // Closes other window, as it is script-closeable. + /// other.close(); + /// print(other.closed); // 'true' + /// + /// var newLocation = window.location + /// ..href = 'http://www.mysite.com'; + /// window.location = newLocation; + /// // Does not close this window, as the history has changed. + /// window.close(); + /// print(window.closed); // 'false' + /// + /// See also: + /// + /// * [Window close discussion](http://www.w3.org/TR/html5/browsers.html#dom-window-close) from the W3C void close(); - void postMessage(dynamic message, String targetOrigin, - [List transfer]); + /// Sends a cross-origin message. + /// + /// ## Other resources + /// + /// * [window.postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage) + /// from MDN. + /// * [Cross-document messaging](https://html.spec.whatwg.org/multipage/comms.html#web-messaging) + /// from WHATWG. + void postMessage(var message, String targetOrigin, + [List? messagePorts]); } abstract class WindowEventHandlers extends EventTarget { diff --git a/lib/src/html/api/window_misc.dart b/lib/src/html/api/window_misc.dart index ef63651..382476e 100644 --- a/lib/src/html/api/window_misc.dart +++ b/lib/src/html/api/window_misc.dart @@ -49,6 +49,10 @@ typedef FrameRequestCallback = void Function(num highResTime); typedef IdleRequestCallback = void Function(IdleDeadline deadline); +class BarProp { + BarProp._(); +} + class CacheStorage { factory CacheStorage._() { throw UnimplementedError(); @@ -324,8 +328,4 @@ abstract class VisualViewport implements EventTarget { num get width; } -class _BarProp { - _BarProp._(); -} - abstract class _Worklet {} diff --git a/lib/src/html/api/service_worker.dart b/lib/src/html/api/workers.dart similarity index 57% rename from lib/src/html/api/service_worker.dart rename to lib/src/html/api/workers.dart index 2d62f80..2279195 100644 --- a/lib/src/html/api/service_worker.dart +++ b/lib/src/html/api/workers.dart @@ -58,6 +58,15 @@ abstract class AbstractWorker implements EventTarget { Stream get onError => errorEvent.forTarget(this); } +@Native('BackgroundFetchFetch') +class BackgroundFetchFetch { + factory BackgroundFetchFetch._() { + throw UnimplementedError(); + } + + _Request? get request => null; +} + class BackgroundFetchManager { factory BackgroundFetchManager._() { throw UnimplementedError(); @@ -74,44 +83,53 @@ class BackgroundFetchManager { Future> getIds() => throw UnimplementedError(); } -abstract class BackgroundFetchRegistration extends EventTarget { +@Native('BackgroundFetchRegistration') +class BackgroundFetchRegistration extends EventTarget { factory BackgroundFetchRegistration._() { throw UnimplementedError(); } - int get downloaded; + int? get downloaded => throw UnimplementedError(); - int get downloadTotal; + int? get downloadTotal => throw UnimplementedError(); - String get id; + String? get id => throw UnimplementedError(); - String get title; + String? get title => throw UnimplementedError(); - int get totalDownloadSize; + int? get totalDownloadSize => throw UnimplementedError(); - int get uploaded; + int? get uploaded => throw UnimplementedError(); - int get uploadTotal; + int? get uploadTotal => throw UnimplementedError(); Future abort() => throw UnimplementedError(); } +class BackgroundFetchSettledFetch extends BackgroundFetchFetch { + factory BackgroundFetchSettledFetch(_Request request, _Response response) { + throw UnimplementedError(); + } + + _Response? get response => null; +} + abstract class Body { factory Body._() { throw UnimplementedError(); } - bool? get bodyUsed; + bool? get bodyUsed => throw UnimplementedError(); - Future arrayBuffer(); + Future arrayBuffer() => throw UnimplementedError(); - Future blob(); + Future blob() => throw UnimplementedError(); - Future formData(); + Future formData() => throw UnimplementedError(); - Future json(); + Future json() => throw UnimplementedError(); - Future text(); + Future text() => throw UnimplementedError(); } abstract class Client { @@ -283,35 +301,46 @@ abstract class PushSubscriptionOptions { bool get userVisibleOnly; } -abstract class ServiceWorker extends EventTarget implements AbstractWorker { +@Native('ServiceWorker') +class ServiceWorker extends EventTarget implements AbstractWorker { + // To suppress missing implicit constructor warnings. static const EventStreamProvider errorEvent = EventStreamProvider('error'); factory ServiceWorker._() { - throw UnsupportedError('Not supported'); + throw UnimplementedError(); } @override Stream get onError => errorEvent.forTarget(this); - String get scriptUrl; + @JSName('scriptURL') + String? get scriptUrl { + throw UnimplementedError(); + } - String get state; + String? get state { + throw UnimplementedError(); + } void postMessage(/*any*/ message, [List? transfer]) { throw UnimplementedError(); } } -abstract class ServiceWorkerContainer extends EventTarget { +@Native('ServiceWorkerContainer') +class ServiceWorkerContainer extends EventTarget { + // To suppress missing implicit constructor warnings. static const EventStreamProvider messageEvent = EventStreamProvider('message'); factory ServiceWorkerContainer._() { - throw UnsupportedError('Not supported'); + throw UnimplementedError(); } - ServiceWorker get controller; + ServiceWorker? get controller { + throw UnimplementedError(); + } Stream get onMessage => messageEvent.forTarget(this); @@ -323,7 +352,7 @@ abstract class ServiceWorkerContainer extends EventTarget { throw UnimplementedError(); } - Future> getRegistrations() { + Future> getRegistrations() { throw UnimplementedError(); } @@ -332,7 +361,9 @@ abstract class ServiceWorkerContainer extends EventTarget { } } -abstract class ServiceWorkerGlobalScope extends WorkerGlobalScope { +@Native('ServiceWorkerGlobalScope') +class ServiceWorkerGlobalScope extends WorkerGlobalScope { + // To suppress missing implicit constructor warnings. static const EventStreamProvider activateEvent = EventStreamProvider('activate'); @@ -356,15 +387,9 @@ abstract class ServiceWorkerGlobalScope extends WorkerGlobalScope { throw UnimplementedError(); } - ApplicationCache get caches => throw UnimplementedError(); - - Clients get clients; - - Crypto get crypto => throw UnimplementedError(); - - Location get location => throw UnimplementedError(); - - Navigator get navigator => throw UnimplementedError(); + Clients? get clients { + throw UnimplementedError(); + } Stream get onActivate => activateEvent.forTarget(this); @@ -377,39 +402,59 @@ abstract class ServiceWorkerGlobalScope extends WorkerGlobalScope { Stream get onMessage => messageEvent.forTarget(this); - Performance get performance => throw UnimplementedError(); - - ServiceWorkerRegistration get registration; + ServiceWorkerRegistration? get registration { + throw UnimplementedError(); + } Future skipWaiting() { throw UnimplementedError(); } } -abstract class ServiceWorkerRegistration extends EventTarget { +@Native('ServiceWorkerRegistration') +class ServiceWorkerRegistration extends EventTarget { + // To suppress missing implicit constructor warnings. factory ServiceWorkerRegistration._() { - throw UnsupportedError('Not supported'); + throw UnimplementedError(); } - ServiceWorker get active; + ServiceWorker? get active { + throw UnimplementedError(); + } - BackgroundFetchManager get backgroundFetch; + BackgroundFetchManager? get backgroundFetch { + throw UnimplementedError(); + } - ServiceWorker get installing; + ServiceWorker? get installing { + throw UnimplementedError(); + } - NavigationPreloadManager get navigationPreload; + NavigationPreloadManager? get navigationPreload { + throw UnimplementedError(); + } - PaymentManager get paymentManager; + PaymentManager? get paymentManager { + throw UnimplementedError(); + } - PushManager get pushManager; + PushManager? get pushManager { + throw UnimplementedError(); + } - String get scope; + String? get scope { + throw UnimplementedError(); + } - SyncManager get sync; + SyncManager? get sync { + throw UnimplementedError(); + } - ServiceWorker get waiting; + ServiceWorker? get waiting { + throw UnimplementedError(); + } - Future> getNotifications([Map? filter]) { + Future> getNotifications([Map? filter]) { throw UnimplementedError(); } @@ -454,44 +499,90 @@ abstract class WindowClient extends Client { } } -abstract class WorkerGlobalScope extends EventTarget { +@SupportedBrowser(SupportedBrowser.CHROME) +@SupportedBrowser(SupportedBrowser.FIREFOX) +@SupportedBrowser(SupportedBrowser.IE, '10') +@SupportedBrowser(SupportedBrowser.SAFARI) +@Native('Worker') +class Worker extends EventTarget implements AbstractWorker { + // To suppress missing implicit constructor warnings. /// Static factory designed to expose `error` events to event - /// handlers that are not necessarily instances of [WorkerGlobalScope]. + /// handlers that are not necessarily instances of [Worker]. /// /// See [EventStreamProvider] for usage information. static const EventStreamProvider errorEvent = EventStreamProvider('error'); - static WorkerGlobalScope get instance { + /// Static factory designed to expose `message` events to event + /// handlers that are not necessarily instances of [Worker]. + /// + /// See [EventStreamProvider] for usage information. + static const EventStreamProvider messageEvent = + EventStreamProvider('message'); + + /// Checks if this type is supported on the current platform. + static bool get supported => false; + + factory Worker(String scriptUrl) { + throw UnimplementedError(); + } + + /// Stream of `error` events handled by this [Worker]. + @override + Stream get onError => errorEvent.forTarget(this); + + /// Stream of `message` events handled by this [Worker]. + Stream get onMessage => messageEvent.forTarget(this); + + void postMessage(/*any*/ message, [List? transfer]) { throw UnimplementedError(); } - factory WorkerGlobalScope._() { - throw UnsupportedError('Not supported'); + void terminate() { + throw UnimplementedError(); + } +} + +@Native('WorkerGlobalScope') +class WorkerGlobalScope extends EventTarget { + // To suppress missing implicit constructor warnings. + /// Static factory designed to expose `error` events to event + /// handlers that are not necessarily instances of [WorkerGlobalScope]. + /// + /// See [EventStreamProvider] for usage information. + static const EventStreamProvider errorEvent = + EventStreamProvider('error'); + + static WorkerGlobalScope get instance { + throw UnimplementedError(); } - // final CacheStorage caches; + WorkerGlobalScope._() : super.internal(); - // final Crypto crypto; + String? get addressSpace => throw UnimplementedError(); - String get addressSpace; + CacheStorage? get caches => throw UnimplementedError(); - IdbFactory get indexedDB; + Crypto? get crypto => throw UnimplementedError(); - // final _WorkerLocation location; + IdbFactory? get indexedDB => throw UnimplementedError(); - // final _WorkerNavigator navigator; + bool? get isSecureContext => throw UnimplementedError(); - bool get isSecureContext; + Location get location => throw UnimplementedError(); - // final WorkerPerformance performance; + _WorkerNavigator get navigator => throw UnimplementedError(); /// Stream of `error` events handled by this [WorkerGlobalScope]. Stream get onError => errorEvent.forTarget(this); - String get origin; + String? get origin => throw UnimplementedError(); + + WorkerPerformance? get performance => throw UnimplementedError(); - WorkerGlobalScope? get self; + WorkerGlobalScope get self => throw UnimplementedError(); + + // From WindowBase64 String atob(String atob) { throw UnimplementedError(); @@ -509,3 +600,133 @@ abstract class WorkerGlobalScope extends EventTarget { throw UnimplementedError(); } } + +@Native('WorkerPerformance') +class WorkerPerformance extends EventTarget { + // To suppress missing implicit constructor warnings. + factory WorkerPerformance._() { + throw UnimplementedError(); + } + + MemoryInfo? get memory { + throw UnimplementedError(); + } + + num? get timeOrigin { + throw UnimplementedError(); + } + + void clearMarks(String? markName) { + throw UnimplementedError(); + } + + void clearMeasures(String? measureName) { + throw UnimplementedError(); + } + + void clearResourceTimings() { + throw UnimplementedError(); + } + + List getEntries() { + throw UnimplementedError(); + } + + List getEntriesByName(String name, String? entryType) { + throw UnimplementedError(); + } + + List getEntriesByType(String entryType) { + throw UnimplementedError(); + } + + void mark(String markName) { + throw UnimplementedError(); + } + + void measure(String measureName, String? startMark, String? endMark) { + throw UnimplementedError(); + } + + double now() { + throw UnimplementedError(); + } + + void setResourceTimingBufferSize(int maxSize) { + throw UnimplementedError(); + } +} + +@Native('WorkletAnimation') +class WorkletAnimation { + factory WorkletAnimation( + String animatorName, + List effects, + List timelines, + /*SerializedScriptValue*/ options) { + throw UnimplementedError(); + } + + String? get playState { + throw UnimplementedError(); + } + + void cancel() { + throw UnimplementedError(); + } + + void play() { + throw UnimplementedError(); + } +} + +@Native('WorkletGlobalScope') +class WorkletGlobalScope { + // To suppress missing implicit constructor warnings. + factory WorkletGlobalScope._() { + throw UnimplementedError(); + } +} + +@Native('Request') +class _Request extends Body { + factory _Request() { + throw UnimplementedError(); + } + + String? get cache => null; + + String? get credentials => null; + + Headers? get headers => null; + + String? get integrity => null; + + String? get mode => null; + + String? get redirect => null; + + String? get referrer => null; + + String? get referrerPolicy => null; + + String? get url => null; + + _Request clone() => throw UnimplementedError(); +} + +@Native('Response') +abstract class _Response extends Body { + factory _Response() { + throw UnimplementedError(); + } +} + +@Native('WorkerNavigator') +abstract class _WorkerNavigator extends NavigatorConcurrentHardware + implements NavigatorOnLine, NavigatorID { + // To suppress missing implicit constructor warnings. + factory _WorkerNavigator._() { + throw UnimplementedError(); + } +} diff --git a/lib/src/html/dom/css.dart b/lib/src/html/dom/css.dart index eeed49f..485f016 100644 --- a/lib/src/html/dom/css.dart +++ b/lib/src/html/dom/css.dart @@ -178,6 +178,7 @@ class Dimension { /// size). This is useful for producing website layouts that scale nicely with /// the user's desired font size. Dimension.em(this.value) : _unit = 'em'; + /// Set this CSS Dimension to the specified number of x-heights. /// /// One ex is equal to the x-height of a font's baseline to its mean line, diff --git a/lib/src/web_audio.dart b/lib/src/web_audio.dart new file mode 100644 index 0000000..3011aa0 --- /dev/null +++ b/lib/src/web_audio.dart @@ -0,0 +1,82 @@ +// Copyright 2019 terrier989@gmail.com +// +// 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. +/* +This file was derived from the Dart SDK. + +The original files in the Dart SDK had the following license: + + Copyright 2012, the Dart project authors. All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +library universal_html.web_audio.internal; + +import 'html.dart'; + +class AudioTrack { + factory AudioTrack._() { + throw UnimplementedError(); + } + + bool? get enabled { + throw UnimplementedError(); + } + + set enabled(bool? value) { + throw UnimplementedError(); + } + + String? get id { + throw UnimplementedError(); + } + + String? get kind { + throw UnimplementedError(); + } + + String? get label { + throw UnimplementedError(); + } + + String? get language { + throw UnimplementedError(); + } + + SourceBuffer? get sourceBuffer { + throw UnimplementedError(); + } +} diff --git a/lib/web_audio.dart b/lib/web_audio.dart new file mode 100644 index 0000000..b879b52 --- /dev/null +++ b/lib/web_audio.dart @@ -0,0 +1,20 @@ +// Copyright 2019 terrier989@gmail.com +// +// 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. + +library universal_html.web_audio; + +export 'dart:web_audio' + if (dart.library.web_audio) 'dart:web_audio' // Browser + if (dart.library.io) 'src/web_audio.dart' // VM + if (dart.library.js) 'src/web_audio.dart'; // Node.JS diff --git a/pubspec.yaml b/pubspec.yaml index db71573..94e2940 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: universal_html -version: 2.0.7 +version: 2.0.8 description: A 'dart:html' that works in all platforms, including Flutter and server-side. Eases cross-platform development and HTML / XML processing. diff --git a/test/main_test.dart b/test/main_test.dart index 0d4a78d..3b2a210 100644 --- a/test/main_test.dart +++ b/test/main_test.dart @@ -30,14 +30,15 @@ import 'src/libraries.dart'; part 'src/controller/content_type_sniffer.dart'; part 'src/controller/window_controller.dart'; +part 'src/controller/window_controller_networking.dart'; part 'src/html/api/blob.dart'; part 'src/html/api/event_target.dart'; part 'src/html/api/file.dart'; part 'src/html/api/history.dart'; part 'src/html/api/navigator.dart'; -part 'src/controller/window_controller_networking.dart'; part 'src/html/api/networking_event_source.dart'; part 'src/html/api/networking_http_request.dart'; +part 'src/html/api/workers.dart'; part 'src/html/api/window.dart'; part 'src/html/dom/cloning.dart'; part 'src/html/dom/css_queries.dart'; @@ -68,10 +69,17 @@ void main() { }, testOn: 'node'); } +const _httpServerWrongPort = 314; + +late int _httpServerPort; + var _isBrowser = false; +// Local TCP port that has a HTTP server. var _isVM = false; +// Local TCP port hat DOES NOT have HTTP server. +// Used for testing connection failures. void _sharedTests() { // DOM _testCloning(); @@ -93,6 +101,7 @@ void _sharedTests() { _testHistory(); _testNavigator(); _testNetworking(); + _testServiceWorker(); _testWindow(); // @@ -107,16 +116,9 @@ void _sharedTests() { testLibraries(); } -// Local TCP port that has a HTTP server. -const _httpServerWrongPort = 314; - -// Local TCP port hat DOES NOT have HTTP server. -// Used for testing connection failures. -late int _httpServerPort; - void _testNetworking() { group( - 'Networking-requiring tests:', + 'Tests that require HTTP server:', () { setUpAll(() async { // Do not run in Flutter or Node.JS diff --git a/test/src/html/api/window.dart b/test/src/html/api/window.dart index 5c05bdb..3cb887e 100644 --- a/test/src/html/api/window.dart +++ b/test/src/html/api/window.dart @@ -17,7 +17,9 @@ part of main_test; void _testWindow() { group('Window', () { test('console', () { - expect(window.console, isNotNull); + final console = window.console; + expect(console, isNotNull); + console.info('Hello'); }); test('localStorage / sessionStorage', () { @@ -46,5 +48,20 @@ void _testWindow() { expect(storage.length, 0); } }); + + test('screen', () { + final screen = window.screen!; + expect(screen, isNotNull); + expect(screen.height, greaterThan(0)); + expect(screen.width, greaterThan(0)); + }); + + test('scrollX', () { + expect(window.scrollX, greaterThanOrEqualTo(0)); + }); + + test('scrollY', () { + expect(window.scrollY, greaterThanOrEqualTo(0)); + }); }); } diff --git a/test/src/html/api/workers.dart b/test/src/html/api/workers.dart new file mode 100644 index 0000000..f5cfc51 --- /dev/null +++ b/test/src/html/api/workers.dart @@ -0,0 +1,33 @@ +// Copyright 2019 terrier989@gmail.com +// +// 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. + +part of main_test; + +void _testServiceWorker() { + group('Worker:', () { + test('Worker()', () { + final worker = Worker('example'); + worker.postMessage('message'); + }, testOn: 'browser && !browser'); // We don't want to execute this test + }); + + group('ServiceWorker', () { + test('ServiceWorker()', () async { + final registration = + await window.navigator.serviceWorker!.register('example'); + final worker = registration.active!; + worker.postMessage('message'); + }, testOn: 'browser && !browser'); // We don't want to execute this test + }); +} diff --git a/test_in_flutter/test/server.dart b/test_in_flutter/test/server.dart index c6bab39..34e14df 100644 --- a/test_in_flutter/test/server.dart +++ b/test_in_flutter/test/server.dart @@ -17,4 +17,4 @@ import '../../test/server.dart' as impl; void hybridMain(StreamChannel streamChannel, Object message) async { impl.hybridMain(streamChannel, message); -} \ No newline at end of file +}