/** * HoloScript+ Runtime Engine * * Executes parsed HoloScript+ AST with: * - Control flow (@for, @if) evaluation * - Lifecycle hook management * - VR trait integration * - Reactive state binding * - TypeScript companion integration * * @version 1.0.0 */ import type { HSPlusAST, HSPlusNode, HSPlusRuntime, VRHand, Vector3 } from '@holoscript/core'; import { TraitEvent } from '@holoscript/core'; import { HoloStatement } from '@holoscript/core'; import { type NetworkState } from './NetworkPredictor'; import type { WebXRFrameEvidence } from '../vr/WebXRFrameEvidence'; import { KeyboardSystem } from './KeyboardSystem'; import { HandMenuSystem } from './HandMenuSystem'; type LifecycleHandler = (...args: unknown[]) => void; export interface NodeInstance { __holo_id: string; node: HSPlusNode; properties: Record; renderedNode: unknown; lifecycleHandlers: Map; children: NodeInstance[]; parent: NodeInstance | null; destroyed: boolean; templateName?: string; templateVersion?: number; dirty: boolean; hasTraits: boolean; } export interface RuntimeOptions { renderer?: Renderer; vrEnabled?: boolean; companions?: Record unknown>>; manifestUrl?: string; baseUrl?: string; webXrManagerClass?: unknown; } export interface Renderer { createElement(type: string, properties: Record): unknown; updateElement(element: unknown, properties: Record): void; appendChild(parent: unknown, child: unknown): void; removeChild(parent: unknown, child: unknown): void; destroy(element: unknown): void; setXRSession?(session: XRSession | null, glBinding: unknown | null, projectionLayer: unknown | null): void; } /** Extended renderer interface for WebXR-capable renderers (e.g. WebGPURenderer). */ export declare class HoloScriptPlusRuntimeImpl implements HSPlusRuntime { private ast; private options; state: any; private evaluator; private builtins; private traitRegistry; private rootInstance; private eventHandlers; private templates; private updateLoopId; private lastUpdateTime; private companions; private networkSync; private mounted; private scaleMultiplier; private chunkLoader; private hotReloader; private networkPredictor; private movementPredictor; private _flatEntities; private _copilot; /** * Set the AI Copilot for generate directive processing. */ setCopilot(copilot: { isReady(): boolean; generateFromPrompt(prompt: string, options: Record): Promise; }): void; vrContext: { hands: { left: VRHand | null; right: VRHand | null; }; headset: { position: Vector3; rotation: Vector3; }; controllers: { left: unknown; right: unknown; }; hitTests: WebXRFrameEvidence['hitTests']; geospatialAnchors: WebXRFrameEvidence['geospatialAnchors']; }; private webXrManager; private isXRSessionActive; private physicsWorld; private vrPhysicsBridge; private debugDrawer; keyboardSystem: KeyboardSystem; handMenuSystem: HandMenuSystem; constructor(ast: HSPlusAST, options?: RuntimeOptions); enterVR(): Promise; /** * Main XR Loop - called by WebXRManager */ private xrLoop; exitVR(): Promise; /** * Convert Quaternion to Euler Angles (YXZ sequence) */ private quaternionToEuler; private updateVRInput; private initializeState; private loadImports; mount(container: unknown): void; unmount(): void; /** * Scans the AST for all template definitions, including nested ones. */ private findAllTemplates; /** * Dynamically mount a new object into the scene (e.g. from a lazy-loaded chunk) */ mountObject(node: HSPlusNode, parent?: NodeInstance | null): NodeInstance; unmountObject(idOrInstance: string | NodeInstance): void; private _holoIdCounter; private generateHoloId; private instantiateNode; getNode(id: string): HSPlusNode | undefined; private processDirectives; private registerLifecycleHandler; private processControlFlow; private cloneNodeWithContext; private interpolateString; private interpolateProperties; private evaluateExpression; private evaluateProperties; /** * Expands spread expressions in a properties object. * Spread keys are formatted as __spread_N with value { type: 'spread', argument: ... } */ private expandPropertySpreads; /** * Expands spread expressions within an array. */ private expandArraySpreads; /** * Resolves a spread argument to its runtime value. */ private resolveSpreadArgument; private callLifecycle; private startUpdateLoop; private stopUpdateLoop; update(delta: number): void; /** * Authoritative server sync for networked state. */ onNetworkStateUpdate(serverState: NetworkState>): void; private updateInstance; private syncAvatarParts; private generatedNodes; private processGenerateDirectives; private apiPollingTimers; private updateExternalApis; private executeExternalApi; private parseDurationToMs; private createTraitContext; private destroyInstance; togglePhysicsDebug(enabled: boolean): void; updateData(data: unknown): void; updateNodeProperty(nodeId: string, property: string, value: unknown): void; getState(): Record; getVariable(name: string): unknown; setVariable(name: string, value: unknown): void; getContext(): Record; reset(): void; updateAnimations(): void; updateParticles(delta: number): void; getHologramStates(): Map>; setState(updates: any): void; emit(event: string, payload?: unknown): void; updateEntity(id: string, properties: Partial>): boolean; on(event: string, handler: (payload: unknown) => void): () => void; hotReload(newAst: HSPlusAST): Promise; /** * Creates a Map proxy that reflects the reactive state. * This allowed the HotReloader (designed for Map-based state) to work with * the runtime's Record-based reactive state. */ private createStateMapProxy; findInstanceById(id: string, root?: NodeInstance | null): NodeInstance | null; /** * Executes a block of HoloScript+ statements */ executeStatementBlock(instance: NodeInstance, body: HoloStatement[]): Promise; /** * Executes a single HoloScript+ statement */ executeStatement(instance: NodeInstance, stmt: HoloStatement): Promise; private migrateInstancesOfTemplate; private findAllInstancesOfTemplate; private migrateInstance; private executeMigrationCode; updateVRContext(context: typeof this.vrContext): void; handleVREvent(event: TraitEvent, node: HSPlusNode): void; private findInstance; registerTemplate(name: string, node: HSPlusNode): void; spawnTemplate(name: string, position: Vector3): HSPlusNode; destroyNode(node: HSPlusNode): void; } /** * Create a new HoloScript+ runtime instance */ export declare function createRuntime(ast: HSPlusAST, options?: RuntimeOptions): HSPlusRuntime; export {}; //# sourceMappingURL=HoloScriptPlusRuntime.d.ts.map