PyScript Core Documentation (#1560)

This commit is contained in:
Andrea Giammarchi
2023-06-27 16:53:19 +02:00
committed by GitHub
parent bf6470c046
commit 9121071ba3
18 changed files with 627 additions and 69 deletions

View File

@@ -46,7 +46,7 @@ export const handleCustomType = (node) => {
version,
config,
env,
onRuntimeReady,
onInterpreterReady,
} = options;
const name = getRuntimeID(runtime, version);
const id = env || `${name}${config ? `|${config}` : ""}`;
@@ -67,7 +67,7 @@ export const handleCustomType = (node) => {
onAfterRunAsync,
} = options;
const hooks = new Hook(options);
const hooks = new Hook(interpreter, options);
const XWorker = function XWorker(...args) {
return Worker.apply(hooks, args);
@@ -121,7 +121,7 @@ export const handleCustomType = (node) => {
resolve(resolved);
onRuntimeReady?.(resolved, node);
onInterpreterReady?.(resolved, node);
});
}
}
@@ -134,17 +134,17 @@ export const handleCustomType = (node) => {
const registry = new Map();
/**
* @typedef {Object} PluginOptions custom configuration
* @typedef {Object} CustomOptions custom configuration
* @prop {'pyodide' | 'micropython' | 'wasmoon' | 'ruby-wasm-wasi'} interpreter the interpreter to use
* @prop {string} [version] the optional interpreter version to use
* @prop {string} [config] the optional config to use within such interpreter
* @prop {(environment: object, node: Element) => void} [onRuntimeReady] the callback that will be invoked once
* @prop {(environment: object, node: Element) => void} [onInterpreterReady] the callback that will be invoked once
*/
/**
* Allows custom types and components on the page to receive interpreters to execute any code
* @param {string} type the unique `<script type="...">` identifier
* @param {PluginOptions} options the custom type configuration
* @param {CustomOptions} options the custom type configuration
*/
export const define = (type, options) => {
if (defaultRegistry.has(type) || registry.has(type))