pub repository
mirror.p-hatan.irweb
1.0.0Lightweight browser API bindings built around JS interop.
Readme
Dart CI pub package package publisher
Lightweight browser API bindings built around JS interop.
What's this?
This package exposes browser APIs. It's generated from the Web IDL definitions and uses recent Dart language features for zero-overhead bindings.
This package is intended to replace
dart:html and
similar Dart SDK libraries. It will support access to browser APIs from Dart
code compiled to either JavaScript or WebAssembly.
Usage
import 'package:web/web.dart';
void main() {
final div = document.querySelector('div')!;
div.text = 'Text set at ${DateTime.now()}';
}
Migrating to package:web
package:web is replacing dart:html and other web libraries as Dart's
long-term web interop solution. To learn how to migrate from dart:html
APIs to package:web, see our
migration guide.
Generation conventions
The generator scripts use a number of conventions to consistently handle Web IDL definitions:
Interfaces
- Interfaces are emitted as extension types that wrap and implement
JSObject. - Interface inheritance is maintained using
implementsbetween extension types. - Members of partial interfaces, partial mixins, and mixins are added to the interfaces that include them, and therefore do not have separate declarations.
Types
- Generic types include the generic in the case of
JSArrayandJSPromise. - Enums are typedef'd to
String. - Callbacks and callback interfaces are typedef'd to
JSFunction. - In general, we prefer the Dart primitive over the JS type equivalent wherever
possible. For example, APIs use
Stringinstead ofJSString. - If a type appears in a generic position and it was typedef'd to a Dart
primitive type, it is replaced with the JS type equivalent to respect the type
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 to 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
Most of the APIs in this package are generated from public assets. See tool/README.md for information on the spec and IDL versions the package was generated from, and for the process for updating the package.
Changelog
1.0.0
- Added supertypes' fields to dictionary constructors as dictionaries are allowed to contain those fields.
- Empty dictionary constructors now create an empty object instead of being
treated like non-object literal
externalconstructors. - Generate MDN API documentation for getters.
- 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.
- Added
onUnloadevent stream toElementEventGettersextension methods. - Expose
ElementStreamas a public class. - Require Dart
^3.4.0. - APIs that return a double value now return
doubleinstead ofnum. This is to avoid users accidentally downcastingnum, which has different semantics depending on whether you compile to JS or Wasm. See issue #57 for more details. - Fix an issue where some union types didn't account for typedef nullability.
0.5.1
- Add
TrustedTypesmembers. - Include MDN API documentation as class and member dartdoc comments. Docs sourced from the MDN Web Docs project; attributions and copyright licensing by Mozilla Contributors is licensed under CC-BY-SA 2.5.
- Add a constructor for each Element tag onto their respective Element interfaces.
- Remove
externalElement constructors that would result in a runtime error. - Deprecate
createAudioElementin favor of theHTMLAudioElementconstructor.
0.5.0
-
Redeprecate APIs that were deprecated in
0.4.1but undeprecated in0.4.2. -
Add support for
dart fixmigrations fromdart:htmlclasses topackage:webclasses. -
Contribute a markdown file for the renamed classes from
dart:htmltopackage:web(see renames.md). -
Migrate classes to use interop extension types that implement
JSObject. -
Add generics to APIs that use
JSArrayandJSPromise. Typedefs of a Dart primitive type are instead replaced with their JS type equivalent if they appear as a type parameter in order to conform with the type bounds ofJSArrayandJSPromise. -
Changed
recordtypes to beJSObjectinstead ofJSAny. -
Reduce the number of DOM APIs we generate code for. Currently, the API needs to be standards-track, and be supported by Safari, Chrome, and Firefox.
-
Updated the source IDL version to
3.43.1. -
Deprecate a few type aliases in favor of their standardized versions:
Deprecated Preferred AudioElementHTMLAudioElementHtmlElementHTMLElementCanvasElementHTMLCanvasElementImageElementHTMLImageElementVideoElementHTMLVideoElementCssStyleDeclarationCSSStyleDeclarationContextEventWebGLContextEventWebGLWebGLRenderingContext -
Deprecate the top-level
createElementTag,createCanvasElement,createIFrameElement, andquerySelectorfunctions. Instead, use the standard creation and query methods ondocument. -
Deprecate the
clientextension methods onMouseEventandTouch. Instead, directly use theclientXandclientYproperties. -
Deprecate the
HttpRequestAPI borrowed fromdart:html. Consider migrating topackage:httpinstead.
0.4.2
- Undeprecate some APIs and helpers library that were deprecated in
0.4.1. Because deprecations are breaking in Flutter, they should be done in a breaking change.
0.4.1
- Exported the helper libraries from
web.dart. - Deprecated the
helpers.dartlibrary in favor ofweb.dart. - Updated the readme to include usage info and package status.
- Added an example.
- Added event extensions for
WebSocket - Fixes to the return types of the
append()andclone()extension methods onNode. - Deprecated
NodeGlue.appendin favor ofNode.appendChild. - Deprecated
NodeGlue.clonein favor ofNode.cloneNode. - Updated
@webref/cssto6.10.0.
0.4.0
- Remove
implements JSObjectfrom all types. This is needed to move the JS types exposed indart:js_interopto extension types. This subtyping will be added back in a future version when we move allpackage:webtypes to extension types. - Add
onMessagegetter toWindowEventGettersextension methods. helpers.dart: expose theEventStreamProvidersclass.- Add
createIFrameElementmethod tohelpers.dart. - Updated types to account for union types.
- Fixed issue where all
JSAnys were treated as nullable. - Changed
JSVoidtovoid. interface mixins are no longer emitted as interfaces. Their members are instead added to the interface that mixes them in.
0.3.0
- Updated source IDL to
v3.39.1. - Fixed a bug where
typedefs were not declared with the IDL type's nullability. - Types that were aliased to
doubleare now aliased tonum. This is to make it easier for users to pass integer values without going through a cast and to make migration fromdart:htmleasier.
0.2.2-beta
- Updates SDK version minimum to 3.2.0-194.0.dev.
- Removes
isInstanceOfDomTypeasdart:js_interopnow exposesinstanceOfString.
0.2.1-beta
helpers.dart- Expose
EventStreamProvider
- Expose
0.2.0-beta
- Added
helpers.darttop-level library. - Require Dart 3.2 pre-release.
- Update to IDL 3.38.2
0.1.4-beta
- Support
bool,int,double,Stringin APIs.
0.1.3-beta
- CSS properties can now be accessed directly.
0.1.2-beta
JSAnyas an IDL type now includesnull.
0.1.1-beta
- Objects now inherit from JSObject.
0.1.0-beta
- First release.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add webpubspec.yaml
name: web
version: 1.0.0
description: Lightweight browser API bindings built around JS interop.
repository: https://github.com/dart-lang/web
environment:
sdk: ^3.4.0
dev_dependencies:
analyzer: ^6.3.0
args: ^2.4.0
build_runner: ^2.4.6
build_web_compilers: ^4.0.8
code_builder: ^4.10.0
collection: ^1.18.0
dart_flutter_team_lints: ^3.0.0
dart_style: ^2.3.4
io: ^1.0.4
path: ^1.8.3
test: ^1.24.4
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2015-07-31T00:10:03.379Z | Download | ed511c92013b89f55926e92cbf5a33e2a47e1d2226925d48d8aed78f7b8fa209 |
| 0.1.0-beta | 2023-05-02T17:10:36.390652Z | Download | 4682cbe455e394c8dcacf1c1e53917eeea446737884ce0983e738a7e2f446761 |
| 0.1.1-beta | 2023-05-15T19:38:58.731494Z | Download | ad8dae821733dd5b425cd98d707084956c9bfece337c8374e17072c6e54af5a7 |
| 0.1.2-beta | 2023-05-15T22:28:04.455621Z | Download | abf85421e1f06c6bb2fe6d81b544e0c1c86437aa4e2fab57153ff6829a8d084d |
| 0.1.3-beta | 2023-05-22T17:34:48.550847Z | Download | 47e396fadea4d65295c81f06f482c8bf6bc804f46f8caf11df160806c4a53785 |
| 0.1.4-beta | 2023-06-14T17:43:18.439747Z | Download | dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 |
| 0.2.0-beta | 2023-09-19T18:03:28.888791Z | Download | 6106a51fd43fe8f82749994ec6f4f8a18025c2bff3651170bebf1f63d420bebc |
| 0.2.1-beta | 2023-09-19T23:14:49.313295Z | Download | 14f1f70c51119012600c5f1f60ca68efda5a9b6077748163c6af2893ec5df8fc |
| 0.2.2-beta | 2023-09-27T21:13:00.893497Z | Download | ccbbfbf29732ee1b391c4c6d13e7032d851f675f47365e81904e4c6fd669c854 |
| 0.3.0 | 2023-10-11T21:50:44.833239Z | Download | afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 |
| 0.3.1-dev | 2023-11-10T23:33:09.415823Z | Download | 03ce602c4639f0b483d22fdfc2dab35d2766912fa76dc2ebe82a8e8fd952dfe0 |
| 0.4.0 | 2023-11-14T20:19:48.904397Z | Download | edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa |
| 0.4.1 | 2024-01-11T19:52:10.711418Z | Download | a4fcead029d8cbde2df1674cdc4585640a28bddd1e46878b9ceebeaf9d7a5913 |
| 0.4.2 | 2024-01-12T01:31:50.952455Z | Download | 4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05 |
| 0.5.0 | 2024-02-13T20:25:54.210715Z | Download | 1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad |
| 0.5.1 | 2024-03-05T19:22:22.757953Z | Download | 97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27 |
| 1.0.0 | 2024-07-16T01:34:24.237084Z | Download | d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 |
| 1.1.0 | 2024-09-24T22:36:58.026862Z | Download | cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb |
| 1.1.1 | 2025-02-26T21:23:27.138850Z | Download | 868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a |
| 1.1.2 | 2026-10-23T00:25:24.742112Z | Download | e119e82ac4795c7925103b7cf3768191f33941b99e7ccffbd6c645201d9f606b |
Dependencies
No direct dependencies declared.