avro-bangla-suggestions 0.0.1
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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/avro/index.d.ts +11 -0
- package/dist/avro/instance.d.ts +6 -0
- package/dist/avro/static/avro.min.d.ts +14 -0
- package/dist/avro/types.d.ts +9 -0
- package/dist/avro/useBanglaTyping.d.ts +23 -0
- package/dist/avro.min-DmpFihaf.js +379 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +150 -0
- package/dist/index.umd.js +3 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hasnat Shohag
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# avro-bangla-suggestions
|
|
2
|
+
|
|
3
|
+
A lightweight React hook providing **Avro phonetics-based Bangla typing suggestions** โ drop it into any React or Next.js project to get instant Bangla word suggestions as users type in English phonetics.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/avro-bangla-suggestions)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- ๐ค Avro phonetics-to-Bangla suggestions in real time
|
|
13
|
+
- โจ๏ธ Keyboard navigation (Arrow keys + Enter to select)
|
|
14
|
+
- ๐ Space-to-commit: pressing space auto-converts the current word
|
|
15
|
+
- ๐งต Web Worker powered โ phonetics processing happens off the main thread
|
|
16
|
+
- ๐ Works with `<input>` and `<textarea>` elements
|
|
17
|
+
- ๐ฆ Zero UI dependencies โ bring your own suggestion UI
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install avro-bangla-suggestions
|
|
25
|
+
# or
|
|
26
|
+
yarn add avro-bangla-suggestions
|
|
27
|
+
# or
|
|
28
|
+
pnpm add avro-bangla-suggestions
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> **Peer dependencies**: `react` and `react-dom` v18 or v19 must be installed in your project.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { useRef, useState } from "react";
|
|
39
|
+
import { useBanglaTyping } from "avro-bangla-suggestions";
|
|
40
|
+
|
|
41
|
+
export default function BanglaInput() {
|
|
42
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
43
|
+
const [mode, setMode] = useState<"bangla" | "english">("bangla");
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
text,
|
|
47
|
+
handleChange,
|
|
48
|
+
handleKeyDown,
|
|
49
|
+
handlePaste,
|
|
50
|
+
handleFocus,
|
|
51
|
+
handleBlur,
|
|
52
|
+
suggestions,
|
|
53
|
+
selectedSuggestionIndex,
|
|
54
|
+
applySuggestion,
|
|
55
|
+
isFocused,
|
|
56
|
+
} = useBanglaTyping({ mode });
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div style={{ position: "relative" }}>
|
|
60
|
+
<textarea
|
|
61
|
+
ref={inputRef}
|
|
62
|
+
value={text}
|
|
63
|
+
onChange={handleChange}
|
|
64
|
+
onKeyDown={handleKeyDown}
|
|
65
|
+
onPaste={handlePaste}
|
|
66
|
+
onFocus={handleFocus}
|
|
67
|
+
onBlur={handleBlur}
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
{/* Suggestion dropdown */}
|
|
71
|
+
{isFocused && suggestions.length > 0 && (
|
|
72
|
+
<div style={{ display: "flex", gap: 4, position: "absolute" }}>
|
|
73
|
+
{suggestions.map((word, idx) => (
|
|
74
|
+
<button
|
|
75
|
+
key={idx}
|
|
76
|
+
onMouseDown={(e) => {
|
|
77
|
+
e.preventDefault(); // prevent blur
|
|
78
|
+
applySuggestion(word, inputRef.current);
|
|
79
|
+
}}
|
|
80
|
+
style={{
|
|
81
|
+
background: selectedSuggestionIndex === idx ? "#7c3aed" : "#f3f4f6",
|
|
82
|
+
color: selectedSuggestionIndex === idx ? "#fff" : "#374151",
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{word}
|
|
86
|
+
</button>
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## `useBanglaTyping` API
|
|
98
|
+
|
|
99
|
+
### Parameters
|
|
100
|
+
|
|
101
|
+
| Prop | Type | Default | Description |
|
|
102
|
+
|------|------|---------|-------------|
|
|
103
|
+
| `mode` | `"bangla" \| "english"` | `"english"` | Enable Bangla suggestions only when `"bangla"` |
|
|
104
|
+
| `initialText` | `string` | `""` | Initial value of the text state |
|
|
105
|
+
| `onTextChange` | `(text: string) => void` | โ | Called whenever the text changes |
|
|
106
|
+
| `onSuggestionsChange` | `(suggestions: string[]) => void` | โ | Called when the suggestion list updates |
|
|
107
|
+
| `onSuggestionsHidden` | `() => void` | โ | Called when suggestions are dismissed |
|
|
108
|
+
|
|
109
|
+
### Returns
|
|
110
|
+
|
|
111
|
+
| Name | Type | Description |
|
|
112
|
+
|------|------|-------------|
|
|
113
|
+
| `text` | `string` | Current text value (use as controlled `value`) |
|
|
114
|
+
| `handleChange` | `ChangeEventHandler` | Attach to `onChange` |
|
|
115
|
+
| `handleKeyDown` | `KeyboardEventHandler` | Attach to `onKeyDown` |
|
|
116
|
+
| `handlePaste` | `ClipboardEventHandler` | Attach to `onPaste` |
|
|
117
|
+
| `handleFocus` | `() => void` | Attach to `onFocus` |
|
|
118
|
+
| `handleBlur` | `() => void` | Attach to `onBlur` |
|
|
119
|
+
| `suggestions` | `string[]` | Current suggestion list |
|
|
120
|
+
| `selectedSuggestionIndex` | `number` | Index of the highlighted suggestion |
|
|
121
|
+
| `applySuggestion` | `(word: string, el: HTMLInputElement \| HTMLTextAreaElement \| null) => void` | Call on suggestion click |
|
|
122
|
+
| `isFocused` | `boolean` | Whether the input is focused |
|
|
123
|
+
| `hideSuggestions` | `() => void` | Programmatically dismiss suggestions |
|
|
124
|
+
|
|
125
|
+
### Keyboard Shortcuts (Bangla mode)
|
|
126
|
+
|
|
127
|
+
| Key | Action |
|
|
128
|
+
|-----|--------|
|
|
129
|
+
| `โ` / `โ` | Select next suggestion |
|
|
130
|
+
| `โ` / `โ` | Select previous suggestion |
|
|
131
|
+
| `Enter` | Apply selected suggestion |
|
|
132
|
+
| `Space` | Auto-convert and commit current word |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## TypeScript Types
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import type { TAvroSuggestion, TAvroPhonetic } from "avro-bangla-suggestions";
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Advanced: Worker Utilities
|
|
145
|
+
|
|
146
|
+
If you need direct access to the Avro worker:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { initAvroWorker, getGlobalAvroWorker } from "avro-bangla-suggestions";
|
|
150
|
+
|
|
151
|
+
// Create a new instance (useful if you need isolated state)
|
|
152
|
+
const worker = initAvroWorker();
|
|
153
|
+
const result = await worker.getSuggestion("ami");
|
|
154
|
+
|
|
155
|
+
// Or use the shared singleton
|
|
156
|
+
const sharedWorker = getGlobalAvroWorker();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
[MIT](./LICENSE) ยฉ Hasnat Shohag
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Remote } from 'comlink';
|
|
2
|
+
import { TAvroPhonetic } from './types';
|
|
3
|
+
|
|
4
|
+
export * from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the Avro worker.
|
|
7
|
+
*
|
|
8
|
+
* @returns A promise that resolves to the Comlink-wrapped worker API.
|
|
9
|
+
*/
|
|
10
|
+
export declare const initAvroWorker: () => Remote<TAvroPhonetic>;
|
|
11
|
+
export declare const getGlobalAvroWorker: () => Remote<TAvroPhonetic>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TAvroSuggestion } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function ensureAvroLoaded(): Promise<void>;
|
|
4
|
+
export declare function getSuggestion(subtext: string): TAvroSuggestion | null;
|
|
5
|
+
export declare function setCommit(queryText: string, bnValue: string): void;
|
|
6
|
+
export declare function getVersion(): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for the bundled Avro Phonetics engine.
|
|
3
|
+
* avro.min.js is the pre-built AvroPhonetic library.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AvroPhonetic {
|
|
6
|
+
version: string;
|
|
7
|
+
constructor(
|
|
8
|
+
getter: () => Record<string, unknown>,
|
|
9
|
+
setter: (cs: Record<string, unknown>) => void,
|
|
10
|
+
);
|
|
11
|
+
suggest(queryText: string): { words: string[]; prevSelection: number };
|
|
12
|
+
candidate(queryText: string): string;
|
|
13
|
+
commit(queryText: string, bnValue: string): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type TAvroSuggestion = {
|
|
2
|
+
prevSelection: number;
|
|
3
|
+
words: Array<string>;
|
|
4
|
+
};
|
|
5
|
+
export type TAvroPhonetic = {
|
|
6
|
+
getVersion: () => string;
|
|
7
|
+
getSuggestion: (queryText: string) => TAvroSuggestion;
|
|
8
|
+
setCommit: (queryText: string, bnValue: string) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
interface UseBanglaTypingProps {
|
|
4
|
+
initialText?: string;
|
|
5
|
+
onTextChange?: (newText: string) => void;
|
|
6
|
+
onSuggestionsChange?: (suggestions: Array<string>) => void;
|
|
7
|
+
onSuggestionsHidden?: () => void;
|
|
8
|
+
mode?: "bangla" | "english";
|
|
9
|
+
}
|
|
10
|
+
export declare function useBanglaTyping({ initialText, onTextChange, onSuggestionsChange, onSuggestionsHidden, mode, }?: UseBanglaTypingProps): {
|
|
11
|
+
text: string;
|
|
12
|
+
handleChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
13
|
+
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => Promise<void>;
|
|
14
|
+
suggestions: string[];
|
|
15
|
+
selectedSuggestionIndex: number;
|
|
16
|
+
applySuggestion: (suggestion: string, element: HTMLInputElement | HTMLTextAreaElement | null) => void;
|
|
17
|
+
handlePaste: () => void;
|
|
18
|
+
hideSuggestions: () => void;
|
|
19
|
+
handleFocus: () => void;
|
|
20
|
+
handleBlur: () => void;
|
|
21
|
+
isFocused: boolean;
|
|
22
|
+
};
|
|
23
|
+
export {};
|