@hyperfixi/types-browser 2.0.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.
- package/README.md +90 -0
- package/dist/core-api.d.ts +217 -0
- package/dist/core-api.d.ts.map +1 -0
- package/dist/i18n-api.d.ts +170 -0
- package/dist/i18n-api.d.ts.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/semantic-api.d.ts +180 -0
- package/dist/semantic-api.d.ts.map +1 -0
- package/dist/type-guards.d.ts +31 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/package.json +47 -0
- package/src/core-api.d.ts +280 -0
- package/src/core-api.ts +261 -0
- package/src/globals.d.ts +85 -0
- package/src/i18n-api.d.ts +57 -0
- package/src/i18n-api.ts +209 -0
- package/src/index.d.ts +28 -0
- package/src/index.ts +62 -0
- package/src/semantic-api.d.ts +74 -0
- package/src/semantic-api.ts +242 -0
- package/src/type-guards.ts +73 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for @lokascript/semantic browser global (window.HyperFixiSemantic)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface LokaScriptSemanticAPI {
|
|
6
|
+
/**
|
|
7
|
+
* Parse hyperscript in any supported language
|
|
8
|
+
*/
|
|
9
|
+
parse(source: string, language: string): SemanticNode;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Translate hyperscript between languages
|
|
13
|
+
*/
|
|
14
|
+
translate(source: string, fromLang: string, toLang: string): string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get all translations for a source in all supported languages
|
|
18
|
+
*/
|
|
19
|
+
getAllTranslations(source: string, sourceLang: string): Record<string, string>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a semantic analyzer instance
|
|
23
|
+
*/
|
|
24
|
+
createSemanticAnalyzer(options?: SemanticAnalyzerOptions): SemanticAnalyzer;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get list of supported languages
|
|
28
|
+
*/
|
|
29
|
+
supportedLanguages: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SemanticNode {
|
|
33
|
+
kind: string;
|
|
34
|
+
action: string;
|
|
35
|
+
roles: ReadonlyMap<string, SemanticValue>;
|
|
36
|
+
confidence: number;
|
|
37
|
+
metadata?: {
|
|
38
|
+
sourcePosition?: {
|
|
39
|
+
start: number;
|
|
40
|
+
end: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SemanticValue {
|
|
46
|
+
type: 'literal' | 'selector' | 'reference' | 'property-path' | 'expression';
|
|
47
|
+
value: string | number | boolean;
|
|
48
|
+
dataType?: string;
|
|
49
|
+
selectorKind?: string;
|
|
50
|
+
object?: SemanticValue;
|
|
51
|
+
property?: string;
|
|
52
|
+
raw?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface SemanticAnalyzer {
|
|
56
|
+
analyze(input: string, language: string): AnalysisResult;
|
|
57
|
+
supportsLanguage(language: string): boolean;
|
|
58
|
+
supportedLanguages(): string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface SemanticAnalyzerOptions {
|
|
62
|
+
confidenceThreshold?: number;
|
|
63
|
+
languages?: string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AnalysisResult {
|
|
67
|
+
confidence: number;
|
|
68
|
+
command?: {
|
|
69
|
+
name: string;
|
|
70
|
+
roles: ReadonlyMap<string, SemanticValue>;
|
|
71
|
+
};
|
|
72
|
+
errors?: string[];
|
|
73
|
+
tokensConsumed?: number;
|
|
74
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for HyperFixi Semantic browser API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type SupportedLanguage =
|
|
6
|
+
| 'en'
|
|
7
|
+
| 'ja'
|
|
8
|
+
| 'ar'
|
|
9
|
+
| 'es'
|
|
10
|
+
| 'ko'
|
|
11
|
+
| 'tr'
|
|
12
|
+
| 'zh'
|
|
13
|
+
| 'pt'
|
|
14
|
+
| 'fr'
|
|
15
|
+
| 'de'
|
|
16
|
+
| 'id'
|
|
17
|
+
| 'qu'
|
|
18
|
+
| 'sw';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* HyperFixi semantic parser API exposed on window.HyperFixiSemantic
|
|
22
|
+
*/
|
|
23
|
+
export interface LokaScriptSemanticAPI {
|
|
24
|
+
/**
|
|
25
|
+
* Parse hyperscript in any supported language to semantic representation
|
|
26
|
+
*
|
|
27
|
+
* @param code Hyperscript code to parse
|
|
28
|
+
* @param language Two-letter language code (en, ja, ar, es, ko, tr, zh, pt, fr, de, id, qu, sw)
|
|
29
|
+
* @returns Parsed semantic node or null
|
|
30
|
+
*/
|
|
31
|
+
parse(code: string, language: SupportedLanguage): SemanticNode | null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Check if hyperscript can be parsed in a language
|
|
35
|
+
*/
|
|
36
|
+
canParse(code: string, language: SupportedLanguage): boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parse in any supported language (auto-detect)
|
|
40
|
+
*/
|
|
41
|
+
parseAny(code: string): SemanticNode | null;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse explicit syntax
|
|
45
|
+
*/
|
|
46
|
+
parseExplicit(code: string): any | null;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Check if code uses explicit syntax
|
|
50
|
+
*/
|
|
51
|
+
isExplicitSyntax(code: string): boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Translate hyperscript between languages
|
|
55
|
+
*/
|
|
56
|
+
translate(
|
|
57
|
+
code: string,
|
|
58
|
+
fromLanguage: SupportedLanguage,
|
|
59
|
+
toLanguage: SupportedLanguage
|
|
60
|
+
): string | null;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get all translations of hyperscript in supported languages
|
|
64
|
+
*/
|
|
65
|
+
getAllTranslations(
|
|
66
|
+
code: string,
|
|
67
|
+
fromLanguage: SupportedLanguage
|
|
68
|
+
): Record<SupportedLanguage, string>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Round-trip translation validation
|
|
72
|
+
*/
|
|
73
|
+
roundTrip(code: string, language: SupportedLanguage): boolean;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validate translation accuracy
|
|
77
|
+
*/
|
|
78
|
+
validateTranslation(
|
|
79
|
+
original: string,
|
|
80
|
+
translated: string,
|
|
81
|
+
fromLang: SupportedLanguage,
|
|
82
|
+
toLang: SupportedLanguage
|
|
83
|
+
): boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Render semantic node to hyperscript
|
|
87
|
+
*/
|
|
88
|
+
render(node: SemanticNode, language: SupportedLanguage): string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Render to explicit syntax
|
|
92
|
+
*/
|
|
93
|
+
renderExplicit(node: SemanticNode): string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Convert to explicit syntax
|
|
97
|
+
*/
|
|
98
|
+
toExplicit(code: string, language: SupportedLanguage): string | null;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Convert from explicit syntax
|
|
102
|
+
*/
|
|
103
|
+
fromExplicit(code: string, language: SupportedLanguage): string | null;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create semantic analyzer
|
|
107
|
+
*/
|
|
108
|
+
createSemanticAnalyzer(options?: any): any;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Check if semantic result should be used
|
|
112
|
+
*/
|
|
113
|
+
shouldUseSemanticResult(semanticNode: SemanticNode | null, fallbackNode: any): boolean;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Build AST from semantic node
|
|
117
|
+
*/
|
|
118
|
+
buildAST(node: SemanticNode): any;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Tokenize code in a specific language
|
|
122
|
+
*/
|
|
123
|
+
tokenize(code: string, language: SupportedLanguage): any[];
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get tokenizer for a language
|
|
127
|
+
*/
|
|
128
|
+
getTokenizer(language: SupportedLanguage): any;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Check if language is supported
|
|
132
|
+
*/
|
|
133
|
+
isLanguageSupported(language: string): boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get list of supported language codes
|
|
137
|
+
*/
|
|
138
|
+
getSupportedLanguages(): SupportedLanguage[];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create CSS selector helper
|
|
142
|
+
*/
|
|
143
|
+
createSelector(value: string): any;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Create literal value helper
|
|
147
|
+
*/
|
|
148
|
+
createLiteral(value: any): any;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Create reference helper
|
|
152
|
+
*/
|
|
153
|
+
createReference(name: string): any;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Create property path helper
|
|
157
|
+
*/
|
|
158
|
+
createPropertyPath(path: string[]): any;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Create command node helper
|
|
162
|
+
*/
|
|
163
|
+
createCommandNode(command: string, options?: any): any;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create event handler helper
|
|
167
|
+
*/
|
|
168
|
+
createEventHandler(event: string, options?: any): any;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get command mapper
|
|
172
|
+
*/
|
|
173
|
+
getCommandMapper(command: string): any;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Register command mapper
|
|
177
|
+
*/
|
|
178
|
+
registerCommandMapper(command: string, mapper: any): void;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Package version
|
|
182
|
+
*/
|
|
183
|
+
VERSION: string;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Default confidence threshold
|
|
187
|
+
*/
|
|
188
|
+
DEFAULT_CONFIDENCE_THRESHOLD: number;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* High confidence threshold
|
|
192
|
+
*/
|
|
193
|
+
HIGH_CONFIDENCE_THRESHOLD: number;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Language-specific tokenizers
|
|
197
|
+
*/
|
|
198
|
+
englishTokenizer: any;
|
|
199
|
+
japaneseTokenizer: any;
|
|
200
|
+
koreanTokenizer: any;
|
|
201
|
+
arabicTokenizer: any;
|
|
202
|
+
spanishTokenizer: any;
|
|
203
|
+
turkishTokenizer: any;
|
|
204
|
+
chineseTokenizer: any;
|
|
205
|
+
portugueseTokenizer: any;
|
|
206
|
+
frenchTokenizer: any;
|
|
207
|
+
germanTokenizer: any;
|
|
208
|
+
indonesianTokenizer: any;
|
|
209
|
+
quechuaTokenizer: any;
|
|
210
|
+
swahiliTokenizer: any;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Semantic analyzer implementation
|
|
214
|
+
*/
|
|
215
|
+
SemanticAnalyzerImpl: any;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* AST Builder class
|
|
219
|
+
*/
|
|
220
|
+
ASTBuilder: any;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface SemanticNode {
|
|
224
|
+
action: string;
|
|
225
|
+
roles: Map<string, SemanticValue>;
|
|
226
|
+
confidence: number;
|
|
227
|
+
errors?: ValidationError[];
|
|
228
|
+
tokens?: any[];
|
|
229
|
+
[key: string]: any;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface SemanticValue {
|
|
233
|
+
value: any;
|
|
234
|
+
type?: string;
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface ValidationError {
|
|
239
|
+
message: string;
|
|
240
|
+
code?: string;
|
|
241
|
+
[key: string]: any;
|
|
242
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guards for browser globals
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LokaScriptCoreAPI } from './core-api';
|
|
6
|
+
import type { LokaScriptSemanticAPI } from './semantic-api';
|
|
7
|
+
import type { LokaScriptI18nAPI } from './i18n-api';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if window.hyperfixi is available and properly typed
|
|
11
|
+
*/
|
|
12
|
+
export function isHyperFixiCoreAvailable(obj?: any): obj is LokaScriptCoreAPI {
|
|
13
|
+
return (
|
|
14
|
+
typeof obj === 'object' &&
|
|
15
|
+
obj !== null &&
|
|
16
|
+
typeof obj.execute === 'function' &&
|
|
17
|
+
typeof obj.compile === 'function'
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if window.HyperFixiSemantic is available
|
|
23
|
+
*/
|
|
24
|
+
export function isHyperFixiSemanticAvailable(obj?: any): obj is LokaScriptSemanticAPI {
|
|
25
|
+
return (
|
|
26
|
+
typeof obj === 'object' &&
|
|
27
|
+
obj !== null &&
|
|
28
|
+
typeof obj.parse === 'function' &&
|
|
29
|
+
typeof obj.canParse === 'function'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Check if window.HyperFixiI18n is available
|
|
35
|
+
*/
|
|
36
|
+
export function isHyperFixiI18nAvailable(obj?: any): obj is LokaScriptI18nAPI {
|
|
37
|
+
return (
|
|
38
|
+
typeof obj === 'object' &&
|
|
39
|
+
obj !== null &&
|
|
40
|
+
typeof obj.translate === 'function' &&
|
|
41
|
+
typeof obj.getSupportedLocales === 'function'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Safe access to window.hyperfixi with type checking
|
|
47
|
+
*/
|
|
48
|
+
export function getHyperFixiCore(): LokaScriptCoreAPI | null {
|
|
49
|
+
if (typeof window !== 'undefined' && isHyperFixiCoreAvailable(window.hyperfixi)) {
|
|
50
|
+
return window.hyperfixi;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Safe access to window.LokaScriptSemantic with type checking
|
|
57
|
+
*/
|
|
58
|
+
export function getHyperFixiSemantic(): LokaScriptSemanticAPI | null {
|
|
59
|
+
if (typeof window !== 'undefined' && isHyperFixiSemanticAvailable(window.LokaScriptSemantic)) {
|
|
60
|
+
return window.LokaScriptSemantic;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Safe access to window.LokaScriptI18n with type checking
|
|
67
|
+
*/
|
|
68
|
+
export function getHyperFixiI18n(): LokaScriptI18nAPI | null {
|
|
69
|
+
if (typeof window !== 'undefined' && isHyperFixiI18nAvailable(window.LokaScriptI18n)) {
|
|
70
|
+
return window.LokaScriptI18n;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|