@webref/xref 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -0
- package/ed/dfns/ecmascript.json +2 -2
- package/ed/dfns/encoding.json +20 -0
- package/ed/dfns/picture-in-picture.json +58 -18
- package/ed/dfns/shacl12-rules.json +181 -86
- package/ed/dfns/webdriver-bidi.json +148 -17
- package/ed/dfns/webmcp.json +164 -3
- package/ed/headings/SVG2.json +1 -1
- package/ed/headings/ecmascript.json +1 -1
- package/ed/headings/encoding.json +1 -1
- package/ed/headings/picture-in-picture.json +5 -5
- package/ed/headings/rfc2397.json +33 -9
- package/ed/headings/rfc4120.json +164 -134
- package/ed/headings/rfc6386.json +128 -104
- package/ed/headings/rfc6454.json +62 -38
- package/ed/headings/rfc6455.json +120 -90
- package/ed/headings/rfc6797.json +104 -80
- package/ed/headings/rfc7034.json +52 -28
- package/ed/headings/rfc7239.json +55 -31
- package/ed/headings/rfc7469.json +63 -39
- package/ed/headings/rfc7578.json +54 -30
- package/ed/headings/rfc7932.json +70 -40
- package/ed/headings/rfc8610.json +100 -63
- package/ed/headings/rfc8878.json +97 -88
- package/ed/headings/rfc9163.json +62 -59
- package/ed/headings/rfc9649.json +82 -79
- package/ed/headings/rfc9659.json +33 -30
- package/ed/headings/selectors-5.json +8 -1
- package/ed/headings/shacl12-rules.json +127 -77
- package/ed/headings/webdriver-bidi.json +10 -3
- package/ed/headings/webmcp.json +14 -0
- package/ed/headings/webusb.json +1 -1
- package/ed/headings/webvtt1.json +2 -2
- package/index.js +82 -9
- package/package.json +1 -1
- package/specs.json +28890 -0
- package/tr/dfns/shacl12-rules.json +181 -86
- package/tr/dfns/webdriver-bidi.json +148 -17
- package/tr/dfns/webvtt1.json +82 -95
- package/tr/headings/shacl12-rules.json +127 -77
- package/tr/headings/webdriver-bidi.json +10 -3
- package/tr/headings/webvtt1.json +3 -9
package/ed/headings/webmcp.json
CHANGED
|
@@ -101,6 +101,20 @@
|
|
|
101
101
|
"title": "Declarative WebMCP",
|
|
102
102
|
"number": "4.3"
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
"id": "events",
|
|
106
|
+
"href": "https://webmachinelearning.github.io/webmcp/#events",
|
|
107
|
+
"level": 3,
|
|
108
|
+
"title": "Events",
|
|
109
|
+
"number": "4.4"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "permissions-policy",
|
|
113
|
+
"href": "https://webmachinelearning.github.io/webmcp/#permissions-policy",
|
|
114
|
+
"level": 3,
|
|
115
|
+
"title": "Permissions policy integration",
|
|
116
|
+
"number": "4.5"
|
|
117
|
+
},
|
|
104
118
|
{
|
|
105
119
|
"id": "interaction-with-agents",
|
|
106
120
|
"href": "https://webmachinelearning.github.io/webmcp/#interaction-with-agents",
|
package/ed/headings/webusb.json
CHANGED
package/ed/headings/webvtt1.json
CHANGED
package/index.js
CHANGED
|
@@ -9,7 +9,8 @@ const scriptPath = path.dirname(fileURLToPath(import.meta.url));
|
|
|
9
9
|
*/
|
|
10
10
|
const xref = {
|
|
11
11
|
dfns: [],
|
|
12
|
-
headings: []
|
|
12
|
+
headings: [],
|
|
13
|
+
specs: []
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -63,7 +64,7 @@ function setupExtracts(type, rootFolder) {
|
|
|
63
64
|
if (entry.alternateIds) {
|
|
64
65
|
for (const id of entry.alternateIds) {
|
|
65
66
|
const url = new URL(entry.href);
|
|
66
|
-
url.hash = id;
|
|
67
|
+
url.hash = encodeURIComponent(id);
|
|
67
68
|
const href = url.toString();
|
|
68
69
|
indexUrl(href, { source: 'headings', entry });
|
|
69
70
|
}
|
|
@@ -83,6 +84,18 @@ export function setup(rootFolder = scriptPath) {
|
|
|
83
84
|
if (initialized) {
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
87
|
+
if (rootFolder === scriptPath) {
|
|
88
|
+
// We're in "package" mode, the root folder contains a `specs.json` file.
|
|
89
|
+
xref.specs = JSON.parse(fs.readFileSync(path.join(rootFolder, 'specs.json'), 'utf8'));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// We're in "use crawl results" mode, the root folder won't contain a
|
|
93
|
+
// `specs.json` file, but the `ed` folder should have a crawl index with a
|
|
94
|
+
// list of specs.
|
|
95
|
+
const crawl = JSON.parse(fs.readFileSync(path.join(rootFolder, 'ed', 'index.json'), 'utf8'));
|
|
96
|
+
xref.specs = crawl.results;
|
|
97
|
+
}
|
|
98
|
+
|
|
86
99
|
for (const type of ['dfns', 'headings']) {
|
|
87
100
|
setupExtracts(type, rootFolder);
|
|
88
101
|
}
|
|
@@ -94,14 +107,74 @@ export function setup(rootFolder = scriptPath) {
|
|
|
94
107
|
* Lookup a URL in the loaded database
|
|
95
108
|
*
|
|
96
109
|
* The function returns an array of entries. Each entry is an object with a
|
|
97
|
-
* `source` key set to "dfns"
|
|
98
|
-
* `
|
|
99
|
-
*
|
|
110
|
+
* `source` key set to "dfns" or "headings"; and a `entry` key set to either a
|
|
111
|
+
* dfn object when `source` is "dfns" or a heading object when `source` is
|
|
112
|
+
* "headings".
|
|
113
|
+
*
|
|
114
|
+
* The function accepts a lookup options object as second parameter that sets
|
|
115
|
+
* lookup capabilities and filters. Check the README for details.
|
|
100
116
|
*/
|
|
101
|
-
export function lookup(url) {
|
|
117
|
+
export function lookup(url, { standing, version, series } = {}) {
|
|
102
118
|
if (!initialized) {
|
|
103
|
-
throw new Error('
|
|
119
|
+
throw new Error('The `lookup()` function was called before `setup()`.');
|
|
120
|
+
}
|
|
121
|
+
if (!url) {
|
|
122
|
+
throw new Error('The `lookup()` function was called without argument.');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// URL hashes in Webref extracts are percent-encoded. Goal is to support
|
|
126
|
+
// lookup of both percent-encoded and non percent-encoded URLs. To make sure
|
|
127
|
+
// that we end up with what we need, let's force a decode (this will be a
|
|
128
|
+
// no-op if the fragment is not percent-encoded) before we re-encode.
|
|
129
|
+
let parsedUrl;
|
|
130
|
+
try {
|
|
131
|
+
parsedUrl = new URL(url);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
throw new Error('The `lookup()` function was called with an invalid URL.', err);
|
|
135
|
+
}
|
|
136
|
+
let decodedHash;
|
|
137
|
+
try {
|
|
138
|
+
decodedHash = decodeURIComponent(parsedUrl.hash);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
decodedHash = parsedUrl.hash;
|
|
142
|
+
}
|
|
143
|
+
parsedUrl.hash = encodeURIComponent(decodedHash.replace(/^#/, ''));
|
|
144
|
+
let lookupUrl = parsedUrl.toString();
|
|
145
|
+
|
|
146
|
+
// If the series flag is set, the provided URL may also be a spec series URL,
|
|
147
|
+
// which we need to convert to the URL of the current spec in the series.
|
|
148
|
+
if (series && !urlIndex[lookupUrl.toString()]) {
|
|
149
|
+
// Drop the hash to match spec URLs
|
|
150
|
+
const hash = parsedUrl.hash;
|
|
151
|
+
parsedUrl.hash = '';
|
|
152
|
+
const specUrl = parsedUrl.toString();
|
|
153
|
+
const spec = xref.specs.find(spec =>
|
|
154
|
+
spec.shortname === spec.series.currentSpecification &&
|
|
155
|
+
(spec.series.nightlyUrl === specUrl || spec.series.releaseUrl === specUrl)
|
|
156
|
+
);
|
|
157
|
+
if (spec) {
|
|
158
|
+
// The lookup URL matches a series URL indeed, let's change it to the URL
|
|
159
|
+
// of the current spec in the series
|
|
160
|
+
const currentUrl = new URL(
|
|
161
|
+
(spec.series.nightlyUrl === specUrl) ? spec.nightly.url : spec.release.url
|
|
162
|
+
);
|
|
163
|
+
currentUrl.hash = hash;
|
|
164
|
+
lookupUrl = currentUrl.toString();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Look for the resulting URL and filter results as needed
|
|
169
|
+
let res = urlIndex[lookupUrl.toString()] ?? [];
|
|
170
|
+
const hasSpecFilter = standing || version;
|
|
171
|
+
if (hasSpecFilter) {
|
|
172
|
+
res = res.filter(match => {
|
|
173
|
+
const entry = match.entry;
|
|
174
|
+
const spec = xref.specs.find(spec => spec.shortname === entry.spec);
|
|
175
|
+
return (!standing || spec.standing === standing) &&
|
|
176
|
+
(!version || entry.version === version);
|
|
177
|
+
});
|
|
104
178
|
}
|
|
105
|
-
|
|
106
|
-
return structuredClone(res) ?? [];
|
|
179
|
+
return structuredClone(res);
|
|
107
180
|
}
|