Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

62 changes: 56 additions & 6 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,70 @@
name: Dart CI

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

env:
PANA_SCORE_MAX_DIFFERENCE: 20

jobs:
format:
name: Verify code formatting
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart --version && dart pub get
- name: Verify formatting
run: dart format --set-exit-if-changed .
lints:
name: Analyze source code
needs: [format]
runs-on: ubuntu-slim
strategy:
fail-fast: false
matrix:
sdk: [3.6, stable, beta, dev]
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDK version 3.6 is specified in the matrix, but this doesn't match standard GitHub Actions SDK version specifications. The dart-lang/setup-dart action expects values like 3.6.0 or ranges. Using just 3.6 may not resolve to a valid version. Consider using 3.6.0 instead.

Suggested change
sdk: [3.6, stable, beta, dev]
sdk: [3.6.0, stable, beta, dev]

Copilot uses AI. Check for mistakes.
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Install dependencies
run: dart --version && dart pub get
- name: Analyze project source
run: dart analyze
package_health:
name: Analyze package health
needs: [lints]
runs-on: ubuntu-slim
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runner is set to ubuntu-slim, but this is not a standard GitHub Actions runner. The valid GitHub-hosted runners are ubuntu-latest, ubuntu-22.04, ubuntu-20.04, etc. This will cause the workflow to fail. Change to ubuntu-latest or another valid runner name.

Copilot uses AI. Check for mistakes.
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart --version && dart pub get && dart pub global activate pana
- name: Run package analyzer
run: dart pub global run pana --exit-code-threshold $PANA_SCORE_MAX_DIFFERENCE
test:
runs-on: ${{ matrix.os }}
name: Run tests
needs: [lints]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [stable, beta, dev]
steps:
- uses: actions/checkout@v3
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The workflow uses actions/checkout@v3, but the latest major version is v4. Consider upgrading to actions/checkout@v4 for the latest features and bug fixes.

Copilot uses AI. Check for mistakes.
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- uses: browser-actions/setup-chrome@v2
- name: Install dependencies
run: dart pub get
- name: Run tests
run: dart test --platform vm
run: dart --version && dart pub get
- name: Run tests (VM)
run: dart test --platform vm
- name: Run tests (Chrome, JS)
run: dart test --platform chrome --compiler dart2js
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Publish to pub.dev

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: pub.dev
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.2.7
* Improves documentation and tests.

## 2.2.6
* Removes an unnecessary dependency.

## 2.2.5
* Updates the library for new Dart SDK and fixes most analyzer warnings.

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
[![Github Actions CI](https://github.com/dint-dev/universal_html/workflows/Dart%20CI/badge.svg)](https://github.com/dint-dev/universal_html/actions)

# Introduction
A cross-platform `dart:html`:
A cross-platform replacement for `dart:html` (or `package:web`):
* __Eases cross-platform development__
* You can use this package in browsers, mobile, desktop, and server-side VM, and Node.JS.
* Just replace `dart:html` imports with `package:universal_html/html.dart`. Normal
* Just replace `dart:html` / `package:web` imports with `package:universal_html/universal_html.dart`. Normal
_dart:html_ will continue to be used when application run in browsers.
* __Extensive support for processing HTML and XML documents__
* Parse, manipulate, and print [DOM nodes](https://api.dart.dev/stable/2.19.3/dart-html/Node-class.html).
* Parse, manipulate, and print [DOM nodes](https://api.flutter.dev/flutter/dart-html/Node-class.html).
* Find DOM nodes with [querySelectorAll](https://api.dart.dev/stable/2.19.3/dart-html/querySelectorAll.html)
and other CSS query methods.
* __EventSource streaming support__
Expand All @@ -35,12 +35,12 @@ which is documented in the relevant files.
In `pubspec.yaml`:
```yaml
dependencies:
universal_html: ^2.2.5
universal_html: ^2.2.7
```

## 2. Use
```dart
import "package:universal_html/html.dart";
import "package:universal_html/universal_html.dart";
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import example has been changed to use package:universal_html/universal_html.dart, but this is inconsistent with line 9 which still says to "replace dart:html / package:web imports with package:universal_html/html.dart". These should be aligned - either both should reference universal_html.dart or both should reference html.dart.

Suggested change
import "package:universal_html/universal_html.dart";
import "package:universal_html/html.dart";

Copilot uses AI. Check for mistakes.

void main() {
// Create a DOM tree
Expand Down Expand Up @@ -121,7 +121,7 @@ is a browser API for reading "application/event-stream" streams. It has been sup
for a long time.

```dart
import 'package:universal_html/html.dart';
import 'package:universal_html/universal_html.dart';

Future<void> main() async {
final eventSource = EventSource('http://example.com/events');
Expand Down
26 changes: 3 additions & 23 deletions lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/// Cross-platform "dart:html" library.
///
/// You can choose from the following libraries:
/// * `package:universal_html/html.dart`
/// * `package:universal_html/prefer_sdk/html.dart`
/// * `package:universal_html/prefer_universal/html.dart`
///
/// # Introduction
///
/// HTML elements and other resources for web-based applications that need to
/// interact with the browser and the DOM (Document Object Model).
///
/// This library includes DOM element types, CSS styling, local storage,
/// media, speech, events, and more.
/// To get started,
/// check out the [Element] class, the base class for many of the HTML
/// DOM types.
///
/// For information on writing web apps with Dart, see https://webdev.dartlang.org.
/// @nodoc
@Deprecated('Replace with "package:universal_html/universal_html.dart.')
library;

export 'src/_sdk/html.dart'
if (dart.library.html) 'src/_sdk/html.dart' // Browser
if (dart.library.io) 'src/html.dart' // VM
if (dart.library.js) 'src/html.dart'; // Node.JS
export 'universal_html.dart';
6 changes: 2 additions & 4 deletions lib/src/_sdk_html_additions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ abstract class EventSourceOutsideBrowser implements EventSource {
FutureOr<void> Function(
EventSourceOutsideBrowser eventSource,
HttpClientRequest request,
)?
onHttpClientRequest;
)? onHttpClientRequest;

/// A callback called when a [HttpClientResponse] arrives (only outside
/// browsers).
Expand All @@ -63,8 +62,7 @@ abstract class EventSourceOutsideBrowser implements EventSource {
EventSourceOutsideBrowser eventSource,
HttpClientRequest request,
HttpClientResponse response,
)?
onHttpClientResponse;
)? onHttpClientResponse;

/// Current timeout.
Duration retryDuration = Duration(seconds: 3);
Expand Down
3 changes: 1 addition & 2 deletions lib/src/controller/internal_element_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import 'package:universal_html/html.dart';

import 'internal_element_data_impl_others.dart'
if (dart.library.html) 'internal_element_data_impl_browser.dart'
as impl;
if (dart.library.html) 'internal_element_data_impl_browser.dart' as impl;

/// Internal data of [Element].
///
Expand Down
3 changes: 1 addition & 2 deletions lib/src/controller/window_behavior.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import 'package:universal_html/html.dart';
import 'window_behavior_impl_browser.dart'
if (dart.library.html) 'window_behavior_impl_browser.dart' // Browser
if (dart.library.io) 'window_behavior_impl_others.dart' // VM
if (dart.library.js) 'window_behavior_impl_others.dart'
as impl; // Node.JS
if (dart.library.js) 'window_behavior_impl_others.dart' as impl; // Node.JS

/// Defines behavior of the browser APIs (such as navigation events).
///
Expand Down
7 changes: 3 additions & 4 deletions lib/src/controller/window_behavior_impl_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ Document newDocument({

HtmlDocument newHtmlDocument({required Window window, String? contentType}) {
return DomParser().parseFromString(
'<html></html>',
contentType ?? 'text/html',
)
as HtmlDocument;
'<html></html>',
contentType ?? 'text/html',
) as HtmlDocument;
}

Navigator newNavigator({required Window window}) {
Expand Down
66 changes: 63 additions & 3 deletions lib/src/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// The library name is needed for generating differences between our library
// and dart:html.
library;

import 'dart:async';
Expand All @@ -31,7 +29,8 @@ import 'package:csslib/parser.dart' as css;
import 'package:csslib/visitor.dart' as css;
import 'package:meta/meta.dart';
import 'package:typed_data/typed_buffers.dart';
import 'package:universal_html/html.dart' as universal_html_in_browser_or_vm;
import 'package:universal_html/universal_html.dart'
as universal_html_in_browser_or_vm;

import '../controller.dart';
import 'html.dart' as universal_html;
Expand All @@ -52,64 +51,125 @@ export 'html_top_level_functions.dart';
export 'js_util.dart' show promiseToFuture;

part 'html/api/accessible_node.dart';

part 'html/api/animation.dart';

part 'html/api/application_cache.dart';

part 'html/api/blob.dart';

part 'html/api/canvas.dart';

part 'html/api/console.dart';

part 'html/api/crypto.dart';

part 'html/api/data_transfer.dart';

part 'html/api/device.dart';

part 'html/api/dom_matrix.dart';

part 'html/api/event.dart';

part 'html/api/event_handlers.dart';

part 'html/api/event_source.dart';

part 'html/api/event_stream.dart';

part 'html/api/event_subclasses.dart';

part 'html/api/event_target.dart';

part 'html/api/file.dart';

part 'html/api/geolocation.dart';

part 'html/api/history.dart';

part 'html/api/http_request.dart';

part 'html/api/keycode.dart';

part 'html/api/media.dart';

part 'html/api/navigator.dart';

part 'html/api/navigator_misc.dart';

part 'html/api/notification.dart';

part 'html/api/payment.dart';

part 'html/api/performance.dart';

part 'html/api/permissions.dart';

part 'html/api/scroll.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';

part 'html/dom/css_selectors.dart';

part 'html/dom/css_style_declaration.dart';

part 'html/dom/css_style_declaration_base.dart';

part 'html/dom/css_style_declaration_set.dart';

part 'html/dom/document.dart';

part 'html/dom/document_fragment.dart';

part 'html/dom/dom_exception.dart';

part 'html/dom/element.dart';

part 'html/dom/element_attributes.dart';

part 'html/dom/element_list.dart';

part 'html/dom/element_misc.dart';

part 'html/dom/element_subclasses.dart';

part 'html/dom/element_subclasses_for_inputs.dart';

part 'html/dom/html_document.dart';

part 'html/dom/html_node_validator.dart';

part 'html/dom/node.dart';

part 'html/dom/node_child_node_list.dart';

part 'html/dom/node_printing.dart';

part 'html/dom/node_validator_builder.dart';

part 'html/dom/parser.dart';

part 'html/dom/shared_with_dart2js/css_class_set.dart';

part 'html/dom/validators.dart';

part 'html/dom/xml_document.dart';
7 changes: 3 additions & 4 deletions lib/src/html/_html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ class _HtmlParser {
if (name is html_parsing.AttributeName) {
result.internalSetAttributeNSFromParser(
namespaceUri: name.namespace,
qualifiedName:
name.prefix == null
? name.name
: '${name.prefix}:${name.name}',
qualifiedName: name.prefix == null
? name.name
: '${name.prefix}:${name.name}',
localName: name.name,
value: value,
);
Expand Down
Loading