Skip to content

Commit 641a8df

Browse files
authored
Add generated element constructors (#185)
For every tag that the interface supports, emits a Dart constructor that can be used to create an element of that tag using either createElement or createElementNS. Adds a dependency to @webref/elements to fetch the element data. Note that not every element interface has a tag associated with it. Adds a test and modifies existing helper messages to point to the new constructors instead. Also deprecates createAudioElement.
1 parent 5e5adc8 commit 641a8df

20 files changed

+1275
-136
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- Include MDN API documentation as class and member dartdoc comments. Docs
55
sourced from the [MDN Web Docs][] project; attributions and copyright
66
licensing by Mozilla Contributors is licensed under [CC-BY-SA 2.5][].
7+
- Add a constructor for each Element tag onto their respective Element
8+
interfaces.
9+
- Remove `external` Element constructors that would result in a runtime error.
10+
- Deprecate `createAudioElement` in favor of the `HTMLAudioElement` constructor.
711

812
[MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web
913
[CC-BY-SA 2.5]: https://creativecommons.org/licenses/by-sa/2.5/

lib/src/dom/css_masking.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@ library;
1313

1414
import 'dart:js_interop';
1515

16+
import 'dom.dart';
1617
import 'svg.dart';
1718

1819
/// The **`SVGClipPathElement`** interface provides access to the properties of
1920
/// elements, as well as methods to manipulate them.
2021
extension type SVGClipPathElement._(JSObject _)
2122
implements SVGElement, JSObject {
23+
/// Creates an [SVGClipPathElement] using the tag 'clipPath'.
24+
SVGClipPathElement()
25+
: _ = document.createElementNS(
26+
'http://www.w3.org/2000/svg',
27+
'clipPath',
28+
);
29+
2230
external SVGAnimatedEnumeration get clipPathUnits;
2331
external SVGAnimatedTransformList get transform;
2432
}
2533

2634
/// The **`SVGMaskElement`** interface provides access to the properties of
2735
/// elements, as well as methods to manipulate them.
2836
extension type SVGMaskElement._(JSObject _) implements SVGElement, JSObject {
37+
/// Creates an [SVGMaskElement] using the tag 'mask'.
38+
SVGMaskElement()
39+
: _ = document.createElementNS(
40+
'http://www.w3.org/2000/svg',
41+
'mask',
42+
);
43+
2944
external SVGAnimatedEnumeration get maskUnits;
3045
external SVGAnimatedEnumeration get maskContentUnits;
3146
external SVGAnimatedLength get x;

0 commit comments

Comments
 (0)