koffi 2.1.0-beta.1 → 2.1.0-beta.2

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.
Files changed (99) hide show
  1. package/CMakeLists.txt +1 -1
  2. package/ChangeLog.md +17 -0
  3. package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  4. package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  5. package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  6. package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  7. package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  8. package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  9. package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  10. package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  11. package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  17. package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
  18. package/doc/functions.md +67 -1
  19. package/doc/templates/badges.html +1 -2
  20. package/doc/types.md +100 -147
  21. package/package.json +1 -1
  22. package/src/abi_arm32.cc +166 -2
  23. package/src/abi_arm64.cc +195 -2
  24. package/src/abi_riscv64.cc +106 -2
  25. package/src/abi_x64_sysv.cc +113 -3
  26. package/src/abi_x64_win.cc +112 -2
  27. package/src/abi_x86.cc +155 -4
  28. package/src/call.cc +199 -0
  29. package/src/ffi.cc +50 -18
  30. package/src/ffi.hh +12 -0
  31. package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
  32. package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
  33. package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
  34. package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
  35. package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
  36. package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
  37. package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
  38. package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
  39. package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  40. package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
  41. package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
  42. package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
  43. package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
  44. package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
  45. package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
  46. package/doc/dist/html/.buildinfo +0 -4
  47. package/doc/dist/html/_sources/benchmarks.md.txt +0 -137
  48. package/doc/dist/html/_sources/changes.md.txt +0 -161
  49. package/doc/dist/html/_sources/contribute.md.txt +0 -127
  50. package/doc/dist/html/_sources/functions.md.txt +0 -355
  51. package/doc/dist/html/_sources/index.rst.txt +0 -39
  52. package/doc/dist/html/_sources/memory.md.txt +0 -32
  53. package/doc/dist/html/_sources/platforms.md.txt +0 -31
  54. package/doc/dist/html/_sources/start.md.txt +0 -100
  55. package/doc/dist/html/_sources/types.md.txt +0 -588
  56. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +0 -134
  57. package/doc/dist/html/_static/basic.css +0 -932
  58. package/doc/dist/html/_static/bench_linux.png +0 -0
  59. package/doc/dist/html/_static/bench_windows.png +0 -0
  60. package/doc/dist/html/_static/custom.css +0 -22
  61. package/doc/dist/html/_static/debug.css +0 -69
  62. package/doc/dist/html/_static/doctools.js +0 -264
  63. package/doc/dist/html/_static/documentation_options.js +0 -14
  64. package/doc/dist/html/_static/file.png +0 -0
  65. package/doc/dist/html/_static/jquery-3.6.0.js +0 -10881
  66. package/doc/dist/html/_static/jquery.js +0 -2
  67. package/doc/dist/html/_static/language_data.js +0 -199
  68. package/doc/dist/html/_static/minus.png +0 -0
  69. package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
  70. package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
  71. package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
  72. package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
  73. package/doc/dist/html/_static/plus.png +0 -0
  74. package/doc/dist/html/_static/pygments.css +0 -252
  75. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  76. package/doc/dist/html/_static/scripts/furo.js +0 -3
  77. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +0 -7
  78. package/doc/dist/html/_static/scripts/furo.js.map +0 -1
  79. package/doc/dist/html/_static/searchtools.js +0 -531
  80. package/doc/dist/html/_static/skeleton.css +0 -296
  81. package/doc/dist/html/_static/styles/furo-extensions.css +0 -2
  82. package/doc/dist/html/_static/styles/furo-extensions.css.map +0 -1
  83. package/doc/dist/html/_static/styles/furo.css +0 -2
  84. package/doc/dist/html/_static/styles/furo.css.map +0 -1
  85. package/doc/dist/html/_static/underscore-1.13.1.js +0 -2042
  86. package/doc/dist/html/_static/underscore.js +0 -6
  87. package/doc/dist/html/benchmarks.html +0 -572
  88. package/doc/dist/html/changes.html +0 -668
  89. package/doc/dist/html/contribute.html +0 -404
  90. package/doc/dist/html/functions.html +0 -657
  91. package/doc/dist/html/genindex.html +0 -254
  92. package/doc/dist/html/index.html +0 -360
  93. package/doc/dist/html/memory.html +0 -347
  94. package/doc/dist/html/objects.inv +0 -0
  95. package/doc/dist/html/platforms.html +0 -372
  96. package/doc/dist/html/search.html +0 -262
  97. package/doc/dist/html/searchindex.js +0 -1
  98. package/doc/dist/html/start.html +0 -385
  99. package/doc/dist/html/types.html +0 -1097
@@ -1,531 +0,0 @@
1
- /*
2
- * searchtools.js
3
- * ~~~~~~~~~~~~~~~~
4
- *
5
- * Sphinx JavaScript utilities for the full-text search.
6
- *
7
- * :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
8
- * :license: BSD, see LICENSE for details.
9
- *
10
- */
11
- "use strict";
12
-
13
- /**
14
- * Simple result scoring code.
15
- */
16
- if (typeof Scorer === "undefined") {
17
- var Scorer = {
18
- // Implement the following function to further tweak the score for each result
19
- // The function takes a result array [docname, title, anchor, descr, score, filename]
20
- // and returns the new score.
21
- /*
22
- score: result => {
23
- const [docname, title, anchor, descr, score, filename] = result
24
- return score
25
- },
26
- */
27
-
28
- // query matches the full name of an object
29
- objNameMatch: 11,
30
- // or matches in the last dotted part of the object name
31
- objPartialMatch: 6,
32
- // Additive scores depending on the priority of the object
33
- objPrio: {
34
- 0: 15, // used to be importantResults
35
- 1: 5, // used to be objectResults
36
- 2: -5, // used to be unimportantResults
37
- },
38
- // Used when the priority is not in the mapping.
39
- objPrioDefault: 0,
40
-
41
- // query found in title
42
- title: 15,
43
- partialTitle: 7,
44
- // query found in terms
45
- term: 5,
46
- partialTerm: 2,
47
- };
48
- }
49
-
50
- const _removeChildren = (element) => {
51
- while (element && element.lastChild) element.removeChild(element.lastChild);
52
- };
53
-
54
- /**
55
- * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
56
- */
57
- const _escapeRegExp = (string) =>
58
- string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
59
-
60
- const _displayItem = (item, highlightTerms, searchTerms) => {
61
- const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
62
- const docUrlRoot = DOCUMENTATION_OPTIONS.URL_ROOT;
63
- const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
64
- const docLinkSuffix = DOCUMENTATION_OPTIONS.LINK_SUFFIX;
65
- const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
66
-
67
- const [docName, title, anchor, descr] = item;
68
-
69
- let listItem = document.createElement("li");
70
- let requestUrl;
71
- let linkUrl;
72
- if (docBuilder === "dirhtml") {
73
- // dirhtml builder
74
- let dirname = docName + "/";
75
- if (dirname.match(/\/index\/$/))
76
- dirname = dirname.substring(0, dirname.length - 6);
77
- else if (dirname === "index/") dirname = "";
78
- requestUrl = docUrlRoot + dirname;
79
- linkUrl = requestUrl;
80
- } else {
81
- // normal html builders
82
- requestUrl = docUrlRoot + docName + docFileSuffix;
83
- linkUrl = docName + docLinkSuffix;
84
- }
85
- const params = new URLSearchParams();
86
- params.set("highlight", [...highlightTerms].join(" "));
87
- let linkEl = listItem.appendChild(document.createElement("a"));
88
- linkEl.href = linkUrl + "?" + params.toString() + anchor;
89
- linkEl.innerHTML = title;
90
- if (descr)
91
- listItem.appendChild(document.createElement("span")).innerText =
92
- " (" + descr + ")";
93
- else if (showSearchSummary)
94
- fetch(requestUrl)
95
- .then((responseData) => responseData.text())
96
- .then((data) => {
97
- if (data)
98
- listItem.appendChild(
99
- Search.makeSearchSummary(data, searchTerms, highlightTerms)
100
- );
101
- });
102
- Search.output.appendChild(listItem);
103
- };
104
- const _finishSearch = (resultCount) => {
105
- Search.stopPulse();
106
- Search.title.innerText = _("Search Results");
107
- if (!resultCount)
108
- Search.status.innerText = Documentation.gettext(
109
- "Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
110
- );
111
- else
112
- Search.status.innerText = _(
113
- `Search finished, found ${resultCount} page(s) matching the search query.`
114
- );
115
- };
116
- const _displayNextItem = (
117
- results,
118
- resultCount,
119
- highlightTerms,
120
- searchTerms
121
- ) => {
122
- // results left, load the summary and display it
123
- // this is intended to be dynamic (don't sub resultsCount)
124
- if (results.length) {
125
- _displayItem(results.pop(), highlightTerms, searchTerms);
126
- setTimeout(
127
- () => _displayNextItem(results, resultCount, highlightTerms, searchTerms),
128
- 5
129
- );
130
- }
131
- // search finished, update title and status message
132
- else _finishSearch(resultCount);
133
- };
134
-
135
- /**
136
- * Default splitQuery function. Can be overridden in ``sphinx.search`` with a
137
- * custom function per language.
138
- *
139
- * The regular expression works by splitting the string on consecutive characters
140
- * that are not Unicode letters, numbers, underscores, or emoji characters.
141
- * This is the same as ``\W+`` in Python, preserving the surrogate pair area.
142
- */
143
- if (typeof splitQuery === "undefined") {
144
- var splitQuery = (query) => query
145
- .split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}]+/gu)
146
- .filter(term => term) // remove remaining empty strings
147
- }
148
-
149
- /**
150
- * Search Module
151
- */
152
- const Search = {
153
- _index: null,
154
- _queued_query: null,
155
- _pulse_status: -1,
156
-
157
- htmlToText: (htmlString) => {
158
- const htmlElement = document
159
- .createRange()
160
- .createContextualFragment(htmlString);
161
- _removeChildren(htmlElement.querySelectorAll(".headerlink"));
162
- const docContent = htmlElement.querySelector('[role="main"]');
163
- if (docContent !== undefined) return docContent.textContent;
164
- console.warn(
165
- "Content block not found. Sphinx search tries to obtain it via '[role=main]'. Could you check your theme or template."
166
- );
167
- return "";
168
- },
169
-
170
- init: () => {
171
- const query = new URLSearchParams(window.location.search).get("q");
172
- document
173
- .querySelectorAll('input[name="q"]')
174
- .forEach((el) => (el.value = query));
175
- if (query) Search.performSearch(query);
176
- },
177
-
178
- loadIndex: (url) =>
179
- (document.body.appendChild(document.createElement("script")).src = url),
180
-
181
- setIndex: (index) => {
182
- Search._index = index;
183
- if (Search._queued_query !== null) {
184
- const query = Search._queued_query;
185
- Search._queued_query = null;
186
- Search.query(query);
187
- }
188
- },
189
-
190
- hasIndex: () => Search._index !== null,
191
-
192
- deferQuery: (query) => (Search._queued_query = query),
193
-
194
- stopPulse: () => (Search._pulse_status = -1),
195
-
196
- startPulse: () => {
197
- if (Search._pulse_status >= 0) return;
198
-
199
- const pulse = () => {
200
- Search._pulse_status = (Search._pulse_status + 1) % 4;
201
- Search.dots.innerText = ".".repeat(Search._pulse_status);
202
- if (Search._pulse_status >= 0) window.setTimeout(pulse, 500);
203
- };
204
- pulse();
205
- },
206
-
207
- /**
208
- * perform a search for something (or wait until index is loaded)
209
- */
210
- performSearch: (query) => {
211
- // create the required interface elements
212
- const searchText = document.createElement("h2");
213
- searchText.textContent = _("Searching");
214
- const searchSummary = document.createElement("p");
215
- searchSummary.classList.add("search-summary");
216
- searchSummary.innerText = "";
217
- const searchList = document.createElement("ul");
218
- searchList.classList.add("search");
219
-
220
- const out = document.getElementById("search-results");
221
- Search.title = out.appendChild(searchText);
222
- Search.dots = Search.title.appendChild(document.createElement("span"));
223
- Search.status = out.appendChild(searchSummary);
224
- Search.output = out.appendChild(searchList);
225
-
226
- const searchProgress = document.getElementById("search-progress");
227
- // Some themes don't use the search progress node
228
- if (searchProgress) {
229
- searchProgress.innerText = _("Preparing search...");
230
- }
231
- Search.startPulse();
232
-
233
- // index already loaded, the browser was quick!
234
- if (Search.hasIndex()) Search.query(query);
235
- else Search.deferQuery(query);
236
- },
237
-
238
- /**
239
- * execute search (requires search index to be loaded)
240
- */
241
- query: (query) => {
242
- // stem the search terms and add them to the correct list
243
- const stemmer = new Stemmer();
244
- const searchTerms = new Set();
245
- const excludedTerms = new Set();
246
- const highlightTerms = new Set();
247
- const objectTerms = new Set(splitQuery(query.toLowerCase().trim()));
248
- splitQuery(query.trim()).forEach((queryTerm) => {
249
- const queryTermLower = queryTerm.toLowerCase();
250
-
251
- // maybe skip this "word"
252
- // stopwords array is from language_data.js
253
- if (
254
- stopwords.indexOf(queryTermLower) !== -1 ||
255
- queryTerm.match(/^\d+$/)
256
- )
257
- return;
258
-
259
- // stem the word
260
- let word = stemmer.stemWord(queryTermLower);
261
- // select the correct list
262
- if (word[0] === "-") excludedTerms.add(word.substr(1));
263
- else {
264
- searchTerms.add(word);
265
- highlightTerms.add(queryTermLower);
266
- }
267
- });
268
-
269
- // console.debug("SEARCH: searching for:");
270
- // console.info("required: ", [...searchTerms]);
271
- // console.info("excluded: ", [...excludedTerms]);
272
-
273
- // array of [docname, title, anchor, descr, score, filename]
274
- let results = [];
275
- _removeChildren(document.getElementById("search-progress"));
276
-
277
- // lookup as object
278
- objectTerms.forEach((term) =>
279
- results.push(...Search.performObjectSearch(term, objectTerms))
280
- );
281
-
282
- // lookup as search terms in fulltext
283
- results.push(...Search.performTermsSearch(searchTerms, excludedTerms));
284
-
285
- // let the scorer override scores with a custom scoring function
286
- if (Scorer.score) results.forEach((item) => (item[4] = Scorer.score(item)));
287
-
288
- // now sort the results by score (in opposite order of appearance, since the
289
- // display function below uses pop() to retrieve items) and then
290
- // alphabetically
291
- results.sort((a, b) => {
292
- const leftScore = a[4];
293
- const rightScore = b[4];
294
- if (leftScore === rightScore) {
295
- // same score: sort alphabetically
296
- const leftTitle = a[1].toLowerCase();
297
- const rightTitle = b[1].toLowerCase();
298
- if (leftTitle === rightTitle) return 0;
299
- return leftTitle > rightTitle ? -1 : 1; // inverted is intentional
300
- }
301
- return leftScore > rightScore ? 1 : -1;
302
- });
303
-
304
- // remove duplicate search results
305
- // note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
306
- let seen = new Set();
307
- results = results.reverse().reduce((acc, result) => {
308
- let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
309
- if (!seen.has(resultStr)) {
310
- acc.push(result);
311
- seen.add(resultStr);
312
- }
313
- return acc;
314
- }, []);
315
-
316
- results = results.reverse();
317
-
318
- // for debugging
319
- //Search.lastresults = results.slice(); // a copy
320
- // console.info("search results:", Search.lastresults);
321
-
322
- // print the results
323
- _displayNextItem(results, results.length, highlightTerms, searchTerms);
324
- },
325
-
326
- /**
327
- * search for object names
328
- */
329
- performObjectSearch: (object, objectTerms) => {
330
- const filenames = Search._index.filenames;
331
- const docNames = Search._index.docnames;
332
- const objects = Search._index.objects;
333
- const objNames = Search._index.objnames;
334
- const titles = Search._index.titles;
335
-
336
- const results = [];
337
-
338
- const objectSearchCallback = (prefix, match) => {
339
- const name = match[4]
340
- const fullname = (prefix ? prefix + "." : "") + name;
341
- const fullnameLower = fullname.toLowerCase();
342
- if (fullnameLower.indexOf(object) < 0) return;
343
-
344
- let score = 0;
345
- const parts = fullnameLower.split(".");
346
-
347
- // check for different match types: exact matches of full name or
348
- // "last name" (i.e. last dotted part)
349
- if (fullnameLower === object || parts.slice(-1)[0] === object)
350
- score += Scorer.objNameMatch;
351
- else if (parts.slice(-1)[0].indexOf(object) > -1)
352
- score += Scorer.objPartialMatch; // matches in last name
353
-
354
- const objName = objNames[match[1]][2];
355
- const title = titles[match[0]];
356
-
357
- // If more than one term searched for, we require other words to be
358
- // found in the name/title/description
359
- const otherTerms = new Set(objectTerms);
360
- otherTerms.delete(object);
361
- if (otherTerms.size > 0) {
362
- const haystack = `${prefix} ${name} ${objName} ${title}`.toLowerCase();
363
- if (
364
- [...otherTerms].some((otherTerm) => haystack.indexOf(otherTerm) < 0)
365
- )
366
- return;
367
- }
368
-
369
- let anchor = match[3];
370
- if (anchor === "") anchor = fullname;
371
- else if (anchor === "-") anchor = objNames[match[1]][1] + "-" + fullname;
372
-
373
- const descr = objName + _(", in ") + title;
374
-
375
- // add custom score for some objects according to scorer
376
- if (Scorer.objPrio.hasOwnProperty(match[2]))
377
- score += Scorer.objPrio[match[2]];
378
- else score += Scorer.objPrioDefault;
379
-
380
- results.push([
381
- docNames[match[0]],
382
- fullname,
383
- "#" + anchor,
384
- descr,
385
- score,
386
- filenames[match[0]],
387
- ]);
388
- };
389
- Object.keys(objects).forEach((prefix) =>
390
- objects[prefix].forEach((array) =>
391
- objectSearchCallback(prefix, array)
392
- )
393
- );
394
- return results;
395
- },
396
-
397
- /**
398
- * search for full-text terms in the index
399
- */
400
- performTermsSearch: (searchTerms, excludedTerms) => {
401
- // prepare search
402
- const terms = Search._index.terms;
403
- const titleTerms = Search._index.titleterms;
404
- const docNames = Search._index.docnames;
405
- const filenames = Search._index.filenames;
406
- const titles = Search._index.titles;
407
-
408
- const scoreMap = new Map();
409
- const fileMap = new Map();
410
-
411
- // perform the search on the required terms
412
- searchTerms.forEach((word) => {
413
- const files = [];
414
- const arr = [
415
- { files: terms[word], score: Scorer.term },
416
- { files: titleTerms[word], score: Scorer.title },
417
- ];
418
- // add support for partial matches
419
- if (word.length > 2) {
420
- const escapedWord = _escapeRegExp(word);
421
- Object.keys(terms).forEach((term) => {
422
- if (term.match(escapedWord) && !terms[word])
423
- arr.push({ files: terms[term], score: Scorer.partialTerm });
424
- });
425
- Object.keys(titleTerms).forEach((term) => {
426
- if (term.match(escapedWord) && !titleTerms[word])
427
- arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
428
- });
429
- }
430
-
431
- // no match but word was a required one
432
- if (arr.every((record) => record.files === undefined)) return;
433
-
434
- // found search word in contents
435
- arr.forEach((record) => {
436
- if (record.files === undefined) return;
437
-
438
- let recordFiles = record.files;
439
- if (recordFiles.length === undefined) recordFiles = [recordFiles];
440
- files.push(...recordFiles);
441
-
442
- // set score for the word in each file
443
- recordFiles.forEach((file) => {
444
- if (!scoreMap.has(file)) scoreMap.set(file, {});
445
- scoreMap.get(file)[word] = record.score;
446
- });
447
- });
448
-
449
- // create the mapping
450
- files.forEach((file) => {
451
- if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
452
- fileMap.get(file).push(word);
453
- else fileMap.set(file, [word]);
454
- });
455
- });
456
-
457
- // now check if the files don't contain excluded terms
458
- const results = [];
459
- for (const [file, wordList] of fileMap) {
460
- // check if all requirements are matched
461
-
462
- // as search terms with length < 3 are discarded
463
- const filteredTermCount = [...searchTerms].filter(
464
- (term) => term.length > 2
465
- ).length;
466
- if (
467
- wordList.length !== searchTerms.size &&
468
- wordList.length !== filteredTermCount
469
- )
470
- continue;
471
-
472
- // ensure that none of the excluded terms is in the search result
473
- if (
474
- [...excludedTerms].some(
475
- (term) =>
476
- terms[term] === file ||
477
- titleTerms[term] === file ||
478
- (terms[term] || []).includes(file) ||
479
- (titleTerms[term] || []).includes(file)
480
- )
481
- )
482
- break;
483
-
484
- // select one (max) score for the file.
485
- const score = Math.max(...wordList.map((w) => scoreMap.get(file)[w]));
486
- // add result to the result list
487
- results.push([
488
- docNames[file],
489
- titles[file],
490
- "",
491
- null,
492
- score,
493
- filenames[file],
494
- ]);
495
- }
496
- return results;
497
- },
498
-
499
- /**
500
- * helper function to return a node containing the
501
- * search summary for a given text. keywords is a list
502
- * of stemmed words, highlightWords is the list of normal, unstemmed
503
- * words. the first one is used to find the occurrence, the
504
- * latter for highlighting it.
505
- */
506
- makeSearchSummary: (htmlText, keywords, highlightWords) => {
507
- const text = Search.htmlToText(htmlText).toLowerCase();
508
- if (text === "") return null;
509
-
510
- const actualStartPosition = [...keywords]
511
- .map((k) => text.indexOf(k.toLowerCase()))
512
- .filter((i) => i > -1)
513
- .slice(-1)[0];
514
- const startWithContext = Math.max(actualStartPosition - 120, 0);
515
-
516
- const top = startWithContext === 0 ? "" : "...";
517
- const tail = startWithContext + 240 < text.length ? "..." : "";
518
-
519
- let summary = document.createElement("div");
520
- summary.classList.add("context");
521
- summary.innerText = top + text.substr(startWithContext, 240).trim() + tail;
522
-
523
- highlightWords.forEach((highlightWord) =>
524
- _highlightText(summary, highlightWord, "highlighted")
525
- );
526
-
527
- return summary;
528
- },
529
- };
530
-
531
- _ready(Search.init);