@lokascript/vite-plugin 1.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/dist/index.js ADDED
@@ -0,0 +1,3228 @@
1
+ // src/language-keywords.ts
2
+ var SUPPORTED_LANGUAGES = [
3
+ "en",
4
+ "es",
5
+ "pt",
6
+ "fr",
7
+ "de",
8
+ "it",
9
+ "vi",
10
+ // Western (Latin script)
11
+ "pl",
12
+ "ru",
13
+ "uk",
14
+ // Slavic (Latin/Cyrillic)
15
+ "ja",
16
+ "zh",
17
+ "ko",
18
+ // East Asian
19
+ "ar",
20
+ // RTL (Arabic script)
21
+ "hi",
22
+ "bn",
23
+ // South Asian (Indic scripts)
24
+ "th",
25
+ // Southeast Asian (Thai script)
26
+ "tr",
27
+ // Agglutinative Latin
28
+ "id",
29
+ "sw",
30
+ "qu",
31
+ // Other
32
+ "tl"
33
+ // Tagalog (auto-added)
34
+ ];
35
+ var REGIONS = {
36
+ western: ["en", "es", "pt", "fr", "de", "it"],
37
+ "east-asian": ["ja", "zh", "ko"],
38
+ slavic: ["pl", "ru", "uk"],
39
+ "south-asian": ["hi", "bn"],
40
+ priority: [
41
+ "en",
42
+ "es",
43
+ "pt",
44
+ "fr",
45
+ "de",
46
+ "it",
47
+ "ja",
48
+ "zh",
49
+ "ko",
50
+ "ar",
51
+ "tr",
52
+ "ru",
53
+ "hi"
54
+ ],
55
+ all: SUPPORTED_LANGUAGES
56
+ };
57
+ var JAPANESE_KEYWORDS = /* @__PURE__ */ new Set([
58
+ "\u5207\u308A\u66FF\u3048",
59
+ "\u5207\u308A\u66FF\u3048\u308B",
60
+ "\u30C8\u30B0\u30EB",
61
+ "\u30C8\u30B0\u30EB\u3059\u308B",
62
+ "\u8FFD\u52A0",
63
+ "\u8FFD\u52A0\u3059\u308B",
64
+ "\u52A0\u3048\u308B",
65
+ "\u524A\u9664",
66
+ "\u524A\u9664\u3059\u308B",
67
+ "\u53D6\u308A\u9664\u304F",
68
+ "\u8868\u793A",
69
+ "\u8868\u793A\u3059\u308B",
70
+ "\u898B\u305B\u308B",
71
+ "\u96A0\u3059",
72
+ "\u975E\u8868\u793A",
73
+ "\u975E\u8868\u793A\u306B\u3059\u308B",
74
+ "\u8A2D\u5B9A",
75
+ "\u8A2D\u5B9A\u3059\u308B",
76
+ "\u30BB\u30C3\u30C8",
77
+ "\u5897\u52A0",
78
+ "\u5897\u3084\u3059",
79
+ "\u30A4\u30F3\u30AF\u30EA\u30E1\u30F3\u30C8",
80
+ "\u6E1B\u5C11",
81
+ "\u6E1B\u3089\u3059",
82
+ "\u30C7\u30AF\u30EA\u30E1\u30F3\u30C8",
83
+ "\u5F15\u304D\u91D1",
84
+ "\u767A\u706B",
85
+ "\u30C8\u30EA\u30AC\u30FC",
86
+ "\u9001\u308B",
87
+ "\u9001\u4FE1",
88
+ "\u3082\u3057",
89
+ "\u6761\u4EF6",
90
+ "\u305D\u3046\u3067\u306A\u3051\u308C\u3070",
91
+ "\u305D\u308C\u4EE5\u5916",
92
+ "\u7E70\u308A\u8FD4\u3057",
93
+ "\u7E70\u308A\u8FD4\u3059",
94
+ "\u30EA\u30D4\u30FC\u30C8",
95
+ "\u5F85\u3064",
96
+ "\u5F85\u6A5F",
97
+ "\u306E\u9593",
98
+ "\u9593"
99
+ ]);
100
+ var KOREAN_KEYWORDS = /* @__PURE__ */ new Set([
101
+ "\uD1A0\uAE00",
102
+ "\uC804\uD658",
103
+ "\uCD94\uAC00",
104
+ "\uC81C\uAC70",
105
+ "\uC0AD\uC81C",
106
+ "\uBCF4\uC774\uB2E4",
107
+ "\uD45C\uC2DC",
108
+ "\uBCF4\uC774\uAE30",
109
+ "\uC228\uAE30\uB2E4",
110
+ "\uC228\uAE30\uAE30",
111
+ "\uC124\uC815",
112
+ "\uC99D\uAC00",
113
+ "\uAC10\uC18C",
114
+ "\uD2B8\uB9AC\uAC70",
115
+ "\uBCF4\uB0B4\uB2E4",
116
+ "\uB9CC\uC57D",
117
+ "\uC544\uB2C8\uBA74",
118
+ "\uBC18\uBCF5",
119
+ "\uB300\uAE30",
120
+ "\uB3D9\uC548"
121
+ ]);
122
+ var CHINESE_KEYWORDS = /* @__PURE__ */ new Set([
123
+ "\u5207\u6362",
124
+ "\u6DFB\u52A0",
125
+ "\u52A0",
126
+ "\u79FB\u9664",
127
+ "\u5220\u9664",
128
+ "\u53BB\u6389",
129
+ "\u663E\u793A",
130
+ "\u5C55\u793A",
131
+ "\u9690\u85CF",
132
+ "\u8BBE\u7F6E",
133
+ "\u8BBE\u5B9A",
134
+ "\u589E\u52A0",
135
+ "\u51CF\u5C11",
136
+ "\u89E6\u53D1",
137
+ "\u53D1\u9001",
138
+ "\u5982\u679C",
139
+ "\u5426\u5219",
140
+ "\u91CD\u590D",
141
+ "\u7B49\u5F85",
142
+ "\u5F53"
143
+ ]);
144
+ var ARABIC_KEYWORDS = /* @__PURE__ */ new Set([
145
+ "\u0628\u062F\u0644",
146
+ "\u0628\u062F\u0651\u0644",
147
+ "\u063A\u064A\u0651\u0631",
148
+ "\u063A\u064A\u0631",
149
+ "\u0623\u0636\u0641",
150
+ "\u0627\u0636\u0641",
151
+ "\u0632\u0650\u062F",
152
+ "\u0627\u062D\u0630\u0641",
153
+ "\u0623\u0632\u0644",
154
+ "\u0627\u0645\u0633\u062D",
155
+ "\u0627\u0638\u0647\u0631",
156
+ "\u0623\u0638\u0647\u0631",
157
+ "\u0627\u0639\u0631\u0636",
158
+ "\u0627\u062E\u0641",
159
+ "\u0623\u062E\u0641\u0650",
160
+ "\u0627\u062E\u0641\u064A",
161
+ "\u0627\u0636\u0628\u0637",
162
+ "\u0639\u064A\u0651\u0646",
163
+ "\u062D\u062F\u062F",
164
+ "\u0627\u0631\u0641\u0639",
165
+ "\u0623\u0646\u0642\u0635",
166
+ "\u0642\u0644\u0644",
167
+ "\u062A\u0634\u063A\u064A\u0644",
168
+ "\u0623\u0637\u0644\u0642",
169
+ "\u0641\u0639\u0651\u0644",
170
+ "\u0623\u0631\u0633\u0644",
171
+ "\u0625\u0630\u0627",
172
+ "\u0648\u0625\u0644\u0627",
173
+ "\u062E\u0644\u0627\u0641 \u0630\u0644\u0643",
174
+ "\u0643\u0631\u0631",
175
+ "\u0627\u0646\u062A\u0638\u0631",
176
+ "\u0628\u064A\u0646\u0645\u0627"
177
+ ]);
178
+ var SPANISH_KEYWORDS = /* @__PURE__ */ new Set([
179
+ "alternar",
180
+ "cambiar",
181
+ "conmutar",
182
+ "agregar",
183
+ "a\xF1adir",
184
+ "quitar",
185
+ "eliminar",
186
+ "remover",
187
+ "sacar",
188
+ "mostrar",
189
+ "ense\xF1ar",
190
+ "ocultar",
191
+ "esconder",
192
+ "establecer",
193
+ "fijar",
194
+ "definir",
195
+ "incrementar",
196
+ "aumentar",
197
+ "decrementar",
198
+ "disminuir",
199
+ "disparar",
200
+ "activar",
201
+ "enviar",
202
+ "si",
203
+ "sino",
204
+ "de lo contrario",
205
+ "repetir",
206
+ "esperar",
207
+ "mientras"
208
+ ]);
209
+ var PORTUGUESE_KEYWORDS = /* @__PURE__ */ new Set([
210
+ "alternar",
211
+ "trocar",
212
+ "adicionar",
213
+ "acrescentar",
214
+ "remover",
215
+ "eliminar",
216
+ "apagar",
217
+ "mostrar",
218
+ "exibir",
219
+ "ocultar",
220
+ "esconder",
221
+ "definir",
222
+ "configurar",
223
+ "incrementar",
224
+ "aumentar",
225
+ "decrementar",
226
+ "diminuir",
227
+ "disparar",
228
+ "ativar",
229
+ "enviar",
230
+ "se",
231
+ "sen\xE3o",
232
+ "repetir",
233
+ "esperar",
234
+ "aguardar",
235
+ "enquanto"
236
+ ]);
237
+ var FRENCH_KEYWORDS = /* @__PURE__ */ new Set([
238
+ "basculer",
239
+ "permuter",
240
+ "alterner",
241
+ "ajouter",
242
+ "supprimer",
243
+ "enlever",
244
+ "retirer",
245
+ "montrer",
246
+ "afficher",
247
+ "cacher",
248
+ "masquer",
249
+ "d\xE9finir",
250
+ "\xE9tablir",
251
+ "incr\xE9menter",
252
+ "augmenter",
253
+ "d\xE9cr\xE9menter",
254
+ "diminuer",
255
+ "d\xE9clencher",
256
+ "envoyer",
257
+ "si",
258
+ "sinon",
259
+ "r\xE9p\xE9ter",
260
+ "attendre",
261
+ "pendant"
262
+ ]);
263
+ var GERMAN_KEYWORDS = /* @__PURE__ */ new Set([
264
+ "umschalten",
265
+ "wechseln",
266
+ "hinzuf\xFCgen",
267
+ "entfernen",
268
+ "l\xF6schen",
269
+ "zeigen",
270
+ "anzeigen",
271
+ "verbergen",
272
+ "verstecken",
273
+ "festlegen",
274
+ "definieren",
275
+ "erh\xF6hen",
276
+ "verringern",
277
+ "vermindern",
278
+ "ausl\xF6sen",
279
+ "senden",
280
+ "schicken",
281
+ "wenn",
282
+ "falls",
283
+ "sonst",
284
+ "ansonsten",
285
+ "wiederholen",
286
+ "warten",
287
+ "solange",
288
+ "w\xE4hrend"
289
+ ]);
290
+ var TURKISH_KEYWORDS = /* @__PURE__ */ new Set([
291
+ "de\u011Fi\u015Ftir",
292
+ "a\xE7/kapat",
293
+ "ekle",
294
+ "kald\u0131r",
295
+ "sil",
296
+ "g\xF6ster",
297
+ "gizle",
298
+ "ayarla",
299
+ "yap",
300
+ "belirle",
301
+ "art\u0131r",
302
+ "azalt",
303
+ "tetikle",
304
+ "g\xF6nder",
305
+ "e\u011Fer",
306
+ "yoksa",
307
+ "tekrarla",
308
+ "bekle",
309
+ "iken"
310
+ ]);
311
+ var INDONESIAN_KEYWORDS = /* @__PURE__ */ new Set([
312
+ "alihkan",
313
+ "ganti",
314
+ "tukar",
315
+ "tambah",
316
+ "tambahkan",
317
+ "hapus",
318
+ "buang",
319
+ "hilangkan",
320
+ "tampilkan",
321
+ "perlihatkan",
322
+ "sembunyikan",
323
+ "tutup",
324
+ "atur",
325
+ "tetapkan",
326
+ "tingkatkan",
327
+ "naikkan",
328
+ "turunkan",
329
+ "kurangi",
330
+ "picu",
331
+ "jalankan",
332
+ "kirim",
333
+ "kirimkan",
334
+ "jika",
335
+ "kalau",
336
+ "bila",
337
+ "selainnya",
338
+ "ulangi",
339
+ "tunggu",
340
+ "selama"
341
+ ]);
342
+ var SWAHILI_KEYWORDS = /* @__PURE__ */ new Set([
343
+ "badilisha",
344
+ "geuza",
345
+ "ongeza",
346
+ "weka",
347
+ "ondoa",
348
+ "futa",
349
+ "toa",
350
+ "onyesha",
351
+ "ficha",
352
+ "mficho",
353
+ "seti",
354
+ "punguza",
355
+ "chochea",
356
+ "anzisha",
357
+ "tuma",
358
+ "peleka",
359
+ "kama",
360
+ "ikiwa",
361
+ "vinginevyo",
362
+ "sivyo",
363
+ "rudia",
364
+ "subiri",
365
+ "ngoja",
366
+ "wakati"
367
+ ]);
368
+ var QUECHUA_KEYWORDS = /* @__PURE__ */ new Set([
369
+ "t",
370
+ "tikray",
371
+ "kutichiy",
372
+ "yapay",
373
+ "yapaykuy",
374
+ "qichuy",
375
+ "hurquy",
376
+ "anchuchiy",
377
+ "rikuchiy",
378
+ "qawachiy",
379
+ "pakay",
380
+ "pakakuy",
381
+ "churay",
382
+ "kamaykuy",
383
+ "yapachiy",
384
+ "pisiyachiy",
385
+ "qallarichiy",
386
+ "kachay",
387
+ "apachiy",
388
+ "sichus",
389
+ "manachus",
390
+ "hukniraq",
391
+ "kutipay",
392
+ "muyu",
393
+ "suyay",
394
+ "kaykamaqa"
395
+ ]);
396
+ var ITALIAN_KEYWORDS = /* @__PURE__ */ new Set([
397
+ "commutare",
398
+ "alternare",
399
+ "cambiare",
400
+ "aggiungere",
401
+ "aggiungi",
402
+ "rimuovere",
403
+ "eliminare",
404
+ "togliere",
405
+ "mostrare",
406
+ "visualizzare",
407
+ "nascondere",
408
+ "impostare",
409
+ "definire",
410
+ "incrementare",
411
+ "aumentare",
412
+ "decrementare",
413
+ "diminuire",
414
+ "scatenare",
415
+ "attivare",
416
+ "inviare",
417
+ "se",
418
+ "altrimenti",
419
+ "ripetere",
420
+ "aspettare",
421
+ "attendere",
422
+ "mentre"
423
+ ]);
424
+ var VIETNAMESE_KEYWORDS = /* @__PURE__ */ new Set([
425
+ "chuy\u1EC3n \u0111\u1ED5i",
426
+ "b\u1EADt t\u1EAFt",
427
+ "chuy\u1EC3n",
428
+ "th\xEAm",
429
+ "b\u1ED5 sung",
430
+ "x\xF3a",
431
+ "g\u1EE1 b\u1ECF",
432
+ "lo\u1EA1i b\u1ECF",
433
+ "b\u1ECF",
434
+ "hi\u1EC3n th\u1ECB",
435
+ "hi\u1EC7n",
436
+ "\u1EA9n",
437
+ "che",
438
+ "gi\u1EA5u",
439
+ "g\xE1n",
440
+ "thi\u1EBFt l\u1EADp",
441
+ "\u0111\u1EB7t",
442
+ "t\u0103ng",
443
+ "t\u0103ng l\xEAn",
444
+ "gi\u1EA3m",
445
+ "gi\u1EA3m \u0111i",
446
+ "k\xEDch ho\u1EA1t",
447
+ "g\u1EEDi",
448
+ "n\u1EBFu",
449
+ "kh\xF4ng th\xEC",
450
+ "n\u1EBFu kh\xF4ng",
451
+ "l\u1EB7p l\u1EA1i",
452
+ "ch\u1EDD",
453
+ "\u0111\u1EE3i",
454
+ "trong khi"
455
+ ]);
456
+ var POLISH_KEYWORDS = /* @__PURE__ */ new Set([
457
+ "prze\u0142\u0105cz",
458
+ "przelacz",
459
+ "dodaj",
460
+ "usu\u0144",
461
+ "usun",
462
+ "wyczy\u015B\u0107",
463
+ "wyczysc",
464
+ "poka\u017C",
465
+ "pokaz",
466
+ "wy\u015Bwietl",
467
+ "wyswietl",
468
+ "ukryj",
469
+ "schowaj",
470
+ "ustaw",
471
+ "okre\u015Bl",
472
+ "okresl",
473
+ "zwi\u0119ksz",
474
+ "zwieksz",
475
+ "zmniejsz",
476
+ "wywo\u0142aj",
477
+ "wywolaj",
478
+ "wyzw\xF3l",
479
+ "wyzwol",
480
+ "wy\u015Blij",
481
+ "wyslij",
482
+ "je\u015Bli",
483
+ "jesli",
484
+ "je\u017Celi",
485
+ "jezeli",
486
+ "inaczej",
487
+ "wpp",
488
+ "powt\xF3rz",
489
+ "powtorz",
490
+ "czekaj",
491
+ "poczekaj",
492
+ "dop\xF3ki",
493
+ "dopoki",
494
+ "podczas"
495
+ ]);
496
+ var RUSSIAN_KEYWORDS = /* @__PURE__ */ new Set([
497
+ "\u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0438\u0442\u044C",
498
+ "\u043F\u0435\u0440\u0435\u043A\u043B\u044E\u0447\u0438",
499
+ "\u0434\u043E\u0431\u0430\u0432\u0438\u0442\u044C",
500
+ "\u0434\u043E\u0431\u0430\u0432\u044C",
501
+ "\u0443\u0434\u0430\u043B\u0438\u0442\u044C",
502
+ "\u0443\u0434\u0430\u043B\u0438",
503
+ "\u0443\u0431\u0440\u0430\u0442\u044C",
504
+ "\u0443\u0431\u0435\u0440\u0438",
505
+ "\u043F\u043E\u043A\u0430\u0437\u0430\u0442\u044C",
506
+ "\u043F\u043E\u043A\u0430\u0436\u0438",
507
+ "\u0441\u043A\u0440\u044B\u0442\u044C",
508
+ "\u0441\u043A\u0440\u043E\u0439",
509
+ "\u0441\u043F\u0440\u044F\u0442\u0430\u0442\u044C",
510
+ "\u0441\u043F\u0440\u044F\u0447\u044C",
511
+ "\u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C",
512
+ "\u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438",
513
+ "\u0437\u0430\u0434\u0430\u0442\u044C",
514
+ "\u0437\u0430\u0434\u0430\u0439",
515
+ "\u0443\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C",
516
+ "\u0443\u0432\u0435\u043B\u0438\u0447\u044C",
517
+ "\u0443\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C",
518
+ "\u0443\u043C\u0435\u043D\u044C\u0448\u0438",
519
+ "\u0432\u044B\u0437\u0432\u0430\u0442\u044C",
520
+ "\u0432\u044B\u0437\u043E\u0432\u0438",
521
+ "\u043E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C",
522
+ "\u043E\u0442\u043F\u0440\u0430\u0432\u044C",
523
+ "\u0435\u0441\u043B\u0438",
524
+ "\u0438\u043D\u0430\u0447\u0435",
525
+ "\u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C",
526
+ "\u043F\u043E\u0432\u0442\u043E\u0440\u0438",
527
+ "\u0436\u0434\u0430\u0442\u044C",
528
+ "\u0436\u0434\u0438",
529
+ "\u043F\u043E\u0434\u043E\u0436\u0434\u0438",
530
+ "\u043F\u043E\u043A\u0430"
531
+ ]);
532
+ var UKRAINIAN_KEYWORDS = /* @__PURE__ */ new Set([
533
+ "\u043F\u0435\u0440\u0435\u043C\u043A\u043D\u0443\u0442\u0438",
534
+ "\u043F\u0435\u0440\u0435\u043C\u043A\u043D\u0438",
535
+ "\u0434\u043E\u0434\u0430\u0442\u0438",
536
+ "\u0434\u043E\u0434\u0430\u0439",
537
+ "\u0432\u0438\u0434\u0430\u043B\u0438\u0442\u0438",
538
+ "\u0432\u0438\u0434\u0430\u043B\u0438",
539
+ "\u043F\u0440\u0438\u0431\u0440\u0430\u0442\u0438",
540
+ "\u043F\u0440\u0438\u0431\u0435\u0440\u0438",
541
+ "\u043F\u043E\u043A\u0430\u0437\u0430\u0442\u0438",
542
+ "\u043F\u043E\u043A\u0430\u0436\u0438",
543
+ "\u0441\u0445\u043E\u0432\u0430\u0442\u0438",
544
+ "\u0441\u0445\u043E\u0432\u0430\u0439",
545
+ "\u043F\u0440\u0438\u0445\u043E\u0432\u0430\u0442\u0438",
546
+ "\u043F\u0440\u0438\u0445\u043E\u0432\u0430\u0439",
547
+ "\u0432\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0438",
548
+ "\u0432\u0441\u0442\u0430\u043D\u043E\u0432\u0438",
549
+ "\u0437\u0430\u0434\u0430\u0442\u0438",
550
+ "\u0437\u0430\u0434\u0430\u0439",
551
+ "\u0437\u0431\u0456\u043B\u044C\u0448\u0438\u0442\u0438",
552
+ "\u0437\u0431\u0456\u043B\u044C\u0448",
553
+ "\u0437\u043C\u0435\u043D\u0448\u0438\u0442\u0438",
554
+ "\u0437\u043C\u0435\u043D\u0448",
555
+ "\u0432\u0438\u043A\u043B\u0438\u043A\u0430\u0442\u0438",
556
+ "\u0432\u0438\u043A\u043B\u0438\u0447",
557
+ "\u043D\u0430\u0434\u0456\u0441\u043B\u0430\u0442\u0438",
558
+ "\u043D\u0430\u0434\u0456\u0448\u043B\u0438",
559
+ "\u044F\u043A\u0449\u043E",
560
+ "\u0456\u043D\u0430\u043A\u0448\u0435",
561
+ "\u043F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u0438",
562
+ "\u043F\u043E\u0432\u0442\u043E\u0440\u0438",
563
+ "\u0447\u0435\u043A\u0430\u0442\u0438",
564
+ "\u0447\u0435\u043A\u0430\u0439",
565
+ "\u0437\u0430\u0447\u0435\u043A\u0430\u0439",
566
+ "\u043F\u043E\u043A\u0438"
567
+ ]);
568
+ var HINDI_KEYWORDS = /* @__PURE__ */ new Set([
569
+ "\u091F\u0949\u0917\u0932",
570
+ "\u092C\u0926\u0932\u0947\u0902",
571
+ "\u092C\u0926\u0932",
572
+ "\u091C\u094B\u0921\u093C\u0947\u0902",
573
+ "\u091C\u094B\u0921\u093C",
574
+ "\u0939\u091F\u093E\u090F\u0902",
575
+ "\u0939\u091F\u093E",
576
+ "\u092E\u093F\u091F\u093E\u090F\u0902",
577
+ "\u0926\u093F\u0916\u093E\u090F\u0902",
578
+ "\u0926\u093F\u0916\u093E",
579
+ "\u091B\u093F\u092A\u093E\u090F\u0902",
580
+ "\u091B\u093F\u092A\u093E",
581
+ "\u0938\u0947\u091F",
582
+ "\u0928\u093F\u0930\u094D\u0927\u093E\u0930\u093F\u0924",
583
+ "\u092C\u0922\u093C\u093E\u090F\u0902",
584
+ "\u092C\u0922\u093C\u093E",
585
+ "\u0918\u091F\u093E\u090F\u0902",
586
+ "\u0918\u091F\u093E",
587
+ "\u091F\u094D\u0930\u093F\u0917\u0930",
588
+ "\u092D\u0947\u091C\u0947\u0902",
589
+ "\u092D\u0947\u091C",
590
+ "\u0905\u0917\u0930",
591
+ "\u092F\u0926\u093F",
592
+ "\u0935\u0930\u0928\u093E",
593
+ "\u0928\u0939\u0940\u0902 \u0924\u094B",
594
+ "\u0926\u094B\u0939\u0930\u093E\u090F\u0902",
595
+ "\u0926\u094B\u0939\u0930\u093E",
596
+ "\u092A\u094D\u0930\u0924\u0940\u0915\u094D\u0937\u093E",
597
+ "\u0930\u0941\u0915\u0947\u0902",
598
+ "\u091C\u092C \u0924\u0915"
599
+ ]);
600
+ var BENGALI_KEYWORDS = /* @__PURE__ */ new Set([
601
+ "\u099F\u0997\u09B2",
602
+ "\u09AA\u09B0\u09BF\u09AC\u09B0\u09CD\u09A4\u09A8",
603
+ "\u09AF\u09CB\u0997",
604
+ "\u09AF\u09CB\u0997 \u0995\u09B0\u09C1\u09A8",
605
+ "\u09B8\u09B0\u09BE\u09A8",
606
+ "\u09B8\u09B0\u09BF\u09AF\u09BC\u09C7 \u09AB\u09C7\u09B2\u09C1\u09A8",
607
+ "\u09AE\u09C1\u099B\u09C1\u09A8",
608
+ "\u09A6\u09C7\u0996\u09BE\u09A8",
609
+ "\u09A6\u09C7\u0996\u09BE\u0993",
610
+ "\u09B2\u09C1\u0995\u09BE\u09A8",
611
+ "\u09B2\u09C1\u0995\u09BE\u0993",
612
+ "\u09B8\u09C7\u099F",
613
+ "\u09A8\u09BF\u09B0\u09CD\u09A7\u09BE\u09B0\u09A3",
614
+ "\u09AC\u09C3\u09A6\u09CD\u09A7\u09BF",
615
+ "\u09AC\u09BE\u09A1\u09BC\u09BE\u09A8",
616
+ "\u09B9\u09CD\u09B0\u09BE\u09B8",
617
+ "\u0995\u09AE\u09BE\u09A8",
618
+ "\u099F\u09CD\u09B0\u09BF\u0997\u09BE\u09B0",
619
+ "\u09AA\u09BE\u09A0\u09BE\u09A8",
620
+ "\u09AA\u09BE\u09A0\u09BE\u0993",
621
+ "\u09AF\u09A6\u09BF",
622
+ "\u09A8\u09A4\u09C1\u09AC\u09BE",
623
+ "\u09A8\u09BE \u09B9\u09B2\u09C7",
624
+ "\u09AA\u09C1\u09A8\u09B0\u09BE\u09AC\u09C3\u09A4\u09CD\u09A4\u09BF",
625
+ "\u09AC\u09BE\u09B0 \u09AC\u09BE\u09B0",
626
+ "\u0985\u09AA\u09C7\u0995\u09CD\u09B7\u09BE",
627
+ "\u09A5\u09BE\u09AE\u09C1\u09A8",
628
+ "\u09AF\u09A4\u0995\u09CD\u09B7\u09A3"
629
+ ]);
630
+ var THAI_KEYWORDS = /* @__PURE__ */ new Set([
631
+ "\u0E2A\u0E25\u0E31\u0E1A",
632
+ "\u0E40\u0E1E\u0E34\u0E48\u0E21",
633
+ "\u0E25\u0E1A",
634
+ "\u0E25\u0E1A\u0E2D\u0E2D\u0E01",
635
+ "\u0E41\u0E2A\u0E14\u0E07",
636
+ "\u0E0B\u0E48\u0E2D\u0E19",
637
+ "\u0E15\u0E31\u0E49\u0E07",
638
+ "\u0E01\u0E33\u0E2B\u0E19\u0E14",
639
+ "\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E04\u0E48\u0E32",
640
+ "\u0E25\u0E14\u0E04\u0E48\u0E32",
641
+ "\u0E17\u0E23\u0E34\u0E01\u0E40\u0E01\u0E2D\u0E23\u0E4C",
642
+ "\u0E2A\u0E48\u0E07",
643
+ "\u0E16\u0E49\u0E32",
644
+ "\u0E2B\u0E32\u0E01",
645
+ "\u0E44\u0E21\u0E48\u0E07\u0E31\u0E49\u0E19",
646
+ "\u0E44\u0E21\u0E48\u0E40\u0E0A\u0E48\u0E19\u0E19\u0E31\u0E49\u0E19",
647
+ "\u0E17\u0E33\u0E0B\u0E49\u0E33",
648
+ "\u0E23\u0E2D",
649
+ "\u0E43\u0E19\u0E02\u0E13\u0E30\u0E17\u0E35\u0E48"
650
+ ]);
651
+ var TL_KEYWORDS = /* @__PURE__ */ new Set([
652
+ "palitan",
653
+ "itoggle",
654
+ "idagdag",
655
+ "magdagdag",
656
+ "alisin",
657
+ "tanggalin",
658
+ "ipakita",
659
+ "magpakita",
660
+ "itago",
661
+ "magtago",
662
+ "itakda",
663
+ "magtakda",
664
+ "dagdagan",
665
+ "taasan",
666
+ "bawasan",
667
+ "ibaba",
668
+ "magpatugtog",
669
+ "ipadala",
670
+ "magpadala",
671
+ "kung",
672
+ "kapag",
673
+ "kung_hindi",
674
+ "kundi",
675
+ "ulitin",
676
+ "paulit-ulit",
677
+ "maghintay",
678
+ "hintay",
679
+ "habang"
680
+ ]);
681
+ var LANGUAGE_KEYWORDS = {
682
+ en: /* @__PURE__ */ new Set(),
683
+ // English is the default, no detection needed
684
+ ja: JAPANESE_KEYWORDS,
685
+ ko: KOREAN_KEYWORDS,
686
+ zh: CHINESE_KEYWORDS,
687
+ ar: ARABIC_KEYWORDS,
688
+ es: SPANISH_KEYWORDS,
689
+ pt: PORTUGUESE_KEYWORDS,
690
+ fr: FRENCH_KEYWORDS,
691
+ de: GERMAN_KEYWORDS,
692
+ it: ITALIAN_KEYWORDS,
693
+ vi: VIETNAMESE_KEYWORDS,
694
+ pl: POLISH_KEYWORDS,
695
+ ru: RUSSIAN_KEYWORDS,
696
+ uk: UKRAINIAN_KEYWORDS,
697
+ hi: HINDI_KEYWORDS,
698
+ bn: BENGALI_KEYWORDS,
699
+ th: THAI_KEYWORDS,
700
+ tr: TURKISH_KEYWORDS,
701
+ id: INDONESIAN_KEYWORDS,
702
+ sw: SWAHILI_KEYWORDS,
703
+ qu: QUECHUA_KEYWORDS,
704
+ tl: TL_KEYWORDS
705
+ };
706
+ function containsLanguageKeywords(script, language) {
707
+ const keywords = LANGUAGE_KEYWORDS[language];
708
+ if (!keywords || keywords.size === 0) return false;
709
+ const nonLatinLangs = ["ja", "ko", "zh", "ar", "ru", "uk", "hi", "bn", "th"];
710
+ if (nonLatinLangs.includes(language)) {
711
+ for (const keyword of keywords) {
712
+ if (script.includes(keyword)) {
713
+ return true;
714
+ }
715
+ }
716
+ return false;
717
+ }
718
+ const lowerScript = script.toLowerCase();
719
+ for (const keyword of keywords) {
720
+ if (keyword.length <= 2) continue;
721
+ const pattern = new RegExp(`\\b${escapeRegExp(keyword.toLowerCase())}\\b`);
722
+ if (pattern.test(lowerScript)) {
723
+ return true;
724
+ }
725
+ }
726
+ return false;
727
+ }
728
+ function escapeRegExp(str) {
729
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
730
+ }
731
+ function detectLanguages(script) {
732
+ const detected = /* @__PURE__ */ new Set();
733
+ for (const lang of SUPPORTED_LANGUAGES) {
734
+ if (lang === "en") continue;
735
+ if (containsLanguageKeywords(script, lang)) {
736
+ detected.add(lang);
737
+ }
738
+ }
739
+ return detected;
740
+ }
741
+ var customKeywordRegistry = /* @__PURE__ */ new Map();
742
+ function registerCustomKeywords(code, config) {
743
+ const existing = LANGUAGE_KEYWORDS[code];
744
+ const nonLatinLangs = ["ja", "ko", "zh", "ar", "ru", "uk", "hi", "bn", "th"];
745
+ const isNonLatin = config.isNonLatin ?? nonLatinLangs.includes(code);
746
+ if (config.extend && existing) {
747
+ const merged = /* @__PURE__ */ new Set([...existing, ...config.keywords]);
748
+ customKeywordRegistry.set(code, { keywords: merged, isNonLatin });
749
+ } else {
750
+ customKeywordRegistry.set(code, { keywords: config.keywords, isNonLatin });
751
+ }
752
+ }
753
+ function getKeywordsForLanguage(code) {
754
+ const custom = customKeywordRegistry.get(code);
755
+ if (custom) return custom.keywords;
756
+ return LANGUAGE_KEYWORDS[code];
757
+ }
758
+ function isNonLatinLanguage(code) {
759
+ const custom = customKeywordRegistry.get(code);
760
+ if (custom) return custom.isNonLatin;
761
+ const nonLatinLangs = ["ja", "ko", "zh", "ar", "ru", "uk", "hi", "bn", "th"];
762
+ return nonLatinLangs.includes(code);
763
+ }
764
+ function getAllLanguageCodes() {
765
+ const builtin = [...SUPPORTED_LANGUAGES];
766
+ const custom = [...customKeywordRegistry.keys()];
767
+ return [.../* @__PURE__ */ new Set([...builtin, ...custom])];
768
+ }
769
+ function clearCustomKeywords() {
770
+ customKeywordRegistry.clear();
771
+ }
772
+ function getOptimalRegion(languages) {
773
+ if (languages.size === 0) return null;
774
+ const langArray = [...languages];
775
+ if (langArray.every((l) => REGIONS.western.includes(l))) {
776
+ return "western";
777
+ }
778
+ if (langArray.every((l) => REGIONS["east-asian"].includes(l))) {
779
+ return "east-asian";
780
+ }
781
+ if (langArray.every((l) => REGIONS.slavic.includes(l))) {
782
+ return "slavic";
783
+ }
784
+ if (langArray.every((l) => REGIONS["south-asian"].includes(l))) {
785
+ return "south-asian";
786
+ }
787
+ if (langArray.every((l) => REGIONS.priority.includes(l))) {
788
+ return "priority";
789
+ }
790
+ return "all";
791
+ }
792
+
793
+ // src/scanner.ts
794
+ function toRegex(pattern, defaultPattern) {
795
+ if (!pattern) return defaultPattern;
796
+ if (pattern instanceof RegExp) return pattern;
797
+ if (Array.isArray(pattern)) {
798
+ const escaped = pattern.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
799
+ return new RegExp(`(${escaped.join("|")})`);
800
+ }
801
+ return defaultPattern;
802
+ }
803
+ var Scanner = class {
804
+ constructor(options) {
805
+ this.include = toRegex(
806
+ options.include,
807
+ /\.(html?|vue|svelte|jsx?|tsx?|astro|php|erb|ejs|hbs|handlebars)$/
808
+ );
809
+ this.exclude = toRegex(options.exclude, /node_modules|\.git/);
810
+ this.debug = options.debug ?? false;
811
+ }
812
+ /**
813
+ * Check if a file should be scanned
814
+ */
815
+ shouldScan(id) {
816
+ return this.include.test(id) && !this.exclude.test(id);
817
+ }
818
+ /**
819
+ * Scan code for hyperscript usage
820
+ */
821
+ scan(code, id) {
822
+ const usage = {
823
+ commands: /* @__PURE__ */ new Set(),
824
+ blocks: /* @__PURE__ */ new Set(),
825
+ positional: false,
826
+ detectedLanguages: /* @__PURE__ */ new Set()
827
+ };
828
+ const attrPatterns = [
829
+ /_\s*=\s*"([^"]+)"/g,
830
+ // _="..."
831
+ /_\s*=\s*'([^']+)'/g,
832
+ // _='...'
833
+ /_\s*=\s*`([^`]+)`/g,
834
+ // _=`...`
835
+ /_=\{`([^`]+)`\}/g,
836
+ // _={`...`} (JSX)
837
+ /_=\{['"]([^'"]+)['"]\}/g
838
+ // _={"..."} or _={'...'} (JSX)
839
+ ];
840
+ for (const pattern of attrPatterns) {
841
+ let match2;
842
+ while (match2 = pattern.exec(code)) {
843
+ this.analyzeScript(match2[1], usage);
844
+ }
845
+ }
846
+ const scriptPattern = /<script[^>]*type=["']?text\/hyperscript["']?[^>]*>([^<]+)<\/script>/gi;
847
+ let match;
848
+ while (match = scriptPattern.exec(code)) {
849
+ this.analyzeScript(match[1], usage);
850
+ }
851
+ if (this.debug && (usage.commands.size > 0 || usage.blocks.size > 0 || usage.detectedLanguages.size > 0)) {
852
+ console.log(`[hyperfixi] Scanned ${id}:`, {
853
+ commands: [...usage.commands],
854
+ blocks: [...usage.blocks],
855
+ positional: usage.positional,
856
+ languages: [...usage.detectedLanguages]
857
+ });
858
+ }
859
+ return usage;
860
+ }
861
+ /**
862
+ * Analyze a hyperscript snippet for commands, blocks, and expressions
863
+ */
864
+ analyzeScript(script, usage) {
865
+ const commandPattern = /\b(toggle|add|remove|removeClass|show|hide|set|get|put|append|take|increment|decrement|log|send|trigger|wait|transition|go|call|focus|blur|return)\b/g;
866
+ let match;
867
+ while (match = commandPattern.exec(script)) {
868
+ usage.commands.add(match[1]);
869
+ }
870
+ if (/\bif\b/.test(script)) usage.blocks.add("if");
871
+ if (/\bunless\b/.test(script)) usage.blocks.add("if");
872
+ if (/\brepeat\s+(\d+|:\w+|\$\w+|[\w.]+)\s+times?\b/i.test(script)) usage.blocks.add("repeat");
873
+ if (/\bfor\s+(each|every)\b/i.test(script)) usage.blocks.add("for");
874
+ if (/\bwhile\b/.test(script)) usage.blocks.add("while");
875
+ if (/\bfetch\b/.test(script)) usage.blocks.add("fetch");
876
+ if (/\b(first|last|next|previous|closest|parent)\b/.test(script)) {
877
+ usage.positional = true;
878
+ }
879
+ const languages = detectLanguages(script);
880
+ for (const lang of languages) {
881
+ usage.detectedLanguages.add(lang);
882
+ }
883
+ }
884
+ /**
885
+ * Scan all files in a project directory
886
+ * Used during production build to scan the entire codebase
887
+ */
888
+ async scanProject(dir) {
889
+ const results = /* @__PURE__ */ new Map();
890
+ try {
891
+ const { glob } = await import("glob");
892
+ const fs = await import("fs");
893
+ const files = await glob("**/*.{html,htm,vue,svelte,js,jsx,ts,tsx,astro,php,erb,ejs,hbs}", {
894
+ cwd: dir,
895
+ ignore: ["node_modules/**", "dist/**", ".git/**"],
896
+ absolute: true
897
+ });
898
+ for (const file of files) {
899
+ if (this.shouldScan(file)) {
900
+ try {
901
+ const code = fs.readFileSync(file, "utf-8");
902
+ const usage = this.scan(code, file);
903
+ if (usage.commands.size > 0 || usage.blocks.size > 0 || usage.positional || usage.detectedLanguages.size > 0) {
904
+ results.set(file, usage);
905
+ }
906
+ } catch {
907
+ }
908
+ }
909
+ }
910
+ } catch (error) {
911
+ console.warn("[hyperfixi] Error scanning project:", error);
912
+ }
913
+ return results;
914
+ }
915
+ };
916
+
917
+ // src/aggregator.ts
918
+ var Aggregator = class {
919
+ constructor() {
920
+ this.fileUsage = /* @__PURE__ */ new Map();
921
+ this.cachedUsage = null;
922
+ }
923
+ /**
924
+ * Add or update usage for a file
925
+ * @returns true if the overall usage changed
926
+ */
927
+ add(filePath, usage) {
928
+ const existing = this.fileUsage.get(filePath);
929
+ if (existing) {
930
+ const commandsEqual = this.setsEqual(existing.commands, usage.commands);
931
+ const blocksEqual = this.setsEqual(existing.blocks, usage.blocks);
932
+ const positionalEqual = existing.positional === usage.positional;
933
+ const languagesEqual = this.setsEqual(existing.detectedLanguages, usage.detectedLanguages);
934
+ if (commandsEqual && blocksEqual && positionalEqual && languagesEqual) {
935
+ return false;
936
+ }
937
+ }
938
+ this.fileUsage.set(filePath, usage);
939
+ this.cachedUsage = null;
940
+ return true;
941
+ }
942
+ /**
943
+ * Remove a file from tracking (e.g., when deleted)
944
+ * @returns true if the overall usage changed
945
+ */
946
+ remove(filePath) {
947
+ const existed = this.fileUsage.delete(filePath);
948
+ if (existed) {
949
+ this.cachedUsage = null;
950
+ }
951
+ return existed;
952
+ }
953
+ /**
954
+ * Get aggregated usage across all files
955
+ */
956
+ getUsage() {
957
+ if (this.cachedUsage) {
958
+ return this.cachedUsage;
959
+ }
960
+ const commands = /* @__PURE__ */ new Set();
961
+ const blocks = /* @__PURE__ */ new Set();
962
+ const detectedLanguages = /* @__PURE__ */ new Set();
963
+ let positional = false;
964
+ for (const usage of this.fileUsage.values()) {
965
+ for (const cmd of usage.commands) commands.add(cmd);
966
+ for (const block of usage.blocks) blocks.add(block);
967
+ for (const lang of usage.detectedLanguages) detectedLanguages.add(lang);
968
+ if (usage.positional) positional = true;
969
+ }
970
+ this.cachedUsage = {
971
+ commands,
972
+ blocks,
973
+ positional,
974
+ detectedLanguages,
975
+ fileUsage: new Map(this.fileUsage)
976
+ };
977
+ return this.cachedUsage;
978
+ }
979
+ /**
980
+ * Load usage from a project scan
981
+ */
982
+ loadFromScan(scannedFiles) {
983
+ this.fileUsage = new Map(scannedFiles);
984
+ this.cachedUsage = null;
985
+ }
986
+ /**
987
+ * Check if any hyperscript usage has been detected
988
+ */
989
+ hasUsage() {
990
+ const usage = this.getUsage();
991
+ return usage.commands.size > 0 || usage.blocks.size > 0 || usage.positional || usage.detectedLanguages.size > 0;
992
+ }
993
+ /**
994
+ * Get summary for logging
995
+ */
996
+ getSummary() {
997
+ const usage = this.getUsage();
998
+ return {
999
+ commands: [...usage.commands].sort(),
1000
+ blocks: [...usage.blocks].sort(),
1001
+ positional: usage.positional,
1002
+ languages: [...usage.detectedLanguages].sort(),
1003
+ fileCount: this.fileUsage.size
1004
+ };
1005
+ }
1006
+ /**
1007
+ * Clear all tracked usage
1008
+ */
1009
+ clear() {
1010
+ this.fileUsage.clear();
1011
+ this.cachedUsage = null;
1012
+ }
1013
+ /**
1014
+ * Compare two sets for equality
1015
+ */
1016
+ setsEqual(a, b) {
1017
+ if (a.size !== b.size) return false;
1018
+ for (const item of a) {
1019
+ if (!b.has(item)) return false;
1020
+ }
1021
+ return true;
1022
+ }
1023
+ };
1024
+
1025
+ // src/generator.ts
1026
+ import {
1027
+ COMMAND_IMPLEMENTATIONS as COMMAND_IMPL_TS,
1028
+ BLOCK_IMPLEMENTATIONS as BLOCK_IMPL_TS,
1029
+ STYLE_COMMANDS,
1030
+ ELEMENT_ARRAY_COMMANDS
1031
+ } from "@lokascript/core/bundle-generator";
1032
+
1033
+ // src/semantic-integration.ts
1034
+ var MULTILINGUAL_COMMAND_ALIASES = {
1035
+ ja: {
1036
+ \u30C8\u30B0\u30EB: "toggle",
1037
+ \u5207\u308A\u66FF\u3048: "toggle",
1038
+ \u8FFD\u52A0: "add",
1039
+ \u524A\u9664: "remove",
1040
+ \u8868\u793A: "show",
1041
+ \u96A0\u3059: "hide",
1042
+ \u975E\u8868\u793A: "hide",
1043
+ \u8A2D\u5B9A: "set",
1044
+ \u30BB\u30C3\u30C8: "set",
1045
+ \u5897\u52A0: "increment",
1046
+ \u6E1B\u5C11: "decrement",
1047
+ \u30ED\u30B0: "log",
1048
+ \u51FA\u529B: "log"
1049
+ },
1050
+ ko: {
1051
+ \uD1A0\uAE00: "toggle",
1052
+ \uC804\uD658: "toggle",
1053
+ \uCD94\uAC00: "add",
1054
+ \uC81C\uAC70: "remove",
1055
+ \uC0AD\uC81C: "remove",
1056
+ \uD45C\uC2DC: "show",
1057
+ \uC228\uAE30\uB2E4: "hide",
1058
+ \uC124\uC815: "set",
1059
+ \uC99D\uAC00: "increment",
1060
+ \uAC10\uC18C: "decrement",
1061
+ \uB85C\uADF8: "log"
1062
+ },
1063
+ zh: {
1064
+ \u5207\u6362: "toggle",
1065
+ \u6DFB\u52A0: "add",
1066
+ \u79FB\u9664: "remove",
1067
+ \u5220\u9664: "remove",
1068
+ \u663E\u793A: "show",
1069
+ \u9690\u85CF: "hide",
1070
+ \u8BBE\u7F6E: "set",
1071
+ \u8BBE\u5B9A: "set",
1072
+ \u589E\u52A0: "increment",
1073
+ \u51CF\u5C11: "decrement",
1074
+ \u65E5\u5FD7: "log",
1075
+ \u8BB0\u5F55: "log"
1076
+ },
1077
+ ar: {
1078
+ \u0628\u062F\u0651\u0644: "toggle",
1079
+ \u0628\u062F\u0644: "toggle",
1080
+ \u0623\u0636\u0641: "add",
1081
+ \u0627\u0636\u0641: "add",
1082
+ \u0623\u0632\u0644: "remove",
1083
+ \u0627\u0632\u0644: "remove",
1084
+ \u0627\u062D\u0630\u0641: "remove",
1085
+ \u0623\u0638\u0647\u0631: "show",
1086
+ \u0627\u0638\u0647\u0631: "show",
1087
+ \u0623\u062E\u0641\u0650: "hide",
1088
+ \u0627\u062E\u0641: "hide",
1089
+ \u0636\u0639: "set",
1090
+ \u0627\u0636\u0639: "set",
1091
+ \u0632\u0650\u062F: "increment",
1092
+ \u0623\u0646\u0642\u0635: "decrement"
1093
+ },
1094
+ es: {
1095
+ alternar: "toggle",
1096
+ a\u00F1adir: "add",
1097
+ agregar: "add",
1098
+ quitar: "remove",
1099
+ eliminar: "remove",
1100
+ mostrar: "show",
1101
+ ocultar: "hide",
1102
+ esconder: "hide",
1103
+ establecer: "set",
1104
+ fijar: "set",
1105
+ incrementar: "increment",
1106
+ decrementar: "decrement"
1107
+ },
1108
+ pt: {
1109
+ alternar: "toggle",
1110
+ adicionar: "add",
1111
+ remover: "remove",
1112
+ mostrar: "show",
1113
+ esconder: "hide",
1114
+ ocultar: "hide",
1115
+ definir: "set",
1116
+ incrementar: "increment",
1117
+ decrementar: "decrement"
1118
+ },
1119
+ fr: {
1120
+ basculer: "toggle",
1121
+ ajouter: "add",
1122
+ supprimer: "remove",
1123
+ retirer: "remove",
1124
+ afficher: "show",
1125
+ montrer: "show",
1126
+ cacher: "hide",
1127
+ masquer: "hide",
1128
+ d\u00E9finir: "set",
1129
+ incr\u00E9menter: "increment",
1130
+ d\u00E9cr\u00E9menter: "decrement"
1131
+ },
1132
+ de: {
1133
+ umschalten: "toggle",
1134
+ hinzuf\u00FCgen: "add",
1135
+ entfernen: "remove",
1136
+ l\u00F6schen: "remove",
1137
+ anzeigen: "show",
1138
+ zeigen: "show",
1139
+ verbergen: "hide",
1140
+ verstecken: "hide",
1141
+ setzen: "set",
1142
+ festlegen: "set",
1143
+ erh\u00F6hen: "increment",
1144
+ verringern: "decrement"
1145
+ },
1146
+ tr: {
1147
+ de\u011Fi\u015Ftir: "toggle",
1148
+ de\u011Fistir: "toggle",
1149
+ ekle: "add",
1150
+ kald\u0131r: "remove",
1151
+ kaldir: "remove",
1152
+ sil: "remove",
1153
+ g\u00F6ster: "show",
1154
+ gizle: "hide",
1155
+ sakla: "hide",
1156
+ ayarla: "set",
1157
+ belirle: "set",
1158
+ artt\u0131r: "increment",
1159
+ azalt: "decrement"
1160
+ },
1161
+ id: {
1162
+ alih: "toggle",
1163
+ beralih: "toggle",
1164
+ tambah: "add",
1165
+ hapus: "remove",
1166
+ buang: "remove",
1167
+ tampilkan: "show",
1168
+ sembunyikan: "hide",
1169
+ atur: "set",
1170
+ tetapkan: "set",
1171
+ tambahkan: "increment",
1172
+ kurangi: "decrement"
1173
+ },
1174
+ sw: {
1175
+ badilisha: "toggle",
1176
+ ongeza: "add",
1177
+ ondoa: "remove",
1178
+ futa: "remove",
1179
+ onyesha: "show",
1180
+ ficha: "hide",
1181
+ weka: "set",
1182
+ sanidi: "set",
1183
+ ongezea: "increment",
1184
+ punguza: "decrement"
1185
+ },
1186
+ qu: {
1187
+ tikray: "toggle",
1188
+ yapay: "add",
1189
+ qichuy: "remove",
1190
+ pichay: "remove",
1191
+ rikuchiy: "show",
1192
+ pakay: "hide",
1193
+ churay: "set",
1194
+ pisiyachiy: "decrement"
1195
+ }
1196
+ };
1197
+ function getMultilingualCommandAliases(languages) {
1198
+ const aliases = {};
1199
+ for (const lang of languages) {
1200
+ const langAliases = MULTILINGUAL_COMMAND_ALIASES[lang];
1201
+ if (langAliases) {
1202
+ Object.assign(aliases, langAliases);
1203
+ }
1204
+ }
1205
+ return aliases;
1206
+ }
1207
+ function generateMultilingualAliases(languages) {
1208
+ const aliases = {};
1209
+ for (const lang of languages) {
1210
+ const langAliases = MULTILINGUAL_COMMAND_ALIASES[lang];
1211
+ if (langAliases) {
1212
+ Object.assign(aliases, langAliases);
1213
+ }
1214
+ }
1215
+ if (Object.keys(aliases).length === 0) {
1216
+ return `
1217
+ // No multilingual aliases needed - just pass through
1218
+ function preprocessMultilingual(code) { return code; }
1219
+ `;
1220
+ }
1221
+ const aliasEntries = Object.entries(aliases).map(([key, val]) => ` '${key}': '${val}'`).join(",\n");
1222
+ const escapedKeys = Object.keys(aliases).map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
1223
+ return `
1224
+ // Multilingual command aliases for HybridParser fallback
1225
+ const MULTILINGUAL_ALIASES = {
1226
+ ${aliasEntries}
1227
+ };
1228
+
1229
+ // Register multilingual aliases with the parser
1230
+ addCommandAliases(MULTILINGUAL_ALIASES);
1231
+
1232
+ // Preprocessing regex to translate multilingual keywords to English
1233
+ // The HybridParser tokenizer only accepts ASCII identifiers, so we need
1234
+ // to translate non-ASCII keywords before parsing.
1235
+ const MULTILINGUAL_KEYWORD_REGEX = new RegExp('(^|\\\\s)(${escapedKeys})(?=\\\\s|\\\\.|$)', 'g');
1236
+
1237
+ /**
1238
+ * Preprocess multilingual code to replace non-ASCII keywords with English equivalents.
1239
+ * This is needed because HybridParser's tokenizer only accepts ASCII identifiers.
1240
+ */
1241
+ function preprocessMultilingual(code) {
1242
+ return code.replace(MULTILINGUAL_KEYWORD_REGEX, (match, prefix, keyword) => {
1243
+ const english = MULTILINGUAL_ALIASES[keyword];
1244
+ return english ? prefix + english : match;
1245
+ });
1246
+ }
1247
+ `;
1248
+ }
1249
+ function resolveSemanticConfig(options, detectedLanguages) {
1250
+ const grammarEnabled = options.grammar ?? false;
1251
+ let semanticEnabled = grammarEnabled;
1252
+ if (options.semantic === true || options.semantic === "auto") {
1253
+ semanticEnabled = true;
1254
+ } else if (options.semantic === "en") {
1255
+ semanticEnabled = true;
1256
+ } else if (options.semantic === false) {
1257
+ semanticEnabled = false;
1258
+ }
1259
+ if (!semanticEnabled) {
1260
+ return {
1261
+ enabled: false,
1262
+ bundleType: null,
1263
+ languages: /* @__PURE__ */ new Set(),
1264
+ grammarEnabled: false
1265
+ };
1266
+ }
1267
+ const languages = /* @__PURE__ */ new Set();
1268
+ for (const lang of detectedLanguages) {
1269
+ languages.add(lang);
1270
+ }
1271
+ if (options.languages) {
1272
+ for (const lang of options.languages) {
1273
+ languages.add(lang);
1274
+ }
1275
+ }
1276
+ if (options.extraLanguages) {
1277
+ for (const lang of options.extraLanguages) {
1278
+ languages.add(lang);
1279
+ }
1280
+ }
1281
+ let bundleType = selectBundleType(options, languages);
1282
+ return {
1283
+ enabled: true,
1284
+ bundleType,
1285
+ languages,
1286
+ grammarEnabled
1287
+ };
1288
+ }
1289
+ function selectBundleType(options, languages) {
1290
+ if (options.region) {
1291
+ return options.region;
1292
+ }
1293
+ if (options.semantic === "en") {
1294
+ return "en";
1295
+ }
1296
+ if (options.languages?.length) {
1297
+ return selectOptimalBundle(new Set(options.languages));
1298
+ }
1299
+ if (languages.size === 0) {
1300
+ return "en";
1301
+ }
1302
+ return selectOptimalBundle(languages);
1303
+ }
1304
+ var SINGLE_LANGUAGE_BUNDLES = [
1305
+ "en",
1306
+ "es",
1307
+ "ja",
1308
+ "ar",
1309
+ "ko",
1310
+ "zh",
1311
+ "tr",
1312
+ "pt",
1313
+ "fr",
1314
+ "de",
1315
+ "id",
1316
+ "qu",
1317
+ "sw"
1318
+ ];
1319
+ function selectOptimalBundle(languages) {
1320
+ if (languages.size === 0) {
1321
+ return "en";
1322
+ }
1323
+ const langArray = [...languages];
1324
+ if (langArray.length === 1) {
1325
+ const lang = langArray[0];
1326
+ if (SINGLE_LANGUAGE_BUNDLES.includes(lang)) {
1327
+ return lang;
1328
+ }
1329
+ }
1330
+ if (langArray.length === 2 && langArray.includes("en") && langArray.includes("es")) {
1331
+ return "es-en";
1332
+ }
1333
+ if (langArray.every((l) => REGIONS.western.includes(l))) {
1334
+ return "western";
1335
+ }
1336
+ if (langArray.every((l) => REGIONS["east-asian"].includes(l))) {
1337
+ return "east-asian";
1338
+ }
1339
+ if (langArray.every((l) => REGIONS.priority.includes(l))) {
1340
+ return "priority";
1341
+ }
1342
+ return "all";
1343
+ }
1344
+ var SEMANTIC_BUNDLE_SIZES = {
1345
+ // Single-language bundles (all 13 languages)
1346
+ en: { raw: "82 KB", gzip: "~20 KB" },
1347
+ es: { raw: "64 KB", gzip: "~16 KB" },
1348
+ ja: { raw: "67 KB", gzip: "~17 KB" },
1349
+ ar: { raw: "66 KB", gzip: "~17 KB" },
1350
+ ko: { raw: "69 KB", gzip: "~18 KB" },
1351
+ zh: { raw: "58 KB", gzip: "~15 KB" },
1352
+ tr: { raw: "73 KB", gzip: "~18 KB" },
1353
+ pt: { raw: "56 KB", gzip: "~14 KB" },
1354
+ fr: { raw: "57 KB", gzip: "~14 KB" },
1355
+ de: { raw: "57 KB", gzip: "~14 KB" },
1356
+ id: { raw: "57 KB", gzip: "~14 KB" },
1357
+ qu: { raw: "56 KB", gzip: "~14 KB" },
1358
+ sw: { raw: "56 KB", gzip: "~14 KB" },
1359
+ // Regional bundles
1360
+ "es-en": { raw: "99 KB", gzip: "~25 KB" },
1361
+ western: { raw: "127 KB", gzip: "~30 KB" },
1362
+ "east-asian": { raw: "99 KB", gzip: "~24 KB" },
1363
+ priority: { raw: "231 KB", gzip: "~48 KB" },
1364
+ all: { raw: "324 KB", gzip: "~61 KB" }
1365
+ };
1366
+ function getSemanticBundleSize(bundleType) {
1367
+ return SEMANTIC_BUNDLE_SIZES[bundleType] ?? SEMANTIC_BUNDLE_SIZES.all;
1368
+ }
1369
+ function getSemanticBundleImport(_bundleType) {
1370
+ return "@lokascript/semantic";
1371
+ }
1372
+ function generateSemanticIntegrationCode(config) {
1373
+ if (!config.enabled || !config.bundleType) {
1374
+ return "";
1375
+ }
1376
+ const bundleImport = getSemanticBundleImport(config.bundleType);
1377
+ const languages = [...config.languages].join("', '");
1378
+ let code = `
1379
+ // =============================================================================
1380
+ // SEMANTIC PARSER INTEGRATION
1381
+ // =============================================================================
1382
+
1383
+ import {
1384
+ createSemanticAnalyzer,
1385
+ buildAST,
1386
+ isLanguageSupported,
1387
+ } from '${bundleImport}';
1388
+ `;
1389
+ if (config.grammarEnabled) {
1390
+ code += `
1391
+ import { GrammarTransformer, translate } from '@lokascript/i18n';
1392
+
1393
+ const grammarTransformer = new GrammarTransformer();
1394
+ `;
1395
+ }
1396
+ const aliasesCode = generateMultilingualAliases(config.languages);
1397
+ code += `
1398
+ const semanticAnalyzer = createSemanticAnalyzer();
1399
+ const SUPPORTED_SEMANTIC_LANGUAGES = ['${languages}', 'en'];
1400
+ const SEMANTIC_CONFIDENCE_THRESHOLD = 0.7;
1401
+
1402
+ ${aliasesCode}
1403
+
1404
+ /**
1405
+ * Parse hyperscript using semantic parser with auto-language detection.
1406
+ * Tries each supported language until one returns a high-confidence result.
1407
+ * Falls back to HybridParser if none match.
1408
+ *
1409
+ * @param code - The hyperscript code to parse
1410
+ * @param lang - Optional language hint. If provided, tries this language first.
1411
+ */
1412
+ function parseWithSemantic(code, lang = null) {
1413
+ // Determine languages to try: specified lang first, then others
1414
+ let languagesToTry = [...SUPPORTED_SEMANTIC_LANGUAGES];
1415
+ if (lang && !languagesToTry.includes(lang)) {
1416
+ languagesToTry.unshift(lang);
1417
+ } else if (lang) {
1418
+ // Move specified lang to front
1419
+ languagesToTry = [lang, ...languagesToTry.filter(l => l !== lang)];
1420
+ }
1421
+
1422
+ // Try each language until one succeeds
1423
+ for (const tryLang of languagesToTry) {
1424
+ if (!isLanguageSupported(tryLang)) continue;
1425
+ try {
1426
+ const result = semanticAnalyzer.analyze(code, tryLang);
1427
+ if (result && result.confidence >= SEMANTIC_CONFIDENCE_THRESHOLD) {
1428
+ // buildAST returns {ast, warnings} - extract the ast
1429
+ const buildResult = buildAST(result.node);
1430
+ const ast = buildResult.ast;
1431
+
1432
+ // Semantic parser doesn't fully handle event handlers - fallback to HybridParser
1433
+ // Event handlers like "on click toggle .active" produce incomplete AST
1434
+ if (ast && ast.type === 'command' && ast.name === 'on') {
1435
+ break; // Fallback to HybridParser
1436
+ }
1437
+
1438
+ return ast;
1439
+ }
1440
+ } catch (e) {
1441
+ // Continue trying other languages
1442
+ }
1443
+ }
1444
+
1445
+ // Fallback to HybridParser for event handlers and unrecognized patterns
1446
+ // Preprocess to translate non-ASCII keywords to English (tokenizer only accepts ASCII)
1447
+ const preprocessedCode = preprocessMultilingual(code);
1448
+ return new HybridParser(preprocessedCode).parse();
1449
+ }
1450
+ `;
1451
+ if (config.grammarEnabled) {
1452
+ code += `
1453
+ /**
1454
+ * Translate hyperscript between languages.
1455
+ */
1456
+ function translateHyperscript(code, fromLang, toLang) {
1457
+ return translate(code, fromLang, toLang);
1458
+ }
1459
+ `;
1460
+ }
1461
+ return code;
1462
+ }
1463
+ function getSemanticExports(config) {
1464
+ const exports = [];
1465
+ if (config.enabled) {
1466
+ exports.push("parseWithSemantic");
1467
+ exports.push("SUPPORTED_SEMANTIC_LANGUAGES");
1468
+ }
1469
+ if (config.grammarEnabled) {
1470
+ exports.push("translateHyperscript");
1471
+ exports.push("grammarTransformer");
1472
+ }
1473
+ return exports;
1474
+ }
1475
+
1476
+ // src/generator.ts
1477
+ function stripTypes(code) {
1478
+ return code.replace(/\s+as\s+\w+(?:\[\])?/g, "").replace(/\((\w+):\s*\w+\)/g, "($1)").replace(/\((\w+):\s*any\)/g, "($1)").replace(/Promise<void>\[\]/g, "Promise[]").replace(/Promise<void>/g, "Promise").replace(/:\s*TransitionEvent/g, "");
1479
+ }
1480
+ var COMMAND_IMPLEMENTATIONS = {};
1481
+ var BLOCK_IMPLEMENTATIONS = {};
1482
+ for (const [name, code] of Object.entries(COMMAND_IMPL_TS)) {
1483
+ COMMAND_IMPLEMENTATIONS[name] = stripTypes(code);
1484
+ }
1485
+ for (const [name, code] of Object.entries(BLOCK_IMPL_TS)) {
1486
+ BLOCK_IMPLEMENTATIONS[name] = stripTypes(code);
1487
+ }
1488
+ function generateBundleCode(config) {
1489
+ const {
1490
+ name,
1491
+ commands,
1492
+ blocks = [],
1493
+ htmxIntegration = false,
1494
+ globalName = "hyperfixi",
1495
+ positionalExpressions = false,
1496
+ parserImportPath = "../parser/hybrid",
1497
+ autoInit = true,
1498
+ esModule = true
1499
+ } = config;
1500
+ const needsStyleHelpers = commands.some((cmd) => STYLE_COMMANDS.includes(cmd));
1501
+ const needsElementArrayHelper = commands.some((cmd) => ELEMENT_ARRAY_COMMANDS.includes(cmd));
1502
+ const hasBlocks = blocks.length > 0;
1503
+ const hasReturn = commands.includes("return");
1504
+ const commandCases = commands.filter((cmd) => COMMAND_IMPLEMENTATIONS[cmd]).map((cmd) => COMMAND_IMPLEMENTATIONS[cmd]).join("\n");
1505
+ const blockCases = blocks.filter((block) => BLOCK_IMPLEMENTATIONS[block]).map((block) => BLOCK_IMPLEMENTATIONS[block]).join("\n");
1506
+ return `/**
1507
+ * HyperFixi ${name} Bundle (Auto-Generated)
1508
+ *
1509
+ * Generated by: @lokascript/vite-plugin
1510
+ * Commands: ${commands.join(", ")}${blocks.length > 0 ? `
1511
+ * Blocks: ${blocks.join(", ")}` : ""}${positionalExpressions ? "\n * Positional expressions: enabled" : ""}
1512
+ *
1513
+ * DO NOT EDIT - This file is automatically regenerated.
1514
+ */
1515
+
1516
+ // Parser imports
1517
+ import { HybridParser, addCommandAliases } from '${parserImportPath}';
1518
+
1519
+ // Runtime state
1520
+ const globalVars = new Map();
1521
+ ${hasBlocks ? "const MAX_LOOP_ITERATIONS = 1000;" : ""}
1522
+
1523
+ async function evaluate(node, ctx) {
1524
+ switch (node.type) {
1525
+ case 'literal': return node.value;
1526
+
1527
+ case 'identifier':
1528
+ if (node.value === 'me' || node.value === 'my') return ctx.me;
1529
+ if (node.value === 'it') return ctx.it;
1530
+ if (node.value === 'you') return ctx.you;
1531
+ if (node.value === 'event') return ctx.event;
1532
+ if (node.value === 'body') return document.body;
1533
+ if (node.value === 'document') return document;
1534
+ if (node.value === 'window') return window;
1535
+ if (ctx.locals.has(node.value)) return ctx.locals.get(node.value);
1536
+ if (node.value in ctx.me) return ctx.me[node.value];
1537
+ return node.value;
1538
+
1539
+ case 'contextReference':
1540
+ // Semantic AST format for context references (me, you, it, etc.)
1541
+ switch (node.contextType || node.name) {
1542
+ case 'me': return ctx.me;
1543
+ case 'it': return ctx.it;
1544
+ case 'you': return ctx.you;
1545
+ case 'event': return ctx.event;
1546
+ case 'body': return document.body;
1547
+ case 'document': return document;
1548
+ case 'window': return window;
1549
+ default: return ctx.me;
1550
+ }
1551
+
1552
+ case 'variable':
1553
+ if (node.scope === 'local') return ctx.locals.get(node.name.slice(1));
1554
+ const gName = node.name.slice(1);
1555
+ if (globalVars.has(gName)) return globalVars.get(gName);
1556
+ return window[node.name];
1557
+
1558
+ case 'selector':
1559
+ const elements = document.querySelectorAll(node.value);
1560
+ return elements.length === 1 ? elements[0] : Array.from(elements);
1561
+
1562
+ case 'binary':
1563
+ return evaluateBinary(node, ctx);
1564
+
1565
+ case 'possessive':
1566
+ case 'member':
1567
+ const obj = await evaluate(node.object, ctx);
1568
+ if (obj == null) return undefined;
1569
+ const prop = node.computed ? await evaluate(node.property, ctx) : node.property;
1570
+ return obj[prop];
1571
+
1572
+ case 'call': {
1573
+ let callContext = null;
1574
+ let callee;
1575
+
1576
+ if (node.callee.type === 'member' || node.callee.type === 'possessive') {
1577
+ callContext = await evaluate(node.callee.object, ctx);
1578
+ const p = node.callee.computed
1579
+ ? await evaluate(node.callee.property, ctx)
1580
+ : node.callee.property;
1581
+ callee = callContext?.[p];
1582
+ } else {
1583
+ callee = await evaluate(node.callee, ctx);
1584
+ }
1585
+
1586
+ const args = await Promise.all(node.args.map(a => evaluate(a, ctx)));
1587
+ if (typeof callee === 'function') return callee.apply(callContext, args);
1588
+ return undefined;
1589
+ }
1590
+ ${positionalExpressions ? `
1591
+ case 'positional':
1592
+ return evaluatePositional(node, ctx);
1593
+ ` : ""}
1594
+ default: return undefined;
1595
+ }
1596
+ }
1597
+
1598
+ async function evaluateBinary(node, ctx) {
1599
+ if (node.operator === 'has') {
1600
+ const left = await evaluate(node.left, ctx);
1601
+ if (left instanceof Element && node.right.type === 'selector' && node.right.value.startsWith('.')) {
1602
+ return left.classList.contains(node.right.value.slice(1));
1603
+ }
1604
+ return false;
1605
+ }
1606
+
1607
+ const left = await evaluate(node.left, ctx);
1608
+ const right = await evaluate(node.right, ctx);
1609
+
1610
+ switch (node.operator) {
1611
+ case '+': return left + right;
1612
+ case '-': return left - right;
1613
+ case '*': return left * right;
1614
+ case '/': return left / right;
1615
+ case '%': return left % right;
1616
+ case '==': case 'is': return left == right;
1617
+ case '!=': case 'is not': return left != right;
1618
+ case '<': return left < right;
1619
+ case '>': return left > right;
1620
+ case '<=': return left <= right;
1621
+ case '>=': return left >= right;
1622
+ case 'and': case '&&': return left && right;
1623
+ case 'or': case '||': return left || right;
1624
+ case 'contains': case 'includes':
1625
+ if (typeof left === 'string') return left.includes(right);
1626
+ if (Array.isArray(left)) return left.includes(right);
1627
+ if (left instanceof Element) return left.contains(right);
1628
+ return false;
1629
+ case 'matches':
1630
+ if (left instanceof Element) return left.matches(right);
1631
+ if (typeof left === 'string') return new RegExp(right).test(left);
1632
+ return false;
1633
+ default: return undefined;
1634
+ }
1635
+ }
1636
+ ${positionalExpressions ? `
1637
+ function evaluatePositional(node, ctx) {
1638
+ const target = node.target;
1639
+ let elements = [];
1640
+
1641
+ let selector = null;
1642
+ if (target.type === 'selector') {
1643
+ selector = target.value;
1644
+ } else if (target.type === 'identifier') {
1645
+ selector = target.value;
1646
+ } else if (target.type === 'htmlSelector') {
1647
+ selector = target.value;
1648
+ }
1649
+ if (selector) {
1650
+ elements = Array.from(document.querySelectorAll(selector));
1651
+ }
1652
+
1653
+ switch (node.position) {
1654
+ case 'first': return elements[0] || null;
1655
+ case 'last': return elements[elements.length - 1] || null;
1656
+ case 'next': return ctx.me.nextElementSibling;
1657
+ case 'previous': return ctx.me.previousElementSibling;
1658
+ case 'closest': return target.value ? ctx.me.closest(target.value) : null;
1659
+ case 'parent': return ctx.me.parentElement;
1660
+ default: return elements[0] || null;
1661
+ }
1662
+ }
1663
+ ` : ""}
1664
+ ${needsStyleHelpers ? `
1665
+ const isStyleProp = (prop) => prop?.startsWith('*');
1666
+ const getStyleName = (prop) => prop.substring(1);
1667
+ const setStyleProp = (el, prop, value) => {
1668
+ if (!isStyleProp(prop)) return false;
1669
+ el.style.setProperty(getStyleName(prop), String(value));
1670
+ return true;
1671
+ };
1672
+ ` : ""}
1673
+
1674
+ ${needsElementArrayHelper ? `
1675
+ const toElementArray = (val) => {
1676
+ if (Array.isArray(val)) return val.filter(e => e instanceof Element);
1677
+ if (val instanceof Element) return [val];
1678
+ if (typeof val === 'string') return Array.from(document.querySelectorAll(val));
1679
+ return [];
1680
+ };
1681
+ ` : ""}
1682
+
1683
+ async function executeCommand(cmd, ctx) {
1684
+ const getTarget = async () => {
1685
+ // Support both HybridParser (cmd.target) and semantic AST (cmd.modifiers.on) formats
1686
+ const target = cmd.target || cmd.modifiers?.on;
1687
+ if (!target) return [ctx.me];
1688
+ const t = await evaluate(target, ctx);
1689
+ if (Array.isArray(t)) return t;
1690
+ if (t instanceof Element) return [t];
1691
+ if (typeof t === 'string') return Array.from(document.querySelectorAll(t));
1692
+ return [ctx.me];
1693
+ };
1694
+
1695
+ const getClassName = (node) => {
1696
+ if (!node) return '';
1697
+ if (node.type === 'selector') return node.value.slice(1);
1698
+ if (node.type === 'string' || node.type === 'literal') {
1699
+ const val = node.value;
1700
+ return typeof val === 'string' && val.startsWith('.') ? val.slice(1) : String(val);
1701
+ }
1702
+ if (node.type === 'identifier') return node.value;
1703
+ return '';
1704
+ };
1705
+
1706
+ switch (cmd.name) {
1707
+ ${commandCases}
1708
+
1709
+ default:
1710
+ console.warn(\`${name} bundle: Unknown command '\${cmd.name}'\`);
1711
+ return null;
1712
+ }
1713
+ }
1714
+ ${hasBlocks ? `
1715
+ async function executeBlock(block, ctx) {
1716
+ switch (block.type) {
1717
+ ${blockCases}
1718
+
1719
+ default:
1720
+ console.warn(\`${name} bundle: Unknown block '\${block.type}'\`);
1721
+ return null;
1722
+ }
1723
+ }
1724
+ ` : ""}
1725
+ async function executeSequence(nodes, ctx) {
1726
+ let result;
1727
+ for (const node of nodes) {
1728
+ if (node.type === 'command') {
1729
+ result = await executeCommand(node, ctx);
1730
+ }${hasBlocks ? ` else if (['if', 'repeat', 'for', 'while', 'fetch'].includes(node.type)) {
1731
+ result = await executeBlock(node, ctx);
1732
+ }` : ""}
1733
+ }
1734
+ return result;
1735
+ }
1736
+ ${hasBlocks ? `
1737
+ async function executeSequenceWithBlocks(nodes, ctx) {
1738
+ try {
1739
+ return await executeSequence(nodes, ctx);
1740
+ } catch (e) {
1741
+ if (e?.type === 'return') throw e;
1742
+ throw e;
1743
+ }
1744
+ }
1745
+ ` : ""}
1746
+ async function executeAST(ast, me, event) {
1747
+ const ctx = { me, event, locals: new Map() };
1748
+
1749
+ if (ast.type === 'sequence') {
1750
+ ${hasReturn || hasBlocks ? "try { return await executeSequence(ast.commands, ctx); } catch (e) { if (e?.type === 'return') return e.value; throw e; }" : "return executeSequence(ast.commands, ctx);"}
1751
+ }
1752
+
1753
+ if (ast.type === 'event') {
1754
+ const eventNode = ast;
1755
+ const eventName = eventNode.event;
1756
+
1757
+ if (eventName === 'init') {
1758
+ ${hasReturn || hasBlocks ? "try { await executeSequence(eventNode.body, ctx); } catch (e) { if (e?.type !== 'return') throw e; }" : "await executeSequence(eventNode.body, ctx);"}
1759
+ return;
1760
+ }
1761
+
1762
+ const target = eventNode.filter ? await evaluate(eventNode.filter, ctx) : me;
1763
+ const targetEl = target instanceof Element ? target : me;
1764
+ const mods = eventNode.modifiers;
1765
+
1766
+ let handler = async (e) => {
1767
+ if (mods.prevent) e.preventDefault();
1768
+ if (mods.stop) e.stopPropagation();
1769
+
1770
+ const handlerCtx = {
1771
+ me, event: e,
1772
+ you: e.target instanceof Element ? e.target : undefined,
1773
+ locals: new Map(),
1774
+ };
1775
+ ${hasReturn || hasBlocks ? "try { await executeSequence(eventNode.body, handlerCtx); } catch (err) { if (err?.type !== 'return') throw err; }" : "await executeSequence(eventNode.body, handlerCtx);"}
1776
+ };
1777
+
1778
+ if (mods.debounce) {
1779
+ let timeout;
1780
+ const orig = handler;
1781
+ handler = async (e) => {
1782
+ clearTimeout(timeout);
1783
+ timeout = setTimeout(() => orig(e), mods.debounce);
1784
+ };
1785
+ }
1786
+
1787
+ if (mods.throttle) {
1788
+ let lastCall = 0;
1789
+ const orig = handler;
1790
+ handler = async (e) => {
1791
+ const now = Date.now();
1792
+ if (now - lastCall >= mods.throttle) {
1793
+ lastCall = now;
1794
+ await orig(e);
1795
+ }
1796
+ };
1797
+ }
1798
+
1799
+ targetEl.addEventListener(eventName, handler, { once: !!mods.once });
1800
+ return;
1801
+ }
1802
+
1803
+ // Handle single command (not wrapped in event or sequence)
1804
+ if (ast.type === 'command') {
1805
+ return executeCommand(ast, ctx);
1806
+ }
1807
+
1808
+ return null;
1809
+ }
1810
+
1811
+ function processElement(el) {
1812
+ const code = el.getAttribute('_');
1813
+ if (!code) return;
1814
+
1815
+ try {
1816
+ const parser = new HybridParser(code);
1817
+ const ast = parser.parse();
1818
+ executeAST(ast, el);
1819
+ } catch (err) {
1820
+ console.error('HyperFixi ${name} error:', err, 'Code:', code);
1821
+ }
1822
+ }
1823
+
1824
+ function processElements(root = document) {
1825
+ const elements = root.querySelectorAll('[_]');
1826
+ elements.forEach(processElement);
1827
+ }
1828
+
1829
+ const api = {
1830
+ version: '1.0.0-${name.toLowerCase().replace(/\s+/g, "-")}',
1831
+
1832
+ parse(code) {
1833
+ const parser = new HybridParser(code);
1834
+ return parser.parse();
1835
+ },
1836
+
1837
+ async execute(code, element) {
1838
+ const me = element || document.body;
1839
+ const parser = new HybridParser(code);
1840
+ const ast = parser.parse();
1841
+ return executeAST(ast, me);
1842
+ },
1843
+
1844
+ run: async (code, element) => api.execute(code, element),
1845
+ eval: async (code, element) => api.execute(code, element),
1846
+
1847
+ init: processElements,
1848
+ process: processElements,
1849
+
1850
+ commands: ${JSON.stringify(commands)},
1851
+ ${blocks.length > 0 ? `blocks: ${JSON.stringify(blocks)},` : ""}
1852
+ parserName: 'hybrid',
1853
+ };
1854
+ ${autoInit ? `
1855
+ if (typeof window !== 'undefined') {
1856
+ window.${globalName} = api;
1857
+ window._hyperscript = api;
1858
+
1859
+ if (document.readyState === 'loading') {
1860
+ document.addEventListener('DOMContentLoaded', () => processElements());
1861
+ } else {
1862
+ processElements();
1863
+ }
1864
+ ${htmxIntegration ? `
1865
+ document.addEventListener('htmx:afterSettle', (e) => {
1866
+ const target = e.detail?.target;
1867
+ if (target) processElements(target);
1868
+ });
1869
+ ` : ""}
1870
+ }
1871
+ ` : ""}
1872
+ ${esModule ? `
1873
+ export default api;
1874
+ export { api, processElements };
1875
+ ` : ""}`;
1876
+ }
1877
+ var Generator = class {
1878
+ constructor(options) {
1879
+ this.debug = options.debug ?? false;
1880
+ }
1881
+ /**
1882
+ * Generate bundle code from aggregated usage
1883
+ */
1884
+ generate(usage, options) {
1885
+ const commands = [...usage.commands, ...options.extraCommands ?? []];
1886
+ const blocks = [...usage.blocks, ...options.extraBlocks ?? []];
1887
+ const positional = usage.positional || options.positional || false;
1888
+ const semanticConfig = resolveSemanticConfig(options, usage.detectedLanguages);
1889
+ if (commands.length === 0 && blocks.length === 0 && !positional && !semanticConfig.enabled) {
1890
+ return this.generateEmptyBundle(options);
1891
+ }
1892
+ const config = {
1893
+ name: options.bundleName ?? "ViteAutoGenerated",
1894
+ commands,
1895
+ blocks,
1896
+ positionalExpressions: positional,
1897
+ htmxIntegration: options.htmx ?? false,
1898
+ globalName: options.globalName ?? "hyperfixi",
1899
+ // Use @lokascript/core package path for virtual module
1900
+ parserImportPath: "@lokascript/core/parser/hybrid",
1901
+ autoInit: true,
1902
+ esModule: true
1903
+ };
1904
+ if (this.debug) {
1905
+ const bundleInfo = {
1906
+ commands,
1907
+ blocks,
1908
+ positional,
1909
+ htmx: config.htmxIntegration,
1910
+ semantic: semanticConfig.enabled
1911
+ };
1912
+ if (semanticConfig.enabled && semanticConfig.bundleType) {
1913
+ const sizeInfo = getSemanticBundleSize(semanticConfig.bundleType);
1914
+ bundleInfo.semanticBundle = semanticConfig.bundleType;
1915
+ bundleInfo.semanticSize = sizeInfo.gzip;
1916
+ bundleInfo.languages = [...semanticConfig.languages];
1917
+ bundleInfo.grammar = semanticConfig.grammarEnabled;
1918
+ }
1919
+ console.log("[hyperfixi] Generating bundle:", bundleInfo);
1920
+ if (semanticConfig.bundleType === "all" || semanticConfig.bundleType === "priority") {
1921
+ console.log(
1922
+ `[hyperfixi] Note: Using '${semanticConfig.bundleType}' semantic bundle (${getSemanticBundleSize(semanticConfig.bundleType).gzip}). Consider using 'region' option to select a smaller regional bundle if all languages aren't needed.`
1923
+ );
1924
+ }
1925
+ }
1926
+ let bundleCode = generateBundleCode(config);
1927
+ if (semanticConfig.enabled) {
1928
+ bundleCode = this.addSemanticIntegration(bundleCode, semanticConfig);
1929
+ }
1930
+ return bundleCode;
1931
+ }
1932
+ /**
1933
+ * Add semantic integration code to the bundle
1934
+ */
1935
+ addSemanticIntegration(bundleCode, config) {
1936
+ const semanticCode = generateSemanticIntegrationCode(config);
1937
+ const semanticExports = getSemanticExports(config);
1938
+ const parserImportEnd = bundleCode.indexOf("// Runtime state");
1939
+ if (parserImportEnd === -1) {
1940
+ bundleCode = semanticCode + "\n" + bundleCode;
1941
+ } else {
1942
+ bundleCode = bundleCode.slice(0, parserImportEnd) + semanticCode + "\n\n" + bundleCode.slice(parserImportEnd);
1943
+ }
1944
+ bundleCode = bundleCode.replace(
1945
+ /function processElement\(el\) \{\s*const code = el\.getAttribute\('_'\);\s*if \(!code\) return;\s*try \{\s*const parser = new HybridParser\(code\);\s*const ast = parser\.parse\(\);/g,
1946
+ `function processElement(el) {
1947
+ const code = el.getAttribute('_');
1948
+ if (!code) return;
1949
+
1950
+ try {
1951
+ const ast = parseWithSemantic(code);`
1952
+ );
1953
+ bundleCode = bundleCode.replace(
1954
+ /parse\(code\) \{\s*const parser = new HybridParser\(code\);\s*return parser\.parse\(\);/g,
1955
+ `parse(code, lang = null) {
1956
+ return parseWithSemantic(code, lang);`
1957
+ );
1958
+ bundleCode = bundleCode.replace(
1959
+ /async execute\(code, element\) \{\s*const me = element \|\| document\.body;\s*const parser = new HybridParser\(code\);\s*const ast = parser\.parse\(\);/g,
1960
+ `async execute(code, element, lang = null) {
1961
+ const me = element || document.body;
1962
+ const ast = parseWithSemantic(code, lang);`
1963
+ );
1964
+ if (semanticExports.length > 0) {
1965
+ const apiExportsMarker = "parserName: 'hybrid',";
1966
+ const additionalApiProps = semanticExports.map((exp) => ` ${exp},`).join("\n");
1967
+ bundleCode = bundleCode.replace(
1968
+ apiExportsMarker,
1969
+ `parserName: 'hybrid',
1970
+ ${additionalApiProps}`
1971
+ );
1972
+ }
1973
+ return bundleCode;
1974
+ }
1975
+ /**
1976
+ * Generate an empty bundle when no hyperscript is detected
1977
+ */
1978
+ generateEmptyBundle(options) {
1979
+ const globalName = options.globalName ?? "hyperfixi";
1980
+ return `/**
1981
+ * HyperFixi Empty Bundle (Auto-Generated)
1982
+ *
1983
+ * No hyperscript usage detected. This bundle provides a minimal API.
1984
+ * Add hyperscript attributes (_="...") to your HTML to enable features.
1985
+ *
1986
+ * Generated by: @lokascript/vite-plugin
1987
+ */
1988
+
1989
+ const api = {
1990
+ version: '1.0.0-empty',
1991
+ commands: [],
1992
+ parserName: 'none',
1993
+
1994
+ parse() {
1995
+ console.warn('HyperFixi: No parser loaded. Add hyperscript to your HTML to enable parsing.');
1996
+ return { type: 'empty' };
1997
+ },
1998
+
1999
+ async execute(code, element) {
2000
+ console.warn('HyperFixi: No commands loaded. Detected commands will be automatically included.');
2001
+ return null;
2002
+ },
2003
+
2004
+ run: async (code, element) => api.execute(code, element),
2005
+ eval: async (code, element) => api.execute(code, element),
2006
+
2007
+ init() {},
2008
+ process() {},
2009
+ };
2010
+
2011
+ if (typeof window !== 'undefined') {
2012
+ (window).${globalName} = api;
2013
+ (window)._hyperscript = api;
2014
+ }
2015
+
2016
+ export default api;
2017
+ export { api };
2018
+ `;
2019
+ }
2020
+ /**
2021
+ * Generate a development fallback bundle
2022
+ */
2023
+ generateDevFallback(fallback) {
2024
+ const bundle = fallback === "full" ? "@lokascript/core/browser" : "@lokascript/core/browser/hybrid-complete";
2025
+ return `/**
2026
+ * HyperFixi Dev Fallback Bundle
2027
+ *
2028
+ * Using pre-built ${fallback} bundle for faster development.
2029
+ * Production builds will generate minimal bundles.
2030
+ *
2031
+ * Generated by: @lokascript/vite-plugin
2032
+ */
2033
+
2034
+ export * from '${bundle}';
2035
+ export { default } from '${bundle}';
2036
+ `;
2037
+ }
2038
+ };
2039
+
2040
+ // src/compiler.ts
2041
+ import { HybridParser } from "@lokascript/core/parser/hybrid/parser-core";
2042
+ var semanticAnalyzer = null;
2043
+ var buildASTFn = null;
2044
+ function setSemanticParser(analyzer, buildAST) {
2045
+ semanticAnalyzer = analyzer;
2046
+ buildASTFn = buildAST;
2047
+ }
2048
+ function clearSemanticParser() {
2049
+ semanticAnalyzer = null;
2050
+ buildASTFn = null;
2051
+ }
2052
+ function hasSemanticParser() {
2053
+ return semanticAnalyzer !== null && buildASTFn !== null;
2054
+ }
2055
+ var SEMANTIC_CONFIDENCE_THRESHOLD = 0.7;
2056
+ var multilingualAliases = {};
2057
+ var multilingualRegex = null;
2058
+ function setMultilingualAliases(aliases) {
2059
+ multilingualAliases = { ...aliases };
2060
+ if (Object.keys(aliases).length > 0) {
2061
+ const escapedKeys = Object.keys(aliases).map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
2062
+ multilingualRegex = new RegExp(`(^|\\s)(${escapedKeys})(?=\\s|\\.|$)`, "g");
2063
+ } else {
2064
+ multilingualRegex = null;
2065
+ }
2066
+ }
2067
+ function preprocessMultilingual(code) {
2068
+ if (!multilingualRegex) return code;
2069
+ return code.replace(multilingualRegex, (match, prefix, keyword) => {
2070
+ const english = multilingualAliases[keyword];
2071
+ return english ? prefix + english : match;
2072
+ });
2073
+ }
2074
+ function sanitizeClassName(name) {
2075
+ if (!/^-?[a-zA-Z_][a-zA-Z0-9_-]*$/.test(name)) {
2076
+ return null;
2077
+ }
2078
+ return name;
2079
+ }
2080
+ function sanitizeSelector(selector) {
2081
+ return selector.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\0/g, "");
2082
+ }
2083
+ function hashScript(script) {
2084
+ let hash = 5381;
2085
+ for (let i = 0; i < script.length; i++) {
2086
+ hash = (hash << 5) + hash ^ script.charCodeAt(i);
2087
+ }
2088
+ return Math.abs(hash).toString(36).slice(0, 4);
2089
+ }
2090
+ var usedIds = /* @__PURE__ */ new Set();
2091
+ function resetCompiler() {
2092
+ usedIds.clear();
2093
+ }
2094
+ function generateHandlerId(event, command, script) {
2095
+ const hash = hashScript(script);
2096
+ let id = `${event}_${command}_${hash}`;
2097
+ let suffix = 0;
2098
+ while (usedIds.has(id)) {
2099
+ id = `${event}_${command}_${hash}${suffix++}`;
2100
+ }
2101
+ usedIds.add(id);
2102
+ return id;
2103
+ }
2104
+ function compile(script, options = {}) {
2105
+ const { language = "en", debug = false } = options;
2106
+ try {
2107
+ let ast;
2108
+ if (language !== "en" && semanticAnalyzer && buildASTFn) {
2109
+ if (semanticAnalyzer.supportsLanguage(language)) {
2110
+ const result = semanticAnalyzer.analyze(script, language);
2111
+ if (result.node && result.confidence >= SEMANTIC_CONFIDENCE_THRESHOLD) {
2112
+ const { ast: builtAST, warnings } = buildASTFn(result.node);
2113
+ if (debug && warnings.length > 0) {
2114
+ console.log(`[hyperfixi] Semantic AST warnings for "${script}":`, warnings);
2115
+ }
2116
+ ast = builtAST;
2117
+ if (debug) {
2118
+ console.log(
2119
+ `[hyperfixi] Compiled ${language}: "${script}" (confidence: ${result.confidence.toFixed(2)})`
2120
+ );
2121
+ }
2122
+ } else {
2123
+ if (debug) {
2124
+ const reason = result.errors?.join(", ") || `low confidence (${result.confidence.toFixed(2)})`;
2125
+ console.log(`[hyperfixi] Semantic parse failed for "${script}": ${reason}`);
2126
+ }
2127
+ return null;
2128
+ }
2129
+ } else {
2130
+ if (debug) {
2131
+ console.log(`[hyperfixi] Language "${language}" not supported by semantic parser`);
2132
+ }
2133
+ return null;
2134
+ }
2135
+ } else if (language !== "en") {
2136
+ if (debug) {
2137
+ console.log(
2138
+ `[hyperfixi] Semantic parser not available for "${language}". Install @lokascript/semantic and call setSemanticParser().`
2139
+ );
2140
+ }
2141
+ return null;
2142
+ } else {
2143
+ const preprocessedScript = preprocessMultilingual(script);
2144
+ const parser = new HybridParser(preprocessedScript);
2145
+ ast = parser.parse();
2146
+ }
2147
+ return compileAST(ast, script);
2148
+ } catch (error) {
2149
+ if (debug) {
2150
+ console.warn(`[hyperfixi] Failed to compile: ${script}`, error);
2151
+ }
2152
+ return null;
2153
+ }
2154
+ }
2155
+ function extractPrimaryCommand(body) {
2156
+ if (body.length === 0) return "handler";
2157
+ const first = body[0];
2158
+ if (first.type === "command") {
2159
+ return first.name || "cmd";
2160
+ }
2161
+ return first.type || "handler";
2162
+ }
2163
+ function compileAST(ast, original) {
2164
+ if (ast.type !== "event") {
2165
+ return null;
2166
+ }
2167
+ const eventNode = ast;
2168
+ const event = eventNode.event;
2169
+ const modifiers = eventNode.modifiers || {};
2170
+ const body = eventNode.body || [];
2171
+ const { code, needsEvaluator, needsLocals, needsGlobals } = compileBody(body);
2172
+ if (code === null || code === "") {
2173
+ return null;
2174
+ }
2175
+ const command = extractPrimaryCommand(body);
2176
+ const id = generateHandlerId(event, command, original);
2177
+ return {
2178
+ id,
2179
+ event,
2180
+ modifiers: {
2181
+ prevent: modifiers.prevent,
2182
+ stop: modifiers.stop,
2183
+ once: modifiers.once,
2184
+ debounce: modifiers.debounce,
2185
+ throttle: modifiers.throttle
2186
+ },
2187
+ code,
2188
+ needsEvaluator: needsEvaluator || needsLocals || needsGlobals,
2189
+ original
2190
+ };
2191
+ }
2192
+ function compileBody(nodes) {
2193
+ const statements = [];
2194
+ let needsEvaluator = false;
2195
+ let needsLocals = false;
2196
+ let needsGlobals = false;
2197
+ for (const node of nodes) {
2198
+ const result = compileNode(node);
2199
+ if (result === null) {
2200
+ return { code: null, needsEvaluator: false, needsLocals: false, needsGlobals: false };
2201
+ }
2202
+ statements.push(result.code);
2203
+ needsEvaluator = needsEvaluator || result.needsEvaluator;
2204
+ needsLocals = needsLocals || result.needsLocals;
2205
+ needsGlobals = needsGlobals || result.needsGlobals;
2206
+ }
2207
+ return {
2208
+ code: statements.join("\n"),
2209
+ needsEvaluator,
2210
+ needsLocals,
2211
+ needsGlobals
2212
+ };
2213
+ }
2214
+ function compileNode(node) {
2215
+ if (node.type === "command") {
2216
+ return compileCommand(node);
2217
+ }
2218
+ return null;
2219
+ }
2220
+ function compileCommand(cmd) {
2221
+ const target = cmd.target ? compileTarget(cmd.target) : "m";
2222
+ switch (cmd.name) {
2223
+ case "toggle":
2224
+ return compileToggle(cmd.args, target);
2225
+ case "add":
2226
+ return compileAdd(cmd.args, target);
2227
+ case "remove":
2228
+ return compileRemove(cmd.args, target);
2229
+ case "removeClass":
2230
+ return compileRemoveClass(cmd.args, target);
2231
+ case "show":
2232
+ return {
2233
+ code: `${target}.style.display = ''`,
2234
+ needsEvaluator: false,
2235
+ needsLocals: false,
2236
+ needsGlobals: false
2237
+ };
2238
+ case "hide":
2239
+ return {
2240
+ code: `${target}.style.display = 'none'`,
2241
+ needsEvaluator: false,
2242
+ needsLocals: false,
2243
+ needsGlobals: false
2244
+ };
2245
+ case "focus":
2246
+ return {
2247
+ code: `${target}.focus()`,
2248
+ needsEvaluator: false,
2249
+ needsLocals: false,
2250
+ needsGlobals: false
2251
+ };
2252
+ case "blur":
2253
+ return {
2254
+ code: `${target}.blur()`,
2255
+ needsEvaluator: false,
2256
+ needsLocals: false,
2257
+ needsGlobals: false
2258
+ };
2259
+ case "log":
2260
+ return compileLog(cmd.args);
2261
+ case "set":
2262
+ return compileSet(cmd.args);
2263
+ case "increment":
2264
+ return compileIncrement(cmd.args);
2265
+ case "decrement":
2266
+ return compileDecrement(cmd.args);
2267
+ case "put":
2268
+ return compilePut(cmd.args, target, cmd.modifier);
2269
+ case "send":
2270
+ case "trigger":
2271
+ return compileTrigger(cmd.args, target);
2272
+ case "wait":
2273
+ return compileWait(cmd.args);
2274
+ default:
2275
+ return null;
2276
+ }
2277
+ }
2278
+ function compileToggle(args, target) {
2279
+ const className = extractClassName(args[0]);
2280
+ if (!className) return null;
2281
+ if (target === "m") {
2282
+ return {
2283
+ code: `m.classList.toggle('${className}')`,
2284
+ needsEvaluator: false,
2285
+ needsLocals: false,
2286
+ needsGlobals: false
2287
+ };
2288
+ }
2289
+ return {
2290
+ code: `${target}.forEach(el => el.classList.toggle('${className}'))`,
2291
+ needsEvaluator: false,
2292
+ needsLocals: false,
2293
+ needsGlobals: false
2294
+ };
2295
+ }
2296
+ function compileAdd(args, target) {
2297
+ const className = extractClassName(args[0]);
2298
+ if (!className) return null;
2299
+ if (target === "m") {
2300
+ return {
2301
+ code: `m.classList.add('${className}')`,
2302
+ needsEvaluator: false,
2303
+ needsLocals: false,
2304
+ needsGlobals: false
2305
+ };
2306
+ }
2307
+ return {
2308
+ code: `${target}.forEach(el => el.classList.add('${className}'))`,
2309
+ needsEvaluator: false,
2310
+ needsLocals: false,
2311
+ needsGlobals: false
2312
+ };
2313
+ }
2314
+ function compileRemove(args, target) {
2315
+ if (!args || args.length === 0) {
2316
+ return {
2317
+ code: `${target}.remove()`,
2318
+ needsEvaluator: false,
2319
+ needsLocals: false,
2320
+ needsGlobals: false
2321
+ };
2322
+ }
2323
+ const className = extractClassName(args[0]);
2324
+ if (!className) return null;
2325
+ if (target === "m") {
2326
+ return {
2327
+ code: `m.classList.remove('${className}')`,
2328
+ needsEvaluator: false,
2329
+ needsLocals: false,
2330
+ needsGlobals: false
2331
+ };
2332
+ }
2333
+ return {
2334
+ code: `${target}.forEach(el => el.classList.remove('${className}'))`,
2335
+ needsEvaluator: false,
2336
+ needsLocals: false,
2337
+ needsGlobals: false
2338
+ };
2339
+ }
2340
+ function compileRemoveClass(args, target) {
2341
+ const className = extractClassName(args[0]);
2342
+ if (!className) return null;
2343
+ if (target === "m") {
2344
+ return {
2345
+ code: `m.classList.remove('${className}')`,
2346
+ needsEvaluator: false,
2347
+ needsLocals: false,
2348
+ needsGlobals: false
2349
+ };
2350
+ }
2351
+ return {
2352
+ code: `${target}.forEach(el => el.classList.remove('${className}'))`,
2353
+ needsEvaluator: false,
2354
+ needsLocals: false,
2355
+ needsGlobals: false
2356
+ };
2357
+ }
2358
+ function compileLog(args) {
2359
+ const compiled = args.map(compileExpression).filter(Boolean);
2360
+ if (compiled.length !== args.length) {
2361
+ return {
2362
+ code: `console.log(${compiled.join(", ")})`,
2363
+ needsEvaluator: true,
2364
+ needsLocals: false,
2365
+ needsGlobals: false
2366
+ };
2367
+ }
2368
+ return {
2369
+ code: `console.log(${compiled.join(", ")})`,
2370
+ needsEvaluator: false,
2371
+ needsLocals: false,
2372
+ needsGlobals: false
2373
+ };
2374
+ }
2375
+ function compileSet(args) {
2376
+ if (args.length < 2) return null;
2377
+ const [target, value] = args;
2378
+ const compiledValue = compileExpression(value);
2379
+ if (!compiledValue) return null;
2380
+ if (target.type === "variable") {
2381
+ const varNode = target;
2382
+ if (varNode.scope === "local") {
2383
+ const varName = varNode.name.slice(1);
2384
+ return {
2385
+ code: `L.${varName} = ${compiledValue}`,
2386
+ needsEvaluator: false,
2387
+ needsLocals: true,
2388
+ needsGlobals: false
2389
+ };
2390
+ }
2391
+ if (varNode.scope === "global") {
2392
+ const varName = varNode.name.slice(1);
2393
+ return {
2394
+ code: `G.${varName} = ${compiledValue}`,
2395
+ needsEvaluator: false,
2396
+ needsLocals: false,
2397
+ needsGlobals: true
2398
+ };
2399
+ }
2400
+ }
2401
+ if (target.type === "possessive") {
2402
+ const possNode = target;
2403
+ const obj = compileExpression(possNode.object);
2404
+ const prop = possNode.property;
2405
+ if (!obj) return null;
2406
+ if (prop.startsWith("*")) {
2407
+ const styleProp = prop.slice(1);
2408
+ return {
2409
+ code: `${obj}.style.${styleProp} = ${compiledValue}`,
2410
+ needsEvaluator: false,
2411
+ needsLocals: false,
2412
+ needsGlobals: false
2413
+ };
2414
+ }
2415
+ return {
2416
+ code: `${obj}.${prop} = ${compiledValue}`,
2417
+ needsEvaluator: false,
2418
+ needsLocals: false,
2419
+ needsGlobals: false
2420
+ };
2421
+ }
2422
+ if (target.type === "member") {
2423
+ const memNode = target;
2424
+ const obj = compileExpression(memNode.object);
2425
+ const prop = typeof memNode.property === "string" ? memNode.property : null;
2426
+ if (!obj || !prop) return null;
2427
+ if (prop.startsWith("*")) {
2428
+ const styleProp = prop.slice(1);
2429
+ return {
2430
+ code: `${obj}.style.${styleProp} = ${compiledValue}`,
2431
+ needsEvaluator: false,
2432
+ needsLocals: false,
2433
+ needsGlobals: false
2434
+ };
2435
+ }
2436
+ return {
2437
+ code: `${obj}.${prop} = ${compiledValue}`,
2438
+ needsEvaluator: false,
2439
+ needsLocals: false,
2440
+ needsGlobals: false
2441
+ };
2442
+ }
2443
+ return null;
2444
+ }
2445
+ function compileIncrement(args) {
2446
+ if (args.length < 1) return null;
2447
+ const target = args[0];
2448
+ const amount = args.length > 1 ? compileExpression(args[1]) : "1";
2449
+ if (target.type === "variable") {
2450
+ const varNode = target;
2451
+ if (varNode.scope === "local") {
2452
+ const varName = varNode.name.slice(1);
2453
+ return {
2454
+ code: `L.${varName} = (L.${varName} || 0) + ${amount}`,
2455
+ needsEvaluator: false,
2456
+ needsLocals: true,
2457
+ needsGlobals: false
2458
+ };
2459
+ }
2460
+ if (varNode.scope === "global") {
2461
+ const varName = varNode.name.slice(1);
2462
+ return {
2463
+ code: `G.${varName} = (G.${varName} || 0) + ${amount}`,
2464
+ needsEvaluator: false,
2465
+ needsLocals: false,
2466
+ needsGlobals: true
2467
+ };
2468
+ }
2469
+ }
2470
+ const compiled = compileExpression(target);
2471
+ if (compiled) {
2472
+ return {
2473
+ code: `${compiled}.textContent = (parseFloat(${compiled}.textContent) || 0) + ${amount}`,
2474
+ needsEvaluator: false,
2475
+ needsLocals: false,
2476
+ needsGlobals: false
2477
+ };
2478
+ }
2479
+ return null;
2480
+ }
2481
+ function compileDecrement(args) {
2482
+ if (args.length < 1) return null;
2483
+ const target = args[0];
2484
+ const amount = args.length > 1 ? compileExpression(args[1]) : "1";
2485
+ if (target.type === "variable") {
2486
+ const varNode = target;
2487
+ if (varNode.scope === "local") {
2488
+ const varName = varNode.name.slice(1);
2489
+ return {
2490
+ code: `L.${varName} = (L.${varName} || 0) - ${amount}`,
2491
+ needsEvaluator: false,
2492
+ needsLocals: true,
2493
+ needsGlobals: false
2494
+ };
2495
+ }
2496
+ if (varNode.scope === "global") {
2497
+ const varName = varNode.name.slice(1);
2498
+ return {
2499
+ code: `G.${varName} = (G.${varName} || 0) - ${amount}`,
2500
+ needsEvaluator: false,
2501
+ needsLocals: false,
2502
+ needsGlobals: true
2503
+ };
2504
+ }
2505
+ }
2506
+ const compiled = compileExpression(target);
2507
+ if (compiled) {
2508
+ return {
2509
+ code: `${compiled}.textContent = (parseFloat(${compiled}.textContent) || 0) - ${amount}`,
2510
+ needsEvaluator: false,
2511
+ needsLocals: false,
2512
+ needsGlobals: false
2513
+ };
2514
+ }
2515
+ return null;
2516
+ }
2517
+ function compilePut(args, target, modifier) {
2518
+ if (args.length < 1) return null;
2519
+ const content = compileExpression(args[0]);
2520
+ if (!content) return null;
2521
+ const mod = modifier || "into";
2522
+ switch (mod) {
2523
+ case "into":
2524
+ return {
2525
+ code: `${target}.innerHTML = ${content}`,
2526
+ needsEvaluator: false,
2527
+ needsLocals: false,
2528
+ needsGlobals: false
2529
+ };
2530
+ case "before":
2531
+ return {
2532
+ code: `${target}.insertAdjacentHTML('beforebegin', ${content})`,
2533
+ needsEvaluator: false,
2534
+ needsLocals: false,
2535
+ needsGlobals: false
2536
+ };
2537
+ case "after":
2538
+ return {
2539
+ code: `${target}.insertAdjacentHTML('afterend', ${content})`,
2540
+ needsEvaluator: false,
2541
+ needsLocals: false,
2542
+ needsGlobals: false
2543
+ };
2544
+ case "at start of":
2545
+ return {
2546
+ code: `${target}.insertAdjacentHTML('afterbegin', ${content})`,
2547
+ needsEvaluator: false,
2548
+ needsLocals: false,
2549
+ needsGlobals: false
2550
+ };
2551
+ case "at end of":
2552
+ return {
2553
+ code: `${target}.insertAdjacentHTML('beforeend', ${content})`,
2554
+ needsEvaluator: false,
2555
+ needsLocals: false,
2556
+ needsGlobals: false
2557
+ };
2558
+ default:
2559
+ return {
2560
+ code: `${target}.innerHTML = ${content}`,
2561
+ needsEvaluator: false,
2562
+ needsLocals: false,
2563
+ needsGlobals: false
2564
+ };
2565
+ }
2566
+ }
2567
+ function compileTrigger(args, target) {
2568
+ if (args.length < 1) return null;
2569
+ const eventName = compileExpression(args[0]);
2570
+ if (!eventName) return null;
2571
+ return {
2572
+ code: `${target}.dispatchEvent(new CustomEvent(${eventName}, { bubbles: true }))`,
2573
+ needsEvaluator: false,
2574
+ needsLocals: false,
2575
+ needsGlobals: false
2576
+ };
2577
+ }
2578
+ function compileWait(args) {
2579
+ if (args.length < 1) return null;
2580
+ const duration = compileExpression(args[0]);
2581
+ if (!duration) return null;
2582
+ return {
2583
+ code: `await new Promise(r => setTimeout(r, ${duration}))`,
2584
+ needsEvaluator: false,
2585
+ needsLocals: false,
2586
+ needsGlobals: false
2587
+ };
2588
+ }
2589
+ function compileExpression(node) {
2590
+ if (!node) return null;
2591
+ switch (node.type) {
2592
+ case "literal": {
2593
+ const litNode = node;
2594
+ return JSON.stringify(litNode.value);
2595
+ }
2596
+ case "identifier": {
2597
+ const idNode = node;
2598
+ const val = idNode.value;
2599
+ if (val === "me" || val === "my") return "m";
2600
+ if (val === "you") return "y";
2601
+ if (val === "it") return "it";
2602
+ if (val === "event") return "e";
2603
+ if (val === "body") return "document.body";
2604
+ if (val === "document") return "document";
2605
+ if (val === "window") return "window";
2606
+ return val;
2607
+ }
2608
+ case "variable": {
2609
+ const varNode = node;
2610
+ const name = varNode.name.slice(1);
2611
+ return varNode.scope === "local" ? `L.${name}` : `G.${name}`;
2612
+ }
2613
+ case "selector": {
2614
+ const selNode = node;
2615
+ const sanitized = sanitizeSelector(selNode.value);
2616
+ return `document.querySelector('${sanitized}')`;
2617
+ }
2618
+ case "possessive": {
2619
+ const possNode = node;
2620
+ const obj = compileExpression(possNode.object);
2621
+ const prop = possNode.property;
2622
+ if (!obj) return null;
2623
+ if (prop.startsWith("*")) {
2624
+ return `${obj}.style.${prop.slice(1)}`;
2625
+ }
2626
+ return `${obj}.${prop}`;
2627
+ }
2628
+ case "member": {
2629
+ const memNode = node;
2630
+ const obj = compileExpression(memNode.object);
2631
+ const prop = typeof memNode.property === "string" ? memNode.property : null;
2632
+ if (!obj || !prop) return null;
2633
+ if (prop.startsWith("*")) {
2634
+ return `${obj}.style.${prop.slice(1)}`;
2635
+ }
2636
+ return `${obj}.${prop}`;
2637
+ }
2638
+ case "binary": {
2639
+ const binNode = node;
2640
+ const left = compileExpression(binNode.left);
2641
+ const right = compileExpression(binNode.right);
2642
+ if (!left || !right) return null;
2643
+ const op = binNode.operator;
2644
+ switch (op) {
2645
+ case "+":
2646
+ case "-":
2647
+ case "*":
2648
+ case "/":
2649
+ case "%":
2650
+ return `(${left} ${op} ${right})`;
2651
+ case "==":
2652
+ case "is":
2653
+ return `(${left} == ${right})`;
2654
+ case "!=":
2655
+ case "is not":
2656
+ return `(${left} != ${right})`;
2657
+ case "<":
2658
+ case ">":
2659
+ case "<=":
2660
+ case ">=":
2661
+ return `(${left} ${op} ${right})`;
2662
+ case "and":
2663
+ case "&&":
2664
+ return `(${left} && ${right})`;
2665
+ case "or":
2666
+ case "||":
2667
+ return `(${left} || ${right})`;
2668
+ case "has": {
2669
+ const rightSel = binNode.right;
2670
+ const className = rightSel.value?.slice(1) || "";
2671
+ const sanitizedClass = sanitizeClassName(className);
2672
+ if (!sanitizedClass) return null;
2673
+ return `${left}.classList.contains('${sanitizedClass}')`;
2674
+ }
2675
+ default:
2676
+ return null;
2677
+ }
2678
+ }
2679
+ case "call": {
2680
+ const callNode = node;
2681
+ const callee = callNode.callee;
2682
+ const args = (callNode.args || []).map(compileExpression);
2683
+ if (args.some((a) => a === null)) return null;
2684
+ if (callee.type === "member" || callee.type === "possessive") {
2685
+ const memCallee = callee;
2686
+ const obj = compileExpression(memCallee.object);
2687
+ const prop = typeof memCallee.property === "string" ? memCallee.property : null;
2688
+ if (!obj || !prop) return null;
2689
+ return `${obj}.${prop}(${args.join(", ")})`;
2690
+ }
2691
+ const fn = compileExpression(callee);
2692
+ if (!fn) return null;
2693
+ return `${fn}(${args.join(", ")})`;
2694
+ }
2695
+ case "positional": {
2696
+ const posNode = node;
2697
+ const position = posNode.position;
2698
+ const target = posNode.target;
2699
+ switch (position) {
2700
+ case "first":
2701
+ if (target?.type === "selector") {
2702
+ const selNode = target;
2703
+ const sanitized = sanitizeSelector(selNode.value);
2704
+ return `document.querySelector('${sanitized}')`;
2705
+ }
2706
+ return null;
2707
+ // Arrays need runtime
2708
+ case "last":
2709
+ if (target?.type === "selector") {
2710
+ const selNode = target;
2711
+ const sanitized = sanitizeSelector(selNode.value);
2712
+ return `(()=>{const e=document.querySelectorAll('${sanitized}');return e[e.length-1]})()`;
2713
+ }
2714
+ return null;
2715
+ // Arrays need runtime
2716
+ case "next":
2717
+ return "m.nextElementSibling";
2718
+ case "previous":
2719
+ return "m.previousElementSibling";
2720
+ case "closest":
2721
+ if (target?.type === "selector") {
2722
+ const selNode = target;
2723
+ const sanitized = sanitizeSelector(selNode.value);
2724
+ return `m.closest('${sanitized}')`;
2725
+ }
2726
+ return null;
2727
+ case "parent":
2728
+ return "m.parentElement";
2729
+ default:
2730
+ return null;
2731
+ }
2732
+ }
2733
+ default:
2734
+ return null;
2735
+ }
2736
+ }
2737
+ function compileTarget(target) {
2738
+ if (target.type === "identifier") {
2739
+ const idNode = target;
2740
+ if (idNode.value === "me" || idNode.value === "my") return "m";
2741
+ if (idNode.value === "you") return "y";
2742
+ }
2743
+ if (target.type === "selector") {
2744
+ const selNode = target;
2745
+ const sanitized = sanitizeSelector(selNode.value);
2746
+ return `document.querySelectorAll('${sanitized}')`;
2747
+ }
2748
+ const compiled = compileExpression(target);
2749
+ return compiled || "m";
2750
+ }
2751
+ function extractClassName(node) {
2752
+ if (!node) return null;
2753
+ if (node.type === "selector") {
2754
+ const selNode = node;
2755
+ const val = selNode.value;
2756
+ const rawClass = val.startsWith(".") ? val.slice(1) : val;
2757
+ return sanitizeClassName(rawClass);
2758
+ }
2759
+ if (node.type === "literal" || node.type === "string") {
2760
+ const litNode = node;
2761
+ const val = litNode.value;
2762
+ if (typeof val === "string") {
2763
+ const rawClass = val.startsWith(".") ? val.slice(1) : val;
2764
+ return sanitizeClassName(rawClass);
2765
+ }
2766
+ }
2767
+ if (node.type === "identifier") {
2768
+ const idNode = node;
2769
+ return sanitizeClassName(idNode.value);
2770
+ }
2771
+ return null;
2772
+ }
2773
+
2774
+ // src/compiled-generator.ts
2775
+ function generateSourceMapTable(handlers) {
2776
+ if (handlers.length === 0) return "";
2777
+ const lines = [
2778
+ " *",
2779
+ " * Handler Source Map:",
2780
+ " * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"
2781
+ ];
2782
+ for (const h of handlers) {
2783
+ const original = h.original.replace(/\n/g, " ").slice(0, 40);
2784
+ const truncated = original.length < h.original.length ? original + "..." : original;
2785
+ lines.push(` * \u2502 ${h.id.padEnd(20)} \u2190 ${truncated.padEnd(40)} \u2502`);
2786
+ }
2787
+ lines.push(" * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518");
2788
+ lines.push(" *");
2789
+ return lines.join("\n");
2790
+ }
2791
+ function generateCompiledBundle(options) {
2792
+ const {
2793
+ handlers,
2794
+ needsLocals,
2795
+ needsGlobals,
2796
+ globalName = "hyperfixi",
2797
+ htmx = false,
2798
+ debug = false
2799
+ } = options;
2800
+ const handlerEntries = handlers.map((h) => {
2801
+ const isAsync = h.code.includes("await");
2802
+ const fn = isAsync ? `async(m,e,y)=>{${h.code}}` : `(m,e,y)=>{${h.code}}`;
2803
+ if (debug) {
2804
+ const escapedOriginal = h.original.replace(/\*/g, "\\*").replace(/\n/g, " ");
2805
+ return `
2806
+ /* ${escapedOriginal} */
2807
+ ${h.id}:${fn}`;
2808
+ }
2809
+ return `${h.id}:${fn}`;
2810
+ });
2811
+ const registrations = handlers.map((h) => {
2812
+ const modsCode = generateModifiersCode(h);
2813
+ return ` case '${h.id}': r(el,'${h.event}',H.${h.id}${modsCode}); break;`;
2814
+ });
2815
+ const localsCode = needsLocals ? "const L={};" : "";
2816
+ const globalsCode = needsGlobals ? "const G={};" : "";
2817
+ const sourceMapTable = debug ? generateSourceMapTable(handlers) : "";
2818
+ return `/**
2819
+ * HyperFixi Compiled Bundle (Auto-Generated)
2820
+ *
2821
+ * Pre-compiled hyperscript - no runtime parser needed!
2822
+ * Handlers: ${handlers.length}
2823
+ *
2824
+ * DO NOT EDIT - Regenerate with build.
2825
+ ${sourceMapTable} */
2826
+
2827
+ ${localsCode}${globalsCode}
2828
+ const H={${handlerEntries.join(",")}};
2829
+
2830
+ function r(el,ev,fn${hasModifiers(handlers) ? ",m" : ""}){
2831
+ let h=e=>fn(el,e,e.target);
2832
+ ${generateModifierWrappers(handlers)}
2833
+ el.addEventListener(ev,h${hasOnce(handlers) ? ",{once:m?.o}" : ""});
2834
+ }
2835
+
2836
+ function init(root=document){
2837
+ root.querySelectorAll('[data-h]').forEach(el=>{
2838
+ switch(el.dataset.h){
2839
+ ${registrations.join("\n")}
2840
+ }
2841
+ });
2842
+ }
2843
+
2844
+ ${htmx ? `document.addEventListener('htmx:afterSettle',e=>init(e.detail?.target));` : ""}
2845
+
2846
+ const api={
2847
+ version:'1.0.0-compiled',
2848
+ commands:${JSON.stringify(handlers.map((h) => h.id))},
2849
+ init,
2850
+ process:init,
2851
+ };
2852
+
2853
+ if(typeof window!=='undefined'){
2854
+ window.${globalName}=api;
2855
+ window._hyperscript=api;
2856
+ document.readyState==='loading'
2857
+ ?document.addEventListener('DOMContentLoaded',()=>init())
2858
+ :init();
2859
+ }
2860
+
2861
+ export default api;
2862
+ export{api,init};
2863
+ `;
2864
+ }
2865
+ function generateModifiersCode(h) {
2866
+ const mods = [];
2867
+ if (h.modifiers.prevent) mods.push("p:1");
2868
+ if (h.modifiers.stop) mods.push("s:1");
2869
+ if (h.modifiers.once) mods.push("o:1");
2870
+ if (h.modifiers.debounce) mods.push(`d:${h.modifiers.debounce}`);
2871
+ if (h.modifiers.throttle) mods.push(`t:${h.modifiers.throttle}`);
2872
+ if (mods.length === 0) return "";
2873
+ return `,{${mods.join(",")}}`;
2874
+ }
2875
+ function hasModifiers(handlers) {
2876
+ return handlers.some(
2877
+ (h) => h.modifiers.prevent || h.modifiers.stop || h.modifiers.once || h.modifiers.debounce || h.modifiers.throttle
2878
+ );
2879
+ }
2880
+ function hasOnce(handlers) {
2881
+ return handlers.some((h) => h.modifiers.once);
2882
+ }
2883
+ function generateModifierWrappers(handlers) {
2884
+ const lines = [];
2885
+ if (handlers.some((h) => h.modifiers.prevent || h.modifiers.stop)) {
2886
+ lines.push(
2887
+ ` if(m?.p||m?.s){const _h=h;h=e=>{m.p&&e.preventDefault();m.s&&e.stopPropagation();_h(e.currentTarget,e,e.target)};}`
2888
+ );
2889
+ }
2890
+ if (handlers.some((h) => h.modifiers.debounce)) {
2891
+ lines.push(
2892
+ ` if(m?.d){let t;const _h=h;h=e=>{clearTimeout(t);t=setTimeout(()=>_h(e.currentTarget,e,e.target),m.d)};}`
2893
+ );
2894
+ }
2895
+ if (handlers.some((h) => h.modifiers.throttle)) {
2896
+ lines.push(
2897
+ ` if(m?.t){let l=0;const _h=h;h=e=>{const n=Date.now();if(n-l>=m.t){l=n;_h(e.currentTarget,e,e.target)}};}`
2898
+ );
2899
+ }
2900
+ return lines.join("\n");
2901
+ }
2902
+
2903
+ // src/html-transformer.ts
2904
+ function transformHTML(html, handlerMap, fallbackScripts) {
2905
+ let modified = false;
2906
+ const fallbacks = [];
2907
+ const patterns = [
2908
+ /(\s)_\s*=\s*"([^"]+)"/g,
2909
+ // _="..."
2910
+ /(\s)_\s*=\s*'([^']+)'/g,
2911
+ // _='...'
2912
+ /(\s)_\s*=\s*`([^`]+)`/g
2913
+ // _=`...`
2914
+ ];
2915
+ let result = html;
2916
+ for (const pattern of patterns) {
2917
+ result = result.replace(pattern, (match, whitespace, script) => {
2918
+ const handlerId = handlerMap.get(script);
2919
+ if (handlerId) {
2920
+ modified = true;
2921
+ return `${whitespace}data-h="${handlerId}"`;
2922
+ }
2923
+ if (fallbackScripts.has(script)) {
2924
+ fallbacks.push(script);
2925
+ return match;
2926
+ }
2927
+ fallbacks.push(script);
2928
+ return match;
2929
+ });
2930
+ }
2931
+ return {
2932
+ code: result,
2933
+ modified,
2934
+ fallbacks
2935
+ };
2936
+ }
2937
+ function extractScripts(html) {
2938
+ const scripts = [];
2939
+ const patterns = [/_\s*=\s*"([^"]+)"/g, /_\s*=\s*'([^']+)'/g, /_\s*=\s*`([^`]+)`/g];
2940
+ for (const pattern of patterns) {
2941
+ let match;
2942
+ while (match = pattern.exec(html)) {
2943
+ scripts.push(match[1]);
2944
+ }
2945
+ }
2946
+ return scripts;
2947
+ }
2948
+
2949
+ // src/index.ts
2950
+ var VIRTUAL_MODULE_ID = "virtual:hyperfixi";
2951
+ var RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
2952
+ var IMPORT_ALIASES = ["hyperfixi", "@lokascript/core", "virtual:hyperfixi"];
2953
+ function hyperfixi(options = {}) {
2954
+ const mode = options.mode ?? "interpret";
2955
+ const scanner = new Scanner(options);
2956
+ const aggregator = new Aggregator();
2957
+ const generator = new Generator(options);
2958
+ let server = null;
2959
+ let cachedBundle = null;
2960
+ let lastUsageHash = "";
2961
+ let isDev = false;
2962
+ const compiledHandlers = [];
2963
+ const handlerMap = /* @__PURE__ */ new Map();
2964
+ const fallbackScripts = /* @__PURE__ */ new Set();
2965
+ let needsLocals = false;
2966
+ let needsGlobals = false;
2967
+ function computeUsageHash(usage) {
2968
+ const commands = [...usage.commands].sort().join(",");
2969
+ const blocks = [...usage.blocks].sort().join(",");
2970
+ const languages = [...usage.detectedLanguages].sort().join(",");
2971
+ return `${commands}|${blocks}|${usage.positional}|${languages}`;
2972
+ }
2973
+ function invalidateVirtualModule() {
2974
+ if (!server) return;
2975
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
2976
+ if (mod) {
2977
+ server.moduleGraph.invalidateModule(mod);
2978
+ server.ws.send({ type: "full-reload" });
2979
+ if (options.debug) {
2980
+ console.log("[hyperfixi] Virtual module invalidated, triggering reload");
2981
+ }
2982
+ }
2983
+ }
2984
+ function compileScript(script) {
2985
+ if (handlerMap.has(script)) {
2986
+ return handlerMap.get(script);
2987
+ }
2988
+ if (fallbackScripts.has(script)) {
2989
+ return null;
2990
+ }
2991
+ const handler = compile(script);
2992
+ if (handler) {
2993
+ compiledHandlers.push(handler);
2994
+ handlerMap.set(script, handler.id);
2995
+ if (handler.needsEvaluator) {
2996
+ if (handler.code.includes("L.")) needsLocals = true;
2997
+ if (handler.code.includes("G.")) needsGlobals = true;
2998
+ }
2999
+ if (options.debug) {
3000
+ console.log(`[hyperfixi] Compiled: "${script}" -> ${handler.id}`);
3001
+ }
3002
+ return handler.id;
3003
+ }
3004
+ fallbackScripts.add(script);
3005
+ if (options.debug) {
3006
+ console.log(`[hyperfixi] Fallback (not compilable): "${script}"`);
3007
+ }
3008
+ return null;
3009
+ }
3010
+ function generateInterpretBundle() {
3011
+ const usage = aggregator.getUsage();
3012
+ const usageHash = computeUsageHash(usage);
3013
+ if (cachedBundle && usageHash === lastUsageHash) {
3014
+ return cachedBundle;
3015
+ }
3016
+ if (isDev && options.devFallback && options.devFallback !== "auto") {
3017
+ cachedBundle = generator.generateDevFallback(options.devFallback);
3018
+ } else {
3019
+ cachedBundle = generator.generate(usage, options);
3020
+ }
3021
+ lastUsageHash = usageHash;
3022
+ if (options.debug) {
3023
+ const summary = aggregator.getSummary();
3024
+ console.log("[hyperfixi] Bundle generated:", summary);
3025
+ }
3026
+ return cachedBundle;
3027
+ }
3028
+ function generateCompiledBundleCode() {
3029
+ if (fallbackScripts.size > 0) {
3030
+ if (options.debug) {
3031
+ console.log(`[hyperfixi] ${fallbackScripts.size} scripts need interpreter fallback`);
3032
+ }
3033
+ return generateInterpretBundle();
3034
+ }
3035
+ const bundle = generateCompiledBundle({
3036
+ handlers: compiledHandlers,
3037
+ needsLocals,
3038
+ needsGlobals,
3039
+ globalName: options.globalName,
3040
+ htmx: options.htmx,
3041
+ debug: options.debug
3042
+ });
3043
+ if (options.debug) {
3044
+ console.log(`[hyperfixi] Compiled bundle: ${compiledHandlers.length} handlers`);
3045
+ }
3046
+ return bundle;
3047
+ }
3048
+ function generateBundle() {
3049
+ if (mode === "compile") {
3050
+ return generateCompiledBundleCode();
3051
+ }
3052
+ return generateInterpretBundle();
3053
+ }
3054
+ return {
3055
+ name: "vite-plugin-hyperfixi",
3056
+ enforce: "pre",
3057
+ /**
3058
+ * Configure plugin based on Vite mode
3059
+ */
3060
+ configResolved(config) {
3061
+ isDev = config.command === "serve";
3062
+ if (options.debug) {
3063
+ console.log("[hyperfixi] Plugin initialized, mode:", isDev ? "development" : "production");
3064
+ }
3065
+ },
3066
+ /**
3067
+ * Store server reference and pre-scan HTML files for HMR
3068
+ */
3069
+ async configureServer(_server) {
3070
+ server = _server;
3071
+ const cwd = _server.config.root;
3072
+ if (options.debug) {
3073
+ console.log("[hyperfixi] Pre-scanning project:", cwd);
3074
+ }
3075
+ const scannedFiles = await scanner.scanProject(cwd);
3076
+ aggregator.loadFromScan(scannedFiles);
3077
+ if (options.debug) {
3078
+ const summary = aggregator.getSummary();
3079
+ console.log("[hyperfixi] Pre-scan complete:", summary);
3080
+ }
3081
+ },
3082
+ /**
3083
+ * Resolve virtual module imports
3084
+ */
3085
+ resolveId(id) {
3086
+ if (IMPORT_ALIASES.includes(id)) {
3087
+ return RESOLVED_VIRTUAL_MODULE_ID;
3088
+ }
3089
+ return null;
3090
+ },
3091
+ /**
3092
+ * Load the virtual module with generated bundle
3093
+ */
3094
+ load(id) {
3095
+ if (id === RESOLVED_VIRTUAL_MODULE_ID) {
3096
+ return generateBundle();
3097
+ }
3098
+ return null;
3099
+ },
3100
+ /**
3101
+ * Scan files during transform for hyperscript usage
3102
+ */
3103
+ transform(code, id) {
3104
+ if (!scanner.shouldScan(id)) {
3105
+ return null;
3106
+ }
3107
+ if (mode === "compile" && !isDev) {
3108
+ const scripts = extractScripts(code);
3109
+ for (const script of scripts) {
3110
+ compileScript(script);
3111
+ }
3112
+ const result = transformHTML(code, handlerMap, fallbackScripts);
3113
+ if (result.modified) {
3114
+ if (options.debug) {
3115
+ console.log(`[hyperfixi] Transformed: ${id.split("/").pop()}`);
3116
+ }
3117
+ return { code: result.code, map: null };
3118
+ }
3119
+ return null;
3120
+ }
3121
+ const usage = scanner.scan(code, id);
3122
+ const changed = aggregator.add(id, usage);
3123
+ if (changed && server) {
3124
+ setImmediate(() => {
3125
+ const currentHash = computeUsageHash(aggregator.getUsage());
3126
+ if (currentHash !== lastUsageHash) {
3127
+ invalidateVirtualModule();
3128
+ }
3129
+ });
3130
+ }
3131
+ return null;
3132
+ },
3133
+ /**
3134
+ * Handle file changes in HMR
3135
+ */
3136
+ async handleHotUpdate(ctx) {
3137
+ const { file, read } = ctx;
3138
+ if (scanner.shouldScan(file)) {
3139
+ try {
3140
+ const content = await read();
3141
+ const usage = scanner.scan(content, file);
3142
+ const changed = aggregator.add(file, usage);
3143
+ if (options.debug) {
3144
+ console.log("[hyperfixi] HMR: Re-scanned", file.split("/").pop(), usage);
3145
+ }
3146
+ if (changed) {
3147
+ const currentHash = computeUsageHash(aggregator.getUsage());
3148
+ if (currentHash !== lastUsageHash) {
3149
+ invalidateVirtualModule();
3150
+ }
3151
+ }
3152
+ } catch {
3153
+ if (aggregator.remove(file)) {
3154
+ invalidateVirtualModule();
3155
+ }
3156
+ }
3157
+ }
3158
+ return void 0;
3159
+ },
3160
+ /**
3161
+ * Scan entire project before production build
3162
+ */
3163
+ async buildStart() {
3164
+ if (!isDev) {
3165
+ if (mode === "compile") {
3166
+ resetCompiler();
3167
+ compiledHandlers.length = 0;
3168
+ handlerMap.clear();
3169
+ fallbackScripts.clear();
3170
+ needsLocals = false;
3171
+ needsGlobals = false;
3172
+ if (options.debug) {
3173
+ console.log("[hyperfixi] Compile mode: ready for build");
3174
+ }
3175
+ }
3176
+ const cwd = process.cwd();
3177
+ if (options.debug) {
3178
+ console.log("[hyperfixi] Scanning project for hyperscript usage...");
3179
+ }
3180
+ const scannedFiles = await scanner.scanProject(cwd);
3181
+ aggregator.loadFromScan(scannedFiles);
3182
+ if (mode === "compile") {
3183
+ const usage = aggregator.getUsage();
3184
+ if (usage.detectedLanguages.size > 0) {
3185
+ const aliases = getMultilingualCommandAliases(
3186
+ usage.detectedLanguages
3187
+ );
3188
+ if (Object.keys(aliases).length > 0) {
3189
+ setMultilingualAliases(aliases);
3190
+ if (options.debug) {
3191
+ console.log(
3192
+ `[hyperfixi] Compile mode: configured ${Object.keys(aliases).length} multilingual aliases`
3193
+ );
3194
+ }
3195
+ }
3196
+ }
3197
+ }
3198
+ if (options.debug) {
3199
+ const summary = aggregator.getSummary();
3200
+ console.log(`[hyperfixi] Found ${summary.fileCount} files with hyperscript:`, {
3201
+ commands: summary.commands,
3202
+ blocks: summary.blocks,
3203
+ positional: summary.positional,
3204
+ languages: summary.languages
3205
+ });
3206
+ }
3207
+ }
3208
+ }
3209
+ };
3210
+ }
3211
+ var index_default = hyperfixi;
3212
+ export {
3213
+ REGIONS,
3214
+ SUPPORTED_LANGUAGES,
3215
+ clearCustomKeywords,
3216
+ clearSemanticParser,
3217
+ index_default as default,
3218
+ detectLanguages,
3219
+ getAllLanguageCodes,
3220
+ getKeywordsForLanguage,
3221
+ getOptimalRegion,
3222
+ hasSemanticParser,
3223
+ hyperfixi,
3224
+ isNonLatinLanguage,
3225
+ registerCustomKeywords,
3226
+ setSemanticParser
3227
+ };
3228
+ //# sourceMappingURL=index.js.map