@lokascript/hyperscript-adapter 2.10.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +16 -11
  2. package/dist/hyperscript-i18n-ar.global.js +5 -6
  3. package/dist/hyperscript-i18n-bn.global.js +5 -6
  4. package/dist/hyperscript-i18n-de.global.js +5 -6
  5. package/dist/hyperscript-i18n-east-asian.global.js +5 -6
  6. package/dist/hyperscript-i18n-en.global.js +7 -8
  7. package/dist/hyperscript-i18n-es.global.js +5 -6
  8. package/dist/hyperscript-i18n-fr.global.js +5 -6
  9. package/dist/hyperscript-i18n-he.global.js +5 -6
  10. package/dist/hyperscript-i18n-hi.global.js +5 -6
  11. package/dist/hyperscript-i18n-id.global.js +5 -6
  12. package/dist/hyperscript-i18n-it.global.js +5 -6
  13. package/dist/hyperscript-i18n-ja.global.js +5 -6
  14. package/dist/hyperscript-i18n-ko.global.js +5 -6
  15. package/dist/hyperscript-i18n-lite.global.js +2 -2
  16. package/dist/hyperscript-i18n-ms.global.js +5 -6
  17. package/dist/hyperscript-i18n-pl.global.js +5 -6
  18. package/dist/hyperscript-i18n-pt.global.js +5 -6
  19. package/dist/hyperscript-i18n-qu.global.js +5 -6
  20. package/dist/hyperscript-i18n-ru.global.js +5 -6
  21. package/dist/hyperscript-i18n-slavic.global.js +5 -6
  22. package/dist/hyperscript-i18n-south-asian.global.js +5 -6
  23. package/dist/hyperscript-i18n-southeast-asian.global.js +5 -6
  24. package/dist/hyperscript-i18n-sw.global.js +5 -6
  25. package/dist/hyperscript-i18n-th.global.js +5 -6
  26. package/dist/hyperscript-i18n-tl.global.js +5 -6
  27. package/dist/hyperscript-i18n-tr.global.js +5 -6
  28. package/dist/hyperscript-i18n-uk.global.js +5 -6
  29. package/dist/hyperscript-i18n-vi.global.js +5 -6
  30. package/dist/hyperscript-i18n-western.global.js +5 -6
  31. package/dist/hyperscript-i18n-zh.global.js +5 -6
  32. package/dist/hyperscript-i18n.global.js +27 -28
  33. package/dist/hyperscript-i18n.global.js.map +1 -1
  34. package/dist/index.cjs +107 -86
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +75 -12
  37. package/dist/index.d.ts +75 -12
  38. package/dist/index.js +107 -93
  39. package/dist/index.js.map +1 -1
  40. package/package.json +2 -2
  41. package/src/attribute-translator.ts +12 -7
  42. package/src/browser-lite.ts +18 -3
  43. package/src/host-validate.ts +63 -0
  44. package/src/hyperscript-renderer.ts +64 -5
  45. package/src/index.ts +6 -1
  46. package/src/language-resolver.ts +15 -3
  47. package/src/plugin.ts +57 -7
  48. package/src/preprocessor-core.ts +217 -0
  49. package/src/preprocessor.ts +14 -215
  50. package/src/slim-plugin.ts +18 -3
  51. package/src/slim-preprocessor.ts +16 -154
package/README.md CHANGED
@@ -112,21 +112,26 @@ The plugin resolves language in this order:
112
112
 
113
113
  1. `data-lang` attribute on the element
114
114
  2. `data-hyperscript-lang` on the element or closest ancestor
115
- 3. `<html lang="...">` on the document
116
- 4. `defaultLanguage` option (if configured)
115
+ 3. `lang` attribute on the element or closest ancestor (the standard HTML
116
+ cascade — a `<section lang="es">` localizes everything inside it, and a
117
+ nested `lang="en"` opts back out)
118
+ 4. `<html lang="...">` on the document (reached via step 3 for attached
119
+ elements; still applies to detached fragments)
120
+ 5. `defaultLanguage` option (if configured)
117
121
 
118
122
  English (`en`) and unresolved languages pass through without translation.
119
123
 
120
124
  ## Options
121
125
 
122
- | Option | Type | Default | Description |
123
- | --------------------- | ---------------------------------- | ------------- | ------------------------------------------------------------- |
124
- | `defaultLanguage` | `string` | — | Default language for all elements |
125
- | `languageAttribute` | `string` | `"data-lang"` | Custom attribute name for per-element language |
126
- | `confidenceThreshold` | `number \| Record<string, number>` | `0.5` | Min confidence (0–1). Per-language map supported (see below). |
127
- | `strategy` | `'semantic' \| 'i18n' \| 'auto'` | `'semantic'` | Translation strategy |
128
- | `debug` | `boolean` | `false` | Log translations to console |
129
- | `i18nToEnglish` | `function` | — | Optional `@lokascript/i18n` `toEnglish` function for fallback |
126
+ | Option | Type | Default | Description |
127
+ | --------------------- | ---------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------ |
128
+ | `defaultLanguage` | `string` | — | Default language for all elements |
129
+ | `languageAttribute` | `string` | `"data-lang"` | Custom attribute name for per-element language |
130
+ | `confidenceThreshold` | `number \| Record<string, number>` | `0.5` | Min confidence (0–1). Per-language map supported (see below). |
131
+ | `strategy` | `'semantic' \| 'i18n' \| 'auto'` | `'semantic'` | Translation strategy |
132
+ | `debug` | `boolean` | `false` | Log translations to console |
133
+ | `i18nToEnglish` | `function` | — | Optional `@lokascript/i18n` `toEnglish` function for fallback |
134
+ | `validateWithHost` | `boolean` | `true` | Check rendered English on the host parser; on rejection keep the original text (no-op on builds without `parse()`) |
130
135
 
131
136
  ### Per-language confidence thresholds
132
137
 
@@ -147,7 +152,7 @@ _hyperscript.use(
147
152
 
148
153
  ## How It Works
149
154
 
150
- The plugin overrides `runtime.getScript()` — the method \_hyperscript calls to read `_="..."` attributes. Non-English input is translated to English via the `@lokascript/semantic` parser before reaching the lexer. No changes to \_hyperscript internals.
155
+ The plugin registers an `addBeforeProcessHook` callback — \_hyperscript's supported public extension point, which fires before the runtime reads `_="..."` attributes (or `<script type="text/hyperscript">` bodies). Non-English input is rewritten to English in place via the `@lokascript/semantic` parser before the runtime's own scan reaches it, and the rendered English is checked on the host's own parser before it is committed (see `validateWithHost`). No \_hyperscript internals are patched. Requires a \_hyperscript build that exposes `addBeforeProcessHook` (0.9.9x era).
151
156
 
152
157
  ## Limitations
153
158