@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.
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Type definitions for HyperFixi Core browser API
3
+ */
4
+
5
+ /**
6
+ * HyperFixi core API exposed on window.hyperfixi
7
+ */
8
+ export interface LokaScriptCoreAPI {
9
+ // ==================== API v2 (Recommended) ====================
10
+
11
+ /**
12
+ * Synchronously compile hyperscript code to AST (API v2).
13
+ * @since API v2
14
+ */
15
+ compileSync(code: string, options?: NewCompileOptions): CompileResult;
16
+
17
+ /**
18
+ * Asynchronously compile hyperscript code (handles all 13 languages) (API v2).
19
+ * @since API v2
20
+ */
21
+ compile(code: string, options?: NewCompileOptions): Promise<CompileResult>;
22
+
23
+ /**
24
+ * Compile and execute hyperscript in one step (API v2).
25
+ * @since API v2
26
+ */
27
+ eval(code: string, contextOrElement?: any): Promise<any>;
28
+
29
+ /**
30
+ * Validate hyperscript syntax and return detailed errors (API v2).
31
+ * @since API v2
32
+ */
33
+ validate(code: string, options?: NewCompileOptions): Promise<ValidateResult>;
34
+
35
+ /**
36
+ * Create execution context with optional parent (unified signature, API v2).
37
+ * @since API v2
38
+ */
39
+ createContext(element?: Element | null, parent?: any): any;
40
+
41
+ // ==================== API v1 (Deprecated) ====================
42
+
43
+ /**
44
+ * Evaluate hyperscript string directly
45
+ */
46
+ evalHyperScript(code: string, element?: Element): any;
47
+
48
+ /**
49
+ * Async evaluation of hyperscript
50
+ */
51
+ evalHyperScriptAsync(code: string, element?: Element): Promise<any>;
52
+
53
+ /**
54
+ * Smart evaluation with automatic context detection
55
+ */
56
+ evalHyperScriptSmart(code: string): Promise<any>;
57
+
58
+ /**
59
+ * Compile multilingual hyperscript code
60
+ * @deprecated Use compile() with options.language instead
61
+ */
62
+ compileMultilingual(code: string, language: string, options?: CompileOptions): CompilationResult;
63
+
64
+ /**
65
+ * Execute hyperscript code
66
+ */
67
+ execute(code: string, element?: Element, options?: ExecuteOptions): Promise<any>;
68
+
69
+ /**
70
+ * Run hyperscript code (alias for execute)
71
+ * @deprecated Use eval() instead
72
+ */
73
+ run(code: string, element?: Element, options?: ExecuteOptions): Promise<any>;
74
+
75
+ /**
76
+ * Create child execution context
77
+ * @deprecated Use createContext(element, parent) instead
78
+ */
79
+ createChildContext(parent: any, element?: Element): any;
80
+
81
+ /**
82
+ * Validate hyperscript syntax (returns boolean)
83
+ * @deprecated Use validate() instead (returns detailed result)
84
+ */
85
+ isValidHyperscript(code: string): boolean;
86
+
87
+ /**
88
+ * Create runtime instance
89
+ */
90
+ createRuntime(options?: RuntimeOptions): any;
91
+
92
+ /**
93
+ * Process DOM node
94
+ */
95
+ processNode(node: Node): void;
96
+
97
+ /**
98
+ * Process DOM node (alias)
99
+ */
100
+ process(node: Node): void;
101
+
102
+ /**
103
+ * Tokenize hyperscript code
104
+ */
105
+ tokenize(code: string): any[];
106
+
107
+ /**
108
+ * Low-level parser access
109
+ */
110
+ Parser: any;
111
+
112
+ /**
113
+ * Low-level runtime access
114
+ */
115
+ Runtime: any;
116
+
117
+ /**
118
+ * Attribute processor
119
+ */
120
+ attributeProcessor: any;
121
+
122
+ /**
123
+ * Tailwind extension
124
+ */
125
+ tailwindExtension: any;
126
+
127
+ /**
128
+ * Debug utilities
129
+ */
130
+ debug: {
131
+ enableDebugLogging(): void;
132
+ disableDebugLogging(): void;
133
+ };
134
+
135
+ /**
136
+ * Style batcher utility
137
+ */
138
+ styleBatcher: any;
139
+
140
+ /**
141
+ * Object pool utility
142
+ */
143
+ ObjectPool: any;
144
+
145
+ /**
146
+ * Semantic parsing utilities
147
+ */
148
+ semantic?: {
149
+ parse(code: string, language: string): any;
150
+ translate(code: string, fromLang: string, toLang: string): string | null;
151
+ buildAST(node: any): any;
152
+ };
153
+
154
+ /**
155
+ * Semantic debug utilities
156
+ */
157
+ semanticDebug?: any;
158
+
159
+ /**
160
+ * Version string
161
+ */
162
+ version: string;
163
+ }
164
+
165
+ export interface CompileOptions {
166
+ language?: string;
167
+ strict?: boolean;
168
+ [key: string]: any;
169
+ }
170
+
171
+ export interface CompilationResult {
172
+ success: boolean;
173
+ code?: any;
174
+ error?: Error;
175
+ [key: string]: any;
176
+ }
177
+
178
+ export interface ExecuteOptions {
179
+ context?: any;
180
+ element?: Element;
181
+ [key: string]: any;
182
+ }
183
+
184
+ export interface ContextOptions {
185
+ element?: Element;
186
+ globals?: Record<string, any>;
187
+ [key: string]: any;
188
+ }
189
+
190
+ export interface RuntimeOptions {
191
+ [key: string]: any;
192
+ }
193
+
194
+ export type EvalHyperScriptFunction = (code: string, element?: Element) => any;
195
+
196
+ export type EvalHyperScriptAsyncFunction = (code: string, element?: Element) => Promise<any>;
197
+
198
+ export type EvalHyperScriptSmartFunction = (code: string) => Promise<any>;
199
+
200
+ // ==================== API v2 Types ====================
201
+
202
+ /**
203
+ * Compilation result (API v2)
204
+ */
205
+ export interface CompileResult {
206
+ /** Whether compilation succeeded */
207
+ ok: boolean;
208
+ /** Compiled AST (only present if ok=true) */
209
+ ast?: any;
210
+ /** Compilation errors (only present if ok=false) */
211
+ errors?: CompileError[];
212
+ /** Compilation metadata */
213
+ meta: {
214
+ /** Parser used: semantic or traditional */
215
+ parser: 'semantic' | 'traditional';
216
+ /** Confidence score (0-1) if semantic parser was used */
217
+ confidence?: number;
218
+ /** Language code */
219
+ language: string;
220
+ /** Compilation time in milliseconds */
221
+ timeMs: number;
222
+ /** Whether direct path was taken (no fallback) */
223
+ directPath?: boolean;
224
+ };
225
+ }
226
+
227
+ /**
228
+ * Compilation error (API v2)
229
+ */
230
+ export interface CompileError {
231
+ /** Error message */
232
+ message: string;
233
+ /** Line number where error occurred */
234
+ line: number;
235
+ /** Column number where error occurred */
236
+ column: number;
237
+ /** Optional suggestion for fixing the error */
238
+ suggestion?: string;
239
+ }
240
+
241
+ /**
242
+ * Compilation options (API v2)
243
+ */
244
+ export interface NewCompileOptions {
245
+ /** Language code (default: 'en') */
246
+ language?: string;
247
+ /** Minimum confidence for semantic parsing (0-1, default: 0.5) */
248
+ confidenceThreshold?: number;
249
+ /** Force traditional parser, skip semantic analysis */
250
+ traditional?: boolean;
251
+ }
252
+
253
+ /**
254
+ * Validation result (API v2)
255
+ */
256
+ export interface ValidateResult {
257
+ /** Whether code is valid */
258
+ valid: boolean;
259
+ /** Validation errors (only present if valid=false) */
260
+ errors?: CompileError[];
261
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Global type augmentation for HyperFixi and LokaScript browser APIs
3
+ *
4
+ * This file augments the Window and globalThis interfaces to include
5
+ * HyperFixi and LokaScript global variables, providing IDE autocomplete and type safety.
6
+ */
7
+
8
+ import type { LokaScriptCoreAPI } from './core-api';
9
+ import type { LokaScriptSemanticAPI } from './semantic-api';
10
+ import type { LokaScriptI18nAPI } from './i18n-api';
11
+
12
+ declare global {
13
+ /**
14
+ * Window interface augmentation
15
+ */
16
+ interface Window {
17
+ /**
18
+ * HyperFixi - Modern hyperscript engine with fixi/htmx integration
19
+ *
20
+ * Loaded from: hyperfixi.js or hyperfixi-hx.js
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * window.hyperfixi.execute('toggle .active', document.body)
25
+ * window.hyperfixi.compile('on click add .highlight')
26
+ * ```
27
+ */
28
+ hyperfixi: LokaScriptCoreAPI;
29
+
30
+ /**
31
+ * @deprecated Use `hyperfixi` instead. Will be removed in v3.0.0.
32
+ *
33
+ * Loaded from: hyperfixi.js (backward-compat alias)
34
+ */
35
+ lokascript: LokaScriptCoreAPI;
36
+
37
+ /**
38
+ * Compatibility alias for official _hyperscript API compatibility
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * window._hyperscript.compile('on click toggle .active')
43
+ * ```
44
+ */
45
+ _hyperscript: LokaScriptCoreAPI;
46
+
47
+ /**
48
+ * LokaScript Semantic - Multilingual semantic parsing (24 languages)
49
+ *
50
+ * Loaded from: lokascript-semantic.browser.global.js
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const result = window.LokaScriptSemantic.parse('トグル .active', 'ja')
55
+ * const korean = window.LokaScriptSemantic.translate('toggle .active', 'en', 'ko')
56
+ * ```
57
+ */
58
+ LokaScriptSemantic: LokaScriptSemanticAPI;
59
+
60
+ /**
61
+ * LokaScript I18n - Grammar transformation for natural language word order
62
+ *
63
+ * Loaded from: lokascript-i18n.min.js
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const japanese = window.LokaScriptI18n.translate('on click toggle .active', 'en', 'ja')
68
+ * // Result: 'クリック で .active を 切り替え' (SOV word order)
69
+ * ```
70
+ */
71
+ LokaScriptI18n: LokaScriptI18nAPI;
72
+ }
73
+
74
+ /**
75
+ * globalThis interface augmentation (same as Window for browser contexts)
76
+ */
77
+ var hyperfixi: LokaScriptCoreAPI;
78
+ var lokascript: LokaScriptCoreAPI;
79
+ var _hyperscript: LokaScriptCoreAPI;
80
+ var LokaScriptSemantic: LokaScriptSemanticAPI;
81
+ var LokaScriptI18n: LokaScriptI18nAPI;
82
+ }
83
+
84
+ // This export ensures the file is treated as a module
85
+ export {};
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Type definitions for @lokascript/i18n browser global (window.HyperFixiI18n)
3
+ */
4
+
5
+ export interface LokaScriptI18nAPI {
6
+ /**
7
+ * Translate hyperscript with grammar transformation
8
+ */
9
+ translate(source: string, fromLang: string, toLang: string): string;
10
+
11
+ /**
12
+ * Create a grammar transformer instance
13
+ */
14
+ createTransformer(options?: TransformerOptions): GrammarTransformer;
15
+
16
+ /**
17
+ * Get supported locales
18
+ */
19
+ supportedLocales: readonly string[];
20
+
21
+ /**
22
+ * Get language profile for a locale
23
+ */
24
+ getProfile(locale: string): LanguageProfile | undefined;
25
+ }
26
+
27
+ export interface GrammarTransformer {
28
+ transform(source: string, fromLang: string, toLang: string): string;
29
+ parseStatement(source: string, language: string): ParsedStatement;
30
+ toLocale(statement: ParsedStatement, locale: string): string;
31
+ toEnglish(source: string, locale: string): string;
32
+ }
33
+
34
+ export interface TransformerOptions {
35
+ strict?: boolean;
36
+ preserveWhitespace?: boolean;
37
+ }
38
+
39
+ export interface LanguageProfile {
40
+ locale: string;
41
+ wordOrder: 'SVO' | 'SOV' | 'VSO';
42
+ adpositions: 'prepositions' | 'postpositions' | 'both';
43
+ morphology: 'isolating' | 'agglutinative' | 'fusional';
44
+ markers?: Record<string, string>;
45
+ }
46
+
47
+ export interface ParsedStatement {
48
+ action: string;
49
+ roles: Map<string, ParsedElement>;
50
+ raw: string;
51
+ }
52
+
53
+ export interface ParsedElement {
54
+ role: string;
55
+ value: string;
56
+ type: 'literal' | 'selector' | 'reference';
57
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Type definitions for HyperFixi i18n/Grammar transformation browser API
3
+ */
4
+
5
+ /**
6
+ * HyperFixi i18n/Grammar transformation API on window.HyperFixiI18n
7
+ */
8
+ export interface LokaScriptI18nAPI {
9
+ /**
10
+ * Transform hyperscript statement from one language word order to another
11
+ *
12
+ * @param statement Parsed hyperscript statement
13
+ * @param fromLocale Source language locale (e.g., 'en')
14
+ * @param toLocale Target language locale (e.g., 'ja')
15
+ * @returns Transformed statement or null
16
+ */
17
+ translate(
18
+ statement: HyperscriptStatement,
19
+ fromLocale: string,
20
+ toLocale: string
21
+ ): HyperscriptStatement | null;
22
+
23
+ /**
24
+ * Transform code from English to target locale
25
+ */
26
+ toLocale(code: string, toLocale: string): string | null;
27
+
28
+ /**
29
+ * Transform code from any locale to English
30
+ */
31
+ toEnglish(code: string, fromLocale: string): string | null;
32
+
33
+ /**
34
+ * Parse hyperscript statement
35
+ */
36
+ parseStatement(code: string): HyperscriptStatement | null;
37
+
38
+ /**
39
+ * Get supported locales for grammar transformation
40
+ */
41
+ getSupportedLocales(): string[];
42
+
43
+ /**
44
+ * Check if transformation is supported between two locales
45
+ */
46
+ supportsTransform(fromLocale: string, toLocale: string): boolean;
47
+
48
+ /**
49
+ * Get language profile information
50
+ */
51
+ getProfile(locale: string): LanguageProfile | null;
52
+
53
+ /**
54
+ * Reorder semantic roles based on language word order
55
+ */
56
+ reorderRoles(
57
+ roles: Record<string, any>,
58
+ fromProfile: LanguageProfile,
59
+ toProfile: LanguageProfile
60
+ ): Record<string, any>;
61
+
62
+ /**
63
+ * Insert grammatical markers
64
+ */
65
+ insertMarkers(tokens: string[], role: string, profile: LanguageProfile): string[];
66
+
67
+ /**
68
+ * Join tokens with language-specific rules
69
+ */
70
+ joinTokens(tokens: string[], profile: LanguageProfile): string;
71
+
72
+ /**
73
+ * Transform statement between locales
74
+ */
75
+ transformStatement(
76
+ statement: HyperscriptStatement,
77
+ fromProfile: LanguageProfile,
78
+ toProfile: LanguageProfile
79
+ ): HyperscriptStatement;
80
+
81
+ /**
82
+ * Check if direct word mapping exists
83
+ */
84
+ hasDirectMapping(word: string, fromLocale: string, toLocale: string): boolean;
85
+
86
+ /**
87
+ * Get direct word mapping
88
+ */
89
+ getDirectMapping(word: string, fromLocale: string, toLocale: string): string | null;
90
+
91
+ /**
92
+ * Translate word directly using mapping
93
+ */
94
+ translateWordDirect(word: string, fromLocale: string, toLocale: string): string | null;
95
+
96
+ /**
97
+ * Get supported language pairs for direct translation
98
+ */
99
+ getSupportedDirectPairs(): Array<[string, string]>;
100
+
101
+ /**
102
+ * Detect browser locale
103
+ */
104
+ detectBrowserLocale(): string;
105
+
106
+ /**
107
+ * Grammar transformer class
108
+ */
109
+ GrammarTransformer: any;
110
+
111
+ /**
112
+ * Locale manager class
113
+ */
114
+ LocaleManager: any;
115
+
116
+ /**
117
+ * Universal patterns for all languages
118
+ */
119
+ UNIVERSAL_PATTERNS: any;
120
+
121
+ /**
122
+ * Language family defaults
123
+ */
124
+ LANGUAGE_FAMILY_DEFAULTS: any;
125
+
126
+ /**
127
+ * All language profiles
128
+ */
129
+ profiles: Record<string, LanguageProfile>;
130
+
131
+ /**
132
+ * Language-specific profiles
133
+ */
134
+ englishProfile: LanguageProfile;
135
+ japaneseProfile: LanguageProfile;
136
+ koreanProfile: LanguageProfile;
137
+ arabicProfile: LanguageProfile;
138
+ spanishProfile: LanguageProfile;
139
+ turkishProfile: LanguageProfile;
140
+ chineseProfile: LanguageProfile;
141
+ portugueseProfile: LanguageProfile;
142
+ frenchProfile: LanguageProfile;
143
+ germanProfile: LanguageProfile;
144
+ indonesianProfile: LanguageProfile;
145
+ quechuaProfile: LanguageProfile;
146
+ swahiliProfile: LanguageProfile;
147
+
148
+ /**
149
+ * Language-specific keyword dictionaries
150
+ */
151
+ esDictionary: any;
152
+ jaDictionary: any;
153
+ frDictionary: any;
154
+ deDictionary: any;
155
+ arDictionary: any;
156
+ koDictionary: any;
157
+ zhDictionary: any;
158
+ trDictionary: any;
159
+ idDictionary: any;
160
+ quDictionary: any;
161
+ swDictionary: any;
162
+ ptDictionary: any;
163
+
164
+ /**
165
+ * Language-specific keywords
166
+ */
167
+ esKeywords: any;
168
+ jaKeywords: any;
169
+ frKeywords: any;
170
+ deKeywords: any;
171
+ arKeywords: any;
172
+ koKeywords: any;
173
+ zhKeywords: any;
174
+ trKeywords: any;
175
+ idKeywords: any;
176
+ quKeywords: any;
177
+ swKeywords: any;
178
+ ptKeywords: any;
179
+
180
+ /**
181
+ * Direct mapping configuration
182
+ */
183
+ directMappings: any;
184
+
185
+ /**
186
+ * Grammar transformation examples
187
+ */
188
+ grammarExamples: Array<{
189
+ english: string;
190
+ [locale: string]: string;
191
+ }>;
192
+ }
193
+
194
+ export interface HyperscriptStatement {
195
+ command: string;
196
+ roles: Record<string, any>;
197
+ modifiers?: string[];
198
+ [key: string]: any;
199
+ }
200
+
201
+ export interface LanguageProfile {
202
+ locale: string;
203
+ name: string;
204
+ wordOrder: 'SVO' | 'SOV' | 'VSO' | 'VOS';
205
+ isRTL: boolean;
206
+ family?: string;
207
+ joinTokens?: Record<string, string>;
208
+ [key: string]: any;
209
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @hyperfixi/types-browser
3
+ * TypeScript type definitions for HyperFixi browser globals
4
+ *
5
+ * This package provides complete type definitions for using HyperFixi
6
+ * packages in the browser via global variables.
7
+ *
8
+ * Install with: npm install --save-dev @hyperfixi/types-browser
9
+ *
10
+ * Then add to your tsconfig.json:
11
+ * ```json
12
+ * {
13
+ * "compilerOptions": {
14
+ * "types": ["@hyperfixi/types-browser"]
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+
20
+ /// <reference path="./core-api.d.ts" />
21
+ /// <reference path="./semantic-api.d.ts" />
22
+ /// <reference path="./i18n-api.d.ts" />
23
+ /// <reference path="./globals.d.ts" />
24
+
25
+ // Re-export all types for convenience
26
+ export * from './core-api';
27
+ export * from './semantic-api';
28
+ export * from './i18n-api';
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @hyperfixi/types-browser
3
+ * TypeScript type definitions for HyperFixi browser globals
4
+ *
5
+ * This package provides complete type definitions for using HyperFixi
6
+ * packages in the browser via global variables.
7
+ *
8
+ * ## Installation
9
+ *
10
+ * ```bash
11
+ * npm install --save-dev @hyperfixi/types-browser
12
+ * ```
13
+ *
14
+ * ## Usage
15
+ *
16
+ * Add to your tsconfig.json:
17
+ * ```json
18
+ * {
19
+ * "compilerOptions": {
20
+ * "types": ["@hyperfixi/types-browser"]
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * Or use triple-slash directive in your TypeScript files:
26
+ * ```typescript
27
+ * /// <reference types="@hyperfixi/types-browser" />
28
+ * ```
29
+ *
30
+ * ## Examples
31
+ *
32
+ * ### Using window.hyperfixi
33
+ * ```typescript
34
+ * // window.hyperfixi is now fully typed
35
+ * const result = await window.hyperfixi.execute('toggle .active')
36
+ * window.evalHyperScript('toggle .active')
37
+ * ```
38
+ *
39
+ * ### Using window.HyperFixiSemantic
40
+ * ```typescript
41
+ * if (window.HyperFixiSemantic) {
42
+ * const node = window.HyperFixiSemantic.parse('toggle .active', 'en')
43
+ * const japanese = window.HyperFixiSemantic.translate('toggle .active', 'en', 'ja')
44
+ * }
45
+ * ```
46
+ *
47
+ * ### Using Type Guards
48
+ * ```typescript
49
+ * import { isHyperFixiCoreAvailable, getHyperFixiCore } from '@hyperfixi/types-browser'
50
+ *
51
+ * const hyperfixi = getHyperFixiCore()
52
+ * if (hyperfixi) {
53
+ * hyperfixi.execute('toggle .active')
54
+ * }
55
+ * ```
56
+ */
57
+
58
+ export * from './core-api';
59
+ export * from './semantic-api';
60
+ export * from './i18n-api';
61
+ export * from './type-guards';
62
+ export * from './globals';