UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

48 lines (39 loc) 1.98 kB
/** * SSR-safe base classes for browser globals that are not available in Node/SSR environments. * * Use these instead of extending browser globals directly so that class definitions * do not throw a ReferenceError at module evaluation time in SSR/Node contexts * (SvelteKit, Next.js, etc.). * * In browser environments each constant is the real global; in SSR it falls back * to a plain empty class so that `class Foo extends HTMLElementBase` is valid. */ /** True when running in an SSR/Node environment (no browser globals). */ export const SSR: boolean = typeof window === "undefined"; /** SSR-safe base class for web components. */ export const HTMLElementBase: typeof HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : (class { } as unknown as typeof HTMLElement); /** SSR-safe base class for pointer events. */ export const PointerEventBase: typeof PointerEvent = typeof PointerEvent !== "undefined" ? PointerEvent : (class { } as unknown as typeof PointerEvent); /** SSR-safe base class for keyboard events. */ export const KeyboardEventBase: typeof KeyboardEvent = typeof KeyboardEvent !== "undefined" ? KeyboardEvent : (class { } as unknown as typeof KeyboardEvent); // #region minimal polyfills // Three.js FileLoader uses ProgressEvent in fetch stream callbacks. // It doesn't exist in Node — install a minimal stub so SSR doesn't crash. if (typeof globalThis.ProgressEvent === "undefined") { (globalThis as any).ProgressEvent = class ProgressEvent { readonly type: string; readonly lengthComputable: boolean; readonly loaded: number; readonly total: number; constructor(type: string, init?: { lengthComputable?: boolean; loaded?: number; total?: number }) { this.type = type; this.lengthComputable = init?.lengthComputable ?? false; this.loaded = init?.loaded ?? 0; this.total = init?.total ?? 0; } }; } // #endregion