diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed8ed72..8968778b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - 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 `external` Element constructors that would result in a runtime error. +- Deprecate `createAudioElement` in favor of the `HTMLAudioElement` constructor. [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web [CC-BY-SA 2.5]: https://creativecommons.org/licenses/by-sa/2.5/ diff --git a/lib/src/dom/css_masking.dart b/lib/src/dom/css_masking.dart index e64944be..82826801 100644 --- a/lib/src/dom/css_masking.dart +++ b/lib/src/dom/css_masking.dart @@ -13,12 +13,20 @@ library; import 'dart:js_interop'; +import 'dom.dart'; import 'svg.dart'; /// The **`SVGClipPathElement`** interface provides access to the properties of /// elements, as well as methods to manipulate them. extension type SVGClipPathElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGClipPathElement] using the tag 'clipPath'. + SVGClipPathElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'clipPath', + ); + external SVGAnimatedEnumeration get clipPathUnits; external SVGAnimatedTransformList get transform; } @@ -26,6 +34,13 @@ extension type SVGClipPathElement._(JSObject _) /// The **`SVGMaskElement`** interface provides access to the properties of /// elements, as well as methods to manipulate them. extension type SVGMaskElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGMaskElement] using the tag 'mask'. + SVGMaskElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'mask', + ); + external SVGAnimatedEnumeration get maskUnits; external SVGAnimatedEnumeration get maskContentUnits; external SVGAnimatedLength get x; diff --git a/lib/src/dom/filter_effects.dart b/lib/src/dom/filter_effects.dart index c39a94b0..dac019c4 100644 --- a/lib/src/dom/filter_effects.dart +++ b/lib/src/dom/filter_effects.dart @@ -13,11 +13,19 @@ library; import 'dart:js_interop'; +import 'dom.dart'; import 'svg.dart'; /// The **`SVGFilterElement`** interface provides access to the properties of /// elements, as well as methods to manipulate them. extension type SVGFilterElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFilterElement] using the tag 'filter'. + SVGFilterElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'filter', + ); + external SVGAnimatedEnumeration get filterUnits; external SVGAnimatedEnumeration get primitiveUnits; external SVGAnimatedLength get x; @@ -29,6 +37,13 @@ extension type SVGFilterElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFEBlendElement`** interface corresponds to the element. extension type SVGFEBlendElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEBlendElement] using the tag 'feBlend'. + SVGFEBlendElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feBlend', + ); + external static int get SVG_FEBLEND_MODE_UNKNOWN; external static int get SVG_FEBLEND_MODE_NORMAL; external static int get SVG_FEBLEND_MODE_MULTIPLY; @@ -59,6 +74,13 @@ extension type SVGFEBlendElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFEColorMatrixElement`** interface corresponds to the element. extension type SVGFEColorMatrixElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEColorMatrixElement] using the tag 'feColorMatrix'. + SVGFEColorMatrixElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feColorMatrix', + ); + external static int get SVG_FECOLORMATRIX_TYPE_UNKNOWN; external static int get SVG_FECOLORMATRIX_TYPE_MATRIX; external static int get SVG_FECOLORMATRIX_TYPE_SATURATE; @@ -78,6 +100,14 @@ extension type SVGFEColorMatrixElement._(JSObject _) /// element. extension type SVGFEComponentTransferElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEComponentTransferElement] using the tag + /// 'feComponentTransfer'. + SVGFEComponentTransferElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feComponentTransfer', + ); + external SVGAnimatedString get in1; external SVGAnimatedLength get x; external SVGAnimatedLength get y; @@ -107,23 +137,58 @@ extension type SVGComponentTransferFunctionElement._(JSObject _) /// The **`SVGFEFuncRElement`** interface corresponds to the element. extension type SVGFEFuncRElement._(JSObject _) - implements SVGComponentTransferFunctionElement, JSObject {} + implements SVGComponentTransferFunctionElement, JSObject { + /// Creates an [SVGFEFuncRElement] using the tag 'feFuncR'. + SVGFEFuncRElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feFuncR', + ); +} /// The **`SVGFEFuncGElement`** interface corresponds to the element. extension type SVGFEFuncGElement._(JSObject _) - implements SVGComponentTransferFunctionElement, JSObject {} + implements SVGComponentTransferFunctionElement, JSObject { + /// Creates an [SVGFEFuncGElement] using the tag 'feFuncG'. + SVGFEFuncGElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feFuncG', + ); +} /// The **`SVGFEFuncBElement`** interface corresponds to the element. extension type SVGFEFuncBElement._(JSObject _) - implements SVGComponentTransferFunctionElement, JSObject {} + implements SVGComponentTransferFunctionElement, JSObject { + /// Creates an [SVGFEFuncBElement] using the tag 'feFuncB'. + SVGFEFuncBElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feFuncB', + ); +} /// The **`SVGFEFuncAElement`** interface corresponds to the element. extension type SVGFEFuncAElement._(JSObject _) - implements SVGComponentTransferFunctionElement, JSObject {} + implements SVGComponentTransferFunctionElement, JSObject { + /// Creates an [SVGFEFuncAElement] using the tag 'feFuncA'. + SVGFEFuncAElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feFuncA', + ); +} /// The **`SVGFECompositeElement`** interface corresponds to the element. extension type SVGFECompositeElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFECompositeElement] using the tag 'feComposite'. + SVGFECompositeElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feComposite', + ); + external static int get SVG_FECOMPOSITE_OPERATOR_UNKNOWN; external static int get SVG_FECOMPOSITE_OPERATOR_OVER; external static int get SVG_FECOMPOSITE_OPERATOR_IN; @@ -148,6 +213,13 @@ extension type SVGFECompositeElement._(JSObject _) /// The **`SVGFEConvolveMatrixElement`** interface corresponds to the element. extension type SVGFEConvolveMatrixElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEConvolveMatrixElement] using the tag 'feConvolveMatrix'. + SVGFEConvolveMatrixElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feConvolveMatrix', + ); + external static int get SVG_EDGEMODE_UNKNOWN; external static int get SVG_EDGEMODE_DUPLICATE; external static int get SVG_EDGEMODE_WRAP; @@ -174,6 +246,14 @@ extension type SVGFEConvolveMatrixElement._(JSObject _) /// The **`SVGFEDiffuseLightingElement`** interface corresponds to the element. extension type SVGFEDiffuseLightingElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEDiffuseLightingElement] using the tag + /// 'feDiffuseLighting'. + SVGFEDiffuseLightingElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feDiffuseLighting', + ); + external SVGAnimatedString get in1; external SVGAnimatedNumber get surfaceScale; external SVGAnimatedNumber get diffuseConstant; @@ -189,6 +269,13 @@ extension type SVGFEDiffuseLightingElement._(JSObject _) /// The **`SVGFEDistantLightElement`** interface corresponds to the element. extension type SVGFEDistantLightElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEDistantLightElement] using the tag 'feDistantLight'. + SVGFEDistantLightElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feDistantLight', + ); + external SVGAnimatedNumber get azimuth; external SVGAnimatedNumber get elevation; } @@ -196,6 +283,13 @@ extension type SVGFEDistantLightElement._(JSObject _) /// The **`SVGFEPointLightElement`** interface corresponds to the element. extension type SVGFEPointLightElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEPointLightElement] using the tag 'fePointLight'. + SVGFEPointLightElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'fePointLight', + ); + external SVGAnimatedNumber get x; external SVGAnimatedNumber get y; external SVGAnimatedNumber get z; @@ -204,6 +298,13 @@ extension type SVGFEPointLightElement._(JSObject _) /// The **`SVGFESpotLightElement`** interface corresponds to the element. extension type SVGFESpotLightElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFESpotLightElement] using the tag 'feSpotLight'. + SVGFESpotLightElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feSpotLight', + ); + external SVGAnimatedNumber get x; external SVGAnimatedNumber get y; external SVGAnimatedNumber get z; @@ -217,6 +318,14 @@ extension type SVGFESpotLightElement._(JSObject _) /// The **`SVGFEDisplacementMapElement`** interface corresponds to the element. extension type SVGFEDisplacementMapElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEDisplacementMapElement] using the tag + /// 'feDisplacementMap'. + SVGFEDisplacementMapElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feDisplacementMap', + ); + external static int get SVG_CHANNEL_UNKNOWN; external static int get SVG_CHANNEL_R; external static int get SVG_CHANNEL_G; @@ -237,6 +346,13 @@ extension type SVGFEDisplacementMapElement._(JSObject _) /// The **`SVGFEDropShadowElement`** interface corresponds to the element. extension type SVGFEDropShadowElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEDropShadowElement] using the tag 'feDropShadow'. + SVGFEDropShadowElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feDropShadow', + ); + external void setStdDeviation( num stdDeviationX, num stdDeviationY, @@ -255,6 +371,13 @@ extension type SVGFEDropShadowElement._(JSObject _) /// The **`SVGFEFloodElement`** interface corresponds to the element. extension type SVGFEFloodElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEFloodElement] using the tag 'feFlood'. + SVGFEFloodElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feFlood', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -265,6 +388,13 @@ extension type SVGFEFloodElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFEGaussianBlurElement`** interface corresponds to the element. extension type SVGFEGaussianBlurElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEGaussianBlurElement] using the tag 'feGaussianBlur'. + SVGFEGaussianBlurElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feGaussianBlur', + ); + external static int get SVG_EDGEMODE_UNKNOWN; external static int get SVG_EDGEMODE_DUPLICATE; external static int get SVG_EDGEMODE_WRAP; @@ -286,6 +416,13 @@ extension type SVGFEGaussianBlurElement._(JSObject _) /// The **`SVGFEImageElement`** interface corresponds to the element. extension type SVGFEImageElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEImageElement] using the tag 'feImage'. + SVGFEImageElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feImage', + ); + external SVGAnimatedPreserveAspectRatio get preserveAspectRatio; external SVGAnimatedString get crossOrigin; external SVGAnimatedLength get x; @@ -298,6 +435,13 @@ extension type SVGFEImageElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFEMergeElement`** interface corresponds to the element. extension type SVGFEMergeElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEMergeElement] using the tag 'feMerge'. + SVGFEMergeElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feMerge', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -308,12 +452,26 @@ extension type SVGFEMergeElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFEMergeNodeElement`** interface corresponds to the element. extension type SVGFEMergeNodeElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEMergeNodeElement] using the tag 'feMergeNode'. + SVGFEMergeNodeElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feMergeNode', + ); + external SVGAnimatedString get in1; } /// The **`SVGFEMorphologyElement`** interface corresponds to the element. extension type SVGFEMorphologyElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEMorphologyElement] using the tag 'feMorphology'. + SVGFEMorphologyElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feMorphology', + ); + external static int get SVG_MORPHOLOGY_OPERATOR_UNKNOWN; external static int get SVG_MORPHOLOGY_OPERATOR_ERODE; external static int get SVG_MORPHOLOGY_OPERATOR_DILATE; @@ -331,6 +489,13 @@ extension type SVGFEMorphologyElement._(JSObject _) /// The **`SVGFEOffsetElement`** interface corresponds to the element. extension type SVGFEOffsetElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFEOffsetElement] using the tag 'feOffset'. + SVGFEOffsetElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feOffset', + ); + external SVGAnimatedString get in1; external SVGAnimatedNumber get dx; external SVGAnimatedNumber get dy; @@ -345,6 +510,14 @@ extension type SVGFEOffsetElement._(JSObject _) /// element. extension type SVGFESpecularLightingElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFESpecularLightingElement] using the tag + /// 'feSpecularLighting'. + SVGFESpecularLightingElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feSpecularLighting', + ); + external SVGAnimatedString get in1; external SVGAnimatedNumber get surfaceScale; external SVGAnimatedNumber get specularConstant; @@ -360,6 +533,13 @@ extension type SVGFESpecularLightingElement._(JSObject _) /// The **`SVGFETileElement`** interface corresponds to the element. extension type SVGFETileElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFETileElement] using the tag 'feTile'. + SVGFETileElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feTile', + ); + external SVGAnimatedString get in1; external SVGAnimatedLength get x; external SVGAnimatedLength get y; @@ -371,6 +551,13 @@ extension type SVGFETileElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGFETurbulenceElement`** interface corresponds to the element. extension type SVGFETurbulenceElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGFETurbulenceElement] using the tag 'feTurbulence'. + SVGFETurbulenceElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'feTurbulence', + ); + external static int get SVG_TURBULENCE_TYPE_UNKNOWN; external static int get SVG_TURBULENCE_TYPE_FRACTALNOISE; external static int get SVG_TURBULENCE_TYPE_TURBULENCE; diff --git a/lib/src/dom/html.dart b/lib/src/dom/html.dart index 98a56997..71d36a71 100644 --- a/lib/src/dom/html.dart +++ b/lib/src/dom/html.dart @@ -199,7 +199,161 @@ extension type DOMStringList._(JSObject _) implements JSObject { /// elements directly implement this interface, while others implement it via an /// interface that inherits it. extension type HTMLElement._(JSObject _) implements Element, JSObject { - external factory HTMLElement(); + /// Creates an [HTMLElement] using the tag 'article'. + HTMLElement.article() : _ = document.createElement('article'); + + /// Creates an [HTMLElement] using the tag 'section'. + HTMLElement.section() : _ = document.createElement('section'); + + /// Creates an [HTMLElement] using the tag 'nav'. + HTMLElement.nav() : _ = document.createElement('nav'); + + /// Creates an [HTMLElement] using the tag 'aside'. + HTMLElement.aside() : _ = document.createElement('aside'); + + /// Creates an [HTMLElement] using the tag 'hgroup'. + HTMLElement.hgroup() : _ = document.createElement('hgroup'); + + /// Creates an [HTMLElement] using the tag 'header'. + HTMLElement.header() : _ = document.createElement('header'); + + /// Creates an [HTMLElement] using the tag 'footer'. + HTMLElement.footer() : _ = document.createElement('footer'); + + /// Creates an [HTMLElement] using the tag 'address'. + HTMLElement.address() : _ = document.createElement('address'); + + /// Creates an [HTMLElement] using the tag 'dt'. + HTMLElement.dt() : _ = document.createElement('dt'); + + /// Creates an [HTMLElement] using the tag 'dd'. + HTMLElement.dd() : _ = document.createElement('dd'); + + /// Creates an [HTMLElement] using the tag 'figure'. + HTMLElement.figure() : _ = document.createElement('figure'); + + /// Creates an [HTMLElement] using the tag 'figcaption'. + HTMLElement.figcaption() : _ = document.createElement('figcaption'); + + /// Creates an [HTMLElement] using the tag 'main'. + HTMLElement.main() : _ = document.createElement('main'); + + /// Creates an [HTMLElement] using the tag 'search'. + HTMLElement.search() : _ = document.createElement('search'); + + /// Creates an [HTMLElement] using the tag 'em'. + HTMLElement.em() : _ = document.createElement('em'); + + /// Creates an [HTMLElement] using the tag 'strong'. + HTMLElement.strong() : _ = document.createElement('strong'); + + /// Creates an [HTMLElement] using the tag 'small'. + HTMLElement.small() : _ = document.createElement('small'); + + /// Creates an [HTMLElement] using the tag 's'. + HTMLElement.s() : _ = document.createElement('s'); + + /// Creates an [HTMLElement] using the tag 'cite'. + HTMLElement.cite() : _ = document.createElement('cite'); + + /// Creates an [HTMLElement] using the tag 'dfn'. + HTMLElement.dfn() : _ = document.createElement('dfn'); + + /// Creates an [HTMLElement] using the tag 'abbr'. + HTMLElement.abbr() : _ = document.createElement('abbr'); + + /// Creates an [HTMLElement] using the tag 'ruby'. + HTMLElement.ruby() : _ = document.createElement('ruby'); + + /// Creates an [HTMLElement] using the tag 'rt'. + HTMLElement.rt() : _ = document.createElement('rt'); + + /// Creates an [HTMLElement] using the tag 'rp'. + HTMLElement.rp() : _ = document.createElement('rp'); + + /// Creates an [HTMLElement] using the tag 'code'. + HTMLElement.code() : _ = document.createElement('code'); + + /// Creates an [HTMLElement] using the tag 'var'. + HTMLElement.var_() : _ = document.createElement('var'); + + /// Creates an [HTMLElement] using the tag 'samp'. + HTMLElement.samp() : _ = document.createElement('samp'); + + /// Creates an [HTMLElement] using the tag 'kbd'. + HTMLElement.kbd() : _ = document.createElement('kbd'); + + /// Creates an [HTMLElement] using the tag 'sub'. + HTMLElement.sub() : _ = document.createElement('sub'); + + /// Creates an [HTMLElement] using the tag 'sup'. + HTMLElement.sup() : _ = document.createElement('sup'); + + /// Creates an [HTMLElement] using the tag 'i'. + HTMLElement.i() : _ = document.createElement('i'); + + /// Creates an [HTMLElement] using the tag 'b'. + HTMLElement.b() : _ = document.createElement('b'); + + /// Creates an [HTMLElement] using the tag 'u'. + HTMLElement.u() : _ = document.createElement('u'); + + /// Creates an [HTMLElement] using the tag 'mark'. + HTMLElement.mark() : _ = document.createElement('mark'); + + /// Creates an [HTMLElement] using the tag 'bdi'. + HTMLElement.bdi() : _ = document.createElement('bdi'); + + /// Creates an [HTMLElement] using the tag 'bdo'. + HTMLElement.bdo() : _ = document.createElement('bdo'); + + /// Creates an [HTMLElement] using the tag 'wbr'. + HTMLElement.wbr() : _ = document.createElement('wbr'); + + /// Creates an [HTMLElement] using the tag 'summary'. + HTMLElement.summary() : _ = document.createElement('summary'); + + /// Creates an [HTMLElement] using the tag 'noscript'. + HTMLElement.noscript() : _ = document.createElement('noscript'); + + /// Creates an [HTMLElement] using the tag 'acronym'. + HTMLElement.acronym() : _ = document.createElement('acronym'); + + /// Creates an [HTMLElement] using the tag 'noframes'. + HTMLElement.noframes() : _ = document.createElement('noframes'); + + /// Creates an [HTMLElement] using the tag 'menuitem'. + HTMLElement.menuitem() : _ = document.createElement('menuitem'); + + /// Creates an [HTMLElement] using the tag 'noembed'. + HTMLElement.noembed() : _ = document.createElement('noembed'); + + /// Creates an [HTMLElement] using the tag 'plaintext'. + HTMLElement.plaintext() : _ = document.createElement('plaintext'); + + /// Creates an [HTMLElement] using the tag 'rb'. + HTMLElement.rb() : _ = document.createElement('rb'); + + /// Creates an [HTMLElement] using the tag 'rtc'. + HTMLElement.rtc() : _ = document.createElement('rtc'); + + /// Creates an [HTMLElement] using the tag 'strike'. + HTMLElement.strike() : _ = document.createElement('strike'); + + /// Creates an [HTMLElement] using the tag 'basefont'. + HTMLElement.basefont() : _ = document.createElement('basefont'); + + /// Creates an [HTMLElement] using the tag 'big'. + HTMLElement.big() : _ = document.createElement('big'); + + /// Creates an [HTMLElement] using the tag 'center'. + HTMLElement.center() : _ = document.createElement('center'); + + /// Creates an [HTMLElement] using the tag 'nobr'. + HTMLElement.nobr() : _ = document.createElement('nobr'); + + /// Creates an [HTMLElement] using the tag 'tt'. + HTMLElement.tt() : _ = document.createElement('tt'); /// The **`HTMLElement.click()`** method simulates a mouse click on /// an element. @@ -534,7 +688,31 @@ extension type HTMLElement._(JSObject _) implements Element, JSObject { /// and derives from the [HTMLElement] interface, but without implementing any /// additional properties or methods. extension type HTMLUnknownElement._(JSObject _) - implements HTMLElement, JSObject {} + implements HTMLElement, JSObject { + /// Creates an [HTMLUnknownElement] using the tag 'applet'. + HTMLUnknownElement.applet() : _ = document.createElement('applet'); + + /// Creates an [HTMLUnknownElement] using the tag 'bgsound'. + HTMLUnknownElement.bgsound() : _ = document.createElement('bgsound'); + + /// Creates an [HTMLUnknownElement] using the tag 'isindex'. + HTMLUnknownElement.isindex() : _ = document.createElement('isindex'); + + /// Creates an [HTMLUnknownElement] using the tag 'keygen'. + HTMLUnknownElement.keygen() : _ = document.createElement('keygen'); + + /// Creates an [HTMLUnknownElement] using the tag 'nextid'. + HTMLUnknownElement.nextid() : _ = document.createElement('nextid'); + + /// Creates an [HTMLUnknownElement] using the tag 'blink'. + HTMLUnknownElement.blink() : _ = document.createElement('blink'); + + /// Creates an [HTMLUnknownElement] using the tag 'multicol'. + HTMLUnknownElement.multicol() : _ = document.createElement('multicol'); + + /// Creates an [HTMLUnknownElement] using the tag 'spacer'. + HTMLUnknownElement.spacer() : _ = document.createElement('spacer'); +} /// The **`DOMStringMap`** interface is used for the [HTMLElement.dataset] /// attribute, to represent data for custom attributes added to elements. @@ -547,7 +725,8 @@ extension type DOMStringMap._(JSObject _) implements JSObject {} /// You can retrieve the `HTMLHtmlElement` object for a given document by /// reading the value of the [document.documentElement] property. extension type HTMLHtmlElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLHtmlElement(); + /// Creates an [HTMLHtmlElement] using the tag 'html'. + HTMLHtmlElement() : _ = document.createElement('html'); external set version(String value); external String get version; @@ -557,14 +736,16 @@ extension type HTMLHtmlElement._(JSObject _) implements HTMLElement, JSObject { /// metadata, for a document. This object inherits all of the properties and /// methods described in the [HTMLElement] interface. extension type HTMLHeadElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLHeadElement(); + /// Creates an [HTMLHeadElement] using the tag 'head'. + HTMLHeadElement() : _ = document.createElement('head'); } /// The **`HTMLTitleElement`** interface is implemented by a document's `title`. /// This element inherits all of the properties and methods of the [HTMLElement] /// interface. extension type HTMLTitleElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTitleElement(); + /// Creates an [HTMLTitleElement] using the tag 'title'. + HTMLTitleElement() : _ = document.createElement('title'); external set text(String value); external String get text; @@ -574,7 +755,8 @@ extension type HTMLTitleElement._(JSObject _) implements HTMLElement, JSObject { /// This object inherits all of the properties and methods as described in the /// [HTMLElement] interface. extension type HTMLBaseElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLBaseElement(); + /// Creates an [HTMLBaseElement] using the tag 'base'. + HTMLBaseElement() : _ = document.createElement('base'); external set href(String value); external String get href; @@ -591,7 +773,8 @@ extension type HTMLBaseElement._(JSObject _) implements HTMLElement, JSObject { /// This object inherits all of the properties and methods of the [HTMLElement] /// interface. extension type HTMLLinkElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLLinkElement(); + /// Creates an [HTMLLinkElement] using the tag 'link'. + HTMLLinkElement() : _ = document.createElement('link'); external set href(String value); external String get href; @@ -637,7 +820,8 @@ extension type HTMLLinkElement._(JSObject _) implements HTMLElement, JSObject { /// This interface inherits all of the properties and methods described in the /// [HTMLElement] interface. extension type HTMLMetaElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLMetaElement(); + /// Creates an [HTMLMetaElement] using the tag 'meta'. + HTMLMetaElement() : _ = document.createElement('meta'); external set name(String value); external String get name; @@ -660,7 +844,8 @@ extension type HTMLMetaElement._(JSObject _) implements HTMLElement, JSObject { /// for an overview of the objects used to manipulate specified CSS properties /// using the DOM. extension type HTMLStyleElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLStyleElement(); + /// Creates an [HTMLStyleElement] using the tag 'style'. + HTMLStyleElement() : _ = document.createElement('style'); external set disabled(bool value); external bool get disabled; @@ -676,7 +861,8 @@ extension type HTMLStyleElement._(JSObject _) implements HTMLElement, JSObject { /// those inherited from the regular [HTMLElement] interface) for manipulating /// `body` elements. extension type HTMLBodyElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLBodyElement(); + /// Creates an [HTMLBodyElement] using the tag 'body'. + HTMLBodyElement() : _ = document.createElement('body'); external set text(String value); external String get text; @@ -736,7 +922,23 @@ extension type HTMLBodyElement._(JSObject _) implements HTMLElement, JSObject { /// and properties from the [HTMLElement] interface. extension type HTMLHeadingElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLHeadingElement(); + /// Creates an [HTMLHeadingElement] using the tag 'h1'. + HTMLHeadingElement.h1() : _ = document.createElement('h1'); + + /// Creates an [HTMLHeadingElement] using the tag 'h2'. + HTMLHeadingElement.h2() : _ = document.createElement('h2'); + + /// Creates an [HTMLHeadingElement] using the tag 'h3'. + HTMLHeadingElement.h3() : _ = document.createElement('h3'); + + /// Creates an [HTMLHeadingElement] using the tag 'h4'. + HTMLHeadingElement.h4() : _ = document.createElement('h4'); + + /// Creates an [HTMLHeadingElement] using the tag 'h5'. + HTMLHeadingElement.h5() : _ = document.createElement('h5'); + + /// Creates an [HTMLHeadingElement] using the tag 'h6'. + HTMLHeadingElement.h6() : _ = document.createElement('h6'); external set align(String value); external String get align; @@ -747,7 +949,8 @@ extension type HTMLHeadingElement._(JSObject _) /// manipulating `p` elements. extension type HTMLParagraphElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLParagraphElement(); + /// Creates an [HTMLParagraphElement] using the tag 'p'. + HTMLParagraphElement() : _ = document.createElement('p'); external set align(String value); external String get align; @@ -757,7 +960,8 @@ extension type HTMLParagraphElement._(JSObject _) /// of the [HTMLElement] interface it also has available to it by inheritance) /// for manipulating `hr` elements. extension type HTMLHRElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLHRElement(); + /// Creates an [HTMLHRElement] using the tag 'hr'. + HTMLHRElement() : _ = document.createElement('hr'); external set align(String value); external String get align; @@ -775,7 +979,14 @@ extension type HTMLHRElement._(JSObject _) implements HTMLElement, JSObject { /// (beyond those of the [HTMLElement] interface it also has available to it by /// inheritance) for manipulating a block of preformatted text (`pre`). extension type HTMLPreElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLPreElement(); + /// Creates an [HTMLPreElement] using the tag 'pre'. + HTMLPreElement.pre() : _ = document.createElement('pre'); + + /// Creates an [HTMLPreElement] using the tag 'listing'. + HTMLPreElement.listing() : _ = document.createElement('listing'); + + /// Creates an [HTMLPreElement] using the tag 'xmp'. + HTMLPreElement.xmp() : _ = document.createElement('xmp'); external set width(int value); external int get width; @@ -786,7 +997,11 @@ extension type HTMLPreElement._(JSObject _) implements HTMLElement, JSObject { /// inheritance) for manipulating quoting elements, like `blockquote` and `q`, /// but not the `cite` element. extension type HTMLQuoteElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLQuoteElement(); + /// Creates an [HTMLQuoteElement] using the tag 'blockquote'. + HTMLQuoteElement.blockquote() : _ = document.createElement('blockquote'); + + /// Creates an [HTMLQuoteElement] using the tag 'q'. + HTMLQuoteElement.q() : _ = document.createElement('q'); external set cite(String value); external String get cite; @@ -796,7 +1011,8 @@ extension type HTMLQuoteElement._(JSObject _) implements HTMLElement, JSObject { /// those defined on the regular [HTMLElement] interface it also has available /// to it by inheritance) for manipulating ordered list elements. extension type HTMLOListElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLOListElement(); + /// Creates an [HTMLOListElement] using the tag 'ol'. + HTMLOListElement() : _ = document.createElement('ol'); external set reversed(bool value); external bool get reversed; @@ -812,7 +1028,8 @@ extension type HTMLOListElement._(JSObject _) implements HTMLElement, JSObject { /// those defined on the regular [HTMLElement] interface it also has available /// to it by inheritance) for manipulating unordered list (`ul`) elements. extension type HTMLUListElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLUListElement(); + /// Creates an [HTMLUListElement] using the tag 'ul'. + HTMLUListElement() : _ = document.createElement('ul'); external set compact(bool value); external bool get compact; @@ -825,7 +1042,8 @@ extension type HTMLUListElement._(JSObject _) implements HTMLElement, JSObject { /// element. /// `` is a semantic alternative to the `ul` element. extension type HTMLMenuElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLMenuElement(); + /// Creates an [HTMLMenuElement] using the tag 'menu'. + HTMLMenuElement() : _ = document.createElement('menu'); external set compact(bool value); external bool get compact; @@ -835,7 +1053,8 @@ extension type HTMLMenuElement._(JSObject _) implements HTMLElement, JSObject { /// (beyond those defined by regular [HTMLElement] interface it also has /// available to it by inheritance) for manipulating list elements. extension type HTMLLIElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLLIElement(); + /// Creates an [HTMLLIElement] using the tag 'li'. + HTMLLIElement() : _ = document.createElement('li'); external set value(int value); external int get value; @@ -847,7 +1066,8 @@ extension type HTMLLIElement._(JSObject _) implements HTMLElement, JSObject { /// those of the regular [HTMLElement] interface it also has available to it by /// inheritance) for manipulating definition list (`dl`) elements. extension type HTMLDListElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDListElement(); + /// Creates an [HTMLDListElement] using the tag 'dl'. + HTMLDListElement() : _ = document.createElement('dl'); external set compact(bool value); external bool get compact; @@ -857,7 +1077,8 @@ extension type HTMLDListElement._(JSObject _) implements HTMLElement, JSObject { /// regular [HTMLElement] interface it also has available to it by inheritance) /// for manipulating `div` elements. extension type HTMLDivElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDivElement(); + /// Creates an [HTMLDivElement] using the tag 'div'. + HTMLDivElement() : _ = document.createElement('div'); external set align(String value); external String get align; @@ -872,7 +1093,8 @@ extension type HTMLDivElement._(JSObject _) implements HTMLElement, JSObject { /// [`HTMLLinkElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement). extension type HTMLAnchorElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLAnchorElement(); + /// Creates an [HTMLAnchorElement] using the tag 'a'. + HTMLAnchorElement() : _ = document.createElement('a'); external set target(String value); external String get target; @@ -928,7 +1150,8 @@ extension type HTMLAnchorElement._(JSObject _) /// regular [HTMLElement] interface it also has available to it by inheritance) /// for manipulating `data` elements. extension type HTMLDataElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDataElement(); + /// Creates an [HTMLDataElement] using the tag 'data'. + HTMLDataElement() : _ = document.createElement('data'); external set value(String value); external String get value; @@ -938,7 +1161,8 @@ extension type HTMLDataElement._(JSObject _) implements HTMLElement, JSObject { /// regular [HTMLElement] interface it also has available to it by inheritance) /// for manipulating `time` elements. extension type HTMLTimeElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTimeElement(); + /// Creates an [HTMLTimeElement] using the tag 'time'. + HTMLTimeElement() : _ = document.createElement('time'); external set dateTime(String value); external String get dateTime; @@ -948,13 +1172,15 @@ extension type HTMLTimeElement._(JSObject _) implements HTMLElement, JSObject { /// from the [HTMLElement] interface, but without implementing any additional /// properties or methods. extension type HTMLSpanElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLSpanElement(); + /// Creates an [HTMLSpanElement] using the tag 'span'. + HTMLSpanElement() : _ = document.createElement('span'); } /// The **`HTMLBRElement`** interface represents an HTML line break element /// (`br`). It inherits from [HTMLElement]. extension type HTMLBRElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLBRElement(); + /// Creates an [HTMLBRElement] using the tag 'br'. + HTMLBRElement() : _ = document.createElement('br'); external set clear(String value); external String get clear; @@ -965,7 +1191,11 @@ extension type HTMLBRElement._(JSObject _) implements HTMLElement, JSObject { /// they also have available to them by inheritance) for manipulating /// modification elements, that is `del` and `ins`. extension type HTMLModElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLModElement(); + /// Creates an [HTMLModElement] using the tag 'ins'. + HTMLModElement.ins() : _ = document.createElement('ins'); + + /// Creates an [HTMLModElement] using the tag 'del'. + HTMLModElement.del() : _ = document.createElement('del'); external set cite(String value); external String get cite; @@ -977,7 +1207,8 @@ extension type HTMLModElement._(JSObject _) implements HTMLElement, JSObject { /// It doesn't implement specific properties or methods. extension type HTMLPictureElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLPictureElement(); + /// Creates an [HTMLPictureElement] using the tag 'picture'. + HTMLPictureElement() : _ = document.createElement('picture'); } /// The **`HTMLSourceElement`** interface provides special properties (beyond @@ -985,7 +1216,8 @@ extension type HTMLPictureElement._(JSObject _) /// inheritance) for manipulating `source` elements. extension type HTMLSourceElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLSourceElement(); + /// Creates an [HTMLSourceElement] using the tag 'source'. + HTMLSourceElement() : _ = document.createElement('source'); external set src(String value); external String get src; @@ -1006,7 +1238,8 @@ extension type HTMLSourceElement._(JSObject _) /// The **`HTMLImageElement`** interface represents an HTML `img` element, /// providing the properties and methods used to manipulate image elements. extension type HTMLImageElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLImageElement(); + /// Creates an [HTMLImageElement] using the tag 'img'. + HTMLImageElement() : _ = document.createElement('img'); /// The **`decode()`** /// method of the [HTMLImageElement] interface returns a @@ -1076,7 +1309,8 @@ extension type HTMLImageElement._(JSObject _) implements HTMLElement, JSObject { /// frame elements. extension type HTMLIFrameElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLIFrameElement(); + /// Creates an [HTMLIFrameElement] using the tag 'iframe'. + HTMLIFrameElement() : _ = document.createElement('iframe'); external Document? getSVGDocument(); external set src(String value); @@ -1122,7 +1356,8 @@ extension type HTMLIFrameElement._(JSObject _) /// > in the standard. It does not address earlier, non-standardized version of /// > the interface. extension type HTMLEmbedElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLEmbedElement(); + /// Creates an [HTMLEmbedElement] using the tag 'embed'. + HTMLEmbedElement() : _ = document.createElement('embed'); external Document? getSVGDocument(); external set src(String value); @@ -1145,7 +1380,8 @@ extension type HTMLEmbedElement._(JSObject _) implements HTMLElement, JSObject { /// `object` element, representing external resources. extension type HTMLObjectElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLObjectElement(); + /// Creates an [HTMLObjectElement] using the tag 'object'. + HTMLObjectElement() : _ = document.createElement('object'); external Document? getSVGDocument(); @@ -1213,7 +1449,8 @@ extension type HTMLObjectElement._(JSObject _) /// need to support are covered. extension type HTMLVideoElement._(JSObject _) implements HTMLMediaElement, JSObject { - external factory HTMLVideoElement(); + /// Creates an [HTMLVideoElement] using the tag 'video'. + HTMLVideoElement() : _ = document.createElement('video'); /// The **[HTMLVideoElement]** method /// **`getVideoPlaybackQuality()`** creates and returns a @@ -1241,7 +1478,8 @@ extension type HTMLVideoElement._(JSObject _) /// [HTMLMediaElement] interface. extension type HTMLAudioElement._(JSObject _) implements HTMLMediaElement, JSObject { - external factory HTMLAudioElement(); + /// Creates an [HTMLAudioElement] using the tag 'audio'. + HTMLAudioElement() : _ = document.createElement('audio'); } /// The **`HTMLTrackElement`** interface represents an `track` element within @@ -1249,7 +1487,8 @@ extension type HTMLAudioElement._(JSObject _) /// specify a text track containing information such as closed captions or /// subtitles. extension type HTMLTrackElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTrackElement(); + /// Creates an [HTMLTrackElement] using the tag 'track'. + HTMLTrackElement() : _ = document.createElement('track'); external static int get NONE; external static int get LOADING; @@ -1642,7 +1881,8 @@ extension type TrackEventInit._(JSObject _) implements EventInit, JSObject { /// available to it by inheritance) for manipulating the layout and presentation /// of map elements. extension type HTMLMapElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLMapElement(); + /// Creates an [HTMLMapElement] using the tag 'map'. + HTMLMapElement() : _ = document.createElement('map'); external set name(String value); external String get name; @@ -1654,7 +1894,8 @@ extension type HTMLMapElement._(JSObject _) implements HTMLElement, JSObject { /// available to it by inheritance) for manipulating the layout and presentation /// of `area` elements. extension type HTMLAreaElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLAreaElement(); + /// Creates an [HTMLAreaElement] using the tag 'area'. + HTMLAreaElement() : _ = document.createElement('area'); external set alt(String value); external String get alt; @@ -1703,7 +1944,8 @@ extension type HTMLAreaElement._(JSObject _) implements HTMLElement, JSObject { /// it by inheritance) for manipulating the layout and presentation of tables in /// an HTML document. extension type HTMLTableElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableElement(); + /// Creates an [HTMLTableElement] using the tag 'table'. + HTMLTableElement() : _ = document.createElement('table'); /// The **`HTMLTableElement.createCaption()`** method returns the /// `caption` element associated with a given `table`. @@ -1823,7 +2065,8 @@ extension type HTMLTableElement._(JSObject _) implements HTMLElement, JSObject { /// inheritance) for manipulating table `caption` elements. extension type HTMLTableCaptionElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableCaptionElement(); + /// Creates an [HTMLTableCaptionElement] using the tag 'caption'. + HTMLTableCaptionElement() : _ = document.createElement('caption'); external set align(String value); external String get align; @@ -1833,7 +2076,11 @@ extension type HTMLTableCaptionElement._(JSObject _) /// single or grouped table column elements. extension type HTMLTableColElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableColElement(); + /// Creates an [HTMLTableColElement] using the tag 'colgroup'. + HTMLTableColElement.colgroup() : _ = document.createElement('colgroup'); + + /// Creates an [HTMLTableColElement] using the tag 'col'. + HTMLTableColElement.col() : _ = document.createElement('col'); external set span(int value); external int get span; @@ -1856,7 +2103,14 @@ extension type HTMLTableColElement._(JSObject _) /// in an HTML table. extension type HTMLTableSectionElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableSectionElement(); + /// Creates an [HTMLTableSectionElement] using the tag 'tbody'. + HTMLTableSectionElement.tbody() : _ = document.createElement('tbody'); + + /// Creates an [HTMLTableSectionElement] using the tag 'thead'. + HTMLTableSectionElement.thead() : _ = document.createElement('thead'); + + /// Creates an [HTMLTableSectionElement] using the tag 'tfoot'. + HTMLTableSectionElement.tfoot() : _ = document.createElement('tfoot'); external HTMLTableRowElement insertRow([int index]); external void deleteRow(int index); @@ -1877,7 +2131,8 @@ extension type HTMLTableSectionElement._(JSObject _) /// table. extension type HTMLTableRowElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableRowElement(); + /// Creates an [HTMLTableRowElement] using the tag 'tr'. + HTMLTableRowElement() : _ = document.createElement('tr'); /// The **`HTMLTableRowElement.insertCell()`** method inserts a new /// cell (`td`) into a table row (`tr`) and returns a @@ -1915,7 +2170,11 @@ extension type HTMLTableRowElement._(JSObject _) /// document. extension type HTMLTableCellElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTableCellElement(); + /// Creates an [HTMLTableCellElement] using the tag 'td'. + HTMLTableCellElement.td() : _ = document.createElement('td'); + + /// Creates an [HTMLTableCellElement] using the tag 'th'. + HTMLTableCellElement.th() : _ = document.createElement('th'); external set colSpan(int value); external int get colSpan; @@ -1952,7 +2211,8 @@ extension type HTMLTableCellElement._(JSObject _) /// It allows access to—and, in some cases, modification of—aspects of the form, /// as well as access to its component elements. extension type HTMLFormElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLFormElement(); + /// Creates an [HTMLFormElement] using the tag 'form'. + HTMLFormElement() : _ = document.createElement('form'); /// The **`HTMLFormElement.submit()`** method submits a given /// `form`. @@ -2039,7 +2299,8 @@ extension type HTMLFormElement._(JSObject _) implements HTMLElement, JSObject { /// `label` elements. It inherits methods and properties from the base /// [HTMLElement] interface. extension type HTMLLabelElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLLabelElement(); + /// Creates an [HTMLLabelElement] using the tag 'label'. + HTMLLabelElement() : _ = document.createElement('label'); external HTMLFormElement? get form; external set htmlFor(String value); @@ -2050,7 +2311,8 @@ extension type HTMLLabelElement._(JSObject _) implements HTMLElement, JSObject { /// The **`HTMLInputElement`** interface provides special properties and methods /// for manipulating the options, layout, and presentation of `input` elements. extension type HTMLInputElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLInputElement(); + /// Creates an [HTMLInputElement] using the tag 'input'. + HTMLInputElement() : _ = document.createElement('input'); /// The **`HTMLInputElement.stepUp()`** method increments the value /// of a numeric type of `input` element by the value of the @@ -2463,7 +2725,8 @@ extension type HTMLInputElement._(JSObject _) implements HTMLElement, JSObject { /// inheritance) for manipulating `button` elements. extension type HTMLButtonElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLButtonElement(); + /// Creates an [HTMLButtonElement] using the tag 'button'. + HTMLButtonElement() : _ = document.createElement('button'); external bool checkValidity(); external bool reportValidity(); @@ -2502,7 +2765,8 @@ extension type HTMLButtonElement._(JSObject _) /// elements via the [HTMLElement] interface. extension type HTMLSelectElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLSelectElement(); + /// Creates an [HTMLSelectElement] using the tag 'select'. + HTMLSelectElement() : _ = document.createElement('select'); /// The **`HTMLSelectElement.item()`** method returns the /// [Element] corresponding to the [HTMLOptionElement] whose @@ -2594,7 +2858,8 @@ extension type HTMLSelectElement._(JSObject _) /// inheritance) to manipulate `datalist` elements and their content. extension type HTMLDataListElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDataListElement(); + /// Creates an [HTMLDataListElement] using the tag 'datalist'. + HTMLDataListElement() : _ = document.createElement('datalist'); external HTMLCollection get options; } @@ -2605,7 +2870,8 @@ extension type HTMLDataListElement._(JSObject _) /// presentation of `optgroup` elements. extension type HTMLOptGroupElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLOptGroupElement(); + /// Creates an [HTMLOptGroupElement] using the tag 'optgroup'. + HTMLOptGroupElement() : _ = document.createElement('optgroup'); external set disabled(bool value); external bool get disabled; @@ -2617,7 +2883,8 @@ extension type HTMLOptGroupElement._(JSObject _) /// inherits all properties and methods of the [HTMLElement] interface. extension type HTMLOptionElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLOptionElement(); + /// Creates an [HTMLOptionElement] using the tag 'option'. + HTMLOptionElement() : _ = document.createElement('option'); external set disabled(bool value); external bool get disabled; @@ -2639,7 +2906,8 @@ extension type HTMLOptionElement._(JSObject _) /// methods for manipulating the layout and presentation of `textarea` elements. extension type HTMLTextAreaElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTextAreaElement(); + /// Creates an [HTMLTextAreaElement] using the tag 'textarea'. + HTMLTextAreaElement() : _ = document.createElement('textarea'); external bool checkValidity(); external bool reportValidity(); @@ -2704,7 +2972,8 @@ extension type HTMLTextAreaElement._(JSObject _) /// presentation of `output` elements. extension type HTMLOutputElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLOutputElement(); + /// Creates an [HTMLOutputElement] using the tag 'output'. + HTMLOutputElement() : _ = document.createElement('output'); external bool checkValidity(); external bool reportValidity(); @@ -2730,7 +2999,8 @@ extension type HTMLOutputElement._(JSObject _) /// `progress` elements. extension type HTMLProgressElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLProgressElement(); + /// Creates an [HTMLProgressElement] using the tag 'progress'. + HTMLProgressElement() : _ = document.createElement('progress'); external set value(num value); external num get value; @@ -2745,7 +3015,8 @@ extension type HTMLProgressElement._(JSObject _) /// interface they also have available to them by inheritance) for manipulating /// the layout and presentation of `meter` elements. extension type HTMLMeterElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLMeterElement(); + /// Creates an [HTMLMeterElement] using the tag 'meter'. + HTMLMeterElement() : _ = document.createElement('meter'); external set value(num value); external num get value; @@ -2768,7 +3039,8 @@ extension type HTMLMeterElement._(JSObject _) implements HTMLElement, JSObject { /// `fieldset` elements. extension type HTMLFieldSetElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLFieldSetElement(); + /// Creates an [HTMLFieldSetElement] using the tag 'fieldset'. + HTMLFieldSetElement() : _ = document.createElement('fieldset'); external bool checkValidity(); external bool reportValidity(); @@ -2790,7 +3062,8 @@ extension type HTMLFieldSetElement._(JSObject _) /// [HTMLElement] interface. extension type HTMLLegendElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLLegendElement(); + /// Creates an [HTMLLegendElement] using the tag 'legend'. + HTMLLegendElement() : _ = document.createElement('legend'); external HTMLFormElement? get form; external set align(String value); @@ -2863,7 +3136,8 @@ extension type FormDataEventInit._(JSObject _) implements EventInit, JSObject { /// inheritance) for manipulating `details` elements. extension type HTMLDetailsElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDetailsElement(); + /// Creates an [HTMLDetailsElement] using the tag 'details'. + HTMLDetailsElement() : _ = document.createElement('details'); external set name(String value); external String get name; @@ -2876,7 +3150,8 @@ extension type HTMLDetailsElement._(JSObject _) /// interface. extension type HTMLDialogElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDialogElement(); + /// Creates an [HTMLDialogElement] using the tag 'dialog'. + HTMLDialogElement() : _ = document.createElement('dialog'); /// The **`show()`** method of the [HTMLDialogElement] /// interface displays the dialog modelessly, i.e. still allowing interaction @@ -2917,7 +3192,8 @@ extension type HTMLDialogElement._(JSObject _) /// [Window/load_event] event. extension type HTMLScriptElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLScriptElement(); + /// Creates an [HTMLScriptElement] using the tag 'script'. + HTMLScriptElement() : _ = document.createElement('script'); external static bool supports(String type); external set src(String value); @@ -2953,7 +3229,8 @@ extension type HTMLScriptElement._(JSObject _) /// HTML `template` element. extension type HTMLTemplateElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLTemplateElement(); + /// Creates an [HTMLTemplateElement] using the tag 'template'. + HTMLTemplateElement() : _ = document.createElement('template'); external DocumentFragment get content; external set shadowRootMode(String value); @@ -2966,7 +3243,8 @@ extension type HTMLTemplateElement._(JSObject _) /// [Shadow DOM API](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) /// enables access to the name and assigned nodes of an HTML `slot` element. extension type HTMLSlotElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLSlotElement(); + /// Creates an [HTMLSlotElement] using the tag 'slot'. + HTMLSlotElement() : _ = document.createElement('slot'); /// The **`assignedNodes()`** method of the [HTMLSlotElement] interface /// returns a sequence of the nodes assigned to this slot. @@ -3014,7 +3292,8 @@ extension type AssignedNodesOptions._(JSObject _) implements JSObject { /// the [HTMLElement] interface. extension type HTMLCanvasElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLCanvasElement(); + /// Creates an [HTMLCanvasElement] using the tag 'canvas'. + HTMLCanvasElement() : _ = document.createElement('canvas'); /// The /// **`HTMLCanvasElement.getContext()`** method returns a drawing @@ -7064,7 +7343,8 @@ extension type StorageEventInit._(JSObject _) implements EventInit, JSObject { /// It inherits properties and methods from the [HTMLElement] interface. extension type HTMLMarqueeElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLMarqueeElement(); + /// Creates an [HTMLMarqueeElement] using the tag 'marquee'. + HTMLMarqueeElement() : _ = document.createElement('marquee'); external void start(); external void stop(); @@ -7097,7 +7377,8 @@ extension type HTMLMarqueeElement._(JSObject _) /// manipulating `frameset` elements. extension type HTMLFrameSetElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLFrameSetElement(); + /// Creates an [HTMLFrameSetElement] using the tag 'frameset'. + HTMLFrameSetElement() : _ = document.createElement('frameset'); external set cols(String value); external String get cols; @@ -7143,7 +7424,8 @@ extension type HTMLFrameSetElement._(JSObject _) external EventHandler get onunload; } extension type HTMLFrameElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLFrameElement(); + /// Creates an [HTMLFrameElement] using the tag 'frame'. + HTMLFrameElement() : _ = document.createElement('frame'); external set name(String value); external String get name; @@ -7166,7 +7448,8 @@ extension type HTMLFrameElement._(JSObject _) implements HTMLElement, JSObject { } extension type HTMLDirectoryElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLDirectoryElement(); + /// Creates an [HTMLDirectoryElement] using the tag 'dir'. + HTMLDirectoryElement() : _ = document.createElement('dir'); external set compact(bool value); external bool get compact; @@ -7176,7 +7459,8 @@ extension type HTMLDirectoryElement._(JSObject _) /// element. The HTML Font Element `font` defines the font size, font face and /// color of text. extension type HTMLFontElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLFontElement(); + /// Creates an [HTMLFontElement] using the tag 'font'. + HTMLFontElement() : _ = document.createElement('font'); external set color(String value); external String get color; @@ -7191,7 +7475,8 @@ extension type HTMLFontElement._(JSObject _) implements HTMLElement, JSObject { /// manipulating `param` elements, representing a pair of a key and a value that /// acts as a parameter for an `object` element. extension type HTMLParamElement._(JSObject _) implements HTMLElement, JSObject { - external factory HTMLParamElement(); + /// Creates an [HTMLParamElement] using the tag 'param'. + HTMLParamElement() : _ = document.createElement('param'); external set name(String value); external String get name; diff --git a/lib/src/dom/mathml_core.dart b/lib/src/dom/mathml_core.dart index 2320fa35..ca3f6566 100644 --- a/lib/src/dom/mathml_core.dart +++ b/lib/src/dom/mathml_core.dart @@ -21,6 +21,216 @@ import 'html.dart'; /// The **`MathMLElement`** interface represents any /// [MathML](https://developer.mozilla.org/en-US/docs/Web/MathML) element. extension type MathMLElement._(JSObject _) implements Element, JSObject { + /// Creates a [MathMLElement] using the tag 'math'. + MathMLElement.math() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'math', + ); + + /// Creates a [MathMLElement] using the tag 'mtext'. + MathMLElement.mtext() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mtext', + ); + + /// Creates a [MathMLElement] using the tag 'mi'. + MathMLElement.mi() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mi', + ); + + /// Creates a [MathMLElement] using the tag 'mn'. + MathMLElement.mn() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mn', + ); + + /// Creates a [MathMLElement] using the tag 'mo'. + MathMLElement.mo() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mo', + ); + + /// Creates a [MathMLElement] using the tag 'mspace'. + MathMLElement.mspace() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mspace', + ); + + /// Creates a [MathMLElement] using the tag 'ms'. + MathMLElement.ms() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'ms', + ); + + /// Creates a [MathMLElement] using the tag 'mrow'. + MathMLElement.mrow() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mrow', + ); + + /// Creates a [MathMLElement] using the tag 'mfrac'. + MathMLElement.mfrac() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mfrac', + ); + + /// Creates a [MathMLElement] using the tag 'msqrt'. + MathMLElement.msqrt() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'msqrt', + ); + + /// Creates a [MathMLElement] using the tag 'mroot'. + MathMLElement.mroot() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mroot', + ); + + /// Creates a [MathMLElement] using the tag 'mstyle'. + MathMLElement.mstyle() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mstyle', + ); + + /// Creates a [MathMLElement] using the tag 'merror'. + MathMLElement.merror() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'merror', + ); + + /// Creates a [MathMLElement] using the tag 'mpadded'. + MathMLElement.mpadded() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mpadded', + ); + + /// Creates a [MathMLElement] using the tag 'mphantom'. + MathMLElement.mphantom() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mphantom', + ); + + /// Creates a [MathMLElement] using the tag 'msub'. + MathMLElement.msub() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'msub', + ); + + /// Creates a [MathMLElement] using the tag 'msup'. + MathMLElement.msup() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'msup', + ); + + /// Creates a [MathMLElement] using the tag 'msubsup'. + MathMLElement.msubsup() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'msubsup', + ); + + /// Creates a [MathMLElement] using the tag 'munder'. + MathMLElement.munder() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'munder', + ); + + /// Creates a [MathMLElement] using the tag 'mover'. + MathMLElement.mover() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mover', + ); + + /// Creates a [MathMLElement] using the tag 'munderover'. + MathMLElement.munderover() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'munderover', + ); + + /// Creates a [MathMLElement] using the tag 'mmultiscripts'. + MathMLElement.mmultiscripts() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mmultiscripts', + ); + + /// Creates a [MathMLElement] using the tag 'mprescripts'. + MathMLElement.mprescripts() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mprescripts', + ); + + /// Creates a [MathMLElement] using the tag 'mtable'. + MathMLElement.mtable() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mtable', + ); + + /// Creates a [MathMLElement] using the tag 'mtr'. + MathMLElement.mtr() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mtr', + ); + + /// Creates a [MathMLElement] using the tag 'mtd'. + MathMLElement.mtd() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'mtd', + ); + + /// Creates a [MathMLElement] using the tag 'maction'. + MathMLElement.maction() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'maction', + ); + + /// Creates a [MathMLElement] using the tag 'semantics'. + MathMLElement.semantics() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'semantics', + ); + + /// Creates a [MathMLElement] using the tag 'annotation'. + MathMLElement.annotation() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'annotation', + ); + + /// Creates a [MathMLElement] using the tag 'annotation-xml'. + MathMLElement.annotation_xml() + : _ = document.createElementNS( + 'http://www.w3.org/1998/Math/MathML', + 'annotation-xml', + ); + external void focus([FocusOptions options]); external void blur(); external StylePropertyMap get attributeStyleMap; diff --git a/lib/src/dom/svg.dart b/lib/src/dom/svg.dart index a5923447..d2dadc18 100644 --- a/lib/src/dom/svg.dart +++ b/lib/src/dom/svg.dart @@ -581,6 +581,13 @@ extension type SVGUnitTypes._(JSObject _) implements JSObject { /// devices. extension type SVGSVGElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGSVGElement] using the tag 'svg'. + SVGSVGElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'svg', + ); + external NodeList getIntersectionList( DOMRectReadOnly rect, SVGElement? referenceElement, @@ -667,25 +674,67 @@ extension type SVGSVGElement._(JSObject _) /// The **`SVGGElement`** interface corresponds to the element. extension type SVGGElement._(JSObject _) - implements SVGGraphicsElement, JSObject {} + implements SVGGraphicsElement, JSObject { + /// Creates an [SVGGElement] using the tag 'g'. + SVGGElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'g', + ); +} /// The **`SVGDefsElement`** interface corresponds to the element. extension type SVGDefsElement._(JSObject _) - implements SVGGraphicsElement, JSObject {} + implements SVGGraphicsElement, JSObject { + /// Creates an [SVGDefsElement] using the tag 'defs'. + SVGDefsElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'defs', + ); +} /// The **`SVGDescElement`** interface corresponds to the element. -extension type SVGDescElement._(JSObject _) implements SVGElement, JSObject {} +extension type SVGDescElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGDescElement] using the tag 'desc'. + SVGDescElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'desc', + ); +} /// The **`SVGMetadataElement`** interface corresponds to the element. extension type SVGMetadataElement._(JSObject _) - implements SVGElement, JSObject {} + implements SVGElement, JSObject { + /// Creates an [SVGMetadataElement] using the tag 'metadata'. + SVGMetadataElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'metadata', + ); +} /// The **`SVGTitleElement`** interface corresponds to the element. -extension type SVGTitleElement._(JSObject _) implements SVGElement, JSObject {} +extension type SVGTitleElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGTitleElement] using the tag 'title'. + SVGTitleElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'title', + ); +} /// The **`SVGSymbolElement`** interface corresponds to the element. extension type SVGSymbolElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGSymbolElement] using the tag 'symbol'. + SVGSymbolElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'symbol', + ); + external SVGAnimatedRect get viewBox; external SVGAnimatedPreserveAspectRatio get preserveAspectRatio; } @@ -693,6 +742,13 @@ extension type SVGSymbolElement._(JSObject _) /// extension type SVGUseElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGUseElement] using the tag 'use'. + SVGUseElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'use', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -714,10 +770,24 @@ extension type ShadowAnimation._(JSObject _) implements Animation, JSObject { /// The **`SVGSwitchElement`** interface corresponds to the element. extension type SVGSwitchElement._(JSObject _) - implements SVGGraphicsElement, JSObject {} + implements SVGGraphicsElement, JSObject { + /// Creates an [SVGSwitchElement] using the tag 'switch'. + SVGSwitchElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'switch', + ); +} /// The **`SVGStyleElement`** interface corresponds to the SVG element. extension type SVGStyleElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGStyleElement] using the tag 'style'. + SVGStyleElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'style', + ); + external set type(String value); external String get type; external set media(String value); @@ -820,12 +890,26 @@ extension type SVGAnimatedPreserveAspectRatio._(JSObject _) /// > `getTotalLength()` and `getPointAtLength()` methods were moved to /// > [SVGGeometryElement]. extension type SVGPathElement._(JSObject _) - implements SVGGeometryElement, JSObject {} + implements SVGGeometryElement, JSObject { + /// Creates an [SVGPathElement] using the tag 'path'. + SVGPathElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'path', + ); +} /// The `SVGRectElement` interface provides access to the properties of /// elements, as well as methods to manipulate them. extension type SVGRectElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGRectElement] using the tag 'rect'. + SVGRectElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'rect', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -837,6 +921,13 @@ extension type SVGRectElement._(JSObject _) /// The **`SVGCircleElement`** interface is an interface for the element. extension type SVGCircleElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGCircleElement] using the tag 'circle'. + SVGCircleElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'circle', + ); + external SVGAnimatedLength get cx; external SVGAnimatedLength get cy; external SVGAnimatedLength get r; @@ -846,6 +937,13 @@ extension type SVGCircleElement._(JSObject _) /// elements. extension type SVGEllipseElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGEllipseElement] using the tag 'ellipse'. + SVGEllipseElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'ellipse', + ); + external SVGAnimatedLength get cx; external SVGAnimatedLength get cy; external SVGAnimatedLength get rx; @@ -856,6 +954,13 @@ extension type SVGEllipseElement._(JSObject _) /// elements, as well as methods to manipulate them. extension type SVGLineElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGLineElement] using the tag 'line'. + SVGLineElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'line', + ); + external SVGAnimatedLength get x1; external SVGAnimatedLength get y1; external SVGAnimatedLength get x2; @@ -908,6 +1013,13 @@ extension type SVGPointList._(JSObject _) implements JSObject { /// elements, as well as methods to manipulate them. extension type SVGPolylineElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGPolylineElement] using the tag 'polyline'. + SVGPolylineElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'polyline', + ); + external SVGPointList get points; external SVGPointList get animatedPoints; } @@ -916,6 +1028,13 @@ extension type SVGPolylineElement._(JSObject _) /// elements, as well as methods to manipulate them. extension type SVGPolygonElement._(JSObject _) implements SVGGeometryElement, JSObject { + /// Creates an [SVGPolygonElement] using the tag 'polygon'. + SVGPolygonElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'polygon', + ); + external SVGPointList get points; external SVGPointList get animatedPoints; } @@ -962,15 +1081,36 @@ extension type SVGTextPositioningElement._(JSObject _) /// The **`SVGTextElement`** interface corresponds to the elements. extension type SVGTextElement._(JSObject _) - implements SVGTextPositioningElement, JSObject {} + implements SVGTextPositioningElement, JSObject { + /// Creates an [SVGTextElement] using the tag 'text'. + SVGTextElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'text', + ); +} /// The **`SVGTSpanElement`** interface represents a element. extension type SVGTSpanElement._(JSObject _) - implements SVGTextPositioningElement, JSObject {} + implements SVGTextPositioningElement, JSObject { + /// Creates an [SVGTSpanElement] using the tag 'tspan'. + SVGTSpanElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'tspan', + ); +} /// The **`SVGTextPathElement`** interface corresponds to the element. extension type SVGTextPathElement._(JSObject _) implements SVGTextContentElement, JSObject { + /// Creates an [SVGTextPathElement] using the tag 'textPath'. + SVGTextPathElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'textPath', + ); + external static int get TEXTPATH_METHODTYPE_UNKNOWN; external static int get TEXTPATH_METHODTYPE_ALIGN; external static int get TEXTPATH_METHODTYPE_STRETCH; @@ -986,6 +1126,13 @@ extension type SVGTextPathElement._(JSObject _) /// The **`SVGImageElement`** interface corresponds to the element. extension type SVGImageElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGImageElement] using the tag 'image'. + SVGImageElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'image', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -1000,6 +1147,13 @@ extension type SVGImageElement._(JSObject _) /// properties of elements, as well as methods to manipulate them. extension type SVGForeignObjectElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGForeignObjectElement] using the tag 'foreignObject'. + SVGForeignObjectElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'foreignObject', + ); + external SVGAnimatedLength get x; external SVGAnimatedLength get y; external SVGAnimatedLength get width; @@ -1013,6 +1167,13 @@ extension type SVGForeignObjectElement._(JSObject _) /// The following properties and methods all return, or act on the attributes of /// the element represented by `SVGMarkerElement`. extension type SVGMarkerElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGMarkerElement] using the tag 'marker'. + SVGMarkerElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'marker', + ); + external static int get SVG_MARKERUNITS_UNKNOWN; external static int get SVG_MARKERUNITS_USERSPACEONUSE; external static int get SVG_MARKERUNITS_STROKEWIDTH; @@ -1058,6 +1219,13 @@ extension type SVGGradientElement._(JSObject _) /// The **`SVGLinearGradientElement`** interface corresponds to the element. extension type SVGLinearGradientElement._(JSObject _) implements SVGGradientElement, JSObject { + /// Creates an [SVGLinearGradientElement] using the tag 'linearGradient'. + SVGLinearGradientElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'linearGradient', + ); + external SVGAnimatedLength get x1; external SVGAnimatedLength get y1; external SVGAnimatedLength get x2; @@ -1067,6 +1235,13 @@ extension type SVGLinearGradientElement._(JSObject _) /// The **`SVGRadialGradientElement`** interface corresponds to the element. extension type SVGRadialGradientElement._(JSObject _) implements SVGGradientElement, JSObject { + /// Creates an [SVGRadialGradientElement] using the tag 'radialGradient'. + SVGRadialGradientElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'radialGradient', + ); + external SVGAnimatedLength get cx; external SVGAnimatedLength get cy; external SVGAnimatedLength get r; @@ -1077,11 +1252,25 @@ extension type SVGRadialGradientElement._(JSObject _) /// The **`SVGStopElement`** interface corresponds to the element. extension type SVGStopElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGStopElement] using the tag 'stop'. + SVGStopElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'stop', + ); + external SVGAnimatedNumber get offset; } /// The **`SVGPatternElement`** interface corresponds to the element. extension type SVGPatternElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGPatternElement] using the tag 'pattern'. + SVGPatternElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'pattern', + ); + external SVGAnimatedEnumeration get patternUnits; external SVGAnimatedEnumeration get patternContentUnits; external SVGAnimatedTransformList get patternTransform; @@ -1096,6 +1285,13 @@ extension type SVGPatternElement._(JSObject _) implements SVGElement, JSObject { /// The **`SVGScriptElement`** interface corresponds to the SVG element. extension type SVGScriptElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGScriptElement] using the tag 'script'. + SVGScriptElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'script', + ); + external set type(String value); external String get type; external set crossOrigin(String? value); @@ -1107,6 +1303,13 @@ extension type SVGScriptElement._(JSObject _) implements SVGElement, JSObject { /// element, as well as methods to manipulate them. extension type SVGAElement._(JSObject _) implements SVGGraphicsElement, JSObject { + /// Creates an [SVGAElement] using the tag 'a'. + SVGAElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'a', + ); + external SVGAnimatedString get target; external set download(String value); external String get download; @@ -1148,6 +1351,13 @@ extension type SVGAElement._(JSObject _) /// The **`SVGViewElement`** interface provides access to the properties of /// elements, as well as methods to manipulate them. extension type SVGViewElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGViewElement] using the tag 'view'. + SVGViewElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'view', + ); + external SVGAnimatedRect get viewBox; external SVGAnimatedPreserveAspectRatio get preserveAspectRatio; } diff --git a/lib/src/dom/svg_animations.dart b/lib/src/dom/svg_animations.dart index c5787532..e53e5083 100644 --- a/lib/src/dom/svg_animations.dart +++ b/lib/src/dom/svg_animations.dart @@ -57,23 +57,58 @@ extension type SVGAnimationElement._(JSObject _) /// The **`SVGAnimateElement`** interface corresponds to the element. extension type SVGAnimateElement._(JSObject _) - implements SVGAnimationElement, JSObject {} + implements SVGAnimationElement, JSObject { + /// Creates an [SVGAnimateElement] using the tag 'animate'. + SVGAnimateElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'animate', + ); +} /// The **`SVGSetElement`** interface corresponds to the element. extension type SVGSetElement._(JSObject _) - implements SVGAnimationElement, JSObject {} + implements SVGAnimationElement, JSObject { + /// Creates an [SVGSetElement] using the tag 'set'. + SVGSetElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'set', + ); +} /// The **`SVGAnimateMotionElement`** interface corresponds to the element. extension type SVGAnimateMotionElement._(JSObject _) - implements SVGAnimationElement, JSObject {} + implements SVGAnimationElement, JSObject { + /// Creates an [SVGAnimateMotionElement] using the tag 'animateMotion'. + SVGAnimateMotionElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'animateMotion', + ); +} /// The **`SVGMPathElement`** interface corresponds to the element. extension type SVGMPathElement._(JSObject _) implements SVGElement, JSObject { + /// Creates an [SVGMPathElement] using the tag 'mpath'. + SVGMPathElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'mpath', + ); + external SVGAnimatedString get href; } /// The `SVGAnimateTransformElement` interface corresponds to the element. extension type SVGAnimateTransformElement._(JSObject _) - implements SVGAnimationElement, JSObject {} + implements SVGAnimationElement, JSObject { + /// Creates an [SVGAnimateTransformElement] using the tag 'animateTransform'. + SVGAnimateTransformElement() + : _ = document.createElementNS( + 'http://www.w3.org/2000/svg', + 'animateTransform', + ); +} extension type SVGDiscardElement._(JSObject _) implements SVGAnimationElement, JSObject {} diff --git a/lib/src/helpers.dart b/lib/src/helpers.dart index ce7a4e70..9f10380b 100644 --- a/lib/src/helpers.dart +++ b/lib/src/helpers.dart @@ -43,7 +43,7 @@ export 'helpers/renames.dart'; /// ```dart /// final anchor = document.createElement('a') as HTMLElement; /// ``` -@Deprecated('Directly use document.createElement instead.') +@Deprecated('Use the specific HTMLElement constructor instead.') HTMLElement createElementTag(String tagName) => document.createElement(tagName) as HTMLElement; @@ -56,7 +56,7 @@ HTMLElement createElementTag(String tagName) => /// ..width = 256 /// ..height = 256; /// ``` -@Deprecated('Directly use document.createElement instead.') +@Deprecated('Use the HTMLCanvasElement constructor instead.') HTMLCanvasElement createCanvasElement({int? width, int? height}) { final result = document.createElement('canvas') as HTMLCanvasElement; if (width != null) result.width = width; @@ -71,12 +71,16 @@ HTMLCanvasElement createCanvasElement({int? width, int? height}) { /// ```dart /// final embed = document.createElement('iframe') as HTMLIFrameElement; /// ``` -@Deprecated('Directly use document.createElement instead.') +@Deprecated('Use the HTMLIFrameElement constructor instead.') HTMLIFrameElement createIFrameElement() => document.createElement('iframe') as HTMLIFrameElement; @JS('Audio') external JSFunction get _audioConstructor; +// While `new Audio()` is a different syntax from +// `document.createElement('audio')`, it looks like they're the same: +// https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio#usage_notes +@Deprecated('Use the HTMLAudioElement constructor instead.') HTMLAudioElement createAudioElement() => _audioConstructor.callAsConstructor(); /// Finds and returns the first element within the [document] diff --git a/test/element_constructor_test.dart b/test/element_constructor_test.dart new file mode 100644 index 00000000..8a502097 --- /dev/null +++ b/test/element_constructor_test.dart @@ -0,0 +1,29 @@ +// 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. + +@TestOn('browser') +library; + +import 'package:test/test.dart'; +import 'package:web/web.dart'; + +void main() { + test('Element constructors create the expected element', () { + const html = 'http://www.w3.org/1999/xhtml'; + const svg = 'http://www.w3.org/2000/svg'; + const mathML = 'http://www.w3.org/1998/Math/MathML'; + final area = HTMLAreaElement(); + expect(area.tagName, 'AREA'); + expect(area.namespaceURI, html); + final footer = HTMLElement.footer(); + expect(footer.tagName, 'FOOTER'); + expect(footer.namespaceURI, html); + final mpath = SVGMPathElement(); + expect(mpath.tagName, 'mpath'); + expect(mpath.namespaceURI, svg); + final annotation = MathMLElement.annotation(); + expect(annotation.tagName, 'annotation'); + expect(annotation.namespaceURI, mathML); + }); +} diff --git a/tool/README.md b/tool/README.md index ccbb1e76..1eb4f239 100644 --- a/tool/README.md +++ b/tool/README.md @@ -3,8 +3,9 @@ Based on: -- @webref/idl [3.43.1](https://www.npmjs.com/package/@webref/idl/v/3.43.1) - @webref/css [6.11.0](https://www.npmjs.com/package/@webref/css/v/6.11.0) +- @webref/elements [2.2.2](https://www.npmjs.com/package/@webref/elements/v/2.2.2) +- @webref/idl [3.43.1](https://www.npmjs.com/package/@webref/idl/v/3.43.1) For instructions on re-generating the DOM bindings, see the diff --git a/tool/generator/banned_names.dart b/tool/generator/banned_names.dart index 41193501..e6e2d0ee 100644 --- a/tool/generator/banned_names.dart +++ b/tool/generator/banned_names.dart @@ -4,10 +4,21 @@ const bannedNames = { 'assert', + 'break', 'continue', + 'extends', 'default', 'in', 'is', - 'extends', - 'break', + 'var', }; + +/// Given a [jsName], returns the allowed Dart equivalent accounting for invalid +/// characters and reserved keywords. +String dartRename(String jsName) { + var dartName = jsName.replaceAll('-', '_'); + if (bannedNames.contains(dartName)) { + dartName = '${dartName}_'; + } + return dartName; +} diff --git a/tool/generator/formatting.dart b/tool/generator/formatting.dart index ba72cd32..2e0d1636 100644 --- a/tool/generator/formatting.dart +++ b/tool/generator/formatting.dart @@ -2,9 +2,10 @@ // 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. -/// Given markdown formatted text and a width, return a line-wrapped dartdoc -/// comment. -List formatDocs(String data, int width) { +/// Given markdown formatted text [data] and a line [width], return a +/// line-wrapped dartdoc comment accounting for any [leadingWhitespace] the +/// comment should have. +List formatDocs(String data, int width, [int leadingWhitespace = 0]) { // TODO(devoncarew): Look at combining soft line breaks in the markdown in // order to better reflow the returned dartdoc comments (i.e., only have line // breaks for markdown paragraphs). @@ -12,6 +13,7 @@ List formatDocs(String data, int width) { final lines = data.split('\n'); final output = []; + width -= leadingWhitespace; width -= '/// '.length; var inCodeFence = false; @@ -50,7 +52,7 @@ List formatDocs(String data, int width) { /// Identify `[foo](bar)` and `[foo]` patterns. final RegExp _linksRegEx = RegExp(r'\[([\w `-]+?)\](\(\S+\))?'); -/// Wrap the given line to [width], breaking at whitespace. +/// Wrap the given [line] to [width], breaking at whitespace. Iterable _wrap(String line, int width) sync* { if (line.isEmpty) { yield line; diff --git a/tool/generator/generate_bindings.dart b/tool/generator/generate_bindings.dart index a2f2f308..e8de011e 100644 --- a/tool/generator/generate_bindings.dart +++ b/tool/generator/generate_bindings.dart @@ -8,6 +8,7 @@ import 'translator.dart'; import 'util.dart'; import 'webidl_api.dart' as webidl; import 'webref_css_api.dart'; +import 'webref_elements_api.dart'; import 'webref_idl_api.dart'; /// Generate CSS property names for setting / getting CSS properties in JS. @@ -45,11 +46,34 @@ Future> _generateCSSStyleDeclarations() async { return cssStyleDeclarations.toList()..sort(); } +/// Parse the elements spec and construct a map of element interfaces to the +/// tag names that correspond to the interface. +Future>> _generateElementTagMap() async { + final elementMap = >{}; + final array = objectEntries(await elements.listAll().toDart); + for (var i = 0; i < array.length; i++) { + final entry = array[i] as JSArray; + final data = entry[1] as ElementsEntries; + final elements = data.elements; + if (elements != null) { + for (var j = 0; j < elements.length; j++) { + final element = elements[j]; + final tag = element.name; + final interface = element.interface; + if (tag == null || interface == null) continue; + elementMap.putIfAbsent(interface, () => {}).add(tag); + } + } + } + return elementMap; +} + Future generateBindings( String packageRoot, String librarySubDir) async { final cssStyleDeclarations = await _generateCSSStyleDeclarations(); - final translator = - Translator(packageRoot, librarySubDir, cssStyleDeclarations); + final elementHTMLMap = await _generateElementTagMap(); + final translator = Translator( + packageRoot, librarySubDir, cssStyleDeclarations, elementHTMLMap); final array = objectEntries(await idl.parseAll().toDart); for (var i = 0; i < array.length; i++) { final entry = array[i] as JSArray; diff --git a/tool/generator/main.mjs b/tool/generator/main.mjs index 4d7c8d04..b60821e7 100644 --- a/tool/generator/main.mjs +++ b/tool/generator/main.mjs @@ -2,11 +2,12 @@ // 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. -import * as fs from 'fs'; import * as childProcess from 'child_process'; +import * as fs from 'fs'; import { createRequire } from 'module'; -import * as idl from '@webref/idl'; import * as css from '@webref/css'; +import * as elements from '@webref/elements'; +import * as idl from '@webref/idl'; const require = createRequire(import.meta.url); @@ -14,11 +15,12 @@ const require = createRequire(import.meta.url); globalThis.self = globalThis; globalThis.childProcess = childProcess; globalThis.css = css; -globalThis.idl = idl; +globalThis.elements = elements; globalThis.fs = fs; -globalThis.location = { href: `file://${process.cwd()}/`} +globalThis.idl = idl; +globalThis.location = { href: `file://${process.cwd()}/` } -globalThis.dartMainRunner = async function(main, args) { +globalThis.dartMainRunner = async function (main, args) { const dir = process.argv[2]; await main(dir); } diff --git a/tool/generator/package-lock.json b/tool/generator/package-lock.json index 80ec4eb0..890d85f0 100644 --- a/tool/generator/package-lock.json +++ b/tool/generator/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@mdn/browser-compat-data": "^5.5.2", "@webref/css": "^6.11.0", + "@webref/elements": "^2.2.2", "@webref/idl": "^3.43.1" }, "devDependencies": { @@ -30,6 +31,11 @@ "css-tree": "^2.3.1" } }, + "node_modules/@webref/elements": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@webref/elements/-/elements-2.2.2.tgz", + "integrity": "sha512-gl6IaktIBI8xufIFozMKGjqlvRty1iZ4EuD+ksSKir6MV8Qkc1Sxy36FCbAmmyoUx6ODGFXCGu06hJJ2V+/tlg==" + }, "node_modules/@webref/idl": { "version": "3.43.1", "resolved": "https://registry.npmjs.org/@webref/idl/-/idl-3.43.1.tgz", diff --git a/tool/generator/package.json b/tool/generator/package.json index 13a71f23..a3049889 100644 --- a/tool/generator/package.json +++ b/tool/generator/package.json @@ -11,9 +11,10 @@ "dependencies": { "@mdn/browser-compat-data": "^5.5.2", "@webref/css": "^6.11.0", + "@webref/elements": "^2.2.2", "@webref/idl": "^3.43.1" }, "devDependencies": { "webidl2": "^24.2.2" } -} +} \ No newline at end of file diff --git a/tool/generator/translator.dart b/tool/generator/translator.dart index ab0f65b0..0c27bd3f 100644 --- a/tool/generator/translator.dart +++ b/tool/generator/translator.dart @@ -10,11 +10,13 @@ import 'package:path/path.dart' as p; import 'banned_names.dart'; import 'bcd.dart'; import 'doc_provider.dart'; +import 'formatting.dart'; import 'singletons.dart'; import 'type_aliases.dart'; import 'type_union.dart'; import 'util.dart'; import 'webidl_api.dart' as idl; +import 'webref_elements_api.dart'; typedef TranslationResult = Map; @@ -374,6 +376,7 @@ class _PartialInterfacelike { switch (type) { case 'constructor': final idlConstructor = member as idl.Constructor; + if (_hasHTMLConstructorAttribute(idlConstructor)) continue; if (constructor == null) { constructor = _OverridableConstructor(idlConstructor); } else { @@ -457,6 +460,13 @@ class _PartialInterfacelike { inheritance ??= interfacelike.inheritance; _processMembers(interfacelike.members); } + + // Constructors with the attribute `HTMLConstructor` are intended for custom + // element behavior, and are not useful otherwise, so avoid emitting them. + // https://html.spec.whatwg.org/#html-element-constructors + bool _hasHTMLConstructorAttribute(idl.Constructor constructor) => + constructor.extAttrs.toDart + .any((extAttr) => extAttr.name == 'HTMLConstructor'); } class _MemberName { @@ -466,11 +476,9 @@ class _MemberName { _MemberName._(this.name, this.jsOverride); factory _MemberName(String name, [String jsOverride = '']) { - if (bannedNames.contains(name)) { - if (jsOverride.isEmpty) jsOverride = name; - name = '${name}_'; - } - return _MemberName._(name, jsOverride); + final rename = dartRename(name); + if (rename != name && jsOverride.isEmpty) jsOverride = name; + return _MemberName._(rename, jsOverride); } } @@ -478,6 +486,7 @@ class Translator { final String packageRoot; final String _librarySubDir; final List _cssStyleDeclarations; + final Map> _elementTagMap; final _libraries = {}; final _typeToDeclaration = {}; @@ -492,8 +501,8 @@ class Translator { /// Singleton so that various helper methods can access info about the AST. static Translator? instance; - Translator( - this.packageRoot, this._librarySubDir, this._cssStyleDeclarations) { + Translator(this.packageRoot, this._librarySubDir, this._cssStyleDeclarations, + this._elementTagMap) { instance = this; docProvider = DocProvider.create(); browserCompatData = BrowserCompatData.read(); @@ -570,14 +579,6 @@ class Translator { ..name = getterName ..type = code.MethodType.getter); - String _parameterName(String name) { - if (bannedNames.contains(name)) { - return '${name}_'; - } else { - return name; - } - } - // Given a raw type, convert it to the Dart type that will be emitted by the // translator. // @@ -628,6 +629,17 @@ class Translator { typeArguments .add(_typeReference(typeParameter, onlyEmitInteropTypes: true)); } + final url = _urlForType(dartType); + return code.TypeReference((b) => b + ..symbol = dartType + ..isNullable = nullable + ..types.addAll(typeArguments) + ..url = url); + } + + // Given a [dartType] that is part of a reference, returns the url that needs + // to be imported to use it, if any. + String? _urlForType(String dartType) { // Unfortunately, `code_builder` doesn't know the url of the library we are // emitting, so we have to remove it here to avoid importing ourselves. var url = _typeToLibrary[dartType]?.url; @@ -643,11 +655,7 @@ class Translator { } else if (p.dirname(url) == p.dirname(_currentlyTranslatingUrl)) { url = p.basename(url); } - return code.TypeReference((b) => b - ..symbol = dartType - ..isNullable = nullable - ..types.addAll(typeArguments) - ..url = url); + return url; } code.TypeReference _idlTypeToTypeReference(idl.IDLType idlType) => @@ -665,7 +673,7 @@ class Translator { final optionalParameters = []; for (final rawParameter in member.parameters) { final parameter = code.Parameter((b) => b - ..name = _parameterName(rawParameter.name) + ..name = dartRename(rawParameter.name) ..type = _typeToTypeReference(rawParameter.type)); if (rawParameter.isOptional) { optionalParameters.add(parameter); @@ -697,7 +705,7 @@ class Translator { final field = member as idl.Field; final isRequired = field.required; final parameter = code.Parameter((b) => b - ..name = _parameterName(field.name) + ..name = dartRename(field.name) ..type = _idlTypeToTypeReference(field.idlType) ..required = isRequired ..named = true); @@ -832,6 +840,52 @@ class Translator { readOnly: false), ]; + // If [jsName] is an element type, creates a constructor for each tag that the + // element interface corresponds to using either `createElement` or + // `createElementNS`. + List _elementConstructors( + String jsName, String dartClassName, String representationFieldName) { + final elementConstructors = []; + final tags = _elementTagMap[jsName]; + if (tags != null) { + final uri = uriForElement(jsName); + assert(tags.isNotEmpty); + final createElementMethod = + uri != null ? 'createElementNS' : 'createElement'; + for (final tag in tags) { + final article = singularArticleForElement(dartClassName); + elementConstructors.add(code.Constructor((b) => b + ..docs.addAll([ + formatDocs( + "Creates $article [$dartClassName] using the tag '$tag'.", + 80, + // Extension type members start with an indentation of 2 + // chars. + 2) + .join('\n') + ]) + // If there are multiple tags, use a named constructor. + ..name = tags.length == 1 ? null : dartRename(tag) + ..initializers.addAll([ + code + .refer(representationFieldName) + .assign(code + .refer('document', _urlForType('Document')) + .property(createElementMethod) + .call([ + // TODO(srujzs): Should we make these URIs a constant and + // refer to the constant instead? Downside is that it requires + // another manual hack to generate them. + if (uri != null) code.literalString(uri), + code.literalString(tag) + ])) + .code + ]))); + } + } + return elementConstructors; + } + code.Extension _extension( {required _RawType type, required List extensionMembers}) => @@ -856,6 +910,7 @@ class Translator { final docs = mdnInterface == null ? [] : mdnInterface.formattedDocs; final jsObject = _typeReference(_RawType('JSObject', false)); + const representationFieldName = '_'; return code.ExtensionType((b) => b ..docs.addAll(docs) ..annotations.addAll( @@ -863,16 +918,18 @@ class Translator { ..name = dartClassName ..primaryConstructorName = '_' ..representationDeclaration = code.RepresentationDeclaration((b) => b - ..name = '_' + ..name = representationFieldName ..declaredRepresentationType = jsObject) ..implements.addAll(implements .map((interface) => _typeReference(_RawType(interface, false))) .followedBy([jsObject])) - ..constructors.addAll(isObjectLiteral - ? [_objectLiteral(members)] - : constructor != null - ? [_constructor(constructor)] - : []) + ..constructors.addAll((isObjectLiteral + ? [_objectLiteral(members)] + : constructor != null + ? [_constructor(constructor)] + : []) + .followedBy(_elementConstructors( + jsName, dartClassName, representationFieldName))) ..methods.addAll(_operations(staticOperations) .followedBy(_members(staticMembers)) .followedBy(_operations(operations)) diff --git a/tool/generator/webidl_api.dart b/tool/generator/webidl_api.dart index f467a642..9b99271d 100644 --- a/tool/generator/webidl_api.dart +++ b/tool/generator/webidl_api.dart @@ -61,6 +61,11 @@ extension type Includes._(JSObject _) implements Node { /// All members inherit from the [Member] node. extension type Member._(JSObject _) implements JSObject { external String get type; + external JSArray get extAttrs; +} + +extension type ExtendedAttribute._(JSObject _) implements JSObject { + external String get name; } extension type Argument._(JSObject _) implements JSObject { diff --git a/tool/generator/webref_elements_api.dart b/tool/generator/webref_elements_api.dart new file mode 100644 index 00000000..73587178 --- /dev/null +++ b/tool/generator/webref_elements_api.dart @@ -0,0 +1,48 @@ +// 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. + +import 'dart:js_interop'; + +// Namespace URIs that are needed to construct non-HTML elements. +// https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS#important_namespace_uris +const _svgNamespaceURI = 'http://www.w3.org/2000/svg'; +const _mathMLNamespaceURI = 'http://www.w3.org/1998/Math/MathML'; + +/// Gets the URI needed to create an element of type [elementInterface]. +String? uriForElement(String elementInterface) { + if (elementInterface.startsWith('SVG')) return _svgNamespaceURI; + if (elementInterface.startsWith('MathML')) return _mathMLNamespaceURI; + // URI is not needed for HTML elements as they can just use `createElement`. + assert(elementInterface.startsWith('HTML')); + return null; +} + +// TODO(srujzs): Generalize this. It's a bit difficult as it requires knowing +// what sound a word begins with rather than just if it starts with a vowel or +// not. +/// Determines whether [elementInterface] should use the article 'a' or 'an'. +String singularArticleForElement(String elementInterface) { + if (elementInterface.startsWith('HTML') || + elementInterface.startsWith('SVG')) { + return 'an'; + } + assert(elementInterface.startsWith('MathML')); + return 'a'; +} + +@JS() +external WebRefElements get elements; + +extension type WebRefElements._(JSObject _) implements JSObject { + external JSPromise listAll(); +} + +extension type ElementsEntries._(JSObject _) implements JSObject { + external JSArray? elements; +} + +extension type ElementEntry._(JSObject _) implements JSObject { + external String? get name; + external String? get interface; +} diff --git a/tool/update_bindings.dart b/tool/update_bindings.dart index 777ea398..43d522fe 100644 --- a/tool/update_bindings.dart +++ b/tool/update_bindings.dart @@ -98,12 +98,14 @@ $_usage'''); final sourceContent = readmeFile.readAsStringSync(); - final idlVersion = _packageLockVersion(_webRefIdl); final cssVersion = _packageLockVersion(_webRefCss); + final elementsVersion = _packageLockVersion(_webRefElements); + final idlVersion = _packageLockVersion(_webRefIdl); final versions = ''' $_startComment -- $_webRefIdl [$idlVersion](https://www.npmjs.com/package/$_webRefIdl/v/$idlVersion) - $_webRefCss [$cssVersion](https://www.npmjs.com/package/$_webRefCss/v/$cssVersion) +- $_webRefElements [$elementsVersion](https://www.npmjs.com/package/$_webRefElements/v/$elementsVersion) +- $_webRefIdl [$idlVersion](https://www.npmjs.com/package/$_webRefIdl/v/$idlVersion) '''; final newContent = @@ -131,8 +133,9 @@ String _packageLockVersion(String package) { final _bindingsGeneratorPath = p.join('tool', 'generator'); -const _webRefIdl = '@webref/idl'; const _webRefCss = '@webref/css'; +const _webRefElements = '@webref/elements'; +const _webRefIdl = '@webref/idl'; const _thisScript = 'tool/update_bindings.dart';