toolcraft-openapi 0.0.169 → 0.0.170

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.
@@ -33,12 +33,12 @@
33
33
  },
34
34
  {
35
35
  "name": "toolcraft-openapi",
36
- "version": "0.0.169",
36
+ "version": "0.0.170",
37
37
  "license": "MIT"
38
38
  },
39
39
  {
40
40
  "name": "toolcraft-schema",
41
- "version": "0.0.169",
41
+ "version": "0.0.170",
42
42
  "license": "MIT"
43
43
  },
44
44
  {
@@ -1,3 +1,4 @@
1
+ import { graphemes } from "../dashboard/terminal-width.js";
1
2
  const MATCH_SCORE = 10;
2
3
  const CONSECUTIVE_BONUS = 14;
3
4
  const WORD_START_BONUS = 10;
@@ -13,7 +14,11 @@ export function filterRows(query, rows, opts = {}) {
13
14
  const preparedText = opts.caseSensitive === true ? text : text.toLocaleLowerCase();
14
15
  const match = matchSubsequence(preparedQuery, preparedText);
15
16
  if (match !== undefined) {
16
- matches.push({ index, ...match });
17
+ matches.push({
18
+ index,
19
+ ...match,
20
+ positions: text === preparedText ? match.positions : projectPositions(text, match.positions)
21
+ });
17
22
  }
18
23
  });
19
24
  return matches.sort((left, right) => right.score - left.score || left.index - right.index);
@@ -27,6 +32,33 @@ function searchableText(row) {
27
32
  function stripAnsi(value) {
28
33
  return value.replace(/\u001b\[[0-9;]*m/g, "");
29
34
  }
35
+ function projectPositions(text, positions) {
36
+ const projected = [];
37
+ let originalOffset = 0;
38
+ let foldedOffset = 0;
39
+ let matchIndex = 0;
40
+ for (const segment of graphemes(text)) {
41
+ const foldedLength = segment.toLocaleLowerCase().length;
42
+ const firstMatch = matchIndex;
43
+ while (matchIndex < positions.length && positions[matchIndex] < foldedOffset + foldedLength) {
44
+ if (segment.length === foldedLength) {
45
+ projected.push(originalOffset + positions[matchIndex] - foldedOffset);
46
+ }
47
+ matchIndex += 1;
48
+ }
49
+ if (matchIndex > firstMatch && segment.length !== foldedLength) {
50
+ for (let offset = 0; offset < segment.length; offset += 1) {
51
+ projected.push(originalOffset + offset);
52
+ }
53
+ }
54
+ if (matchIndex === positions.length) {
55
+ break;
56
+ }
57
+ originalOffset += segment.length;
58
+ foldedOffset += foldedLength;
59
+ }
60
+ return projected;
61
+ }
30
62
  function matchSubsequence(query, text) {
31
63
  const queryCharacters = Array.from(query);
32
64
  const textCharacters = Array.from(text);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.169",
3
+ "version": "0.0.170",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-openapi",
3
- "version": "0.0.169",
3
+ "version": "0.0.170",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "toolcraft-openapi-generate": "dist/bin/generate.js"
31
31
  },
32
32
  "dependencies": {
33
- "toolcraft": "0.0.169",
33
+ "toolcraft": "0.0.170",
34
34
  "fast-string-width": "^3.0.2",
35
35
  "fast-wrap-ansi": "^0.2.0",
36
36
  "sisteransi": "^1.0.5",
@@ -45,7 +45,7 @@
45
45
  "directory": "packages/toolcraft-openapi"
46
46
  },
47
47
  "optionalDependencies": {
48
- "toolcraft-schema": "0.0.169",
48
+ "toolcraft-schema": "0.0.170",
49
49
  "toolcraft-design": "*",
50
50
  "@poe-code/frontmatter": "*"
51
51
  },