p-hatan/ mirror

pub repository

mirror.p-hatan.ir

js

0.6.1+1

Access JavaScript from Dart.

This package is discontinued upstream.

Download archive

Readme

Methods and annotations to specify interoperability with JavaScript APIs.

This packages requires Dart SDK 1.13.0.

This is beta software. Please files issues.

Adding the dependency

Add the following to your pubspec.yaml:

dependencies:
  js: ^0.6.0

Example

See the Chart.js Dart API for an end-to-end example.

Usage

Calling methods

// Calls invoke JavaScript `JSON.stringify(obj)`.
@JS("JSON.stringify")
external String stringify(obj);

Classes and Namespaces

@JS('google.maps')
library maps;

import "package:js/js.dart";

// Invokes the JavaScript getter `google.maps.map`.
external Map get map;

// `new Map` invokes JavaScript `new google.maps.Map(location)`
@JS()
class Map {
  external Map(Location location);
  external Location getLocation();
}

// `new Location(...)` invokes JavaScript `new google.maps.LatLng(...)`
//
// We recommend against using custom JavaScript names whenever
// possible. It is easier for users if the JavaScript names and Dart names
// are consistent.
@JS("LatLng")
class Location {
  external Location(num lat, num lng);
}

JavaScript object literals

Many JavaScript APIs take an object literal as an argument. For example:

// JavaScript
printOptions({responsive: true});

If you want to use printOptions from Dart, you cannot simply pass a Dart Map object – they are "opaque" in JavaScript.

Instead, create a Dart class with both the @JS() and @anonymous annotations.

// Dart
void main() {
  printOptions(new Options(responsive: true));
}

@JS()
external printOptions(Options options);

@JS()
@anonymous
class Options {
  external bool get responsive;

  external factory Options({bool responsive});
}

NB: This anonymous class must have an unnamed factory constructor.

Passing functions to JavaScript.

If you are passing a Dart function to a JavaScript API, you must wrap it using allowInterop or allowInteropCaptureThis.

Contributing and Filing Bugs

Please file bugs and features requests on the Github issue tracker.

We also love and accept community contributions, from API suggestions to pull requests. Please file an issue before beginning work so we can discuss the design and implementation. We are trying to create issues for all current and future work, so if something there intrigues you (or you need it!) join in on the discussion.

Code contributors must sign the Google Individual Contributor License Agreement.

Changelog

0.6.1+1

  • Support Dart 2 final release.

0.6.1

  • Add js_util library of utility methods to efficiently manipulate typed JavaScript interop objects in cases where the member name is not known statically.

0.6.0

  • Version 0.6.0 is a complete rewrite of package:js.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add js
pubspec.yaml
name: js
version: 0.6.1+1
author: Dart Team <misc@dartlang.org>
description: Access JavaScript from Dart.
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/js

environment:
  sdk: '>=1.19.0-dev.0.0 <3.0.0'

Version history

VersionPublishedArchiveSHA-256
0.0.12012-09-24T21:03:16.822740ZDownload3c2c8833edfb7ca2efe75ae764bec2b72d72c57a086997a2625a8c5f8cb46b94
0.0.22012-10-03T01:23:09.043490ZDownload94cbef92f926432977da55890c1e84ab91f44874e9d4c18e2498920a0eb9430a
0.0.32012-10-10T22:20:33.342400ZDownload810a0c6360e246fd91aa371a36935f707d6516f49548e2e14fe63044bba38d95
0.0.42012-10-15T20:37:36.622420ZDownloadc8cd4ab04cd1cbcee43d0856117103f28d10919d53c0be3a31a7a3ce0ba6641e
0.0.52012-10-15T23:19:36.506600ZDownload8b484f37eaa93daab891cae7801b8528a3bb13f29b29a78c0ac712c1294dbc4d
0.0.62012-10-21T04:33:30.988520ZDownloada26db6f5b48a4f6188e3a006bda5d2ae6faf0ca9c97c2ba9cb327b2cb829fbbf
0.0.72012-10-25T20:52:00.878570ZDownloadd91f6834484d97614d0ef1cee192621b218674fb787f886a28deedfc9fc7cf4c
0.0.82012-11-05T18:47:13.077110ZDownload5485720ad3c8111fe5450aa62ba8329ff8997b22fb8b6cb7425d95628f72f19c
0.0.92012-11-05T19:00:38.961530ZDownload9fbef9d63ad2193e52db28ce09a65a6e683d637064d1fbb8e0c3de4a12cd130f
0.0.102012-11-14T20:01:42.779590ZDownload26be8b9f00b72fc2774f7f269713170e93febfa7c28c7240541099c2af8d85b8
0.0.112012-11-28T22:53:09.688640ZDownload4e3bf11f35e882f990ad4401b7b25a8dbc6795f7b829cc3c286b9b0a1a6ae62b
0.0.122012-11-30T23:10:00.246170ZDownload47be97d29f6946eea63be83617677a0ecc877909d5b0eeac7de20eac81651d06
0.0.132012-12-07T00:41:42.148850ZDownload76529a055dcd58c09e0dfd00d2c3edc7808d43ac1e98f9da766fcca150f64f28
0.0.142013-01-22T19:37:57.173180ZDownload4d24f7724484ddec3457ffab1c85dc321faec1ffa0579f3b5b624c37a51159c9
0.0.152013-01-23T18:21:55.168490ZDownloadc820d2fe2d439d6118b4775b865e98ca79a794649cdced46f76fdc3ebe90ea5c
0.0.162013-02-13T18:22:13.477660ZDownload947d3e9c03e8018afc9b1380c854b32a2223c410c60263f0b18ad78b203867eb
0.0.172013-03-06T22:59:57.316680ZDownloadfed2d53a1c6bc1e3eae602ef6a101c1d7632cf6ec188d5460ad5730ba3c6786f
0.0.182013-03-19T03:10:08.159620ZDownload91ebff359988a2a82007518ef974d63042ab4bc82b1c80a8c748124024be1a72
0.0.192013-04-09T15:43:13.109070ZDownload9320585cb52e375857e0648d5b858bd9fe2176bd2f34b0ceaa5701a1faf88828
0.0.202013-04-16T18:23:20.285230ZDownload24653ceacc36dd4888334d0fc8657fc69edae4386339af16447fd97b98a15d95
0.0.212013-04-19T20:22:54.869590ZDownload81723719ec542bde1f04861984110935bd1c28a3e8423a4f0f1acfde05cb7c21
0.0.222013-04-24T15:38:43.240530ZDownload9b303085b8e77bab0c7e1998b6801b586dc896b2617af0522713ab56a796c56c
0.0.232013-06-21T22:59:48.556680ZDownload9af701213d9b35470b2a0cc2d50dca88e720aeef4285ba3cffda2203a12338a8
0.0.242013-07-16T01:16:01.117040ZDownload1ad33dde6eae3750e5b71685f6235eacaacb9048f489475fd359ad4022e2e551
0.0.252013-10-02T19:14:47.453780ZDownload7ccc419dff8fb953636c5c6b21d49f99b3e0f4648c7212ce3f4ae9618d94cfbc
0.0.262013-10-29T02:53:31.608580ZDownload8cf24c9311a0ed6add3d5c11b01d4e4436117f2ca8835a067c720e6c81130e9e
0.1.02013-10-30T19:11:03.607080ZDownload9df5657946ff751d237edf0d7888c86b41afd72eb5bbeffffaf29e5a4141b4ad
0.2.02013-11-04T00:33:58.548550ZDownload2e4e72c132fb165e5195a40992c690b4a5004b1e17e044343ec8e4a0eed8e39f
0.2.12013-12-11T22:47:10.812210ZDownloade45f5c2fba62ed63afaef3cad952eb4627f19b14d10b08a56a62b7f8a4a42777
0.2.22014-02-02T19:51:46.379130ZDownload78f49cdff1cb148cf48b14d31dfee75bedbfc0a698ee48a751f80ac289e2f353
0.3.02014-08-29T21:14:58.790770ZDownload6b7ed037786d5a2dc865deb34d6b9b24a2c3839ab136593db0d8f9e2861dd238
0.6.0-beta.12015-10-15T16:46:57.924ZDownloadf4cf66144b92611b50c3a03a3a35c84044f13d220420ed64203b3096e7679ef8
0.6.0-beta.22015-10-15T17:47:25.667ZDownload2e87a9007b324275ea8d34a87d26c5fdc62168473aabf05bbeb351ca20daba4f
0.6.0-beta.32015-10-15T21:52:33.891ZDownloade9aec46b50ed4b5dbeaa1ae57455473f95bbfabc0682b71b024ac4506bca9929
0.6.0-beta.42015-10-15T23:33:35.627ZDownload13cca2d0eb805013a3b2355e30c567bced0e3ee2112f3156be6630a34736ea1b
0.6.0-beta.52015-10-21T16:58:53.459ZDownload60fef118cdb33122d4b7e331b7608444b281c8a7018b06c2c56086f92d7d13bc
0.6.0-beta.62015-10-29T17:33:33.371ZDownloadb3ce6df01f1a586ae17a203cb74612c8aff0c2b10303dd8fcc476156b462f6fb
0.6.0-beta.72015-11-02T17:37:19.899ZDownload12266f4b714763608141a774ae535876636a8c6f973dcaa21eefacbd5fe60b3e
0.6.0-beta.92015-11-11T20:20:09.418ZDownload1e4706c4e2ef5a13f47239ab0df3f1f63bfef7120964a801101eac9725d6e2d5
0.6.0-beta.102015-11-17T19:11:02.790ZDownload103d2ddc8a42ae40c8d9a78b708fc21219554e10a8e5c5203f9d546c5d34330a
0.6.02015-11-18T23:34:48.837ZDownload47af5e70008e954aa7e1ba12033e8f2c554aa8d1d09e55d85909e1cc11c9bda7
0.6.12016-08-31T16:45:17.993ZDownloaddefb25374b721cec96ea772f036b9a57a421c256db30bb12f4c17fabae4ff637
0.6.1+12018-07-18T21:37:17.769238ZDownload5003282c974d9d96d105efe1f027df6a3f005b3e316576d798218d8c8464d5c0
0.6.22020-06-08T22:34:52.573362ZDownloade2c83d11970692d58756bac957864eb1f3d4ade99fa6cbaeb1e70fe847813cb6
0.6.3-nullsafety2020-07-29T16:15:38.449054ZDownloadcfe8da7ca1273dc137968e9e97160f202fbc07fe51c6ff1be884bc94330f5d64
0.6.3-nullsafety.12020-09-22T15:50:28.163235ZDownload25d4b7e160a788d454da1442e72e1e830668b86e76b0e71e90299e0e69029212
0.6.3-nullsafety.22020-10-23T19:46:00.268956ZDownload62eca6c377ba74b654ede9c10715f41a0ce386fcb3a2bd5f1fd407735f1c7e93
0.6.3-nullsafety.32020-11-03T21:33:23.352260ZDownloaddfb559417d67d585f9e9b587db20ddedf3662b14fb4d440b70fec16fb6e37b94
0.6.32021-02-02T21:48:56.864313ZDownloadd9bdfd70d828eeb352390f81b18d6a354ef2044aa28ef25682079797fa7cd174
0.6.42021-12-22T23:38:47.033384ZDownloada5e201311cb08bf3912ebbe9a2be096e182d703f881136ec1e81a2338a9e120d
0.6.52022-10-19T19:07:26.638527ZDownload5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7
0.6.62022-12-16T21:57:04.327278ZDownload323b7c70073cccf6b9b8d8b334be418a3293cfb612a560dc2737160a37bf61bd
0.6.72023-01-26T21:40:19.536574ZDownloadf2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
0.6.82023-03-17T23:34:32.544803ZDownloadcf7243a0c29626284ada2add68a33f5b1102affe3509393e75136e0f6616bd68
0.7.02024-01-05T00:17:24.675663ZDownload4186c61b32f99e60f011f7160e32c89a758ae9b1d0c6d28e2c02ef0382300e2b
0.7.12024-02-16T19:19:51.410919ZDownloadc1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
0.7.22025-02-11T20:13:19.280145ZDownload53385261521cc4a0c4658fd0ad07a7d14591cf8fc33abbceae306ddb974888dc

Dependencies

No direct dependencies declared.