@selvajs/compute 1.5.1 → 1.5.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-IJZNCO5X.cjs","../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/compute-fetch/compute-fetch.ts"],"names":["ErrorCodes","RhinoComputeError","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CCA1N,IAAMA,CAAAA,CAAa,CACzB,aAAA,CAAe,eAAA,CACf,UAAA,CAAY,YAAA,CACZ,gBAAA,CAAkB,kBAAA,CAClB,iBAAA,CAAmB,mBAAA,CACnB,aAAA,CAAe,eAAA,CACf,UAAA,CAAY,YAAA,CACZ,aAAA,CAAe,eAAA,CACf,aAAA,CAAe,eAAA,CACf,aAAA,CAAe,eAAA,CACf,cAAA,CAAgB,gBAAA,CAChB,YAAA,CAAc,cAAA,CACd,iBAAA,CAAmB,mBAAA,CACnB,cAAA,CAAgB,gBACjB,CAAA,CCPO,IAAMC,CAAAA,CAAN,MAAMC,EAAAA,QAA0B,KAAM,CAM5C,WAAA,CACCC,CAAAA,CACAC,CAAAA,CAAe,eAAA,CACfC,CAAAA,CACC,CACD,KAAA,CAAMF,CAAO,CAAA,CAVdG,CAAAA,CAAA,IAAA,CAAgB,MAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,YAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,SAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,eAAA,CAAA,CAQf,IAAA,CAAK,IAAA,CAAO,mBAAA,CACZ,IAAA,CAAK,IAAA,CAAOF,CAAAA,CACZ,IAAA,CAAK,UAAA,iBAAaC,CAAAA,6BAAS,YAAA,CAC3B,IAAA,CAAK,OAAA,iBAAUA,CAAAA,6BAAS,SAAA,CACxB,IAAA,CAAK,aAAA,iBAAgBA,CAAAA,6BAAS,eAAA,CAG1B,OAAA,GAAW,KAAA,CAAM,SAAA,EACpB,MAAA,CAAO,cAAA,CAAe,IAAA,CAAM,OAAA,CAAS,CACpC,KAAA,iBAAOA,CAAAA,6BAAS,eAAA,CAChB,UAAA,CAAY,CAAA,CACb,CAAC,CAEH,CASA,OAAO,UAAA,CAAWE,CAAAA,CAAmBC,CAAAA,CAAgBC,CAAAA,CAAmC,CACvF,OAAO,IAAIP,CAAAA,CAAkB,CAAA,OAAA,EAAUK,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA;AC2Wd","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-IJZNCO5X.cjs","sourcesContent":[null,"export const ErrorCodes = {\n\tNETWORK_ERROR: 'NETWORK_ERROR',\n\tAUTH_ERROR: 'AUTH_ERROR',\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tCOMPUTATION_ERROR: 'COMPUTATION_ERROR',\n\tTIMEOUT_ERROR: 'TIMEOUT_ERROR',\n\tCORS_ERROR: 'CORS_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\tINVALID_INPUT: 'INVALID_INPUT',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\tBROWSER_ONLY: 'BROWSER_ONLY',\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tENCODING_ERROR: 'ENCODING_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n","import { ErrorCodes } from './error-codes';\n\n/**\n * Simplified error for Rhino Compute operations\n *\n * @public Use this for error handling with error codes and context.\n */\nexport class RhinoComputeError extends Error {\n\tpublic readonly code: string;\n\tpublic readonly statusCode?: number;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string = 'UNKNOWN_ERROR',\n\t\toptions?: { statusCode?: number; context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'RhinoComputeError';\n\t\tthis.code = code;\n\t\tthis.statusCode = options?.statusCode;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\n\t\t// Support error chaining (Node.js 16.9+, TypeScript 4.6+)\n\t\tif ('cause' in Error.prototype) {\n\t\t\tObject.defineProperty(this, 'cause', {\n\t\t\t\tvalue: options?.originalError,\n\t\t\t\tenumerable: true\n\t\t\t});\n\t\t}\n\t}\n\n\t// ============================================================================\n\t// Static Validation Error Helpers\n\t// ============================================================================\n\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tstatic validation(inputName: string, reason: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tstatic missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedType, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tstatic invalidDefault(\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`ValueList input \"${inputName}\" default value \"${defaultValue}\" is not in available values`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { inputName, defaultValue, availableValues, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tstatic unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tstatic invalidStructure(\n\t\tinputName: string,\n\t\texpectedStructure: string,\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedStructure, ...context } }\n\t\t);\n\t}\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig, RetryPolicy } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute (improved response type handling).\n */\nexport type Endpoint = 'grasshopper' | 'io' | string;\n\nexport type EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\nexport type ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\n\n// ============================================================================\n// Retry Policy\n// ============================================================================\n\nconst DEFAULT_RETRY: Required<RetryPolicy> = {\n\tattempts: 0,\n\tbaseDelayMs: 500,\n\tmaxDelayMs: 30_000,\n\tretryOn429: true\n};\n\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nfunction resolveRetryPolicy(policy: RetryPolicy | undefined): Required<RetryPolicy> {\n\tif (!policy) return DEFAULT_RETRY;\n\treturn {\n\t\tattempts: policy.attempts ?? DEFAULT_RETRY.attempts,\n\t\tbaseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,\n\t\tmaxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,\n\t\tretryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429\n\t};\n}\n\n/**\n * Parse a Retry-After header value (seconds-int or HTTP-date) into ms.\n * Returns null if the header is missing or unparseable.\n */\nfunction parseRetryAfter(headerValue: string | null): number | null {\n\tif (!headerValue) return null;\n\tconst seconds = Number(headerValue);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;\n\tconst dateMs = Date.parse(headerValue);\n\tif (Number.isFinite(dateMs)) {\n\t\tconst delta = dateMs - Date.now();\n\t\treturn delta > 0 ? delta : 0;\n\t}\n\treturn null;\n}\n\nfunction backoffDelay(attempt: number, policy: Required<RetryPolicy>): number {\n\tconst exponential = policy.baseDelayMs * Math.pow(2, attempt);\n\tconst jitter = Math.random() * policy.baseDelayMs;\n\treturn Math.min(exponential + jitter, policy.maxDelayMs);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t\treturn;\n\t\t}\n\t\tconst id = setTimeout(() => {\n\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(id);\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t};\n\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t});\n}\n\n// ============================================================================\n// Error Handling\n// ============================================================================\n\nfunction throwHttpError(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\terrorBody: string\n): never {\n\tconst { status, statusText } = response;\n\tconst context = { url: fullUrl, requestId, method: 'POST', requestSize, serverUrl };\n\n\tconst bodyHint = errorBody ? ` — ${errorBody.slice(0, 200)}` : '';\n\tconst errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t403: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t404: { message: `Endpoint not found: ${fullUrl}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t413: {\n\t\t\tmessage: `Request too large: ${(requestSize / 1024).toFixed(2)}KB`,\n\t\t\tcode: ErrorCodes.VALIDATION_ERROR\n\t\t},\n\t\t429: { message: 'Rate limit exceeded', code: ErrorCodes.NETWORK_ERROR },\n\t\t500: {\n\t\t\tmessage: `Server error: ${errorBody || statusText}`,\n\t\t\tcode: ErrorCodes.COMPUTATION_ERROR\n\t\t},\n\t\t502: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t503: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t504: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR }\n\t};\n\n\tconst error = errorMap[status] || {\n\t\tmessage: `HTTP ${status}: ${statusText}`,\n\t\tcode: ErrorCodes.UNKNOWN_ERROR\n\t};\n\n\tthrow new RhinoComputeError(error.message, error.code, { statusCode: status, context });\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\nfunction buildUrl(endpoint: string, serverUrl: string): string {\n\tconst base = serverUrl.replace(/\\/+$/, '');\n\tconst path = endpoint.replace(/^\\/+/, '');\n\treturn `${base}/${path}`;\n}\n\nfunction isLocalhost(serverUrl: string): boolean {\n\ttry {\n\t\tconst host = new URL(serverUrl).host;\n\t\treturn /^(localhost|127\\.0\\.0\\.1|::1)(:\\d+)?$/i.test(host);\n\t} catch {\n\t\treturn /(localhost|127\\.0\\.0\\.1)/i.test(serverUrl);\n\t}\n}\n\nfunction buildHeaders(requestId: string, config: ComputeConfig): HeadersInit {\n\tconst headers: HeadersInit = {\n\t\t'X-Request-ID': requestId,\n\t\t'Content-Type': 'application/json',\n\t\t...(config.authToken && { Authorization: config.authToken }),\n\t\t...(config.apiKey && { RhinoComputeKey: config.apiKey })\n\t};\n\n\tif (!config.apiKey && !isLocalhost(config.serverUrl)) {\n\t\tgetLogger().warn(\n\t\t\t`⚠️ [Rhino Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`\n\t\t);\n\t}\n\n\treturn headers;\n}\n\nfunction generateRequestId(): string {\n\treturn `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;\n}\n\nfunction log(message: string, debug?: boolean): void {\n\tif (debug) getLogger().debug(message);\n}\n\n/**\n * Compose a caller-supplied AbortSignal with an optional timeout. Returns a\n * combined signal, or `undefined` if neither was given.\n *\n * Uses `AbortSignal.timeout` (not setTimeout) so the timer is not throttled\n * when the tab is hidden. Falls back to a manual timer for older runtimes.\n */\nfunction composeSignal(\n\tcallerSignal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined\n): { signal: AbortSignal | undefined; cleanup: () => void } {\n\tconst signals: AbortSignal[] = [];\n\tlet cleanup = () => {};\n\n\tif (callerSignal) signals.push(callerSignal);\n\n\tif (timeoutMs && timeoutMs > 0) {\n\t\tif (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') {\n\t\t\tsignals.push(AbortSignal.timeout(timeoutMs));\n\t\t} else {\n\t\t\t// Fallback for runtimes without AbortSignal.timeout\n\t\t\tconst ctrl = new AbortController();\n\t\t\tconst id = setTimeout(() => ctrl.abort(), timeoutMs);\n\t\t\tcleanup = () => clearTimeout(id);\n\t\t\tsignals.push(ctrl.signal);\n\t\t}\n\t}\n\n\tif (signals.length === 0) return { signal: undefined, cleanup };\n\tif (signals.length === 1) return { signal: signals[0], cleanup };\n\n\tif (typeof AbortSignal !== 'undefined' && typeof (AbortSignal as any).any === 'function') {\n\t\treturn { signal: (AbortSignal as any).any(signals) as AbortSignal, cleanup };\n\t}\n\n\t// Manual composition fallback\n\tconst ctrl = new AbortController();\n\tconst onAbort = () => ctrl.abort();\n\tfor (const s of signals) {\n\t\tif (s.aborted) {\n\t\t\tctrl.abort();\n\t\t\tbreak;\n\t\t}\n\t\ts.addEventListener('abort', onAbort, { once: true });\n\t}\n\tconst prevCleanup = cleanup;\n\tcleanup = () => {\n\t\tprevCleanup();\n\t\tfor (const s of signals) s.removeEventListener('abort', onAbort);\n\t};\n\treturn { signal: ctrl.signal, cleanup };\n}\n\n// ============================================================================\n// Response Processing\n// ============================================================================\n\nasync function handleResponse(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\tstartTime: number,\n\tdebug?: boolean\n): Promise<any> {\n\tconst responseTime = Math.round(performance.now() - startTime);\n\n\tif (!response.ok) {\n\t\t// Read body once and reuse\n\t\tlet errorBody = await response.text();\n\n\t\t// Enhanced logging for errors\n\t\tif (debug) {\n\t\t\tlog(\n\t\t\t\t`❌ Request [${requestId}] failed with HTTP ${response.status} in ${responseTime}ms`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t\tlog(` URL: ${fullUrl}`, true);\n\t\t\tlog(` Status: ${response.status} ${response.statusText}`, true);\n\t\t\tif (errorBody) {\n\t\t\t\tlog(\n\t\t\t\t\t` Response body: ${errorBody.substring(0, 500)}${errorBody.length > 500 ? '...' : ''}`,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Check if it's a valid compute response with errors/warnings\n\t\tif (response.status === 500) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(errorBody);\n\t\t\t\t// If it has values, it's a partial success with errors\n\t\t\t\tif (parsed?.values && (parsed.errors || parsed.warnings)) {\n\t\t\t\t\tif (debug) {\n\t\t\t\t\t\tlog(\n\t\t\t\t\t\t\t`⚠️ Request [${requestId}] completed with Grasshopper errors in ${responseTime}ms`,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (parsed.errors?.length > 0) {\n\t\t\t\t\t\t\tlog(` Errors: ${JSON.stringify(parsed.errors, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parsed.warnings?.length > 0) {\n\t\t\t\t\t\t\tlog(` Warnings: ${JSON.stringify(parsed.warnings, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\n\t\t\t\t// If it's a raw exception from the server (like ArgumentException), include it in the error message\n\t\t\t\tif (parsed?.Message) {\n\t\t\t\t\terrorBody = `${parsed.ExceptionType ? parsed.ExceptionType + ': ' : ''}${parsed.Message}\\n${parsed.StackTrace || ''}`;\n\t\t\t\t} else if (parsed?.error) {\n\t\t\t\t\terrorBody =\n\t\t\t\t\t\ttypeof parsed.error === 'string' ? parsed.error : JSON.stringify(parsed.error, null, 2);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (debug) {\n\t\t\t\t\tlog(` Failed to parse error body as JSON: ${e}`, true);\n\t\t\t\t}\n\t\t\t\t// Not valid JSON, proceed with HTTP error\n\t\t\t}\n\t\t}\n\n\t\tthrowHttpError(response, fullUrl, requestId, requestSize, serverUrl, errorBody);\n\t}\n\n\tlog(`✅ Request [${requestId}] completed in ${responseTime}ms`, debug);\n\n\ttry {\n\t\treturn await response.json();\n\t} catch (error) {\n\t\tthrow new RhinoComputeError('Failed to parse JSON response', ErrorCodes.NETWORK_ERROR, {\n\t\t\tstatusCode: response.status,\n\t\t\tcontext: {\n\t\t\t\turl: fullUrl,\n\t\t\t\trequestId\n\t\t\t},\n\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t});\n\t}\n}\n\n// ============================================================================\n// Single attempt\n// ============================================================================\n\ninterface AttemptContext {\n\tendpoint: string;\n\tbody: string;\n\trequestSize: number;\n\tfullUrl: string;\n\trequestId: string;\n\theaders: HeadersInit;\n\tconfig: ComputeConfig | GrasshopperComputeConfig;\n}\n\ninterface AttemptResult {\n\tok: true;\n\tvalue: any;\n}\n\ninterface AttemptRetry {\n\tok: false;\n\tretry: true;\n\tdelayMs: number;\n\tcause: RhinoComputeError;\n}\n\ninterface AttemptFatal {\n\tok: false;\n\tretry: false;\n\tcause: RhinoComputeError;\n}\n\nasync function attemptFetch(\n\tctx: AttemptContext,\n\tretryPolicy: Required<RetryPolicy>,\n\tattempt: number,\n\ttotalAttempts: number\n): Promise<AttemptResult | AttemptRetry | AttemptFatal> {\n\tconst { signal, cleanup } = composeSignal(ctx.config.signal, ctx.config.timeoutMs);\n\tconst startTime = performance.now();\n\n\ttry {\n\t\tconst response = await fetch(ctx.fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: ctx.body,\n\t\t\theaders: ctx.headers,\n\t\t\tsignal\n\t\t});\n\n\t\t// 429 with Retry-After or retryable 5xx → maybe retry\n\t\tconst isRetryableStatus =\n\t\t\tRETRYABLE_STATUS.has(response.status) ||\n\t\t\t(retryPolicy.retryOn429 && response.status === 429);\n\n\t\tif (isRetryableStatus && attempt < totalAttempts - 1) {\n\t\t\tconst retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n\t\t\tconst delayMs = retryAfterMs ?? backoffDelay(attempt, retryPolicy);\n\t\t\t// Drain the body so the connection can be reused\n\t\t\tawait response.text().catch(() => {});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tretry: true,\n\t\t\t\tdelayMs,\n\t\t\t\tcause: new RhinoComputeError(\n\t\t\t\t\t`HTTP ${response.status} ${response.statusText} (will retry)`,\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ statusCode: response.status, context: { requestId: ctx.requestId } }\n\t\t\t\t)\n\t\t\t};\n\t\t}\n\n\t\tconst value = await handleResponse(\n\t\t\tresponse,\n\t\t\tctx.fullUrl,\n\t\t\tctx.requestId,\n\t\t\tctx.requestSize,\n\t\t\tctx.config.serverUrl,\n\t\t\tstartTime,\n\t\t\tctx.config.debug\n\t\t);\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\t// Caller-aborted vs timeout-aborted distinction\n\t\tif (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {\n\t\t\tconst callerAborted = ctx.config.signal?.aborted === true;\n\n\t\t\tif (callerAborted) {\n\t\t\t\t// Caller cancellation is never retried — propagate immediately\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: false,\n\t\t\t\t\tcause: new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t\t},\n\t\t\t\t\t\toriginalError: error\n\t\t\t\t\t})\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Timeout — retryable up to attempts limit\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Request timed out after ${ctx.config.timeoutMs}ms`,\n\t\t\t\tErrorCodes.TIMEOUT_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: ctx.config.timeoutMs,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// Network error (TypeError) — retryable\n\t\tif (error instanceof TypeError) {\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Network error: ${error.message}`,\n\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t},\n\t\t\t\t\toriginalError: error\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// RhinoComputeError thrown from handleResponse — already has full context.\n\t\t// Retryable only if it carries a retryable status code.\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tconst status = error.statusCode;\n\t\t\tconst retryable =\n\t\t\t\tstatus !== undefined &&\n\t\t\t\t(RETRYABLE_STATUS.has(status) || (retryPolicy.retryOn429 && status === 429));\n\t\t\tif (retryable && attempt < totalAttempts - 1) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: true,\n\t\t\t\t\tdelayMs: backoffDelay(attempt, retryPolicy),\n\t\t\t\t\tcause: error\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: error };\n\t\t}\n\n\t\t// Unknown — wrap and don't retry\n\t\treturn {\n\t\t\tok: false,\n\t\t\tretry: false,\n\t\t\tcause: new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.UNKNOWN_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: { endpoint: ctx.endpoint, requestId: ctx.requestId },\n\t\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t\t}\n\t\t\t)\n\t\t};\n\t} finally {\n\t\tcleanup();\n\t}\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Generic Rhino Compute fetch function.\n * Sends a POST request to any Compute endpoint with pre-prepared arguments.\n *\n * Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @typeParam E - The endpoint name (e.g., 'grasshopper', 'io'). Determines the response type for better type safety.\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request body.\n * @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).\n * @returns The parsed JSON response from the server, typed according to the endpoint.\n *\n * @example\n * // Basic usage for the Grasshopper endpoint:\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * { ... },\n * {\n * serverUrl: 'https://my-server.com',\n * debug: true,\n * timeoutMs: 30_000,\n * retry: { attempts: 2 },\n * signal: controller.signal,\n * }\n * );\n */\nexport async function fetchRhinoCompute<E extends Endpoint>(\n\tendpoint: E,\n\targs: Record<string, any>,\n\tconfig: ComputeConfig | GrasshopperComputeConfig\n): Promise<ComputeResponseFor<E>> {\n\tconst requestId = generateRequestId();\n\tconst body = JSON.stringify(args);\n\tconst requestSize = body.length;\n\tconst fullUrl = buildUrl(endpoint, config.serverUrl);\n\tconst headers = buildHeaders(requestId, config);\n\tconst retryPolicy = resolveRetryPolicy(config.retry);\n\tconst totalAttempts = retryPolicy.attempts + 1;\n\n\tif (config.debug) {\n\t\tconst sizeKb = (requestSize / 1024).toFixed(2);\n\t\tconst emoji = requestSize > 100000 ? '⚠️' : '🚀';\n\t\tlog(`${emoji} Starting compute request [${requestId}]: ${endpoint} (${sizeKb}KB)`, true);\n\t}\n\n\tconst ctx: AttemptContext = {\n\t\tendpoint,\n\t\tbody,\n\t\trequestSize,\n\t\tfullUrl,\n\t\trequestId,\n\t\theaders,\n\t\tconfig\n\t};\n\n\tlet lastError: RhinoComputeError | null = null;\n\n\tfor (let attempt = 0; attempt < totalAttempts; attempt++) {\n\t\tconst result = await attemptFetch(ctx, retryPolicy, attempt, totalAttempts);\n\n\t\tif (result.ok) return result.value as ComputeResponseFor<E>;\n\n\t\tif (!result.retry) throw result.cause;\n\n\t\tlastError = result.cause;\n\t\tif (config.debug) {\n\t\t\tlog(\n\t\t\t\t`🔁 Request [${requestId}] retrying after ${result.delayMs}ms (attempt ${attempt + 2}/${totalAttempts}): ${result.cause.message}`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tawait sleep(result.delayMs, config.signal);\n\t\t} catch {\n\t\t\t// Caller cancelled during backoff\n\t\t\tthrow new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\tcontext: { endpoint, requestId, requestSize },\n\t\t\t\toriginalError: lastError\n\t\t\t});\n\t\t}\n\t}\n\n\t// Exhausted retries — throw the last seen error\n\tthrow (\n\t\tlastError ??\n\t\tnew RhinoComputeError('Unknown error after retries', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\tcontext: { endpoint, requestId, requestSize }\n\t\t})\n\t);\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-XULONXVP.cjs","../src/core/errors/error-codes.ts","../src/core/errors/base.ts","../src/core/compute-fetch/compute-fetch.ts"],"names":["ErrorCodes","RhinoComputeError","_RhinoComputeError","message","code","options","__publicField","inputName","reason","context"],"mappings":"AAAA,qrBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CCA1N,IAAMA,CAAAA,CAAa,CACzB,aAAA,CAAe,eAAA,CACf,UAAA,CAAY,YAAA,CACZ,gBAAA,CAAkB,kBAAA,CAClB,iBAAA,CAAmB,mBAAA,CACnB,aAAA,CAAe,eAAA,CACf,UAAA,CAAY,YAAA,CACZ,aAAA,CAAe,eAAA,CACf,aAAA,CAAe,eAAA,CACf,aAAA,CAAe,eAAA,CACf,cAAA,CAAgB,gBAAA,CAChB,YAAA,CAAc,cAAA,CACd,iBAAA,CAAmB,mBAAA,CACnB,cAAA,CAAgB,gBACjB,CAAA,CCPO,IAAMC,CAAAA,CAAN,MAAMC,EAAAA,QAA0B,KAAM,CAM5C,WAAA,CACCC,CAAAA,CACAC,CAAAA,CAAe,eAAA,CACfC,CAAAA,CACC,CACD,KAAA,CAAMF,CAAO,CAAA,CAVdG,CAAAA,CAAA,IAAA,CAAgB,MAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,YAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,SAAA,CAAA,CAChBA,CAAAA,CAAA,IAAA,CAAgB,eAAA,CAAA,CAQf,IAAA,CAAK,IAAA,CAAO,mBAAA,CACZ,IAAA,CAAK,IAAA,CAAOF,CAAAA,CACZ,IAAA,CAAK,UAAA,iBAAaC,CAAAA,6BAAS,YAAA,CAC3B,IAAA,CAAK,OAAA,iBAAUA,CAAAA,6BAAS,SAAA,CACxB,IAAA,CAAK,aAAA,iBAAgBA,CAAAA,6BAAS,eAAA,CAG1B,OAAA,GAAW,KAAA,CAAM,SAAA,EACpB,MAAA,CAAO,cAAA,CAAe,IAAA,CAAM,OAAA,CAAS,CACpC,KAAA,iBAAOA,CAAAA,6BAAS,eAAA,CAChB,UAAA,CAAY,CAAA,CACb,CAAC,CAEH,CASA,OAAO,UAAA,CAAWE,CAAAA,CAAmBC,CAAAA,CAAgBC,CAAAA,CAAmC,CACvF,OAAO,IAAIP,CAAAA,CAAkB,CAAA,OAAA,EAAUK,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA;AC2Wd","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-XULONXVP.cjs","sourcesContent":[null,"export const ErrorCodes = {\n\tNETWORK_ERROR: 'NETWORK_ERROR',\n\tAUTH_ERROR: 'AUTH_ERROR',\n\tVALIDATION_ERROR: 'VALIDATION_ERROR',\n\tCOMPUTATION_ERROR: 'COMPUTATION_ERROR',\n\tTIMEOUT_ERROR: 'TIMEOUT_ERROR',\n\tCORS_ERROR: 'CORS_ERROR',\n\tUNKNOWN_ERROR: 'UNKNOWN_ERROR',\n\tINVALID_STATE: 'INVALID_STATE',\n\tINVALID_INPUT: 'INVALID_INPUT',\n\tINVALID_CONFIG: 'INVALID_CONFIG',\n\tBROWSER_ONLY: 'BROWSER_ONLY',\n\tENVIRONMENT_ERROR: 'ENVIRONMENT_ERROR',\n\tENCODING_ERROR: 'ENCODING_ERROR'\n} as const;\n\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\n","import { ErrorCodes } from './error-codes';\n\n/**\n * Simplified error for Rhino Compute operations\n *\n * @public Use this for error handling with error codes and context.\n */\nexport class RhinoComputeError extends Error {\n\tpublic readonly code: string;\n\tpublic readonly statusCode?: number;\n\tpublic readonly context?: Record<string, unknown>;\n\tpublic readonly originalError?: Error;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: string = 'UNKNOWN_ERROR',\n\t\toptions?: { statusCode?: number; context?: Record<string, unknown>; originalError?: Error }\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'RhinoComputeError';\n\t\tthis.code = code;\n\t\tthis.statusCode = options?.statusCode;\n\t\tthis.context = options?.context;\n\t\tthis.originalError = options?.originalError;\n\n\t\t// Support error chaining (Node.js 16.9+, TypeScript 4.6+)\n\t\tif ('cause' in Error.prototype) {\n\t\t\tObject.defineProperty(this, 'cause', {\n\t\t\t\tvalue: options?.originalError,\n\t\t\t\tenumerable: true\n\t\t\t});\n\t\t}\n\t}\n\n\t// ============================================================================\n\t// Static Validation Error Helpers\n\t// ============================================================================\n\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tstatic validation(inputName: string, reason: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tstatic missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedType, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tstatic invalidDefault(\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`ValueList input \"${inputName}\" default value \"${defaultValue}\" is not in available values`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{ context: { inputName, defaultValue, availableValues, ...context } }\n\t\t);\n\t}\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tstatic unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>) {\n\t\treturn new RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...context }\n\t\t});\n\t}\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tstatic invalidStructure(\n\t\tinputName: string,\n\t\texpectedStructure: string,\n\t\tcontext?: Record<string, unknown>\n\t) {\n\t\treturn new RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { inputName, expectedStructure, ...context } }\n\t\t);\n\t}\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig, RetryPolicy } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute (improved response type handling).\n */\nexport type Endpoint = 'grasshopper' | 'io' | string;\n\nexport type EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\nexport type ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\n\n// ============================================================================\n// Retry Policy\n// ============================================================================\n\nconst DEFAULT_RETRY: Required<RetryPolicy> = {\n\tattempts: 0,\n\tbaseDelayMs: 500,\n\tmaxDelayMs: 30_000,\n\tretryOn429: true\n};\n\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nfunction resolveRetryPolicy(policy: RetryPolicy | undefined): Required<RetryPolicy> {\n\tif (!policy) return DEFAULT_RETRY;\n\treturn {\n\t\tattempts: policy.attempts ?? DEFAULT_RETRY.attempts,\n\t\tbaseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,\n\t\tmaxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,\n\t\tretryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429\n\t};\n}\n\n/**\n * Parse a Retry-After header value (seconds-int or HTTP-date) into ms.\n * Returns null if the header is missing or unparseable.\n */\nfunction parseRetryAfter(headerValue: string | null): number | null {\n\tif (!headerValue) return null;\n\tconst seconds = Number(headerValue);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1000;\n\tconst dateMs = Date.parse(headerValue);\n\tif (Number.isFinite(dateMs)) {\n\t\tconst delta = dateMs - Date.now();\n\t\treturn delta > 0 ? delta : 0;\n\t}\n\treturn null;\n}\n\nfunction backoffDelay(attempt: number, policy: Required<RetryPolicy>): number {\n\tconst exponential = policy.baseDelayMs * Math.pow(2, attempt);\n\tconst jitter = Math.random() * policy.baseDelayMs;\n\treturn Math.min(exponential + jitter, policy.maxDelayMs);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t\treturn;\n\t\t}\n\t\tconst id = setTimeout(() => {\n\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(id);\n\t\t\treject(new DOMException('Aborted', 'AbortError'));\n\t\t};\n\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t});\n}\n\n// ============================================================================\n// Error Handling\n// ============================================================================\n\nfunction throwHttpError(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\terrorBody: string\n): never {\n\tconst { status, statusText } = response;\n\tconst context = { url: fullUrl, requestId, method: 'POST', requestSize, serverUrl };\n\n\tconst bodyHint = errorBody ? ` — ${errorBody.slice(0, 200)}` : '';\n\tconst errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t403: {\n\t\t\tmessage: `HTTP ${status}: ${statusText}${bodyHint}`,\n\t\t\tcode: ErrorCodes.AUTH_ERROR\n\t\t},\n\t\t404: { message: `Endpoint not found: ${fullUrl}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t413: {\n\t\t\tmessage: `Request too large: ${(requestSize / 1024).toFixed(2)}KB`,\n\t\t\tcode: ErrorCodes.VALIDATION_ERROR\n\t\t},\n\t\t429: { message: 'Rate limit exceeded', code: ErrorCodes.NETWORK_ERROR },\n\t\t500: {\n\t\t\tmessage: `Server error: ${errorBody || statusText}`,\n\t\t\tcode: ErrorCodes.COMPUTATION_ERROR\n\t\t},\n\t\t502: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t503: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR },\n\t\t504: { message: `Service unavailable: ${statusText}`, code: ErrorCodes.NETWORK_ERROR }\n\t};\n\n\tconst error = errorMap[status] || {\n\t\tmessage: `HTTP ${status}: ${statusText}`,\n\t\tcode: ErrorCodes.UNKNOWN_ERROR\n\t};\n\n\tthrow new RhinoComputeError(error.message, error.code, { statusCode: status, context });\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\nfunction buildUrl(endpoint: string, serverUrl: string): string {\n\tconst base = serverUrl.replace(/\\/+$/, '');\n\tconst path = endpoint.replace(/^\\/+/, '');\n\treturn `${base}/${path}`;\n}\n\nfunction isLocalhost(serverUrl: string): boolean {\n\ttry {\n\t\tconst host = new URL(serverUrl).host;\n\t\treturn /^(localhost|127\\.0\\.0\\.1|::1)(:\\d+)?$/i.test(host);\n\t} catch {\n\t\treturn /(localhost|127\\.0\\.0\\.1)/i.test(serverUrl);\n\t}\n}\n\nfunction buildHeaders(requestId: string, config: ComputeConfig): HeadersInit {\n\tconst headers: HeadersInit = {\n\t\t'X-Request-ID': requestId,\n\t\t'Content-Type': 'application/json',\n\t\t...(config.authToken && { Authorization: config.authToken }),\n\t\t...(config.apiKey && { RhinoComputeKey: config.apiKey })\n\t};\n\n\tif (!config.apiKey && !isLocalhost(config.serverUrl)) {\n\t\tgetLogger().warn(\n\t\t\t`⚠️ [Rhino Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key is configured. Requests may fail or be rate-limited.`\n\t\t);\n\t}\n\n\treturn headers;\n}\n\nfunction generateRequestId(): string {\n\treturn `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;\n}\n\nfunction log(message: string, debug?: boolean): void {\n\tif (debug) getLogger().debug(message);\n}\n\n/**\n * Compose a caller-supplied AbortSignal with an optional timeout. Returns a\n * combined signal, or `undefined` if neither was given.\n *\n * Uses `AbortSignal.timeout` (not setTimeout) so the timer is not throttled\n * when the tab is hidden. Falls back to a manual timer for older runtimes.\n */\nfunction composeSignal(\n\tcallerSignal: AbortSignal | undefined,\n\ttimeoutMs: number | undefined\n): { signal: AbortSignal | undefined; cleanup: () => void } {\n\tconst signals: AbortSignal[] = [];\n\tlet cleanup = () => {};\n\n\tif (callerSignal) signals.push(callerSignal);\n\n\tif (timeoutMs && timeoutMs > 0) {\n\t\tif (typeof AbortSignal !== 'undefined' && typeof AbortSignal.timeout === 'function') {\n\t\t\tsignals.push(AbortSignal.timeout(timeoutMs));\n\t\t} else {\n\t\t\t// Fallback for runtimes without AbortSignal.timeout\n\t\t\tconst ctrl = new AbortController();\n\t\t\tconst id = setTimeout(() => ctrl.abort(), timeoutMs);\n\t\t\tcleanup = () => clearTimeout(id);\n\t\t\tsignals.push(ctrl.signal);\n\t\t}\n\t}\n\n\tif (signals.length === 0) return { signal: undefined, cleanup };\n\tif (signals.length === 1) return { signal: signals[0], cleanup };\n\n\tif (typeof AbortSignal !== 'undefined' && typeof (AbortSignal as any).any === 'function') {\n\t\treturn { signal: (AbortSignal as any).any(signals) as AbortSignal, cleanup };\n\t}\n\n\t// Manual composition fallback\n\tconst ctrl = new AbortController();\n\tconst onAbort = () => ctrl.abort();\n\tfor (const s of signals) {\n\t\tif (s.aborted) {\n\t\t\tctrl.abort();\n\t\t\tbreak;\n\t\t}\n\t\ts.addEventListener('abort', onAbort, { once: true });\n\t}\n\tconst prevCleanup = cleanup;\n\tcleanup = () => {\n\t\tprevCleanup();\n\t\tfor (const s of signals) s.removeEventListener('abort', onAbort);\n\t};\n\treturn { signal: ctrl.signal, cleanup };\n}\n\n// ============================================================================\n// Response Processing\n// ============================================================================\n\nasync function handleResponse(\n\tresponse: Response,\n\tfullUrl: string,\n\trequestId: string,\n\trequestSize: number,\n\tserverUrl: string,\n\tstartTime: number,\n\tdebug?: boolean\n): Promise<any> {\n\tconst responseTime = Math.round(performance.now() - startTime);\n\n\tif (!response.ok) {\n\t\t// Read body once and reuse\n\t\tlet errorBody = await response.text();\n\n\t\t// Enhanced logging for errors\n\t\tif (debug) {\n\t\t\tlog(\n\t\t\t\t`❌ Request [${requestId}] failed with HTTP ${response.status} in ${responseTime}ms`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t\tlog(` URL: ${fullUrl}`, true);\n\t\t\tlog(` Status: ${response.status} ${response.statusText}`, true);\n\t\t\tif (errorBody) {\n\t\t\t\tlog(\n\t\t\t\t\t` Response body: ${errorBody.substring(0, 500)}${errorBody.length > 500 ? '...' : ''}`,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Check if it's a valid compute response with errors/warnings\n\t\tif (response.status === 500) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse(errorBody);\n\t\t\t\t// If it has values, it's a partial success with errors\n\t\t\t\tif (parsed?.values && (parsed.errors || parsed.warnings)) {\n\t\t\t\t\tif (debug) {\n\t\t\t\t\t\tlog(\n\t\t\t\t\t\t\t`⚠️ Request [${requestId}] completed with Grasshopper errors in ${responseTime}ms`,\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (parsed.errors?.length > 0) {\n\t\t\t\t\t\t\tlog(` Errors: ${JSON.stringify(parsed.errors, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parsed.warnings?.length > 0) {\n\t\t\t\t\t\t\tlog(` Warnings: ${JSON.stringify(parsed.warnings, null, 2)}`, true);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\n\t\t\t\t// If it's a raw exception from the server (like ArgumentException), include it in the error message\n\t\t\t\tif (parsed?.Message) {\n\t\t\t\t\terrorBody = `${parsed.ExceptionType ? parsed.ExceptionType + ': ' : ''}${parsed.Message}\\n${parsed.StackTrace || ''}`;\n\t\t\t\t} else if (parsed?.error) {\n\t\t\t\t\terrorBody =\n\t\t\t\t\t\ttypeof parsed.error === 'string' ? parsed.error : JSON.stringify(parsed.error, null, 2);\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (debug) {\n\t\t\t\t\tlog(` Failed to parse error body as JSON: ${e}`, true);\n\t\t\t\t}\n\t\t\t\t// Not valid JSON, proceed with HTTP error\n\t\t\t}\n\t\t}\n\n\t\tthrowHttpError(response, fullUrl, requestId, requestSize, serverUrl, errorBody);\n\t}\n\n\tlog(`✅ Request [${requestId}] completed in ${responseTime}ms`, debug);\n\n\ttry {\n\t\treturn await response.json();\n\t} catch (error) {\n\t\tthrow new RhinoComputeError('Failed to parse JSON response', ErrorCodes.NETWORK_ERROR, {\n\t\t\tstatusCode: response.status,\n\t\t\tcontext: {\n\t\t\t\turl: fullUrl,\n\t\t\t\trequestId\n\t\t\t},\n\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t});\n\t}\n}\n\n// ============================================================================\n// Single attempt\n// ============================================================================\n\ninterface AttemptContext {\n\tendpoint: string;\n\tbody: string;\n\trequestSize: number;\n\tfullUrl: string;\n\trequestId: string;\n\theaders: HeadersInit;\n\tconfig: ComputeConfig | GrasshopperComputeConfig;\n}\n\ninterface AttemptResult {\n\tok: true;\n\tvalue: any;\n}\n\ninterface AttemptRetry {\n\tok: false;\n\tretry: true;\n\tdelayMs: number;\n\tcause: RhinoComputeError;\n}\n\ninterface AttemptFatal {\n\tok: false;\n\tretry: false;\n\tcause: RhinoComputeError;\n}\n\nasync function attemptFetch(\n\tctx: AttemptContext,\n\tretryPolicy: Required<RetryPolicy>,\n\tattempt: number,\n\ttotalAttempts: number\n): Promise<AttemptResult | AttemptRetry | AttemptFatal> {\n\tconst { signal, cleanup } = composeSignal(ctx.config.signal, ctx.config.timeoutMs);\n\tconst startTime = performance.now();\n\n\ttry {\n\t\tconst response = await fetch(ctx.fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: ctx.body,\n\t\t\theaders: ctx.headers,\n\t\t\tsignal\n\t\t});\n\n\t\t// 429 with Retry-After or retryable 5xx → maybe retry\n\t\tconst isRetryableStatus =\n\t\t\tRETRYABLE_STATUS.has(response.status) ||\n\t\t\t(retryPolicy.retryOn429 && response.status === 429);\n\n\t\tif (isRetryableStatus && attempt < totalAttempts - 1) {\n\t\t\tconst retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n\t\t\tconst delayMs = retryAfterMs ?? backoffDelay(attempt, retryPolicy);\n\t\t\t// Drain the body so the connection can be reused\n\t\t\tawait response.text().catch(() => {});\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tretry: true,\n\t\t\t\tdelayMs,\n\t\t\t\tcause: new RhinoComputeError(\n\t\t\t\t\t`HTTP ${response.status} ${response.statusText} (will retry)`,\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ statusCode: response.status, context: { requestId: ctx.requestId } }\n\t\t\t\t)\n\t\t\t};\n\t\t}\n\n\t\tconst value = await handleResponse(\n\t\t\tresponse,\n\t\t\tctx.fullUrl,\n\t\t\tctx.requestId,\n\t\t\tctx.requestSize,\n\t\t\tctx.config.serverUrl,\n\t\t\tstartTime,\n\t\t\tctx.config.debug\n\t\t);\n\t\treturn { ok: true, value };\n\t} catch (error) {\n\t\t// Caller-aborted vs timeout-aborted distinction\n\t\tif (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {\n\t\t\tconst callerAborted = ctx.config.signal?.aborted === true;\n\n\t\t\tif (callerAborted) {\n\t\t\t\t// Caller cancellation is never retried — propagate immediately\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: false,\n\t\t\t\t\tcause: new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t\t},\n\t\t\t\t\t\toriginalError: error\n\t\t\t\t\t})\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Timeout — retryable up to attempts limit\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Request timed out after ${ctx.config.timeoutMs}ms`,\n\t\t\t\tErrorCodes.TIMEOUT_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: ctx.config.timeoutMs,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// Network error (TypeError) — retryable\n\t\tif (error instanceof TypeError) {\n\t\t\tconst fatal = new RhinoComputeError(\n\t\t\t\t`Network error: ${error.message}`,\n\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tserverUrl: ctx.config.serverUrl,\n\t\t\t\t\t\turl: ctx.fullUrl,\n\t\t\t\t\t\trequestId: ctx.requestId,\n\t\t\t\t\t\tendpoint: ctx.endpoint,\n\t\t\t\t\t\trequestSize: ctx.requestSize\n\t\t\t\t\t},\n\t\t\t\t\toriginalError: error\n\t\t\t\t}\n\t\t\t);\n\t\t\tif (attempt < totalAttempts - 1) {\n\t\t\t\treturn { ok: false, retry: true, delayMs: backoffDelay(attempt, retryPolicy), cause: fatal };\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: fatal };\n\t\t}\n\n\t\t// RhinoComputeError thrown from handleResponse — already has full context.\n\t\t// Retryable only if it carries a retryable status code.\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tconst status = error.statusCode;\n\t\t\tconst retryable =\n\t\t\t\tstatus !== undefined &&\n\t\t\t\t(RETRYABLE_STATUS.has(status) || (retryPolicy.retryOn429 && status === 429));\n\t\t\tif (retryable && attempt < totalAttempts - 1) {\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\tretry: true,\n\t\t\t\t\tdelayMs: backoffDelay(attempt, retryPolicy),\n\t\t\t\t\tcause: error\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn { ok: false, retry: false, cause: error };\n\t\t}\n\n\t\t// Unknown — wrap and don't retry\n\t\treturn {\n\t\t\tok: false,\n\t\t\tretry: false,\n\t\t\tcause: new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.UNKNOWN_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: { endpoint: ctx.endpoint, requestId: ctx.requestId },\n\t\t\t\t\toriginalError: error instanceof Error ? error : new Error(String(error))\n\t\t\t\t}\n\t\t\t)\n\t\t};\n\t} finally {\n\t\tcleanup();\n\t}\n}\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Generic Rhino Compute fetch function.\n * Sends a POST request to any Compute endpoint with pre-prepared arguments.\n *\n * Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @typeParam E - The endpoint name (e.g., 'grasshopper', 'io'). Determines the response type for better type safety.\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request body.\n * @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).\n * @returns The parsed JSON response from the server, typed according to the endpoint.\n *\n * @example\n * // Basic usage for the Grasshopper endpoint:\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * { ... },\n * {\n * serverUrl: 'https://my-server.com',\n * debug: true,\n * timeoutMs: 30_000,\n * retry: { attempts: 2 },\n * signal: controller.signal,\n * }\n * );\n */\nexport async function fetchRhinoCompute<E extends Endpoint>(\n\tendpoint: E,\n\targs: Record<string, any>,\n\tconfig: ComputeConfig | GrasshopperComputeConfig\n): Promise<ComputeResponseFor<E>> {\n\tconst requestId = generateRequestId();\n\tconst body = JSON.stringify(args);\n\tconst requestSize = body.length;\n\tconst fullUrl = buildUrl(endpoint, config.serverUrl);\n\tconst headers = buildHeaders(requestId, config);\n\tconst retryPolicy = resolveRetryPolicy(config.retry);\n\tconst totalAttempts = retryPolicy.attempts + 1;\n\n\tif (config.debug) {\n\t\tconst sizeKb = (requestSize / 1024).toFixed(2);\n\t\tconst emoji = requestSize > 100000 ? '⚠️' : '🚀';\n\t\tlog(`${emoji} Starting compute request [${requestId}]: ${endpoint} (${sizeKb}KB)`, true);\n\t}\n\n\tconst ctx: AttemptContext = {\n\t\tendpoint,\n\t\tbody,\n\t\trequestSize,\n\t\tfullUrl,\n\t\trequestId,\n\t\theaders,\n\t\tconfig\n\t};\n\n\tlet lastError: RhinoComputeError | null = null;\n\n\tfor (let attempt = 0; attempt < totalAttempts; attempt++) {\n\t\tconst result = await attemptFetch(ctx, retryPolicy, attempt, totalAttempts);\n\n\t\tif (result.ok) return result.value as ComputeResponseFor<E>;\n\n\t\tif (!result.retry) throw result.cause;\n\n\t\tlastError = result.cause;\n\t\tif (config.debug) {\n\t\t\tlog(\n\t\t\t\t`🔁 Request [${requestId}] retrying after ${result.delayMs}ms (attempt ${attempt + 2}/${totalAttempts}): ${result.cause.message}`,\n\t\t\t\ttrue\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tawait sleep(result.delayMs, config.signal);\n\t\t} catch {\n\t\t\t// Caller cancelled during backoff\n\t\t\tthrow new RhinoComputeError('Request aborted by caller', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\t\tcontext: { endpoint, requestId, requestSize },\n\t\t\t\toriginalError: lastError\n\t\t\t});\n\t\t}\n\t}\n\n\t// Exhausted retries — throw the last seen error\n\tthrow (\n\t\tlastError ??\n\t\tnew RhinoComputeError('Unknown error after retries', ErrorCodes.UNKNOWN_ERROR, {\n\t\t\tcontext: { endpoint, requestId, requestSize }\n\t\t})\n\t);\n}\n"]}
@@ -1,2 +1,2 @@
1
- import{c as p,d as m}from"./chunk-VK2TSW7S.js";function v(r){return Buffer.from(r,"utf-8").toString("base64")}function T(r){return!r||r.length<2||r.length%4!==0?!1:/^[A-Za-z0-9+/]+={0,2}$/.test(r)}function S(r){if(typeof globalThis.Buffer=="function"){let e=globalThis.Buffer.from(r,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}if(typeof globalThis.atob=="function"){let e=globalThis.atob(r),n=new Uint8Array(e.length);for(let a=0;a<e.length;a++)n[a]=e.charCodeAt(a)&255;return n}throw new m("Base64 decoding not supported in this environment.",p.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function C(r){if(r==null)throw new m("Input bytes must not be null or undefined",p.INVALID_INPUT,{context:{receivedValue:r}});let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=r;n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191&&(n=n.slice(3));let a=n.byteLength,y=a%3,u=a-y,b="",o,i,c,l,d;for(let t=0;t<u;t+=3){let f=n[t]!==void 0?n[t]:0,h=n[t+1]!==void 0?n[t+1]:0,g=n[t+2]!==void 0?n[t+2]:0,s=f<<16|h<<8|g;if(o=(s&16515072)>>18,i=(s&258048)>>12,c=(s&4032)>>6,l=s&63,typeof e!="string")throw new Error("encodings must be a string");if(typeof o!="number"||o<0||o>=e.length)throw new Error("Invalid index a");if(typeof i!="number"||i<0||i>=e.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=e.length)throw new Error("Invalid index c");if(typeof l!="number"||l<0||l>=e.length)throw new Error("Invalid index d");let w=e[o],B=e[i],x=e[c],I=e[l];if(w===void 0||B===void 0||x===void 0||I===void 0)throw new Error("Invalid encoding index");b+=w+B+x+I}if(y===1){if(d=n[u],d===void 0)throw new Error("'chunk' must not be undefined");o=(d&252)>>2,i=(d&3)<<4;let t=e[o],f=e[i];if(t===void 0||f===void 0)throw new Error("Invalid encoding index");b+=`${t+f}==`}else if(y===2){let t=n[u]??0,f=n[u+1]!==void 0?n[u+1]:0;if(typeof t!="number"||t<0||t>255||typeof f!="number"||f<0||f>255)throw new Error("Invalid byte1");d=t<<8|f,o=(d&64512)>>10,i=(d&1008)>>4,c=(d&15)<<2;let h=e[o],g=e[i],s=e[c];if(h===void 0||g===void 0||s===void 0)throw new Error("Invalid encoding index");b+=`${h+g+s}=`}return b}export{v as a,T as b,S as c,C as d};
2
- //# sourceMappingURL=chunk-PZ4HZLFJ.js.map
1
+ import{c as p,d as m}from"./chunk-CZCPL35F.js";function v(r){return Buffer.from(r,"utf-8").toString("base64")}function T(r){return!r||r.length<2||r.length%4!==0?!1:/^[A-Za-z0-9+/]+={0,2}$/.test(r)}function S(r){if(typeof globalThis.Buffer=="function"){let e=globalThis.Buffer.from(r,"base64");return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}if(typeof globalThis.atob=="function"){let e=globalThis.atob(r),n=new Uint8Array(e.length);for(let a=0;a<e.length;a++)n[a]=e.charCodeAt(a)&255;return n}throw new m("Base64 decoding not supported in this environment.",p.INVALID_STATE,{context:{environmentInfo:"atob or Buffer not available"}})}function C(r){if(r==null)throw new m("Input bytes must not be null or undefined",p.INVALID_INPUT,{context:{receivedValue:r}});let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=r;n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191&&(n=n.slice(3));let a=n.byteLength,y=a%3,u=a-y,b="",o,i,c,l,d;for(let t=0;t<u;t+=3){let f=n[t]!==void 0?n[t]:0,h=n[t+1]!==void 0?n[t+1]:0,g=n[t+2]!==void 0?n[t+2]:0,s=f<<16|h<<8|g;if(o=(s&16515072)>>18,i=(s&258048)>>12,c=(s&4032)>>6,l=s&63,typeof e!="string")throw new Error("encodings must be a string");if(typeof o!="number"||o<0||o>=e.length)throw new Error("Invalid index a");if(typeof i!="number"||i<0||i>=e.length)throw new Error("Invalid index b");if(typeof c!="number"||c<0||c>=e.length)throw new Error("Invalid index c");if(typeof l!="number"||l<0||l>=e.length)throw new Error("Invalid index d");let w=e[o],B=e[i],x=e[c],I=e[l];if(w===void 0||B===void 0||x===void 0||I===void 0)throw new Error("Invalid encoding index");b+=w+B+x+I}if(y===1){if(d=n[u],d===void 0)throw new Error("'chunk' must not be undefined");o=(d&252)>>2,i=(d&3)<<4;let t=e[o],f=e[i];if(t===void 0||f===void 0)throw new Error("Invalid encoding index");b+=`${t+f}==`}else if(y===2){let t=n[u]??0,f=n[u+1]!==void 0?n[u+1]:0;if(typeof t!="number"||t<0||t>255||typeof f!="number"||f<0||f>255)throw new Error("Invalid byte1");d=t<<8|f,o=(d&64512)>>10,i=(d&1008)>>4,c=(d&15)<<2;let h=e[o],g=e[i],s=e[c];if(h===void 0||g===void 0||s===void 0)throw new Error("Invalid encoding index");b+=`${h+g+s}=`}return b}export{v as a,T as b,S as c,C as d};
2
+ //# sourceMappingURL=chunk-XZUTU46G.js.map
package/dist/core.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');exports.ComputeServerStats = _chunkIJZNCO5Xcjs.i; exports.ErrorCodes = _chunkIJZNCO5Xcjs.c; exports.RhinoComputeError = _chunkIJZNCO5Xcjs.d; exports.camelcaseKeys = _chunkIJZNCO5Xcjs.k; exports.enableDebugLogging = _chunkIJZNCO5Xcjs.g; exports.fetchRhinoCompute = _chunkIJZNCO5Xcjs.h; exports.getLogger = _chunkIJZNCO5Xcjs.e; exports.setLogger = _chunkIJZNCO5Xcjs.f; exports.toCamelCase = _chunkIJZNCO5Xcjs.j;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkXULONXVPcjs = require('./chunk-XULONXVP.cjs');exports.ComputeServerStats = _chunkXULONXVPcjs.i; exports.ErrorCodes = _chunkXULONXVPcjs.c; exports.RhinoComputeError = _chunkXULONXVPcjs.d; exports.camelcaseKeys = _chunkXULONXVPcjs.k; exports.enableDebugLogging = _chunkXULONXVPcjs.g; exports.fetchRhinoCompute = _chunkXULONXVPcjs.h; exports.getLogger = _chunkXULONXVPcjs.e; exports.setLogger = _chunkXULONXVPcjs.f; exports.toCamelCase = _chunkXULONXVPcjs.j;
2
2
  //# sourceMappingURL=core.cjs.map
package/dist/core.js CHANGED
@@ -1,2 +1,2 @@
1
- import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,k as i}from"./chunk-VK2TSW7S.js";export{g as ComputeServerStats,a as ErrorCodes,b as RhinoComputeError,i as camelcaseKeys,e as enableDebugLogging,f as fetchRhinoCompute,c as getLogger,d as setLogger,h as toCamelCase};
1
+ import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,k as i}from"./chunk-CZCPL35F.js";export{g as ComputeServerStats,a as ErrorCodes,b as RhinoComputeError,i as camelcaseKeys,e as enableDebugLogging,f as fetchRhinoCompute,c as getLogger,d as setLogger,h as toCamelCase};
2
2
  //# sourceMappingURL=core.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFRSLCR7Gcjs = require('./chunk-FRSLCR7G.cjs');require('./chunk-LNIUUPA5.cjs');var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');exports.GrasshopperClient = _chunkFRSLCR7Gcjs.c; exports.GrasshopperResponseProcessor = _chunkFRSLCR7Gcjs.f; exports.RhinoComputeError = _chunkIJZNCO5Xcjs.d; exports.SolveScheduler = _chunkFRSLCR7Gcjs.b; exports.TreeBuilder = _chunkFRSLCR7Gcjs.l; exports.downloadFileData = _chunkFRSLCR7Gcjs.e; exports.extractFilesFromComputeResponse = _chunkFRSLCR7Gcjs.d; exports.fetchDefinitionIO = _chunkFRSLCR7Gcjs.j; exports.fetchParsedDefinitionIO = _chunkFRSLCR7Gcjs.k; exports.hashSolveInput = _chunkFRSLCR7Gcjs.a; exports.processInput = _chunkFRSLCR7Gcjs.h; exports.processInputs = _chunkFRSLCR7Gcjs.i; exports.solveGrasshopperDefinition = _chunkFRSLCR7Gcjs.g;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJSS6OQMLcjs = require('./chunk-JSS6OQML.cjs');require('./chunk-2NFN5ERT.cjs');var _chunkXULONXVPcjs = require('./chunk-XULONXVP.cjs');exports.GrasshopperClient = _chunkJSS6OQMLcjs.c; exports.GrasshopperResponseProcessor = _chunkJSS6OQMLcjs.f; exports.RhinoComputeError = _chunkXULONXVPcjs.d; exports.SolveScheduler = _chunkJSS6OQMLcjs.b; exports.TreeBuilder = _chunkJSS6OQMLcjs.l; exports.downloadFileData = _chunkJSS6OQMLcjs.e; exports.extractFilesFromComputeResponse = _chunkJSS6OQMLcjs.d; exports.fetchDefinitionIO = _chunkJSS6OQMLcjs.j; exports.fetchParsedDefinitionIO = _chunkJSS6OQMLcjs.k; exports.hashSolveInput = _chunkJSS6OQMLcjs.a; exports.processInput = _chunkJSS6OQMLcjs.h; exports.processInputs = _chunkJSS6OQMLcjs.i; exports.solveGrasshopperDefinition = _chunkJSS6OQMLcjs.g;
2
2
  //# sourceMappingURL=grasshopper.cjs.map
@@ -1,2 +1,2 @@
1
- import{a as b,b as c,c as d,d as e,e as f,f as g,g as h,h as i,i as j,j as k,k as l,l as m}from"./chunk-WXQGTKU6.js";import"./chunk-PZ4HZLFJ.js";import{d as a}from"./chunk-VK2TSW7S.js";export{d as GrasshopperClient,g as GrasshopperResponseProcessor,a as RhinoComputeError,c as SolveScheduler,m as TreeBuilder,f as downloadFileData,e as extractFilesFromComputeResponse,k as fetchDefinitionIO,l as fetchParsedDefinitionIO,b as hashSolveInput,i as processInput,j as processInputs,h as solveGrasshopperDefinition};
1
+ import{a as b,b as c,c as d,d as e,e as f,f as g,g as h,h as i,i as j,j as k,k as l,l as m}from"./chunk-BKGFHI2J.js";import"./chunk-XZUTU46G.js";import{d as a}from"./chunk-CZCPL35F.js";export{d as GrasshopperClient,g as GrasshopperResponseProcessor,a as RhinoComputeError,c as SolveScheduler,m as TreeBuilder,f as downloadFileData,e as extractFilesFromComputeResponse,k as fetchDefinitionIO,l as fetchParsedDefinitionIO,b as hashSolveInput,i as processInput,j as processInputs,h as solveGrasshopperDefinition};
2
2
  //# sourceMappingURL=grasshopper.js.map
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFRSLCR7Gcjs = require('./chunk-FRSLCR7G.cjs');require('./chunk-LNIUUPA5.cjs');var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');exports.ComputeServerStats = _chunkIJZNCO5Xcjs.i; exports.ErrorCodes = _chunkIJZNCO5Xcjs.c; exports.GrasshopperClient = _chunkFRSLCR7Gcjs.c; exports.GrasshopperResponseProcessor = _chunkFRSLCR7Gcjs.f; exports.RhinoComputeError = _chunkIJZNCO5Xcjs.d; exports.SolveScheduler = _chunkFRSLCR7Gcjs.b; exports.TreeBuilder = _chunkFRSLCR7Gcjs.l; exports.camelcaseKeys = _chunkIJZNCO5Xcjs.k; exports.downloadFileData = _chunkFRSLCR7Gcjs.e; exports.enableDebugLogging = _chunkIJZNCO5Xcjs.g; exports.extractFilesFromComputeResponse = _chunkFRSLCR7Gcjs.d; exports.fetchDefinitionIO = _chunkFRSLCR7Gcjs.j; exports.fetchParsedDefinitionIO = _chunkFRSLCR7Gcjs.k; exports.fetchRhinoCompute = _chunkIJZNCO5Xcjs.h; exports.getLogger = _chunkIJZNCO5Xcjs.e; exports.hashSolveInput = _chunkFRSLCR7Gcjs.a; exports.processInput = _chunkFRSLCR7Gcjs.h; exports.processInputs = _chunkFRSLCR7Gcjs.i; exports.setLogger = _chunkIJZNCO5Xcjs.f; exports.solveGrasshopperDefinition = _chunkFRSLCR7Gcjs.g; exports.toCamelCase = _chunkIJZNCO5Xcjs.j;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJSS6OQMLcjs = require('./chunk-JSS6OQML.cjs');require('./chunk-2NFN5ERT.cjs');var _chunkXULONXVPcjs = require('./chunk-XULONXVP.cjs');exports.ComputeServerStats = _chunkXULONXVPcjs.i; exports.ErrorCodes = _chunkXULONXVPcjs.c; exports.GrasshopperClient = _chunkJSS6OQMLcjs.c; exports.GrasshopperResponseProcessor = _chunkJSS6OQMLcjs.f; exports.RhinoComputeError = _chunkXULONXVPcjs.d; exports.SolveScheduler = _chunkJSS6OQMLcjs.b; exports.TreeBuilder = _chunkJSS6OQMLcjs.l; exports.camelcaseKeys = _chunkXULONXVPcjs.k; exports.downloadFileData = _chunkJSS6OQMLcjs.e; exports.enableDebugLogging = _chunkXULONXVPcjs.g; exports.extractFilesFromComputeResponse = _chunkJSS6OQMLcjs.d; exports.fetchDefinitionIO = _chunkJSS6OQMLcjs.j; exports.fetchParsedDefinitionIO = _chunkJSS6OQMLcjs.k; exports.fetchRhinoCompute = _chunkXULONXVPcjs.h; exports.getLogger = _chunkXULONXVPcjs.e; exports.hashSolveInput = _chunkJSS6OQMLcjs.a; exports.processInput = _chunkJSS6OQMLcjs.h; exports.processInputs = _chunkJSS6OQMLcjs.i; exports.setLogger = _chunkXULONXVPcjs.f; exports.solveGrasshopperDefinition = _chunkJSS6OQMLcjs.g; exports.toCamelCase = _chunkXULONXVPcjs.j;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as b,b as c,c as d,d as g,e as h,f as i,g as j,h as k,i as l,j as n,k as q,l as s}from"./chunk-WXQGTKU6.js";import"./chunk-PZ4HZLFJ.js";import{c as o,d as r,e,f,g as m,h as p,i as t,j as x,k as a}from"./chunk-VK2TSW7S.js";export{t as ComputeServerStats,o as ErrorCodes,d as GrasshopperClient,i as GrasshopperResponseProcessor,r as RhinoComputeError,c as SolveScheduler,s as TreeBuilder,a as camelcaseKeys,h as downloadFileData,m as enableDebugLogging,g as extractFilesFromComputeResponse,n as fetchDefinitionIO,q as fetchParsedDefinitionIO,p as fetchRhinoCompute,e as getLogger,b as hashSolveInput,k as processInput,l as processInputs,f as setLogger,j as solveGrasshopperDefinition,x as toCamelCase};
1
+ import{a as b,b as c,c as d,d as g,e as h,f as i,g as j,h as k,i as l,j as n,k as q,l as s}from"./chunk-BKGFHI2J.js";import"./chunk-XZUTU46G.js";import{c as o,d as r,e,f,g as m,h as p,i as t,j as x,k as a}from"./chunk-CZCPL35F.js";export{t as ComputeServerStats,o as ErrorCodes,d as GrasshopperClient,i as GrasshopperResponseProcessor,r as RhinoComputeError,c as SolveScheduler,s as TreeBuilder,a as camelcaseKeys,h as downloadFileData,m as enableDebugLogging,g as extractFilesFromComputeResponse,n as fetchDefinitionIO,q as fetchParsedDefinitionIO,p as fetchRhinoCompute,e as getLogger,b as hashSolveInput,k as processInput,l as processInputs,f as setLogger,j as solveGrasshopperDefinition,x as toCamelCase};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkLNIUUPA5cjs = require('./chunk-LNIUUPA5.cjs');var _chunkIJZNCO5Xcjs = require('./chunk-IJZNCO5X.cjs');var _three = require('three'); var i = _interopRequireWildcard(_three); var y = _interopRequireWildcard(_three); var E = _interopRequireWildcard(_three); var b = _interopRequireWildcard(_three);var _OrbitControlsjs = require('three/addons/controls/OrbitControls.js');var _HDRLoaderjs = require('three/addons/loaders/HDRLoader.js');var W=new i.Vector3(0,0,1),P=(e,r,t,n)=>{switch(e){case"mm":return r;case"cm":return t;default:return n}},$= exports.initThree =function(e,r){let t=oe(r||{}),n=ae(t),o=de(t,e),s=he(e,t),a=ue(o,e,t);ce(n,t),le(n,t),_optionalChain([t, 'access', _2 => _2.floor, 'optionalAccess', _3 => _3.enabled])&&fe(n,t);let l=t.events.enableEventHandlers!==!1?me(e,n,o,a,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},c=e.parentElement,g=()=>c?{width:c.clientWidth,height:c.clientHeight}:{width:window.innerWidth,height:window.innerHeight},{animate:u,dispose:d}=ie(s,n,o,a,g,t.events.onFrame);u();let m=_optionalChain([t, 'access', _4 => _4.environment, 'optionalAccess', _5 => _5.sceneUp])||W;return n.up.set(m.x,m.y,m.z),{scene:n,camera:o,controls:a,renderer:s,dispose:()=>{d(),l.dispose(),a.dispose(),s.dispose(),n.traverse(h=>{h instanceof i.Mesh&&(_optionalChain([h, 'access', _6 => _6.geometry, 'optionalAccess', _7 => _7.dispose, 'call', _8 => _8()]),Array.isArray(h.material)?h.material.forEach(x=>x.dispose()):_optionalChain([h, 'access', _9 => _9.material, 'optionalAccess', _10 => _10.dispose, 'call', _11 => _11()]))})},fitToView:l.fitToView,clearSelection:l.clearSelection}};function oe(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:_optionalChain([e, 'access', _12 => _12.camera, 'optionalAccess', _13 => _13.position])||new i.Vector3(-n.cameraDistance,n.cameraDistance,n.cameraDistance),fov:_optionalChain([e, 'access', _14 => _14.camera, 'optionalAccess', _15 => _15.fov])||20,near:_optionalChain([e, 'access', _16 => _16.camera, 'optionalAccess', _17 => _17.near])||n.near,far:_optionalChain([e, 'access', _18 => _18.camera, 'optionalAccess', _19 => _19.far])||n.far,target:_optionalChain([e, 'access', _20 => _20.camera, 'optionalAccess', _21 => _21.target])||new i.Vector3(0,0,0)},lighting:{enableSunlight:_nullishCoalesce(_optionalChain([e, 'access', _22 => _22.lighting, 'optionalAccess', _23 => _23.enableSunlight]), () => (!0)),sunlightIntensity:_optionalChain([e, 'access', _24 => _24.lighting, 'optionalAccess', _25 => _25.sunlightIntensity])||1,sunlightPosition:_optionalChain([e, 'access', _26 => _26.lighting, 'optionalAccess', _27 => _27.sunlightPosition])||new i.Vector3(n.lightDistance,n.lightHeight,n.lightDistance),ambientLightColor:_optionalChain([e, 'access', _28 => _28.lighting, 'optionalAccess', _29 => _29.ambientLightColor])||new i.Color(4210752),ambientLightIntensity:_optionalChain([e, 'access', _30 => _30.lighting, 'optionalAccess', _31 => _31.ambientLightIntensity])||1,sunlightColor:_optionalChain([e, 'access', _32 => _32.lighting, 'optionalAccess', _33 => _33.sunlightColor])||16777215},environment:{hdrPath:_optionalChain([e, 'access', _34 => _34.environment, 'optionalAccess', _35 => _35.hdrPath])||"/baseHDR.hdr",backgroundColor:_optionalChain([e, 'access', _36 => _36.environment, 'optionalAccess', _37 => _37.backgroundColor])||new i.Color(15790320),enableEnvironmentLighting:_nullishCoalesce(_optionalChain([e, 'access', _38 => _38.environment, 'optionalAccess', _39 => _39.enableEnvironmentLighting]), () => (!0)),sceneUp:_optionalChain([e, 'access', _40 => _40.environment, 'optionalAccess', _41 => _41.sceneUp])||W,showEnvironment:_nullishCoalesce(_optionalChain([e, 'access', _42 => _42.environment, 'optionalAccess', _43 => _43.showEnvironment]), () => (!1))},floor:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _44 => _44.floor, 'optionalAccess', _45 => _45.enabled]), () => (!1)),size:_optionalChain([e, 'access', _46 => _46.floor, 'optionalAccess', _47 => _47.size])||n.floorSize,color:_optionalChain([e, 'access', _48 => _48.floor, 'optionalAccess', _49 => _49.color])||new i.Color(8421504),roughness:_optionalChain([e, 'access', _50 => _50.floor, 'optionalAccess', _51 => _51.roughness])||.7,metalness:_optionalChain([e, 'access', _52 => _52.floor, 'optionalAccess', _53 => _53.metalness])||0,receiveShadow:_nullishCoalesce(_optionalChain([e, 'access', _54 => _54.floor, 'optionalAccess', _55 => _55.receiveShadow]), () => (!0))},render:{enableShadows:_nullishCoalesce(_optionalChain([e, 'access', _56 => _56.render, 'optionalAccess', _57 => _57.enableShadows]), () => (!0)),shadowMapSize:_optionalChain([e, 'access', _58 => _58.render, 'optionalAccess', _59 => _59.shadowMapSize])||2048,antialias:_nullishCoalesce(_optionalChain([e, 'access', _60 => _60.render, 'optionalAccess', _61 => _61.antialias]), () => (!0)),pixelRatio:_optionalChain([e, 'access', _62 => _62.render, 'optionalAccess', _63 => _63.pixelRatio])||Math.min(window.devicePixelRatio,2),toneMapping:_optionalChain([e, 'access', _64 => _64.render, 'optionalAccess', _65 => _65.toneMapping])||i.NeutralToneMapping,toneMappingExposure:_optionalChain([e, 'access', _66 => _66.render, 'optionalAccess', _67 => _67.toneMappingExposure])||1,preserveDrawingBuffer:_nullishCoalesce(_optionalChain([e, 'access', _68 => _68.render, 'optionalAccess', _69 => _69.preserveDrawingBuffer]), () => (!1))},controls:{enableDamping:_nullishCoalesce(_optionalChain([e, 'access', _70 => _70.controls, 'optionalAccess', _71 => _71.enableDamping]), () => (!1)),dampingFactor:_optionalChain([e, 'access', _72 => _72.controls, 'optionalAccess', _73 => _73.dampingFactor])||.05,autoRotate:_nullishCoalesce(_optionalChain([e, 'access', _74 => _74.controls, 'optionalAccess', _75 => _75.autoRotate]), () => (!1)),autoRotateSpeed:_optionalChain([e, 'access', _76 => _76.controls, 'optionalAccess', _77 => _77.autoRotateSpeed])||.5,enableZoom:_nullishCoalesce(_optionalChain([e, 'access', _78 => _78.controls, 'optionalAccess', _79 => _79.enableZoom]), () => (!0)),enablePan:_nullishCoalesce(_optionalChain([e, 'access', _80 => _80.controls, 'optionalAccess', _81 => _81.enablePan]), () => (!0)),minDistance:_optionalChain([e, 'access', _82 => _82.controls, 'optionalAccess', _83 => _83.minDistance])||n.minDistance,maxDistance:_optionalChain([e, 'access', _84 => _84.controls, 'optionalAccess', _85 => _85.maxDistance])||1/0},events:{onBackgroundClicked:_optionalChain([e, 'access', _86 => _86.events, 'optionalAccess', _87 => _87.onBackgroundClicked]),onObjectSelected:_optionalChain([e, 'access', _88 => _88.events, 'optionalAccess', _89 => _89.onObjectSelected]),onMeshMetadataClicked:_optionalChain([e, 'access', _90 => _90.events, 'optionalAccess', _91 => _91.onMeshMetadataClicked]),onMeshDoubleClicked:_optionalChain([e, 'access', _92 => _92.events, 'optionalAccess', _93 => _93.onMeshDoubleClicked]),selectionColor:_optionalChain([e, 'access', _94 => _94.events, 'optionalAccess', _95 => _95.selectionColor])||"#ff0000",enableEventHandlers:_nullishCoalesce(_optionalChain([e, 'access', _96 => _96.events, 'optionalAccess', _97 => _97.enableEventHandlers]), () => (!0)),enableKeyboardControls:_nullishCoalesce(_optionalChain([e, 'access', _98 => _98.events, 'optionalAccess', _99 => _99.enableKeyboardControls]), () => (!0)),enableClickToFocus:_nullishCoalesce(_optionalChain([e, 'access', _100 => _100.events, 'optionalAccess', _101 => _101.enableClickToFocus]), () => (!0)),enableDoubleClickZoom:_nullishCoalesce(_optionalChain([e, 'access', _102 => _102.events, 'optionalAccess', _103 => _103.enableDoubleClickZoom]), () => (!0)),onReady:_optionalChain([e, 'access', _104 => _104.events, 'optionalAccess', _105 => _105.onReady]),onFrame:_optionalChain([e, 'access', _106 => _106.events, 'optionalAccess', _107 => _107.onFrame])}}}function ae(e){let r=new i.Scene,t=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function se(e,r,t,n,o=200){let s=e.position.clone(),a=r.target.clone(),l=performance.now(),c=u=>1-Math.pow(1-u,3),g=()=>{let u=performance.now()-l,d=c(Math.min(u/o,1));e.position.lerpVectors(s,t,d),r.target.lerpVectors(a,n,d),r.update(),d<1&&requestAnimationFrame(g)};requestAnimationFrame(g)}function ie(e,r,t,n,o,s){let a=null,l=performance.now(),c=()=>{let{width:d,height:m}=o();if(d===0||m===0)return;let w=Math.min(window.devicePixelRatio,2),h=Math.round(d*w),x=Math.round(m*w);(e.domElement.width!==h||e.domElement.height!==x)&&(e.setPixelRatio(w),e.setSize(d,m,!1),t.aspect=d/m,t.updateProjectionMatrix())},g=function(){a=requestAnimationFrame(g);let d=performance.now(),m=(d-l)/1e3;l=d,c(),(n.enableDamping||n.autoRotate)&&n.update(),_optionalChain([s, 'optionalCall', _108 => _108(m)]),e.render(r,t)};return{animate:g,dispose:()=>{a!==null&&(cancelAnimationFrame(a),a=null)}}}function ce(e,r){r.environment.enableEnvironmentLighting?new (0, _HDRLoaderjs.HDRLoader)().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){t.mapping=i.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),_optionalChain([r, 'access', _109 => _109.events, 'access', _110 => _110.onReady, 'optionalCall', _111 => _111()])},void 0,function(t){_chunkIJZNCO5Xcjs.e.call(void 0, ).warn("HDR texture could not be loaded, falling back to basic lighting:",t),_optionalChain([r, 'access', _112 => _112.events, 'access', _113 => _113.onReady, 'optionalCall', _114 => _114()])}):_optionalChain([r, 'access', _115 => _115.events, 'access', _116 => _116.onReady, 'optionalCall', _117 => _117()])}function le(e,r){let t=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new i.DirectionalLight(_nullishCoalesce(r.lighting.sunlightColor, () => (16777215)),r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows){n.castShadow=!0;let s=P(r.sceneScale,.1,10,100);n.shadow.camera.left=-s,n.shadow.camera.right=s,n.shadow.camera.top=s,n.shadow.camera.bottom=-s;let a=P(r.sceneScale,.001,.1,.5),l=P(r.sceneScale,1,100,500);n.shadow.camera.near=a,n.shadow.camera.far=l,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function fe(e,r){let t=r.floor.size,n=new i.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,s=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),a=new i.Mesh(n,s);a.userData.id="floor",a.name="floor",a.rotation.x=-Math.PI/2,a.position.y=0,r.floor.receiveShadow&&r.render.enableShadows&&(a.receiveShadow=!0),e.add(a)}function de(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function he(e,r){let t=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,s=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,s,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=i.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=i.SRGBColorSpace,t.sortObjects=!0,t}function me(e,r,t,n,o){let s=new Set,a=new Map,l=new i.Raycaster,c=new i.Vector2,g=new i.Vector2,u=f=>{let R=f;for(;R;){if(!R.visible)return!1;R=R.parent}return!0},d=()=>{let f=new i.Box3;if(r.traverse(D=>{D.visible&&D.userData.id!=="floor"&&D instanceof i.Mesh&&f.expandByObject(D)}),f.isEmpty()){_chunkIJZNCO5Xcjs.e.call(void 0, ).warn("No objects to fit to view");return}let R=f.getCenter(new i.Vector3),M=f.getSize(new i.Vector3),A=Math.max(M.x,M.y,M.z),T=t.fov*(Math.PI/180),v=A/(2*Math.tan(T/2));v*=1.5;let B=t.position.clone().sub(n.target).normalize();t.position.copy(R.clone().add(B.multiplyScalar(v))),n.target.copy(R),n.update()},m=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),w=()=>{s.forEach(f=>{f instanceof i.Mesh&&a.has(f)&&(f.material=a.get(f),a.delete(f))}),s.clear()},h=f=>{g.set(f.clientX,f.clientY)},x=f=>{let R=new i.Vector2(f.clientX,f.clientY);if(g.distanceTo(R)>5)return;let M=e.getBoundingClientRect();c.x=(f.clientX-M.left)/M.width*2-1,c.y=-((f.clientY-M.top)/M.height)*2+1,l.setFromCamera(c,t);let A=l.intersectObjects(r.children,!0).filter(T=>u(T.object));if(A.length>0){let T=A[0].object;if(!s.has(T)){if(w(),s.add(T),T instanceof i.Mesh&&T.material instanceof i.Material){a.set(T,T.material);let v=T.material.clone();v.emissive=m.clone(),T.material=v}_optionalChain([o, 'access', _118 => _118.events, 'optionalAccess', _119 => _119.onObjectSelected, 'optionalCall', _120 => _120(T)]),T instanceof i.Mesh&&Object.keys(T.userData).length>0&&_optionalChain([o, 'access', _121 => _121.events, 'optionalAccess', _122 => _122.onMeshMetadataClicked, 'optionalCall', _123 => _123(T.userData)])}}else w(),_optionalChain([o, 'access', _124 => _124.events, 'optionalAccess', _125 => _125.onBackgroundClicked, 'optionalCall', _126 => _126({x:c.x,y:c.y})])},I=f=>{let R=e.getBoundingClientRect();c.x=(f.clientX-R.left)/R.width*2-1,c.y=-((f.clientY-R.top)/R.height)*2+1,l.setFromCamera(c,t);let M=l.intersectObjects(r.children,!0).filter(ee=>u(ee.object));if(M.length===0)return;let A=M[0].object;if(_optionalChain([o, 'access', _127 => _127.events, 'optionalAccess', _128 => _128.onMeshDoubleClicked, 'optionalCall', _129 => _129(A)]),!_optionalChain([o, 'access', _130 => _130.events, 'optionalAccess', _131 => _131.enableDoubleClickZoom]))return;let T=new i.Box3().setFromObject(A);if(T.isEmpty())return;let v=T.getCenter(new i.Vector3),B=T.getSize(new i.Vector3),D=Math.max(B.x,B.y,B.z),K=t.fov*(Math.PI/180),X=D/(2*Math.tan(K/2))*1.5,J=t.position.clone().sub(n.target).normalize(),Q=v.clone().add(J.multiplyScalar(X));se(t,n,Q,v)},L=f=>{if(_optionalChain([o, 'access', _132 => _132.events, 'optionalAccess', _133 => _133.enableKeyboardControls]))switch(f.key.toLowerCase()){case"f":f.preventDefault(),d();break;case"escape":f.preventDefault(),w();break;case" ":f.preventDefault(),d();break}};return _optionalChain([o, 'access', _134 => _134.events, 'optionalAccess', _135 => _135.enableClickToFocus])&&(e.addEventListener("mousedown",h),e.addEventListener("click",x),e.addEventListener("dblclick",I)),_optionalChain([o, 'access', _136 => _136.events, 'optionalAccess', _137 => _137.enableKeyboardControls])&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",L)),{dispose:()=>{e.removeEventListener("mousedown",h),e.removeEventListener("click",x),e.removeEventListener("dblclick",I),e.removeEventListener("keydown",L),w()},fitToView:d,clearSelection:w}}function ue(e,r,t){let n=new (0, _OrbitControlsjs.OrbitControls)(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=_nullishCoalesce(t.controls.enableZoom, () => (!0)),n.enablePan=_nullishCoalesce(t.controls.enablePan, () => (!0)),n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}var C={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},INITIAL_DISTANCE_MULTIPLIER:4};function j(e,r,t,n,o){if(Ee(e),r.length===0)return;r.forEach(u=>{e.add(u)});let s=F(r),a=s.getCenter(new y.Vector3),l=s.getSize(new y.Vector3),c=Math.max(l.x,l.y,l.z);if(c/Math.min(l.x||1,l.y||1,l.z||1)>C.SCALE_RATIO_THRESHOLD||c>C.HUGE_THRESHOLD?(t.near=c*C.NEAR_PLANE_FACTOR.TINY,t.far=c*C.FAR_PLANE_FACTOR.HUGE):c>C.LARGE_THRESHOLD?(t.near=c*C.NEAR_PLANE_FACTOR.SMALL,t.far=c*C.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,c*C.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,c*C.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let u=c*C.INITIAL_DISTANCE_MULTIPLIER;t.position.set(a.x+u*.8,a.y+u,a.z+u*1.2),n.target.copy(a),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function z(e){if(!e||typeof e!="string")return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Invalid color input: ${e}, using white`),new y.Color(16777215);let r=e.trim();if(r.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new y.Color(t)}catch (e2){return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Invalid hex color: ${e}, using white`),new y.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new y.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new y.Color(r.toLowerCase())}catch (e3){return _chunkIJZNCO5Xcjs.e.call(void 0, ).warn(`Invalid color string: ${e}, using white`),new y.Color(16777215)}}function _(e,r){e.forEach(t=>{t.position.y-=r})}function F(e){let r=new y.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new y.Box3().setFromObject(t);r.union(n)}),r}function Ee(e){[...e.children].forEach(t=>{t.userData.id!=="floor"&&(t.traverse(n=>{if(!(n instanceof y.Mesh))return;_optionalChain([n, 'access', _138 => _138.geometry, 'optionalAccess', _139 => _139.dispose, 'call', _140 => _140()]),(Array.isArray(n.material)?n.material:[n.material]).forEach(s=>{for(let a of Object.values(s))a instanceof y.Texture&&a.dispose();s.dispose()})}),t.removeFromParent())})}var V={};_chunkIJZNCO5Xcjs.a.call(void 0, V,{CONCRETE_MATERIAL:()=>Re,EMISSIVE_MATERIAL:()=>pe,GLASS_MATERIAL:()=>ye,METAL_MATERIAL:()=>ge,PLASTIC_MATERIAL:()=>Te,RUBBER_MATERIAL:()=>we,WOOD_MATERIAL:()=>be});var pe=new E.MeshPhysicalMaterial({color:0,emissive:new E.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),ge=new E.MeshPhysicalMaterial({color:new E.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),Re=new E.MeshPhysicalMaterial({color:new E.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),Te=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),ye=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:E.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new E.MeshPhysicalMaterial({color:new E.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),be=new E.MeshPhysicalMaterial({color:new E.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});var _fflate = require('fflate'); var q = _interopRequireWildcard(_fflate);async function Y(e){return new Promise((r,t)=>{try{let n=()=>{try{let o=_chunkLNIUUPA5cjs.c.call(void 0, e),s=q.gunzipSync(o),a=Me(s);r(a)}catch(o){t(new (0, _chunkIJZNCO5Xcjs.d)(o instanceof _chunkIJZNCO5Xcjs.d?o.message:`Failed to decompress batched data: ${o instanceof Error?o.message:String(o)}`,o instanceof _chunkIJZNCO5Xcjs.d?o.code:_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))}))}};"requestIdleCallback"in globalThis?globalThis.requestIdleCallback(n,{timeout:5e3}):setTimeout(n,0)}catch(n){t(new (0, _chunkIJZNCO5Xcjs.d)(`Failed to schedule decompression: ${n instanceof Error?n.message:String(n)}`,_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{originalError:n instanceof Error?n:new Error(String(n))}))}})}function Me(e){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),t=0;if(t+4>r.byteLength)throw new (0, _chunkIJZNCO5Xcjs.d)("Insufficient data to read the number of vertex floats.",_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength,offset:t}});let n=r.getUint32(t,!0);if(t+=4,n%3!==0)throw new (0, _chunkIJZNCO5Xcjs.d)("Invalid number of vertex floats; should be divisible by 3.",_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{numVertexFloats:n,remainder:n%3,totalBytes:r.byteLength}});let o=n*Float32Array.BYTES_PER_ELEMENT;if(t+o>r.byteLength)throw new (0, _chunkIJZNCO5Xcjs.d)("Insufficient data to read vertices.",_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{expectedBytes:o,availableBytes:r.byteLength-t,offset:t}});let s=new Float32Array(e.buffer.slice(e.byteOffset+t,e.byteOffset+t+o));if(t+=o,t+4>r.byteLength)throw new (0, _chunkIJZNCO5Xcjs.d)("Insufficient data to read the number of face indices.",_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:r.byteLength-t,offset:t}});let a=r.getUint32(t,!0);t+=4;let l=a*Uint32Array.BYTES_PER_ELEMENT;if(t+l>r.byteLength)throw new (0, _chunkIJZNCO5Xcjs.d)("Insufficient data to read face indices.",_chunkIJZNCO5Xcjs.c.VALIDATION_ERROR,{context:{expectedBytes:l,availableBytes:r.byteLength-t,offset:t}});let c=new Uint32Array(e.buffer.slice(e.byteOffset+t,e.byteOffset+t+l));return{vertices:s,faces:c}}async function N(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,debug:o=!1}=_nullishCoalesce(r, () => ({})),s=o?performance.now():0,a=0;try{let l=performance.now(),c=JSON.parse(e);return a=performance.now()-l,await k(c,{mergeByMaterial:t,applyTransforms:n,debug:o,parseTime:a,perfStart:s})}catch(l){return _chunkIJZNCO5Xcjs.e.call(void 0, ).error("Error parsing mesh batch:",l),[]}}async function k(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:s=!1,parseTime:a=0,perfStart:l=s?performance.now():0}=_nullishCoalesce(r, () => ({})),c=0,g=0;try{let u=performance.now(),{vertices:d,faces:m}=await Y(e.compressedData);c=performance.now()-u;let w=(e.compressedData.length*.75/1024/1024).toFixed(2),h=((d.byteLength+m.byteLength)/1024/1024).toFixed(2),x=((1-parseFloat(w)/parseFloat(h))*100).toFixed(1);s&&(_chunkIJZNCO5Xcjs.e.call(void 0, ).debug("Mesh Batch Stats:"),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Materials: ${e.materials.length} | Groups: ${e.groups.length}`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Vertices: ${(d.length/3).toLocaleString()} | Faces: ${(m.length/3).toLocaleString()}`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Compressed: ${w} MB | Uncompressed: ${h} MB`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Compression Ratio: ${x}%`)),n&&ve(d);let I=performance.now(),L=e.materials.map(xe),S=[];for(let f of e.groups)if(t&&f.meshes.length>1){let R=He(f,d,m,L);R.userData.sourceComponentId=_nullishCoalesce(e.sourceComponentId, () => (null)),S.push(R)}else{let R=Ce(f,d,m,L);for(let M of R)M.userData.sourceComponentId=_nullishCoalesce(e.sourceComponentId, () => (null));S.push(...R)}if(o!==1)for(let f of S)f.scale.set(o,o,o);if(g=performance.now()-I,s){let f=performance.now()-l;_chunkIJZNCO5Xcjs.e.call(void 0, ).debug("Performance:"),a>0&&_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Parse JSON: ${a.toFixed(2)}ms`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Decompress: ${c.toFixed(2)}ms`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Create Meshes: ${g.toFixed(2)}ms`),_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(` Total: ${f.toFixed(2)}ms`)}return S}catch(u){return _chunkIJZNCO5Xcjs.e.call(void 0, ).error("Error parsing mesh batch object:",u),[]}}function xe(e){let r=z(e.color);return new b.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function He(e,r,t,n){let o=new b.BufferGeometry,s=0,a=0;for(let h of e.meshes)s+=h.vertexCount,a+=h.faceCount;let l=new Float32Array(s),c=new Uint32Array(a),g=0,u=0;for(let h of e.meshes){l.set(r.subarray(h.vertexOffset,h.vertexOffset+h.vertexCount),g);let x=t.subarray(h.faceOffset,h.faceOffset+h.faceCount),I=Math.floor(h.vertexOffset/3),S=Math.floor(g/3)-I;for(let f=0;f<x.length;f++)c[u+f]=x[f]+S;g+=h.vertexCount,u+=h.faceCount}o.setAttribute("position",new b.BufferAttribute(l,3)),o.setIndex(new b.BufferAttribute(c,1)),o.computeVertexNormals();let d=new b.Mesh(o,n[e.materialId]),m=e.meshes[0],w=e.meshes.map(h=>h.name).filter(h=>h&&h.length>0);return d.name=w.length>0?w[0]:`merged_material_${e.materialId}`,d.castShadow=!0,d.receiveShadow=!0,d.userData={name:d.name,layer:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _141 => _141.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _142 => _142.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _143 => _143.metadata]), () => ({})),mergedFrom:e.meshes.slice(1).map(h=>({name:h.name,layer:h.layer,originalIndex:h.originalIndex}))},d}function Ce(e,r,t,n){let o=[];for(let s of e.meshes){let a=new b.BufferGeometry,l=r.subarray(s.vertexOffset,s.vertexOffset+s.vertexCount),c=t.subarray(s.faceOffset,s.faceOffset+s.faceCount),g=Math.floor(s.vertexOffset/3),u=new Uint32Array(c.length);for(let m=0;m<c.length;m++)u[m]=c[m]-g;a.setAttribute("position",new b.BufferAttribute(l,3)),a.setIndex(new b.BufferAttribute(u,1)),a.computeVertexNormals();let d=new b.Mesh(a,n[e.materialId]);d.name=s.name,d.userData={name:s.name,layer:_nullishCoalesce(s.layer, () => ("")),originalIndex:s.originalIndex,metadata:_nullishCoalesce(s.metadata, () => ({}))},d.castShadow=!0,d.receiveShadow=!0,o.push(d)}return o}function ve(e){let r=Math.cos(-Math.PI/2),t=Math.sin(-Math.PI/2);for(let n=0;n<e.length;n+=3){let o=e[n],s=e[n+1],a=e[n+2];e[n]=o,e[n+1]=s*r-a*t,e[n+2]=s*t+a*r}}var U={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},Oe="Display";async function Z(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:l={}}=_nullishCoalesce(r, () => ({}));try{let c=o?Se(e.modelunits):1;return await Ae(e,n,c,l,a),s&&Le(n),n}catch(c){throw De(c,n),c}finally{a&&Fe(t)}}function Se(e){return _nullishCoalesce(U[e], () => (1))}async function Ae(e,r,t,n,o){for(let s of e.values){let a=s.InnerTree;for(let l in a){let c=a[l];c&&await Ie(c,r,t,n,o)}}}async function Ie(e,r,t,n,o){for(let s of e)if(s.type.includes(Oe)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await N(s.data,a);if(t!==1)for(let c of l)c.scale.set(t,t,t);r.push(...l),o&&_chunkIJZNCO5Xcjs.e.call(void 0, ).debug(`Extracted ${l.length} meshes from batch`)}}function Le(e){if(e.length===0)return;let t=F(e).min.y;_(e,t)}function De(e,r){_chunkIJZNCO5Xcjs.e.call(void 0, ).error("An unexpected error occurred:",e),Be(r)}function Be(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(t=>t.dispose()):r.material.dispose())}function Fe(e){let r=performance.now()-e;_chunkIJZNCO5Xcjs.e.call(void 0, ).info("Time to process meshes:",`${r.toFixed(2)}ms`)}exports.Materials = V; exports.SCALE_FACTORS = U; exports.getThreeMeshesFromComputeResponse = Z; exports.initThree = $; exports.parseMeshBatchObject = k; exports.updateScene = j;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk2NFN5ERTcjs = require('./chunk-2NFN5ERT.cjs');var _chunkXULONXVPcjs = require('./chunk-XULONXVP.cjs');var _three = require('three'); var i = _interopRequireWildcard(_three); var w = _interopRequireWildcard(_three); var E = _interopRequireWildcard(_three); var b = _interopRequireWildcard(_three);var _OrbitControlsjs = require('three/addons/controls/OrbitControls.js');var _HDRLoaderjs = require('three/addons/loaders/HDRLoader.js');var $=new i.Vector3(0,0,1),z=(e,r,t,n)=>{switch(e){case"mm":return r;case"cm":return t;default:return n}},j= exports.initThree =function(e,r){let t=oe(r||{}),n=ae(t),o=de(t,e),s=he(e,t),a=ue(o,e,t);ce(n,t),le(n,t),_optionalChain([t, 'access', _2 => _2.floor, 'optionalAccess', _3 => _3.enabled])&&fe(n,t);let l=t.events.enableEventHandlers!==!1?me(e,n,o,a,t):{dispose:()=>{},fitToView:()=>{},clearSelection:()=>{}},c=e.parentElement,g=()=>c?{width:c.clientWidth,height:c.clientHeight}:{width:window.innerWidth,height:window.innerHeight},{animate:u,dispose:d}=ie(s,n,o,a,g,t.events.onFrame);u();let m=_optionalChain([t, 'access', _4 => _4.environment, 'optionalAccess', _5 => _5.sceneUp])||$;return n.up.set(m.x,m.y,m.z),{scene:n,camera:o,controls:a,renderer:s,dispose:()=>{d(),l.dispose(),a.dispose(),s.dispose(),n.traverse(h=>{h instanceof i.Mesh&&(_optionalChain([h, 'access', _6 => _6.geometry, 'optionalAccess', _7 => _7.dispose, 'call', _8 => _8()]),Array.isArray(h.material)?h.material.forEach(x=>x.dispose()):_optionalChain([h, 'access', _9 => _9.material, 'optionalAccess', _10 => _10.dispose, 'call', _11 => _11()]))})},fitToView:l.fitToView,clearSelection:l.clearSelection}};function oe(e){let r=e.sceneScale||"m",n={mm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:10,lightHeight:20,minDistance:.1,shadowSize:100,scaleFactor:1e3},cm:{cameraDistance:20,near:.1,far:2e3,floorSize:100,lightDistance:25,lightHeight:50,minDistance:.1,shadowSize:100,scaleFactor:100},m:{cameraDistance:10,near:.01,far:2e3,floorSize:50,lightDistance:25,lightHeight:50,minDistance:.001,shadowSize:100,scaleFactor:1},inches:{cameraDistance:15,near:.1,far:2e3,floorSize:80,lightDistance:20,lightHeight:40,minDistance:.1,shadowSize:80,scaleFactor:39.37},feet:{cameraDistance:8,near:.1,far:2e3,floorSize:40,lightDistance:15,lightHeight:30,minDistance:.1,shadowSize:60,scaleFactor:3.28084}}[r];return{sceneScale:r,camera:{position:_optionalChain([e, 'access', _12 => _12.camera, 'optionalAccess', _13 => _13.position])||new i.Vector3(-n.cameraDistance,n.cameraDistance,n.cameraDistance),fov:_optionalChain([e, 'access', _14 => _14.camera, 'optionalAccess', _15 => _15.fov])||20,near:_optionalChain([e, 'access', _16 => _16.camera, 'optionalAccess', _17 => _17.near])||n.near,far:_optionalChain([e, 'access', _18 => _18.camera, 'optionalAccess', _19 => _19.far])||n.far,target:_optionalChain([e, 'access', _20 => _20.camera, 'optionalAccess', _21 => _21.target])||new i.Vector3(0,0,0)},lighting:{enableSunlight:_nullishCoalesce(_optionalChain([e, 'access', _22 => _22.lighting, 'optionalAccess', _23 => _23.enableSunlight]), () => (!0)),sunlightIntensity:_optionalChain([e, 'access', _24 => _24.lighting, 'optionalAccess', _25 => _25.sunlightIntensity])||1,sunlightPosition:_optionalChain([e, 'access', _26 => _26.lighting, 'optionalAccess', _27 => _27.sunlightPosition])||new i.Vector3(n.lightDistance,n.lightHeight,n.lightDistance),ambientLightColor:_optionalChain([e, 'access', _28 => _28.lighting, 'optionalAccess', _29 => _29.ambientLightColor])||new i.Color(4210752),ambientLightIntensity:_optionalChain([e, 'access', _30 => _30.lighting, 'optionalAccess', _31 => _31.ambientLightIntensity])||1,sunlightColor:_optionalChain([e, 'access', _32 => _32.lighting, 'optionalAccess', _33 => _33.sunlightColor])||16777215},environment:{hdrPath:_optionalChain([e, 'access', _34 => _34.environment, 'optionalAccess', _35 => _35.hdrPath])||"/baseHDR.hdr",backgroundColor:_optionalChain([e, 'access', _36 => _36.environment, 'optionalAccess', _37 => _37.backgroundColor])||new i.Color(15790320),enableEnvironmentLighting:_nullishCoalesce(_optionalChain([e, 'access', _38 => _38.environment, 'optionalAccess', _39 => _39.enableEnvironmentLighting]), () => (!0)),sceneUp:_optionalChain([e, 'access', _40 => _40.environment, 'optionalAccess', _41 => _41.sceneUp])||$,showEnvironment:_nullishCoalesce(_optionalChain([e, 'access', _42 => _42.environment, 'optionalAccess', _43 => _43.showEnvironment]), () => (!1))},floor:{enabled:_nullishCoalesce(_optionalChain([e, 'access', _44 => _44.floor, 'optionalAccess', _45 => _45.enabled]), () => (!1)),size:_optionalChain([e, 'access', _46 => _46.floor, 'optionalAccess', _47 => _47.size])||n.floorSize,color:_optionalChain([e, 'access', _48 => _48.floor, 'optionalAccess', _49 => _49.color])||new i.Color(8421504),roughness:_optionalChain([e, 'access', _50 => _50.floor, 'optionalAccess', _51 => _51.roughness])||.7,metalness:_optionalChain([e, 'access', _52 => _52.floor, 'optionalAccess', _53 => _53.metalness])||0,receiveShadow:_nullishCoalesce(_optionalChain([e, 'access', _54 => _54.floor, 'optionalAccess', _55 => _55.receiveShadow]), () => (!0))},render:{enableShadows:_nullishCoalesce(_optionalChain([e, 'access', _56 => _56.render, 'optionalAccess', _57 => _57.enableShadows]), () => (!0)),shadowMapSize:_optionalChain([e, 'access', _58 => _58.render, 'optionalAccess', _59 => _59.shadowMapSize])||2048,antialias:_nullishCoalesce(_optionalChain([e, 'access', _60 => _60.render, 'optionalAccess', _61 => _61.antialias]), () => (!0)),pixelRatio:_optionalChain([e, 'access', _62 => _62.render, 'optionalAccess', _63 => _63.pixelRatio])||Math.min(window.devicePixelRatio,2),toneMapping:_optionalChain([e, 'access', _64 => _64.render, 'optionalAccess', _65 => _65.toneMapping])||i.NeutralToneMapping,toneMappingExposure:_optionalChain([e, 'access', _66 => _66.render, 'optionalAccess', _67 => _67.toneMappingExposure])||1,preserveDrawingBuffer:_nullishCoalesce(_optionalChain([e, 'access', _68 => _68.render, 'optionalAccess', _69 => _69.preserveDrawingBuffer]), () => (!1))},controls:{enableDamping:_nullishCoalesce(_optionalChain([e, 'access', _70 => _70.controls, 'optionalAccess', _71 => _71.enableDamping]), () => (!1)),dampingFactor:_optionalChain([e, 'access', _72 => _72.controls, 'optionalAccess', _73 => _73.dampingFactor])||.05,autoRotate:_nullishCoalesce(_optionalChain([e, 'access', _74 => _74.controls, 'optionalAccess', _75 => _75.autoRotate]), () => (!1)),autoRotateSpeed:_optionalChain([e, 'access', _76 => _76.controls, 'optionalAccess', _77 => _77.autoRotateSpeed])||.5,enableZoom:_nullishCoalesce(_optionalChain([e, 'access', _78 => _78.controls, 'optionalAccess', _79 => _79.enableZoom]), () => (!0)),enablePan:_nullishCoalesce(_optionalChain([e, 'access', _80 => _80.controls, 'optionalAccess', _81 => _81.enablePan]), () => (!0)),minDistance:_optionalChain([e, 'access', _82 => _82.controls, 'optionalAccess', _83 => _83.minDistance])||n.minDistance,maxDistance:_optionalChain([e, 'access', _84 => _84.controls, 'optionalAccess', _85 => _85.maxDistance])||1/0},events:{onBackgroundClicked:_optionalChain([e, 'access', _86 => _86.events, 'optionalAccess', _87 => _87.onBackgroundClicked]),onObjectSelected:_optionalChain([e, 'access', _88 => _88.events, 'optionalAccess', _89 => _89.onObjectSelected]),onMeshMetadataClicked:_optionalChain([e, 'access', _90 => _90.events, 'optionalAccess', _91 => _91.onMeshMetadataClicked]),onMeshDoubleClicked:_optionalChain([e, 'access', _92 => _92.events, 'optionalAccess', _93 => _93.onMeshDoubleClicked]),selectionColor:_optionalChain([e, 'access', _94 => _94.events, 'optionalAccess', _95 => _95.selectionColor])||"#ff0000",enableEventHandlers:_nullishCoalesce(_optionalChain([e, 'access', _96 => _96.events, 'optionalAccess', _97 => _97.enableEventHandlers]), () => (!0)),enableKeyboardControls:_nullishCoalesce(_optionalChain([e, 'access', _98 => _98.events, 'optionalAccess', _99 => _99.enableKeyboardControls]), () => (!0)),enableClickToFocus:_nullishCoalesce(_optionalChain([e, 'access', _100 => _100.events, 'optionalAccess', _101 => _101.enableClickToFocus]), () => (!0)),enableDoubleClickZoom:_nullishCoalesce(_optionalChain([e, 'access', _102 => _102.events, 'optionalAccess', _103 => _103.enableDoubleClickZoom]), () => (!0)),onReady:_optionalChain([e, 'access', _104 => _104.events, 'optionalAccess', _105 => _105.onReady]),onFrame:_optionalChain([e, 'access', _106 => _106.events, 'optionalAccess', _107 => _107.onFrame])}}}function ae(e){let r=new i.Scene,t=typeof e.environment.backgroundColor=="string"?new i.Color(e.environment.backgroundColor):e.environment.backgroundColor;return r.background=t||null,r}function se(e,r,t,n,o=200){let s=e.position.clone(),a=r.target.clone(),l=performance.now(),c=u=>1-Math.pow(1-u,3),g=()=>{let u=performance.now()-l,d=c(Math.min(u/o,1));e.position.lerpVectors(s,t,d),r.target.lerpVectors(a,n,d),r.update(),d<1&&requestAnimationFrame(g)};requestAnimationFrame(g)}function ie(e,r,t,n,o,s){let a=null,l=performance.now(),c=()=>{let{width:d,height:m}=o();if(d===0||m===0)return;let y=Math.min(window.devicePixelRatio,2),h=Math.round(d*y),x=Math.round(m*y);(e.domElement.width!==h||e.domElement.height!==x)&&(e.setPixelRatio(y),e.setSize(d,m,!1),t.aspect=d/m,t.updateProjectionMatrix())},g=function(){a=requestAnimationFrame(g);let d=performance.now(),m=(d-l)/1e3;l=d,c(),(n.enableDamping||n.autoRotate)&&n.update(),_optionalChain([s, 'optionalCall', _108 => _108(m)]),e.render(r,t)};return{animate:g,dispose:()=>{a!==null&&(cancelAnimationFrame(a),a=null)}}}function ce(e,r){r.environment.enableEnvironmentLighting?new (0, _HDRLoaderjs.HDRLoader)().load(r.environment.hdrPath||"/baseHDR.hdr",function(t){t.mapping=i.EquirectangularReflectionMapping,e.environment=t,r.environment.showEnvironment&&(e.background=t),_optionalChain([r, 'access', _109 => _109.events, 'access', _110 => _110.onReady, 'optionalCall', _111 => _111()])},void 0,function(t){_chunkXULONXVPcjs.e.call(void 0, ).warn("HDR texture could not be loaded, falling back to basic lighting:",t),_optionalChain([r, 'access', _112 => _112.events, 'access', _113 => _113.onReady, 'optionalCall', _114 => _114()])}):_optionalChain([r, 'access', _115 => _115.events, 'access', _116 => _116.onReady, 'optionalCall', _117 => _117()])}function le(e,r){let t=new i.AmbientLight(r.lighting.ambientLightColor,r.lighting.ambientLightIntensity);if(e.add(t),r.lighting.enableSunlight){let n=new i.DirectionalLight(_nullishCoalesce(r.lighting.sunlightColor, () => (16777215)),r.lighting.sunlightIntensity),o=r.lighting.sunlightPosition;if(o&&n.position.set(o.x,o.y,o.z),r.render.enableShadows){n.castShadow=!0;let s=z(r.sceneScale,.1,10,100);n.shadow.camera.left=-s,n.shadow.camera.right=s,n.shadow.camera.top=s,n.shadow.camera.bottom=-s;let a=z(r.sceneScale,.001,.1,.5),l=z(r.sceneScale,1,100,500);n.shadow.camera.near=a,n.shadow.camera.far=l,n.shadow.mapSize.width=r.render.shadowMapSize||2048,n.shadow.mapSize.height=r.render.shadowMapSize||2048,n.shadow.bias=-1e-4,n.shadow.normalBias=.02}e.add(n)}}function fe(e,r){let t=r.floor.size,n=new i.PlaneGeometry(t,t),o=typeof r.floor.color=="string"?new i.Color(r.floor.color):r.floor.color,s=new i.MeshStandardMaterial({color:o,roughness:r.floor.roughness,metalness:r.floor.metalness,side:i.DoubleSide}),a=new i.Mesh(n,s);a.userData.id="floor",a.name="floor",a.rotation.x=-Math.PI/2,a.position.y=0,r.floor.receiveShadow&&r.render.enableShadows&&(a.receiveShadow=!0),e.add(a)}function de(e,r){let t=r.parentElement,n=t?t.clientWidth:window.innerWidth,o=t?t.clientHeight:window.innerHeight,s=new i.PerspectiveCamera(e.camera.fov,n/o,e.camera.near,e.camera.far),a=e.camera.position;return a&&s.position.set(a.x,a.y,a.z),s}function he(e,r){let t=new i.WebGLRenderer({antialias:r.render.antialias,canvas:e,alpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:r.render.preserveDrawingBuffer,logarithmicDepthBuffer:!0}),n=e.parentElement,o=n?n.clientWidth:window.innerWidth,s=n?n.clientHeight:window.innerHeight;return n&&(e.style.width="100%",e.style.height="100%",e.style.display="block"),t.setSize(o,s,!1),t.setPixelRatio(r.render.pixelRatio||Math.min(window.devicePixelRatio,2)),r.render.enableShadows&&(t.shadowMap.enabled=!0,t.shadowMap.type=i.VSMShadowMap),t.toneMapping=r.render.toneMapping,t.toneMappingExposure=r.render.toneMappingExposure||1,t.outputColorSpace=i.SRGBColorSpace,t.sortObjects=!0,t}function me(e,r,t,n,o){let s=new Set,a=new Map,l=new i.Raycaster,c=new i.Vector2,g=new i.Vector2,u=f=>{let R=f;for(;R;){if(!R.visible)return!1;R=R.parent}return!0},d=()=>{let f=new i.Box3;if(r.traverse(D=>{D.visible&&D.userData.id!=="floor"&&D instanceof i.Mesh&&f.expandByObject(D)}),f.isEmpty()){_chunkXULONXVPcjs.e.call(void 0, ).warn("No objects to fit to view");return}let R=f.getCenter(new i.Vector3),M=f.getSize(new i.Vector3),A=Math.max(M.x,M.y,M.z),T=t.fov*(Math.PI/180),C=A/(2*Math.tan(T/2));C*=1.5;let B=t.position.clone().sub(n.target).normalize();t.position.copy(R.clone().add(B.multiplyScalar(C))),n.target.copy(R),n.update()},m=typeof o.events.selectionColor=="string"?new i.Color(o.events.selectionColor):o.events.selectionColor instanceof i.Color?o.events.selectionColor:new i.Color("#ff0000"),y=()=>{s.forEach(f=>{f instanceof i.Mesh&&a.has(f)&&(f.material=a.get(f),a.delete(f))}),s.clear()},h=f=>{g.set(f.clientX,f.clientY)},x=f=>{let R=new i.Vector2(f.clientX,f.clientY);if(g.distanceTo(R)>5)return;let M=e.getBoundingClientRect();c.x=(f.clientX-M.left)/M.width*2-1,c.y=-((f.clientY-M.top)/M.height)*2+1,l.setFromCamera(c,t);let A=l.intersectObjects(r.children,!0).filter(T=>u(T.object));if(A.length>0){let T=A[0].object;if(!s.has(T)){if(y(),s.add(T),T instanceof i.Mesh&&T.material instanceof i.Material){a.set(T,T.material);let C=T.material.clone();C.emissive=m.clone(),T.material=C}_optionalChain([o, 'access', _118 => _118.events, 'optionalAccess', _119 => _119.onObjectSelected, 'optionalCall', _120 => _120(T)]),T instanceof i.Mesh&&Object.keys(T.userData).length>0&&_optionalChain([o, 'access', _121 => _121.events, 'optionalAccess', _122 => _122.onMeshMetadataClicked, 'optionalCall', _123 => _123(T.userData)])}}else y(),_optionalChain([o, 'access', _124 => _124.events, 'optionalAccess', _125 => _125.onBackgroundClicked, 'optionalCall', _126 => _126({x:c.x,y:c.y})])},L=f=>{let R=e.getBoundingClientRect();c.x=(f.clientX-R.left)/R.width*2-1,c.y=-((f.clientY-R.top)/R.height)*2+1,l.setFromCamera(c,t);let M=l.intersectObjects(r.children,!0).filter(ee=>u(ee.object));if(M.length===0)return;let A=M[0].object;if(_optionalChain([o, 'access', _127 => _127.events, 'optionalAccess', _128 => _128.onMeshDoubleClicked, 'optionalCall', _129 => _129(A)]),!_optionalChain([o, 'access', _130 => _130.events, 'optionalAccess', _131 => _131.enableDoubleClickZoom]))return;let T=new i.Box3().setFromObject(A);if(T.isEmpty())return;let C=T.getCenter(new i.Vector3),B=T.getSize(new i.Vector3),D=Math.max(B.x,B.y,B.z),K=t.fov*(Math.PI/180),X=D/(2*Math.tan(K/2))*1.5,J=t.position.clone().sub(n.target).normalize(),Q=C.clone().add(J.multiplyScalar(X));se(t,n,Q,C)},I=f=>{if(_optionalChain([o, 'access', _132 => _132.events, 'optionalAccess', _133 => _133.enableKeyboardControls]))switch(f.key.toLowerCase()){case"f":f.preventDefault(),d();break;case"escape":f.preventDefault(),y();break;case" ":f.preventDefault(),d();break}};return _optionalChain([o, 'access', _134 => _134.events, 'optionalAccess', _135 => _135.enableClickToFocus])&&(e.addEventListener("mousedown",h),e.addEventListener("click",x),e.addEventListener("dblclick",L)),_optionalChain([o, 'access', _136 => _136.events, 'optionalAccess', _137 => _137.enableKeyboardControls])&&(e.setAttribute("tabindex","0"),e.addEventListener("keydown",I)),{dispose:()=>{e.removeEventListener("mousedown",h),e.removeEventListener("click",x),e.removeEventListener("dblclick",L),e.removeEventListener("keydown",I),y()},fitToView:d,clearSelection:y}}function ue(e,r,t){let n=new (0, _OrbitControlsjs.OrbitControls)(e,r),o=t.camera.target;return o&&n.target.set(o.x,o.y,o.z),n.enableDamping=t.controls.enableDamping||!1,n.dampingFactor=t.controls.dampingFactor||.05,n.autoRotate=t.controls.autoRotate||!1,n.autoRotateSpeed=t.controls.autoRotateSpeed||.5,n.enableZoom=_nullishCoalesce(t.controls.enableZoom, () => (!0)),n.enablePan=_nullishCoalesce(t.controls.enablePan, () => (!0)),n.minDistance=t.controls.minDistance||.001,n.maxDistance=t.controls.maxDistance||1/0,n.screenSpacePanning=!1,n.maxPolarAngle=Math.PI,n.update(),n}var v={HUGE_THRESHOLD:1e4,LARGE_THRESHOLD:1e3,SCALE_RATIO_THRESHOLD:100,NEAR_PLANE_FACTOR:{TINY:1e-4,SMALL:.001,NORMAL:.01},FAR_PLANE_FACTOR:{HUGE:100,LARGE:50,NORMAL:20},INITIAL_DISTANCE_MULTIPLIER:4};function q(e,r,t,n,o){if(Ee(e),r.length===0)return;r.forEach(u=>{e.add(u)});let s=F(r),a=s.getCenter(new w.Vector3),l=s.getSize(new w.Vector3),c=Math.max(l.x,l.y,l.z);if(c/Math.min(l.x||1,l.y||1,l.z||1)>v.SCALE_RATIO_THRESHOLD||c>v.HUGE_THRESHOLD?(t.near=c*v.NEAR_PLANE_FACTOR.TINY,t.far=c*v.FAR_PLANE_FACTOR.HUGE):c>v.LARGE_THRESHOLD?(t.near=c*v.NEAR_PLANE_FACTOR.SMALL,t.far=c*v.FAR_PLANE_FACTOR.LARGE):(t.near=Math.max(.01,c*v.NEAR_PLANE_FACTOR.NORMAL),t.far=Math.max(2e3,c*v.FAR_PLANE_FACTOR.NORMAL)),t.updateProjectionMatrix(),o)n.minDistance=t.near*2,n.maxDistance=t.far*.9;else{let u=c*v.INITIAL_DISTANCE_MULTIPLIER;t.position.set(a.x+u*.8,a.y+u,a.z+u*1.2),n.target.copy(a),n.minDistance=t.near*2,n.maxDistance=t.far*.9,n.update()}}function _(e){if(!e||typeof e!="string")return _chunkXULONXVPcjs.e.call(void 0, ).warn(`Invalid color input: ${e}, using white`),new w.Color(16777215);let r=e.trim();if(/^#?[0-9A-Fa-f]{6}$/.test(r))try{let t=r.startsWith("#")?r:`#${r}`;return new w.Color(t)}catch (e2){return _chunkXULONXVPcjs.e.call(void 0, ).warn(`Invalid hex color: ${e}, using white`),new w.Color(16777215)}if(r.includes(",")){let t=r.split(",").map(n=>parseInt(n.trim(),10));if(t.length===3&&t.every(n=>!isNaN(n)&&n>=0&&n<=255))return new w.Color(t[0]/255,t[1]/255,t[2]/255)}try{return new w.Color(r.toLowerCase())}catch (e3){return _chunkXULONXVPcjs.e.call(void 0, ).warn(`Invalid color string: ${e}, using white`),new w.Color(16777215)}}function V(e,r){e.forEach(t=>{t.position.y-=r})}function F(e){let r=new w.Box3;return e.length===0||e.forEach(t=>{t.updateMatrixWorld(!0);let n=new w.Box3().setFromObject(t);r.union(n)}),r}function Ee(e){[...e.children].forEach(t=>{t.userData.id!=="floor"&&(t.traverse(n=>{if(!(n instanceof w.Mesh))return;_optionalChain([n, 'access', _138 => _138.geometry, 'optionalAccess', _139 => _139.dispose, 'call', _140 => _140()]),(Array.isArray(n.material)?n.material:[n.material]).forEach(s=>{for(let a of Object.values(s))a instanceof w.Texture&&a.dispose();s.dispose()})}),t.removeFromParent())})}var N={};_chunkXULONXVPcjs.a.call(void 0, N,{CONCRETE_MATERIAL:()=>Re,EMISSIVE_MATERIAL:()=>pe,GLASS_MATERIAL:()=>ye,METAL_MATERIAL:()=>ge,PLASTIC_MATERIAL:()=>Te,RUBBER_MATERIAL:()=>we,WOOD_MATERIAL:()=>be});var pe=new E.MeshPhysicalMaterial({color:0,emissive:new E.Color(16777215),emissiveIntensity:5,metalness:0,roughness:.2,clearcoat:.3,clearcoatRoughness:.2,depthWrite:!0,depthTest:!0,transparent:!1,alphaTest:0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),ge=new E.MeshPhysicalMaterial({color:new E.Color(0),metalness:.9,roughness:.3,envMapIntensity:1.2,clearcoat:.3,clearcoatRoughness:.2,reflectivity:1,ior:2.5,thickness:1,depthWrite:!0,transparent:!1,alphaTest:0,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),Re=new E.MeshPhysicalMaterial({color:new E.Color(13421772),metalness:0,roughness:.92,envMapIntensity:.15,clearcoat:.05,clearcoatRoughness:.9,reflectivity:.15,transmission:0,ior:1.45,thickness:0,depthWrite:!0,transparent:!1,alphaTest:.5,depthTest:!0,polygonOffset:!0,side:E.FrontSide,dithering:!0}),Te=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:.3,envMapIntensity:.5,clearcoat:.5,clearcoatRoughness:.1,reflectivity:.5,ior:1.4,transmission:0,transparent:!1,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),ye=new E.MeshPhysicalMaterial({color:new E.Color(16777215),metalness:0,roughness:0,transmission:.95,transparent:!0,opacity:.3,envMapIntensity:1,clearcoat:1,clearcoatRoughness:0,ior:1.52,reflectivity:.9,thickness:1,side:E.DoubleSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),we=new E.MeshPhysicalMaterial({color:new E.Color(1710618),metalness:0,roughness:.9,envMapIntensity:.2,clearcoat:.1,clearcoatRoughness:.8,reflectivity:.2,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),be=new E.MeshPhysicalMaterial({color:new E.Color(8934707),metalness:0,roughness:.7,envMapIntensity:.3,clearcoat:.3,clearcoatRoughness:.4,reflectivity:.3,ior:1.3,transmission:0,depthWrite:!0,side:E.FrontSide,dithering:!0,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1});var _fflate = require('fflate'); var P = _interopRequireWildcard(_fflate);var Me=typeof globalThis<"u"&&typeof globalThis.window<"u"&&typeof globalThis.document<"u";async function Y(e,r=!1){let t=_chunk2NFN5ERTcjs.c.call(void 0, e),n;try{n=Me?await new Promise((o,s)=>{P.gunzip(t,(a,l)=>{a?s(a):o(l)})}):P.gunzipSync(t)}catch(o){throw new (0, _chunkXULONXVPcjs.d)(`Failed to decompress batched data: ${o instanceof Error?o.message:String(o)}`,_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))})}try{return xe(n,r)}catch(o){throw new (0, _chunkXULONXVPcjs.d)(o instanceof _chunkXULONXVPcjs.d?o.message:`Failed to parse decompressed batched data: ${o instanceof Error?o.message:String(o)}`,o instanceof _chunkXULONXVPcjs.d?o.code:_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{base64StringLength:e.length},originalError:o instanceof Error?o:new Error(String(o))})}}function xe(e,r){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=0;if(n+4>t.byteLength)throw new (0, _chunkXULONXVPcjs.d)("Insufficient data to read the number of vertex floats.",_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:t.byteLength,offset:n}});let o=t.getUint32(n,!0);if(n+=4,o%3!==0)throw new (0, _chunkXULONXVPcjs.d)("Invalid number of vertex floats; should be divisible by 3.",_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{numVertexFloats:o,remainder:o%3,totalBytes:t.byteLength}});let s=o*Float32Array.BYTES_PER_ELEMENT;if(n+s>t.byteLength)throw new (0, _chunkXULONXVPcjs.d)("Insufficient data to read vertices.",_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{expectedBytes:s,availableBytes:t.byteLength-n,offset:n}});let a=e.byteOffset+n,l;if(r){let d=new Float32Array(e.buffer,a,o);l=new Float32Array(o);for(let m=0;m<o;m+=3){let y=d[m+1],h=d[m+2];l[m]=d[m],l[m+1]=h,l[m+2]=-y}}else l=new Float32Array(e.buffer,a,o);if(n+=s,n+4>t.byteLength)throw new (0, _chunkXULONXVPcjs.d)("Insufficient data to read the number of face indices.",_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{expectedBytes:4,availableBytes:t.byteLength-n,offset:n}});let c=t.getUint32(n,!0);n+=4;let g=c*Uint32Array.BYTES_PER_ELEMENT;if(n+g>t.byteLength)throw new (0, _chunkXULONXVPcjs.d)("Insufficient data to read face indices.",_chunkXULONXVPcjs.c.VALIDATION_ERROR,{context:{expectedBytes:g,availableBytes:t.byteLength-n,offset:n}});let u=new Uint32Array(e.buffer,e.byteOffset+n,c);return{vertices:l,faces:u}}async function k(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,debug:o=!1}=_nullishCoalesce(r, () => ({})),s=o?performance.now():0,a=0;try{let l=performance.now(),c=JSON.parse(e);return a=performance.now()-l,await U(c,{mergeByMaterial:t,applyTransforms:n,debug:o,parseTime:a,perfStart:s})}catch(l){return _chunkXULONXVPcjs.e.call(void 0, ).error("Error parsing mesh batch:",l),[]}}async function U(e,r){let{mergeByMaterial:t=!0,applyTransforms:n=!0,scaleFactor:o=1,debug:s=!1,parseTime:a=0,perfStart:l=s?performance.now():0}=_nullishCoalesce(r, () => ({})),c=0,g=0;try{let u=performance.now(),{vertices:d,faces:m}=await Y(e.compressedData,n);c=performance.now()-u;let y=(e.compressedData.length*.75/1024/1024).toFixed(2),h=((d.byteLength+m.byteLength)/1024/1024).toFixed(2),x=((1-parseFloat(y)/parseFloat(h))*100).toFixed(1);s&&(_chunkXULONXVPcjs.e.call(void 0, ).debug("Mesh Batch Stats:"),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Materials: ${e.materials.length} | Groups: ${e.groups.length}`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Vertices: ${(d.length/3).toLocaleString()} | Faces: ${(m.length/3).toLocaleString()}`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Compressed: ${y} MB | Uncompressed: ${h} MB`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Compression Ratio: ${x}%`));let L=performance.now(),I=e.materials.map(He),S=[];for(let f of e.groups)if(t&&f.meshes.length>1){let R=ve(f,d,m,I);R.userData.sourceComponentId=_nullishCoalesce(e.sourceComponentId, () => (null)),S.push(R)}else{let R=Ce(f,d,m,I);for(let M of R)M.userData.sourceComponentId=_nullishCoalesce(e.sourceComponentId, () => (null));S.push(...R)}if(o!==1)for(let f of S)f.scale.set(o,o,o);if(g=performance.now()-L,s){let f=performance.now()-l;_chunkXULONXVPcjs.e.call(void 0, ).debug("Performance:"),a>0&&_chunkXULONXVPcjs.e.call(void 0, ).debug(` Parse JSON: ${a.toFixed(2)}ms`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Decompress: ${c.toFixed(2)}ms`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Create Meshes: ${g.toFixed(2)}ms`),_chunkXULONXVPcjs.e.call(void 0, ).debug(` Total: ${f.toFixed(2)}ms`)}return S}catch(u){return _chunkXULONXVPcjs.e.call(void 0, ).error("Error parsing mesh batch object:",u),[]}}function He(e){let r=_(e.color);return new b.MeshPhysicalMaterial({color:r,metalness:e.metalness,roughness:e.roughness,opacity:e.opacity,transparent:e.transparent,side:b.DoubleSide,polygonOffset:!0,polygonOffsetFactor:.5,polygonOffsetUnits:.5,depthWrite:!0,depthTest:!0})}function ve(e,r,t,n){let o=new b.BufferGeometry,s=0,a=0;for(let h of e.meshes)s+=h.vertexCount,a+=h.faceCount;let l=new Float32Array(s),c=new Uint32Array(a),g=0,u=0;for(let h of e.meshes){l.set(r.subarray(h.vertexOffset,h.vertexOffset+h.vertexCount),g);let x=t.subarray(h.faceOffset,h.faceOffset+h.faceCount),L=Math.floor(h.vertexOffset/3),S=Math.floor(g/3)-L;for(let f=0;f<x.length;f++)c[u+f]=x[f]+S;g+=h.vertexCount,u+=h.faceCount}o.setAttribute("position",new b.BufferAttribute(l,3)),o.setIndex(new b.BufferAttribute(c,1)),o.computeVertexNormals();let d=new b.Mesh(o,n[e.materialId]),m=e.meshes[0],y=e.meshes.map(h=>h.name).filter(h=>h&&h.length>0);return d.name=y.length>0?y[0]:`merged_material_${e.materialId}`,d.castShadow=!0,d.receiveShadow=!0,d.userData={name:d.name,layer:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _141 => _141.layer]), () => ("")),originalIndex:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _142 => _142.originalIndex]), () => (0)),metadata:_nullishCoalesce(_optionalChain([m, 'optionalAccess', _143 => _143.metadata]), () => ({})),mergedFrom:e.meshes.slice(1).map(h=>({name:h.name,layer:h.layer,originalIndex:h.originalIndex}))},d}function Ce(e,r,t,n){let o=[];for(let s of e.meshes){let a=new b.BufferGeometry,l=r.subarray(s.vertexOffset,s.vertexOffset+s.vertexCount),c=t.subarray(s.faceOffset,s.faceOffset+s.faceCount),g=Math.floor(s.vertexOffset/3),u=new Uint32Array(c.length);for(let m=0;m<c.length;m++)u[m]=c[m]-g;a.setAttribute("position",new b.BufferAttribute(l,3)),a.setIndex(new b.BufferAttribute(u,1)),a.computeVertexNormals();let d=new b.Mesh(a,n[e.materialId]);d.name=s.name,d.userData={name:s.name,layer:_nullishCoalesce(s.layer, () => ("")),originalIndex:s.originalIndex,metadata:_nullishCoalesce(s.metadata, () => ({}))},d.castShadow=!0,d.receiveShadow=!0,o.push(d)}return o}var G={Millimeters:1/1e3,Centimeters:1/100,Meters:1,Inches:1/39.37,Feet:1/3.28084},Oe="Display";async function Z(e,r){let t=performance.now(),n=[],{allowScaling:o=!0,allowAutoPosition:s=!0,debug:a=!1,parsing:l={}}=_nullishCoalesce(r, () => ({}));try{let c=o?Se(e.modelunits):1;return await Ae(e,n,c,l,a),s&&Ie(n),n}catch(c){throw De(c,n),c}finally{a&&Fe(t)}}function Se(e){return _nullishCoalesce(G[e], () => (1))}async function Ae(e,r,t,n,o){for(let s of e.values){let a=s.InnerTree;for(let l in a){let c=a[l];c&&await Le(c,r,t,n,o)}}}async function Le(e,r,t,n,o){for(let s of e)if(s.type.includes(Oe)){let a={mergeByMaterial:!0,applyTransforms:!0,debug:!1,...n},l=await k(s.data,a);if(t!==1)for(let c of l)c.scale.set(t,t,t);r.push(...l),o&&_chunkXULONXVPcjs.e.call(void 0, ).debug(`Extracted ${l.length} meshes from batch`)}}function Ie(e){if(e.length===0)return;let t=F(e).min.y;V(e,t)}function De(e,r){_chunkXULONXVPcjs.e.call(void 0, ).error("An unexpected error occurred:",e),Be(r)}function Be(e){for(let r of e)r.geometry&&r.geometry.dispose(),r.material&&(Array.isArray(r.material)?r.material.forEach(t=>t.dispose()):r.material.dispose())}function Fe(e){let r=performance.now()-e;_chunkXULONXVPcjs.e.call(void 0, ).info("Time to process meshes:",`${r.toFixed(2)}ms`)}exports.Materials = N; exports.SCALE_FACTORS = G; exports.getThreeMeshesFromComputeResponse = Z; exports.initThree = j; exports.parseMeshBatchObject = U; exports.updateScene = q;
2
2
  //# sourceMappingURL=visualization.cjs.map