@hyperfixi/vite-plugin 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/README.md +100 -95
- package/dist/index.cjs +244 -1856
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -130
- package/dist/index.d.ts +36 -130
- package/dist/index.js +243 -1863
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { ASTNode } from '@hyperfixi/core/parser/hybrid/ast-types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Vite Plugin Types
|
|
@@ -11,19 +10,9 @@ import { ASTNode } from '@hyperfixi/core/parser/hybrid/ast-types';
|
|
|
11
10
|
*/
|
|
12
11
|
interface HyperfixiPluginOptions {
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - 'compile'
|
|
17
|
-
*
|
|
18
|
-
* Compile mode limitations:
|
|
19
|
-
* - No dynamic hyperscript (runtime execute() won't work)
|
|
20
|
-
* - No block commands (if, for, repeat, while, fetch)
|
|
21
|
-
* - HTML must be transformed to use data-h attributes
|
|
22
|
-
*
|
|
23
|
-
* Use compile mode when:
|
|
24
|
-
* - Bundle size is critical (<1KB target)
|
|
25
|
-
* - All hyperscript is static (no dynamic generation)
|
|
26
|
-
* - Only simple commands are used (toggle, add, remove, set, etc.)
|
|
13
|
+
* @deprecated Removed in 4.0. `'compile'` pre-compiled handlers to JS with
|
|
14
|
+
* `@hyperfixi/core`'s parser; it went with that parser, and the plugin always emits the
|
|
15
|
+
* engine-module bundle now (setting `'compile'` logs a warning and does that).
|
|
27
16
|
*/
|
|
28
17
|
mode?: 'interpret' | 'compile';
|
|
29
18
|
/**
|
|
@@ -51,16 +40,19 @@ interface HyperfixiPluginOptions {
|
|
|
51
40
|
*/
|
|
52
41
|
positional?: boolean;
|
|
53
42
|
/**
|
|
54
|
-
*
|
|
43
|
+
* Hand content htmx swaps in to the engine (`htmx:load` / `htmx:afterSettle`
|
|
44
|
+
* → `processNode`). On by default when the scan finds htmx attributes.
|
|
45
|
+
* htmx itself is not bundled: load htmx 4 beside the generated bundle.
|
|
55
46
|
*/
|
|
56
47
|
htmx?: boolean;
|
|
57
48
|
/**
|
|
58
49
|
* Development mode fallback strategy.
|
|
59
|
-
* - '
|
|
60
|
-
* - '
|
|
61
|
-
* - '
|
|
50
|
+
* - 'everything': the engine with every module (34 KB gzipped), for faster dev rebuilds
|
|
51
|
+
* - 'auto': generate the module-list bundle in dev too
|
|
52
|
+
* - 'hybrid-complete' | 'full': accepted for compatibility; both mean 'everything'
|
|
53
|
+
* (core's prebuilt bundles are no longer what the plugin falls back to)
|
|
62
54
|
*/
|
|
63
|
-
devFallback?: 'hybrid-complete' | 'full' | 'auto';
|
|
55
|
+
devFallback?: 'everything' | 'hybrid-complete' | 'full' | 'auto';
|
|
64
56
|
/**
|
|
65
57
|
* Global variable name for the hyperfixi API.
|
|
66
58
|
* Defaults to 'hyperfixi'.
|
|
@@ -215,26 +207,26 @@ interface HtmxUsage {
|
|
|
215
207
|
*/
|
|
216
208
|
needsSwapTiming?: boolean;
|
|
217
209
|
/**
|
|
218
|
-
* htmx v4 reactive/streaming surface detected.
|
|
219
|
-
*
|
|
220
|
-
*
|
|
210
|
+
* htmx v4 reactive/streaming surface detected. `needsHxLive` pulls in the
|
|
211
|
+
* engine's reactivity modules; htmx itself is not bundled (core's
|
|
212
|
+
* hyperfixi-hx-v4.js, the premade bundle for this surface, retired in C3).
|
|
221
213
|
*
|
|
222
214
|
* Optional to keep older fixture literals (and callers that ignore
|
|
223
215
|
* htmx v4) compatible. Scanner code always emits explicit `false`.
|
|
224
216
|
*/
|
|
225
217
|
needsHxLive?: boolean;
|
|
226
|
-
/** sse-connect / sse-swap detected.
|
|
218
|
+
/** sse-connect / sse-swap detected. Detection only: SSE is htmx 4's (core's htmx layer retired in C3). */
|
|
227
219
|
needsSSE?: boolean;
|
|
228
|
-
/** ws-connect / ws-send detected.
|
|
220
|
+
/** ws-connect / ws-send detected. Detection only: WebSockets are htmx 4's. */
|
|
229
221
|
needsWS?: boolean;
|
|
230
222
|
/**
|
|
231
223
|
* `bind $x to <expr>.<prop>` detected inside an `_=` attribute. Implies
|
|
232
|
-
* reactivity (the
|
|
224
|
+
* reactivity (the engine's reactivity modules).
|
|
233
225
|
*/
|
|
234
226
|
needsBindToProperty?: boolean;
|
|
235
227
|
/**
|
|
236
|
-
* Any
|
|
237
|
-
*
|
|
228
|
+
* Any reactive feature → the generated bundle registers the engine's
|
|
229
|
+
* reactivity modules. Derived from needsHxLive || needsBindToProperty.
|
|
238
230
|
*/
|
|
239
231
|
needsReactivity?: boolean;
|
|
240
232
|
}
|
|
@@ -254,9 +246,9 @@ interface FileUsage {
|
|
|
254
246
|
htmx?: HtmxUsage;
|
|
255
247
|
/**
|
|
256
248
|
* Reactivity-requiring constructs detected directly inside `_=` script
|
|
257
|
-
* bodies (independent of htmx attributes)
|
|
258
|
-
*
|
|
259
|
-
*
|
|
249
|
+
* bodies (independent of htmx attributes): the engine's `live` / `when` /
|
|
250
|
+
* `bind` features and the `^var` form. When true, the generated bundle
|
|
251
|
+
* registers the engine's `reactivity` (and `liveTemplates`) modules.
|
|
260
252
|
*
|
|
261
253
|
* Kept top-level rather than under `htmx` because authors may use these
|
|
262
254
|
* features without any htmx attributes at all (pure `_=` reactive code).
|
|
@@ -272,6 +264,10 @@ interface FileUsage {
|
|
|
272
264
|
* in an `_=` body. Implies `needsReactivity` too.
|
|
273
265
|
*/
|
|
274
266
|
needsBindToProperty?: boolean;
|
|
267
|
+
/** `new X(…)` seen: the engine's `construct` addition is registered. */
|
|
268
|
+
needsConstruct?: boolean;
|
|
269
|
+
/** `cookies` seen: the engine's `cookies` expression module is registered. */
|
|
270
|
+
needsCookies?: boolean;
|
|
275
271
|
}
|
|
276
272
|
/**
|
|
277
273
|
* Aggregated usage information across all files
|
|
@@ -290,7 +286,7 @@ interface AggregatedUsage {
|
|
|
290
286
|
/**
|
|
291
287
|
* Whether any file uses reactivity-requiring constructs (either via
|
|
292
288
|
* `hx-live` attributes or inside `_=` scripts). Drives the generated
|
|
293
|
-
* bundle's
|
|
289
|
+
* bundle's registration of the engine's reactivity modules.
|
|
294
290
|
*
|
|
295
291
|
* Optional to keep test fixtures compatible; the aggregator always
|
|
296
292
|
* emits an explicit boolean.
|
|
@@ -298,6 +294,10 @@ interface AggregatedUsage {
|
|
|
298
294
|
needsReactivity?: boolean;
|
|
299
295
|
/** Whether any file uses explicit-property bind. */
|
|
300
296
|
needsBindToProperty?: boolean;
|
|
297
|
+
/** Whether any file uses `new X(…)` (the engine's `construct` addition). */
|
|
298
|
+
needsConstruct?: boolean;
|
|
299
|
+
/** Whether any file reads `cookies`. */
|
|
300
|
+
needsCookies?: boolean;
|
|
301
301
|
/** Map of file paths to their usage */
|
|
302
302
|
fileUsage: Map<string, FileUsage>;
|
|
303
303
|
}
|
|
@@ -438,92 +438,6 @@ declare class DomainAggregator {
|
|
|
438
438
|
private isEqual;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
/**
|
|
442
|
-
* Compiler
|
|
443
|
-
*
|
|
444
|
-
* Compiles hyperscript AST to JavaScript at build time.
|
|
445
|
-
* Eliminates the need for runtime parsing.
|
|
446
|
-
*
|
|
447
|
-
* Multilingual support:
|
|
448
|
-
* - For English: Uses HybridParser directly
|
|
449
|
-
* - For other languages: Uses semantic parser to translate → AST → JavaScript
|
|
450
|
-
* - Semantic parsing happens at BUILD time (zero runtime overhead)
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Result shape returned by the semantic parse function.
|
|
455
|
-
* Matches `ParseWithConfidenceResult` from `@lokascript/semantic`.
|
|
456
|
-
*/
|
|
457
|
-
interface SemanticParseResult {
|
|
458
|
-
confidence: number;
|
|
459
|
-
node?: unknown;
|
|
460
|
-
error?: string | undefined;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Function that parses input in a given language and returns a confidence
|
|
464
|
-
* score plus an optional semantic node. Matches `parseSemantic` / `parseWithConfidence`
|
|
465
|
-
* from `@lokascript/semantic`.
|
|
466
|
-
*/
|
|
467
|
-
type SemanticParseFn = (input: string, language: string) => SemanticParseResult;
|
|
468
|
-
/**
|
|
469
|
-
* Function that checks whether a language is registered for parsing.
|
|
470
|
-
* Matches `isLanguageRegistered` from `@lokascript/semantic`.
|
|
471
|
-
*/
|
|
472
|
-
type SupportsLanguageFn = (language: string) => boolean;
|
|
473
|
-
type BuildASTFn = (node: unknown) => {
|
|
474
|
-
ast: ASTNode;
|
|
475
|
-
warnings: string[];
|
|
476
|
-
};
|
|
477
|
-
/**
|
|
478
|
-
* Configure the semantic parser for multilingual compilation.
|
|
479
|
-
*
|
|
480
|
-
* @example
|
|
481
|
-
* ```typescript
|
|
482
|
-
* import { parseSemantic, isLanguageRegistered, buildAST } from '@lokascript/semantic';
|
|
483
|
-
* import { setSemanticParser } from '@hyperfixi/vite-plugin';
|
|
484
|
-
*
|
|
485
|
-
* setSemanticParser(parseSemantic, isLanguageRegistered, buildAST);
|
|
486
|
-
* ```
|
|
487
|
-
*/
|
|
488
|
-
declare function setSemanticParser(parse: SemanticParseFn, supports: SupportsLanguageFn, buildAST: BuildASTFn): void;
|
|
489
|
-
/**
|
|
490
|
-
* Clear the semantic parser (for testing).
|
|
491
|
-
*/
|
|
492
|
-
declare function clearSemanticParser(): void;
|
|
493
|
-
/**
|
|
494
|
-
* Check if semantic parser is available.
|
|
495
|
-
*/
|
|
496
|
-
declare function hasSemanticParser(): boolean;
|
|
497
|
-
interface CompiledHandler {
|
|
498
|
-
/** Unique handler ID (h0, h1, etc.) */
|
|
499
|
-
id: string;
|
|
500
|
-
/** Event name (click, input, etc.) */
|
|
501
|
-
event: string;
|
|
502
|
-
/** Event modifiers */
|
|
503
|
-
modifiers: {
|
|
504
|
-
prevent?: boolean;
|
|
505
|
-
stop?: boolean;
|
|
506
|
-
once?: boolean;
|
|
507
|
-
debounce?: number;
|
|
508
|
-
throttle?: number;
|
|
509
|
-
};
|
|
510
|
-
/** Compiled JavaScript code */
|
|
511
|
-
code: string;
|
|
512
|
-
/** Whether handler needs the mini-evaluator for dynamic expressions */
|
|
513
|
-
needsEvaluator: boolean;
|
|
514
|
-
/** Original hyperscript for debugging */
|
|
515
|
-
original: string;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Compile options for multilingual support.
|
|
519
|
-
*/
|
|
520
|
-
interface CompileOptions {
|
|
521
|
-
/** Language code (ISO 639-1). Defaults to 'en'. */
|
|
522
|
-
language?: string;
|
|
523
|
-
/** Enable debug logging. */
|
|
524
|
-
debug?: boolean;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
441
|
/**
|
|
528
442
|
* Language Keywords for Detection
|
|
529
443
|
*
|
|
@@ -620,24 +534,16 @@ declare function getOptimalRegion(languages: Set<SupportedLanguage>): 'western'
|
|
|
620
534
|
* })
|
|
621
535
|
* ```
|
|
622
536
|
*
|
|
623
|
-
* @example
|
|
624
|
-
* ```javascript
|
|
625
|
-
* // Compile mode for smallest bundles (~500 bytes)
|
|
626
|
-
* hyperfixi({
|
|
627
|
-
* mode: 'compile', // Pre-compile hyperscript to JS
|
|
628
|
-
* debug: true,
|
|
629
|
-
* })
|
|
630
|
-
* ```
|
|
631
537
|
*/
|
|
632
538
|
|
|
633
539
|
/**
|
|
634
540
|
* Compute a hash of the current usage for dev-server cache invalidation.
|
|
635
541
|
*
|
|
636
542
|
* Every input that influences bundle SELECTION must be part of this hash.
|
|
637
|
-
* The htmx/reactivity flags
|
|
638
|
-
* were hashed, adding or removing an hx-live/sse-connect/ws-send
|
|
639
|
-
* without touching any command/block/language — left the cached
|
|
640
|
-
*
|
|
543
|
+
* The htmx/reactivity flags decide which engine modules are registered; before
|
|
544
|
+
* they were hashed, adding or removing an hx-live/sse-connect/ws-send
|
|
545
|
+
* attribute — without touching any command/block/language — left the cached
|
|
546
|
+
* dev bundle stale. Exported for tests.
|
|
641
547
|
*/
|
|
642
548
|
declare function computeUsageHash(usage: AggregatedUsage): string;
|
|
643
549
|
/**
|
|
@@ -648,4 +554,4 @@ declare function computeUsageHash(usage: AggregatedUsage): string;
|
|
|
648
554
|
*/
|
|
649
555
|
declare function hyperfixi(options?: HyperfixiPluginOptions): Plugin;
|
|
650
556
|
|
|
651
|
-
export { type AggregatedUsage, type
|
|
557
|
+
export { type AggregatedUsage, type CustomLanguageKeywords, type DomainAggregatedUsage, DomainAggregator, type DomainFileUsage, type DomainScanRule, DomainScanner, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type ServerBridgeOptions, type SupportedLanguage, clearCustomKeywords, computeUsageHash, hyperfixi as default, descriptorToScanRule, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hyperfixi, isNonLatinLanguage, registerCustomKeywords };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { ASTNode } from '@hyperfixi/core/parser/hybrid/ast-types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Vite Plugin Types
|
|
@@ -11,19 +10,9 @@ import { ASTNode } from '@hyperfixi/core/parser/hybrid/ast-types';
|
|
|
11
10
|
*/
|
|
12
11
|
interface HyperfixiPluginOptions {
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - 'compile'
|
|
17
|
-
*
|
|
18
|
-
* Compile mode limitations:
|
|
19
|
-
* - No dynamic hyperscript (runtime execute() won't work)
|
|
20
|
-
* - No block commands (if, for, repeat, while, fetch)
|
|
21
|
-
* - HTML must be transformed to use data-h attributes
|
|
22
|
-
*
|
|
23
|
-
* Use compile mode when:
|
|
24
|
-
* - Bundle size is critical (<1KB target)
|
|
25
|
-
* - All hyperscript is static (no dynamic generation)
|
|
26
|
-
* - Only simple commands are used (toggle, add, remove, set, etc.)
|
|
13
|
+
* @deprecated Removed in 4.0. `'compile'` pre-compiled handlers to JS with
|
|
14
|
+
* `@hyperfixi/core`'s parser; it went with that parser, and the plugin always emits the
|
|
15
|
+
* engine-module bundle now (setting `'compile'` logs a warning and does that).
|
|
27
16
|
*/
|
|
28
17
|
mode?: 'interpret' | 'compile';
|
|
29
18
|
/**
|
|
@@ -51,16 +40,19 @@ interface HyperfixiPluginOptions {
|
|
|
51
40
|
*/
|
|
52
41
|
positional?: boolean;
|
|
53
42
|
/**
|
|
54
|
-
*
|
|
43
|
+
* Hand content htmx swaps in to the engine (`htmx:load` / `htmx:afterSettle`
|
|
44
|
+
* → `processNode`). On by default when the scan finds htmx attributes.
|
|
45
|
+
* htmx itself is not bundled: load htmx 4 beside the generated bundle.
|
|
55
46
|
*/
|
|
56
47
|
htmx?: boolean;
|
|
57
48
|
/**
|
|
58
49
|
* Development mode fallback strategy.
|
|
59
|
-
* - '
|
|
60
|
-
* - '
|
|
61
|
-
* - '
|
|
50
|
+
* - 'everything': the engine with every module (34 KB gzipped), for faster dev rebuilds
|
|
51
|
+
* - 'auto': generate the module-list bundle in dev too
|
|
52
|
+
* - 'hybrid-complete' | 'full': accepted for compatibility; both mean 'everything'
|
|
53
|
+
* (core's prebuilt bundles are no longer what the plugin falls back to)
|
|
62
54
|
*/
|
|
63
|
-
devFallback?: 'hybrid-complete' | 'full' | 'auto';
|
|
55
|
+
devFallback?: 'everything' | 'hybrid-complete' | 'full' | 'auto';
|
|
64
56
|
/**
|
|
65
57
|
* Global variable name for the hyperfixi API.
|
|
66
58
|
* Defaults to 'hyperfixi'.
|
|
@@ -215,26 +207,26 @@ interface HtmxUsage {
|
|
|
215
207
|
*/
|
|
216
208
|
needsSwapTiming?: boolean;
|
|
217
209
|
/**
|
|
218
|
-
* htmx v4 reactive/streaming surface detected.
|
|
219
|
-
*
|
|
220
|
-
*
|
|
210
|
+
* htmx v4 reactive/streaming surface detected. `needsHxLive` pulls in the
|
|
211
|
+
* engine's reactivity modules; htmx itself is not bundled (core's
|
|
212
|
+
* hyperfixi-hx-v4.js, the premade bundle for this surface, retired in C3).
|
|
221
213
|
*
|
|
222
214
|
* Optional to keep older fixture literals (and callers that ignore
|
|
223
215
|
* htmx v4) compatible. Scanner code always emits explicit `false`.
|
|
224
216
|
*/
|
|
225
217
|
needsHxLive?: boolean;
|
|
226
|
-
/** sse-connect / sse-swap detected.
|
|
218
|
+
/** sse-connect / sse-swap detected. Detection only: SSE is htmx 4's (core's htmx layer retired in C3). */
|
|
227
219
|
needsSSE?: boolean;
|
|
228
|
-
/** ws-connect / ws-send detected.
|
|
220
|
+
/** ws-connect / ws-send detected. Detection only: WebSockets are htmx 4's. */
|
|
229
221
|
needsWS?: boolean;
|
|
230
222
|
/**
|
|
231
223
|
* `bind $x to <expr>.<prop>` detected inside an `_=` attribute. Implies
|
|
232
|
-
* reactivity (the
|
|
224
|
+
* reactivity (the engine's reactivity modules).
|
|
233
225
|
*/
|
|
234
226
|
needsBindToProperty?: boolean;
|
|
235
227
|
/**
|
|
236
|
-
* Any
|
|
237
|
-
*
|
|
228
|
+
* Any reactive feature → the generated bundle registers the engine's
|
|
229
|
+
* reactivity modules. Derived from needsHxLive || needsBindToProperty.
|
|
238
230
|
*/
|
|
239
231
|
needsReactivity?: boolean;
|
|
240
232
|
}
|
|
@@ -254,9 +246,9 @@ interface FileUsage {
|
|
|
254
246
|
htmx?: HtmxUsage;
|
|
255
247
|
/**
|
|
256
248
|
* Reactivity-requiring constructs detected directly inside `_=` script
|
|
257
|
-
* bodies (independent of htmx attributes)
|
|
258
|
-
*
|
|
259
|
-
*
|
|
249
|
+
* bodies (independent of htmx attributes): the engine's `live` / `when` /
|
|
250
|
+
* `bind` features and the `^var` form. When true, the generated bundle
|
|
251
|
+
* registers the engine's `reactivity` (and `liveTemplates`) modules.
|
|
260
252
|
*
|
|
261
253
|
* Kept top-level rather than under `htmx` because authors may use these
|
|
262
254
|
* features without any htmx attributes at all (pure `_=` reactive code).
|
|
@@ -272,6 +264,10 @@ interface FileUsage {
|
|
|
272
264
|
* in an `_=` body. Implies `needsReactivity` too.
|
|
273
265
|
*/
|
|
274
266
|
needsBindToProperty?: boolean;
|
|
267
|
+
/** `new X(…)` seen: the engine's `construct` addition is registered. */
|
|
268
|
+
needsConstruct?: boolean;
|
|
269
|
+
/** `cookies` seen: the engine's `cookies` expression module is registered. */
|
|
270
|
+
needsCookies?: boolean;
|
|
275
271
|
}
|
|
276
272
|
/**
|
|
277
273
|
* Aggregated usage information across all files
|
|
@@ -290,7 +286,7 @@ interface AggregatedUsage {
|
|
|
290
286
|
/**
|
|
291
287
|
* Whether any file uses reactivity-requiring constructs (either via
|
|
292
288
|
* `hx-live` attributes or inside `_=` scripts). Drives the generated
|
|
293
|
-
* bundle's
|
|
289
|
+
* bundle's registration of the engine's reactivity modules.
|
|
294
290
|
*
|
|
295
291
|
* Optional to keep test fixtures compatible; the aggregator always
|
|
296
292
|
* emits an explicit boolean.
|
|
@@ -298,6 +294,10 @@ interface AggregatedUsage {
|
|
|
298
294
|
needsReactivity?: boolean;
|
|
299
295
|
/** Whether any file uses explicit-property bind. */
|
|
300
296
|
needsBindToProperty?: boolean;
|
|
297
|
+
/** Whether any file uses `new X(…)` (the engine's `construct` addition). */
|
|
298
|
+
needsConstruct?: boolean;
|
|
299
|
+
/** Whether any file reads `cookies`. */
|
|
300
|
+
needsCookies?: boolean;
|
|
301
301
|
/** Map of file paths to their usage */
|
|
302
302
|
fileUsage: Map<string, FileUsage>;
|
|
303
303
|
}
|
|
@@ -438,92 +438,6 @@ declare class DomainAggregator {
|
|
|
438
438
|
private isEqual;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
/**
|
|
442
|
-
* Compiler
|
|
443
|
-
*
|
|
444
|
-
* Compiles hyperscript AST to JavaScript at build time.
|
|
445
|
-
* Eliminates the need for runtime parsing.
|
|
446
|
-
*
|
|
447
|
-
* Multilingual support:
|
|
448
|
-
* - For English: Uses HybridParser directly
|
|
449
|
-
* - For other languages: Uses semantic parser to translate → AST → JavaScript
|
|
450
|
-
* - Semantic parsing happens at BUILD time (zero runtime overhead)
|
|
451
|
-
*/
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Result shape returned by the semantic parse function.
|
|
455
|
-
* Matches `ParseWithConfidenceResult` from `@lokascript/semantic`.
|
|
456
|
-
*/
|
|
457
|
-
interface SemanticParseResult {
|
|
458
|
-
confidence: number;
|
|
459
|
-
node?: unknown;
|
|
460
|
-
error?: string | undefined;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Function that parses input in a given language and returns a confidence
|
|
464
|
-
* score plus an optional semantic node. Matches `parseSemantic` / `parseWithConfidence`
|
|
465
|
-
* from `@lokascript/semantic`.
|
|
466
|
-
*/
|
|
467
|
-
type SemanticParseFn = (input: string, language: string) => SemanticParseResult;
|
|
468
|
-
/**
|
|
469
|
-
* Function that checks whether a language is registered for parsing.
|
|
470
|
-
* Matches `isLanguageRegistered` from `@lokascript/semantic`.
|
|
471
|
-
*/
|
|
472
|
-
type SupportsLanguageFn = (language: string) => boolean;
|
|
473
|
-
type BuildASTFn = (node: unknown) => {
|
|
474
|
-
ast: ASTNode;
|
|
475
|
-
warnings: string[];
|
|
476
|
-
};
|
|
477
|
-
/**
|
|
478
|
-
* Configure the semantic parser for multilingual compilation.
|
|
479
|
-
*
|
|
480
|
-
* @example
|
|
481
|
-
* ```typescript
|
|
482
|
-
* import { parseSemantic, isLanguageRegistered, buildAST } from '@lokascript/semantic';
|
|
483
|
-
* import { setSemanticParser } from '@hyperfixi/vite-plugin';
|
|
484
|
-
*
|
|
485
|
-
* setSemanticParser(parseSemantic, isLanguageRegistered, buildAST);
|
|
486
|
-
* ```
|
|
487
|
-
*/
|
|
488
|
-
declare function setSemanticParser(parse: SemanticParseFn, supports: SupportsLanguageFn, buildAST: BuildASTFn): void;
|
|
489
|
-
/**
|
|
490
|
-
* Clear the semantic parser (for testing).
|
|
491
|
-
*/
|
|
492
|
-
declare function clearSemanticParser(): void;
|
|
493
|
-
/**
|
|
494
|
-
* Check if semantic parser is available.
|
|
495
|
-
*/
|
|
496
|
-
declare function hasSemanticParser(): boolean;
|
|
497
|
-
interface CompiledHandler {
|
|
498
|
-
/** Unique handler ID (h0, h1, etc.) */
|
|
499
|
-
id: string;
|
|
500
|
-
/** Event name (click, input, etc.) */
|
|
501
|
-
event: string;
|
|
502
|
-
/** Event modifiers */
|
|
503
|
-
modifiers: {
|
|
504
|
-
prevent?: boolean;
|
|
505
|
-
stop?: boolean;
|
|
506
|
-
once?: boolean;
|
|
507
|
-
debounce?: number;
|
|
508
|
-
throttle?: number;
|
|
509
|
-
};
|
|
510
|
-
/** Compiled JavaScript code */
|
|
511
|
-
code: string;
|
|
512
|
-
/** Whether handler needs the mini-evaluator for dynamic expressions */
|
|
513
|
-
needsEvaluator: boolean;
|
|
514
|
-
/** Original hyperscript for debugging */
|
|
515
|
-
original: string;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* Compile options for multilingual support.
|
|
519
|
-
*/
|
|
520
|
-
interface CompileOptions {
|
|
521
|
-
/** Language code (ISO 639-1). Defaults to 'en'. */
|
|
522
|
-
language?: string;
|
|
523
|
-
/** Enable debug logging. */
|
|
524
|
-
debug?: boolean;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
441
|
/**
|
|
528
442
|
* Language Keywords for Detection
|
|
529
443
|
*
|
|
@@ -620,24 +534,16 @@ declare function getOptimalRegion(languages: Set<SupportedLanguage>): 'western'
|
|
|
620
534
|
* })
|
|
621
535
|
* ```
|
|
622
536
|
*
|
|
623
|
-
* @example
|
|
624
|
-
* ```javascript
|
|
625
|
-
* // Compile mode for smallest bundles (~500 bytes)
|
|
626
|
-
* hyperfixi({
|
|
627
|
-
* mode: 'compile', // Pre-compile hyperscript to JS
|
|
628
|
-
* debug: true,
|
|
629
|
-
* })
|
|
630
|
-
* ```
|
|
631
537
|
*/
|
|
632
538
|
|
|
633
539
|
/**
|
|
634
540
|
* Compute a hash of the current usage for dev-server cache invalidation.
|
|
635
541
|
*
|
|
636
542
|
* Every input that influences bundle SELECTION must be part of this hash.
|
|
637
|
-
* The htmx/reactivity flags
|
|
638
|
-
* were hashed, adding or removing an hx-live/sse-connect/ws-send
|
|
639
|
-
* without touching any command/block/language — left the cached
|
|
640
|
-
*
|
|
543
|
+
* The htmx/reactivity flags decide which engine modules are registered; before
|
|
544
|
+
* they were hashed, adding or removing an hx-live/sse-connect/ws-send
|
|
545
|
+
* attribute — without touching any command/block/language — left the cached
|
|
546
|
+
* dev bundle stale. Exported for tests.
|
|
641
547
|
*/
|
|
642
548
|
declare function computeUsageHash(usage: AggregatedUsage): string;
|
|
643
549
|
/**
|
|
@@ -648,4 +554,4 @@ declare function computeUsageHash(usage: AggregatedUsage): string;
|
|
|
648
554
|
*/
|
|
649
555
|
declare function hyperfixi(options?: HyperfixiPluginOptions): Plugin;
|
|
650
556
|
|
|
651
|
-
export { type AggregatedUsage, type
|
|
557
|
+
export { type AggregatedUsage, type CustomLanguageKeywords, type DomainAggregatedUsage, DomainAggregator, type DomainFileUsage, type DomainScanRule, DomainScanner, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type ServerBridgeOptions, type SupportedLanguage, clearCustomKeywords, computeUsageHash, hyperfixi as default, descriptorToScanRule, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hyperfixi, isNonLatinLanguage, registerCustomKeywords };
|