Skip to content

Commit 4264dcc

Browse files
authored
baseline status for html elements and attributes (#113)
1 parent 1073929 commit 4264dcc

7 files changed

Lines changed: 6219 additions & 273 deletions

File tree

web-data/css/mdn/mdn-browser-compat-data-importer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function toCompatString(bcdProperty) {
150150
return s.join(',');
151151
}
152152

153-
function supportToShortCompatString(support, browserAbbrev) {
153+
export function supportToShortCompatString(support, browserAbbrev) {
154154
let version_added;
155155
if (Array.isArray(support) && support[0] && support[0].version_added) {
156156
version_added = support[0].version_added;

web-data/data/browsers.html-data.json

Lines changed: 6005 additions & 266 deletions
Large diffs are not rendered by default.

web-data/html/generateData.mjs

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import fs from 'fs';
77
import path from 'path';
88
import bcd from '@mdn/browser-compat-data' with { type: 'json' };
9+
import { getStatus } from 'compute-baseline';
910
import htmlTags from './htmlTags.json' with { type: 'json' };
1011
import htmlTagDescriptions from './mdnTagDescriptions.json' with { type: 'json' };
1112
import htmlGlobalAttributes from './htmlGlobalAttributes.json' with { type: 'json' };
@@ -14,6 +15,35 @@ import oldEvents from './oldEvents.json' with { type: 'json' };
1415
import ariaData from './ariaData.json' with { type: 'json' };
1516
import ariaSpec from './ariaSpec.json' with { type: 'json' };
1617
import valueSets from './valueSets.json' with { type: 'json' };
18+
import { supportToShortCompatString } from '../css/mdn/mdn-browser-compat-data-importer.mjs';
19+
20+
21+
function getFeatureId(compat) {
22+
return compat?.tags?.find(tag => {
23+
const parts = tag.split(':');
24+
return parts.length == 2 && parts[0] == 'web-features';
25+
})?.split(':')[1];
26+
}
27+
28+
const BaselineBrowserAbbreviations = {
29+
"chrome": "C",
30+
"chrome_android": "CA",
31+
"edge": "E",
32+
"firefox": "FF",
33+
"firefox_android": "FFA",
34+
"safari": "S",
35+
"safari_ios": "SM"
36+
};
37+
38+
function getBrowserCompatString(support) {
39+
if (!support) {
40+
return;
41+
}
42+
return Object.entries(support).map(([browser, version_added]) => {
43+
const abbreviation = BaselineBrowserAbbreviations[browser];
44+
return supportToShortCompatString({version_added}, abbreviation);
45+
});
46+
}
1747

1848
/*---------------------------------------------------------------------------------------------
1949
* Tags
@@ -67,6 +97,35 @@ htmlTags.forEach(t => {
6797
name: 'MDN Reference',
6898
url: bcdMatchingTag.__compat.mdn_url
6999
});
100+
101+
// Add the Baseline status to the HTML element
102+
const featureId = getFeatureId(bcdMatchingTag.__compat);
103+
if (!featureId) {
104+
return;
105+
}
106+
const status = getStatus(featureId, `html.elements.${t.name}`);
107+
if (!status) {
108+
return;
109+
}
110+
t.browsers = getBrowserCompatString(status.support);
111+
delete status.support;
112+
t.status = status;
113+
114+
// Add the Baseline status to each attribute
115+
t.attributes.forEach(a => {
116+
const bcdMatchingAttr = bcdHTMLElements[t.name][a.name];
117+
if (!bcdMatchingAttr) {
118+
return;
119+
}
120+
const attrFeatureId = getFeatureId(bcdMatchingAttr.__compat) || featureId;
121+
const attrStatus = getStatus(attrFeatureId, `html.elements.${t.name}.${a.name}`);
122+
if (!attrStatus) {
123+
return;
124+
}
125+
a.browsers = getBrowserCompatString(attrStatus.support);
126+
delete attrStatus.support;
127+
a.status = attrStatus;
128+
});
70129
}
71130
}
72131
});
@@ -84,19 +143,28 @@ htmlGlobalAttributes.forEach(a => {
84143
value: a.description
85144
};
86145
}
87-
if (
88-
bcdGlobalAttributes[a.name] &&
89-
bcdGlobalAttributes[a.name].__compat &&
90-
bcdGlobalAttributes[a.name].__compat.mdn_url
91-
) {
146+
const bcdMatchingAttr = bcdGlobalAttributes[a.name];
147+
if (bcdMatchingAttr?.__compat?.mdn_url) {
92148
if (!a.references) {
93149
a.references = [];
94150
}
95151
a.references.push({
96152
name: 'MDN Reference',
97-
url: bcdGlobalAttributes[a.name].__compat.mdn_url
153+
url: bcdMatchingAttr.__compat.mdn_url
98154
});
99155
}
156+
157+
const featureId = getFeatureId(bcdMatchingAttr?.__compat);
158+
if (!featureId) {
159+
return;
160+
}
161+
const status = getStatus(featureId, `html.global_attributes.${a.name}`);
162+
if (!status) {
163+
return;
164+
}
165+
a.browsers = getBrowserCompatString(status.support);
166+
delete status.support;
167+
a.status = status;
100168
});
101169

102170
/*---------------------------------------------------------------------------------------------

web-data/html/htmlGlobalAttributes.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
"name": "autocapitalize",
88
"description": "Controls whether and how text input is automatically capitalized as it is entered/edited by the user. It can have the following values:\n\n* `off` or `none`, no autocapitalization is applied (all letters default to lowercase)\n* `on` or `sentences`, the first letter of each sentence defaults to a capital letter; all other letters default to lowercase\n* `words`, the first letter of each word defaults to a capital letter; all other letters default to lowercase\n* `characters`, all letters should default to uppercase"
99
},
10+
{
11+
"name": "autocorrect",
12+
"description": "Controls whether autocorrection of editable text is enabled for spelling and/or punctuation errors.",
13+
"valueSet": "o"
14+
},
15+
{
16+
"name": "autofocus",
17+
"description": "Indicates that an element should be focused on page load, or when the [`<dialog>`](https://developer.mozilla.org/docs/Web/HTML/Element/dialog) that it is part of is displayed."
18+
},
1019
{
1120
"name": "class",
1221
"description": "A space-separated list of the classes of the element. Classes allows CSS and JavaScript to select and access specific elements via the [class selectors](https://developer.mozilla.org/docs/Web/CSS/Class_selectors) or functions like the method [`Document.getElementsByClassName()`](https://developer.mozilla.org/docs/Web/API/Document/getElementsByClassName \"returns an array-like object of all child elements which have all of the given class names.\")."
@@ -33,6 +42,11 @@
3342
"name": "dropzone",
3443
"description": "An enumerated attribute indicating what types of content can be dropped on an element, using the [Drag and Drop API](https://developer.mozilla.org/docs/DragDrop/Drag_and_Drop). It can have the following values:\n\n* `copy`, which indicates that dropping will create a copy of the element that was dragged\n* `move`, which indicates that the element that was dragged will be moved to this new location.\n* `link`, will create a link to the dragged data."
3544
},
45+
{
46+
"name": "enterkeyhint",
47+
"description": "An enumerated attribute defining what action label (or icon) to present for the enter key on virtual keyboards.",
48+
"valueSet": "enterkeyhint"
49+
},
3650
{
3751
"name": "exportparts",
3852
"description": "Used to transitively export shadow parts from a nested shadow tree into a containing light tree."
@@ -46,6 +60,10 @@
4660
"name": "id",
4761
"description": "Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS)."
4862
},
63+
{
64+
"name": "inert",
65+
"description": "Indicates that the element and all of its flat tree descendants become _inert_. Modal `<dialog>`s generated with [`showModal()`](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/showModal) escape inertness, meaning that they don't inherit inertness from their ancestors, but can only be made inert by having the `inert` attribute explicitly set on themselves."
66+
},
4967
{
5068
"name": "inputmode",
5169
"description": "Provides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents. Used primarily on [`<input>`](https://developer.mozilla.org/docs/Web/HTML/Element/input \"The HTML <input> element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent.\") elements, but is usable on any element while in `[contenteditable](https://developer.mozilla.org/docs/Web/HTML/Global_attributes#attr-contenteditable)` mode."
@@ -79,10 +97,19 @@
7997
"name": "lang",
8098
"description": "Helps define the language of an element: the language that non-editable elements are in, or the language that editable elements should be written in by the user. The attribute contains one “language tag” (made of hyphen-separated “language subtags”) in the format defined in [_Tags for Identifying Languages (BCP47)_](https://www.ietf.org/rfc/bcp/bcp47.txt). [**xml:lang**](#attr-xml:lang) has priority over it."
8199
},
100+
{
101+
"name": "nonce",
102+
"description": "Defines a cryptographic nonce (\"number used once\") which can be used by [Content Security Policy](https://developer.mozilla.org/docs/Web/HTTP/Guides/CSP) to determine whether or not a given fetch will be allowed to proceed for a given element."
103+
},
82104
{
83105
"name": "part",
84106
"description": "A space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the [`::part`](https://developer.mozilla.org/docs/Web/CSS/::part \"The ::part CSS pseudo-element represents any element within a shadow tree that has a matching part attribute.\") pseudo-element."
85107
},
108+
{
109+
"name": "popover",
110+
"description": "Designates an element as a popover element.",
111+
"valueSet": "popover"
112+
},
86113
{
87114
"name": "role",
88115
"valueSet": "roles"
@@ -112,5 +139,10 @@
112139
"name": "translate",
113140
"description": "An enumerated attribute that is used to specify whether an element's attribute values and the values of its [`Text`](https://developer.mozilla.org/docs/Web/API/Text \"The Text interface represents the textual content of Element or Attr. If an element has no markup within its content, it has a single child implementing Text that contains the element's text. However, if the element contains markup, it is parsed into information items and Text nodes that form its children.\") node children are to be translated when the page is localized, or whether to leave them unchanged. It can have the following values:\n\n* empty string and `yes`, which indicates that the element will be translated.\n* `no`, which indicates that the element will not be translated.",
114141
"valueSet": "y"
142+
},
143+
{
144+
"name": "virtualkeyboardpolicy",
145+
"description": "When specified on an element that the element's content is editable (for example, it is an `<input>` or `<textarea>` element, or an element with the `contenteditable` attribute set), it controls the on-screen virtual keyboard behavior on devices such as tablets, mobile phones, or other devices where a hardware keyboard may not be available.",
146+
"valueSet": "b"
115147
}
116148
]

web-data/html/htmlTags.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@
543543
"value": "Indicates how the browser should load the image."
544544
}
545545
},
546+
{
547+
"name": "fetchpriority",
548+
"valueSet": "fetchpriority"
549+
},
546550
{
547551
"name": "referrerpolicy",
548552
"valueSet": "referrerpolicy"
@@ -1040,6 +1044,12 @@
10401044
{
10411045
"name": "placeholder"
10421046
},
1047+
{
1048+
"name": "popovertarget"
1049+
},
1050+
{
1051+
"name": "popovertargetaction"
1052+
},
10431053
{
10441054
"name": "readonly",
10451055
"valueSet": "v"
@@ -1105,6 +1115,12 @@
11051115
{
11061116
"name": "name"
11071117
},
1118+
{
1119+
"name": "popovertarget"
1120+
},
1121+
{
1122+
"name": "popovertargetaction"
1123+
},
11081124
{
11091125
"name": "type",
11101126
"valueSet": "bt"
@@ -1416,5 +1432,30 @@
14161432
"name": "menu",
14171433
"description": "The menu element represents an unordered list of interactive items.",
14181434
"attributes": []
1435+
},
1436+
{
1437+
"name": "search",
1438+
"description": "The search element represents the parts of the document or application with form controls or other content related to performing a search or filtering operation.",
1439+
"attributes": []
1440+
},
1441+
{
1442+
"name": "fencedframe",
1443+
"description": "The fencedframe element represents a nested browsing context, embedding another HTML page into the current one.",
1444+
"attributes": [
1445+
{
1446+
"name": "allow"
1447+
},
1448+
{
1449+
"name": "height"
1450+
},
1451+
{
1452+
"name": "width"
1453+
}
1454+
]
1455+
},
1456+
{
1457+
"name": "selectedcontent",
1458+
"description": "The selectedcontent element can be used to display the content of the currently selected option element inside of a closed select element.",
1459+
"attributes": []
14191460
}
14201461
]

web-data/html/mdnTagDescriptions.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@
315315
"name": "name",
316316
"description": "The name of the button, which is submitted with the form data."
317317
},
318+
{
319+
"name": "popovertarget",
320+
"description": "Turns the button into a popover control button; takes the ID of the popover element to control as its value."
321+
},
322+
{
323+
"name": "popovertargetaction",
324+
"description": "Specifies the action to be performed on a popover element being controlled by the button."
325+
},
318326
{
319327
"name": "type",
320328
"description": "The type of the button. Possible values are:\n\n* `submit`: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.\n* `reset`: The button resets all the controls to their initial values.\n* `button`: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur."
@@ -734,6 +742,10 @@
734742
"name": "decoding",
735743
"description": "`sync`\n\nDecode the image synchronously for atomic presentation with other content.\n\n`async`\n\nDecode the image asynchronously to reduce delay in presenting other content.\n\n`auto`\n\nDefault mode, which indicates no preference for the decoding mode. The browser decides what is best for the user."
736744
},
745+
{
746+
"name": "fetchpriority",
747+
"description": "Provides a hint of the relative priority to use when fetching the image."
748+
},
737749
{
738750
"name": "height",
739751
"description": "The intrinsic height of the image in pixels."

web-data/html/valueSets.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,5 +1268,59 @@
12681268
"name": "unsafe-url"
12691269
}
12701270
]
1271+
},
1272+
{
1273+
"name": "enterkeyhint",
1274+
"values": [
1275+
{
1276+
"name": "enter"
1277+
},
1278+
{
1279+
"name": "done"
1280+
},
1281+
{
1282+
"name": "go"
1283+
},
1284+
{
1285+
"name": "next"
1286+
},
1287+
{
1288+
"name": "previous"
1289+
},
1290+
{
1291+
"name": "search"
1292+
},
1293+
{
1294+
"name": "send"
1295+
}
1296+
]
1297+
},
1298+
{
1299+
"name": "popover",
1300+
"values": [
1301+
{
1302+
"name": "auto"
1303+
},
1304+
{
1305+
"name": "hint"
1306+
},
1307+
{
1308+
"name": "manual"
1309+
}
1310+
]
1311+
},
1312+
{
1313+
"name": "fetchpriority",
1314+
"values": [
1315+
{
1316+
"name": "high"
1317+
},
1318+
{
1319+
"name": "low"
1320+
},
1321+
{
1322+
"name": "auto"
1323+
}
1324+
]
12711325
}
12721326
]

0 commit comments

Comments
 (0)