@hyperfixi/types-browser 3.3.0 → 4.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/src/index.ts CHANGED
@@ -31,26 +31,26 @@
31
31
  *
32
32
  * ### Using window.hyperfixi
33
33
  * ```typescript
34
- * // window.hyperfixi is now fully typed
35
- * const result = await window.hyperfixi.execute('toggle .active')
36
- * window.evalHyperScript('toggle .active')
34
+ * // window.hyperfixi (and window._hyperscript, the same object) is fully typed
35
+ * window.hyperfixi.evaluate('toggle .active on me', { me: button })
36
+ * window.hyperfixi.parse('on click toggle .active').errors // []
37
37
  * ```
38
38
  *
39
- * ### Using window.HyperFixiSemantic
39
+ * ### Using window.LokaScriptSemantic
40
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')
41
+ * if (window.LokaScriptSemantic) {
42
+ * const node = window.LokaScriptSemantic.parse('toggle .active', 'en')
43
+ * const japanese = window.LokaScriptSemantic.translate('toggle .active', 'en', 'ja')
44
44
  * }
45
45
  * ```
46
46
  *
47
47
  * ### Using Type Guards
48
48
  * ```typescript
49
- * import { isHyperFixiCoreAvailable, getHyperFixiCore } from '@hyperfixi/types-browser'
49
+ * import { getHyperFixiCore } from '@hyperfixi/types-browser'
50
50
  *
51
51
  * const hyperfixi = getHyperFixiCore()
52
52
  * if (hyperfixi) {
53
- * hyperfixi.execute('toggle .active')
53
+ * hyperfixi.evaluate('toggle .active on me', { me: button })
54
54
  * }
55
55
  * ```
56
56
  */
@@ -2,19 +2,19 @@
2
2
  * Type guards for browser globals
3
3
  */
4
4
 
5
- import type { LokaScriptCoreAPI } from './core-api';
5
+ import type { HyperfixiAPI } from './core-api';
6
6
  import type { LokaScriptSemanticAPI } from './semantic-api';
7
7
  import type { LokaScriptI18nAPI } from './i18n-api';
8
8
 
9
9
  /**
10
- * Check if window.hyperfixi is available and properly typed
10
+ * Check that a value is the hyperscript host (`window.hyperfixi` / `window._hyperscript`):
11
+ * callable, with `evaluate` and `processNode`.
11
12
  */
12
- export function isHyperFixiCoreAvailable(obj?: any): obj is LokaScriptCoreAPI {
13
+ export function isHyperFixiCoreAvailable(obj?: any): obj is HyperfixiAPI {
13
14
  return (
14
- typeof obj === 'object' &&
15
- obj !== null &&
16
- typeof obj.execute === 'function' &&
17
- typeof obj.compile === 'function'
15
+ typeof obj === 'function' &&
16
+ typeof obj.evaluate === 'function' &&
17
+ typeof obj.processNode === 'function'
18
18
  );
19
19
  }
20
20
 
@@ -48,7 +48,7 @@ export function isHyperFixiI18nAvailable(obj?: any): obj is LokaScriptI18nAPI {
48
48
  /**
49
49
  * Safe access to window.hyperfixi with type checking
50
50
  */
51
- export function getHyperFixiCore(): LokaScriptCoreAPI | null {
51
+ export function getHyperFixiCore(): HyperfixiAPI | null {
52
52
  if (typeof window !== 'undefined' && isHyperFixiCoreAvailable(window.hyperfixi)) {
53
53
  return window.hyperfixi;
54
54
  }
package/src/core-api.d.ts DELETED
@@ -1,280 +0,0 @@
1
- /**
2
- * Type definitions for @hyperfixi/core browser global (window.hyperfixi)
3
- */
4
-
5
- export interface LokaScriptCoreAPI {
6
- // ==================== API v2 (Recommended) ====================
7
-
8
- /**
9
- * Synchronously compile hyperscript code to AST.
10
- * Use this for English-only code that needs synchronous compilation.
11
- *
12
- * @example
13
- * ```typescript
14
- * const result = hyperfixi.compileSync('toggle .active');
15
- * if (result.ok) {
16
- * console.log('Parser used:', result.meta.parser);
17
- * await hyperfixi.execute(result.ast, element);
18
- * }
19
- * ```
20
- *
21
- * @since API v2
22
- */
23
- compileSync(source: string, options?: NewCompileOptions): CompileResult;
24
-
25
- /**
26
- * Asynchronously compile hyperscript code (handles all 13 languages).
27
- * Use this for multilingual support or when async compilation is acceptable.
28
- *
29
- * @example
30
- * ```typescript
31
- * // English
32
- * const result = await hyperfixi.compile('toggle .active');
33
- *
34
- * // Japanese
35
- * const result = await hyperfixi.compile('トグル .active', { language: 'ja' });
36
- * ```
37
- *
38
- * @since API v2
39
- */
40
- compile(source: string, options?: NewCompileOptions): Promise<CompileResult>;
41
-
42
- /**
43
- * Compile and execute hyperscript in one step.
44
- *
45
- * @example
46
- * ```typescript
47
- * // With context
48
- * const ctx = hyperfixi.createContext(element);
49
- * await hyperfixi.eval('toggle .active', ctx);
50
- *
51
- * // With element directly
52
- * await hyperfixi.eval('toggle .active', element);
53
- * ```
54
- *
55
- * @since API v2
56
- */
57
- eval(source: string, contextOrElement?: ExecutionContext | Element): Promise<any>;
58
-
59
- /**
60
- * Validate hyperscript syntax and return detailed errors.
61
- *
62
- * @example
63
- * ```typescript
64
- * const result = await hyperfixi.validate('toggle .active');
65
- * if (result.valid) {
66
- * console.log('Valid syntax');
67
- * } else {
68
- * result.errors?.forEach(err => {
69
- * console.error(`Line ${err.line}: ${err.message}`);
70
- * });
71
- * }
72
- * ```
73
- *
74
- * @since API v2
75
- */
76
- validate(source: string, options?: NewCompileOptions): Promise<ValidateResult>;
77
-
78
- /**
79
- * Create execution context (unified signature with optional parent).
80
- *
81
- * @example
82
- * ```typescript
83
- * // Basic context
84
- * const ctx = hyperfixi.createContext(element);
85
- *
86
- * // Child context
87
- * const child = hyperfixi.createContext(element, parentContext);
88
- * ```
89
- *
90
- * @since API v2
91
- */
92
- createContext(element?: Element | null, parent?: ExecutionContext): ExecutionContext;
93
-
94
- // ==================== API v1 (Deprecated) ====================
95
-
96
- /**
97
- * Execute hyperscript on an element
98
- */
99
- execute(source: string, element?: Element, context?: ExecutionOptions): Promise<void>;
100
-
101
- /**
102
- * @deprecated Use `eval()` instead
103
- * Run (compile and execute) hyperscript
104
- */
105
- run(source: string, element?: Element): Promise<void>;
106
-
107
- /**
108
- * @deprecated Use `eval()` instead
109
- * Alias for run()
110
- */
111
- evaluate(source: string, element?: Element): Promise<void>;
112
-
113
- /**
114
- * Parse hyperscript to AST
115
- */
116
- parse(source: string): ParseResult;
117
-
118
- /**
119
- * Process a DOM node for hyperscript attributes
120
- */
121
- processNode(node: Node): void;
122
-
123
- /**
124
- * Process entire document for hyperscript
125
- */
126
- process(root?: Document | Element): void;
127
-
128
- /**
129
- * @deprecated Use `createContext(element, parent)` instead
130
- * Create child execution context
131
- */
132
- createChildContext(parent: ExecutionContext, element?: Element): ExecutionContext;
133
-
134
- /**
135
- * @deprecated Use `validate()` instead
136
- * Validate hyperscript syntax
137
- */
138
- isValidHyperscript(source: string): boolean;
139
-
140
- /**
141
- * Get HyperFixi version
142
- */
143
- version: string;
144
-
145
- /**
146
- * Create runtime instance
147
- */
148
- createRuntime(options?: RuntimeOptions): Runtime;
149
- }
150
-
151
- export interface CompileOptions {
152
- strict?: boolean;
153
- includeSource?: boolean;
154
- }
155
-
156
- export interface CompilationResult {
157
- ast: ASTNode;
158
- errors: ParseError[];
159
- success: boolean;
160
- }
161
-
162
- export interface ParseResult {
163
- ast: ASTNode;
164
- tokens: Token[];
165
- errors: ParseError[];
166
- }
167
-
168
- export interface ParseError {
169
- message: string;
170
- position: number;
171
- line: number;
172
- column: number;
173
- }
174
-
175
- export interface Token {
176
- type: string;
177
- value: string;
178
- position: number;
179
- line: number;
180
- column: number;
181
- }
182
-
183
- export interface ASTNode {
184
- type: string;
185
- [key: string]: unknown;
186
- }
187
-
188
- export interface ExecutionOptions {
189
- globals?: Record<string, unknown>;
190
- locals?: Record<string, unknown>;
191
- }
192
-
193
- export interface ExecutionContext {
194
- me: Element | null;
195
- you?: Element | null;
196
- it?: unknown;
197
- result?: unknown;
198
- locals: Map<string, unknown>;
199
- globals: Map<string, unknown>;
200
- target?: Element | EventTarget | null;
201
- detail?: unknown;
202
- }
203
-
204
- export interface ContextOptions {
205
- element?: Element;
206
- globals?: Record<string, unknown>;
207
- }
208
-
209
- export interface RuntimeOptions {
210
- strict?: boolean;
211
- timeout?: number;
212
- }
213
-
214
- export interface Runtime {
215
- execute(ast: ASTNode, context: ExecutionContext): Promise<void>;
216
- processCommand(command: ASTNode, context: ExecutionContext): Promise<void>;
217
- }
218
-
219
- // ==================== API v2 Types ====================
220
-
221
- /**
222
- * Result of compilation (API v2)
223
- */
224
- export interface CompileResult {
225
- /** Whether compilation succeeded */
226
- ok: boolean;
227
- /** Compiled AST (only present if ok=true) */
228
- ast?: ASTNode;
229
- /** Compilation errors (only present if ok=false) */
230
- errors?: CompileError[];
231
- /** Compilation metadata */
232
- meta: {
233
- /** Parser used: semantic or traditional */
234
- parser: 'semantic' | 'traditional';
235
- /** Confidence score (0-1) if semantic parser was used */
236
- confidence?: number;
237
- /** Language code */
238
- language: string;
239
- /** Compilation time in milliseconds */
240
- timeMs: number;
241
- /** Whether direct path was taken (no fallback) */
242
- directPath?: boolean;
243
- };
244
- }
245
-
246
- /**
247
- * Compilation error (API v2)
248
- */
249
- export interface CompileError {
250
- /** Error message */
251
- message: string;
252
- /** Line number where error occurred */
253
- line: number;
254
- /** Column number where error occurred */
255
- column: number;
256
- /** Optional suggestion for fixing the error */
257
- suggestion?: string;
258
- }
259
-
260
- /**
261
- * Compilation options (API v2)
262
- */
263
- export interface NewCompileOptions {
264
- /** Language code (default: 'en') */
265
- language?: string;
266
- /** Minimum confidence for semantic parsing (0-1, default: 0.5) */
267
- confidenceThreshold?: number;
268
- /** Force traditional parser, skip semantic analysis */
269
- traditional?: boolean;
270
- }
271
-
272
- /**
273
- * Validation result (API v2)
274
- */
275
- export interface ValidateResult {
276
- /** Whether code is valid */
277
- valid: boolean;
278
- /** Validation errors (only present if valid=false) */
279
- errors?: CompileError[];
280
- }
package/src/i18n-api.d.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * Type definitions for @lokascript/i18n browser global (window.HyperFixiI18n)
3
- */
4
-
5
- /**
6
- * NOTE: this file and `i18n-api.ts` both declare `LokaScriptI18nAPI`, with
7
- * different shapes — `index.d.ts` references this one, `index.ts` exports the
8
- * other. That divergence predates this change and is untouched here; only the
9
- * retired transformer surface is removed from both.
10
- */
11
- export interface LokaScriptI18nAPI {
12
- // RETIRED 2026-08-28 with `@lokascript/i18n`'s grammar transformer:
13
- // `translate` and `createTransformer` (plus the `GrammarTransformer` and
14
- // `TransformerOptions` interfaces they referenced). Translation is
15
- // `@lokascript/semantic`'s job; in the browser that is `hyperfixi.translate`
16
- // from the multilingual bundle.
17
-
18
- /**
19
- * Get supported locales
20
- */
21
- supportedLocales: readonly string[];
22
-
23
- /**
24
- * Get language profile for a locale
25
- */
26
- getProfile(locale: string): LanguageProfile | undefined;
27
- }
28
-
29
- export interface LanguageProfile {
30
- locale: string;
31
- wordOrder: 'SVO' | 'SOV' | 'VSO';
32
- adpositions: 'prepositions' | 'postpositions' | 'both';
33
- morphology: 'isolating' | 'agglutinative' | 'fusional';
34
- markers?: Record<string, string>;
35
- }
36
-
37
- export interface ParsedStatement {
38
- action: string;
39
- roles: Map<string, ParsedElement>;
40
- raw: string;
41
- }
42
-
43
- export interface ParsedElement {
44
- role: string;
45
- value: string;
46
- type: 'literal' | 'selector' | 'reference';
47
- }
package/src/index.d.ts DELETED
@@ -1,28 +0,0 @@
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';
@@ -1,74 +0,0 @@
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
- }