@lokascript/hyperscript-adapter 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -0
  3. package/dist/hyperscript-i18n-ar.global.js +4 -0
  4. package/dist/hyperscript-i18n-bn.global.js +4 -0
  5. package/dist/hyperscript-i18n-de.global.js +4 -0
  6. package/dist/hyperscript-i18n-east-asian.global.js +4 -0
  7. package/dist/hyperscript-i18n-en.global.js +6 -0
  8. package/dist/hyperscript-i18n-es.global.js +4 -0
  9. package/dist/hyperscript-i18n-fr.global.js +4 -0
  10. package/dist/hyperscript-i18n-he.global.js +4 -0
  11. package/dist/hyperscript-i18n-hi.global.js +4 -0
  12. package/dist/hyperscript-i18n-id.global.js +4 -0
  13. package/dist/hyperscript-i18n-it.global.js +4 -0
  14. package/dist/hyperscript-i18n-ja.global.js +4 -0
  15. package/dist/hyperscript-i18n-ko.global.js +4 -0
  16. package/dist/hyperscript-i18n-lite.global.js +1 -0
  17. package/dist/hyperscript-i18n-ms.global.js +4 -0
  18. package/dist/hyperscript-i18n-pl.global.js +4 -0
  19. package/dist/hyperscript-i18n-pt.global.js +4 -0
  20. package/dist/hyperscript-i18n-qu.global.js +4 -0
  21. package/dist/hyperscript-i18n-ru.global.js +4 -0
  22. package/dist/hyperscript-i18n-slavic.global.js +4 -0
  23. package/dist/hyperscript-i18n-south-asian.global.js +4 -0
  24. package/dist/hyperscript-i18n-southeast-asian.global.js +4 -0
  25. package/dist/hyperscript-i18n-sw.global.js +4 -0
  26. package/dist/hyperscript-i18n-th.global.js +4 -0
  27. package/dist/hyperscript-i18n-tl.global.js +4 -0
  28. package/dist/hyperscript-i18n-tr.global.js +4 -0
  29. package/dist/hyperscript-i18n-uk.global.js +4 -0
  30. package/dist/hyperscript-i18n-vi.global.js +4 -0
  31. package/dist/hyperscript-i18n-western.global.js +4 -0
  32. package/dist/hyperscript-i18n-zh.global.js +4 -0
  33. package/dist/hyperscript-i18n.global.js +8 -0
  34. package/dist/hyperscript-i18n.global.js.map +1 -0
  35. package/dist/index.cjs +203 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +99 -0
  38. package/dist/index.d.ts +99 -0
  39. package/dist/index.js +179 -0
  40. package/dist/index.js.map +1 -0
  41. package/package.json +169 -0
  42. package/src/browser-lite.ts +159 -0
  43. package/src/browser.ts +74 -0
  44. package/src/bundles/ar.ts +6 -0
  45. package/src/bundles/bn.ts +6 -0
  46. package/src/bundles/de.ts +6 -0
  47. package/src/bundles/east-asian.ts +8 -0
  48. package/src/bundles/en.ts +6 -0
  49. package/src/bundles/es.ts +6 -0
  50. package/src/bundles/fr.ts +6 -0
  51. package/src/bundles/he.ts +6 -0
  52. package/src/bundles/hi.ts +6 -0
  53. package/src/bundles/id.ts +6 -0
  54. package/src/bundles/it.ts +6 -0
  55. package/src/bundles/ja.ts +6 -0
  56. package/src/bundles/ko.ts +6 -0
  57. package/src/bundles/ms.ts +6 -0
  58. package/src/bundles/pl.ts +6 -0
  59. package/src/bundles/pt.ts +6 -0
  60. package/src/bundles/qu.ts +6 -0
  61. package/src/bundles/ru.ts +6 -0
  62. package/src/bundles/shared.ts +65 -0
  63. package/src/bundles/slavic.ts +8 -0
  64. package/src/bundles/south-asian.ts +7 -0
  65. package/src/bundles/southeast-asian.ts +10 -0
  66. package/src/bundles/sw.ts +6 -0
  67. package/src/bundles/th.ts +6 -0
  68. package/src/bundles/tl.ts +6 -0
  69. package/src/bundles/tr.ts +6 -0
  70. package/src/bundles/uk.ts +6 -0
  71. package/src/bundles/vi.ts +6 -0
  72. package/src/bundles/western.ts +9 -0
  73. package/src/bundles/zh.ts +6 -0
  74. package/src/derive-syntax.ts +126 -0
  75. package/src/generated/syntax-table.ts +61 -0
  76. package/src/hyperscript-renderer.ts +150 -0
  77. package/src/index.ts +27 -0
  78. package/src/language-resolver.ts +41 -0
  79. package/src/plugin.ts +119 -0
  80. package/src/preprocessor.ts +251 -0
  81. package/src/slim-plugin.ts +60 -0
  82. package/src/slim-preprocessor.ts +190 -0
package/package.json ADDED
@@ -0,0 +1,169 @@
1
+ {
2
+ "name": "@lokascript/hyperscript-adapter",
3
+ "version": "2.0.0",
4
+ "description": "Multilingual adapter plugin for original _hyperscript — write hyperscript in 24 languages",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./browser": {
16
+ "default": "./dist/hyperscript-i18n.global.js"
17
+ },
18
+ "./browser/lite": {
19
+ "default": "./dist/hyperscript-i18n-lite.global.js"
20
+ },
21
+ "./browser/ar": {
22
+ "default": "./dist/hyperscript-i18n-ar.global.js"
23
+ },
24
+ "./browser/bn": {
25
+ "default": "./dist/hyperscript-i18n-bn.global.js"
26
+ },
27
+ "./browser/de": {
28
+ "default": "./dist/hyperscript-i18n-de.global.js"
29
+ },
30
+ "./browser/en": {
31
+ "default": "./dist/hyperscript-i18n-en.global.js"
32
+ },
33
+ "./browser/es": {
34
+ "default": "./dist/hyperscript-i18n-es.global.js"
35
+ },
36
+ "./browser/fr": {
37
+ "default": "./dist/hyperscript-i18n-fr.global.js"
38
+ },
39
+ "./browser/he": {
40
+ "default": "./dist/hyperscript-i18n-he.global.js"
41
+ },
42
+ "./browser/hi": {
43
+ "default": "./dist/hyperscript-i18n-hi.global.js"
44
+ },
45
+ "./browser/id": {
46
+ "default": "./dist/hyperscript-i18n-id.global.js"
47
+ },
48
+ "./browser/it": {
49
+ "default": "./dist/hyperscript-i18n-it.global.js"
50
+ },
51
+ "./browser/ja": {
52
+ "default": "./dist/hyperscript-i18n-ja.global.js"
53
+ },
54
+ "./browser/ko": {
55
+ "default": "./dist/hyperscript-i18n-ko.global.js"
56
+ },
57
+ "./browser/ms": {
58
+ "default": "./dist/hyperscript-i18n-ms.global.js"
59
+ },
60
+ "./browser/pl": {
61
+ "default": "./dist/hyperscript-i18n-pl.global.js"
62
+ },
63
+ "./browser/pt": {
64
+ "default": "./dist/hyperscript-i18n-pt.global.js"
65
+ },
66
+ "./browser/qu": {
67
+ "default": "./dist/hyperscript-i18n-qu.global.js"
68
+ },
69
+ "./browser/ru": {
70
+ "default": "./dist/hyperscript-i18n-ru.global.js"
71
+ },
72
+ "./browser/sw": {
73
+ "default": "./dist/hyperscript-i18n-sw.global.js"
74
+ },
75
+ "./browser/th": {
76
+ "default": "./dist/hyperscript-i18n-th.global.js"
77
+ },
78
+ "./browser/tl": {
79
+ "default": "./dist/hyperscript-i18n-tl.global.js"
80
+ },
81
+ "./browser/tr": {
82
+ "default": "./dist/hyperscript-i18n-tr.global.js"
83
+ },
84
+ "./browser/uk": {
85
+ "default": "./dist/hyperscript-i18n-uk.global.js"
86
+ },
87
+ "./browser/vi": {
88
+ "default": "./dist/hyperscript-i18n-vi.global.js"
89
+ },
90
+ "./browser/zh": {
91
+ "default": "./dist/hyperscript-i18n-zh.global.js"
92
+ },
93
+ "./browser/western": {
94
+ "default": "./dist/hyperscript-i18n-western.global.js"
95
+ },
96
+ "./browser/east-asian": {
97
+ "default": "./dist/hyperscript-i18n-east-asian.global.js"
98
+ },
99
+ "./browser/south-asian": {
100
+ "default": "./dist/hyperscript-i18n-south-asian.global.js"
101
+ },
102
+ "./browser/southeast-asian": {
103
+ "default": "./dist/hyperscript-i18n-southeast-asian.global.js"
104
+ },
105
+ "./browser/slavic": {
106
+ "default": "./dist/hyperscript-i18n-slavic.global.js"
107
+ }
108
+ },
109
+ "scripts": {
110
+ "generate:syntax": "npx tsx scripts/generate-syntax.ts",
111
+ "prebuild": "npm run generate:syntax",
112
+ "build": "tsup",
113
+ "dev": "tsup --watch",
114
+ "test": "vitest",
115
+ "test:run": "vitest run",
116
+ "test:check": "vitest run --reporter=dot 2>&1 | tail -5",
117
+ "test:browser": "npx playwright test",
118
+ "typecheck": "tsc --noEmit"
119
+ },
120
+ "keywords": [
121
+ "hyperscript",
122
+ "_hyperscript",
123
+ "i18n",
124
+ "internationalization",
125
+ "multilingual",
126
+ "localization",
127
+ "plugin",
128
+ "adapter",
129
+ "translation",
130
+ "lokascript",
131
+ "preprocessor"
132
+ ],
133
+ "author": "LokaScript Contributors",
134
+ "license": "MIT",
135
+ "repository": {
136
+ "type": "git",
137
+ "url": "git+https://github.com/codetalcott/hyperfixi.git",
138
+ "directory": "packages/hyperscript-adapter"
139
+ },
140
+ "bugs": {
141
+ "url": "https://github.com/codetalcott/hyperfixi/issues"
142
+ },
143
+ "homepage": "https://github.com/codetalcott/hyperfixi/tree/main/packages/hyperscript-adapter#readme",
144
+ "dependencies": {
145
+ "@lokascript/semantic": "*"
146
+ },
147
+ "optionalDependencies": {
148
+ "@lokascript/i18n": "*"
149
+ },
150
+ "devDependencies": {
151
+ "@types/node": "^20.0.0",
152
+ "tsup": "^8.0.0",
153
+ "typescript": "^5.0.0",
154
+ "vitest": "^4.0.0"
155
+ },
156
+ "files": [
157
+ "dist",
158
+ "src",
159
+ "README.md",
160
+ "LICENSE"
161
+ ],
162
+ "engines": {
163
+ "node": ">=18.0.0"
164
+ },
165
+ "sideEffects": false,
166
+ "publishConfig": {
167
+ "access": "public"
168
+ }
169
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Lite Browser Bundle (~4 KB)
3
+ *
4
+ * Lightweight adapter that expects @lokascript/semantic to be loaded
5
+ * separately (any regional bundle). Pair with whichever semantic bundle
6
+ * matches your target languages.
7
+ *
8
+ * @example
9
+ * <script src="_hyperscript.js"></script>
10
+ * <script src="lokascript-semantic-es.global.js"></script>
11
+ * <script src="hyperscript-i18n-lite.global.js"></script>
12
+ *
13
+ * <button _="on click alternar .active" data-lang="es">Toggle</button>
14
+ */
15
+
16
+ import { resolveLanguage } from './language-resolver';
17
+ import type { PluginOptions } from './plugin';
18
+ import type { PreprocessorConfig } from './preprocessor';
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // Detect semantic global
22
+ // ---------------------------------------------------------------------------
23
+
24
+ interface SemanticGlobal {
25
+ parse: (input: string, lang: string) => unknown;
26
+ render: (node: unknown, lang: string) => string;
27
+ translate?: (input: string, src: string, tgt: string) => string;
28
+ createSemanticAnalyzer?: () => {
29
+ analyze: (input: string, lang: string) => { confidence: number; node?: unknown };
30
+ supportsLanguage: (lang: string) => boolean;
31
+ };
32
+ getSupportedLanguages?: () => string[];
33
+ }
34
+
35
+ function findSemanticGlobal(): SemanticGlobal | null {
36
+ if (typeof globalThis === 'undefined') return null;
37
+ const g = globalThis as Record<string, unknown>;
38
+
39
+ // Check known global names (full → regional → single-language)
40
+ const candidates = [
41
+ 'LokaScriptSemantic',
42
+ 'LokaScriptSemanticPriority',
43
+ 'LokaScriptSemanticWestern',
44
+ 'LokaScriptSemanticEastAsian',
45
+ 'LokaScriptSemanticEsEn',
46
+ 'LokaScriptSemanticEn',
47
+ 'LokaScriptSemanticEs',
48
+ ];
49
+
50
+ for (const name of candidates) {
51
+ const obj = g[name];
52
+ if (obj && typeof obj === 'object' && 'parse' in obj && 'render' in obj) {
53
+ return obj as SemanticGlobal;
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // Preprocessor (uses external semantic global)
61
+ // ---------------------------------------------------------------------------
62
+
63
+ function preprocessToEnglish(
64
+ src: string,
65
+ lang: string,
66
+ semantic: SemanticGlobal,
67
+ _config: Partial<PreprocessorConfig>
68
+ ): string {
69
+ try {
70
+ // Prefer translate() if available (combines parse+render)
71
+ if (semantic.translate) {
72
+ return semantic.translate(src, lang, 'en');
73
+ }
74
+
75
+ // Fallback: parse then render
76
+ const node = semantic.parse(src, lang);
77
+ if (node) {
78
+ return semantic.render(node, 'en');
79
+ }
80
+ } catch {
81
+ // Fall through
82
+ }
83
+
84
+ return src;
85
+ }
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // Plugin
89
+ // ---------------------------------------------------------------------------
90
+
91
+ export function hyperscriptI18n(options: PluginOptions = {}) {
92
+ return function plugin(hs: unknown): void {
93
+ const semantic = findSemanticGlobal();
94
+ if (!semantic) {
95
+ console.warn(
96
+ '[hyperscript-i18n] No LokaScriptSemantic global found. ' +
97
+ 'Load a semantic bundle before the adapter: ' +
98
+ '<script src="lokascript-semantic.browser.global.js"></script>'
99
+ );
100
+ return;
101
+ }
102
+
103
+ const { internals } = hs as {
104
+ internals: { runtime: { getScript: (elt: Element) => string | null } };
105
+ };
106
+ const runtime = internals.runtime;
107
+ const originalGetScript = runtime.getScript.bind(runtime);
108
+
109
+ runtime.getScript = function (elt: Element): string | null {
110
+ const src = originalGetScript(elt);
111
+ if (!src) return null;
112
+
113
+ const lang = resolveLanguageWithOptions(elt, options);
114
+ if (!lang || lang === 'en') return src;
115
+
116
+ const english = preprocessToEnglish(src, lang, semantic, options);
117
+
118
+ if (options.debug && english !== src) {
119
+ console.log(`[hyperscript-i18n] ${lang}: "${src}" → "${english}"`);
120
+ }
121
+
122
+ return english;
123
+ };
124
+
125
+ if (options.debug) {
126
+ const langs = semantic.getSupportedLanguages?.() ?? ['(unknown)'];
127
+ console.log(`[hyperscript-i18n] Lite adapter loaded. Languages: ${langs.join(', ')}`);
128
+ }
129
+ };
130
+ }
131
+
132
+ function resolveLanguageWithOptions(elt: Element, options: PluginOptions): string | null {
133
+ if (options.languageAttribute) {
134
+ const custom = elt.getAttribute(options.languageAttribute);
135
+ if (custom) return custom.split('-')[0].toLowerCase();
136
+ }
137
+ const resolved = resolveLanguage(elt);
138
+ if (resolved) return resolved;
139
+ return options.defaultLanguage ?? null;
140
+ }
141
+
142
+ export function preprocess(src: string, lang: string): string {
143
+ if (lang === 'en') return src;
144
+ const semantic = findSemanticGlobal();
145
+ if (!semantic) throw new Error('No LokaScriptSemantic global found');
146
+ return preprocessToEnglish(src, lang, semantic, {});
147
+ }
148
+
149
+ export { resolveLanguage };
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // Auto-register
153
+ // ---------------------------------------------------------------------------
154
+
155
+ declare const _hyperscript: { use: (plugin: unknown) => void } | undefined;
156
+
157
+ if (typeof _hyperscript !== 'undefined' && _hyperscript.use) {
158
+ _hyperscript.use(hyperscriptI18n());
159
+ }
package/src/browser.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Browser bundle entry point.
3
+ *
4
+ * Exposes the plugin as a global `HyperscriptI18n` object for use
5
+ * with a <script> tag alongside the original _hyperscript.
6
+ *
7
+ * Usage (self-contained — bundles semantic parser):
8
+ * <script src="_hyperscript.js"></script>
9
+ * <script src="hyperscript-i18n.global.js"></script>
10
+ * <!-- Auto-registers on load -->
11
+ *
12
+ * Usage (manual registration):
13
+ * <script src="_hyperscript.js"></script>
14
+ * <script src="hyperscript-i18n.global.js"></script>
15
+ * <script>
16
+ * // Already auto-registered, or manually:
17
+ * _hyperscript.use(HyperscriptI18n.plugin({ debug: true }));
18
+ * </script>
19
+ */
20
+
21
+ // Import semantic package — exports reference ensures languages get registered
22
+ import { getSupportedLanguages, VERSION } from '@lokascript/semantic';
23
+
24
+ import { hyperscriptI18n, preprocess } from './plugin';
25
+ import { preprocessToEnglish } from './preprocessor';
26
+ import { resolveLanguage } from './language-resolver';
27
+
28
+ // Re-export to prevent tree-shaking the semantic import
29
+ export const semanticVersion = VERSION;
30
+ export const supportedLanguages = getSupportedLanguages();
31
+
32
+ export { hyperscriptI18n as plugin, preprocess, preprocessToEnglish, resolveLanguage };
33
+
34
+ // Auto-register if _hyperscript is available globally
35
+ declare const _hyperscript: { use: (plugin: unknown) => void } | undefined;
36
+
37
+ if (typeof _hyperscript !== 'undefined' && _hyperscript.use) {
38
+ _hyperscript.use(hyperscriptI18n());
39
+ reprocessInitializedElements();
40
+ }
41
+
42
+ /**
43
+ * _hyperscript processes the DOM immediately on load (via browserInit()),
44
+ * so elements are already marked as initialized with unparsed multilingual
45
+ * text by the time the adapter registers. Clear the initialized flag on
46
+ * all script-bearing elements and re-process them through the patched
47
+ * getScript() pipeline.
48
+ */
49
+ function reprocessInitializedElements(): void {
50
+ if (typeof document === 'undefined') return;
51
+
52
+ const hs = _hyperscript as unknown as {
53
+ internals?: {
54
+ runtime?: {
55
+ getInternalData: (el: Element) => { initialized?: boolean };
56
+ processNode: (el: Element) => void;
57
+ getScriptSelector: () => string;
58
+ };
59
+ };
60
+ };
61
+
62
+ const runtime = hs?.internals?.runtime;
63
+ if (!runtime?.processNode || !runtime?.getInternalData) return;
64
+
65
+ const selector = runtime.getScriptSelector?.() ?? '[_], [script], [data-script]';
66
+ document.querySelectorAll(selector).forEach(el => {
67
+ const data = runtime.getInternalData(el);
68
+ if (data.initialized) {
69
+ data.initialized = false;
70
+ }
71
+ });
72
+
73
+ runtime.processNode(document.body);
74
+ }
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Arabic (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/ar';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['ar'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Bengali (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/bn';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['bn'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: German (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/de';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['de'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,8 @@
1
+ /** Self-contained: East Asian languages (ja, ko, zh) */
2
+ import '@lokascript/semantic/languages/ja';
3
+ import '@lokascript/semantic/languages/ko';
4
+ import '@lokascript/semantic/languages/zh';
5
+ export { plugin, preprocess, resolveLanguage } from './shared';
6
+ export const supportedLanguages = ['ja', 'ko', 'zh'];
7
+ import { autoRegister } from './shared';
8
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: English-only (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/en';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['en'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Spanish (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/es';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['es'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: French (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/fr';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['fr'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Hebrew (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/he';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['he'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Hindi (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/hi';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['hi'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Indonesian (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/id';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['id'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Italian (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/it';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['it'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Japanese (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/ja';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['ja'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Korean (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/ko';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['ko'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Malay (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/ms';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['ms'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Polish (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/pl';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['pl'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Portuguese (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/pt';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['pt'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Quechua (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/qu';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['qu'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Russian (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/ru';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['ru'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Shared bundle boilerplate.
3
+ * Each per-language entry imports languages, then calls setup().
4
+ *
5
+ * Also wires up the pattern generator so that registered languages
6
+ * can have their patterns generated on demand from their profiles.
7
+ * Without this, getPatternsForLanguage() throws for non-English
8
+ * languages that only register a tokenizer + profile.
9
+ */
10
+
11
+ import {
12
+ setPatternGenerator,
13
+ generatePatternsForLanguage,
14
+ type LanguageProfile,
15
+ } from '@lokascript/semantic/core';
16
+ import { hyperscriptI18n, preprocess } from '../slim-plugin';
17
+ import { resolveLanguage } from '../language-resolver';
18
+
19
+ // Enable on-demand pattern generation for registered languages.
20
+ setPatternGenerator((profile: LanguageProfile) => generatePatternsForLanguage(profile));
21
+
22
+ export { hyperscriptI18n as plugin, preprocess, resolveLanguage };
23
+
24
+ declare const _hyperscript: { use: (plugin: unknown) => void } | undefined;
25
+
26
+ export function autoRegister(): void {
27
+ if (typeof _hyperscript !== 'undefined' && _hyperscript.use) {
28
+ _hyperscript.use(hyperscriptI18n());
29
+ reprocessInitializedElements();
30
+ }
31
+ }
32
+
33
+ /**
34
+ * _hyperscript processes the DOM immediately on load (via browserInit()),
35
+ * so elements are already marked as initialized with unparsed multilingual
36
+ * text by the time the adapter registers. Clear the initialized flag on
37
+ * all script-bearing elements and re-process them through the patched
38
+ * getScript() pipeline.
39
+ */
40
+ function reprocessInitializedElements(): void {
41
+ if (typeof document === 'undefined') return;
42
+
43
+ const hs = _hyperscript as unknown as {
44
+ internals?: {
45
+ runtime?: {
46
+ getInternalData: (el: Element) => { initialized?: boolean };
47
+ processNode: (el: Element) => void;
48
+ getScriptSelector: () => string;
49
+ };
50
+ };
51
+ };
52
+
53
+ const runtime = hs?.internals?.runtime;
54
+ if (!runtime?.processNode || !runtime?.getInternalData) return;
55
+
56
+ const selector = runtime.getScriptSelector?.() ?? '[_], [script], [data-script]';
57
+ document.querySelectorAll(selector).forEach(el => {
58
+ const data = runtime.getInternalData(el);
59
+ if (data.initialized) {
60
+ data.initialized = false;
61
+ }
62
+ });
63
+
64
+ runtime.processNode(document.body);
65
+ }
@@ -0,0 +1,8 @@
1
+ /** Self-contained: Slavic languages (ru, pl, uk) */
2
+ import '@lokascript/semantic/languages/ru';
3
+ import '@lokascript/semantic/languages/pl';
4
+ import '@lokascript/semantic/languages/uk';
5
+ export { plugin, preprocess, resolveLanguage } from './shared';
6
+ export const supportedLanguages = ['ru', 'pl', 'uk'];
7
+ import { autoRegister } from './shared';
8
+ autoRegister();
@@ -0,0 +1,7 @@
1
+ /** Self-contained: South Asian languages (hi, bn) */
2
+ import '@lokascript/semantic/languages/hi';
3
+ import '@lokascript/semantic/languages/bn';
4
+ export { plugin, preprocess, resolveLanguage } from './shared';
5
+ export const supportedLanguages = ['hi', 'bn'];
6
+ import { autoRegister } from './shared';
7
+ autoRegister();
@@ -0,0 +1,10 @@
1
+ /** Self-contained: Southeast Asian languages (id, ms, tl, th, vi) */
2
+ import '@lokascript/semantic/languages/id';
3
+ import '@lokascript/semantic/languages/ms';
4
+ import '@lokascript/semantic/languages/tl';
5
+ import '@lokascript/semantic/languages/th';
6
+ import '@lokascript/semantic/languages/vi';
7
+ export { plugin, preprocess, resolveLanguage } from './shared';
8
+ export const supportedLanguages = ['id', 'ms', 'tl', 'th', 'vi'];
9
+ import { autoRegister } from './shared';
10
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Swahili (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/sw';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['sw'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Thai (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/th';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['th'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();
@@ -0,0 +1,6 @@
1
+ /** Self-contained: Tagalog (renders to English via custom renderer) */
2
+ import '@lokascript/semantic/languages/tl';
3
+ export { plugin, preprocess, resolveLanguage } from './shared';
4
+ export const supportedLanguages = ['tl'];
5
+ import { autoRegister } from './shared';
6
+ autoRegister();