@nghyane/arcane-natives 0.1.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.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Types for grep/search operations.
3
+ */
4
+
5
+ import type { Cancellable, TsFunc } from "../bindings";
6
+
7
+ /** Options for searching files. */
8
+ export interface GrepOptions extends Cancellable {
9
+ /** Regex pattern to search for */
10
+ pattern: string;
11
+ /** Directory or file to search */
12
+ path: string;
13
+ /** Glob filter for filenames (e.g., "*.ts") */
14
+ glob?: string;
15
+ /** Filter by file type (e.g., "js", "py", "rust") */
16
+ type?: string;
17
+ /** Case-insensitive search */
18
+ ignoreCase?: boolean;
19
+ /** Enable multiline matching */
20
+ multiline?: boolean;
21
+ /** Include hidden files (default: true) */
22
+ hidden?: boolean;
23
+ /** Enable shared filesystem scan cache (default: false). */
24
+ cache?: boolean;
25
+ /** Maximum number of matches to return */
26
+ maxCount?: number;
27
+ /** Skip first N matches */
28
+ offset?: number;
29
+ /** Lines of context before matches */
30
+ contextBefore?: number;
31
+ /** Lines of context after matches */
32
+ contextAfter?: number;
33
+ /** Lines of context before/after matches (legacy) */
34
+ context?: number;
35
+ /** Truncate lines longer than this (characters) */
36
+ maxColumns?: number;
37
+ /** Output mode */
38
+ mode?: "content" | "filesWithMatches" | "count";
39
+ }
40
+
41
+ /** A context line returned around a match. */
42
+ export interface ContextLine {
43
+ /** 1-indexed line number. */
44
+ lineNumber: number;
45
+ /** Line content (trimmed line ending). */
46
+ line: string;
47
+ }
48
+
49
+ /** A single grep match or per-file count entry. */
50
+ export interface GrepMatch {
51
+ /** File path for the match (relative for directory searches). */
52
+ path: string;
53
+ /** 1-indexed line number (0 for count-only entries). */
54
+ lineNumber: number;
55
+ /** Matched line content (empty for count-only entries). */
56
+ line: string;
57
+ /** Context lines before the match. */
58
+ contextBefore?: ContextLine[];
59
+ /** Context lines after the match. */
60
+ contextAfter?: ContextLine[];
61
+ /** Whether the line was truncated. */
62
+ truncated?: boolean;
63
+ /** Per-file match count (count mode only). */
64
+ matchCount?: number;
65
+ }
66
+
67
+ /** Summary stats for a grep run. */
68
+ export interface GrepSummary {
69
+ /** Total matches across all files. */
70
+ totalMatches: number;
71
+ /** Number of files with at least one match. */
72
+ filesWithMatches: number;
73
+ /** Number of files searched. */
74
+ filesSearched: number;
75
+ /** Whether the limit/offset stopped the search early. */
76
+ limitReached?: boolean;
77
+ }
78
+
79
+ /** Full grep result including matches and summary counts. */
80
+ export interface GrepResult extends GrepSummary {
81
+ /** Matches or per-file counts, depending on mode. */
82
+ matches: GrepMatch[];
83
+ }
84
+
85
+ /** Options for searching in-memory content. */
86
+ export interface SearchOptions {
87
+ /** Regex pattern to search for */
88
+ pattern: string;
89
+ /** Case-insensitive search */
90
+ ignoreCase?: boolean;
91
+ /** Enable multiline matching */
92
+ multiline?: boolean;
93
+ /** Maximum number of matches to return */
94
+ maxCount?: number;
95
+ /** Skip first N matches */
96
+ offset?: number;
97
+ /** Lines of context before matches */
98
+ contextBefore?: number;
99
+ /** Lines of context after matches */
100
+ contextAfter?: number;
101
+ /** Lines of context before/after matches (legacy) */
102
+ context?: number;
103
+ /** Truncate lines longer than this (characters) */
104
+ maxColumns?: number;
105
+ /** Output mode */
106
+ mode?: "content" | "count";
107
+ }
108
+
109
+ /** A single content match. */
110
+ export interface SearchMatch {
111
+ /** 1-indexed line number. */
112
+ lineNumber: number;
113
+ /** Matched line content. */
114
+ line: string;
115
+ /** Context lines before the match. */
116
+ contextBefore?: ContextLine[];
117
+ /** Context lines after the match. */
118
+ contextAfter?: ContextLine[];
119
+ /** Whether the line was truncated. */
120
+ truncated?: boolean;
121
+ }
122
+
123
+ /** Result of searching in-memory content. */
124
+ export interface SearchResult {
125
+ /** All matches found. */
126
+ matches: SearchMatch[];
127
+ /** Total number of matches (may exceed `matches.length`). */
128
+ matchCount: number;
129
+ /** Whether the limit was reached. */
130
+ limitReached: boolean;
131
+ /** Error message, if any. */
132
+ error?: string;
133
+ }
134
+
135
+ /** Options for fuzzy file path search. */
136
+ export interface FuzzyFindOptions extends Cancellable {
137
+ /** Fuzzy query to match against file paths (case-insensitive). */
138
+ query: string;
139
+ /** Directory to search. */
140
+ path: string;
141
+ /** Include hidden files (default: false). */
142
+ hidden?: boolean;
143
+ /** Respect .gitignore (default: true). */
144
+ gitignore?: boolean;
145
+ /** Enable shared filesystem scan cache (default: false). */
146
+ cache?: boolean;
147
+ /** Maximum number of matches to return (default: 100). */
148
+ maxResults?: number;
149
+ }
150
+
151
+ /** A single match in fuzzy find results. */
152
+ export interface FuzzyFindMatch {
153
+ /** Relative path from the search root (uses `/` separators). */
154
+ path: string;
155
+ /** Whether this entry is a directory. */
156
+ isDirectory: boolean;
157
+ /** Match quality score (higher is better). */
158
+ score: number;
159
+ }
160
+
161
+ /** Result of fuzzy file path search. */
162
+ export interface FuzzyFindResult {
163
+ /** Matched entries (up to `maxResults`). */
164
+ matches: FuzzyFindMatch[];
165
+ /** Total number of matches found (may exceed `matches.length`). */
166
+ totalMatches: number;
167
+ }
168
+
169
+ declare module "../bindings" {
170
+ interface NativeBindings {
171
+ /** Fuzzy file path search for autocomplete. */
172
+ fuzzyFind(options: FuzzyFindOptions): Promise<FuzzyFindResult>;
173
+ /** Search files for a regex pattern. */
174
+ grep(options: GrepOptions, onMatch?: TsFunc<GrepMatch>): Promise<GrepResult>;
175
+ /** Search in-memory content for a regex pattern. */
176
+ search(content: string | Uint8Array, options: SearchOptions): SearchResult;
177
+ /** Quick check if content matches a pattern. */
178
+ hasMatch(
179
+ content: string | Uint8Array,
180
+ pattern: string | Uint8Array,
181
+ ignoreCase: boolean,
182
+ multiline: boolean,
183
+ ): boolean;
184
+ }
185
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Syntax highlighting powered by native syntect bindings.
3
+ */
4
+
5
+ import { native } from "../native";
6
+
7
+ export type { HighlightColors } from "./types";
8
+
9
+ export const { highlightCode, supportsLanguage, getSupportedLanguages } = native;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Types for syntax highlighting.
3
+ */
4
+
5
+ /**
6
+ * Theme colors for syntax highlighting.
7
+ * Each color should be an ANSI escape sequence (e.g., "\x1b[38;2;255;0;0m").
8
+ */
9
+ export interface HighlightColors {
10
+ /** ANSI color for comments. */
11
+ comment: string;
12
+ /** ANSI color for keywords. */
13
+ keyword: string;
14
+ /** ANSI color for function names. */
15
+ function: string;
16
+ /** ANSI color for variables and identifiers. */
17
+ variable: string;
18
+ /** ANSI color for string literals. */
19
+ string: string;
20
+ /** ANSI color for numeric literals. */
21
+ number: string;
22
+ /** ANSI color for type identifiers. */
23
+ type: string;
24
+ /** ANSI color for operators. */
25
+ operator: string;
26
+ /** ANSI color for punctuation tokens. */
27
+ punctuation: string;
28
+ /** Color for diff inserted lines (+). */
29
+ inserted?: string;
30
+ /** Color for diff deleted lines (-). */
31
+ deleted?: string;
32
+ }
33
+
34
+ declare module "../bindings" {
35
+ interface NativeBindings {
36
+ /**
37
+ * Highlight code with syntax coloring.
38
+ * @param code Source code to highlight.
39
+ * @param lang Language name, extension, or null for plain text.
40
+ * @param colors ANSI color palette for semantic scopes.
41
+ * @returns Highlighted code with ANSI color codes.
42
+ */
43
+ highlightCode(code: string, lang: string | null | undefined, colors: HighlightColors): string;
44
+ /**
45
+ * Check if a language is supported for highlighting.
46
+ * @param lang Language name or extension to test.
47
+ * @returns True when highlighting is available.
48
+ */
49
+ supportsLanguage(lang: string): boolean;
50
+ /**
51
+ * Get list of all supported languages.
52
+ * @returns Syntect language names supported by the native highlighter.
53
+ */
54
+ getSupportedLanguages(): string[];
55
+ }
56
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * HTML to Markdown conversion powered by native bindings.
3
+ */
4
+
5
+ import { native } from "../native";
6
+ import type { HtmlToMarkdownOptions } from "./types";
7
+
8
+ export type { HtmlToMarkdownOptions } from "./types";
9
+
10
+ /**
11
+ * Convert HTML to Markdown.
12
+ *
13
+ * @param html - HTML content to convert
14
+ * @param options - Conversion options
15
+ * @returns Markdown text
16
+ */
17
+ export async function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions): Promise<string> {
18
+ return native.htmlToMarkdown(html, options);
19
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Types for HTML to Markdown conversion.
3
+ */
4
+
5
+ /** Options controlling HTML preprocessing and output. */
6
+ export interface HtmlToMarkdownOptions {
7
+ /** Remove navigation elements, forms, headers, and footers. */
8
+ cleanContent?: boolean;
9
+ /** Skip images during conversion. */
10
+ skipImages?: boolean;
11
+ }
12
+
13
+ declare module "../bindings" {
14
+ /** Native HTML utilities exposed by the Rust bindings. */
15
+ interface NativeBindings {
16
+ /**
17
+ * Convert HTML to Markdown.
18
+ * @param html HTML source to convert.
19
+ * @param options Optional conversion settings.
20
+ * @returns Markdown output.
21
+ */
22
+ htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions | null): Promise<string>;
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Image processing via native bindings.
3
+ */
4
+
5
+ import { native } from "../native";
6
+
7
+ export { ImageFormat, type PhotonImageConstructor, SamplingFilter } from "./types";
8
+
9
+ /** PhotonImage class for image manipulation. Use PhotonImage.parse() to create instances. */
10
+ export const PhotonImage = native.PhotonImage;
11
+
12
+ /** PhotonImage instance type. */
13
+ export type PhotonImage = import("./types").PhotonImage;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Types for image processing.
3
+ */
4
+
5
+ /** Output format for image encoding. */
6
+ export const enum ImageFormat {
7
+ /** PNG encoded bytes. */
8
+ PNG = 0,
9
+ /** JPEG encoded bytes. */
10
+ JPEG = 1,
11
+ /** WebP encoded bytes. */
12
+ WEBP = 2,
13
+ /** GIF encoded bytes. */
14
+ GIF = 3,
15
+ }
16
+
17
+ /** Sampling filter for resize operations. */
18
+ export const enum SamplingFilter {
19
+ /** Nearest-neighbor sampling (fast, low quality). */
20
+ Nearest = 1,
21
+ /** Triangle filter (linear interpolation). */
22
+ Triangle = 2,
23
+ /** Catmull-Rom filter with sharper edges. */
24
+ CatmullRom = 3,
25
+ /** Gaussian filter for smoother results. */
26
+ Gaussian = 4,
27
+ /** Lanczos3 filter for high-quality downscaling. */
28
+ Lanczos3 = 5,
29
+ }
30
+
31
+ /** Image container for native image operations. */
32
+ export interface PhotonImage {
33
+ /** Image width in pixels. */
34
+ get width(): number;
35
+ /** Image height in pixels. */
36
+ get height(): number;
37
+ /**
38
+ * Encode the image using the requested format and quality.
39
+ * Returns the encoded image bytes.
40
+ */
41
+ encode(format: ImageFormat, quality: number): Promise<Uint8Array>;
42
+ /**
43
+ * Resize the image to the requested dimensions with the filter.
44
+ * Returns a new image instance.
45
+ */
46
+ resize(width: number, height: number, filter: SamplingFilter): Promise<PhotonImage>;
47
+ }
48
+
49
+ /** Static entrypoints for creating `PhotonImage` instances. */
50
+ export interface PhotonImageConstructor {
51
+ /** Parse image bytes (PNG, JPEG, WebP, GIF) into a native image. */
52
+ parse(bytes: Uint8Array): Promise<PhotonImage>;
53
+ /** Instance prototype reference. */
54
+ prototype: PhotonImage;
55
+ }
56
+
57
+ declare module "../bindings" {
58
+ /** Native bindings for image operations. */
59
+ interface NativeBindings {
60
+ /** Sampling filters exposed by the native module. */
61
+ SamplingFilter: typeof SamplingFilter;
62
+ /** Photon image constructor exposed by the native module. */
63
+ PhotonImage: PhotonImageConstructor;
64
+ }
65
+ }
package/src/index.ts ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Native utilities powered by N-API.
3
+ */
4
+
5
+ // =============================================================================
6
+ // Clipboard
7
+ // =============================================================================
8
+
9
+ export { type ClipboardImage, copyToClipboard, readImageFromClipboard } from "./clipboard";
10
+
11
+ // =============================================================================
12
+ // Grep (ripgrep-based regex search)
13
+ // =============================================================================
14
+
15
+ export {
16
+ type ContextLine,
17
+ type FuzzyFindMatch,
18
+ type FuzzyFindOptions,
19
+ type FuzzyFindResult,
20
+ fuzzyFind,
21
+ type GrepMatch,
22
+ type GrepOptions,
23
+ type GrepResult,
24
+ type GrepSummary,
25
+ grep,
26
+ hasMatch,
27
+ searchContent,
28
+ } from "./grep";
29
+
30
+ // =============================================================================
31
+ // Glob (file discovery)
32
+ // =============================================================================
33
+
34
+ export {
35
+ FileType,
36
+ type GlobMatch,
37
+ type GlobOptions,
38
+ type GlobResult,
39
+ glob,
40
+ invalidateFsScanCache,
41
+ } from "./glob";
42
+
43
+ // =============================================================================
44
+ // Image processing (photon-compatible API)
45
+ // =============================================================================
46
+
47
+ export { ImageFormat, PhotonImage, SamplingFilter } from "./image";
48
+
49
+ // =============================================================================
50
+ // Text utilities
51
+ // =============================================================================
52
+
53
+ export {
54
+ Ellipsis,
55
+ type ExtractSegmentsResult,
56
+ extractSegments,
57
+ type SliceWithWidthResult,
58
+ sanitizeText,
59
+ sliceWithWidth,
60
+ truncateToWidth,
61
+ visibleWidth,
62
+ wrapTextWithAnsi,
63
+ } from "./text";
64
+
65
+ // =============================================================================
66
+ // Syntax highlighting
67
+ // =============================================================================
68
+
69
+ export {
70
+ getSupportedLanguages,
71
+ type HighlightColors,
72
+ highlightCode,
73
+ supportsLanguage,
74
+ } from "./highlight";
75
+
76
+ // =============================================================================
77
+ // Keyboard sequence helpers
78
+ // =============================================================================
79
+
80
+ export {
81
+ type KeyEventType,
82
+ matchesKey,
83
+ matchesKittySequence,
84
+ matchesLegacySequence,
85
+ type ParsedKittyResult,
86
+ parseKey,
87
+ parseKittySequence,
88
+ } from "./keys";
89
+
90
+ // =============================================================================
91
+ // HTML to Markdown
92
+ // =============================================================================
93
+
94
+ export { type HtmlToMarkdownOptions, htmlToMarkdown } from "./html";
95
+
96
+ // =============================================================================
97
+ // Shell execution (brush-core)
98
+ // =============================================================================
99
+
100
+ export {
101
+ executeShell,
102
+ Shell,
103
+ type ShellExecuteOptions,
104
+ type ShellExecuteResult,
105
+ type ShellOptions,
106
+ type ShellRunOptions,
107
+ type ShellRunResult,
108
+ } from "./shell";
109
+
110
+ // =============================================================================
111
+ // PTY execution
112
+ // =============================================================================
113
+
114
+ export { type PtyRunResult, PtySession, type PtyStartOptions } from "./pty";
115
+ // =============================================================================
116
+ // Process management
117
+ // =============================================================================
118
+
119
+ export { killTree, listDescendants } from "./ps";
120
+
121
+ // =============================================================================
122
+ // Work profiling
123
+ // =============================================================================
124
+
125
+ export { getWorkProfile, type WorkProfile } from "./work";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Keyboard sequence utilities powered by native bindings.
3
+ */
4
+
5
+ import { native } from "../native";
6
+
7
+ export type { KeyEventType, ParsedKittyResult } from "./types";
8
+
9
+ export const { matchesKittySequence, parseKey, matchesLegacySequence, parseKittySequence, matchesKey } = native;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Types for keyboard sequence handling.
3
+ */
4
+
5
+ /**
6
+ * Event types from Kitty keyboard protocol (flag 2).
7
+ * 1 = key press, 2 = key repeat, 3 = key release.
8
+ */
9
+ export const enum KeyEventType {
10
+ /** Key press event. */
11
+ Press = 1,
12
+ /** Key repeat event. */
13
+ Repeat = 2,
14
+ /** Key release event. */
15
+ Release = 3,
16
+ }
17
+
18
+ /** Parsed Kitty keyboard protocol sequence result. */
19
+ export interface ParsedKittyResult {
20
+ /** Primary codepoint associated with the key. */
21
+ codepoint: number;
22
+ /** Optional shifted key codepoint from the sequence. */
23
+ shiftedKey?: number;
24
+ /** Optional base layout key codepoint from the sequence. */
25
+ baseLayoutKey?: number;
26
+ /** Modifier bitmask (shift/alt/ctrl), excluding lock bits. */
27
+ modifier: number;
28
+ /** Optional event type from the sequence. */
29
+ eventType?: KeyEventType;
30
+ }
31
+
32
+ declare module "../bindings" {
33
+ interface NativeBindings {
34
+ /**
35
+ * Match Kitty protocol sequences for a codepoint and modifier mask.
36
+ * @param data Raw terminal input data.
37
+ * @param expectedCodepoint Codepoint to compare against the parsed sequence.
38
+ * @param expectedModifier Modifier mask (shift/alt/ctrl).
39
+ * @returns True when the sequence matches the expected codepoint and modifiers.
40
+ */
41
+ matchesKittySequence(data: string, expectedCodepoint: number, expectedModifier: number): boolean;
42
+ /**
43
+ * Parse terminal input and return a normalized key identifier.
44
+ * Returns key names like "escape", "ctrl+c", "shift+tab", "alt+enter".
45
+ * Returns null if the input is not a recognized key sequence.
46
+ * @param data Raw terminal input data.
47
+ * @param kittyProtocolActive Whether Kitty disambiguation is enabled.
48
+ * @returns The normalized key id or null when unrecognized.
49
+ */
50
+ parseKey(data: string, kittyProtocolActive: boolean): string | null;
51
+ /**
52
+ * Check if input matches a legacy escape sequence for a specific key.
53
+ * @param data Raw terminal input data.
54
+ * @param keyName Key identifier to match (e.g. "home").
55
+ * @returns True when the sequence maps to the given key name.
56
+ */
57
+ matchesLegacySequence(data: string, keyName: string): boolean;
58
+ /**
59
+ * Parse a Kitty keyboard protocol sequence.
60
+ * @param data Raw terminal input data.
61
+ * @returns Parsed sequence info or null if not a Kitty sequence.
62
+ */
63
+ parseKittySequence(data: string): ParsedKittyResult | null;
64
+ /**
65
+ * Match input data against a key identifier string.
66
+ * Supports: escape, tab, enter, backspace, delete, home, end, space,
67
+ * arrows (up/down/left/right), ctrl+X, shift+X, alt+X, combined modifiers.
68
+ * @param data Raw terminal input data.
69
+ * @param keyId Key identifier string to match (e.g. "ctrl+c").
70
+ * @param kittyProtocolActive Whether Kitty disambiguation is enabled.
71
+ * @returns True when the input matches the key identifier.
72
+ */
73
+ matchesKey(data: string, keyId: string, kittyProtocolActive: boolean): boolean;
74
+ }
75
+ }