@oh-my-pi/pi-natives 8.12.9 → 8.12.10
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/highlight/index.ts +55 -0
- package/src/index.ts +11 -0
- package/wasm/pi_natives.d.ts +26 -0
- package/wasm/pi_natives.js +79 -0
- package/wasm/pi_natives_bg.wasm +0 -0
- package/wasm/pi_natives_bg.wasm.d.ts +3 -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.10",
|
|
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.10"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.0.10"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syntax highlighting powered by WASM (syntect).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as wasm from "../../wasm/pi_natives";
|
|
6
|
+
|
|
7
|
+
type WasmHighlightExports = typeof wasm & {
|
|
8
|
+
highlight_code: (code: string, lang: string | null | undefined, colors: HighlightColors) => string;
|
|
9
|
+
supports_language: (lang: string) => boolean;
|
|
10
|
+
get_supported_languages: () => string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const wasmHighlight = wasm as WasmHighlightExports;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Theme colors for syntax highlighting.
|
|
17
|
+
* Each color should be an ANSI escape sequence (e.g., "\x1b[38;2;255;0;0m").
|
|
18
|
+
*/
|
|
19
|
+
export interface HighlightColors {
|
|
20
|
+
comment: string;
|
|
21
|
+
keyword: string;
|
|
22
|
+
function: string;
|
|
23
|
+
variable: string;
|
|
24
|
+
string: string;
|
|
25
|
+
number: string;
|
|
26
|
+
type: string;
|
|
27
|
+
operator: string;
|
|
28
|
+
punctuation: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Highlight code with syntax coloring.
|
|
33
|
+
*
|
|
34
|
+
* @param code - The source code to highlight
|
|
35
|
+
* @param lang - Optional language identifier (e.g., "rust", "typescript", "python")
|
|
36
|
+
* @param colors - Theme colors as ANSI escape sequences
|
|
37
|
+
* @returns Highlighted code as a single string with ANSI color codes
|
|
38
|
+
*/
|
|
39
|
+
export function highlightCode(code: string, lang: string | undefined, colors: HighlightColors): string {
|
|
40
|
+
return wasmHighlight.highlight_code(code, lang, colors);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if a language is supported for highlighting.
|
|
45
|
+
*/
|
|
46
|
+
export function supportsLanguage(lang: string): boolean {
|
|
47
|
+
return wasmHighlight.supports_language(lang);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get list of all supported languages.
|
|
52
|
+
*/
|
|
53
|
+
export function getSupportedLanguages(): string[] {
|
|
54
|
+
return wasmHighlight.get_supported_languages();
|
|
55
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -146,6 +146,17 @@ export {
|
|
|
146
146
|
visibleWidth,
|
|
147
147
|
} from "./text/index";
|
|
148
148
|
|
|
149
|
+
// =============================================================================
|
|
150
|
+
// Syntax highlighting
|
|
151
|
+
// =============================================================================
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
getSupportedLanguages,
|
|
155
|
+
type HighlightColors,
|
|
156
|
+
highlightCode,
|
|
157
|
+
supportsLanguage,
|
|
158
|
+
} from "./highlight/index";
|
|
159
|
+
|
|
149
160
|
// =============================================================================
|
|
150
161
|
// Worker Pool (shared infrastructure)
|
|
151
162
|
// =============================================================================
|
package/wasm/pi_natives.d.ts
CHANGED
|
@@ -77,11 +77,30 @@ export enum SamplingFilter {
|
|
|
77
77
|
*/
|
|
78
78
|
export function extract_segments(line: string, before_end: number, after_start: number, after_len: number, strict_after: boolean): any;
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Get list of supported languages.
|
|
82
|
+
*/
|
|
83
|
+
export function get_supported_languages(): string[];
|
|
84
|
+
|
|
80
85
|
/**
|
|
81
86
|
* Quick check if content matches a pattern.
|
|
82
87
|
*/
|
|
83
88
|
export function has_match(content: string, pattern: string, ignore_case: boolean, multiline: boolean): boolean;
|
|
84
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Highlight code and return ANSI-colored lines.
|
|
92
|
+
*
|
|
93
|
+
* # Arguments
|
|
94
|
+
* * `code` - The source code to highlight
|
|
95
|
+
* * `lang` - Language identifier (e.g., "rust", "typescript", "python")
|
|
96
|
+
* * `colors` - Theme colors as ANSI escape sequences
|
|
97
|
+
*
|
|
98
|
+
* # Returns
|
|
99
|
+
* Highlighted code with ANSI color codes, or the original code if highlighting
|
|
100
|
+
* fails.
|
|
101
|
+
*/
|
|
102
|
+
export function highlight_code(code: string, lang: string | null | undefined, colors: any): string;
|
|
103
|
+
|
|
85
104
|
/**
|
|
86
105
|
* Resize an image to the specified dimensions.
|
|
87
106
|
*/
|
|
@@ -98,6 +117,13 @@ export function search(content: string, options: any): any;
|
|
|
98
117
|
*/
|
|
99
118
|
export function slice_with_width(line: string, start_col: number, length: number, strict: boolean): any;
|
|
100
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Check if a language is supported for highlighting.
|
|
122
|
+
* Returns true if the language has either direct support or a fallback
|
|
123
|
+
* mapping.
|
|
124
|
+
*/
|
|
125
|
+
export function supports_language(lang: string): boolean;
|
|
126
|
+
|
|
101
127
|
/**
|
|
102
128
|
* Truncate text to a visible width, preserving ANSI codes.
|
|
103
129
|
*/
|
package/wasm/pi_natives.js
CHANGED
|
@@ -226,6 +226,24 @@ export function extract_segments(line, before_end, after_start, after_len, stric
|
|
|
226
226
|
return takeObject(ret);
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Get list of supported languages.
|
|
231
|
+
* @returns {string[]}
|
|
232
|
+
*/
|
|
233
|
+
export function get_supported_languages() {
|
|
234
|
+
try {
|
|
235
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
236
|
+
wasm.get_supported_languages(retptr);
|
|
237
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
238
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
239
|
+
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
240
|
+
wasm.__wbindgen_export3(r0, r1 * 4, 4);
|
|
241
|
+
return v1;
|
|
242
|
+
} finally {
|
|
243
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
229
247
|
/**
|
|
230
248
|
* Quick check if content matches a pattern.
|
|
231
249
|
* @param {string} content
|
|
@@ -254,6 +272,43 @@ export function has_match(content, pattern, ignore_case, multiline) {
|
|
|
254
272
|
}
|
|
255
273
|
}
|
|
256
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Highlight code and return ANSI-colored lines.
|
|
277
|
+
*
|
|
278
|
+
* # Arguments
|
|
279
|
+
* * `code` - The source code to highlight
|
|
280
|
+
* * `lang` - Language identifier (e.g., "rust", "typescript", "python")
|
|
281
|
+
* * `colors` - Theme colors as ANSI escape sequences
|
|
282
|
+
*
|
|
283
|
+
* # Returns
|
|
284
|
+
* Highlighted code with ANSI color codes, or the original code if highlighting
|
|
285
|
+
* fails.
|
|
286
|
+
* @param {string} code
|
|
287
|
+
* @param {string | null | undefined} lang
|
|
288
|
+
* @param {any} colors
|
|
289
|
+
* @returns {string}
|
|
290
|
+
*/
|
|
291
|
+
export function highlight_code(code, lang, colors) {
|
|
292
|
+
let deferred3_0;
|
|
293
|
+
let deferred3_1;
|
|
294
|
+
try {
|
|
295
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
296
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
297
|
+
const len0 = WASM_VECTOR_LEN;
|
|
298
|
+
var ptr1 = isLikeNone(lang) ? 0 : passStringToWasm0(lang, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
299
|
+
var len1 = WASM_VECTOR_LEN;
|
|
300
|
+
wasm.highlight_code(retptr, ptr0, len0, ptr1, len1, addHeapObject(colors));
|
|
301
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
302
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
303
|
+
deferred3_0 = r0;
|
|
304
|
+
deferred3_1 = r1;
|
|
305
|
+
return getStringFromWasm0(r0, r1);
|
|
306
|
+
} finally {
|
|
307
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
308
|
+
wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
257
312
|
/**
|
|
258
313
|
* Resize an image to the specified dimensions.
|
|
259
314
|
* @param {PhotonImage} image
|
|
@@ -297,6 +352,20 @@ export function slice_with_width(line, start_col, length, strict) {
|
|
|
297
352
|
return takeObject(ret);
|
|
298
353
|
}
|
|
299
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Check if a language is supported for highlighting.
|
|
357
|
+
* Returns true if the language has either direct support or a fallback
|
|
358
|
+
* mapping.
|
|
359
|
+
* @param {string} lang
|
|
360
|
+
* @returns {boolean}
|
|
361
|
+
*/
|
|
362
|
+
export function supports_language(lang) {
|
|
363
|
+
const ptr0 = passStringToWasm0(lang, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
364
|
+
const len0 = WASM_VECTOR_LEN;
|
|
365
|
+
const ret = wasm.supports_language(ptr0, len0);
|
|
366
|
+
return ret !== 0;
|
|
367
|
+
}
|
|
368
|
+
|
|
300
369
|
/**
|
|
301
370
|
* Truncate text to a visible width, preserving ANSI codes.
|
|
302
371
|
* @param {string} text
|
|
@@ -629,6 +698,16 @@ function dropObject(idx) {
|
|
|
629
698
|
heap_next = idx;
|
|
630
699
|
}
|
|
631
700
|
|
|
701
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
702
|
+
ptr = ptr >>> 0;
|
|
703
|
+
const mem = getDataViewMemory0();
|
|
704
|
+
const result = [];
|
|
705
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
706
|
+
result.push(takeObject(mem.getUint32(i, true)));
|
|
707
|
+
}
|
|
708
|
+
return result;
|
|
709
|
+
}
|
|
710
|
+
|
|
632
711
|
function getArrayU8FromWasm0(ptr, len) {
|
|
633
712
|
ptr = ptr >>> 0;
|
|
634
713
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
package/wasm/pi_natives_bg.wasm
CHANGED
|
Binary file
|
|
@@ -7,7 +7,9 @@ export const compiledpattern_has_match: (a: number, b: number, c: number) => num
|
|
|
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
9
|
export const extract_segments: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
10
|
+
export const get_supported_languages: (a: number) => void;
|
|
10
11
|
export const has_match: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
12
|
+
export const highlight_code: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
11
13
|
export const photonimage_get_bytes: (a: number, b: number) => void;
|
|
12
14
|
export const photonimage_get_bytes_jpeg: (a: number, b: number, c: number) => void;
|
|
13
15
|
export const photonimage_get_height: (a: number) => number;
|
|
@@ -16,6 +18,7 @@ export const photonimage_new_from_byteslice: (a: number, b: number, c: number) =
|
|
|
16
18
|
export const resize: (a: number, b: number, c: number, d: number) => number;
|
|
17
19
|
export const search: (a: number, b: number, c: number) => number;
|
|
18
20
|
export const slice_with_width: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
21
|
+
export const supports_language: (a: number, b: number) => number;
|
|
19
22
|
export const truncate_to_width: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
20
23
|
export const visible_width: (a: number, b: number) => number;
|
|
21
24
|
export const compiledpattern_has_match_bytes: (a: number, b: number, c: number) => number;
|