searchsocket 0.3.3 → 0.5.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 +57 -39
- package/dist/cli.js +947 -1378
- package/dist/client.cjs +45 -0
- package/dist/client.d.cts +3 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +45 -1
- package/dist/index.cjs +909 -1286
- package/dist/index.d.cts +73 -33
- package/dist/index.d.ts +73 -33
- package/dist/index.js +906 -1281
- package/dist/plugin-B_npJSux.d.cts +36 -0
- package/dist/plugin-M-aW0ev6.d.ts +36 -0
- package/dist/scroll.cjs +185 -0
- package/dist/scroll.d.cts +42 -0
- package/dist/scroll.d.ts +42 -0
- package/dist/scroll.js +183 -0
- package/dist/sveltekit.cjs +997 -1204
- package/dist/sveltekit.d.cts +3 -43
- package/dist/sveltekit.d.ts +3 -43
- package/dist/sveltekit.js +995 -1202
- package/dist/{types-BrG6XTUU.d.cts → types-Dk43uz25.d.cts} +50 -109
- package/dist/{types-BrG6XTUU.d.ts → types-Dk43uz25.d.ts} +50 -109
- package/package.json +10 -3
package/dist/client.cjs
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/client.ts
|
|
4
|
+
var SNIPPET_TARGET_MAX_WORDS = 12;
|
|
5
|
+
function normalizeTargetText(value) {
|
|
6
|
+
return value.replace(/\u2026/g, " ").replace(/\.{3,}/g, " ").replace(/\s+/g, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
function shortenForTarget(value) {
|
|
9
|
+
const words = value.split(/\s+/).filter(Boolean);
|
|
10
|
+
if (words.length <= SNIPPET_TARGET_MAX_WORDS) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
return words.slice(0, SNIPPET_TARGET_MAX_WORDS).join(" ");
|
|
14
|
+
}
|
|
15
|
+
function selectTextTarget(result) {
|
|
16
|
+
const sectionTitle = normalizeTargetText(result.sectionTitle ?? "");
|
|
17
|
+
const snippetCandidate = normalizeTargetText(result.chunks?.[0]?.snippet ?? result.snippet);
|
|
18
|
+
if (snippetCandidate) {
|
|
19
|
+
if (!sectionTitle || snippetCandidate.toLowerCase().includes(sectionTitle.toLowerCase())) {
|
|
20
|
+
return shortenForTarget(snippetCandidate);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return sectionTitle;
|
|
24
|
+
}
|
|
25
|
+
function buildResultUrl(result) {
|
|
26
|
+
const textTarget = selectTextTarget(result);
|
|
27
|
+
if (!textTarget) {
|
|
28
|
+
return result.url;
|
|
29
|
+
}
|
|
30
|
+
const hashIdx = result.url.indexOf("#");
|
|
31
|
+
const beforeHash = hashIdx >= 0 ? result.url.slice(0, hashIdx) : result.url;
|
|
32
|
+
const existingHash = hashIdx >= 0 ? result.url.slice(hashIdx) : "";
|
|
33
|
+
const queryIdx = beforeHash.indexOf("?");
|
|
34
|
+
const path = queryIdx >= 0 ? beforeHash.slice(0, queryIdx) : beforeHash;
|
|
35
|
+
const existingQuery = queryIdx >= 0 ? beforeHash.slice(queryIdx + 1) : "";
|
|
36
|
+
const params = new URLSearchParams(existingQuery);
|
|
37
|
+
if (result.sectionTitle) {
|
|
38
|
+
params.set("_ssk", result.sectionTitle);
|
|
39
|
+
} else {
|
|
40
|
+
params.delete("_ssk");
|
|
41
|
+
}
|
|
42
|
+
params.set("_sskt", textTarget);
|
|
43
|
+
const textFragment = `:~:text=${encodeURIComponent(textTarget)}`;
|
|
44
|
+
const hashWithoutTextFragment = existingHash.replace(/:~:text=.*$/u, "");
|
|
45
|
+
const hash = existingHash ? `${hashWithoutTextFragment}${textFragment}` : `#${textFragment}`;
|
|
46
|
+
return `${path}?${params.toString()}${hash}`;
|
|
47
|
+
}
|
|
4
48
|
function createSearchClient(options = {}) {
|
|
5
49
|
const endpoint = options.endpoint ?? "/api/search";
|
|
6
50
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
@@ -31,6 +75,7 @@ function createSearchClient(options = {}) {
|
|
|
31
75
|
};
|
|
32
76
|
}
|
|
33
77
|
|
|
78
|
+
exports.buildResultUrl = buildResultUrl;
|
|
34
79
|
exports.createSearchClient = createSearchClient;
|
|
35
80
|
//# sourceMappingURL=client.cjs.map
|
|
36
81
|
//# sourceMappingURL=client.cjs.map
|
package/dist/client.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SearchRequest, a as SearchResponse } from './types-
|
|
1
|
+
import { S as SearchRequest, a as SearchResponse, b as SearchResult } from './types-Dk43uz25.cjs';
|
|
2
2
|
|
|
3
|
+
declare function buildResultUrl(result: SearchResult): string;
|
|
3
4
|
interface SearchClientOptions {
|
|
4
5
|
endpoint?: string;
|
|
5
6
|
fetchImpl?: typeof fetch;
|
|
@@ -8,4 +9,4 @@ declare function createSearchClient(options?: SearchClientOptions): {
|
|
|
8
9
|
search(request: SearchRequest): Promise<SearchResponse>;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export { type SearchClientOptions, createSearchClient };
|
|
12
|
+
export { type SearchClientOptions, buildResultUrl, createSearchClient };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SearchRequest, a as SearchResponse } from './types-
|
|
1
|
+
import { S as SearchRequest, a as SearchResponse, b as SearchResult } from './types-Dk43uz25.js';
|
|
2
2
|
|
|
3
|
+
declare function buildResultUrl(result: SearchResult): string;
|
|
3
4
|
interface SearchClientOptions {
|
|
4
5
|
endpoint?: string;
|
|
5
6
|
fetchImpl?: typeof fetch;
|
|
@@ -8,4 +9,4 @@ declare function createSearchClient(options?: SearchClientOptions): {
|
|
|
8
9
|
search(request: SearchRequest): Promise<SearchResponse>;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export { type SearchClientOptions, createSearchClient };
|
|
12
|
+
export { type SearchClientOptions, buildResultUrl, createSearchClient };
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
+
var SNIPPET_TARGET_MAX_WORDS = 12;
|
|
3
|
+
function normalizeTargetText(value) {
|
|
4
|
+
return value.replace(/\u2026/g, " ").replace(/\.{3,}/g, " ").replace(/\s+/g, " ").trim();
|
|
5
|
+
}
|
|
6
|
+
function shortenForTarget(value) {
|
|
7
|
+
const words = value.split(/\s+/).filter(Boolean);
|
|
8
|
+
if (words.length <= SNIPPET_TARGET_MAX_WORDS) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return words.slice(0, SNIPPET_TARGET_MAX_WORDS).join(" ");
|
|
12
|
+
}
|
|
13
|
+
function selectTextTarget(result) {
|
|
14
|
+
const sectionTitle = normalizeTargetText(result.sectionTitle ?? "");
|
|
15
|
+
const snippetCandidate = normalizeTargetText(result.chunks?.[0]?.snippet ?? result.snippet);
|
|
16
|
+
if (snippetCandidate) {
|
|
17
|
+
if (!sectionTitle || snippetCandidate.toLowerCase().includes(sectionTitle.toLowerCase())) {
|
|
18
|
+
return shortenForTarget(snippetCandidate);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return sectionTitle;
|
|
22
|
+
}
|
|
23
|
+
function buildResultUrl(result) {
|
|
24
|
+
const textTarget = selectTextTarget(result);
|
|
25
|
+
if (!textTarget) {
|
|
26
|
+
return result.url;
|
|
27
|
+
}
|
|
28
|
+
const hashIdx = result.url.indexOf("#");
|
|
29
|
+
const beforeHash = hashIdx >= 0 ? result.url.slice(0, hashIdx) : result.url;
|
|
30
|
+
const existingHash = hashIdx >= 0 ? result.url.slice(hashIdx) : "";
|
|
31
|
+
const queryIdx = beforeHash.indexOf("?");
|
|
32
|
+
const path = queryIdx >= 0 ? beforeHash.slice(0, queryIdx) : beforeHash;
|
|
33
|
+
const existingQuery = queryIdx >= 0 ? beforeHash.slice(queryIdx + 1) : "";
|
|
34
|
+
const params = new URLSearchParams(existingQuery);
|
|
35
|
+
if (result.sectionTitle) {
|
|
36
|
+
params.set("_ssk", result.sectionTitle);
|
|
37
|
+
} else {
|
|
38
|
+
params.delete("_ssk");
|
|
39
|
+
}
|
|
40
|
+
params.set("_sskt", textTarget);
|
|
41
|
+
const textFragment = `:~:text=${encodeURIComponent(textTarget)}`;
|
|
42
|
+
const hashWithoutTextFragment = existingHash.replace(/:~:text=.*$/u, "");
|
|
43
|
+
const hash = existingHash ? `${hashWithoutTextFragment}${textFragment}` : `#${textFragment}`;
|
|
44
|
+
return `${path}?${params.toString()}${hash}`;
|
|
45
|
+
}
|
|
2
46
|
function createSearchClient(options = {}) {
|
|
3
47
|
const endpoint = options.endpoint ?? "/api/search";
|
|
4
48
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
@@ -29,6 +73,6 @@ function createSearchClient(options = {}) {
|
|
|
29
73
|
};
|
|
30
74
|
}
|
|
31
75
|
|
|
32
|
-
export { createSearchClient };
|
|
76
|
+
export { buildResultUrl, createSearchClient };
|
|
33
77
|
//# sourceMappingURL=client.js.map
|
|
34
78
|
//# sourceMappingURL=client.js.map
|