@oh-my-pi/pi-natives 8.12.4 → 8.12.7
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/package.json +2 -2
- package/src/index.ts +13 -0
- package/src/text/index.ts +64 -0
- package/wasm/pi_natives.d.ts +22 -1
- package/wasm/pi_natives.js +77 -2
- package/wasm/pi_natives_bg.wasm +0 -0
- package/wasm/pi_natives_bg.wasm.d.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-natives",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.7",
|
|
4
4
|
"description": "Native Rust functionality compiled to WebAssembly via wasm-bindgen",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"directory": "packages/natives"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@oh-my-pi/pi-utils": "8.12.
|
|
33
|
+
"@oh-my-pi/pi-utils": "8.12.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.0.10"
|
package/src/index.ts
CHANGED
|
@@ -133,6 +133,19 @@ export {
|
|
|
133
133
|
terminate as terminateImageWorker,
|
|
134
134
|
} from "./image/index";
|
|
135
135
|
|
|
136
|
+
// =============================================================================
|
|
137
|
+
// Text utilities
|
|
138
|
+
// =============================================================================
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
type ExtractSegmentsResult,
|
|
142
|
+
extractSegments,
|
|
143
|
+
type SliceWithWidthResult,
|
|
144
|
+
sliceWithWidth,
|
|
145
|
+
truncateToWidth,
|
|
146
|
+
visibleWidth,
|
|
147
|
+
} from "./text/index";
|
|
148
|
+
|
|
136
149
|
// =============================================================================
|
|
137
150
|
// Worker Pool (shared infrastructure)
|
|
138
151
|
// =============================================================================
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ANSI-aware text utilities powered by WASM.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as wasm from "../../wasm/pi_natives";
|
|
6
|
+
|
|
7
|
+
export interface SliceWithWidthResult {
|
|
8
|
+
text: string;
|
|
9
|
+
width: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ExtractSegmentsResult {
|
|
13
|
+
before: string;
|
|
14
|
+
beforeWidth: number;
|
|
15
|
+
after: string;
|
|
16
|
+
afterWidth: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type WasmTextExports = typeof wasm & {
|
|
20
|
+
visible_width: (text: string) => number;
|
|
21
|
+
truncate_to_width: (text: string, maxWidth: number, ellipsis: string, pad: boolean) => string;
|
|
22
|
+
slice_with_width: (line: string, startCol: number, length: number, strict: boolean) => SliceWithWidthResult;
|
|
23
|
+
extract_segments: (
|
|
24
|
+
line: string,
|
|
25
|
+
beforeEnd: number,
|
|
26
|
+
afterStart: number,
|
|
27
|
+
afterLen: number,
|
|
28
|
+
strictAfter: boolean,
|
|
29
|
+
) => ExtractSegmentsResult;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const wasmText = wasm as WasmTextExports;
|
|
33
|
+
|
|
34
|
+
/** Compute the visible width of a string, ignoring ANSI codes. */
|
|
35
|
+
export function visibleWidth(text: string): number {
|
|
36
|
+
return wasmText.visible_width(text);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Truncate a string to a visible width, preserving ANSI codes.
|
|
41
|
+
*/
|
|
42
|
+
export function truncateToWidth(text: string, maxWidth: number, ellipsis = "…", pad = false): string {
|
|
43
|
+
return wasmText.truncate_to_width(text, maxWidth, ellipsis, pad);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Slice a range of visible columns from a line.
|
|
48
|
+
*/
|
|
49
|
+
export function sliceWithWidth(line: string, startCol: number, length: number, strict = false): SliceWithWidthResult {
|
|
50
|
+
return wasmText.slice_with_width(line, startCol, length, strict);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Extract before/after segments around an overlay region.
|
|
55
|
+
*/
|
|
56
|
+
export function extractSegments(
|
|
57
|
+
line: string,
|
|
58
|
+
beforeEnd: number,
|
|
59
|
+
afterStart: number,
|
|
60
|
+
afterLen: number,
|
|
61
|
+
strictAfter = false,
|
|
62
|
+
): ExtractSegmentsResult {
|
|
63
|
+
return wasmText.extract_segments(line, beforeEnd, afterStart, afterLen, strictAfter);
|
|
64
|
+
}
|
package/wasm/pi_natives.d.ts
CHANGED
|
@@ -55,7 +55,8 @@ export class PhotonImage {
|
|
|
55
55
|
*/
|
|
56
56
|
get_width(): number;
|
|
57
57
|
/**
|
|
58
|
-
* Create a new PhotonImage from encoded image bytes (PNG, JPEG, WebP,
|
|
58
|
+
* Create a new `PhotonImage` from encoded image bytes (PNG, JPEG, WebP,
|
|
59
|
+
* GIF).
|
|
59
60
|
*/
|
|
60
61
|
static new_from_byteslice(bytes: Uint8Array): PhotonImage;
|
|
61
62
|
}
|
|
@@ -71,6 +72,11 @@ export enum SamplingFilter {
|
|
|
71
72
|
Lanczos3 = 5,
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Extract the before/after slices around an overlay region.
|
|
77
|
+
*/
|
|
78
|
+
export function extract_segments(line: string, before_end: number, after_start: number, after_len: number, strict_after: boolean): any;
|
|
79
|
+
|
|
74
80
|
/**
|
|
75
81
|
* Quick check if content matches a pattern.
|
|
76
82
|
*/
|
|
@@ -86,3 +92,18 @@ export function resize(image: PhotonImage, width: number, height: number, filter
|
|
|
86
92
|
* For repeated searches with the same pattern, use [`CompiledPattern`].
|
|
87
93
|
*/
|
|
88
94
|
export function search(content: string, options: any): any;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Slice a range of visible columns from a line.
|
|
98
|
+
*/
|
|
99
|
+
export function slice_with_width(line: string, start_col: number, length: number, strict: boolean): any;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Truncate text to a visible width, preserving ANSI codes.
|
|
103
|
+
*/
|
|
104
|
+
export function truncate_to_width(text: string, max_width: number, ellipsis: string, pad: boolean): string;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Compute the visible width of a string, ignoring ANSI codes.
|
|
108
|
+
*/
|
|
109
|
+
export function visible_width(text: string): number;
|
package/wasm/pi_natives.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import wasmPath from "./pi_natives_bg.wasm";
|
|
2
|
+
|
|
1
3
|
/* @ts-self-types="./pi_natives.d.ts" */
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -171,7 +173,8 @@ export class PhotonImage {
|
|
|
171
173
|
return ret >>> 0;
|
|
172
174
|
}
|
|
173
175
|
/**
|
|
174
|
-
* Create a new PhotonImage from encoded image bytes (PNG, JPEG, WebP,
|
|
176
|
+
* Create a new `PhotonImage` from encoded image bytes (PNG, JPEG, WebP,
|
|
177
|
+
* GIF).
|
|
175
178
|
* @param {Uint8Array} bytes
|
|
176
179
|
* @returns {PhotonImage}
|
|
177
180
|
*/
|
|
@@ -207,6 +210,22 @@ export const SamplingFilter = Object.freeze({
|
|
|
207
210
|
Lanczos3: 5, "5": "Lanczos3",
|
|
208
211
|
});
|
|
209
212
|
|
|
213
|
+
/**
|
|
214
|
+
* Extract the before/after slices around an overlay region.
|
|
215
|
+
* @param {string} line
|
|
216
|
+
* @param {number} before_end
|
|
217
|
+
* @param {number} after_start
|
|
218
|
+
* @param {number} after_len
|
|
219
|
+
* @param {boolean} strict_after
|
|
220
|
+
* @returns {any}
|
|
221
|
+
*/
|
|
222
|
+
export function extract_segments(line, before_end, after_start, after_len, strict_after) {
|
|
223
|
+
const ptr0 = passStringToWasm0(line, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
224
|
+
const len0 = WASM_VECTOR_LEN;
|
|
225
|
+
const ret = wasm.extract_segments(ptr0, len0, before_end, after_start, after_len, strict_after);
|
|
226
|
+
return takeObject(ret);
|
|
227
|
+
}
|
|
228
|
+
|
|
210
229
|
/**
|
|
211
230
|
* Quick check if content matches a pattern.
|
|
212
231
|
* @param {string} content
|
|
@@ -263,6 +282,62 @@ export function search(content, options) {
|
|
|
263
282
|
return takeObject(ret);
|
|
264
283
|
}
|
|
265
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Slice a range of visible columns from a line.
|
|
287
|
+
* @param {string} line
|
|
288
|
+
* @param {number} start_col
|
|
289
|
+
* @param {number} length
|
|
290
|
+
* @param {boolean} strict
|
|
291
|
+
* @returns {any}
|
|
292
|
+
*/
|
|
293
|
+
export function slice_with_width(line, start_col, length, strict) {
|
|
294
|
+
const ptr0 = passStringToWasm0(line, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
295
|
+
const len0 = WASM_VECTOR_LEN;
|
|
296
|
+
const ret = wasm.slice_with_width(ptr0, len0, start_col, length, strict);
|
|
297
|
+
return takeObject(ret);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Truncate text to a visible width, preserving ANSI codes.
|
|
302
|
+
* @param {string} text
|
|
303
|
+
* @param {number} max_width
|
|
304
|
+
* @param {string} ellipsis
|
|
305
|
+
* @param {boolean} pad
|
|
306
|
+
* @returns {string}
|
|
307
|
+
*/
|
|
308
|
+
export function truncate_to_width(text, max_width, ellipsis, pad) {
|
|
309
|
+
let deferred3_0;
|
|
310
|
+
let deferred3_1;
|
|
311
|
+
try {
|
|
312
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
313
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
314
|
+
const len0 = WASM_VECTOR_LEN;
|
|
315
|
+
const ptr1 = passStringToWasm0(ellipsis, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
316
|
+
const len1 = WASM_VECTOR_LEN;
|
|
317
|
+
wasm.truncate_to_width(retptr, ptr0, len0, max_width, ptr1, len1, pad);
|
|
318
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
319
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
320
|
+
deferred3_0 = r0;
|
|
321
|
+
deferred3_1 = r1;
|
|
322
|
+
return getStringFromWasm0(r0, r1);
|
|
323
|
+
} finally {
|
|
324
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
325
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Compute the visible width of a string, ignoring ANSI codes.
|
|
331
|
+
* @param {string} text
|
|
332
|
+
* @returns {number}
|
|
333
|
+
*/
|
|
334
|
+
export function visible_width(text) {
|
|
335
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
336
|
+
const len0 = WASM_VECTOR_LEN;
|
|
337
|
+
const ret = wasm.visible_width(ptr0, len0);
|
|
338
|
+
return ret >>> 0;
|
|
339
|
+
}
|
|
340
|
+
|
|
266
341
|
function __wbg_get_imports() {
|
|
267
342
|
const import0 = {
|
|
268
343
|
__proto__: null,
|
|
@@ -651,6 +726,6 @@ const cachedTextEncoder = new TextEncoder();
|
|
|
651
726
|
|
|
652
727
|
let WASM_VECTOR_LEN = 0;
|
|
653
728
|
|
|
654
|
-
const wasmUrl =
|
|
729
|
+
const wasmUrl = import.meta.resolve(wasmPath);
|
|
655
730
|
const wasmInstantiated = await WebAssembly.instantiateStreaming(fetch(wasmUrl), __wbg_get_imports());
|
|
656
731
|
const wasm = wasmInstantiated.instance.exports;
|
package/wasm/pi_natives_bg.wasm
CHANGED
|
Binary file
|
|
@@ -6,6 +6,7 @@ export const __wbg_photonimage_free: (a: number, b: number) => void;
|
|
|
6
6
|
export const compiledpattern_has_match: (a: number, b: number, c: number) => number;
|
|
7
7
|
export const compiledpattern_new: (a: number, b: number) => void;
|
|
8
8
|
export const compiledpattern_search: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
9
|
+
export const extract_segments: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
9
10
|
export const has_match: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
10
11
|
export const photonimage_get_bytes: (a: number, b: number) => void;
|
|
11
12
|
export const photonimage_get_bytes_jpeg: (a: number, b: number, c: number) => void;
|
|
@@ -14,6 +15,9 @@ export const photonimage_get_width: (a: number) => number;
|
|
|
14
15
|
export const photonimage_new_from_byteslice: (a: number, b: number, c: number) => void;
|
|
15
16
|
export const resize: (a: number, b: number, c: number, d: number) => number;
|
|
16
17
|
export const search: (a: number, b: number, c: number) => number;
|
|
18
|
+
export const slice_with_width: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
19
|
+
export const truncate_to_width: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
20
|
+
export const visible_width: (a: number, b: number) => number;
|
|
17
21
|
export const compiledpattern_has_match_bytes: (a: number, b: number, c: number) => number;
|
|
18
22
|
export const compiledpattern_search_bytes: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
19
23
|
export const __wbindgen_export: (a: number, b: number) => number;
|