/** * @packageDocumentation * * A pure-JavaScript implementation of the {@link https://lynxjs.org/guide/spec.html | Lynx Spec}, * notably the {@link https://lynxjs.org/api/engine/element-api | Element PAPI} and {@link https://lynxjs.org/guide/spec#dual-threaded-model | Dual-threaded Model} for use with Node.js. */ import { LynxGlobalThis } from './lynx/GlobalThis.js'; import { initElementTree } from './lynx/ElementPAPI.js'; export { initElementTree } from './lynx/ElementPAPI.js'; export type { LynxElement } from './lynx/ElementPAPI.js'; export type { LynxGlobalThis } from './lynx/GlobalThis.js'; export { GlobalEventEmitter } from './lynx/GlobalEventEmitter.js'; /** * The host environment used to initialize `LynxTestingEnv`. * * @public */ export interface LynxEnv { window: Window & typeof globalThis; } /** * @public * The lynx element tree */ export type ElementTree = ReturnType; /** * @public */ export type FilterUnderscoreKeys = { [K in keyof T]: K extends `__${string}` ? K : never; }[keyof T]; /** * @public */ export type PickUnderscoreKeys = Pick>; /** * The Element PAPI Types * @public */ export type ElementTreeGlobals = PickUnderscoreKeys; declare global { var lynxEnv: LynxEnv; var lynxTestingEnv: LynxTestingEnv; var elementTree: ElementTree; var __JS__: boolean; var __LEPUS__: boolean; var __BACKGROUND__: boolean; var __MAIN_THREAD__: boolean; namespace lynxCoreInject { var tt: any; } /** * Called after background thread globals are injected. Use to add framework-specific * globals (e.g. Vue runtime, custom modules) to the background thread. * @public */ function onInjectBackgroundThreadGlobals(globals: any): void; /** * Called after main thread globals are injected. Use to add framework-specific * globals to the main thread. * @public */ function onInjectMainThreadGlobals(globals: any): void; /** * Called each time the active thread switches to the background thread. * @public */ function onSwitchedToBackgroundThread(): void; /** * Called each time the active thread switches to the main thread. * @public */ function onSwitchedToMainThread(): void; /** * Called when `LynxTestingEnv.reset()` completes. Use to re-apply framework state. * @public */ function onResetLynxTestingEnv(): void; /** * Called when the worklet runtime chunk is loaded. Return the worklet runtime module. * @public */ function onInitWorkletRuntime(): unknown; } /** * Installs a `LynxTestingEnv` instance and its required globals onto a target. * * @public */ export declare function installLynxTestingEnv(target: typeof globalThis & { lynxEnv?: LynxEnv; lynxTestingEnv?: LynxTestingEnv; Node?: typeof Node; }, env: LynxEnv): void; /** * Removes the globals installed by `installLynxTestingEnv`. * * @public */ export declare function uninstallLynxTestingEnv(target: typeof globalThis & { lynxEnv?: LynxEnv; lynxTestingEnv?: LynxTestingEnv; Node?: typeof Node; }): void; /** * A pure-JavaScript implementation of the {@link https://lynxjs.org/guide/spec.html | Lynx Spec}, * notably the {@link https://lynxjs.org/api/engine/element-api | Element PAPI} and {@link https://lynxjs.org/guide/spec#dual-threaded-model | Dual-threaded Model} for use with Node.js. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToMainThread(); * // use the main thread Element PAPI * const page = __CreatePage('0', 0); * const view = __CreateView(0); * __AppendElement(page, view); * * ``` * * @public */ export declare class LynxTestingEnv { private originals; /** * The global object for the background thread. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToBackgroundThread(); * // use the background thread global object * globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args); * ``` */ backgroundThread: LynxGlobalThis; /** * The global object for the main thread. * * @example * * ```ts * import { LynxTestingEnv } from '@lynx-js/testing-environment'; * import { JSDOM } from 'jsdom'; * * const lynxTestingEnv = new LynxTestingEnv({ window: new JSDOM().window }); * * lynxTestingEnv.switchToMainThread(); * // use the main thread global object * const page = globalThis.__CreatePage('0', 0); * const view = globalThis.__CreateView(0); * globalThis.__AppendElement(page, view); * ``` */ mainThread: LynxGlobalThis & ElementTreeGlobals; env: LynxEnv; constructor(env?: LynxEnv); injectGlobals(): void; switchToBackgroundThread(): void; switchToMainThread(): void; clearGlobal(): void; reset(): void; }