emissions-api-sdk 1.0.12 → 1.0.13
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 +42 -2
- package/dist/Constants.js +4 -1
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +24 -0
- package/dist/api/Factor.js +19 -0
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +19 -2
- package/dist/coverage/clover.xml +149 -87
- package/dist/coverage/coverage-final.json +14 -8
- package/dist/coverage/lcov-report/index.html +21 -21
- package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
- package/dist/coverage/lcov-report/src/Constants.ts.html +36 -27
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +77 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +59 -2
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +74 -5
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +55 -4
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +36 -6
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +5 -5
- package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/index.html +63 -3
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +249 -122
- package/dist/index.js +3 -1
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/types/Constants.d.ts +3 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +24 -0
- package/dist/types/api/Factor.d.ts +19 -0
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +23 -0
- package/dist/types/api/TypeRecommender.d.ts +19 -2
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/common.d.ts +40 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +538 -74
- package/docs/_sources/index.rst.txt +11 -0
- package/docs/_sources/reference.rst.txt +26 -0
- package/docs/_sources/troubleshooting.rst.txt +77 -12
- package/docs/_static/basic.css +8 -0
- package/docs/_static/doctools.js +5 -6
- package/docs/_static/language_data.js +186 -7
- package/docs/_static/pygments.css +146 -164
- package/docs/_static/searchtools.js +60 -121
- package/docs/_static/sphinx_highlight.js +31 -36
- package/docs/_static/styles/furo.css +1 -1
- package/docs/_static/styles/furo.css.map +1 -1
- package/docs/authentication.html +61 -26
- package/docs/client.html +33 -22
- package/docs/genindex.html +52 -23
- package/docs/getting_started.html +745 -103
- package/docs/index.html +65 -21
- package/docs/reference.html +484 -66
- package/docs/sdk.html +32 -21
- package/docs/search.html +32 -21
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +105 -38
- package/package.json +7 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +538 -74
- package/sphinx-build/source/index.rst +11 -0
- package/sphinx-build/source/reference.rst +26 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +3 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +24 -0
- package/src/api/Factor.ts +19 -0
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +19 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +46 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +2 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditLog.test.ts +216 -0
- package/test/mocks/AttributionRequest.ts +23 -0
- package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
- package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
- package/test/mocks/PhysicalActivityRequest.ts +23 -0
|
@@ -41,12 +41,11 @@ if (typeof Scorer === "undefined") {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Global search result kind enum, used by themes to style search results.
|
|
44
|
-
// prettier-ignore
|
|
45
44
|
class SearchResultKind {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
static get index() { return "index"; }
|
|
46
|
+
static get object() { return "object"; }
|
|
47
|
+
static get text() { return "text"; }
|
|
48
|
+
static get title() { return "title"; }
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
const _removeChildren = (element) => {
|
|
@@ -59,15 +58,6 @@ const _removeChildren = (element) => {
|
|
|
59
58
|
const _escapeRegExp = (string) =>
|
|
60
59
|
string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
|
61
60
|
|
|
62
|
-
const _escapeHTML = (text) => {
|
|
63
|
-
return text
|
|
64
|
-
.replaceAll("&", "&")
|
|
65
|
-
.replaceAll("<", "<")
|
|
66
|
-
.replaceAll(">", ">")
|
|
67
|
-
.replaceAll('"', """)
|
|
68
|
-
.replaceAll("'", "'");
|
|
69
|
-
};
|
|
70
|
-
|
|
71
61
|
const _displayItem = (item, searchTerms, highlightTerms) => {
|
|
72
62
|
const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
|
|
73
63
|
const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
|
|
@@ -100,30 +90,25 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
|
|
|
100
90
|
let linkEl = listItem.appendChild(document.createElement("a"));
|
|
101
91
|
linkEl.href = linkUrl + anchor;
|
|
102
92
|
linkEl.dataset.score = score;
|
|
103
|
-
linkEl.innerHTML =
|
|
93
|
+
linkEl.innerHTML = title;
|
|
104
94
|
if (descr) {
|
|
105
95
|
listItem.appendChild(document.createElement("span")).innerHTML =
|
|
106
|
-
|
|
96
|
+
" (" + descr + ")";
|
|
107
97
|
// highlight search terms in the description
|
|
108
|
-
if (SPHINX_HIGHLIGHT_ENABLED)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
} else if (showSearchSummary)
|
|
98
|
+
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
|
|
99
|
+
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
|
|
100
|
+
}
|
|
101
|
+
else if (showSearchSummary)
|
|
114
102
|
fetch(requestUrl)
|
|
115
103
|
.then((responseData) => responseData.text())
|
|
116
104
|
.then((data) => {
|
|
117
105
|
if (data)
|
|
118
106
|
listItem.appendChild(
|
|
119
|
-
Search.makeSearchSummary(data, searchTerms, anchor)
|
|
107
|
+
Search.makeSearchSummary(data, searchTerms, anchor)
|
|
120
108
|
);
|
|
121
109
|
// highlight search terms in the summary
|
|
122
|
-
if (SPHINX_HIGHLIGHT_ENABLED)
|
|
123
|
-
|
|
124
|
-
highlightTerms.forEach((term) =>
|
|
125
|
-
_highlightText(listItem, term, "highlighted"),
|
|
126
|
-
);
|
|
110
|
+
if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
|
|
111
|
+
highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
|
|
127
112
|
});
|
|
128
113
|
Search.output.appendChild(listItem);
|
|
129
114
|
};
|
|
@@ -132,14 +117,14 @@ const _finishSearch = (resultCount) => {
|
|
|
132
117
|
Search.title.innerText = _("Search Results");
|
|
133
118
|
if (!resultCount)
|
|
134
119
|
Search.status.innerText = Documentation.gettext(
|
|
135
|
-
"Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
|
|
120
|
+
"Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
|
|
136
121
|
);
|
|
137
122
|
else
|
|
138
123
|
Search.status.innerText = Documentation.ngettext(
|
|
139
124
|
"Search finished, found one page matching the search query.",
|
|
140
125
|
"Search finished, found ${resultCount} pages matching the search query.",
|
|
141
126
|
resultCount,
|
|
142
|
-
).replace(
|
|
127
|
+
).replace('${resultCount}', resultCount);
|
|
143
128
|
};
|
|
144
129
|
const _displayNextItem = (
|
|
145
130
|
results,
|
|
@@ -153,7 +138,7 @@ const _displayNextItem = (
|
|
|
153
138
|
_displayItem(results.pop(), searchTerms, highlightTerms);
|
|
154
139
|
setTimeout(
|
|
155
140
|
() => _displayNextItem(results, resultCount, searchTerms, highlightTerms),
|
|
156
|
-
5
|
|
141
|
+
5
|
|
157
142
|
);
|
|
158
143
|
}
|
|
159
144
|
// search finished, update title and status message
|
|
@@ -185,10 +170,9 @@ const _orderResultsByScoreThenName = (a, b) => {
|
|
|
185
170
|
* This is the same as ``\W+`` in Python, preserving the surrogate pair area.
|
|
186
171
|
*/
|
|
187
172
|
if (typeof splitQuery === "undefined") {
|
|
188
|
-
var splitQuery = (query) =>
|
|
189
|
-
query
|
|
173
|
+
var splitQuery = (query) => query
|
|
190
174
|
.split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}]+/gu)
|
|
191
|
-
.filter(
|
|
175
|
+
.filter(term => term) // remove remaining empty strings
|
|
192
176
|
}
|
|
193
177
|
|
|
194
178
|
/**
|
|
@@ -200,23 +184,16 @@ const Search = {
|
|
|
200
184
|
_pulse_status: -1,
|
|
201
185
|
|
|
202
186
|
htmlToText: (htmlString, anchor) => {
|
|
203
|
-
const htmlElement = new DOMParser().parseFromString(
|
|
204
|
-
htmlString,
|
|
205
|
-
"text/html",
|
|
206
|
-
);
|
|
187
|
+
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
|
|
207
188
|
for (const removalQuery of [".headerlink", "script", "style"]) {
|
|
208
|
-
htmlElement.querySelectorAll(removalQuery).forEach((el) => {
|
|
209
|
-
el.remove();
|
|
210
|
-
});
|
|
189
|
+
htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() });
|
|
211
190
|
}
|
|
212
191
|
if (anchor) {
|
|
213
|
-
const anchorContent = htmlElement.querySelector(
|
|
214
|
-
`[role="main"] ${anchor}`,
|
|
215
|
-
);
|
|
192
|
+
const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`);
|
|
216
193
|
if (anchorContent) return anchorContent.textContent;
|
|
217
194
|
|
|
218
195
|
console.warn(
|
|
219
|
-
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template
|
|
196
|
+
`Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`
|
|
220
197
|
);
|
|
221
198
|
}
|
|
222
199
|
|
|
@@ -225,7 +202,7 @@ const Search = {
|
|
|
225
202
|
if (docContent) return docContent.textContent;
|
|
226
203
|
|
|
227
204
|
console.warn(
|
|
228
|
-
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
|
|
205
|
+
"Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
|
|
229
206
|
);
|
|
230
207
|
return "";
|
|
231
208
|
},
|
|
@@ -310,8 +287,12 @@ const Search = {
|
|
|
310
287
|
const queryTermLower = queryTerm.toLowerCase();
|
|
311
288
|
|
|
312
289
|
// maybe skip this "word"
|
|
313
|
-
// stopwords
|
|
314
|
-
if (
|
|
290
|
+
// stopwords array is from language_data.js
|
|
291
|
+
if (
|
|
292
|
+
stopwords.indexOf(queryTermLower) !== -1 ||
|
|
293
|
+
queryTerm.match(/^\d+$/)
|
|
294
|
+
)
|
|
295
|
+
return;
|
|
315
296
|
|
|
316
297
|
// stem the word
|
|
317
298
|
let word = stemmer.stemWord(queryTermLower);
|
|
@@ -323,12 +304,8 @@ const Search = {
|
|
|
323
304
|
}
|
|
324
305
|
});
|
|
325
306
|
|
|
326
|
-
if (SPHINX_HIGHLIGHT_ENABLED) {
|
|
327
|
-
|
|
328
|
-
localStorage.setItem(
|
|
329
|
-
"sphinx_highlight_terms",
|
|
330
|
-
[...highlightTerms].join(" "),
|
|
331
|
-
);
|
|
307
|
+
if (SPHINX_HIGHLIGHT_ENABLED) { // set in sphinx_highlight.js
|
|
308
|
+
localStorage.setItem("sphinx_highlight_terms", [...highlightTerms].join(" "))
|
|
332
309
|
}
|
|
333
310
|
|
|
334
311
|
// console.debug("SEARCH: searching for:");
|
|
@@ -341,13 +318,7 @@ const Search = {
|
|
|
341
318
|
/**
|
|
342
319
|
* execute search (requires search index to be loaded)
|
|
343
320
|
*/
|
|
344
|
-
_performSearch: (
|
|
345
|
-
query,
|
|
346
|
-
searchTerms,
|
|
347
|
-
excludedTerms,
|
|
348
|
-
highlightTerms,
|
|
349
|
-
objectTerms,
|
|
350
|
-
) => {
|
|
321
|
+
_performSearch: (query, searchTerms, excludedTerms, highlightTerms, objectTerms) => {
|
|
351
322
|
const filenames = Search._index.filenames;
|
|
352
323
|
const docNames = Search._index.docnames;
|
|
353
324
|
const titles = Search._index.titles;
|
|
@@ -363,15 +334,10 @@ const Search = {
|
|
|
363
334
|
|
|
364
335
|
const queryLower = query.toLowerCase().trim();
|
|
365
336
|
for (const [title, foundTitles] of Object.entries(allTitles)) {
|
|
366
|
-
if (
|
|
367
|
-
title.toLowerCase().trim().includes(queryLower)
|
|
368
|
-
&& queryLower.length >= title.length / 2
|
|
369
|
-
) {
|
|
337
|
+
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
|
|
370
338
|
for (const [file, id] of foundTitles) {
|
|
371
|
-
const score = Math.round(
|
|
372
|
-
|
|
373
|
-
);
|
|
374
|
-
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
|
|
339
|
+
const score = Math.round(Scorer.title * queryLower.length / title.length);
|
|
340
|
+
const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
|
|
375
341
|
normalResults.push([
|
|
376
342
|
docNames[file],
|
|
377
343
|
titles[file] !== title ? `${titles[file]} > ${title}` : title,
|
|
@@ -387,9 +353,9 @@ const Search = {
|
|
|
387
353
|
|
|
388
354
|
// search for explicit entries in index directives
|
|
389
355
|
for (const [entry, foundEntries] of Object.entries(indexEntries)) {
|
|
390
|
-
if (entry.includes(queryLower) && queryLower.length >= entry.length
|
|
356
|
+
if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) {
|
|
391
357
|
for (const [file, id, isMain] of foundEntries) {
|
|
392
|
-
const score = Math.round(
|
|
358
|
+
const score = Math.round(100 * queryLower.length / entry.length);
|
|
393
359
|
const result = [
|
|
394
360
|
docNames[file],
|
|
395
361
|
titles[file],
|
|
@@ -410,13 +376,11 @@ const Search = {
|
|
|
410
376
|
|
|
411
377
|
// lookup as object
|
|
412
378
|
objectTerms.forEach((term) =>
|
|
413
|
-
normalResults.push(...Search.performObjectSearch(term, objectTerms))
|
|
379
|
+
normalResults.push(...Search.performObjectSearch(term, objectTerms))
|
|
414
380
|
);
|
|
415
381
|
|
|
416
382
|
// lookup as search terms in fulltext
|
|
417
|
-
normalResults.push(
|
|
418
|
-
...Search.performTermsSearch(searchTerms, excludedTerms),
|
|
419
|
-
);
|
|
383
|
+
normalResults.push(...Search.performTermsSearch(searchTerms, excludedTerms));
|
|
420
384
|
|
|
421
385
|
// let the scorer override scores with a custom scoring function
|
|
422
386
|
if (Scorer.score) {
|
|
@@ -437,11 +401,7 @@ const Search = {
|
|
|
437
401
|
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
|
|
438
402
|
let seen = new Set();
|
|
439
403
|
results = results.reverse().reduce((acc, result) => {
|
|
440
|
-
let resultStr = result
|
|
441
|
-
.slice(0, 4)
|
|
442
|
-
.concat([result[5]])
|
|
443
|
-
.map((v) => String(v))
|
|
444
|
-
.join(",");
|
|
404
|
+
let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
|
|
445
405
|
if (!seen.has(resultStr)) {
|
|
446
406
|
acc.push(result);
|
|
447
407
|
seen.add(resultStr);
|
|
@@ -453,20 +413,8 @@ const Search = {
|
|
|
453
413
|
},
|
|
454
414
|
|
|
455
415
|
query: (query) => {
|
|
456
|
-
const [
|
|
457
|
-
|
|
458
|
-
searchTerms,
|
|
459
|
-
excludedTerms,
|
|
460
|
-
highlightTerms,
|
|
461
|
-
objectTerms,
|
|
462
|
-
] = Search._parseQuery(query);
|
|
463
|
-
const results = Search._performSearch(
|
|
464
|
-
searchQuery,
|
|
465
|
-
searchTerms,
|
|
466
|
-
excludedTerms,
|
|
467
|
-
highlightTerms,
|
|
468
|
-
objectTerms,
|
|
469
|
-
);
|
|
416
|
+
const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] = Search._parseQuery(query);
|
|
417
|
+
const results = Search._performSearch(searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms);
|
|
470
418
|
|
|
471
419
|
// for debugging
|
|
472
420
|
//Search.lastresults = results.slice(); // a copy
|
|
@@ -489,7 +437,7 @@ const Search = {
|
|
|
489
437
|
const results = [];
|
|
490
438
|
|
|
491
439
|
const objectSearchCallback = (prefix, match) => {
|
|
492
|
-
const name = match[4]
|
|
440
|
+
const name = match[4]
|
|
493
441
|
const fullname = (prefix ? prefix + "." : "") + name;
|
|
494
442
|
const fullnameLower = fullname.toLowerCase();
|
|
495
443
|
if (fullnameLower.indexOf(object) < 0) return;
|
|
@@ -541,7 +489,9 @@ const Search = {
|
|
|
541
489
|
]);
|
|
542
490
|
};
|
|
543
491
|
Object.keys(objects).forEach((prefix) =>
|
|
544
|
-
objects[prefix].forEach((array) =>
|
|
492
|
+
objects[prefix].forEach((array) =>
|
|
493
|
+
objectSearchCallback(prefix, array)
|
|
494
|
+
)
|
|
545
495
|
);
|
|
546
496
|
return results;
|
|
547
497
|
},
|
|
@@ -563,17 +513,9 @@ const Search = {
|
|
|
563
513
|
// perform the search on the required terms
|
|
564
514
|
searchTerms.forEach((word) => {
|
|
565
515
|
const files = [];
|
|
566
|
-
// find documents, if any, containing the query word in their text/title term indices
|
|
567
|
-
// use Object.hasOwnProperty to avoid mismatching against prototype properties
|
|
568
516
|
const arr = [
|
|
569
|
-
{
|
|
570
|
-
|
|
571
|
-
score: Scorer.term,
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
files: titleTerms.hasOwnProperty(word) ? titleTerms[word] : undefined,
|
|
575
|
-
score: Scorer.title,
|
|
576
|
-
},
|
|
517
|
+
{ files: terms[word], score: Scorer.term },
|
|
518
|
+
{ files: titleTerms[word], score: Scorer.title },
|
|
577
519
|
];
|
|
578
520
|
// add support for partial matches
|
|
579
521
|
if (word.length > 2) {
|
|
@@ -605,17 +547,15 @@ const Search = {
|
|
|
605
547
|
|
|
606
548
|
// set score for the word in each file
|
|
607
549
|
recordFiles.forEach((file) => {
|
|
608
|
-
if (!scoreMap.has(file)) scoreMap.set(file,
|
|
609
|
-
|
|
610
|
-
fileScores.set(word, record.score);
|
|
550
|
+
if (!scoreMap.has(file)) scoreMap.set(file, {});
|
|
551
|
+
scoreMap.get(file)[word] = record.score;
|
|
611
552
|
});
|
|
612
553
|
});
|
|
613
554
|
|
|
614
555
|
// create the mapping
|
|
615
556
|
files.forEach((file) => {
|
|
616
557
|
if (!fileMap.has(file)) fileMap.set(file, [word]);
|
|
617
|
-
else if (fileMap.get(file).indexOf(word) === -1)
|
|
618
|
-
fileMap.get(file).push(word);
|
|
558
|
+
else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);
|
|
619
559
|
});
|
|
620
560
|
});
|
|
621
561
|
|
|
@@ -626,11 +566,11 @@ const Search = {
|
|
|
626
566
|
|
|
627
567
|
// as search terms with length < 3 are discarded
|
|
628
568
|
const filteredTermCount = [...searchTerms].filter(
|
|
629
|
-
(term) => term.length > 2
|
|
569
|
+
(term) => term.length > 2
|
|
630
570
|
).length;
|
|
631
571
|
if (
|
|
632
|
-
wordList.length !== searchTerms.size
|
|
633
|
-
|
|
572
|
+
wordList.length !== searchTerms.size &&
|
|
573
|
+
wordList.length !== filteredTermCount
|
|
634
574
|
)
|
|
635
575
|
continue;
|
|
636
576
|
|
|
@@ -638,16 +578,16 @@ const Search = {
|
|
|
638
578
|
if (
|
|
639
579
|
[...excludedTerms].some(
|
|
640
580
|
(term) =>
|
|
641
|
-
terms[term] === file
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
581
|
+
terms[term] === file ||
|
|
582
|
+
titleTerms[term] === file ||
|
|
583
|
+
(terms[term] || []).includes(file) ||
|
|
584
|
+
(titleTerms[term] || []).includes(file)
|
|
645
585
|
)
|
|
646
586
|
)
|
|
647
587
|
break;
|
|
648
588
|
|
|
649
589
|
// select one (max) score for the file.
|
|
650
|
-
const score = Math.max(...wordList.map((w) => scoreMap.get(file)
|
|
590
|
+
const score = Math.max(...wordList.map((w) => scoreMap.get(file)[w]));
|
|
651
591
|
// add result to the result list
|
|
652
592
|
results.push([
|
|
653
593
|
docNames[file],
|
|
@@ -683,8 +623,7 @@ const Search = {
|
|
|
683
623
|
|
|
684
624
|
let summary = document.createElement("p");
|
|
685
625
|
summary.classList.add("context");
|
|
686
|
-
summary.textContent =
|
|
687
|
-
top + text.substr(startWithContext, 240).trim() + tail;
|
|
626
|
+
summary.textContent = top + text.substr(startWithContext, 240).trim() + tail;
|
|
688
627
|
|
|
689
628
|
return summary;
|
|
690
629
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Highlighting utilities for Sphinx HTML documentation. */
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
const SPHINX_HIGHLIGHT_ENABLED = true
|
|
4
|
+
const SPHINX_HIGHLIGHT_ENABLED = true
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* highlight a given string on a node by wrapping it in
|
|
@@ -13,9 +13,9 @@ const _highlight = (node, addItems, text, className) => {
|
|
|
13
13
|
const parent = node.parentNode;
|
|
14
14
|
const pos = val.toLowerCase().indexOf(text);
|
|
15
15
|
if (
|
|
16
|
-
pos >= 0
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
pos >= 0 &&
|
|
17
|
+
!parent.classList.contains(className) &&
|
|
18
|
+
!parent.classList.contains("nohighlight")
|
|
19
19
|
) {
|
|
20
20
|
let span;
|
|
21
21
|
|
|
@@ -30,7 +30,13 @@ const _highlight = (node, addItems, text, className) => {
|
|
|
30
30
|
|
|
31
31
|
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
|
|
32
32
|
const rest = document.createTextNode(val.substr(pos + text.length));
|
|
33
|
-
parent.insertBefore(
|
|
33
|
+
parent.insertBefore(
|
|
34
|
+
span,
|
|
35
|
+
parent.insertBefore(
|
|
36
|
+
rest,
|
|
37
|
+
node.nextSibling
|
|
38
|
+
)
|
|
39
|
+
);
|
|
34
40
|
node.nodeValue = val.substr(0, pos);
|
|
35
41
|
/* There may be more occurrences of search term in this node. So call this
|
|
36
42
|
* function recursively on the remaining fragment.
|
|
@@ -40,7 +46,7 @@ const _highlight = (node, addItems, text, className) => {
|
|
|
40
46
|
if (isInSVG) {
|
|
41
47
|
const rect = document.createElementNS(
|
|
42
48
|
"http://www.w3.org/2000/svg",
|
|
43
|
-
"rect"
|
|
49
|
+
"rect"
|
|
44
50
|
);
|
|
45
51
|
const bbox = parent.getBBox();
|
|
46
52
|
rect.x.baseVal.value = bbox.x;
|
|
@@ -59,7 +65,7 @@ const _highlightText = (thisNode, text, className) => {
|
|
|
59
65
|
let addItems = [];
|
|
60
66
|
_highlight(thisNode, addItems, text, className);
|
|
61
67
|
addItems.forEach((obj) =>
|
|
62
|
-
obj.parent.insertAdjacentElement("beforebegin", obj.target)
|
|
68
|
+
obj.parent.insertAdjacentElement("beforebegin", obj.target)
|
|
63
69
|
);
|
|
64
70
|
};
|
|
65
71
|
|
|
@@ -67,31 +73,25 @@ const _highlightText = (thisNode, text, className) => {
|
|
|
67
73
|
* Small JavaScript module for the documentation.
|
|
68
74
|
*/
|
|
69
75
|
const SphinxHighlight = {
|
|
76
|
+
|
|
70
77
|
/**
|
|
71
78
|
* highlight the search words provided in localstorage in the text
|
|
72
79
|
*/
|
|
73
80
|
highlightSearchWords: () => {
|
|
74
|
-
if (!SPHINX_HIGHLIGHT_ENABLED) return;
|
|
81
|
+
if (!SPHINX_HIGHLIGHT_ENABLED) return; // bail if no highlight
|
|
75
82
|
|
|
76
83
|
// get and clear terms from localstorage
|
|
77
84
|
const url = new URL(window.location);
|
|
78
85
|
const highlight =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
localStorage.removeItem("sphinx_highlight_terms")
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (url.searchParams.has("highlight")) {
|
|
86
|
-
url.searchParams.delete("highlight");
|
|
87
|
-
window.history.replaceState({}, "", url);
|
|
88
|
-
}
|
|
86
|
+
localStorage.getItem("sphinx_highlight_terms")
|
|
87
|
+
|| url.searchParams.get("highlight")
|
|
88
|
+
|| "";
|
|
89
|
+
localStorage.removeItem("sphinx_highlight_terms")
|
|
90
|
+
url.searchParams.delete("highlight");
|
|
91
|
+
window.history.replaceState({}, "", url);
|
|
89
92
|
|
|
90
93
|
// get individual terms from highlight string
|
|
91
|
-
const terms = highlight
|
|
92
|
-
.toLowerCase()
|
|
93
|
-
.split(/\s+/)
|
|
94
|
-
.filter((x) => x);
|
|
94
|
+
const terms = highlight.toLowerCase().split(/\s+/).filter(x => x);
|
|
95
95
|
if (terms.length === 0) return; // nothing to do
|
|
96
96
|
|
|
97
97
|
// There should never be more than one element matching "div.body"
|
|
@@ -107,11 +107,11 @@ const SphinxHighlight = {
|
|
|
107
107
|
document
|
|
108
108
|
.createRange()
|
|
109
109
|
.createContextualFragment(
|
|
110
|
-
'<p class="highlight-link">'
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)
|
|
110
|
+
'<p class="highlight-link">' +
|
|
111
|
+
'<a href="javascript:SphinxHighlight.hideSearchWords()">' +
|
|
112
|
+
_("Hide Search Matches") +
|
|
113
|
+
"</a></p>"
|
|
114
|
+
)
|
|
115
115
|
);
|
|
116
116
|
},
|
|
117
117
|
|
|
@@ -125,7 +125,7 @@ const SphinxHighlight = {
|
|
|
125
125
|
document
|
|
126
126
|
.querySelectorAll("span.highlighted")
|
|
127
127
|
.forEach((el) => el.classList.remove("highlighted"));
|
|
128
|
-
localStorage.removeItem("sphinx_highlight_terms")
|
|
128
|
+
localStorage.removeItem("sphinx_highlight_terms")
|
|
129
129
|
},
|
|
130
130
|
|
|
131
131
|
initEscapeListener: () => {
|
|
@@ -134,15 +134,10 @@ const SphinxHighlight = {
|
|
|
134
134
|
|
|
135
135
|
document.addEventListener("keydown", (event) => {
|
|
136
136
|
// bail for input elements
|
|
137
|
-
if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName))
|
|
138
|
-
return;
|
|
137
|
+
if (BLACKLISTED_KEY_CONTROL_ELEMENTS.has(document.activeElement.tagName)) return;
|
|
139
138
|
// bail with special keys
|
|
140
|
-
if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey)
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS
|
|
144
|
-
&& event.key === "Escape"
|
|
145
|
-
) {
|
|
139
|
+
if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
140
|
+
if (DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS && (event.key === "Escape")) {
|
|
146
141
|
SphinxHighlight.hideSearchWords();
|
|
147
142
|
event.preventDefault();
|
|
148
143
|
}
|