@kiroku-solutions/typefix-wasm-core 0.1.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/LICENSE-APACHE +221 -0
- package/README.md +361 -0
- package/package.json +33 -0
- package/typefix.d.ts +74 -0
- package/typefix.js +372 -0
- package/typefix_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Kiroku Solutions
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024-2026 Kiroku Solutions
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
Full Apache License 2.0 text:
|
|
20
|
+
|
|
21
|
+
Apache License
|
|
22
|
+
Version 2.0, January 2004
|
|
23
|
+
http://www.apache.org/licenses/
|
|
24
|
+
|
|
25
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
26
|
+
|
|
27
|
+
1. Definitions.
|
|
28
|
+
|
|
29
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
30
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
31
|
+
|
|
32
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
33
|
+
the copyright owner that is granting the License.
|
|
34
|
+
|
|
35
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
36
|
+
other entities that control, are controlled by, or are under common
|
|
37
|
+
control with that entity. For the purposes of this definition,
|
|
38
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
39
|
+
direction or management of such entity, whether by contract or
|
|
40
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
41
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
42
|
+
|
|
43
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
44
|
+
exercising permissions granted by this License.
|
|
45
|
+
|
|
46
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
47
|
+
including but not limited to software source code, documentation
|
|
48
|
+
source, and configuration files.
|
|
49
|
+
|
|
50
|
+
"Object" form shall mean any form resulting from mechanical
|
|
51
|
+
transformation or translation of a Source form, including but
|
|
52
|
+
not limited to compiled object code, generated documentation,
|
|
53
|
+
and conversions to other media types.
|
|
54
|
+
|
|
55
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
56
|
+
Object form, made available under the License, as indicated by a
|
|
57
|
+
copyright notice that is included in or attached to the work
|
|
58
|
+
(an example is provided in the Appendix below).
|
|
59
|
+
|
|
60
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
61
|
+
form, that is based on (or derived from) the Work and for which the
|
|
62
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
63
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
64
|
+
of this License, Derivative Works shall not include works that remain
|
|
65
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
66
|
+
the Work and Derivative Works thereof.
|
|
67
|
+
|
|
68
|
+
"Contribution" shall mean any work of authorship, including
|
|
69
|
+
the original version of the Work and any modifications or additions
|
|
70
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
71
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
72
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
73
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
74
|
+
means any form of electronic, verbal, or written communication sent
|
|
75
|
+
to the Licensor or its representatives, including but not limited to
|
|
76
|
+
communication on electronic mailing lists, source code control systems,
|
|
77
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
78
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
79
|
+
excluding communication that is conspicuously marked or otherwise
|
|
80
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
81
|
+
|
|
82
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
83
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
84
|
+
subsequently incorporated within the Work.
|
|
85
|
+
|
|
86
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
87
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
88
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
89
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
90
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
91
|
+
Work and such Derivative Works in Source or Object form.
|
|
92
|
+
|
|
93
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
94
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
95
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
96
|
+
(except as stated in this section) patent license to make, have made,
|
|
97
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
98
|
+
where such license applies only to those patent claims licensable
|
|
99
|
+
by such Contributor that are necessarily infringed by their
|
|
100
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
101
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
102
|
+
institute patent litigation against any entity (including a
|
|
103
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
104
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
105
|
+
or contributory patent infringement, then any patent licenses
|
|
106
|
+
granted to You under this License for that Work shall terminate
|
|
107
|
+
as of the date such litigation is filed.
|
|
108
|
+
|
|
109
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
110
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
111
|
+
modifications, and in Source or Object form, provided that You
|
|
112
|
+
meet the following conditions:
|
|
113
|
+
|
|
114
|
+
(a) You must give any other recipients of the Work or
|
|
115
|
+
Derivative Works a copy of this License; and
|
|
116
|
+
|
|
117
|
+
(b) You must cause any modified files to carry prominent notices
|
|
118
|
+
stating that You changed the files; and
|
|
119
|
+
|
|
120
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
121
|
+
that You distribute, all copyright, patent, trademark, and
|
|
122
|
+
attribution notices from the Source form of the Work,
|
|
123
|
+
excluding those notices that do not pertain to any part of
|
|
124
|
+
the Derivative Works; and
|
|
125
|
+
|
|
126
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
127
|
+
distribution, then any Derivative Works that You distribute must
|
|
128
|
+
include a readable copy of the attribution notices contained
|
|
129
|
+
within such NOTICE file, excluding those notices that do not
|
|
130
|
+
pertain to any part of the Derivative Works, in at least one
|
|
131
|
+
of the following places: within a NOTICE text file distributed
|
|
132
|
+
as part of the Derivative Works; within the Source form or
|
|
133
|
+
documentation, if provided along with the Derivative Works; or,
|
|
134
|
+
within a display generated by the Derivative Works, if and
|
|
135
|
+
wherever such third-party notices normally appear. The contents
|
|
136
|
+
of the NOTICE file are for informational purposes only and
|
|
137
|
+
do not modify the License. You may add Your own attribution
|
|
138
|
+
notices within Derivative Works that You distribute, alongside
|
|
139
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
140
|
+
that such additional attribution notices cannot be construed
|
|
141
|
+
as modifying the License.
|
|
142
|
+
|
|
143
|
+
You may add Your own copyright statement to Your modifications and
|
|
144
|
+
may provide additional or different license terms and conditions
|
|
145
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
146
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
147
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
148
|
+
the conditions stated in this License.
|
|
149
|
+
|
|
150
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
151
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
152
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
153
|
+
this License, without any additional terms or conditions.
|
|
154
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
155
|
+
the terms of any separate license agreement you may have executed
|
|
156
|
+
with Licensor regarding such Contributions.
|
|
157
|
+
|
|
158
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
159
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
160
|
+
except as required for describing the origin of the Work and
|
|
161
|
+
reproducing the content of the NOTICE file.
|
|
162
|
+
|
|
163
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
164
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
165
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
166
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
167
|
+
implied, including, without limitation, any warranties or conditions
|
|
168
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
169
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
170
|
+
appropriateness of using or redistributing the Work and assume any
|
|
171
|
+
risks associated with Your exercise of permissions under this License.
|
|
172
|
+
|
|
173
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
174
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
175
|
+
unless required by applicable law (such as deliberate and grossly
|
|
176
|
+
negligent acts) or agreed in writing, shall any Contributor be
|
|
177
|
+
liable to You for damages, including any direct, indirect, special,
|
|
178
|
+
incidental, or consequential damages of any character arising as a
|
|
179
|
+
result of this License or out of the use or inability to use the
|
|
180
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
181
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
182
|
+
other commercial damages or losses), even if such Contributor
|
|
183
|
+
has been advised of the possibility of such damages.
|
|
184
|
+
|
|
185
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
186
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
187
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
188
|
+
liability obligations and/or rights consistent with this License.
|
|
189
|
+
However, in accepting such obligations, You may act only on Your
|
|
190
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
191
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
192
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
193
|
+
or claims asserted against, such Contributor by reason of your
|
|
194
|
+
accepting any such warranty or support.
|
|
195
|
+
|
|
196
|
+
END OF TERMS AND CONDITIONS
|
|
197
|
+
|
|
198
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
199
|
+
|
|
200
|
+
To apply the Apache License to your work, attach the following
|
|
201
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
202
|
+
replaced with your own identifying information. (Don't include
|
|
203
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
204
|
+
comment syntax for the file format. We also recommend that a
|
|
205
|
+
file or class name and description of purpose be included on the
|
|
206
|
+
same "printed page" as the copyright notice for easier
|
|
207
|
+
identification within third-party archives.
|
|
208
|
+
|
|
209
|
+
Copyright 2024-2026 Kiroku Solutions
|
|
210
|
+
|
|
211
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
212
|
+
you may not use this file except in compliance with the License.
|
|
213
|
+
You may obtain a copy of the License at
|
|
214
|
+
|
|
215
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
216
|
+
|
|
217
|
+
Unless required by applicable law or agreed to in writing, software
|
|
218
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
219
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
220
|
+
See the License for the specific language governing permissions and
|
|
221
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# TypeFix
|
|
2
|
+
|
|
3
|
+
**Hyper-lightweight, zero-latency typo correction and language detection engine written in Rust.**
|
|
4
|
+
|
|
5
|
+
> Open-source project maintained by [Kiroku Solutions](https://github.com/kiroku-solutions).
|
|
6
|
+
> Licensed under MIT OR Apache-2.0.
|
|
7
|
+
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://www.rust-lang.org)
|
|
10
|
+
[](https://github.com/kiroku-solutions)
|
|
11
|
+
[](https://crates.io/crates/typefix)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Zero-latency correction**: O(1) lookup for known typos, O(m*n) for Damerau-Levenshtein
|
|
16
|
+
- **Dynamic language detection**: Bayesian inference with rolling window
|
|
17
|
+
- **Memory efficient**: < 10MB RAM footprint (target)
|
|
18
|
+
- **Cross-platform**: Windows, Linux, macOS support
|
|
19
|
+
- **Fail-safe design**: Graceful degradation on any error
|
|
20
|
+
- **No garbage collection**: 100% Rust, zero allocations in hot path
|
|
21
|
+
|
|
22
|
+
## Performance
|
|
23
|
+
|
|
24
|
+
Stress test results on typical hardware:
|
|
25
|
+
|
|
26
|
+
| Benchmark | Result |
|
|
27
|
+
|-----------|--------|
|
|
28
|
+
| 50K word dictionary insert | 354ms |
|
|
29
|
+
| 50K word search | 3.6ms |
|
|
30
|
+
| 10K corrections/second | ✅ |
|
|
31
|
+
| Memory (idle) | < 10MB target |
|
|
32
|
+
| Latency per correction | < 1ms target |
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
38
|
+
│ TypeFixPipeline │
|
|
39
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
40
|
+
│ │
|
|
41
|
+
│ ┌──────────┐ ┌──────────────┐ ┌─────────────────────┐ │
|
|
42
|
+
│ │CharBuffer│───▶│LanguageDetec│───▶│ CorrectionEngine │ │
|
|
43
|
+
│ │ (64 chars)│ │ tor │ │ ┌───────────────┐ │ │
|
|
44
|
+
│ └──────────┘ │ │ │ │ StaticErrorMap│ │ │
|
|
45
|
+
│ │ │ • Bayesian │ │ │ (O(1) lookup) │ │ │
|
|
46
|
+
│ │ │ • Stopwords │ │ └───────────────┘ │ │
|
|
47
|
+
│ │ │ • Window │ │ ┌───────────────┐ │ │
|
|
48
|
+
│ │ │ (5 words) │ │ │ Trie (fuzzy) │ │ │
|
|
49
|
+
│ ▼ └──────────────┘ │ │ (O(m*n) DL) │ │ │
|
|
50
|
+
│ ┌──────────┐ │ └───────────────┘ │ │
|
|
51
|
+
│ │ Delimiter│ └─────────────────────┘ │
|
|
52
|
+
│ │ (space,.)│ │
|
|
53
|
+
│ └──────────┘ │
|
|
54
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Data Flow
|
|
58
|
+
|
|
59
|
+
1. **Keystroke Input** → `CharBuffer` accumulates characters
|
|
60
|
+
2. **Delimiter detected** → Buffer emits word token
|
|
61
|
+
3. **Language Detection** → Rolling window of 5 words analyzed
|
|
62
|
+
4. **Typo Correction** → Static map (instant) or Damerau-Levenshtein (fuzzy)
|
|
63
|
+
5. **Result** → Return corrected word if different
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
### Basic Usage
|
|
68
|
+
|
|
69
|
+
```rust
|
|
70
|
+
use typefix::{TypeFixPipeline, PipelineConfig};
|
|
71
|
+
|
|
72
|
+
// Create simple pipeline with test data
|
|
73
|
+
let pipeline = TypeFixPipeline::simple();
|
|
74
|
+
|
|
75
|
+
// Process text character by character
|
|
76
|
+
for ch in "teh world".chars() {
|
|
77
|
+
if let Some(result) = pipeline.push(ch) {
|
|
78
|
+
println!("Word: {}, Corrected: {:?}",
|
|
79
|
+
result.original,
|
|
80
|
+
result.corrected);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Output:
|
|
84
|
+
// Word: teh, Corrected: Some("the")
|
|
85
|
+
// Word: world, Corrected: None
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Using Individual Components
|
|
89
|
+
|
|
90
|
+
```rust
|
|
91
|
+
use typefix::{CharBuffer, LanguageDetector, CorrectionEngine};
|
|
92
|
+
|
|
93
|
+
// Buffer - accumulates keystrokes until delimiter
|
|
94
|
+
let buffer = CharBuffer::new();
|
|
95
|
+
buffer.push('h');
|
|
96
|
+
buffer.push('e');
|
|
97
|
+
buffer.push('l');
|
|
98
|
+
buffer.push('l');
|
|
99
|
+
let word = buffer.push(' '); // Some("hell")
|
|
100
|
+
|
|
101
|
+
// Language Detection - Bayesian inference
|
|
102
|
+
let mut detector = LanguageDetector::new(Default::default());
|
|
103
|
+
detector.set_language("en");
|
|
104
|
+
detector.process_word("the");
|
|
105
|
+
|
|
106
|
+
// Correction - static map + fuzzy matching
|
|
107
|
+
let mut engine = CorrectionEngine::new(Default::default());
|
|
108
|
+
let result = engine.correct("qeu"); // Some("que")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Event Subscription
|
|
112
|
+
|
|
113
|
+
```rust
|
|
114
|
+
use typefix::{TypeFixPipeline, PipelineConfig, PipelineEvent};
|
|
115
|
+
|
|
116
|
+
let config = PipelineConfig::default();
|
|
117
|
+
let mut pipeline = TypeFixPipeline::new(config);
|
|
118
|
+
|
|
119
|
+
// Subscribe to pipeline events
|
|
120
|
+
pipeline.on_event(|event| {
|
|
121
|
+
match event {
|
|
122
|
+
PipelineEvent::WordExtracted { word } => {
|
|
123
|
+
println!("Extracted: {}", word);
|
|
124
|
+
}
|
|
125
|
+
PipelineEvent::WordCorrected { original, corrected } => {
|
|
126
|
+
println!("{} → {}", original, corrected);
|
|
127
|
+
}
|
|
128
|
+
PipelineEvent::LanguageDetected { language, confidence } => {
|
|
129
|
+
println!("Detected: {} ({:.0}%)", language, confidence * 100.0);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Building
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Debug build
|
|
139
|
+
cargo build
|
|
140
|
+
|
|
141
|
+
# Release build (optimized)
|
|
142
|
+
cargo build --release
|
|
143
|
+
|
|
144
|
+
# Run stress tests
|
|
145
|
+
cargo run --bin stress-runner
|
|
146
|
+
|
|
147
|
+
# Run benchmarks
|
|
148
|
+
cargo bench
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Testing
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Run all tests
|
|
155
|
+
cargo test
|
|
156
|
+
|
|
157
|
+
# Run with output
|
|
158
|
+
cargo test -- --nocapture
|
|
159
|
+
|
|
160
|
+
# Run specific test file
|
|
161
|
+
cargo test --test stress_test
|
|
162
|
+
|
|
163
|
+
# Run specific test
|
|
164
|
+
cargo test test_name
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Data Files
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
data/
|
|
171
|
+
├── dictionaries/ # Word dictionaries by language
|
|
172
|
+
│ ├── es.json # Spanish
|
|
173
|
+
│ ├── en.json # English
|
|
174
|
+
│ └── pt.json # Portuguese
|
|
175
|
+
├── stopwords/ # Stopwords for language detection
|
|
176
|
+
│ ├── es.json
|
|
177
|
+
│ ├── en.json
|
|
178
|
+
│ └── pt.json
|
|
179
|
+
└── errors/ # Common typos
|
|
180
|
+
├── es.json
|
|
181
|
+
└── en.json
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Dictionary Format
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"language": "es",
|
|
189
|
+
"version": "1.0",
|
|
190
|
+
"words": [
|
|
191
|
+
{"word": "que", "frequency": 1000000},
|
|
192
|
+
{"word": "hola", "frequency": 500000}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Stopwords Format
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"language": "es",
|
|
202
|
+
"stopwords": ["el", "la", "de", "que", "y"]
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Common Errors Format
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"language": "es",
|
|
211
|
+
"errors": {
|
|
212
|
+
"qeu": "que",
|
|
213
|
+
"qe": "que",
|
|
214
|
+
"teh": "the"
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Configuration
|
|
220
|
+
|
|
221
|
+
### Default Configuration
|
|
222
|
+
|
|
223
|
+
```rust
|
|
224
|
+
// Pipeline
|
|
225
|
+
PipelineConfig {
|
|
226
|
+
max_buffer_size: 64,
|
|
227
|
+
enable_correction: true,
|
|
228
|
+
enable_language_detection: true,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Engine
|
|
232
|
+
EngineConfig {
|
|
233
|
+
max_edit_distance: 1,
|
|
234
|
+
max_corrections: 3,
|
|
235
|
+
min_word_length: 2,
|
|
236
|
+
dictionary: None,
|
|
237
|
+
error_map: None,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Detector
|
|
241
|
+
DetectorConfig {
|
|
242
|
+
window_size: 5,
|
|
243
|
+
confidence_threshold: 0.85,
|
|
244
|
+
hysteresis_zone: 0.10,
|
|
245
|
+
min_words_before_switch: 5,
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### JSON Configuration
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"language_detection": {
|
|
254
|
+
"window_size": 5,
|
|
255
|
+
"confidence_threshold": 0.85,
|
|
256
|
+
"hysteresis_zone": 0.10,
|
|
257
|
+
"min_words_before_switch": 5
|
|
258
|
+
},
|
|
259
|
+
"correction": {
|
|
260
|
+
"max_edit_distance": 1,
|
|
261
|
+
"max_corrections": 3,
|
|
262
|
+
"min_word_length": 2
|
|
263
|
+
},
|
|
264
|
+
"buffer": {
|
|
265
|
+
"max_size": 64
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Project Structure
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
typefix/
|
|
274
|
+
├── src/
|
|
275
|
+
│ ├── core/ # Core data structures
|
|
276
|
+
│ │ ├── buffer.rs # Ring buffer for keystrokes
|
|
277
|
+
│ │ ├── trie.rs # Trie for dictionary lookups
|
|
278
|
+
│ │ └── config.rs # Configuration management
|
|
279
|
+
│ ├── language/ # Language detection
|
|
280
|
+
│ │ ├── detector.rs # Bayesian language detector
|
|
281
|
+
│ │ └── stopwords.rs# Stopwords trie
|
|
282
|
+
│ ├── correction/ # Typo correction
|
|
283
|
+
│ │ ├── damerau.rs # Damerau-Levenshtein distance
|
|
284
|
+
│ │ ├── engine.rs # Correction engine
|
|
285
|
+
│ │ └── static_map.rs# Static error map
|
|
286
|
+
│ ├── pipeline.rs # Complete processing pipeline
|
|
287
|
+
│ ├── hooks/ # Platform hooks
|
|
288
|
+
│ │ ├── platform.rs # Platform abstraction
|
|
289
|
+
│ │ ├── windows.rs # Windows implementation
|
|
290
|
+
│ │ ├── linux.rs # Linux implementation
|
|
291
|
+
│ │ └── macos.rs # macOS implementation
|
|
292
|
+
│ ├── memory.rs # Memory profiling utilities
|
|
293
|
+
│ ├── benchmark.rs # Performance benchmarks
|
|
294
|
+
│ └── lib.rs # Library entry point
|
|
295
|
+
├── tests/
|
|
296
|
+
│ └── stress_test.rs # Stress tests and benchmarks
|
|
297
|
+
├── docs/
|
|
298
|
+
│ ├── plan-implementacion.md
|
|
299
|
+
│ ├── final-review-2026-06-16.md
|
|
300
|
+
│ └── integration-ehr-legal.md # EHR/Legal integration guide
|
|
301
|
+
├── Cargo.toml
|
|
302
|
+
└── README.md
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## EHR and Legal Integration
|
|
306
|
+
|
|
307
|
+
The TypeFix supports integration with Electronic Health Records (EHR) and Legal document management systems. See [docs/integration-ehr-legal.md](docs/integration-ehr-legal.md) for:
|
|
308
|
+
|
|
309
|
+
- **EHR Integration**: HIPAA-compliant configuration, medical terminology support (ICD-10, SNOMED CT), audit trails
|
|
310
|
+
- **Legal Integration**: Citation preservation, redlining support, multi-jurisdiction dictionaries
|
|
311
|
+
- **API Reference**: Full API documentation with data structures
|
|
312
|
+
- **Security Considerations**: PHI handling, audit logging patterns
|
|
313
|
+
- **Example Code**: Production-ready integration handlers for both domains
|
|
314
|
+
|
|
315
|
+
## Implementation Phases
|
|
316
|
+
|
|
317
|
+
| Phase | Status | Description |
|
|
318
|
+
|-------|--------|-------------|
|
|
319
|
+
| 1 | ✅ Done | Core engine (Trie, Buffer, Config) |
|
|
320
|
+
| 2 | ✅ Done | Language detection |
|
|
321
|
+
| 3 | ✅ Done | Correction engine (Damerau-Levenshtein) |
|
|
322
|
+
| 4 | ✅ Done | Platform hooks (Windows/Linux/macOS) |
|
|
323
|
+
| 5 | ✅ Done | Performance testing (benchmarks, stress tests) |
|
|
324
|
+
| 6 | In Progress | Documentation and deployment |
|
|
325
|
+
| 7-10 | Pending | Real-world integration testing |
|
|
326
|
+
|
|
327
|
+
## Contributing
|
|
328
|
+
|
|
329
|
+
1. Fork the repository
|
|
330
|
+
2. Create a feature branch
|
|
331
|
+
3. Run tests: `cargo test`
|
|
332
|
+
4. Run benchmarks: `cargo run --bin stress-runner`
|
|
333
|
+
5. Submit a pull request
|
|
334
|
+
|
|
335
|
+
## License
|
|
336
|
+
|
|
337
|
+
TypeFix is open-source software licensed under the **MIT OR Apache-2.0** dual license.
|
|
338
|
+
|
|
339
|
+
Copyright (c) 2024-2026 Kiroku Solutions. All rights reserved.
|
|
340
|
+
|
|
341
|
+
See [LICENSE](./LICENSE) and [LICENSE-APACHE](./LICENSE-APACHE) for the full text.
|
|
342
|
+
|
|
343
|
+
## About Kiroku Solutions
|
|
344
|
+
|
|
345
|
+
TypeFix is developed and maintained by [Kiroku Solutions](https://github.com/kiroku-solutions), a software consultancy focused on high-performance, low-latency text processing systems. We build open-source tools that make software more accessible to everyone.
|
|
346
|
+
|
|
347
|
+
- Website: [kiroku.solutions](https://www.kirokusolutions.com/)
|
|
348
|
+
- GitHub: [@kiroku-solutions](https://github.com/kiroku-solutions)
|
|
349
|
+
- Contact: contact@kirokusolutions.com
|
|
350
|
+
|
|
351
|
+
## Support
|
|
352
|
+
|
|
353
|
+
- **Issues**: [GitHub Issues](https://github.com/kiroku-solutions/typefix/issues)
|
|
354
|
+
- **Discussions**: [GitHub Discussions](https://github.com/kiroku-solutions/typefix/discussions)
|
|
355
|
+
- **Security**: See [SECURITY.md](./SECURITY.md) for reporting vulnerabilities
|
|
356
|
+
|
|
357
|
+
## Contributing
|
|
358
|
+
|
|
359
|
+
We welcome contributions from the community! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
360
|
+
|
|
361
|
+
Please read our [Code of Conduct](./CODE_OF_CONDUCT.md) before participating.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kiroku-solutions/typefix-wasm-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Kiroku Solutions <opensource@kiroku.solutions>"
|
|
6
|
+
],
|
|
7
|
+
"description": "Hyper-lightweight, zero-latency typo correction and language detection engine",
|
|
8
|
+
"version": "0.1.1",
|
|
9
|
+
"license": "MIT OR Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/kiroku-solutions/typefix"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"typefix_bg.wasm",
|
|
16
|
+
"typefix.js",
|
|
17
|
+
"typefix.d.ts",
|
|
18
|
+
"LICENSE-APACHE"
|
|
19
|
+
],
|
|
20
|
+
"main": "typefix.js",
|
|
21
|
+
"homepage": "https://github.com/kiroku-solutions/typefix",
|
|
22
|
+
"types": "typefix.d.ts",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./snippets/*"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"typo",
|
|
28
|
+
"correction",
|
|
29
|
+
"language-detection",
|
|
30
|
+
"trie",
|
|
31
|
+
"damerau-levenshtein"
|
|
32
|
+
]
|
|
33
|
+
}
|
package/typefix.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class TypeFixWeb {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Clear the internal buffer
|
|
9
|
+
*/
|
|
10
|
+
clear(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Load an FST dictionary from a Uint8Array
|
|
13
|
+
*/
|
|
14
|
+
loadDictionary(lang: string, bytes: Uint8Array): void;
|
|
15
|
+
/**
|
|
16
|
+
* Load stopwords from a JSON string
|
|
17
|
+
*/
|
|
18
|
+
loadStopwords(lang: string, json_str: string): void;
|
|
19
|
+
constructor(auto_correct: boolean, detect_language: boolean, buffer_size: number);
|
|
20
|
+
/**
|
|
21
|
+
* Process an entire string statelessly
|
|
22
|
+
* Returns a JSON array of PipelineEvents
|
|
23
|
+
*/
|
|
24
|
+
processString(text: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Process a character input
|
|
27
|
+
* Returns a JSON string of the PipelineEvent if an event was generated, or null.
|
|
28
|
+
*/
|
|
29
|
+
pushChar(ch: string): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Set the current language
|
|
32
|
+
*/
|
|
33
|
+
setLanguage(lang: string): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
37
|
+
|
|
38
|
+
export interface InitOutput {
|
|
39
|
+
readonly memory: WebAssembly.Memory;
|
|
40
|
+
readonly __wbg_typefixweb_free: (a: number, b: number) => void;
|
|
41
|
+
readonly typefixweb_clear: (a: number) => void;
|
|
42
|
+
readonly typefixweb_loadDictionary: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
43
|
+
readonly typefixweb_loadStopwords: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
44
|
+
readonly typefixweb_new: (a: number, b: number, c: number) => number;
|
|
45
|
+
readonly typefixweb_processString: (a: number, b: number, c: number, d: number) => void;
|
|
46
|
+
readonly typefixweb_pushChar: (a: number, b: number, c: number) => void;
|
|
47
|
+
readonly typefixweb_setLanguage: (a: number, b: number, c: number) => void;
|
|
48
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
49
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
50
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
51
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
58
|
+
* a precompiled `WebAssembly.Module`.
|
|
59
|
+
*
|
|
60
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
61
|
+
*
|
|
62
|
+
* @returns {InitOutput}
|
|
63
|
+
*/
|
|
64
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
68
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
71
|
+
*
|
|
72
|
+
* @returns {Promise<InitOutput>}
|
|
73
|
+
*/
|
|
74
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/typefix.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/* @ts-self-types="./typefix.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class TypeFixWeb {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
TypeFixWebFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_typefixweb_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Clear the internal buffer
|
|
16
|
+
*/
|
|
17
|
+
clear() {
|
|
18
|
+
wasm.typefixweb_clear(this.__wbg_ptr);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load an FST dictionary from a Uint8Array
|
|
22
|
+
* @param {string} lang
|
|
23
|
+
* @param {Uint8Array} bytes
|
|
24
|
+
*/
|
|
25
|
+
loadDictionary(lang, bytes) {
|
|
26
|
+
try {
|
|
27
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
28
|
+
const ptr0 = passStringToWasm0(lang, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
29
|
+
const len0 = WASM_VECTOR_LEN;
|
|
30
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
31
|
+
const len1 = WASM_VECTOR_LEN;
|
|
32
|
+
wasm.typefixweb_loadDictionary(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
33
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
34
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
35
|
+
if (r1) {
|
|
36
|
+
throw takeObject(r0);
|
|
37
|
+
}
|
|
38
|
+
} finally {
|
|
39
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Load stopwords from a JSON string
|
|
44
|
+
* @param {string} lang
|
|
45
|
+
* @param {string} json_str
|
|
46
|
+
*/
|
|
47
|
+
loadStopwords(lang, json_str) {
|
|
48
|
+
try {
|
|
49
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
50
|
+
const ptr0 = passStringToWasm0(lang, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
51
|
+
const len0 = WASM_VECTOR_LEN;
|
|
52
|
+
const ptr1 = passStringToWasm0(json_str, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
53
|
+
const len1 = WASM_VECTOR_LEN;
|
|
54
|
+
wasm.typefixweb_loadStopwords(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
55
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
56
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
57
|
+
if (r1) {
|
|
58
|
+
throw takeObject(r0);
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @param {boolean} auto_correct
|
|
66
|
+
* @param {boolean} detect_language
|
|
67
|
+
* @param {number} buffer_size
|
|
68
|
+
*/
|
|
69
|
+
constructor(auto_correct, detect_language, buffer_size) {
|
|
70
|
+
const ret = wasm.typefixweb_new(auto_correct, detect_language, buffer_size);
|
|
71
|
+
this.__wbg_ptr = ret;
|
|
72
|
+
TypeFixWebFinalization.register(this, this.__wbg_ptr, this);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Process an entire string statelessly
|
|
77
|
+
* Returns a JSON array of PipelineEvents
|
|
78
|
+
* @param {string} text
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
processString(text) {
|
|
82
|
+
let deferred2_0;
|
|
83
|
+
let deferred2_1;
|
|
84
|
+
try {
|
|
85
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
86
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
87
|
+
const len0 = WASM_VECTOR_LEN;
|
|
88
|
+
wasm.typefixweb_processString(retptr, this.__wbg_ptr, ptr0, len0);
|
|
89
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
90
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
91
|
+
deferred2_0 = r0;
|
|
92
|
+
deferred2_1 = r1;
|
|
93
|
+
return getStringFromWasm0(r0, r1);
|
|
94
|
+
} finally {
|
|
95
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
96
|
+
wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Process a character input
|
|
101
|
+
* Returns a JSON string of the PipelineEvent if an event was generated, or null.
|
|
102
|
+
* @param {string} ch
|
|
103
|
+
* @returns {string | undefined}
|
|
104
|
+
*/
|
|
105
|
+
pushChar(ch) {
|
|
106
|
+
try {
|
|
107
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
108
|
+
const char0 = ch.codePointAt(0);
|
|
109
|
+
_assertChar(char0);
|
|
110
|
+
wasm.typefixweb_pushChar(retptr, this.__wbg_ptr, char0);
|
|
111
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
112
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
113
|
+
let v2;
|
|
114
|
+
if (r0 !== 0) {
|
|
115
|
+
v2 = getStringFromWasm0(r0, r1).slice();
|
|
116
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
117
|
+
}
|
|
118
|
+
return v2;
|
|
119
|
+
} finally {
|
|
120
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Set the current language
|
|
125
|
+
* @param {string} lang
|
|
126
|
+
*/
|
|
127
|
+
setLanguage(lang) {
|
|
128
|
+
const ptr0 = passStringToWasm0(lang, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
129
|
+
const len0 = WASM_VECTOR_LEN;
|
|
130
|
+
wasm.typefixweb_setLanguage(this.__wbg_ptr, ptr0, len0);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (Symbol.dispose) TypeFixWeb.prototype[Symbol.dispose] = TypeFixWeb.prototype.free;
|
|
134
|
+
function __wbg_get_imports() {
|
|
135
|
+
const import0 = {
|
|
136
|
+
__proto__: null,
|
|
137
|
+
__wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
|
|
138
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
139
|
+
},
|
|
140
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
141
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
142
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
143
|
+
return addHeapObject(ret);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
__proto__: null,
|
|
148
|
+
"./typefix_bg.js": import0,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const TypeFixWebFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
153
|
+
? { register: () => {}, unregister: () => {} }
|
|
154
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_typefixweb_free(ptr, 1));
|
|
155
|
+
|
|
156
|
+
function addHeapObject(obj) {
|
|
157
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
158
|
+
const idx = heap_next;
|
|
159
|
+
heap_next = heap[idx];
|
|
160
|
+
|
|
161
|
+
heap[idx] = obj;
|
|
162
|
+
return idx;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function _assertChar(c) {
|
|
166
|
+
if (typeof(c) === 'number' && (c >= 0x110000 || (c >= 0xD800 && c < 0xE000))) throw new Error(`expected a valid Unicode scalar value, found ${c}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function dropObject(idx) {
|
|
170
|
+
if (idx < 1028) return;
|
|
171
|
+
heap[idx] = heap_next;
|
|
172
|
+
heap_next = idx;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let cachedDataViewMemory0 = null;
|
|
176
|
+
function getDataViewMemory0() {
|
|
177
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
178
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
179
|
+
}
|
|
180
|
+
return cachedDataViewMemory0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function getStringFromWasm0(ptr, len) {
|
|
184
|
+
return decodeText(ptr >>> 0, len);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let cachedUint8ArrayMemory0 = null;
|
|
188
|
+
function getUint8ArrayMemory0() {
|
|
189
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
190
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
191
|
+
}
|
|
192
|
+
return cachedUint8ArrayMemory0;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getObject(idx) { return heap[idx]; }
|
|
196
|
+
|
|
197
|
+
let heap = new Array(1024).fill(undefined);
|
|
198
|
+
heap.push(undefined, null, true, false);
|
|
199
|
+
|
|
200
|
+
let heap_next = heap.length;
|
|
201
|
+
|
|
202
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
203
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
204
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
205
|
+
WASM_VECTOR_LEN = arg.length;
|
|
206
|
+
return ptr;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
210
|
+
if (realloc === undefined) {
|
|
211
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
212
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
213
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
214
|
+
WASM_VECTOR_LEN = buf.length;
|
|
215
|
+
return ptr;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let len = arg.length;
|
|
219
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
220
|
+
|
|
221
|
+
const mem = getUint8ArrayMemory0();
|
|
222
|
+
|
|
223
|
+
let offset = 0;
|
|
224
|
+
|
|
225
|
+
for (; offset < len; offset++) {
|
|
226
|
+
const code = arg.charCodeAt(offset);
|
|
227
|
+
if (code > 0x7F) break;
|
|
228
|
+
mem[ptr + offset] = code;
|
|
229
|
+
}
|
|
230
|
+
if (offset !== len) {
|
|
231
|
+
if (offset !== 0) {
|
|
232
|
+
arg = arg.slice(offset);
|
|
233
|
+
}
|
|
234
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
235
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
236
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
237
|
+
|
|
238
|
+
offset += ret.written;
|
|
239
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
WASM_VECTOR_LEN = offset;
|
|
243
|
+
return ptr;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function takeObject(idx) {
|
|
247
|
+
const ret = getObject(idx);
|
|
248
|
+
dropObject(idx);
|
|
249
|
+
return ret;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
253
|
+
cachedTextDecoder.decode();
|
|
254
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
255
|
+
let numBytesDecoded = 0;
|
|
256
|
+
function decodeText(ptr, len) {
|
|
257
|
+
numBytesDecoded += len;
|
|
258
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
259
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
260
|
+
cachedTextDecoder.decode();
|
|
261
|
+
numBytesDecoded = len;
|
|
262
|
+
}
|
|
263
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const cachedTextEncoder = new TextEncoder();
|
|
267
|
+
|
|
268
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
269
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
270
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
271
|
+
view.set(buf);
|
|
272
|
+
return {
|
|
273
|
+
read: arg.length,
|
|
274
|
+
written: buf.length
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let WASM_VECTOR_LEN = 0;
|
|
280
|
+
|
|
281
|
+
let wasmModule, wasmInstance, wasm;
|
|
282
|
+
function __wbg_finalize_init(instance, module) {
|
|
283
|
+
wasmInstance = instance;
|
|
284
|
+
wasm = instance.exports;
|
|
285
|
+
wasmModule = module;
|
|
286
|
+
cachedDataViewMemory0 = null;
|
|
287
|
+
cachedUint8ArrayMemory0 = null;
|
|
288
|
+
return wasm;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function __wbg_load(module, imports) {
|
|
292
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
293
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
294
|
+
try {
|
|
295
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
298
|
+
|
|
299
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
300
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
301
|
+
|
|
302
|
+
} else { throw e; }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const bytes = await module.arrayBuffer();
|
|
307
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
308
|
+
} else {
|
|
309
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
310
|
+
|
|
311
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
312
|
+
return { instance, module };
|
|
313
|
+
} else {
|
|
314
|
+
return instance;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function expectedResponseType(type) {
|
|
319
|
+
switch (type) {
|
|
320
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function initSync(module) {
|
|
327
|
+
if (wasm !== undefined) return wasm;
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
if (module !== undefined) {
|
|
331
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
332
|
+
({module} = module)
|
|
333
|
+
} else {
|
|
334
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const imports = __wbg_get_imports();
|
|
339
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
340
|
+
module = new WebAssembly.Module(module);
|
|
341
|
+
}
|
|
342
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
343
|
+
return __wbg_finalize_init(instance, module);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function __wbg_init(module_or_path) {
|
|
347
|
+
if (wasm !== undefined) return wasm;
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
if (module_or_path !== undefined) {
|
|
351
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
352
|
+
({module_or_path} = module_or_path)
|
|
353
|
+
} else {
|
|
354
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (module_or_path === undefined) {
|
|
359
|
+
module_or_path = new URL('typefix_bg.wasm', import.meta.url);
|
|
360
|
+
}
|
|
361
|
+
const imports = __wbg_get_imports();
|
|
362
|
+
|
|
363
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
364
|
+
module_or_path = fetch(module_or_path);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
368
|
+
|
|
369
|
+
return __wbg_finalize_init(instance, module);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export { initSync, __wbg_init as default };
|
package/typefix_bg.wasm
ADDED
|
Binary file
|