@hyperfixi/types-browser 3.3.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +199 -1
- package/README.md +36 -29
- package/dist/core-api.d.ts +110 -199
- package/dist/core-api.d.ts.map +1 -1
- package/dist/globals.d.ts +71 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/type-guards.d.ts +5 -4
- package/dist/type-guards.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/core-api.ts +123 -229
- package/src/{globals.d.ts → globals.ts} +15 -22
- package/src/i18n-api.ts +1 -1
- package/src/index.ts +9 -9
- package/src/type-guards.ts +8 -8
- package/src/core-api.d.ts +0 -280
- package/src/i18n-api.d.ts +0 -47
- package/src/index.d.ts +0 -28
- package/src/semantic-api.d.ts +0 -74
package/dist/core-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-api.d.ts","sourceRoot":"","sources":["../src/core-api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"core-api.d.ts","sourceRoot":"","sources":["../src/core-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,kEAAkE;IAClE,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,uBAAuB;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,yCAA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YAChC,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;SAClC,CAAC;KACH,CAAC;IAEF,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wFAAwF;AACxF,MAAM,MAAM,iBAAiB,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
import type { HyperfixiAPI } from './core-api';
|
|
8
|
+
import type { LokaScriptSemanticAPI } from './semantic-api';
|
|
9
|
+
import type { LokaScriptI18nAPI } from './i18n-api';
|
|
10
|
+
declare global {
|
|
11
|
+
/**
|
|
12
|
+
* Window interface augmentation
|
|
13
|
+
*/
|
|
14
|
+
interface Window {
|
|
15
|
+
/**
|
|
16
|
+
* The hyperscript engine (`@hyperfixi/engine`'s public object).
|
|
17
|
+
*
|
|
18
|
+
* Loaded from: hyperfixi-hs.js (or hyperfixi.js, the same file under `@hyperfixi/core`'s name)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* window.hyperfixi.evaluate('add .highlight to me', { me: document.body })
|
|
23
|
+
* window.hyperfixi.parse('on click toggle .active').errors // []
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
hyperfixi: HyperfixiAPI;
|
|
27
|
+
/**
|
|
28
|
+
* The same object as `window.hyperfixi`, under upstream `_hyperscript`'s name — set by
|
|
29
|
+
* hyperfixi-hs.js, and by upstream `_hyperscript` itself.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* window._hyperscript.processNode(document.body)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
_hyperscript: HyperfixiAPI;
|
|
37
|
+
/**
|
|
38
|
+
* LokaScript Semantic - Multilingual semantic parsing (24 languages)
|
|
39
|
+
*
|
|
40
|
+
* Loaded from: lokascript-semantic.browser.global.js
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const result = window.LokaScriptSemantic.parse('トグル .active', 'ja')
|
|
45
|
+
* const korean = window.LokaScriptSemantic.translate('toggle .active', 'en', 'ko')
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
LokaScriptSemantic: LokaScriptSemanticAPI;
|
|
49
|
+
/**
|
|
50
|
+
* LokaScript I18n - per-language vocabulary and word-order profiles (24 languages).
|
|
51
|
+
* Translation is `window.LokaScriptSemantic.translate`.
|
|
52
|
+
*
|
|
53
|
+
* Loaded from: lokascript-i18n.min.js
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* window.LokaScriptI18n.getProfile('ja')?.wordOrder // 'SOV'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
LokaScriptI18n: LokaScriptI18nAPI;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* globalThis interface augmentation (same as Window for browser contexts)
|
|
64
|
+
*/
|
|
65
|
+
var hyperfixi: HyperfixiAPI;
|
|
66
|
+
var _hyperscript: HyperfixiAPI;
|
|
67
|
+
var LokaScriptSemantic: LokaScriptSemanticAPI;
|
|
68
|
+
var LokaScriptI18n: LokaScriptI18nAPI;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=globals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,CAAC,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,MAAM;QACd;;;;;;;;;;WAUG;QACH,SAAS,EAAE,YAAY,CAAC;QAExB;;;;;;;;WAQG;QACH,YAAY,EAAE,YAAY,CAAC;QAE3B;;;;;;;;;;WAUG;QACH,kBAAkB,EAAE,qBAAqB,CAAC;QAE1C;;;;;;;;;;WAUG;QACH,cAAc,EAAE,iBAAiB,CAAC;KACnC;IAED;;OAEG;IACH,IAAI,SAAS,EAAE,YAAY,CAAC;IAC5B,IAAI,YAAY,EAAE,YAAY,CAAC;IAC/B,IAAI,kBAAkB,EAAE,qBAAqB,CAAC;IAC9C,IAAI,cAAc,EAAE,iBAAiB,CAAC;CACvC;AAGD,OAAO,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,26 +31,26 @@
|
|
|
31
31
|
*
|
|
32
32
|
* ### Using window.hyperfixi
|
|
33
33
|
* ```typescript
|
|
34
|
-
* // window.hyperfixi is
|
|
35
|
-
*
|
|
36
|
-
* window.
|
|
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.
|
|
39
|
+
* ### Using window.LokaScriptSemantic
|
|
40
40
|
* ```typescript
|
|
41
|
-
* if (window.
|
|
42
|
-
* const node = window.
|
|
43
|
-
* const japanese = window.
|
|
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 {
|
|
49
|
+
* import { getHyperFixiCore } from '@hyperfixi/types-browser'
|
|
50
50
|
*
|
|
51
51
|
* const hyperfixi = getHyperFixiCore()
|
|
52
52
|
* if (hyperfixi) {
|
|
53
|
-
* hyperfixi.
|
|
53
|
+
* hyperfixi.evaluate('toggle .active on me', { me: button })
|
|
54
54
|
* }
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
package/dist/type-guards.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type guards for browser globals
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { HyperfixiAPI } from './core-api';
|
|
5
5
|
import type { LokaScriptSemanticAPI } from './semantic-api';
|
|
6
6
|
import type { LokaScriptI18nAPI } from './i18n-api';
|
|
7
7
|
/**
|
|
8
|
-
* Check
|
|
8
|
+
* Check that a value is the hyperscript host (`window.hyperfixi` / `window._hyperscript`):
|
|
9
|
+
* callable, with `evaluate` and `processNode`.
|
|
9
10
|
*/
|
|
10
|
-
export declare function isHyperFixiCoreAvailable(obj?: any): obj is
|
|
11
|
+
export declare function isHyperFixiCoreAvailable(obj?: any): obj is HyperfixiAPI;
|
|
11
12
|
/**
|
|
12
13
|
* Check if window.HyperFixiSemantic is available
|
|
13
14
|
*/
|
|
@@ -19,7 +20,7 @@ export declare function isHyperFixiI18nAvailable(obj?: any): obj is LokaScriptI1
|
|
|
19
20
|
/**
|
|
20
21
|
* Safe access to window.hyperfixi with type checking
|
|
21
22
|
*/
|
|
22
|
-
export declare function getHyperFixiCore():
|
|
23
|
+
export declare function getHyperFixiCore(): HyperfixiAPI | null;
|
|
23
24
|
/**
|
|
24
25
|
* Safe access to window.LokaScriptSemantic with type checking
|
|
25
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../src/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../src/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAMvE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,qBAAqB,CAOpF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,iBAAiB,CAU5E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAKtD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,qBAAqB,GAAG,IAAI,CAKnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,iBAAiB,GAAG,IAAI,CAK3D"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperfixi/types-browser",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "TypeScript
|
|
3
|
+
"version": "4.0.1",
|
|
4
|
+
"description": "TypeScript definitions for the hyperfixi browser globals: window.hyperfixi / window._hyperscript (the engine), LokaScriptSemantic, LokaScriptI18n",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"clean": "rm -rf dist",
|
|
21
|
-
"typecheck": "tsc --noEmit"
|
|
21
|
+
"typecheck": "tsc --noEmit -p tsconfig.check.json"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"hyperfixi",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"author": "LokaScript Contributors",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@hyperfixi/engine": "^4.0.1",
|
|
33
34
|
"typescript": "^5.8.3"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
package/src/core-api.ts
CHANGED
|
@@ -1,256 +1,150 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type definitions for
|
|
2
|
+
* Type definitions for the hyperscript host on `window.hyperfixi` and `window._hyperscript`.
|
|
3
|
+
*
|
|
4
|
+
* Both globals are one object: `@hyperfixi/engine`'s public API, which the engine's
|
|
5
|
+
* `hyperfixi-hs.js` installs, and which `@hyperfixi/core` ships as `hyperfixi.js` (the same
|
|
6
|
+
* file, since Phase C3 of the engine cutover). It is shaped like upstream `_hyperscript`'s
|
|
7
|
+
* public object, so upstream plugins can use it, plus one hook upstream lacks
|
|
8
|
+
* (`addSourceTransform`). `test/engine-api.check.ts` checks the engine's own `api` against
|
|
9
|
+
* this interface, so the two cannot drift apart.
|
|
10
|
+
*
|
|
11
|
+
* (Until then `hyperfixi.js` was core's own bundle, and `window.hyperfixi` had core's API:
|
|
12
|
+
* `compile`, `compileSync`, `execute`, `createContext`, `evalHyperScript`, … — none of which
|
|
13
|
+
* the engine has. Those types are gone; see `HyperfixiAPI` for what replaced each.)
|
|
3
14
|
*/
|
|
4
15
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
16
|
+
/** The context `evaluate` runs its source in. Every field is optional. */
|
|
17
|
+
export interface HyperscriptContext {
|
|
18
|
+
/** What `me` / `my` / `I` refer to (default: `document.body`). */
|
|
19
|
+
me?: unknown;
|
|
20
|
+
you?: unknown;
|
|
21
|
+
/** `it` / `result`. */
|
|
22
|
+
result?: unknown;
|
|
23
|
+
event?: unknown;
|
|
24
|
+
target?: unknown;
|
|
25
|
+
detail?: unknown;
|
|
26
|
+
sender?: unknown;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
/** Local variables, by name. */
|
|
29
|
+
locals?: Record<string, unknown>;
|
|
30
|
+
}
|
|
116
31
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
32
|
+
/** The token a parse error points at. */
|
|
33
|
+
export interface HyperscriptToken {
|
|
34
|
+
type: string;
|
|
35
|
+
value: string;
|
|
36
|
+
/** Offsets into the source. */
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
/** 1-based line, 0-based column. */
|
|
40
|
+
line: number;
|
|
41
|
+
column: number;
|
|
42
|
+
}
|
|
121
43
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
44
|
+
/** A grammar error, as `parse` reports it and as the `hyperscript:parse-error` event carries it. */
|
|
45
|
+
export interface HyperscriptParseError {
|
|
46
|
+
message: string;
|
|
47
|
+
token: HyperscriptToken;
|
|
48
|
+
source: string;
|
|
49
|
+
/** The words the parser would have accepted, when it knows. */
|
|
50
|
+
expected?: string[];
|
|
51
|
+
/** What the author wrote, when a source transform rewrote the script before it was parsed. */
|
|
52
|
+
written?: string;
|
|
53
|
+
}
|
|
129
54
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
55
|
+
/** `parse`'s result: the parsed node in upstream's shape, with its `errors` (empty when it parsed). */
|
|
56
|
+
export interface HyperscriptParseResult {
|
|
57
|
+
errors: HyperscriptParseError[];
|
|
58
|
+
}
|
|
134
59
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*/
|
|
138
|
-
ObjectPool: any;
|
|
60
|
+
/** A root `processNode` initialises: hooks receive it before and after. */
|
|
61
|
+
export type HyperscriptProcessRoot = Element | Document | DocumentFragment;
|
|
139
62
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
63
|
+
/**
|
|
64
|
+
* A plugin's rewrite of a script, applied as the script is read; the element keeps the text its
|
|
65
|
+
* author wrote. Return nothing to leave the script as it is.
|
|
66
|
+
*/
|
|
67
|
+
export type HyperscriptSourceTransform = (
|
|
68
|
+
source: string,
|
|
69
|
+
element: Element
|
|
70
|
+
) => string | null | undefined;
|
|
71
|
+
|
|
72
|
+
/** `config`: upstream's settings, and the table `as <Name>` conversions read. */
|
|
73
|
+
export interface HyperscriptConfig {
|
|
74
|
+
/** Attributes that hold a script (default `'_, script, data-script'`). */
|
|
75
|
+
attributes: string;
|
|
76
|
+
defaultTransition: string;
|
|
77
|
+
disableSelector: string;
|
|
78
|
+
/** The strategy `hide` / `show` / `toggle` use when none is named (`display` if unset). */
|
|
79
|
+
defaultHideShowStrategy?: string;
|
|
80
|
+
/** Extra strategies, by name. */
|
|
81
|
+
hideShowStrategies: Record<
|
|
82
|
+
string,
|
|
83
|
+
(op: 'hide' | 'show' | 'toggle', elt: HTMLElement, arg?: string) => void
|
|
84
|
+
>;
|
|
85
|
+
/** `fetch` throws when the response status matches one of these. */
|
|
86
|
+
fetchThrowsOn: RegExp[];
|
|
87
|
+
/** `as <Name>` conversions, by name; `dynamicResolvers` handle names with arguments. */
|
|
88
|
+
conversions: Record<string, (value: unknown) => unknown> & {
|
|
89
|
+
dynamicResolvers: ((name: string, value: unknown) => unknown)[];
|
|
147
90
|
};
|
|
91
|
+
}
|
|
148
92
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
93
|
+
/**
|
|
94
|
+
* `window.hyperfixi` / `window._hyperscript`. Callable: `hyperfixi(source, context?)` is
|
|
95
|
+
* `hyperfixi.evaluate(source, context?)`.
|
|
96
|
+
*
|
|
97
|
+
* Replacing core 3.x's API: `compileSync(code)` → `parse(code).errors`;
|
|
98
|
+
* `eval(code, element)` / `execute(code, element)` → `evaluate(code, { me: element })`;
|
|
99
|
+
* `processNode(node)` is unchanged; `compile(code, { language })` → load
|
|
100
|
+
* `@lokascript/hyperscript-adapter` beside a semantic bundle, which translates each script as
|
|
101
|
+
* the engine reads it.
|
|
102
|
+
*/
|
|
103
|
+
export interface HyperfixiAPI {
|
|
104
|
+
(source: string, context?: HyperscriptContext): unknown;
|
|
153
105
|
|
|
154
106
|
/**
|
|
155
|
-
*
|
|
107
|
+
* Run source: commands, features (installed on `document.body`) or one expression.
|
|
108
|
+
* Synchronous unless the source itself waits on something; then it returns a promise.
|
|
109
|
+
* A parse error throws.
|
|
156
110
|
*/
|
|
157
|
-
|
|
158
|
-
}
|
|
111
|
+
evaluate(source: string, context?: HyperscriptContext): unknown;
|
|
159
112
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
strict?: boolean;
|
|
163
|
-
[key: string]: any;
|
|
164
|
-
}
|
|
113
|
+
/** Parse without running. A grammar error is reported in `errors`; a tokenizer error throws. */
|
|
114
|
+
parse(source: string): HyperscriptParseResult;
|
|
165
115
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
code?: any;
|
|
169
|
-
error?: Error;
|
|
170
|
-
[key: string]: any;
|
|
171
|
-
}
|
|
116
|
+
/** Initialise every scripted element under a node; elements already initialised are skipped. */
|
|
117
|
+
process(node: unknown): void;
|
|
172
118
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
element?: Element;
|
|
176
|
-
[key: string]: any;
|
|
177
|
-
}
|
|
119
|
+
/** Upstream's older name for `process`. */
|
|
120
|
+
processNode(node: unknown): void;
|
|
178
121
|
|
|
179
|
-
|
|
180
|
-
element
|
|
181
|
-
globals?: Record<string, any>;
|
|
182
|
-
[key: string]: any;
|
|
183
|
-
}
|
|
122
|
+
/** Remove everything an element's script installed: listeners, observers, timers, state. */
|
|
123
|
+
cleanup(element: Element): void;
|
|
184
124
|
|
|
185
|
-
|
|
186
|
-
[key: string]: any;
|
|
187
|
-
}
|
|
125
|
+
config: HyperscriptConfig;
|
|
188
126
|
|
|
189
|
-
|
|
127
|
+
/** `use(plugin)`: the plugin receives this object (upstream's plugin API). */
|
|
128
|
+
use(plugin: (hyperscript: unknown) => void): void;
|
|
190
129
|
|
|
191
|
-
|
|
130
|
+
addBeforeProcessHook(hook: (root: HyperscriptProcessRoot) => void): void;
|
|
192
131
|
|
|
193
|
-
|
|
132
|
+
addAfterProcessHook(hook: (root: HyperscriptProcessRoot) => void): void;
|
|
194
133
|
|
|
195
|
-
|
|
134
|
+
/** Not in upstream: rewrite a script as it is read, leaving the attribute as written. */
|
|
135
|
+
addSourceTransform(transform: HyperscriptSourceTransform): void;
|
|
196
136
|
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/** Compiled AST (only present if ok=true) */
|
|
204
|
-
ast?: any;
|
|
205
|
-
/** Compilation errors (only present if ok=false) */
|
|
206
|
-
errors?: CompileError[];
|
|
207
|
-
/** Compilation metadata */
|
|
208
|
-
meta: {
|
|
209
|
-
/** Parser used: semantic or traditional */
|
|
210
|
-
parser: 'semantic' | 'traditional';
|
|
211
|
-
/** Confidence score (0-1) if semantic parser was used */
|
|
212
|
-
confidence?: number;
|
|
213
|
-
/** Language code */
|
|
214
|
-
language: string;
|
|
215
|
-
/** Compilation time in milliseconds */
|
|
216
|
-
timeMs: number;
|
|
217
|
-
/** Whether direct path was taken (no fallback) */
|
|
218
|
-
directPath?: boolean;
|
|
137
|
+
/** The part of upstream's `internals` that pages and tests reach for. */
|
|
138
|
+
internals: {
|
|
139
|
+
runtime: {
|
|
140
|
+
cleanup(element: Element): void;
|
|
141
|
+
processNode(node: unknown): void;
|
|
142
|
+
};
|
|
219
143
|
};
|
|
220
|
-
}
|
|
221
144
|
|
|
222
|
-
/**
|
|
223
|
-
|
|
224
|
-
*/
|
|
225
|
-
export interface CompileError {
|
|
226
|
-
/** Error message */
|
|
227
|
-
message: string;
|
|
228
|
-
/** Line number where error occurred */
|
|
229
|
-
line: number;
|
|
230
|
-
/** Column number where error occurred */
|
|
231
|
-
column: number;
|
|
232
|
-
/** Optional suggestion for fixing the error */
|
|
233
|
-
suggestion?: string;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Compilation options (API v2)
|
|
238
|
-
*/
|
|
239
|
-
export interface NewCompileOptions {
|
|
240
|
-
/** Language code (default: 'en') */
|
|
241
|
-
language?: string;
|
|
242
|
-
/** Minimum confidence for semantic parsing (0-1, default: 0.5) */
|
|
243
|
-
confidenceThreshold?: number;
|
|
244
|
-
/** Force traditional parser, skip semantic analysis */
|
|
245
|
-
traditional?: boolean;
|
|
145
|
+
/** The engine's package version (`'dev'` when built from source without one). */
|
|
146
|
+
version: string;
|
|
246
147
|
}
|
|
247
148
|
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
*/
|
|
251
|
-
export interface ValidateResult {
|
|
252
|
-
/** Whether code is valid */
|
|
253
|
-
valid: boolean;
|
|
254
|
-
/** Validation errors (only present if valid=false) */
|
|
255
|
-
errors?: CompileError[];
|
|
256
|
-
}
|
|
149
|
+
/** @deprecated The 3.x name; `window.hyperfixi` is a {@link HyperfixiAPI} since 4.0. */
|
|
150
|
+
export type LokaScriptCoreAPI = HyperfixiAPI;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* HyperFixi and LokaScript global variables, providing IDE autocomplete and type safety.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { HyperfixiAPI } from './core-api';
|
|
9
9
|
import type { LokaScriptSemanticAPI } from './semantic-api';
|
|
10
10
|
import type { LokaScriptI18nAPI } from './i18n-api';
|
|
11
11
|
|
|
@@ -15,34 +15,28 @@ declare global {
|
|
|
15
15
|
*/
|
|
16
16
|
interface Window {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* The hyperscript engine (`@hyperfixi/engine`'s public object).
|
|
19
19
|
*
|
|
20
|
-
* Loaded from: hyperfixi.js or hyperfixi
|
|
20
|
+
* Loaded from: hyperfixi-hs.js (or hyperfixi.js, the same file under `@hyperfixi/core`'s name)
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```typescript
|
|
24
|
-
* window.hyperfixi.
|
|
25
|
-
* window.hyperfixi.
|
|
24
|
+
* window.hyperfixi.evaluate('add .highlight to me', { me: document.body })
|
|
25
|
+
* window.hyperfixi.parse('on click toggle .active').errors // []
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
hyperfixi:
|
|
28
|
+
hyperfixi: HyperfixiAPI;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Loaded from: hyperfixi.js (backward-compat alias)
|
|
34
|
-
*/
|
|
35
|
-
lokascript: LokaScriptCoreAPI;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Compatibility alias for official _hyperscript API compatibility
|
|
31
|
+
* The same object as `window.hyperfixi`, under upstream `_hyperscript`'s name — set by
|
|
32
|
+
* hyperfixi-hs.js, and by upstream `_hyperscript` itself.
|
|
39
33
|
*
|
|
40
34
|
* @example
|
|
41
35
|
* ```typescript
|
|
42
|
-
* window._hyperscript.
|
|
36
|
+
* window._hyperscript.processNode(document.body)
|
|
43
37
|
* ```
|
|
44
38
|
*/
|
|
45
|
-
_hyperscript:
|
|
39
|
+
_hyperscript: HyperfixiAPI;
|
|
46
40
|
|
|
47
41
|
/**
|
|
48
42
|
* LokaScript Semantic - Multilingual semantic parsing (24 languages)
|
|
@@ -58,14 +52,14 @@ declare global {
|
|
|
58
52
|
LokaScriptSemantic: LokaScriptSemanticAPI;
|
|
59
53
|
|
|
60
54
|
/**
|
|
61
|
-
* LokaScript I18n -
|
|
55
|
+
* LokaScript I18n - per-language vocabulary and word-order profiles (24 languages).
|
|
56
|
+
* Translation is `window.LokaScriptSemantic.translate`.
|
|
62
57
|
*
|
|
63
58
|
* Loaded from: lokascript-i18n.min.js
|
|
64
59
|
*
|
|
65
60
|
* @example
|
|
66
61
|
* ```typescript
|
|
67
|
-
*
|
|
68
|
-
* // Result: 'クリック で .active を 切り替え' (SOV word order)
|
|
62
|
+
* window.LokaScriptI18n.getProfile('ja')?.wordOrder // 'SOV'
|
|
69
63
|
* ```
|
|
70
64
|
*/
|
|
71
65
|
LokaScriptI18n: LokaScriptI18nAPI;
|
|
@@ -74,9 +68,8 @@ declare global {
|
|
|
74
68
|
/**
|
|
75
69
|
* globalThis interface augmentation (same as Window for browser contexts)
|
|
76
70
|
*/
|
|
77
|
-
var hyperfixi:
|
|
78
|
-
var
|
|
79
|
-
var _hyperscript: LokaScriptCoreAPI;
|
|
71
|
+
var hyperfixi: HyperfixiAPI;
|
|
72
|
+
var _hyperscript: HyperfixiAPI;
|
|
80
73
|
var LokaScriptSemantic: LokaScriptSemanticAPI;
|
|
81
74
|
var LokaScriptI18n: LokaScriptI18nAPI;
|
|
82
75
|
}
|