Skip to content

Commit

Permalink
Only emit APIs that are standards track and not experimental (#239)
Browse files Browse the repository at this point in the history
* Only emit APIs that are standards track and not experimental

The current implementation only emits APIs that are on the
standards track and supported in Chrome, Firefox, and Safari.
This leaves out widely used APIs like Trusted Types, so this
change relaxes those requirements. In order to support this
change, a number of changes are included:

- BrowserCompatData is modified to handle some slight
discrepancies in how compatibility data is stored, including
global APIs, namespaces, static members, and event handlers.
- Interfaces and namespaces are generated based on whether they
are standards track and experimental. If they are not generated,
any references to them will be replaced by the equivalent JS
type.
- Likewise, inheritance for interfaces is modified to subtype
the first generated interface in the inheritance hierarchy.
- Dictionaries and typedef-like types are generated based on
whether they are used as they don't have compatibility data. In
order to determine this, whenever we generate a _RawType, we
mark it as used, and recursively generate the types needed.
- For each API within an interface, compat data in that interface
and its superinterfaces are used to determine if an API is
generated.
- In order to support the above changes, intermediate
representations for some members (attributes, fields, constants)
are added. There are other members that might be worth moving to
an IR, but that refactoring can be done in a future CL.

Closes a number of issues:

#209
#234
#216
#205
#203
#192

* Generate APIs based on standards track and not experimental

* Handle some TODOs that came up when addressing #209

- Removes an unnecessary null-check
- Refactors getTypeForUnionCalculation to a shared
_getJSTypeEquivalent function
- Avoids shadowing an instance variable

* Address some lints

* Update CHANGELOG and README

* Add types to the field declaration
  • Loading branch information
srujzs authored May 21, 2024
1 parent d776645 commit 7604578
Show file tree
Hide file tree
Showing 106 changed files with 7,133 additions and 4,871 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- Update the docs for generated interface types to reference the MDN Web Docs
project.
- Address several broken links in API documentation.
- Generate APIs based on if they're on track to be a standard and not
experimental. This is a looser restriction from the previous requirement that
APIs need to be implemented by Chrome, Firefox, and Safari. As part of this,
dictionaries and typedefs are only emitted if they're used by a generated API.

## 0.5.1

Expand Down Expand Up @@ -42,7 +46,7 @@
- Deprecate a few type aliases in favor of their standardized versions:

| Deprecated | Preferred |
|-----------------------|-------------------------|
| --------------------- | ----------------------- |
| `AudioElement` | `HTMLAudioElement` |
| `HtmlElement` | `HTMLElement` |
| `CanvasElement` | `HTMLCanvasElement` |
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ definitions:
bound of `JSAny?`.
- Union types are computed by picking the least upper bound of the types in the
JS type hierarchy, where every interface is equivalent to `JSObject`.
- Dictionary and typedef types are only emitted if they're used by another API.

### Compatibility

- The generator uses the
[MDN compatibility data](https://github.com/mdn/browser-compat-data) to
determine what members and interfaces to emit. Currently, we only emit code
that is standards track and supported on Chrome, Firefox, and Safari to reduce
the number of breaking changes. This is currently WIP and some members may be
added or removed.
determine what members, interfaces, and namespaces to emit. Currently, we only
emit code that is standards track and is not experimental to reduce the number
of breaking changes.

## Generation and updating the package

Expand Down
52 changes: 50 additions & 2 deletions lib/src/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'dom/accelerometer.dart';
export 'dom/angle_instanced_arrays.dart';
export 'dom/attribution_reporting_api.dart';
export 'dom/battery_status.dart';
export 'dom/clipboard_apis.dart';
export 'dom/compression.dart';
export 'dom/console.dart';
export 'dom/cookie_store.dart';
export 'dom/credential_management.dart';
export 'dom/csp.dart';
export 'dom/css_animations.dart';
Expand All @@ -18,46 +22,60 @@ export 'dom/css_font_loading.dart';
export 'dom/css_fonts.dart';
export 'dom/css_highlight_api.dart';
export 'dom/css_masking.dart';
export 'dom/css_paint_api.dart';
export 'dom/css_properties_values_api.dart';
export 'dom/css_transitions.dart';
export 'dom/css_transitions_2.dart';
export 'dom/css_typed_om.dart';
export 'dom/css_view_transitions.dart';
export 'dom/cssom.dart';
export 'dom/cssom_view.dart';
export 'dom/dom.dart';
export 'dom/dom_parsing.dart';
export 'dom/encoding.dart';
export 'dom/encrypted_media.dart';
export 'dom/entries_api.dart';
export 'dom/event_timing.dart';
export 'dom/ext_blend_minmax.dart';
export 'dom/ext_color_buffer_float.dart';
export 'dom/ext_color_buffer_half_float.dart';
export 'dom/ext_disjoint_timer_query.dart';
export 'dom/ext_disjoint_timer_query_webgl2.dart';
export 'dom/ext_float_blend.dart';
export 'dom/ext_frag_depth.dart';
export 'dom/ext_shader_texture_lod.dart';
export 'dom/ext_srgb.dart';
export 'dom/ext_texture_compression_bptc.dart';
export 'dom/ext_texture_compression_rgtc.dart';
export 'dom/ext_texture_filter_anisotropic.dart';
export 'dom/ext_texture_norm16.dart';
export 'dom/fedcm.dart';
export 'dom/fetch.dart';
export 'dom/fido.dart';
export 'dom/fileapi.dart';
export 'dom/filter_effects.dart';
export 'dom/fs.dart';
export 'dom/fullscreen.dart';
export 'dom/gamepad.dart';
export 'dom/generic_sensor.dart';
export 'dom/geolocation.dart';
export 'dom/geometry.dart';
export 'dom/gyroscope.dart';
export 'dom/hr_time.dart';
export 'dom/html.dart';
export 'dom/image_capture.dart';
export 'dom/indexeddb.dart';
export 'dom/intersection_observer.dart';
export 'dom/khr_parallel_shader_compile.dart';
export 'dom/largest_contentful_paint.dart';
export 'dom/mathml_core.dart';
export 'dom/media_capabilities.dart';
export 'dom/media_playback_quality.dart';
export 'dom/media_source.dart';
export 'dom/mediacapture_fromelement.dart';
export 'dom/mediacapture_streams.dart';
export 'dom/mediasession.dart';
export 'dom/mediastream_recording.dart';
export 'dom/mst_content_hint.dart';
export 'dom/navigation_timing.dart';
export 'dom/notifications.dart';
export 'dom/oes_draw_buffers_indexed.dart';
Expand All @@ -70,18 +88,27 @@ export 'dom/oes_texture_half_float.dart';
export 'dom/oes_texture_half_float_linear.dart';
export 'dom/oes_vertex_array_object.dart';
export 'dom/orientation_event.dart';
export 'dom/orientation_sensor.dart';
export 'dom/ovr_multiview2.dart';
export 'dom/paint_timing.dart';
export 'dom/payment_request.dart';
export 'dom/performance_timeline.dart';
export 'dom/permissions.dart';
export 'dom/picture_in_picture.dart';
export 'dom/pointerevents.dart';
export 'dom/private_network_access.dart';
export 'dom/push_api.dart';
export 'dom/referrer_policy.dart';
export 'dom/remote_playback.dart';
export 'dom/reporting.dart';
export 'dom/requestidlecallback.dart';
export 'dom/resize_observer.dart';
export 'dom/resource_timing.dart';
export 'dom/scheduling_apis.dart';
export 'dom/screen_capture.dart';
export 'dom/screen_orientation.dart';
export 'dom/screen_wake_lock.dart';
export 'dom/secure_payment_confirmation.dart';
export 'dom/selection_api.dart';
export 'dom/server_timing.dart';
export 'dom/service_workers.dart';
Expand All @@ -91,32 +118,53 @@ export 'dom/streams.dart';
export 'dom/svg.dart';
export 'dom/svg_animations.dart';
export 'dom/touch_events.dart';
export 'dom/trust_token_api.dart';
export 'dom/trusted_types.dart';
export 'dom/uievents.dart';
export 'dom/url.dart';
export 'dom/user_timing.dart';
export 'dom/vibration.dart';
export 'dom/video_rvfc.dart';
export 'dom/wasm_js_api.dart';
export 'dom/web_animations.dart';
export 'dom/web_animations_2.dart';
export 'dom/web_bluetooth.dart';
export 'dom/web_locks.dart';
export 'dom/web_otp.dart';
export 'dom/web_share.dart';
export 'dom/webaudio.dart';
export 'dom/webauthn.dart';
export 'dom/webcodecs.dart';
export 'dom/webcodecs_av1_codec_registration.dart';
export 'dom/webcodecs_avc_codec_registration.dart';
export 'dom/webcodecs_hevc_codec_registration.dart';
export 'dom/webcodecs_vp9_codec_registration.dart';
export 'dom/webcryptoapi.dart';
export 'dom/webgl1.dart';
export 'dom/webgl2.dart';
export 'dom/webgl_color_buffer_float.dart';
export 'dom/webgl_compressed_texture_astc.dart';
export 'dom/webgl_compressed_texture_etc.dart';
export 'dom/webgl_compressed_texture_etc1.dart';
export 'dom/webgl_compressed_texture_pvrtc.dart';
export 'dom/webgl_compressed_texture_s3tc.dart';
export 'dom/webgl_compressed_texture_s3tc_srgb.dart';
export 'dom/webgl_debug_renderer_info.dart';
export 'dom/webgl_debug_shaders.dart';
export 'dom/webgl_depth_texture.dart';
export 'dom/webgl_draw_buffers.dart';
export 'dom/webgl_lose_context.dart';
export 'dom/webgl_multi_draw.dart';
export 'dom/webgpu.dart';
export 'dom/webidl.dart';
export 'dom/webmidi.dart';
export 'dom/webrtc.dart';
export 'dom/webrtc_encoded_transform.dart';
export 'dom/webrtc_stats.dart';
export 'dom/webrtc_identity.dart';
export 'dom/webrtc_priority.dart';
export 'dom/websockets.dart';
export 'dom/webtransport.dart';
export 'dom/webvtt.dart';
export 'dom/webxr.dart';
export 'dom/webxr_hand_input.dart';
export 'dom/xhr.dart';
70 changes: 70 additions & 0 deletions lib/src/dom/accelerometer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// API docs from [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web).
// Attributions and copyright licensing by Mozilla Contributors is licensed
// under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/.

// Generated from Web IDL definitions.

@JS()
library;

import 'dart:js_interop';

import 'generic_sensor.dart';

typedef AccelerometerLocalCoordinateSystem = String;
extension type AccelerometerSensorOptions._(JSObject _)
implements SensorOptions, JSObject {
external factory AccelerometerSensorOptions({
num frequency,
AccelerometerLocalCoordinateSystem referenceFrame,
});

external AccelerometerLocalCoordinateSystem get referenceFrame;
external set referenceFrame(AccelerometerLocalCoordinateSystem value);
}

/// The **`LinearAccelerationSensor`** interface of the
/// [Sensor APIs](https://developer.mozilla.org/en-US/docs/Web/API/Sensor_APIs)
/// provides on each reading the acceleration applied to the device along all
/// three axes, but without the contribution of gravity.
///
/// To use this sensor, the user must grant permission to the `'accelerometer'`
/// device sensor through the
/// [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API).
/// In addition, this feature may be blocked by a
/// [Permissions Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy)
/// set on your server.
///
/// ---
///
/// API documentation sourced from
/// [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/LinearAccelerationSensor).
extension type LinearAccelerationSensor._(JSObject _)
implements Sensor, JSObject {
external factory LinearAccelerationSensor(
[AccelerometerSensorOptions options]);
}

/// The **`GravitySensor`** interface of the
/// [Sensor APIs](https://developer.mozilla.org/en-US/docs/Web/API/Sensor_APIs)
/// provides on each reading the gravity applied to the device along all three
/// axes.
///
/// To use this sensor, the user must grant permission to the `'accelerometer'`
/// device sensor through the
/// [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API).
/// In addition, this feature may be blocked by a
/// [Permissions Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy)
/// set on your server.
///
/// ---
///
/// API documentation sourced from
/// [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/GravitySensor).
extension type GravitySensor._(JSObject _) implements Sensor, JSObject {
external factory GravitySensor([AccelerometerSensorOptions options]);
}
27 changes: 27 additions & 0 deletions lib/src/dom/attribution_reporting_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// API docs from [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web).
// Attributions and copyright licensing by Mozilla Contributors is licensed
// under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/.

// Generated from Web IDL definitions.

@JS()
library;

import 'dart:js_interop';

extension type AttributionReportingRequestOptions._(JSObject _)
implements JSObject {
external factory AttributionReportingRequestOptions({
required bool eventSourceEligible,
required bool triggerEligible,
});

external bool get eventSourceEligible;
external set eventSourceEligible(bool value);
external bool get triggerEligible;
external set triggerEligible(bool value);
}
83 changes: 83 additions & 0 deletions lib/src/dom/battery_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// API docs from [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web).
// Attributions and copyright licensing by Mozilla Contributors is licensed
// under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/.

// Generated from Web IDL definitions.

@JS()
library;

import 'dart:js_interop';

import 'dom.dart';
import 'html.dart';

/// The `BatteryManager` interface of the [Battery Status API] provides
/// information about the system's battery charge level. The
/// [navigator.getBattery] method returns a promise that resolves with a
/// `BatteryManager` interface.
///
/// Since Chrome 103, the `BatteryManager` interface of [Battery Status API]
/// only expose to secure context.
///
/// ---
///
/// API documentation sourced from
/// [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager).
extension type BatteryManager._(JSObject _) implements EventTarget, JSObject {
/// The **`BatteryManager.charging`** property is a Boolean value indicating
/// whether or not the device's battery is currently being charged. When its
/// value changes, the [BatteryManager.chargingchange_event] event is fired.
///
/// If the battery is charging or the user agent is unable to report the
/// battery status information, this value is `true`. Otherwise, it is
/// `false`.
external bool get charging;

/// The **`BatteryManager.chargingTime`** property indicates the amount of
/// time, in seconds, that remain until the battery is fully charged, or `0`
/// if the battery is already fully charged or the user agent is unable to
/// report the battery status information.
/// If the battery is currently discharging, its value is `Infinity`.
/// When its value changes, the [BatteryManager.chargingtimechange_event]
/// event is fired.
///
/// > **Note:** Even if the time returned is precise to the second,
/// > browsers round them to a higher interval
/// > (typically to the closest 15 minutes) for privacy reasons.
external num get chargingTime;

/// The **`BatteryManager.dischargingTime`** property indicates the amount of
/// time, in seconds, that remains until the battery is fully discharged,
/// or `Infinity` if the battery is currently charging rather than discharging
/// or the user agent is unable to report the battery status information.
/// When its value changes, the [BatteryManager.dischargingtimechange_event]
/// event is fired.
///
/// > **Note:** Even if the time returned is precise to the second, browsers
/// > round them to a higher
/// > interval (typically to the closest 15 minutes) for privacy reasons.
external num get dischargingTime;

/// The **`BatteryManager.level`** property indicates the current battery
/// charge level as a value between `0.0` and `1.0`.
/// A value of `0.0` means the battery is empty and the system is about to be
/// suspended.
/// A value of `1.0` means the battery is full or the user agent is unable to
/// report the battery status information.
/// When its value changes, the [BatteryManager.levelchange_event] event is
/// fired.
external num get level;
external EventHandler get onchargingchange;
external set onchargingchange(EventHandler value);
external EventHandler get onchargingtimechange;
external set onchargingtimechange(EventHandler value);
external EventHandler get ondischargingtimechange;
external set ondischargingtimechange(EventHandler value);
external EventHandler get onlevelchange;
external set onlevelchange(EventHandler value);
}
Loading

0 comments on commit 7604578

Please sign in to comment.