{"version":3,"file":"index.cjs","sources":["../node_modules/fixed-len-array/dist/index.es.js","../src/types.ts","../src/pointer/base-pointer.ts","../src/pointer/array-pointer.ts","../src/type-converter.ts","../src/pointer/bool-pointer.ts","../src/pointer/char-pointer.ts","../src/pointer/null-pointer.ts","../src/pointer/number-pointer.ts","../src/pointer/string-pointer.ts"],"sourcesContent":["function l(u, n, e) {\n  const t = u.slice(0, n);\n  for (; t.length < n; )\n    t.push(e ?? null);\n  return t;\n}\nexport {\n  l as toFixedLengthArray\n};\n//# sourceMappingURL=index.es.js.map\n","/**\n * Shared type definitions and conversion utilities for WASM memory operations.\n * This module provides type-safe conversion utilities between JavaScript types\n * and their C equivalents in WebAssembly memory, eliminating redundancy across\n * pointer classes.\n *\n * @author Pt. Prashant Tripathi\n * @since 1.0.0\n */\n\n// =============================================================================\n// Type Definitions\n// =============================================================================\n\n/** C-style numeric types supported by Emscripten */\nexport type C_NumberType = Emscripten.CIntType | Emscripten.CFloatType;\n\n/** C-style boolean type (0 for false, 1 for true) */\nexport type C_BoolType = number;\n\n/** C-style character type (ASCII code 0-255) */\nexport type C_CharType = number;\n\n/** Type constants for C-style booleans */\nexport const C_TRUE: C_BoolType = 1;\nexport const C_FALSE: C_BoolType = 0;\n\n// =============================================================================\n// Size Mappings\n// =============================================================================\n\n/**\n * Size (in bytes) for each WASM number type. Used for memory allocation and\n * pointer arithmetic.\n */\nexport const C_TYPE_SIZES: Readonly<Record<C_NumberType, number>> = {\n    i8: Int8Array.BYTES_PER_ELEMENT,\n    i16: Int16Array.BYTES_PER_ELEMENT,\n    i32: Int32Array.BYTES_PER_ELEMENT,\n    i64: BigInt64Array.BYTES_PER_ELEMENT,\n    float: Float32Array.BYTES_PER_ELEMENT,\n    double: Float64Array.BYTES_PER_ELEMENT,\n} as const;\n\n/**\n * TypeScript bindings for the Emscripten-generated WebAssembly module. Extends\n * the EmscriptenModule with custom wrapped native functions.\n */\nexport interface WASMModule {\n    /** Sets a value in the WebAssembly heap memory. */\n    setValue: typeof setValue;\n\n    /** Retrieves a value from the WebAssembly heap memory. */\n    getValue: typeof getValue;\n\n    /**\n     * Converts a JavaScript string to a UTF-8 encoded string in the WebAssembly\n     * memory.\n     */\n    stringToUTF8: typeof stringToUTF8;\n\n    /**\n     * Converts a UTF-8 encoded string from the WebAssembly memory to a\n     * JavaScript string.\n     */\n    UTF8ToString: typeof UTF8ToString;\n\n    /**\n     * Returns the number of bytes required to encode a JavaScript string as\n     * UTF-8.\n     */\n    lengthBytesUTF8: typeof lengthBytesUTF8;\n\n    /**\n     * Frees allocated memory in the WebAssembly heap.\n     *\n     * Equivalent to `free(void* ptr)` in C.\n     *\n     * @param ptr Pointer to the memory location to free.\n     */\n    _free(ptr: number): void;\n\n    /**\n     * Allocates memory in the WebAssembly heap.\n     *\n     * Equivalent to `malloc(size_t size)` in C.\n     *\n     * @param size Number of bytes to allocate.\n     * @returns A pointer to the beginning of the allocated memory block.\n     */\n    _malloc(size: number): number;\n}\n","import type { WASMModule } from \"../types\";\n\n/**\n * @author Pt. Prashant Tripathi\n * @since 1.0.0\n *\n *   Abstract base class for all WASM memory pointer implementations. Provides\n *   common memory management functionality and enforces a consistent interface\n *   across all pointer types in the wasp-lib library.\n *\n *   This class provides common memory management functionality including\n *   allocation, deallocation, and pointer validation. All specific pointer\n *   types (StringPointer, NumberPointer, etc.) extend this base class.\n * @example\n *     // This is an abstract class - use concrete implementations:\n *     const strPtr = StringPointer.from(wasm, \"Hello World\");\n *     const numPtr = NumberPointer.from(wasm, \"i32\", 42);\n *     const arrPtr = ArrayPointer.from(wasm, \"double\", 3, [1.1, 2.2, 3.3]);\n *\n * @abstract\n * @template T The type of value stored in memory\n */\nexport abstract class BasePointer<T = unknown> {\n    /** Raw memory pointer address in WASM heap */\n    protected _ptr: number = 0;\n\n    /** The WebAssembly module instance */\n    protected readonly wasm: WASMModule;\n\n    /**\n     * Creates a new BasePointer instance.\n     *\n     * @param wasm - The Emscripten WebAssembly module instance\n     * @param ptr - Pre-allocated memory pointer. If not provided, subclasses\n     *   should handle allocation.\n     * @protected\n     */\n    protected constructor(wasm: WASMModule, ptr: number) {\n        this.wasm = wasm;\n        this._ptr = ptr;\n    }\n\n    /**\n     * Gets the raw memory pointer address.\n     *\n     * @example\n     *     const strPtr = StringPointer.from(wasm, \"test\");\n     *     console.log(strPtr.ptr); // e.g., 1048576\n     *\n     * @returns The memory address as a number, or 0 if freed\n     */\n    get ptr(): number {\n        return this._ptr;\n    }\n\n    /**\n     * Checks if the pointer is valid (non-zero and not freed).\n     *\n     * @example\n     *     const ptr = StringPointer.from(wasm, \"test\");\n     *     console.log(ptr.isValid); // true\n     *     ptr.free();\n     *     console.log(ptr.isValid); // false\n     *\n     * @returns True if pointer is valid, false if freed or unallocated\n     */\n    get isValid(): boolean {\n        return this._ptr !== 0;\n    }\n\n    /**\n     * Validates that the pointer is still valid before operations.\n     *\n     * @throws {Error} If pointer has been freed or is invalid\n     * @protected\n     */\n    protected validatePointer(): void {\n        if (!this.isValid) {\n            throw new Error(\"Cannot operate on freed or invalid pointer\");\n        }\n    }\n\n    /**\n     * Reads the value from WASM memory.\n     *\n     * @abstract\n     * @returns The value stored in memory\n     * @throws {Error} If pointer is invalid\n     */\n    abstract read(): T;\n\n    /**\n     * Frees the allocated WASM memory.\n     *\n     * After calling this method, the pointer becomes invalid and cannot be used\n     * for further operations. This method is idempotent - calling it multiple\n     * times is safe.\n     *\n     * @example\n     *     const ptr = StringPointer.from(wasm, \"test\");\n     *     ptr.free(); // Memory is freed\n     *     ptr.free(); // Safe to call again\n     */\n    free(): void {\n        if (this._ptr !== 0) {\n            this.wasm._free(this._ptr);\n            this._ptr = 0;\n        }\n    }\n\n    /**\n     * Convenience method that reads the value and immediately frees the memory.\n     *\n     * This is the recommended way to retrieve values when you don't need to\n     * keep the pointer around for multiple operations.\n     *\n     * @example\n     *     const result = StringPointer.from(wasm, \"test\").readAndFree();\n     *     console.log(result); // \"test\"\n     *     // Memory is automatically freed\n     *\n     * @returns The value stored in memory before freeing\n     * @throws {Error} If pointer is invalid\n     */\n    readAndFree(): T {\n        this.validatePointer();\n        const value = this.read();\n        this.free();\n        return value;\n    }\n\n    /**\n     * Returns a string representation of the pointer for debugging.\n     *\n     * @example\n     *     const ptr = StringPointer.from(wasm, \"test\");\n     *     console.log(ptr.toString()); // \"BasePointer(ptr=1048576, valid=true)\"\n     *\n     * @returns Debug string containing pointer address and validity\n     */\n    toString(): string {\n        return `${this.constructor.name}(ptr=${this._ptr}, valid=${this.isValid})`;\n    }\n}\n","import { type FixedLengthArray, toFixedLengthArray } from \"fixed-len-array\";\n\nimport { type C_NumberType, C_TYPE_SIZES, type WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/** A class representing a typed numeric array in WASM memory. */\nexport class ArrayPointer<\n    T extends C_NumberType,\n    N extends number = number,\n> extends BasePointer<FixedLengthArray<N, T extends \"i64\" ? bigint : number>> {\n    /** Data type of the elements stored (e.g., \"i32\", \"double\"). */\n    public type: T;\n\n    /** Number of elements in the array. */\n    public length: N;\n\n    /**\n     * Creates a new ArrayPointer instance.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - The type of each numeric element in the array.\n     * @param length - Number of elements in the array.\n     * @param ptr - Optional raw pointer to pre-allocated memory. If\n     *   `undefined`, memory is allocated.\n     */\n    constructor(wasm: WASMModule, type: T, length: N, ptr?: number) {\n        super(wasm, ptr ?? wasm._malloc(length * C_TYPE_SIZES[type]));\n        this.type = type;\n        this.length = length;\n    }\n\n    /**\n     * Creates a new ArrayPointer from a JavaScript number array.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - Type of each numeric element (e.g., \"double\", \"i32\").\n     * @param input - JavaScript array of numbers to write to WASM memory.\n     * @returns A new instance of ArrayPointer.\n     */\n    static from<T extends C_NumberType, N extends number>(\n        wasm: WASMModule,\n        type: T,\n        length: N,\n        input: T extends \"i64\" ? bigint[] : number[] = []\n    ): ArrayPointer<T, N> {\n        const arr = ArrayPointer.alloc(wasm, type, length);\n        arr.write(input);\n        return arr;\n    }\n\n    /**\n     * Allocates an empty buffer for a numeric array.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - Type of numeric element stored.\n     * @param length - Number of elements to allocate.\n     * @returns A new instance of ArrayPointer.\n     */\n    static alloc<T extends C_NumberType, N extends number>(\n        wasm: WASMModule,\n        type: T,\n        length: N\n    ): ArrayPointer<T, N> {\n        return new ArrayPointer(wasm, type, length);\n    }\n\n    /**\n     * Writes a numeric value at a given index in WASM memory.\n     *\n     * @param loc - Index to write to.\n     * @param val - Numeric value to write.\n     * @throws If index is out of bounds.\n     */\n    add(loc: number, val: T extends \"i64\" ? bigint : number): void {\n        this.validatePointer();\n        if (loc >= 0 && loc < this.length) {\n            this.wasm.setValue(\n                this.ptr + loc * C_TYPE_SIZES[this.type],\n                val as T extends \"i64\" | \"i64*\" ? bigint : number,\n                this.type\n            );\n        } else {\n            throw new Error(\n                `Out-of-bounds access: tried to write at index ${loc} in array of length ${this.length}`\n            );\n        }\n    }\n\n    /**\n     * Reads the entire numeric array from WASM memory and trims or pads it to\n     * the specified fixed length.\n     *\n     * @returns A fixed-length array\n     */\n    read(): FixedLengthArray<N, T extends \"i64\" ? bigint : number> {\n        this.validatePointer();\n        const size = C_TYPE_SIZES[this.type];\n\n        // Read up to this.length elements from WASM memory\n        const array = Array.from({ length: this.length }, (_, i) =>\n            this.wasm.getValue(this.ptr + i * size, this.type)\n        );\n\n        return toFixedLengthArray(array, this.length, null);\n    }\n\n    /** Writes a JS array into WASM memory */\n    write(values: T extends \"i64\" ? bigint[] : number[]): void {\n        this.validatePointer();\n        if (values.length > this.length) {\n            throw new Error(\n                `Array length mismatch. Expected ${this.length}, got ${values.length}`\n            );\n        }\n\n        // Type assertion to help TypeScript understand the correct type\n        values.forEach((val, i) =>\n            this.add(i, val as T extends \"i64\" ? bigint : number)\n        );\n    }\n}\n","import {\n    type C_BoolType,\n    type C_CharType,\n    C_FALSE,\n    type C_NumberType,\n    C_TRUE,\n    C_TYPE_SIZES,\n} from \"./types\";\n\n/**\n * Utility class for converting between JavaScript and C types.\n *\n * Provides static methods for type-safe conversions that are used across all\n * pointer classes to maintain consistency.\n *\n * @example\n *     // Convert JS boolean to C boolean\n *     const cBool = TypeConverter.boolToC(true); // Returns 1\n *\n *     // Convert C boolean to JS boolean\n *     const jsBool = TypeConverter.boolFromC(0); // Returns false\n *\n *     // Convert single character to ASCII\n *     const ascii = TypeConverter.charToC(\"A\"); // Returns 65\n */\n\nexport class TypeConverter {\n    /**\n     * Converts a JavaScript boolean to a C-style boolean.\n     *\n     * @example\n     *     TypeConverter.boolToC(true); // Returns 1\n     *     TypeConverter.boolToC(false); // Returns 0\n     *\n     * @param value - The JavaScript boolean value\n     * @returns 1 for true, 0 for false\n     */\n    static boolToC(value: boolean): C_BoolType {\n        return value ? C_TRUE : C_FALSE;\n    }\n\n    /**\n     * Converts a C-style boolean to a JavaScript boolean.\n     *\n     * @example\n     *     TypeConverter.boolFromC(1); // Returns true\n     *     TypeConverter.boolFromC(0); // Returns false\n     *\n     * @param value - The C boolean value (0 or 1)\n     * @returns True for non-zero values, false for zero\n     */\n    static boolFromC(value: C_BoolType): boolean {\n        return Boolean(value);\n    }\n\n    /**\n     * Converts a single-character JavaScript string to its ASCII code.\n     *\n     * @example\n     *     TypeConverter.charToC(\"A\"); // Returns 65\n     *     TypeConverter.charToC(\"0\"); // Returns 48\n     *\n     * @param char - A string containing exactly one character\n     * @returns The ASCII code (0-255) of the character\n     * @throws {Error} If input is not exactly one character\n     */\n    static charToC(char: string): C_CharType {\n        if (typeof char !== \"string\" || char.length !== 1) {\n            throw new Error(\"Input must be exactly one character\");\n        }\n        const code = char.charCodeAt(0);\n        if (code < 0 || code > 255) {\n            throw new Error(\n                `Character '${char}' is outside ASCII range (0-255)`\n            );\n        }\n        return code;\n    }\n\n    /**\n     * Converts an ASCII code to a single-character JavaScript string.\n     *\n     * @example\n     *     TypeConverter.charFromC(65); // Returns 'A'\n     *     TypeConverter.charFromC(48); // Returns '0'\n     *\n     * @param code - The ASCII code (must be 0-255)\n     * @returns A single-character string\n     * @throws {Error} If code is outside valid ASCII range\n     */\n    static charFromC(code: C_CharType): string {\n        if (!Number.isInteger(code) || code < 0 || code > 255) {\n            throw new Error(`Invalid ASCII code: ${code}. Must be 0-255`);\n        }\n        return String.fromCharCode(code);\n    }\n\n    /**\n     * Validates that a numeric type is supported by the library.\n     *\n     * @param type - The type to validate\n     * @returns True if the type is supported\n     * @throws {Error} If the type is not supported\n     */\n    static validateNumberType(type: string): type is C_NumberType {\n        if (!(type in C_TYPE_SIZES)) {\n            throw new Error(`Unsupported number type: ${type}`);\n        }\n        return true;\n    }\n\n    /**\n     * Gets the size in bytes for a given numeric type.\n     *\n     * @param type - The numeric type\n     * @returns Size in bytes\n     * @throws {Error} If type is not supported\n     */\n    static getTypeSize(type: C_NumberType): number {\n        this.validateNumberType(type);\n        return C_TYPE_SIZES[type];\n    }\n}\n","import { TypeConverter } from \"../type-converter\";\nimport { type C_BoolType, C_TYPE_SIZES, type WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/** Pointer wrapper for C-style booleans in WASM memory */\nexport class BoolPointer extends BasePointer<boolean> {\n    /**\n     * Creates a new BoolPointer. If no `ptr` is given, allocates memory\n     * initialized to `false` (0).\n     *\n     * @param wasm - Emscripten WASM module instance\n     * @param ptr - Optional pointer to an existing WASM memory address.\n     */\n    constructor(wasm: WASMModule, ptr?: number) {\n        super(wasm, ptr ?? wasm._malloc(C_TYPE_SIZES.i8));\n        if (!ptr) {\n            this.write(false); // default false\n        }\n    }\n\n    /**\n     * Creates a BoolPointer from a JavaScript boolean.\n     *\n     * @param wasm - Emscripten WASM module instance\n     * @param value - The boolean value to store (true/false).\n     * @returns A new instance of BoolPointer.\n     */\n    static from(wasm: WASMModule, value: boolean): BoolPointer {\n        const ptr = BoolPointer.alloc(wasm);\n        ptr.write(value);\n        return ptr;\n    }\n\n    /**\n     * Allocates an empty BoolPointer initialized to false.\n     *\n     * @param wasm - Emscripten WASM module instance\n     * @returns A new instance of BoolPointer.\n     */\n    static alloc(wasm: WASMModule): BoolPointer {\n        return new BoolPointer(wasm);\n    }\n\n    /**\n     * Writes a JavaScript boolean into WASM memory.\n     *\n     * @param value - The boolean to write.\n     */\n    write(value: boolean): void {\n        this.validatePointer();\n        const cVal: C_BoolType = TypeConverter.boolToC(value);\n        this.wasm.setValue(this.ptr, cVal, \"i8\");\n    }\n\n    /**\n     * Reads the boolean value from WASM memory.\n     *\n     * @returns The stored JavaScript boolean.\n     */\n    read(): boolean {\n        this.validatePointer();\n        const cVal = this.wasm.getValue(this.ptr, \"i8\") as C_BoolType;\n        return TypeConverter.boolFromC(cVal);\n    }\n}\n","import { TypeConverter } from \"../type-converter\";\nimport { type C_CharType, C_TYPE_SIZES, type WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/**\n * A wrapper around a C-style `char*` allocated in WebAssembly (WASM) memory.\n *\n * Provides methods for creating, writing, reading, and freeing memory for\n * single-character UTF-8 strings in the WASM heap.\n */\nexport class CharPointer extends BasePointer<string> {\n    /**\n     * Constructs a new `CharPointer`. If `ptr` is not provided, memory is\n     * allocated for a single null-terminated char (initialized to `\\0`).\n     *\n     * @param wasm - The Emscripten WebAssembly module instance.\n     * @param ptr - Optional pointer to an existing WASM memory address.\n     */\n    constructor(wasm: WASMModule, ptr?: number) {\n        super(wasm, ptr ?? wasm._malloc(C_TYPE_SIZES.i8));\n        if (!ptr) {\n            this.write(\"\\0\"); // null char\n        }\n    }\n\n    /**\n     * Creates a new `CharPointer` from a JavaScript string.\\\n     * Only the first character is stored (C `char` is a single byte).\n     *\n     * @param wasm - The Emscripten WebAssembly module instance.\n     * @param input - A string from which the first character will be stored.\n     * @returns A new instance of `CharPointer`.\n     */\n    static from(wasm: WASMModule, input: string): CharPointer {\n        if (input.length !== 1) {\n            throw new Error(\"Input must be exactly one character\");\n        }\n        const char = CharPointer.alloc(wasm);\n        char.write(input);\n        return char;\n    }\n\n    /**\n     * Allocates a new empty buffer for a single character (`char`).\n     *\n     * @param wasm - The Emscripten WebAssembly module instance.\n     * @returns A new zero-initialized `CharPointer`.\n     */\n    static alloc(wasm: WASMModule): CharPointer {\n        return new CharPointer(wasm);\n    }\n\n    /**\n     * Writes a JavaScript string into the allocated WASM memory.\\\n     * Only the first character of the string will be stored.\n     *\n     * @param input - The string to write (must be exactly one character).\n     * @throws Error if the string length is not exactly one character.\n     */\n    write(input: string): void {\n        this.validatePointer();\n        const cVal: C_CharType = TypeConverter.charToC(input);\n        this.wasm.setValue(this.ptr, cVal, \"i8\");\n    }\n\n    /**\n     * Reads the stored character as a JavaScript string.\n     *\n     * @returns A one-character string read from WASM memory.\n     */\n    read(): string {\n        this.validatePointer();\n        const cVal = this.wasm.getValue(this.ptr, \"i8\") as C_CharType;\n        return TypeConverter.charFromC(cVal);\n    }\n}\n","import type { WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/**\n * A NullPointer is a special pointer that never points to valid WASM memory. It\n * provides a safe representation of \"no memory\" within the pointer system.\n *\n * This class is useful when an API requires a pointer instance but you want to\n * explicitly represent the absence of allocated memory without using `null` or\n * `undefined`.\n *\n * @example\n *     const nullPtr = new NullPointer();\n *     console.log(nullPtr.ptr); // 0\n */\nexport class NullPointer<T = void> extends BasePointer<T> {\n    /**\n     * Creates a new NullPointer instance.\n     *\n     * Unlike other pointers, this does not need a WASM module.\n     */\n    constructor() {\n        // Pass a dummy object for wasm, since BasePointer expects it\n        super({} as WASMModule, 0);\n    }\n\n    /**\n     * Always throws because a NullPointer cannot read memory.\n     *\n     * @throws {Error} Always throws: \"Cannot read from a NullPointer\"\n     */\n    read(): T {\n        throw new Error(\"Cannot read from a NullPointer\");\n    }\n}\n","import { type C_NumberType, C_TYPE_SIZES, type WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/** Class representing a single number allocated in WASM memory. */\nexport class NumberPointer<T extends C_NumberType> extends BasePointer<\n    T extends \"i64\" ? bigint : number\n> {\n    /** Data type of the elements stored (e.g., \"i32\", \"double\"). */\n    public type: T;\n\n    /**\n     * Creates a new NumberPointer. If no pointer is given, allocates memory for\n     * one number.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - The type of each numeric element in the Number.\n     * @param ptr - Optional raw pointer to pre-allocated memory. If\n     *   `undefined`, memory is allocated.\n     */\n    constructor(wasm: WASMModule, type: T, ptr?: number) {\n        super(wasm, ptr ?? wasm._malloc(C_TYPE_SIZES[type]));\n        this.type = type;\n    }\n\n    /**\n     * Creates a new NumberPointer from a JavaScript number Number.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - Type of each numeric element (e.g., \"double\", \"i32\").\n     * @param input - JavaScript Number of numbers to write to WASM memory.\n     * @returns A new instance of NumberPointer.\n     */\n    static from<T extends C_NumberType>(\n        wasm: WASMModule,\n        type: T,\n        input: T extends \"i64\" ? bigint : number\n    ): NumberPointer<T> {\n        const arr = NumberPointer.alloc(wasm, type);\n        arr.write(input);\n        return arr;\n    }\n\n    /** Writes a JS Number into WASM memory */\n    write(values: T extends \"i64\" ? bigint : number): void {\n        // Type assertion to help TypeScript understand the correct type\n        this.validatePointer();\n        this.add(values as T extends \"i64\" ? bigint : number);\n    }\n\n    /**\n     * Allocates an empty buffer for a numeric Number.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - Type of numeric element stored.\n     * @param length - Number of elements to allocate.\n     * @returns A new instance of NumberPointer.\n     */\n    static alloc<T extends C_NumberType>(\n        wasm: WASMModule,\n        type: T\n    ): NumberPointer<T> {\n        return new NumberPointer(wasm, type);\n    }\n\n    /**\n     * Writes a numeric value at a given index in WASM memory.\n     *\n     * @param val - Numeric value to write.\n     * @throws If index is out of bounds.\n     */\n    add(val: T extends \"i64\" ? bigint : number): void {\n        this.validatePointer();\n        this.wasm.setValue(\n            this.ptr,\n            val as T extends \"i64\" | \"i64*\" ? bigint : number,\n            this.type\n        );\n    }\n\n    /**\n     * Reads the entire numeric Number from WASM memory and trims or pads it to\n     * the specified fixed length.\n     *\n     * @returns A fixed-length Number\n     */\n    read(): T extends \"i64\" ? bigint : number {\n        this.validatePointer();\n        // Read up to this.length elements from WASM memory\n        return this.wasm.getValue(this.ptr, this.type) as T extends \"i64\"\n            ? bigint\n            : number;\n    }\n}\n","import { C_TYPE_SIZES, type WASMModule } from \"../types\";\nimport { BasePointer } from \"./base-pointer\";\n\n/** Class representing a UTF-8 string allocated in WASM memory. */\nexport class StringPointer<\n    N extends number = number,\n> extends BasePointer<string> {\n    /** Number of character in the String. */\n    public length: number;\n\n    /**\n     * Creates a new StringPointer instance.\n     *\n     * @param wasm - Swisseph Emscripten Module instance\n     * @param type - The type of each numeric element in the String.\n     * @param length - Number of elements in the String.\n     * @param ptr - Optional raw pointer to pre-allocated memory. If\n     *   `undefined`, memory is allocated.\n     */\n    constructor(wasm: WASMModule, length: N, ptr?: number) {\n        super(wasm, ptr ?? wasm._malloc(length * C_TYPE_SIZES.i8));\n        this.length = length;\n    }\n\n    /**\n     * Creates a StringPointer from a JavaScript string.\n     *\n     * @param wasm - Emscripten Module instance\n     * @param input - The string to encode and store in WASM memory.\n     * @returns A new instance of StringPointer.\n     */\n    static from<N extends number = number>(\n        wasm: WASMModule,\n        length: N,\n        input: string = \"\"\n    ): StringPointer {\n        const str = StringPointer.alloc(wasm, length + 1); // +1 for null terminator\n        str.write(input);\n        return str;\n    }\n\n    /**\n     * Allocates an empty buffer for a string of given length.\n     *\n     * @param wasm - Emscripten Module instance\n     * @param length - Number of bytes to allocate in WASM memory.\n     * @returns A new instance of StringPointer with zero-filled memory.\n     */\n    static alloc(wasm: WASMModule, length: number): StringPointer {\n        return new StringPointer(wasm, length);\n    }\n\n    /**\n     * Writes a JavaScript string into the allocated WASM memory buffer.\n     *\n     * @param input - The string to write.\n     * @throws Will throw an error if the input string is too long for the\n     *   allocated buffer.\n     */\n    write(input: string): void {\n        this.validatePointer();\n        if (input.length + 1 > this.length) {\n            throw new Error(\"String length exceeds buffer size\");\n        }\n        this.wasm.stringToUTF8(input, this.ptr, this.length);\n    }\n\n    /**\n     * Reads the UTF-8 string from WASM memory.\n     *\n     * @returns The decoded JavaScript string.\n     */\n    read(): string {\n        this.validatePointer();\n        return this.wasm.UTF8ToString(this.ptr, this.length);\n    }\n}\n"],"names":["l","u","n","e","t","C_TRUE","C_FALSE","C_TYPE_SIZES","BasePointer","wasm","ptr","__publicField","value","ArrayPointer","type","length","input","arr","loc","val","size","array","_","i","toFixedLengthArray","values","TypeConverter","char","code","BoolPointer","cVal","CharPointer","NullPointer","NumberPointer","StringPointer","str"],"mappings":"oPAAA,SAASA,EAAEC,EAAGC,EAAGC,EAAG,CAClB,MAAMC,EAAIH,EAAE,MAAM,EAAGC,CAAC,EACtB,KAAOE,EAAE,OAASF,GAChBE,EAAE,KAAU,IAAI,EAClB,OAAOA,CACT,CCmBO,MAAMC,EAAqB,EACrBC,EAAsB,EAUtBC,EAAuD,CAChE,GAAI,UAAU,kBACd,IAAK,WAAW,kBAChB,IAAK,WAAW,kBAChB,IAAK,cAAc,kBACnB,MAAO,aAAa,kBACpB,OAAQ,aAAa,iBACzB,ECpBO,MAAeC,CAAyB,CAejC,YAAYC,EAAkBC,EAAa,CAb3CC,EAAA,YAAe,GAGNA,EAAA,aAWf,KAAK,KAAOF,EACZ,KAAK,KAAOC,CAChB,CAWA,IAAI,KAAc,CACd,OAAO,KAAK,IAChB,CAaA,IAAI,SAAmB,CACnB,OAAO,KAAK,OAAS,CACzB,CAQU,iBAAwB,CAC9B,GAAI,CAAC,KAAK,QACN,MAAM,IAAI,MAAM,4CAA4C,CAEpE,CAuBA,MAAa,CACL,KAAK,OAAS,IACd,KAAK,KAAK,MAAM,KAAK,IAAI,EACzB,KAAK,KAAO,EAEpB,CAgBA,aAAiB,CACb,KAAK,gBAAA,EACL,MAAME,EAAQ,KAAK,KAAA,EACnB,YAAK,KAAA,EACEA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