@hyperfixi/types-browser
v4.0.1
Published
TypeScript definitions for the hyperfixi browser globals: window.hyperfixi / window._hyperscript (the engine), LokaScriptSemantic, LokaScriptI18n
Downloads
574
Maintainers
Readme
@hyperfixi/types-browser
TypeScript type definitions for the hyperfixi browser globals.
Installation
npm install --save-dev @hyperfixi/types-browserUsage
Add to your tsconfig.json:
{
"compilerOptions": {
"types": ["@hyperfixi/types-browser"]
}
}The globals are then typed:
window.hyperfixi.evaluate('toggle .active on me', { me: button });
window._hyperscript.parse('on click add .highlight').errors; // []
window.LokaScriptSemantic.parse('トグル .active', 'ja');
window.LokaScriptSemantic.translate('toggle .active', 'en', 'ko');
window.LokaScriptI18n.getProfile('ja');Provided Types
window.hyperfixi / window._hyperscript
One object, HyperfixiAPI: the public API of @hyperfixi/engine, which its hyperfixi-hs.js
installs (and @hyperfixi/core's hyperfixi.js, the same file). It is shaped like upstream
_hyperscript's:
hyperfixi(source, context?)/evaluate(source, context?)— run commands, features or an expression;context.meis the elementmerefers toparse(source)— parse without running; grammar errors are in.errorsprocess(node)/processNode(node)— initialise the scripted elements under a nodecleanup(element)— remove what an element's script installedconfig— settings, and theas <Name>conversion tableuse(plugin),addBeforeProcessHook(hook),addAfterProcessHook(hook)— upstream's plugin APIaddSourceTransform(transform)— not in upstream: rewrite a script as it is readversion
The package's typecheck checks the engine's own api against HyperfixiAPI, so the two cannot
drift apart.
4.0: until then
window.hyperfixiwas typed as@hyperfixi/core's own API (compile,compileSync,execute,createContext,evalHyperScript, …).hyperfixi.jsis the engine's file now, and none of those exist on it:compileSync(code)→parse(code).errors;execute(code, el)→evaluate(code, { me: el });compile(code, { language })→ load@lokascript/hyperscript-adapterbeside a semantic bundle.window.lokascriptis gone.LokaScriptCoreAPIremains as a deprecated alias ofHyperfixiAPI. (3.x's publishedindex.d.tsalso never reached its window augmentation:globals.d.tswas not emitted.)
window.LokaScriptSemantic
Semantic parsing and translation API (from @lokascript/semantic's browser bundles):
parse(source, language)- Parse in any of 24 languagestranslate(source, fromLang, toLang)- Translate between languagesgetAllTranslations(source, sourceLang)- Get all translationscreateSemanticAnalyzer(options?)- Create analyzersupportedLanguages- Array of supported language codes
window.LokaScriptI18n
Language vocabulary API (from lokascript-i18n.min.js):
supportedLocales- Array of supported localesgetProfile(locale)- Get language grammar profile
translate(source, fromLang, toLang)andcreateTransformer(options?)were removed in 3.0.0 along with@lokascript/i18n's grammar transformer. Translation lives onwindow.LokaScriptSemantic.translate— it parses to a semantic node and renders from it, so the output re-parses in the target language.
Browser Bundle Loading
<script src="https://cdn.jsdelivr.net/npm/@hyperfixi/engine/dist/hyperfixi-hs.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lokascript/semantic/dist/browser.global.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lokascript/i18n/dist/lokascript-i18n.min.js"></script>
<script>
window.hyperfixi.evaluate('add .ready to me', { me: document.body });
window.LokaScriptSemantic.translate('toggle .active', 'en', 'ja');
</script>License
MIT
