selva-compute 1.0.0 → 1.0.1

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.
package/README.md CHANGED
@@ -48,28 +48,6 @@ try {
48
48
  }
49
49
  ```
50
50
 
51
- ## Comparison: selva-compute vs compute-rhino3d
52
-
53
- | Feature | selva-compute | compute-rhino3d (Official) |
54
- | :---------------------- | :--------------------------------------- | :----------------------------- |
55
- | **Primary Goal** | Application Framework | API Wrapper |
56
- | **Abstraction Level** | High (Apps, Definitions, UI) | Low (Geometry, Direct Calls) |
57
- | **Grasshopper Solving** | Optimized, Schema-aware | Basic `solve` endpoint wrapper |
58
- | **Geometry Handling** | Automatic decoding to `rhino3dm` | Returns raw JSON/base64 |
59
- | **Visualization** | Includes `three.js` converters & helpers | Manual implementation required |
60
- | **Typing** | TypeScript-first, handwritten for DX | Auto-generated from C# |
61
-
62
- **Choose `selva-compute` if:**
63
-
64
- - You are building a web app (Svelte, React, Vue, etc.) that interacts with Grasshopper.
65
- - You want "batteries-included" features like geometry decoding and three.js visualization.
66
- - You prefer a cleaner, more idiomatic TypeScript API for definition solving.
67
-
68
- **Choose `compute-rhino3d` if:**
69
-
70
- - You need to call specific low-level Rhino geometry functions (e.g. `Intersection.brepPlane`) directly from JS.
71
- - You are building a complex script that chains geometry operations without a GH definition.
72
-
73
51
  ## Features
74
52
 
75
53
  - **Robust Client**: Handles connection, retries, and error parsing.
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/chunk-5DJRUPGI.cjs","../src/core/utils/encoding.ts"],"names":["encodeStringToBase64","str","isBase64","decodeBase64ToBinary","base64File","c","RhinoComputeError","ErrorCodes","base64ByteArray","bytes","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","i","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"],"mappings":"AAAA,qOAAsD,SCQtCA,CAAAA,CAAqBC,CAAAA,CAAqB,CACzD,OAAO,M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GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CAClF,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCb,CAAAA,EAAUU,CAAAA,CAAQC,CAAAA,CAAQC,CAAAA,CAAQC,CACnC,CAGA,EAAA,CAAIf,CAAAA,GAAkB,CAAA,CAAG,CAGxB,EAAA,CAFAM,CAAAA,CAAQR,CAAAA,CAAWG,CAAU,CAAA,CAEzBK,CAAAA,GAAU,KAAA,CAAA,CACb,MAAM,IAAI,KAAA,CAAM,+BAA+B,CAAA,CAGhDH,CAAAA,CAAAA,CAAKG,CAAAA,CAAQ,GAAA,CAAA,EAAQ,CAAA,CACrBF,CAAAA,CAAAA,CAAKE,CAAAA,CAAQ,CAAA,CAAA,EAAM,CAAA,CAEnB,IAAMM,CAAAA,CAAQf,CAAAA,CAAUM,CAAC,CAAA,CACnBU,CAAAA,CAAQhB,CAAAA,CAAUO,CAAC,CAAA,CAEzB,EAAA,CAAIQ,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CACpC,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCX,CAAAA,EAAU,CAAA,EAAA","file":"/Users/felix/coding/selva-compute/dist/chunk-5DJRUPGI.cjs","sourcesContent":[null,"/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param str - String to encode\n * @returns Base64 encoded string\n */\nexport function encodeStringToBase64(str: string): string {\n\treturn Buffer.from(str, 'utf-8').toString('base64');\n}\n\n/**\n * Decodes a base64 string to a UTF-8 string (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param base64Str - Base64 encoded string\n * @returns Decoded UTF-8 string\n */\nexport function decodeBase64ToString(base64Str: string): string {\n\treturn Buffer.from(base64Str, 'base64').toString('utf-8');\n}\n\n\n/**\n * Checks if a string is valid base64\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param str - String to check\n * @returns True if the string is valid base64\n */\nexport function isBase64(str: string): boolean {\n\tif (!str || str.trim().length === 0) return false;\n\ttry {\n\t\treturn Buffer.from(str, 'base64').toString('base64') === str;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param base64File - Base64 encoded string\n * @returns Decoded binary data as Uint8Array\n * @throws {RhinoComputeError} If base64 decoding is not supported in this environment.\n */\nexport function decodeBase64ToBinary(base64File: string): Uint8Array {\n\tif (typeof globalThis.atob === 'function') {\n\t\treturn Uint8Array.from(globalThis.atob(base64File), (c) => c.charCodeAt(0));\n\t}\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\t// Buffer.from returns a Uint8Array-compatible Buffer\n\t\treturn (globalThis as any).Buffer.from(base64File, 'base64');\n\t}\n\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\n\tthrow new RhinoComputeError(\n\t\t'Base64 decoding not supported in this environment.',\n\t\tErrorCodes.INVALID_STATE,\n\t\t{ context: { environmentInfo: 'atob or Buffer not available' } }\n\t);\n}\n\n/**\n * Encodes binary data (Uint8Array) to base64 string\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * https://gist.github.com/jonleighton/958841\n *\n * MIT LICENSE\n * Copyright 2011 Jon Leighton\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\nexport function base64ByteArray(bytes: Uint8Array | null | undefined): string {\n\tif (bytes === null || bytes === undefined) {\n\t\t// Import here to avoid circular dependencies at top level\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\n\t\tthrow new RhinoComputeError(\n\t\t\t'Input bytes must not be null or undefined',\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { receivedValue: bytes } }\n\t\t);\n\t}\n\n\tconst encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n\tlet inputBytes = bytes;\n\n\t// strip bom (Byte Order Mark)\n\tif (\n\t\tinputBytes.length >= 3 &&\n\t\tinputBytes[0] === 239 &&\n\t\tinputBytes[1] === 187 &&\n\t\tinputBytes[2] === 191\n\t) {\n\t\tinputBytes = inputBytes.slice(3);\n\t}\n\n\tconst byteLength = inputBytes.byteLength;\n\tconst byteRemainder = byteLength % 3;\n\tconst mainLength = byteLength - byteRemainder;\n\n\tlet base64 = '';\n\tlet a, b, c, d;\n\tlet chunk;\n\n\t// Main loop deals with bytes in chunks of 3\n\tfor (let i = 0; i < mainLength; i += 3) {\n\t\t// Combine the three bytes into a single integer\n\n\t\tconst byte1 = inputBytes[i] !== undefined ? inputBytes[i] : 0;\n\t\tconst byte2 = inputBytes[i + 1] !== undefined ? inputBytes[i + 1] : 0;\n\t\tconst byte3 = inputBytes[i + 2] !== undefined ? inputBytes[i + 2] : 0;\n\n\t\tconst innerChunk = (byte1 << 16) | (byte2 << 8) | byte3;\n\n\t\t// Use bitmasks to extract 6-bit segments from the triplet\n\t\ta = (innerChunk & 16515072) >> 18;\n\t\tb = (innerChunk & 258048) >> 12;\n\t\tc = (innerChunk & 4032) >> 6;\n\t\td = innerChunk & 63;\n\n\t\t// Convert the raw binary segments to the appropriate ASCII encoding\n\t\tif (typeof encodings !== 'string') {\n\t\t\tthrow new Error('encodings must be a string');\n\t\t}\n\n\t\tif (typeof a !== 'number' || a < 0 || a >= encodings.length) {\n\t\t\tthrow new Error('Invalid index a');\n\t\t}\n\n\t\tif (typeof b !== 'number' || b < 0 || b >= encodings.length) {\n\t\t\tthrow new Error('Invalid index b');\n\t\t}\n\n\t\tif (typeof c !== 'number' || c < 0 || c >= encodings.length) {\n\t\t\tthrow new Error('Invalid index c');\n\t\t}\n\n\t\tif (typeof d !== 'number' || d < 0 || d >= encodings.length) {\n\t\t\tthrow new Error('Invalid index d');\n\t\t}\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\t\tconst charD = encodings[d];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined || charD === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += charA + charB + charC + charD;\n\t}\n\n\t// Deal with the remaining bytes and padding\n\tif (byteRemainder === 1) {\n\t\tchunk = inputBytes[mainLength];\n\n\t\tif (chunk === undefined) {\n\t\t\tthrow new Error(\"'chunk' must not be undefined\");\n\t\t}\n\n\t\ta = (chunk & 252) >> 2;\n\t\tb = (chunk & 3) << 4;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\n\t\tif (charA === undefined || charB === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB}==`;\n\t} else if (byteRemainder === 2) {\n\t\tconst byte1 = inputBytes[mainLength] ?? 0;\n\t\tconst byte2 = inputBytes[mainLength + 1] !== undefined ? inputBytes[mainLength + 1] : 0;\n\n\t\tif (\n\t\t\ttypeof byte1 !== 'number' ||\n\t\t\tbyte1 < 0 ||\n\t\t\tbyte1 > 255 ||\n\t\t\ttypeof byte2 !== 'number' ||\n\t\t\tbyte2 < 0 ||\n\t\t\tbyte2 > 255\n\t\t) {\n\t\t\tthrow new Error('Invalid byte1');\n\t\t}\n\n\t\tchunk = (byte1 << 8) | byte2;\n\n\t\ta = (chunk & 64512) >> 10;\n\t\tb = (chunk & 1008) >> 4;\n\t\tc = (chunk & 15) << 2;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB + charC}=`;\n\t}\n\n\treturn base64;\n}\n\n/**\n * Convert base64 string to rhino object\n *\n * @internal Internal helper for decoding Rhino objects — not public API.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * @param rhino is the rhino module form rhino3dm. Since not properly typed its not used here.\n * @param item\n * @returns\n */\nexport function base64ToRhinoObject(\n\trhino: any,\n\titem: {\n\t\ttype: string;\n\t\tdata: string;\n\t}\n) {\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { getLogger } = require('./logger');\n\n\t//Make a type definition for this?\n\tlet decodata: null | object = null;\n\ttry {\n\t\tdecodata = JSON.parse(item.data);\n\t} catch (error) {\n\t\tdecodata = item;\n\t\tgetLogger().warn('Failed to parse JSON, returning original data:', error, item);\n\t}\n\tif (item.type === 'System.String') {\n\t\ttry {\n\t\t\treturn rhino.DracoCompression.decompressBase64String(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decompress Draco base64 string:', error);\n\t\t}\n\t} else if (\n\t\ttypeof decodata === 'object' &&\n\t\tObject.prototype.hasOwnProperty.call(decodata, 'opennurbs')\n\t) {\n\t\treturn rhino.CommonObject.decode(decodata);\n\t} else if (typeof decodata === 'object') {\n\t\ttry {\n\t\t\treturn rhino.CommonObject.decode(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decode Rhino object:', error);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-5DJRUPGI.cjs","../src/core/utils/encoding.ts"],"names":["encodeStringToBase64","str","isBase64","decodeBase64ToBinary","base64File","c","RhinoComputeError","ErrorCodes","base64ByteArray","bytes","encodings","inputBytes","byteLength","byteRemainder","mainLength","base64","a","b","d","chunk","i","byte1","byte2","byte3","innerChunk","charA","charB","charC","charD"],"mappings":"AAAA,qOAAsD,SCQtCA,CAAAA,CAAqBC,CAAAA,CAAqB,CACzD,OAAO,MAAA,CAAO,IAAA,CAAKA,CAAAA,CAAK,OAAO,CAAA,CAAE,QAAA,CAAS,QAAQ,CACnD,CAuBO,SAASC,CAAAA,CAASD,CAAAA,CAAsB,CAC9C,EAAA,CAAI,CAACA,CAAAA,EAAOA,CAAAA,CAAI,IAAA,CAAK,CAAA,CAAE,MAAA,GAAW,CAAA,CAAG,MAAO,CAAA,CAAA,CAC5C,GAAI,CACH,OAAO,MAAA,CAAO,IAAA,CAAKA,CAAAA,CAAK,QAAQ,CAAA,CAAE,QAAA,CAAS,QAAQ,CAAA,GAAMA,CAC1D,CAAA,UAAQ,CACP,MAAO,CAAA,CACR,CACD,CAYO,SAASE,CAAAA,CAAqBC,CAAAA,CAAgC,CACpE,EAAA,CAAI,OAAO,UAAA,CAAW,IAAA,EAAS,UAAA,CAC9B,OAAO,UAAA,CAAW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CAAQ,CAAA,CAAA,EAAM,CAAA,CAEnB,IAAMM,CAAAA,CAAQf,CAAAA,CAAUM,CAAC,CAAA,CACnBU,CAAAA,CAAQhB,CAAAA,CAAUO,CAAC,CAAA,CAEzB,EAAA,CAAIQ,CAAAA,GAAU,KAAA,CAAA,EAAaC,CAAAA,GAAU,KAAA,CAAA,CACpC,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA,CAGzCX,CAAAA,EAAU,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-5DJRUPGI.cjs","sourcesContent":[null,"/**\n * Encodes a string to base64 (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param str - String to encode\n * @returns Base64 encoded string\n */\nexport function encodeStringToBase64(str: string): string {\n\treturn Buffer.from(str, 'utf-8').toString('base64');\n}\n\n/**\n * Decodes a base64 string to a UTF-8 string (Node 20+ safe)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param base64Str - Base64 encoded string\n * @returns Decoded UTF-8 string\n */\nexport function decodeBase64ToString(base64Str: string): string {\n\treturn Buffer.from(base64Str, 'base64').toString('utf-8');\n}\n\n\n/**\n * Checks if a string is valid base64\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param str - String to check\n * @returns True if the string is valid base64\n */\nexport function isBase64(str: string): boolean {\n\tif (!str || str.trim().length === 0) return false;\n\ttry {\n\t\treturn Buffer.from(str, 'base64').toString('base64') === str;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n\n/**\n * Decodes a base64 string to binary data (Uint8Array)\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * @param base64File - Base64 encoded string\n * @returns Decoded binary data as Uint8Array\n * @throws {RhinoComputeError} If base64 decoding is not supported in this environment.\n */\nexport function decodeBase64ToBinary(base64File: string): Uint8Array {\n\tif (typeof globalThis.atob === 'function') {\n\t\treturn Uint8Array.from(globalThis.atob(base64File), (c) => c.charCodeAt(0));\n\t}\n\tif (typeof (globalThis as any).Buffer === 'function') {\n\t\t// Buffer.from returns a Uint8Array-compatible Buffer\n\t\treturn (globalThis as any).Buffer.from(base64File, 'base64');\n\t}\n\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\n\tthrow new RhinoComputeError(\n\t\t'Base64 decoding not supported in this environment.',\n\t\tErrorCodes.INVALID_STATE,\n\t\t{ context: { environmentInfo: 'atob or Buffer not available' } }\n\t);\n}\n\n/**\n * Encodes binary data (Uint8Array) to base64 string\n *\n * @internal Internal encoding helper — kept internal to `selva-compute`.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * https://gist.github.com/jonleighton/958841\n *\n * MIT LICENSE\n * Copyright 2011 Jon Leighton\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\nexport function base64ByteArray(bytes: Uint8Array | null | undefined): string {\n\tif (bytes === null || bytes === undefined) {\n\t\t// Import here to avoid circular dependencies at top level\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { RhinoComputeError, ErrorCodes } = require('./../../core/errors');\n\t\tthrow new RhinoComputeError(\n\t\t\t'Input bytes must not be null or undefined',\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{ context: { receivedValue: bytes } }\n\t\t);\n\t}\n\n\tconst encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n\tlet inputBytes = bytes;\n\n\t// strip bom (Byte Order Mark)\n\tif (\n\t\tinputBytes.length >= 3 &&\n\t\tinputBytes[0] === 239 &&\n\t\tinputBytes[1] === 187 &&\n\t\tinputBytes[2] === 191\n\t) {\n\t\tinputBytes = inputBytes.slice(3);\n\t}\n\n\tconst byteLength = inputBytes.byteLength;\n\tconst byteRemainder = byteLength % 3;\n\tconst mainLength = byteLength - byteRemainder;\n\n\tlet base64 = '';\n\tlet a, b, c, d;\n\tlet chunk;\n\n\t// Main loop deals with bytes in chunks of 3\n\tfor (let i = 0; i < mainLength; i += 3) {\n\t\t// Combine the three bytes into a single integer\n\n\t\tconst byte1 = inputBytes[i] !== undefined ? inputBytes[i] : 0;\n\t\tconst byte2 = inputBytes[i + 1] !== undefined ? inputBytes[i + 1] : 0;\n\t\tconst byte3 = inputBytes[i + 2] !== undefined ? inputBytes[i + 2] : 0;\n\n\t\tconst innerChunk = (byte1 << 16) | (byte2 << 8) | byte3;\n\n\t\t// Use bitmasks to extract 6-bit segments from the triplet\n\t\ta = (innerChunk & 16515072) >> 18;\n\t\tb = (innerChunk & 258048) >> 12;\n\t\tc = (innerChunk & 4032) >> 6;\n\t\td = innerChunk & 63;\n\n\t\t// Convert the raw binary segments to the appropriate ASCII encoding\n\t\tif (typeof encodings !== 'string') {\n\t\t\tthrow new Error('encodings must be a string');\n\t\t}\n\n\t\tif (typeof a !== 'number' || a < 0 || a >= encodings.length) {\n\t\t\tthrow new Error('Invalid index a');\n\t\t}\n\n\t\tif (typeof b !== 'number' || b < 0 || b >= encodings.length) {\n\t\t\tthrow new Error('Invalid index b');\n\t\t}\n\n\t\tif (typeof c !== 'number' || c < 0 || c >= encodings.length) {\n\t\t\tthrow new Error('Invalid index c');\n\t\t}\n\n\t\tif (typeof d !== 'number' || d < 0 || d >= encodings.length) {\n\t\t\tthrow new Error('Invalid index d');\n\t\t}\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\t\tconst charD = encodings[d];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined || charD === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += charA + charB + charC + charD;\n\t}\n\n\t// Deal with the remaining bytes and padding\n\tif (byteRemainder === 1) {\n\t\tchunk = inputBytes[mainLength];\n\n\t\tif (chunk === undefined) {\n\t\t\tthrow new Error(\"'chunk' must not be undefined\");\n\t\t}\n\n\t\ta = (chunk & 252) >> 2;\n\t\tb = (chunk & 3) << 4;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\n\t\tif (charA === undefined || charB === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB}==`;\n\t} else if (byteRemainder === 2) {\n\t\tconst byte1 = inputBytes[mainLength] ?? 0;\n\t\tconst byte2 = inputBytes[mainLength + 1] !== undefined ? inputBytes[mainLength + 1] : 0;\n\n\t\tif (\n\t\t\ttypeof byte1 !== 'number' ||\n\t\t\tbyte1 < 0 ||\n\t\t\tbyte1 > 255 ||\n\t\t\ttypeof byte2 !== 'number' ||\n\t\t\tbyte2 < 0 ||\n\t\t\tbyte2 > 255\n\t\t) {\n\t\t\tthrow new Error('Invalid byte1');\n\t\t}\n\n\t\tchunk = (byte1 << 8) | byte2;\n\n\t\ta = (chunk & 64512) >> 10;\n\t\tb = (chunk & 1008) >> 4;\n\t\tc = (chunk & 15) << 2;\n\n\t\tconst charA = encodings[a];\n\t\tconst charB = encodings[b];\n\t\tconst charC = encodings[c];\n\n\t\tif (charA === undefined || charB === undefined || charC === undefined) {\n\t\t\tthrow new Error('Invalid encoding index');\n\t\t}\n\n\t\tbase64 += `${charA + charB + charC}=`;\n\t}\n\n\treturn base64;\n}\n\n/**\n * Convert base64 string to rhino object\n *\n * @internal Internal helper for decoding Rhino objects — not public API.\n *\n * Source: https://github.com/mcneel/compute.rhino3d.appserver/blob/92c95a3b1d076a4d4a5360214ffd27c46425ff03/src/examples/convert/scriptjs\n * @param rhino is the rhino module form rhino3dm. Since not properly typed its not used here.\n * @param item\n * @returns\n */\nexport function base64ToRhinoObject(\n\trhino: any,\n\titem: {\n\t\ttype: string;\n\t\tdata: string;\n\t}\n) {\n\t// Import here to avoid circular dependencies at top level\n\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\tconst { getLogger } = require('./logger');\n\n\t//Make a type definition for this?\n\tlet decodata: null | object = null;\n\ttry {\n\t\tdecodata = JSON.parse(item.data);\n\t} catch (error) {\n\t\tdecodata = item;\n\t\tgetLogger().warn('Failed to parse JSON, returning original data:', error, item);\n\t}\n\tif (item.type === 'System.String') {\n\t\ttry {\n\t\t\treturn rhino.DracoCompression.decompressBase64String(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decompress Draco base64 string:', error);\n\t\t}\n\t} else if (\n\t\ttypeof decodata === 'object' &&\n\t\tObject.prototype.hasOwnProperty.call(decodata, 'opennurbs')\n\t) {\n\t\treturn rhino.CommonObject.decode(decodata);\n\t} else if (typeof decodata === 'object') {\n\t\ttry {\n\t\t\treturn rhino.CommonObject.decode(decodata);\n\t\t} catch (error) {\n\t\t\tgetLogger().error('Failed to decode Rhino object:', error);\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/chunk-P57VU27W.cjs","../src/core/errors/base.ts","../src/core/errors/error-codes.ts","../src/core/errors/index.ts","../src/core/utils/logger.ts","../src/core/compute-fetch/compute-fetch.ts","../src/core/server/compute-server-stats.ts"],"names":["RhinoComputeError","init_base","__esmMin","message","code","options","__publicField","ErrorCodes","init_error_codes","errors_exports","__export","init_errors","getLogger","internalLogger","setLogger","logger","NoOpLogger","ConsoleLogger","enableDebugLogging","init_logger","args","throwHttpError","response","fullUrl","requestId","requestSize","serverUrl","errorBody","status","statusText","context","error"],"mappings":"AAAA,qxBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,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,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,C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CC/CjCL,CAAAA,CAAAA,CAAAA,CACAQ,CAAAA,CAAAA,CAAAA,CAHA,iHAAyB,SA8BhBE,CAAAA,CACRC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACQ,CACR,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,UAAA,CAAAC,CAAW,CAAA,CAAIP,CAAAA,CACzBQ,CAAAA,CAAU,CAAE,GAAA,CAAKP,CAAAA,CAAS,SAAA,CAAAC,CAAAA,CAAW,MAAA,CAAQ,MAAA,CAAQ,WAAA,CAAAC,CAAAA,CAAa,SAAA,CAAAC,CAAU,CAAA,CAoB5EK,CAAAA,CAlB8D,CACnE,GAAA,CAAK,CAAE,OAAA,CAAS,CAAA,KAAA,EAAQH,CAAM,CAAA,EAAA,EAAKC,CAAU,CAAA,CAAA;ACmC5B","file":"/Users/felix/coding/selva-compute/dist/chunk-P57VU27W.cjs","sourcesContent":[null,"/**\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","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","/**\n * Error handling - explicit public API\n */\n\nexport { RhinoComputeError } from './base';\nexport { ErrorCodes } from './error-codes';\nexport type { ErrorCode } from './error-codes';\n","/**\n * Logger interface for structured logging\n *\n * @public Implement this interface to provide custom logging behavior.\n */\nexport interface Logger {\n\tdebug(message: string, ...args: unknown[]): void;\n\tinfo(message: string, ...args: unknown[]): void;\n\twarn(message: string, ...args: unknown[]): void;\n\terror(message: string, ...args: unknown[]): void;\n}\n\n/**\n * No-op logger implementation (default)\n * @internal\n */\nclass NoOpLogger implements Logger {\n\tdebug(): void { }\n\tinfo(): void { }\n\twarn(): void { }\n\terror(): void { }\n}\n\n/**\n * Console logger implementation\n * @internal\n */\nclass ConsoleLogger implements Logger {\n\tdebug(message: string, ...args: unknown[]): void {\n\t\tconsole.debug(message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tconsole.info(message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tconsole.warn(message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tconsole.error(message, ...args);\n\t}\n}\n\n/**\n * Internal logger instance\n * @internal\n */\nlet internalLogger: Logger = new NoOpLogger();\n\n/**\n * Get the current logger instance\n *\n * @returns The current logger instance\n */\nexport function getLogger(): Logger {\n\treturn internalLogger;\n}\n\n/**\n * Set a custom logger instance\n *\n * @public Use this to configure custom logging behavior.\n *\n * @param logger - Custom logger implementation or null to disable logging\n *\n * @example\n * ```typescript\n * import { setLogger } from 'selva-compute';\n *\n * // Enable console logging\n * setLogger(console);\n *\n * // Use a custom logger\n * setLogger({\n * debug: (msg, ...args) => myLogger.debug(msg, ...args),\n * info: (msg, ...args) => myLogger.info(msg, ...args),\n * warn: (msg, ...args) => myLogger.warn(msg, ...args),\n * error: (msg, ...args) => myLogger.error(msg, ...args)\n * });\n *\n * // Disable logging\n * setLogger(null);\n * ```\n */\nexport function setLogger(logger: Logger | Console | null): void {\n\tif (logger === null) {\n\t\tinternalLogger = new NoOpLogger();\n\t} else if ('debug' in logger && 'info' in logger && 'warn' in logger && 'error' in logger) {\n\t\tinternalLogger = logger as Logger;\n\t} else {\n\t\tinternalLogger = new ConsoleLogger();\n\t}\n}\n\n/**\n * Enable debug logging to console\n *\n * @public Convenience method to enable console logging.\n *\n * @example\n * ```typescript\n * import { enableDebugLogging } from 'selva-compute';\n *\n * enableDebugLogging();\n * ```\n */\nexport function enableDebugLogging(): void {\n\tsetLogger(new ConsoleLogger());\n}\n","import RhinoCompute from 'compute-rhino3d';\n\nimport { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute\n */\ntype Endpoint = 'grasshopper' | 'io' | string;\n\ntype EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\ntype ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\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 errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\n\t\t403: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\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'User-Agent': `compute.rhino3d.js/${RhinoCompute.version}`,\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// 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// 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 * @public Use this for advanced low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request.\n * @param config - Compute configuration (server URL, API key, timeout, debug).\n * @returns The parsed JSON response from the server.\n *\n * @example\n * ```typescript\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * {\n * pointer: { url: 'https://example.com/definition.gh' },\n * values: [{ ParamName: 'x', InnerTree: { '0': [{ type: 'System.Double', data: 10 }] } }]\n * },\n * { serverUrl: 'https://compute.rhino3d.com', debug: true, timeoutMs: 30000 }\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\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 controller = new AbortController();\n\tconst timeoutId = config.timeoutMs\n\t\t? setTimeout(() => controller.abort(), config.timeoutMs)\n\t\t: null;\n\n\ttry {\n\t\tconst startTime = performance.now();\n\t\tconst response = await fetch(fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody,\n\t\t\theaders: buildHeaders(requestId, config),\n\t\t\tsignal: controller.signal\n\t\t});\n\n\t\treturn await handleResponse(\n\t\t\tresponse,\n\t\t\tfullUrl,\n\t\t\trequestId,\n\t\t\trequestSize,\n\t\t\tconfig.serverUrl,\n\t\t\tstartTime,\n\t\t\tconfig.debug\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof Error && error.name === 'AbortError' && config.timeoutMs) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Request timed out after ${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: config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: config.timeoutMs,\n\t\t\t\t\t\turl: fullUrl,\n\t\t\t\t\t\trequestId,\n\t\t\t\t\t\targs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t// Handle fetch errors (network issues, connection refused, etc.)\n\t\tif (error instanceof TypeError) {\n\t\t\tthrow new RhinoComputeError(`Network error: ${error.message}`, ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: {\n\t\t\t\t\tserverUrl: config.serverUrl,\n\t\t\t\t\turl: fullUrl,\n\t\t\t\t\trequestId,\n\t\t\t\t\tendpoint\n\t\t\t\t},\n\t\t\t\toriginalError: error\n\t\t\t});\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tif (timeoutId !== null) clearTimeout(timeoutId);\n\t}\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\n/**\n * ComputeServerStats provides methods to query Rhino Compute server statistics.\n *\n * @public Use this for server health monitoring and statistics.\n *\n * @example\n * ```typescript\n * const stats = new ComputeServerStats('http://localhost:6500', 'your-api-key');\n *\n * try {\n * const isOnline = await stats.isServerOnline();\n * const children = await stats.getActiveChildren();\n * const version = await stats.getVersion();\n *\n * // Or get everything at once\n * const allStats = await stats.getServerStats();\n * } finally {\n * await stats.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class ComputeServerStats {\n\tprivate readonly serverUrl: string;\n\tprivate readonly apiKey?: string;\n\tprivate disposed = false;\n\tprivate activeMonitors: Set<() => void> = new Set();\n\tprivate activeTimeouts: Set<ReturnType<typeof setTimeout>> = new Set();\n\n\t/**\n\t * @param serverUrl - Base URL of the Rhino Compute server with http:// or https:// scheme (e.g., 'http://localhost:6500')\n\t * @param apiKey - Optional API key for authentication\n\t */\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tif (!serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl is required',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\t// Validate URL has http:// or https:// scheme\n\t\tif (!serverUrl.match(/^https?:\\/\\//)) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must start with \"http://\" or \"https://\". ` +\n\t\t\t\t`For example: \"http://localhost:5000\" or \"https://example.com\"`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tnew URL(serverUrl);\n\t\t} catch (err) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must be a valid URL. ` +\n\t\t\t\t`Received error: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{\n\t\t\t\t\tcontext: { serverUrl },\n\t\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tthis.apiKey = apiKey;\n\t\tthis.serverUrl = serverUrl.replace(/\\/+$/, '');\n\t}\n\n\t/**\n\t * Build request headers with optional API key.\n\t */\n\tprivate buildHeaders(): HeadersInit {\n\t\tconst headers: HeadersInit = {\n\t\t\t'Content-Type': 'application/json'\n\t\t};\n\n\t\tif (this.apiKey) {\n\t\t\theaders['RhinoComputeKey'] = this.apiKey;\n\t\t}\n\n\t\treturn headers;\n\t}\n\n\t/**\n\t * Check if the server is online.\n\t */\n\tpublic async isServerOnline(): Promise<boolean> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst url = `${this.serverUrl}/healthcheck`;\n\t\tconst init: RequestInit = { headers: this.buildHeaders(), method: 'GET' };\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, init);\n\n\t\t\treturn response.ok;\n\t\t} catch (err) {\n\t\t\tgetLogger().debug('[ComputeServerStats] Fetch error:', err);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of active child processes on the server.\n\t *\n\t * @returns Number of active children, or null if unavailable\n\t */\n\tpublic async getActiveChildren(): Promise<number | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/activechildren`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn(\n\t\t\t\t\t'[ComputeServerStats] Failed to fetch active children:',\n\t\t\t\t\tresponse.status\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst text = await response.text();\n\t\t\tconst count = parseInt(text.trim(), 10);\n\n\t\t\tif (isNaN(count)) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Invalid active children response:', text);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn count;\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching active children:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get the server version information.\n\t *\n\t * @returns Version object with rhino, compute, and git_sha, or null if unavailable\n\t */\n\tpublic async getVersion(): Promise<{\n\t\trhino: string;\n\t\tcompute: string;\n\t\tgit_sha: string | null;\n\t} | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/version`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Failed to fetch version:', response.status);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst json = await response.json();\n\t\t\t\treturn {\n\t\t\t\t\trhino: json.rhino ?? '',\n\t\t\t\t\tcompute: json.compute ?? '',\n\t\t\t\t\tgit_sha: json.git_sha ?? null\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// Fallback: parse as plain text\n\t\t\t\tconst text = await response.text();\n\t\t\t\treturn { rhino: text, compute: '', git_sha: null };\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching version:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get comprehensive server statistics.\n\t * Fetches all available server information in parallel.\n\t *\n\t * @returns Object containing server status and available stats\n\t */\n\tpublic async getServerStats(): Promise<{\n\t\tisOnline: boolean;\n\t\tversion?: { rhino: string; compute: string; git_sha: string | null };\n\t\tactiveChildren?: number;\n\t}> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst isOnline = await this.isServerOnline();\n\n\t\tif (!isOnline) {\n\t\t\treturn { isOnline: false };\n\t\t}\n\n\t\tconst [version, activeChildren] = await Promise.all([\n\t\t\tthis.getVersion(),\n\t\t\tthis.getActiveChildren()\n\t\t]);\n\n\t\treturn {\n\t\t\tisOnline: true,\n\t\t\t...(version && { version }),\n\t\t\t...(activeChildren !== null && { activeChildren })\n\t\t};\n\t}\n\n\t/**\n\t * Continuously monitor server stats at specified interval.\n\t *\n\t * @param callback - Function called with stats on each interval\n\t * @param intervalMs - Milliseconds between checks (default: 5000)\n\t * @returns Function to stop monitoring\n\t *\n\t * @example\n\t * ```typescript\n\t * const stopMonitoring = stats.monitor((data) => {\n\t * console.log('Server stats:', data);\n\t * }, 3000);\n\t *\n\t * // Later...\n\t * stopMonitoring();\n\t * ```\n\t */\n\tpublic monitor(\n\t\tcallback: (stats: Awaited<ReturnType<typeof this.getServerStats>>) => void,\n\t\tintervalMs: number = 5000\n\t): () => void {\n\t\tthis.ensureNotDisposed();\n\n\t\tlet active = true;\n\t\tlet currentTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n\t\tgetLogger().info(`🔄 Starting server stats monitoring every ${intervalMs}ms`);\n\n\t\tconst check = async () => {\n\t\t\t// Clear current timeout from tracking since it has fired\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tconst _stats = await this.getServerStats();\n\n\t\t\t// Check again after async operation to prevent race condition\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tcallback(_stats);\n\n\t\t\tif (active && !this.disposed) {\n\t\t\t\tcurrentTimeoutId = setTimeout(() => void check(), intervalMs);\n\t\t\t\tthis.activeTimeouts.add(currentTimeoutId);\n\t\t\t}\n\t\t};\n\n\t\tconst stopMonitoring = () => {\n\t\t\tactive = false;\n\n\t\t\t// Clear any pending timeout\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tclearTimeout(currentTimeoutId);\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tthis.activeMonitors.delete(stopMonitoring);\n\t\t};\n\n\t\tthis.activeMonitors.add(stopMonitoring);\n\n\t\t// Explicitly mark as fire-and-forget since we don't need to await the initial call\n\t\tvoid check();\n\n\t\treturn stopMonitoring;\n\t}\n\n\t/**\n\t * Disposes of all resources and stops all active monitors.\n\t * Call this when you're done using the stats instance.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// Stop all active monitors (this will also clear their timeouts)\n\t\tfor (const stopMonitor of this.activeMonitors) {\n\t\t\tstopMonitor();\n\t\t}\n\t\tthis.activeMonitors.clear();\n\n\t\t// Clear any remaining timeouts (defensive cleanup)\n\t\tfor (const timeoutId of this.activeTimeouts) {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t\tthis.activeTimeouts.clear();\n\t}\n\n\t/**\n\t * Ensures the instance hasn't been disposed.\n\t */\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'ComputeServerStats has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t\t{ context: { disposed: this.disposed } }\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-P57VU27W.cjs","../src/core/errors/base.ts","../src/core/errors/error-codes.ts","../src/core/errors/index.ts","../src/core/utils/logger.ts","../src/core/compute-fetch/compute-fetch.ts","../src/core/server/compute-server-stats.ts"],"names":["RhinoComputeError","init_base","__esmMin","message","code","options","__publicField","ErrorCodes","init_error_codes","errors_exports","__export","init_errors","getLogger","internalLogger","setLogger","logger","NoOpLogger","ConsoleLogger","enableDebugLogging","init_logger","args","throwHttpError","response","fullUrl","requestId","requestSize","serverUrl","errorBody","status","statusText","context","error"],"mappings":"AAAA,qxBAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,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,CAA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C,CACrC,KAAA,CAAMd,CAAAA,CAAAA,GAAoBiB,CAAAA,CAAuB,CAChD,OAAA,CAAQ,KAAA,CAAMjB,CAAAA,CAAS,GAAGiB,CAAI,CAC/B,CAEA,IAAA,CAAKjB,CAAAA,CAAAA,GAAoBiB,CAAAA,CAAuB,CAC/C,OAAA,CAAQ,IAAA,CAAKjB,CAAAA,CAAS,GAAGiB,CAAI,CAC9B,CAEA,IAAA,CAAKjB,CAAAA,CAAAA,GAAoBiB,CAAAA,CAAuB,CAC/C,OAAA,CAAQ,IAAA,CAAKjB,CAAAA,CAAS,GAAGiB,CAAI,CAC9B,CAEA,KAAA,CAAMjB,CAAAA,CAAAA,GAAoBiB,CAAAA,CAAuB,CAChD,OAAA,CAAQ,KAAA,CAAMjB,CAAAA,CAAS,GAAGiB,CAAI,CAC/B,CACD,CAAA,CAMIP,CAAAA,CAAyB,IAAIG,CAAAA,CAAAA,CAAAA,CC/CjCL,CAAAA,CAAAA,CAAAA,CACAQ,CAAAA,CAAAA,CAAAA,CAHA,iHAAyB,SA8BhBE,CAAAA,CACRC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACQ,CACR,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,UAAA,CAAAC,CAAW,CAAA,CAAIP,CAAAA,CACzBQ,CAAAA,CAAU,CAAE,GAAA,CAAKP,CAAAA,CAAS,SAAA,CAAAC,CAAAA,CAAW,MAAA,CAAQ,MAAA,CAAQ,WAAA,CAAAC,CAAAA,CAAa,SAAA,CAAAC,CAAU,CAAA,CAoB5EK,CAAAA,CAlB8D,CACnE,GAAA,CAAK,CAAE,OAAA,CAAS,CAAA,KAAA,EAAQH,CAAM,CAAA,EAAA,EAAKC,CAAU,CAAA,CAAA;ACmC5B","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-P57VU27W.cjs","sourcesContent":[null,"/**\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","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","/**\n * Error handling - explicit public API\n */\n\nexport { RhinoComputeError } from './base';\nexport { ErrorCodes } from './error-codes';\nexport type { ErrorCode } from './error-codes';\n","/**\n * Logger interface for structured logging\n *\n * @public Implement this interface to provide custom logging behavior.\n */\nexport interface Logger {\n\tdebug(message: string, ...args: unknown[]): void;\n\tinfo(message: string, ...args: unknown[]): void;\n\twarn(message: string, ...args: unknown[]): void;\n\terror(message: string, ...args: unknown[]): void;\n}\n\n/**\n * No-op logger implementation (default)\n * @internal\n */\nclass NoOpLogger implements Logger {\n\tdebug(): void { }\n\tinfo(): void { }\n\twarn(): void { }\n\terror(): void { }\n}\n\n/**\n * Console logger implementation\n * @internal\n */\nclass ConsoleLogger implements Logger {\n\tdebug(message: string, ...args: unknown[]): void {\n\t\tconsole.debug(message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tconsole.info(message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tconsole.warn(message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tconsole.error(message, ...args);\n\t}\n}\n\n/**\n * Internal logger instance\n * @internal\n */\nlet internalLogger: Logger = new NoOpLogger();\n\n/**\n * Get the current logger instance\n *\n * @returns The current logger instance\n */\nexport function getLogger(): Logger {\n\treturn internalLogger;\n}\n\n/**\n * Set a custom logger instance\n *\n * @public Use this to configure custom logging behavior.\n *\n * @param logger - Custom logger implementation or null to disable logging\n *\n * @example\n * ```typescript\n * import { setLogger } from 'selva-compute';\n *\n * // Enable console logging\n * setLogger(console);\n *\n * // Use a custom logger\n * setLogger({\n * debug: (msg, ...args) => myLogger.debug(msg, ...args),\n * info: (msg, ...args) => myLogger.info(msg, ...args),\n * warn: (msg, ...args) => myLogger.warn(msg, ...args),\n * error: (msg, ...args) => myLogger.error(msg, ...args)\n * });\n *\n * // Disable logging\n * setLogger(null);\n * ```\n */\nexport function setLogger(logger: Logger | Console | null): void {\n\tif (logger === null) {\n\t\tinternalLogger = new NoOpLogger();\n\t} else if ('debug' in logger && 'info' in logger && 'warn' in logger && 'error' in logger) {\n\t\tinternalLogger = logger as Logger;\n\t} else {\n\t\tinternalLogger = new ConsoleLogger();\n\t}\n}\n\n/**\n * Enable debug logging to console\n *\n * @public Convenience method to enable console logging.\n *\n * @example\n * ```typescript\n * import { enableDebugLogging } from 'selva-compute';\n *\n * enableDebugLogging();\n * ```\n */\nexport function enableDebugLogging(): void {\n\tsetLogger(new ConsoleLogger());\n}\n","import RhinoCompute from 'compute-rhino3d';\n\nimport { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\nimport type { ComputeConfig } from '../types';\nimport type {\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tIoResponseSchema\n} from '@/features/grasshopper/types';\n\n/**\n * Valid endpoints for Rhino Compute\n */\ntype Endpoint = 'grasshopper' | 'io' | string;\n\ntype EndpointResponseMap = {\n\tgrasshopper: GrasshopperComputeResponse;\n\tio: IoResponseSchema;\n};\n\ntype ComputeResponseFor<E extends string> = E extends keyof EndpointResponseMap\n\t? EndpointResponseMap[E]\n\t: unknown;\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 errorMap: Record<number, { message: string; code: string }> = {\n\t\t401: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\n\t\t403: { message: `HTTP ${status}: ${statusText}`, code: ErrorCodes.AUTH_ERROR },\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'User-Agent': `compute.rhino3d.js/${RhinoCompute.version}`,\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// 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// 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 * @public Use this for advanced low-level control over compute requests. For most use cases, prefer higher-level APIs.\n *\n * @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').\n * @param args - Pre-prepared arguments for the request.\n * @param config - Compute configuration (server URL, API key, timeout, debug).\n * @returns The parsed JSON response from the server.\n *\n * @example\n * ```typescript\n * const response = await fetchRhinoCompute(\n * 'grasshopper',\n * {\n * pointer: { url: 'https://example.com/definition.gh' },\n * values: [{ ParamName: 'x', InnerTree: { '0': [{ type: 'System.Double', data: 10 }] } }]\n * },\n * { serverUrl: 'https://compute.rhino3d.com', debug: true, timeoutMs: 30000 }\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\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 controller = new AbortController();\n\tconst timeoutId = config.timeoutMs\n\t\t? setTimeout(() => controller.abort(), config.timeoutMs)\n\t\t: null;\n\n\ttry {\n\t\tconst startTime = performance.now();\n\t\tconst response = await fetch(fullUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tbody,\n\t\t\theaders: buildHeaders(requestId, config),\n\t\t\tsignal: controller.signal\n\t\t});\n\n\t\treturn await handleResponse(\n\t\t\tresponse,\n\t\t\tfullUrl,\n\t\t\trequestId,\n\t\t\trequestSize,\n\t\t\tconfig.serverUrl,\n\t\t\tstartTime,\n\t\t\tconfig.debug\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof Error && error.name === 'AbortError' && config.timeoutMs) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Request timed out after ${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: config.serverUrl,\n\t\t\t\t\t\ttimeoutMs: config.timeoutMs,\n\t\t\t\t\t\turl: fullUrl,\n\t\t\t\t\t\trequestId,\n\t\t\t\t\t\targs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t// Handle fetch errors (network issues, connection refused, etc.)\n\t\tif (error instanceof TypeError) {\n\t\t\tthrow new RhinoComputeError(`Network error: ${error.message}`, ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: {\n\t\t\t\t\tserverUrl: config.serverUrl,\n\t\t\t\t\turl: fullUrl,\n\t\t\t\t\trequestId,\n\t\t\t\t\tendpoint\n\t\t\t\t},\n\t\t\t\toriginalError: error\n\t\t\t});\n\t\t}\n\n\t\tthrow error;\n\t} finally {\n\t\tif (timeoutId !== null) clearTimeout(timeoutId);\n\t}\n}\n","import { RhinoComputeError, ErrorCodes } from '../errors';\nimport { getLogger } from '../utils/logger';\n\n/**\n * ComputeServerStats provides methods to query Rhino Compute server statistics.\n *\n * @public Use this for server health monitoring and statistics.\n *\n * @example\n * ```typescript\n * const stats = new ComputeServerStats('http://localhost:6500', 'your-api-key');\n *\n * try {\n * const isOnline = await stats.isServerOnline();\n * const children = await stats.getActiveChildren();\n * const version = await stats.getVersion();\n *\n * // Or get everything at once\n * const allStats = await stats.getServerStats();\n * } finally {\n * await stats.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class ComputeServerStats {\n\tprivate readonly serverUrl: string;\n\tprivate readonly apiKey?: string;\n\tprivate disposed = false;\n\tprivate activeMonitors: Set<() => void> = new Set();\n\tprivate activeTimeouts: Set<ReturnType<typeof setTimeout>> = new Set();\n\n\t/**\n\t * @param serverUrl - Base URL of the Rhino Compute server with http:// or https:// scheme (e.g., 'http://localhost:6500')\n\t * @param apiKey - Optional API key for authentication\n\t */\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tif (!serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl is required',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\t// Validate URL has http:// or https:// scheme\n\t\tif (!serverUrl.match(/^https?:\\/\\//)) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must start with \"http://\" or \"https://\". ` +\n\t\t\t\t`For example: \"http://localhost:5000\" or \"https://example.com\"`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tnew URL(serverUrl);\n\t\t} catch (err) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t`Invalid serverUrl: \"${serverUrl}\". Must be a valid URL. ` +\n\t\t\t\t`Received error: ${err instanceof Error ? err.message : String(err)}`,\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{\n\t\t\t\t\tcontext: { serverUrl },\n\t\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tthis.apiKey = apiKey;\n\t\tthis.serverUrl = serverUrl.replace(/\\/+$/, '');\n\t}\n\n\t/**\n\t * Build request headers with optional API key.\n\t */\n\tprivate buildHeaders(): HeadersInit {\n\t\tconst headers: HeadersInit = {\n\t\t\t'Content-Type': 'application/json'\n\t\t};\n\n\t\tif (this.apiKey) {\n\t\t\theaders['RhinoComputeKey'] = this.apiKey;\n\t\t}\n\n\t\treturn headers;\n\t}\n\n\t/**\n\t * Check if the server is online.\n\t */\n\tpublic async isServerOnline(): Promise<boolean> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst url = `${this.serverUrl}/healthcheck`;\n\t\tconst init: RequestInit = { headers: this.buildHeaders(), method: 'GET' };\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, init);\n\n\t\t\treturn response.ok;\n\t\t} catch (err) {\n\t\t\tgetLogger().debug('[ComputeServerStats] Fetch error:', err);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Get the number of active child processes on the server.\n\t *\n\t * @returns Number of active children, or null if unavailable\n\t */\n\tpublic async getActiveChildren(): Promise<number | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/activechildren`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn(\n\t\t\t\t\t'[ComputeServerStats] Failed to fetch active children:',\n\t\t\t\t\tresponse.status\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst text = await response.text();\n\t\t\tconst count = parseInt(text.trim(), 10);\n\n\t\t\tif (isNaN(count)) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Invalid active children response:', text);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn count;\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching active children:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get the server version information.\n\t *\n\t * @returns Version object with rhino, compute, and git_sha, or null if unavailable\n\t */\n\tpublic async getVersion(): Promise<{\n\t\trhino: string;\n\t\tcompute: string;\n\t\tgit_sha: string | null;\n\t} | null> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\tconst response = await fetch(`${this.serverUrl}/version`, {\n\t\t\t\theaders: this.buildHeaders()\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tgetLogger().warn('[ComputeServerStats] Failed to fetch version:', response.status);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst json = await response.json();\n\t\t\t\treturn {\n\t\t\t\t\trhino: json.rhino ?? '',\n\t\t\t\t\tcompute: json.compute ?? '',\n\t\t\t\t\tgit_sha: json.git_sha ?? null\n\t\t\t\t};\n\t\t\t} catch {\n\t\t\t\t// Fallback: parse as plain text\n\t\t\t\tconst text = await response.text();\n\t\t\t\treturn { rhino: text, compute: '', git_sha: null };\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tgetLogger().warn('[ComputeServerStats] Error fetching version:', err);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Get comprehensive server statistics.\n\t * Fetches all available server information in parallel.\n\t *\n\t * @returns Object containing server status and available stats\n\t */\n\tpublic async getServerStats(): Promise<{\n\t\tisOnline: boolean;\n\t\tversion?: { rhino: string; compute: string; git_sha: string | null };\n\t\tactiveChildren?: number;\n\t}> {\n\t\tthis.ensureNotDisposed();\n\n\t\tconst isOnline = await this.isServerOnline();\n\n\t\tif (!isOnline) {\n\t\t\treturn { isOnline: false };\n\t\t}\n\n\t\tconst [version, activeChildren] = await Promise.all([\n\t\t\tthis.getVersion(),\n\t\t\tthis.getActiveChildren()\n\t\t]);\n\n\t\treturn {\n\t\t\tisOnline: true,\n\t\t\t...(version && { version }),\n\t\t\t...(activeChildren !== null && { activeChildren })\n\t\t};\n\t}\n\n\t/**\n\t * Continuously monitor server stats at specified interval.\n\t *\n\t * @param callback - Function called with stats on each interval\n\t * @param intervalMs - Milliseconds between checks (default: 5000)\n\t * @returns Function to stop monitoring\n\t *\n\t * @example\n\t * ```typescript\n\t * const stopMonitoring = stats.monitor((data) => {\n\t * console.log('Server stats:', data);\n\t * }, 3000);\n\t *\n\t * // Later...\n\t * stopMonitoring();\n\t * ```\n\t */\n\tpublic monitor(\n\t\tcallback: (stats: Awaited<ReturnType<typeof this.getServerStats>>) => void,\n\t\tintervalMs: number = 5000\n\t): () => void {\n\t\tthis.ensureNotDisposed();\n\n\t\tlet active = true;\n\t\tlet currentTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n\t\tgetLogger().info(`🔄 Starting server stats monitoring every ${intervalMs}ms`);\n\n\t\tconst check = async () => {\n\t\t\t// Clear current timeout from tracking since it has fired\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tconst _stats = await this.getServerStats();\n\n\t\t\t// Check again after async operation to prevent race condition\n\t\t\tif (!active || this.disposed) return;\n\n\t\t\tcallback(_stats);\n\n\t\t\tif (active && !this.disposed) {\n\t\t\t\tcurrentTimeoutId = setTimeout(() => void check(), intervalMs);\n\t\t\t\tthis.activeTimeouts.add(currentTimeoutId);\n\t\t\t}\n\t\t};\n\n\t\tconst stopMonitoring = () => {\n\t\t\tactive = false;\n\n\t\t\t// Clear any pending timeout\n\t\t\tif (currentTimeoutId !== null) {\n\t\t\t\tclearTimeout(currentTimeoutId);\n\t\t\t\tthis.activeTimeouts.delete(currentTimeoutId);\n\t\t\t\tcurrentTimeoutId = null;\n\t\t\t}\n\n\t\t\tthis.activeMonitors.delete(stopMonitoring);\n\t\t};\n\n\t\tthis.activeMonitors.add(stopMonitoring);\n\n\t\t// Explicitly mark as fire-and-forget since we don't need to await the initial call\n\t\tvoid check();\n\n\t\treturn stopMonitoring;\n\t}\n\n\t/**\n\t * Disposes of all resources and stops all active monitors.\n\t * Call this when you're done using the stats instance.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// Stop all active monitors (this will also clear their timeouts)\n\t\tfor (const stopMonitor of this.activeMonitors) {\n\t\t\tstopMonitor();\n\t\t}\n\t\tthis.activeMonitors.clear();\n\n\t\t// Clear any remaining timeouts (defensive cleanup)\n\t\tfor (const timeoutId of this.activeTimeouts) {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t\tthis.activeTimeouts.clear();\n\t}\n\n\t/**\n\t * Ensures the instance hasn't been disposed.\n\t */\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'ComputeServerStats has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t\t{ context: { disposed: this.disposed } }\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/chunk-PNG3L5TM.cjs","../src/features/grasshopper/client/grasshopper-client.ts","../src/features/grasshopper/io/output/rhino-decoder.ts","../src/features/grasshopper/io/output/response-processors.ts","../src/features/grasshopper/client/grasshopper-response-processor.ts","../src/core/utils/warnings.ts","../src/features/grasshopper/compute/solve.ts","../src/core/utils/camel-case.ts","../src/features/grasshopper/io/input/input-processors.ts","../src/core/errors/error-factory.ts"],"names":["init_errors","init_base","init_logger","GrasshopperClient","_GrasshopperClient","config","__publicField","ComputeServerStats","client","RhinoComputeError","ErrorCodes","definition","fetchParsedDefinitionIO","fetchDefinitionIO","dataTree","result","solveGrasshopperDefinition","error","getLogger","decoderRegistry","registerDecoder","typeName","decoder","rhino","data","d","findDecoder","rhinoType","key","dec","extractPayload","parsedData","decodeRhinoGeometry","payload","SYSTEM_TYPES","EXCLUDED_TYPES","RHINO_GEOMETRY_PREFIX","FILE_DATA_TYPE","isExcludedType","type","t","tryDecodeJSON","value","trimmed","first","decodeBySystemType","raw","extractItemValue","parseValues","forEachTreeItem","tree","handler","list","item","getValues","response","byId","options","stringOnly","param","extractFileData","output","parsed","getValue","parseOptions","targetParam","p","found","collected","v","GrasshopperResponseProcessor","debug","paramName","paramId","mergedOptions","getThreeMeshesFromComputeResponse","folderName","additionalFiles","files","downloadFileData","warnIfClientSide","functionName","suppress","args","prepareGrasshopperArgs","applyOptionalComputeSettings","fetchRhinoCompute","base64ByteArray","isBase64","encodeStringToBase64","arglist","toCamelCase","str","preserveSpaces","s","_","c","m","camelcaseKeys","obj","camelKey","init_error_codes","ValidationErrors","inputName","reason"],"mappings":"AAAA,2/BAAwC,wDAAuD,wDAAoH,iCCAnNA,CAAAA,CACAC,iCAAAA,CAAAA,CACAC,iCAAAA,CAAAA,CA8BA,IAAqBC,CAAAA,CAArB,MAAqBC,CAAkB,CAK9B,WAAA,CAAYC,CAAAA,CAAkC,CAJtDC,iCAAAA,IAAA,CAAiB,QAAA,CAAA,CACjBA,iCAAAA,IAAA,CAAgB,aAAA,CAAA,CAChBA,iCAAAA,IAAA,CAAQ,UAAA,CAAW,CAAA,CAAA,CAAA,CAGlB,IAAA,CAAK,MAAA,CAAS,IAAA,CAAK,sBAAA,CAAuBD,CAAM,CAAA,CAChD,IAAA,CA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AAG,CAAA,CACvDF,CAAAA,CAQT,CAWO,SAASI,CAAAA,CACfC,CAAAA,CACA1C,CAAAA,CAAwD,CAAC,CAAA,CAC/C,CACV,MAAI,CAAC0C,CAAAA,EAAO,OAAOA,CAAAA,EAAQ,QAAA,CACnBA,CAAAA,CAGJ,KAAA,CAAM,OAAA,CAAQA,CAAG,CAAA,CACb1C,CAAAA,CAAQ,IAAA,CAAO0C,CAAAA,CAAI,GAAA,CAAK9C,CAAAA,EAAS6C,CAAAA,CAAc7C,CAAAA,CAAMI,CAAO,CAAC,CAAA,CAAI0C,CAAAA,CAGlE,MAAA,CAAO,IAAA,CAAKA,CAAG,CAAA,CAAE,MAAA,CACvB,CAACpF,CAAAA,CAAQa,CAAAA,CAAAA,EAAQ,CAChB,IAAMwE,CAAAA,CAAWT,EAAAA,CAAY/D,CAAAA,CAAK,CAAE,cAAA,CAAgB6B,CAAAA,CAAQ,cAAe,CAAC,CAAA,CACtEf,CAAAA,CAASyD,CAAAA,CAAYvE,CAAG,CAAA,CAC9B,OAACb,CAAAA,CAAeqF,CAAQ,CAAA,CAAI3C,CAAAA,CAAQ,IAAA,CAAOyC,CAAAA,CAAcxD,CAAAA,CAAOe,CAAO,CAAA,CAAIf,CAAAA,CACpE3B,CACR,CAAA,CACA,CAAC,CACF,CACD,CCtDAf,iCAAAA,CAAAA,CCAAC,iCAAAA,CAAAA,CACAoG,iCAAAA,CAAAA,CAyBO,IAAMC,CAAAA,CAAmB,CAI/B,OAAA,CAAS,CAACC,CAAAA,CAAmBC,CAAAA,CAAgB/C,CAAAA,CAAAA,EAC5C,IAAIhD,wBAAAA,CAAkB,CAAA,OAAA,EAAU8F,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA","file":"/Users/felix/coding/selva-compute/dist/chunk-PNG3L5TM.cjs","sourcesContent":[null,"import { ErrorCodes } from '@/core/errors';\nimport { RhinoComputeError } from '@/core/errors/base';\nimport { getLogger } from '@/core/utils/logger';\nimport ComputeServerStats from '@/core/server/compute-server-stats';\nimport { ComputeConfig } from '@/core/types';\n\nimport { fetchDefinitionIO, fetchParsedDefinitionIO, solveGrasshopperDefinition } from '..';\nimport { GrasshopperComputeConfig, GrasshopperComputeResponse, DataTree } from '../types';\n\n/**\n * GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.\n *\n * @public This is the recommended high-level API for Rhino Compute operations.\n *\n * **Security Warning:**\n * Using this client in a browser environment exposes your server URL and API key to users.\n * For production, use this library server-side or proxy requests through your own backend.\n *\n * @example\n * ```typescript\n * const client = await GrasshopperClient.create({\n * serverUrl: 'http://localhost:6500',\n * apiKey: 'your-api-key'\n * });\n *\n * try {\n * const result = await client.solve(definitionUrl, { x: 1, y: 2 });\n * } finally {\n * await client.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class GrasshopperClient {\n\tprivate readonly config: GrasshopperComputeConfig;\n\tpublic readonly serverStats: ComputeServerStats;\n\tprivate disposed = false;\n\n\tprivate constructor(config: GrasshopperComputeConfig) {\n\t\tthis.config = this.normalizeComputeConfig(config);\n\t\tthis.serverStats = new ComputeServerStats(this.config.serverUrl, this.config.apiKey);\n\t}\n\n\t/**\n\t * Creates and initializes a GrasshopperClient with server validation.\n\t *\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tstatic async create(config: GrasshopperComputeConfig): Promise<GrasshopperClient> {\n\t\tconst client = new GrasshopperClient(config);\n\n\t\t// Check server is online before returning\n\t\tif (!(await client.serverStats.isServerOnline())) {\n\t\t\tthrow new RhinoComputeError('Rhino Compute server is not online', ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: { serverUrl: client.config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\treturn client;\n\t}\n\n\t/**\n\t * Gets the client's configuration.\n\t * Useful for passing to lower-level functions.\n\t */\n\tpublic getConfig(): GrasshopperComputeConfig {\n\t\tthis.ensureNotDisposed();\n\t\treturn { ...this.config };\n\t}\n\n\t/**\n\t * Get input/output parameters of a Grasshopper definition.\n\t */\n\tpublic async getIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchParsedDefinitionIO(definition, this.config);\n\t}\n\n\tpublic async getRawIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchDefinitionIO(definition, this.config);\n\t}\n\n\t/**\n\t * Run a compute job with a Grasshopper definition.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails\n\t */\n\tpublic async solve(\n\t\tdefinition: string | Uint8Array,\n\t\tdataTree: DataTree[]\n\t): Promise<GrasshopperComputeResponse> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\t// Validate inputs\n\t\t\tif (typeof definition === 'string' && !definition?.trim()) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Definition URL/content is required',\n\t\t\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: { receivedUrl: definition }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} else if (definition instanceof Uint8Array && definition.length === 0) {\n\t\t\t\tthrow new RhinoComputeError('Definition content is empty', ErrorCodes.INVALID_INPUT);\n\t\t\t}\n\n\t\t\t// Check server\n\t\t\tif (!(await this.serverStats.isServerOnline())) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Rhino Compute server is not online',\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ context: { serverUrl: this.config.serverUrl } }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run computation\n\t\t\tconst result = await solveGrasshopperDefinition(dataTree, definition, this.config);\n\n\t\t\t// Check for errors\n\t\t\tif (result && typeof result === 'object' && 'message' in result && !('fileData' in result)) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t(result as { message: string }).message || 'Computation failed',\n\t\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tgetLogger().error('Compute failed:', error);\n\t\t\t}\n\n\t\t\tif (error instanceof RhinoComputeError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t},\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}\n\n\t/**\n\t * Disposes of client resources.\n\t * Call this when you're done using the client.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// If serverStats has a dispose method, call it\n\t\tif ('dispose' in this.serverStats && typeof this.serverStats.dispose === 'function') {\n\t\t\tawait this.serverStats.dispose();\n\t\t}\n\n\t\t// Clear any cached data or connections if needed\n\t}\n\n\t/**\n\t * Ensures the client hasn't been disposed.\n\t */\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'GrasshopperClient has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validates and normalizes a compute configuration.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tprivate normalizeComputeConfig<T extends ComputeConfig | GrasshopperComputeConfig>(config: T): T {\n\t\tif (!config.serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError('serverUrl is required', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate URL format\n\t\ttry {\n\t\t\tnew URL(config.serverUrl);\n\t\t} catch {\n\t\t\tthrow new RhinoComputeError('serverUrl must be a valid URL', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate that it's not the default public endpoint\n\t\tif (config.serverUrl === '' || config.serverUrl === 'https://compute.rhino3d.com/') {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { receivedServerUrl: config.serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\t...config,\n\t\t\tserverUrl: config.serverUrl.replace(/\\/+$/, ''), // Remove trailing slashes\n\t\t\tapiKey: config.apiKey,\n\t\t\tauthToken: config.authToken,\n\t\t\tdebug: config.debug ?? false,\n\t\t\tsuppressClientSideWarning: config.suppressClientSideWarning\n\t\t} as T;\n\t}\n}\n","import type { RhinoModule } from 'rhino3dm';\nimport { getLogger } from '@/core';\n\n// -----------------------------------------------------------------------------\n// Decoder Types\n// -----------------------------------------------------------------------------\n\ntype RhinoDecoder = (rhino: RhinoModule, data: unknown) => unknown;\n\nconst decoderRegistry = new Map<string, RhinoDecoder>();\n\n// -----------------------------------------------------------------------------\n// Registration\n// -----------------------------------------------------------------------------\n\nexport function registerDecoder(typeName: string, decoder: RhinoDecoder): void {\n\tdecoderRegistry.set(typeName, decoder);\n}\n\nregisterDecoder('Rhino.Geometry.Point3d', (rhino, data) => {\n\tconst d = data as any;\n\tif (!d || typeof d.X !== 'number') return null;\n\treturn new rhino.Point([d.X, d.Y, d.Z]);\n});\n\nregisterDecoder('Rhino.Geometry.Line', (rhino, data) => {\n\tconst d = data as any;\n\tif (!d || !d.From || !d.To) return null;\n\treturn new rhino.Line([d.From.X, d.From.Y, d.From.Z], [d.To.X, d.To.Y, d.To.Z]);\n});\n\n// -----------------------------------------------------------------------------\n// Utility Functions\n// -----------------------------------------------------------------------------\n\nfunction findDecoder(rhinoType: string): RhinoDecoder | undefined {\n\tif (decoderRegistry.has(rhinoType)) return decoderRegistry.get(rhinoType);\n\tfor (const [key, dec] of decoderRegistry) {\n\t\tif (rhinoType.startsWith(key)) return dec;\n\t}\n\treturn undefined;\n}\n\nfunction extractPayload(parsedData: any): any {\n\tif (!parsedData || typeof parsedData !== 'object') return null;\n\treturn (parsedData as any).data ?? (parsedData as any).value ?? null;\n}\n\n// -----------------------------------------------------------------------------\n// Geometry Decoding\n// -----------------------------------------------------------------------------\n\nexport function decodeRhinoGeometry(\n\tparsedData: unknown,\n\trhinoType: string,\n\trhino: RhinoModule\n): unknown {\n\tconst decoder = findDecoder(rhinoType);\n\tif (decoder) {\n\t\ttry {\n\t\t\treturn decoder(rhino, parsedData);\n\t\t} catch (error) {\n\t\t\tgetLogger().warn(`Failed to decode Rhino type ${rhinoType}:`, error);\n\t\t}\n\t}\n\n\t// Fallback using CommonObject.decode\n\ttry {\n\t\tconst payload = extractPayload(parsedData);\n\t\tif (payload) return rhino.CommonObject.decode(payload);\n\t} catch (error) {\n\t\tgetLogger().warn(`Failed to decode ${rhinoType} with CommonObject:`, error);\n\t\treturn { __decodeError: true, type: rhinoType, raw: parsedData };\n\t}\n\n\treturn parsedData;\n}\n\n// -----------------------------------------------------------------------------\n// Object Decoder\n// -----------------------------------------------------------------------------\n\nexport interface DecodeRhinoOptions {\n\tkeys?: string[];\n\tskipKeys?: string[];\n\tdeep?: boolean;\n}\n\nexport function decodeRhinoObject<T extends Record<string, unknown>>(\n\tobj: T,\n\trhino: RhinoModule,\n\toptions: DecodeRhinoOptions = {}\n): T {\n\tconst { keys, skipKeys, deep } = options;\n\tconst out: Record<string, unknown> = { ...obj };\n\n\tconst shouldProcessKey = (k: string) => {\n\t\tif (skipKeys?.includes(k)) return false;\n\t\tif (keys && !keys.includes(k)) return false;\n\t\treturn true;\n\t};\n\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tif (!shouldProcessKey(key)) continue;\n\t\tif (!value || typeof value !== 'object') continue;\n\n\t\tconst v: any = value;\n\t\tconst maybeType = typeof v.type === 'string' ? v.type : undefined;\n\n\t\tif (maybeType) {\n\t\t\tout[key] = decodeRhinoGeometry(v, maybeType, rhino);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (deep && typeof v === 'object') {\n\t\t\tout[key] = decodeRhinoObject(v as any, rhino, options);\n\t\t}\n\t}\n\n\treturn out as T;\n}\n","import { FileData } from '../../../file-handling/types';\nimport { GrasshopperComputeResponse, DataItem } from '../../types';\nimport { decodeRhinoGeometry } from './rhino-decoder';\n\nexport interface ParsedContext {\n\t[key: string]: any;\n}\n\nexport interface GetValuesOptions {\n\tparseValues?: boolean;\n\trhino?: any;\n\t/**\n\t * If true, only include values of type System.String in the result.\n\t * Non-string types are filtered out.\n\t */\n\tstringOnly?: boolean;\n}\n\nexport interface GetValuesResult<T = ParsedContext> {\n\tvalues: T;\n}\n\n// -----------------------------------------------------------------------------\n// Constants\n// -----------------------------------------------------------------------------\n\nconst SYSTEM_TYPES = {\n\tSTRING: 'System.String',\n\tINT: 'System.Int32',\n\tDOUBLE: 'System.Double',\n\tBOOL: 'System.Boolean'\n};\n\nconst EXCLUDED_TYPES = ['WebDisplay'];\nconst RHINO_GEOMETRY_PREFIX = 'Rhino.Geometry.';\nconst FILE_DATA_TYPE = 'FileData';\n\n// -----------------------------------------------------------------------------\n// Utilities\n// -----------------------------------------------------------------------------\n\nfunction isExcludedType(type: string): boolean {\n\treturn EXCLUDED_TYPES.some((t) => type.includes(t));\n}\n\nfunction tryDecodeJSON(value: string): any {\n\tif (typeof value !== 'string') return value;\n\n\tconst trimmed = value.trim();\n\tconst looksJson = trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('\"');\n\tif (!looksJson) return value;\n\n\ttry {\n\t\tconst first = JSON.parse(trimmed);\n\t\tif (typeof first === 'string') {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(first);\n\t\t\t} catch {\n\t\t\t\treturn first;\n\t\t\t}\n\t\t}\n\t\treturn first;\n\t} catch {\n\t\treturn value;\n\t}\n}\n\nfunction decodeBySystemType(raw: any, type: string, rhino?: any): any {\n\tswitch (type) {\n\t\tcase SYSTEM_TYPES.STRING:\n\t\t\tif (typeof raw !== 'string') return raw;\n\t\t\treturn raw.replace(/^\"(.*)\"$/, '$1');\n\n\t\tcase SYSTEM_TYPES.INT:\n\t\t\treturn Number.parseInt(raw, 10);\n\n\t\tcase SYSTEM_TYPES.DOUBLE:\n\t\t\treturn Number.parseFloat(raw);\n\n\t\tcase SYSTEM_TYPES.BOOL: {\n\t\t\tconst str = String(raw).toLowerCase();\n\t\t\treturn str === 'true';\n\t\t}\n\n\t\tdefault:\n\t\t\tif (rhino && type.startsWith(RHINO_GEOMETRY_PREFIX)) {\n\t\t\t\treturn decodeRhinoGeometry(raw, type, rhino);\n\t\t\t}\n\t\t\treturn raw;\n\t}\n}\n\n// Main extractor\nfunction extractItemValue(data: any, type: string, parseValues: boolean, rhino?: any): any {\n\tif (isExcludedType(type)) return null;\n\n\tif (typeof data !== 'string') return data;\n\n\tconst raw = parseValues ? tryDecodeJSON(data) : data;\n\treturn decodeBySystemType(raw, type, rhino);\n}\n\n// Traversal helper\nfunction forEachTreeItem(\n\ttree: GrasshopperComputeResponse['values'][0]['InnerTree'],\n\thandler: (item: DataItem) => void\n) {\n\tfor (const list of Object.values(tree)) {\n\t\tif (Array.isArray(list)) {\n\t\t\tfor (const item of list) handler(item);\n\t\t}\n\t}\n}\n\n// -----------------------------------------------------------------------------\n// Public API\n// -----------------------------------------------------------------------------\n\nexport function getValues<T = ParsedContext>(\n\tresponse: GrasshopperComputeResponse,\n\tbyId: boolean = false,\n\toptions: GetValuesOptions = {}\n): GetValuesResult<T> {\n\tconst { parseValues = true, rhino, stringOnly = false } = options;\n\tconst result: ParsedContext = {};\n\n\tfor (const param of response.values) {\n\t\tforEachTreeItem(param.InnerTree, (item) => {\n\t\t\t// Skip non-string types if stringOnly is enabled\n\t\t\tif (stringOnly && item.type !== SYSTEM_TYPES.STRING) return;\n\n\t\t\tconst key = byId ? item.id : param.ParamName;\n\t\t\tif (!key) return;\n\n\t\t\tconst value = extractItemValue(item.data, item.type, parseValues, rhino);\n\n\t\t\tif (result[key] === undefined) {\n\t\t\t\tresult[key] = value;\n\t\t\t} else if (Array.isArray(result[key])) {\n\t\t\t\tresult[key].push(value);\n\t\t\t} else {\n\t\t\t\tresult[key] = [result[key], value];\n\t\t\t}\n\t\t});\n\t}\n\n\treturn { values: result as T };\n}\n\nexport function extractFileData(response: GrasshopperComputeResponse): FileData[] {\n\tconst output: FileData[] = [];\n\n\tfor (const param of response.values) {\n\t\tforEachTreeItem(param.InnerTree, (item) => {\n\t\t\tif (!item.type.includes(FILE_DATA_TYPE)) return;\n\n\t\t\tconst parsed = tryDecodeJSON(item.data);\n\t\t\tif (parsed && parsed.FileName && parsed.FileType && parsed.Data) {\n\t\t\t\toutput.push(parsed as FileData);\n\t\t\t}\n\t\t});\n\t}\n\n\treturn output;\n}\n\nexport function getValue(\n\tresponse: GrasshopperComputeResponse,\n\toptions: { byName: string } | { byId: string },\n\tparseOptions: GetValuesOptions = {}\n): any {\n\tconst { parseValues = true, rhino, stringOnly = false } = parseOptions;\n\n\tlet targetParam: GrasshopperComputeResponse['values'][0] | undefined;\n\n\tif ('byName' in options) {\n\t\ttargetParam = response.values.find((p) => p.ParamName === options.byName);\n\t} else {\n\t\ttargetParam = response.values.find((p) => {\n\t\t\tlet found = false;\n\t\t\tforEachTreeItem(p.InnerTree, (item) => {\n\t\t\t\tif (item.id === options.byId) found = true;\n\t\t\t});\n\t\t\treturn found;\n\t\t});\n\t}\n\n\tif (!targetParam) return undefined;\n\n\tconst collected: any[] = [];\n\n\tforEachTreeItem(targetParam.InnerTree, (item) => {\n\t\tif ('byId' in options && item.id !== options.byId) return;\n\t\t// Skip non-string types if stringOnly is enabled\n\t\tif (stringOnly && item.type !== SYSTEM_TYPES.STRING) return;\n\t\tconst v = extractItemValue(item.data, item.type, parseValues, rhino);\n\t\tcollected.push(v);\n\t});\n\n\tif (collected.length === 0) return undefined;\n\tif (collected.length === 1) return collected[0];\n\treturn collected;\n}\n","import { downloadFileData } from '@/features/file-handling';\nimport { FileBaseInfo, FileData } from '@/features/file-handling/types';\nimport type { MeshExtractionOptions } from '@/features/visualization/webdisplay/types';\n\nimport { GrasshopperComputeResponse } from '../types';\n\nimport {\n\textractFileData,\n\tgetValue,\n\tgetValues,\n\tGetValuesOptions,\n\tGetValuesResult,\n\tParsedContext\n} from '../io/output/response-processors';\n\n/**\n * High-level wrapper for interacting with Grasshopper Compute responses.\n *\n * This class exposes a clean, consistent API for accessing parsed values,\n * geometry, and produced files. It is designed to be the primary interface\n * when working with Grasshopper results in client applications.\n */\nexport default class GrasshopperResponseProcessor {\n\t/**\n\t * Store the compute response for reuse.\n\t */\n\tconstructor(\n\t\tprivate readonly response: GrasshopperComputeResponse,\n\t\tprivate readonly debug: boolean = false\n\t) { }\n\n\t/**\n\t * Extract all values in the response.\n\t *\n\t * @typeParam T - Expected structure of the return value. Defaults to a simple key/value map. (later cast as needed)\n\t * @param byId - If true, keys are parameter IDs; if false, keys are parameter names.\n\t * @param options - Controls parsing behavior such as Rhino geometry decoding.\n\t * @returns Parsed Grasshopper output values.\n\t *\n\t * @example\n\t * ```ts\n\t * const processor = new GrasshopperResponseProcessor(response);\n\t * const { values } = processor.getValues();\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const { values } = processor.getValues(true); // keyed by param ID\n\t * ```\n\t */\n\tpublic getValues<T = ParsedContext>(\n\t\tbyId: boolean = false,\n\t\toptions: GetValuesOptions = {}\n\t): GetValuesResult<T> {\n\t\treturn getValues<T>(this.response, byId, options);\n\t}\n\n\t/**\n\t * Retrieve a specific value using the parameter name.\n\t *\n\t * @param paramName - Human-readable parameter name from the Grasshopper definition.\n\t * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).\n\t * @returns Single parsed value, array of values, or undefined if the parameter is absent.\n\t *\n\t * @example\n\t * ```ts\n\t * const schema = processor.getValueByParamName('Schema');\n\t * ```\n\t */\n\tpublic getValueByParamName(paramName: string, options?: GetValuesOptions): any {\n\t\treturn getValue(this.response, { byName: paramName }, options);\n\t}\n\n\t/**\n\t * Retrieve a specific value using the parameter ID.\n\t *\n\t * @param paramId - Parameter GUID from the Grasshopper definition.\n\t * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).\n\t * @returns Parsed value, array of values, or undefined if not present.\n\t *\n\t * @example\n\t * ```ts\n\t * const output = processor.getValueByParamId('a4be1c1e-23f9-4c27-b942-7f3bb2c45c6f');\n\t * ```\n\t */\n\tpublic getValueByParamId(paramId: string, options?: GetValuesOptions): any {\n\t\treturn getValue(this.response, { byId: paramId }, options);\n\t}\n\n\t/**\n\t * Convert all geometry results into Three.js mesh objects.\n\t *\n\t * This uses internal helpers to decode Rhino geometry into Three.js\n\t * primitives such as meshes and lines, making them ready for rendering.\n\t *\n\t * All processing options (scaling, positioning, compression, etc.) can be customized.\n\t * The processor's debug flag is merged with options - explicit options take precedence.\n\t *\n\t * **Note:** This method dynamically imports three.js visualization modules. Ensure\n\t * three.js is installed as a peer dependency if you use this feature.\n\t *\n\t * @param options - Configuration for mesh extraction and parsing. Overrides processor's debug flag if provided.\n\t * @returns Promise resolving to an array of Three.js mesh objects.\n\t * @throws {RhinoComputeError} If three.js visualization module cannot be loaded.\n\t *\n\t * @example\n\t * ```ts\n\t * const meshes = await processor.extractMeshesFromResponse();\n\t * scene.add(...meshes);\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const meshes = await processor.extractMeshesFromResponse({\n\t * debug: true,\n\t * allowScaling: true,\n\t * allowAutoPosition: false,\n\t * parsing: {\n\t * mergeByMaterial: false,\n\t * applyTransforms: true,\n\t * debug: true,\n\t * },\n\t * });\n\t * ```\n\t */\n\tpublic async extractMeshesFromResponse(options?: MeshExtractionOptions) {\n\t\tconst mergedOptions: MeshExtractionOptions = {\n\t\t\tdebug: this.debug,\n\t\t\t...options\n\t\t};\n\n\t\t// Dynamically import visualization module to avoid coupling three.js at module load time\n\t\ttry {\n\t\t\tconst { getThreeMeshesFromComputeResponse } = await import('@/features/visualization');\n\t\t\treturn getThreeMeshesFromComputeResponse(this.response, mergedOptions);\n\t\t} catch (error) {\n\t\t\t// Import here to avoid circular dependencies at top level\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\t\tconst { RhinoComputeError, ErrorCodes } = require('@/core/errors');\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'Failed to load three.js visualization module. Ensure three.js is installed as a peer dependency.',\n\t\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t\t{\n\t\t\t\t\tcontext: { originalError: error instanceof Error ? error.message : String(error) }\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Extract internal file data structures from the response.\n\t * This includes Grasshopper-generated textures, JSON exports,\n\t * CAD formats, or any file structure packaged in the response.\n\t *\n\t * @returns Raw file data entries.\n\t */\n\tprivate getFileData(): FileData[] {\n\t\treturn extractFileData(this.response);\n\t}\n\n\t/**\n\t * Download all files generated by Grasshopper, optionally including\n\t * additional user-provided files.\n\t *\n\t * Files are grouped under the specified folder name when downloaded.\n\t *\n\t * @param folderName - Name for the download directory.\n\t * @param additionalFiles - Extra files to package (single file, array, or null).\n\t *\n\t * @example\n\t * ```ts\n\t * processor.getAndDownloadFiles('gh-output');\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const extra = { name: 'notes.txt', data: 'Example' };\n\t * processor.getAndDownloadFiles('project', extra);\n\t * ```\n\t */\n\tpublic getAndDownloadFiles(\n\t\tfolderName: string,\n\t\tadditionalFiles?: FileBaseInfo[] | FileBaseInfo | null\n\t) {\n\t\tconst files = this.getFileData();\n\t\tdownloadFileData(files, folderName, additionalFiles);\n\t}\n}\n","import { getLogger } from './logger';\n\nexport function warnIfClientSide(functionName: string, suppress?: boolean): void {\n\tif (suppress) {\n\t\treturn;\n\t}\n\n\tif (typeof window !== 'undefined') {\n\t\tgetLogger().warn(\n\t\t\t`Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`\n\t\t);\n\t}\n}\n","import { fetchRhinoCompute } from '@/core';\nimport { base64ByteArray, encodeStringToBase64, isBase64 } from '@/core/utils/encoding';\nimport { warnIfClientSide } from '@/core/utils/warnings';\n\nimport {\n\tGrasshopperRequestSchema,\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tDataTree\n} from '../types';\n\n/**\n * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.\n *\n * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.\n *\n * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.\n * @param definition - The Grasshopper definition, which can be:\n * - A URL string (e.g., 'https://example.com/definition.gh')\n * - A base64-encoded string of the .gh file\n * - A plain string (will be base64-encoded)\n * - A Uint8Array of the .gh file (will be base64-encoded)\n * @param config - Compute configuration (server URL, API key, etc.)\n * @param options - Optional compute options (timeout, cachesolve, model units, tolerances, etc.).\n * @returns An object containing the compute result and extracted file data.\n *\n * @example\n * // Using a URL\n * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);\n *\n * // Using a base64 string\n * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);\n *\n * // Using binary data\n * const fileData = new Uint8Array([...]);\n * await solveGrasshopperDefinition(trees, fileData, config);\n */\nexport async function solveGrasshopperDefinition(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<GrasshopperComputeResponse> {\n\tif (config.debug) {\n\t\twarnIfClientSide('solveGrasshopperDefinition', config.suppressClientSideWarning);\n\t}\n\n\tconst args = prepareGrasshopperArgs(definition, dataTree);\n\tapplyOptionalComputeSettings(args, config);\n\n\tconst result = await fetchRhinoCompute('grasshopper', args, config);\n\n\tif ('pointer' in result) {\n\t\tdelete (result as any).pointer;\n\t}\n\n\treturn result;\n}\n\n// ============================================================================\n// Grasshopper Arguments\n// ============================================================================\n\n/**\n * Prepares Grasshopper arguments from a definition and data tree.\n * Automatically detects the definition format and converts it appropriately.\n *\n * @param definition - Can be a URL, base64 string, plain string, or Uint8Array\n * @param dataTree - Array of DataTree objects for compute inputs\n * @internal\n */\nexport function prepareGrasshopperArgs(\n\tdefinition: string | Uint8Array,\n\tdataTree: DataTree[]\n): GrasshopperRequestSchema {\n\tconst args: GrasshopperRequestSchema = {\n\t\talgo: null,\n\t\tpointer: null,\n\t\tvalues: dataTree\n\t};\n\n\tif (definition instanceof Uint8Array) {\n\t\t// Binary data → convert to base64\n\t\targs.algo = base64ByteArray(definition);\n\t} else if (definition.startsWith('http')) {\n\t\t// URL → use as pointer reference\n\t\targs.pointer = definition;\n\t} else if (isBase64(definition)) {\n\t\t// Already base64 → use as-is\n\t\targs.algo = definition;\n\t} else {\n\t\t// Plain string → encode to base64\n\t\targs.algo = encodeStringToBase64(definition);\n\t}\n\n\treturn args;\n}\n\n\n/**\n * @internal\n */\nexport function applyOptionalComputeSettings(\n\targlist: GrasshopperRequestSchema,\n\toptions: GrasshopperComputeConfig\n): void {\n\tif (options.cachesolve !== null) arglist.cachesolve = options.cachesolve;\n\tif (options.modelunits !== null) arglist.modelunits = options.modelunits;\n\tif (options.angletolerance !== null) arglist.angletolerance = options.angletolerance;\n\tif (options.absolutetolerance !== null) arglist.absolutetolerance = options.absolutetolerance;\n\tif (options.dataversion !== null) arglist.dataversion = options.dataversion;\n\tif (options.filename !== null) arglist.filename = options.filename;\n}\n","/**\n * Converts a string to camelCase.\n * @param str - The string to convert\n * @param options - Options object\n * - preserveSpaces: If true, spaces are preserved (default: false)\n */\nexport function toCamelCase(str: string, options: { preserveSpaces?: boolean } = {}): string {\n\tconst { preserveSpaces = false } = options;\n\tlet s = str.trim();\n\tif (!preserveSpaces) {\n\t\t// Remove spaces, dashes, and underscores, camelCase the next letter\n\t\ts = s\n\t\t\t.replace(/^[A-Z]/, (m) => m.toLowerCase())\n\t\t\t.replace(/[\\s-_]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t} else {\n\t\t// Only camelCase after dashes/underscores, preserve spaces\n\t\ts =\n\t\t\ts.charAt(0).toLowerCase() +\n\t\t\ts.slice(1).replace(/[-_](.)/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t}\n}\n\n/**\n * Recursively converts all object keys to camelCase.\n * @param obj - The object to process\n * @param options - Options object\n * - deep: If true, process deeply\n * - preserveSpaces: If true, spaces are preserved in keys\n * @returns The new object with camelCased keys\n * @internal\n */\nexport function camelcaseKeys(\n\tobj: unknown,\n\toptions: { deep?: boolean; preserveSpaces?: boolean } = {}\n): unknown {\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn obj;\n\t}\n\n\tif (Array.isArray(obj)) {\n\t\treturn options.deep ? obj.map((item) => camelcaseKeys(item, options)) : obj;\n\t}\n\n\treturn Object.keys(obj).reduce(\n\t\t(result, key) => {\n\t\t\tconst camelKey = toCamelCase(key, { preserveSpaces: options.preserveSpaces });\n\t\t\tconst value = (obj as any)[key];\n\t\t\t(result as any)[camelKey] = options.deep ? camelcaseKeys(value, options) : value;\n\t\t\treturn result;\n\t\t},\n\t\t{} as Record<string, unknown>\n\t);\n}\n","import { RhinoComputeError } from '@/core/errors';\nimport { ValidationErrors } from '@/core/errors/error-factory';\n\nimport { preProcessInputDefault } from './input-validators';\nimport { PARSERS } from './input-parsers';\nimport { getLogger } from '@/core/utils/logger';\n\nimport type {\n\tBaseInputType,\n\tBooleanInputType,\n\tGeometryInputType,\n\tInputParam,\n\tNumericInputType,\n\tInputParamSchema,\n\tTextInputType,\n\tValueListInputType,\n\tFileInputType\n} from '../../types';\n\n/**\n * Creates a safe default InputType when processing fails\n */\nfunction createSafeDefault(rawInput: InputParamSchema, baseInput: BaseInputType): InputParam {\n\tswitch (rawInput.paramType) {\n\t\tcase 'Number':\n\t\tcase 'Integer':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: rawInput.paramType,\n\t\t\t\tminimum: rawInput.minimum,\n\t\t\t\tmaximum: rawInput.maximum,\n\t\t\t\tatLeast: rawInput.atLeast,\n\t\t\t\tatMost: rawInput.atMost,\n\t\t\t\tdefault: rawInput.atMost > 1 ? [0] : 0\n\t\t\t} as NumericInputType;\n\t\tcase 'Boolean':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Boolean',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [false] : false\n\t\t\t} as BooleanInputType;\n\t\tcase 'Text':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Text',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [''] : ''\n\t\t\t} as TextInputType;\n\t\tcase 'ValueList':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'ValueList',\n\t\t\t\tvalues: rawInput.values ?? {},\n\t\t\t\tdefault: rawInput.atMost > 1 ? [rawInput.default] : rawInput.default\n\t\t\t} as ValueListInputType;\n\t\tcase 'File':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'File',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [null] : null\n\t\t\t} as FileInputType;\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Geometry',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [null] : null\n\t\t\t} as GeometryInputType;\n\t}\n}\n\n/**\n * Processes a raw input parameter schema and converts it into a typed InputParam object.\n *\n * @internal This is an internal processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.\n *\n * This function handles the transformation of raw input parameter data from Grasshopper into\n * a structured, type-safe format. It performs validation, type-specific processing, and error\n * handling for various parameter types including numeric, boolean, text, geometry, point, and line inputs.\n *\n * @param rawInput - The raw input parameter schema to process\n * @returns A fully processed and typed InputParam object with appropriate type-specific properties\n *\n * @throws {RhinoComputeError} When an unknown paramType is encountered\n * @throws {Error} Re-throws any non-RhinoComputeError exceptions\n *\n * @remarks\n * The function performs the following operations:\n * - Extracts base properties common to all input types\n * - Preprocesses the raw input data\n * - Applies type-specific validation and transformation\n * - Handles errors gracefully by creating safe default values for validation errors\n *\n * Supported parameter types:\n * - `Number` and `Integer`: Numeric inputs with optional min/max constraints\n * - `Boolean`: Boolean flag inputs\n * - `Text`: String inputs\n * - `Geometry`: Generic geometry objects\n * - `Point`: 3D point objects\n * - `Line`: Line objects\n *\n * @example\n * ```typescript\n * const rawInput = {\n * name: 'Length',\n * paramType: 'Number',\n * minimum: 0,\n * maximum: 100,\n * default: 50\n * };\n * const processedInput = processInput(rawInput);\n * ```\n */\nexport function processInput(rawInput: InputParamSchema): InputParam {\n\t// Create base properties outside try-catch so it's accessible in catch block\n\tconst baseInput: BaseInputType = {\n\t\tdescription: rawInput.description,\n\t\tname: rawInput.name,\n\t\tnickname: rawInput.nickname,\n\t\ttreeAccess: rawInput.treeAccess,\n\t\tgroupName: rawInput.groupName ?? '',\n\t\tid: rawInput.id\n\t};\n\n\ttry {\n\t\t// Handle default object processing\n\t\tpreProcessInputDefault(rawInput);\n\n\t\t// Get parser for this type\n\t\tconst parser = PARSERS[rawInput.paramType];\n\t\tif (!parser) {\n\t\t\tthrow ValidationErrors.unknownParamType(rawInput.paramType, rawInput.name);\n\t\t}\n\n\t\t// Apply type-specific parsing\n\t\tparser(rawInput);\n\n\t\t// Return typed result based on paramType\n\t\tswitch (rawInput.paramType) {\n\t\t\tcase 'Number':\n\t\t\tcase 'Integer':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType,\n\t\t\t\t\tminimum: rawInput.minimum,\n\t\t\t\t\tmaximum: rawInput.maximum,\n\t\t\t\t\tatLeast: rawInput.atLeast,\n\t\t\t\t\tatMost: rawInput.atMost,\n\t\t\t\t\tstepSize: rawInput.stepSize,\n\t\t\t\t\tdefault: rawInput.default as number | undefined\n\t\t\t\t} as NumericInputType;\n\t\t\tcase 'Boolean':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'Boolean',\n\t\t\t\t\tdefault: rawInput.default as boolean | undefined\n\t\t\t\t} as BooleanInputType;\n\t\t\tcase 'Text':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'Text',\n\t\t\t\t\tdefault: rawInput.default as string | undefined\n\t\t\t\t} as TextInputType;\n\t\t\tcase 'ValueList':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'ValueList',\n\t\t\t\t\tvalues: rawInput.values as Record<string, string>,\n\t\t\t\t\tdefault: rawInput.default as string | undefined\n\t\t\t\t} as ValueListInputType;\n\t\t\tcase 'Geometry':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType as 'Geometry',\n\t\t\t\t\tdefault: rawInput.default as object | string | undefined\n\t\t\t\t} as GeometryInputType;\n\t\t\tcase 'File':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType as 'File',\n\t\t\t\t\tacceptedFormats: rawInput.acceptedFormats,\n\t\t\t\t\tdefault: rawInput.default as object | string | undefined\n\t\t\t\t} as FileInputType;\n\t\t\tdefault:\n\t\t\t\t// This should be unreachable due to parser registry check above\n\t\t\t\tthrow ValidationErrors.unknownParamType(rawInput.paramType, rawInput.name);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tgetLogger().error(`Validation error for input ${rawInput.name || 'unknown'}:`, error.message);\n\t\t\t// Return a safe default based on paramType\n\t\t\treturn createSafeDefault(rawInput, baseInput);\n\t\t} else {\n\t\t\t// Transform unexpected errors\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t'VALIDATION_ERROR',\n\t\t\t\t{\n\t\t\t\t\tcontext: { paramName: rawInput.name, paramType: rawInput.paramType },\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}\n}\n\n/**\n * Processes raw Grasshopper input schemas into strongly-typed TypeScript interfaces.\n *\n * @internal This is an internal batch processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.\n *\n * Transforms each raw input parameter by:\n * - Normalizing default values (flattening data trees, parsing primitives)\n * - Applying type-specific parsing (Number, Text, Boolean, Geometry, etc.)\n * - Validating constraints (min/max, required fields)\n * - Converting to discriminated union types for type safety\n *\n * @param rawInputs - Array of raw input schemas from Rhino Compute API\n * @returns Array of processed, strongly-typed input parameters\n *\n * @remarks\n * - Empty data trees are converted to `undefined`\n * - Single values are extracted from arrays when appropriate\n * - Tree structures are preserved for list/tree access parameters\n * - Invalid inputs fall back to safe defaults with console warnings\n *\n * @example\n * ```typescript\n * const rawInputs = [\n * { paramType: 'Number', name: 'radius', minimum: 0, default: 10 },\n * { paramType: 'Text', name: 'label', default: 'Hello' }\n * ];\n *\n * const processed = processInputs(rawInputs);\n * // Result: [\n * // { paramType: 'Number', name: 'radius', minimum: 0, default: 10, ... },\n * // { paramType: 'Text', name: 'label', default: 'Hello', ... }\n * // ]\n *\n * // Now type-safe:\n * if (processed[0].paramType === 'Number') {\n * console.log(processed[0].minimum); // TypeScript knows this exists\n * }\n * ```\n *\n * @see {@link processInput} for individual input processing logic\n * @see {@link preProcessRawInput} for default value normalization\n */\nexport function processInputs(rawInputs: InputParamSchema[]): InputParam[] {\n\treturn rawInputs.map((rawInput) => processInput(rawInput));\n}\n","import { RhinoComputeError } from './base';\nimport { ErrorCodes } from './error-codes';\n\n/**\n * Factory functions for creating consistent error instances across the codebase.\n * Standardizes error creation patterns and reduces duplication.\n *\n * @internal This is an internal error factory module.\n */\n\nexport interface ValidationErrorOptions {\n\tinputName?: string;\n\tparamType?: string;\n\treceivedValue?: unknown;\n\treason?: string;\n}\n\nexport interface ErrorOptions {\n\tcontext?: Record<string, unknown>;\n\tstatusCode?: number;\n\toriginalError?: Error;\n}\n\n/**\n * Validation error factory - creates standardized validation errors\n */\nexport const ValidationErrors = {\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tinvalid: (inputName: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...options?.context },\n\t\t\t...options\n\t\t}),\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tmissingValues: (inputName: string, expectedType?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedType, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid boolean value\n\t */\n\tinvalidBoolean: (value: unknown, inputName?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid boolean value: ${value}${inputName ? ` in input \"${inputName}\"` : ''}`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\treceivedValue: value,\n\t\t\t\t\tinputName,\n\t\t\t\t\texpectedValues: ['true', 'false'],\n\t\t\t\t\t...options?.context\n\t\t\t\t},\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tinvalidDefault: (\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\toptions?: ErrorOptions\n\t) =>\n\t\tnew 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{\n\t\t\t\tcontext: { inputName, defaultValue, availableValues, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tunknownParamType: (paramType: string, paramName?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...options?.context },\n\t\t\t...options\n\t\t}),\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tinvalidStructure: (inputName: string, expectedStructure: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedStructure, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Input processing error factory\n */\nexport const InputErrors = {\n\t/**\n\t * Create an error for failed input parsing\n\t */\n\tparseError: (inputName: string, inputType: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Failed to parse ${inputType} input \"${inputName}\": ${reason}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, inputType, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tinvalidStructure: (inputName: string, expectedStructure: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedStructure, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Data transformation error factory\n */\nexport const DataErrors = {\n\t/**\n\t * Create an error for failed data transformation\n\t */\n\ttransformError: (dataType: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Data transformation error for ${dataType}: ${reason}`,\n\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { dataType, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid data type\n\t */\n\tinvalidType: (expectedType: string, receivedType: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid data type: expected ${expectedType}, received ${receivedType}`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { expectedType, receivedType, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Configuration error factory\n */\nexport const ConfigErrors = {\n\t/**\n\t * Create an error for invalid configuration\n\t */\n\tinvalid: (configName: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid configuration \"${configName}\": ${reason}`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{\n\t\t\t\tcontext: { configName, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for missing required config property\n\t */\n\tmissingRequired: (configName: string, propertyName: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Configuration \"${configName}\" is missing required property \"${propertyName}\"`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{\n\t\t\t\tcontext: { configName, propertyName, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-PNG3L5TM.cjs","../src/features/grasshopper/client/grasshopper-client.ts","../src/features/grasshopper/io/output/rhino-decoder.ts","../src/features/grasshopper/io/output/response-processors.ts","../src/features/grasshopper/client/grasshopper-response-processor.ts","../src/core/utils/warnings.ts","../src/features/grasshopper/compute/solve.ts","../src/core/utils/camel-case.ts","../src/features/grasshopper/io/input/input-processors.ts","../src/core/errors/error-factory.ts"],"names":["init_errors","init_base","init_logger","GrasshopperClient","_GrasshopperClient","config","__publicField","ComputeServerStats","client","RhinoComputeError","ErrorCodes","definition","fetchParsedDefinitionIO","fetchDefinitionIO","dataTree","result","solveGrasshopperDefinition","error","getLogger","decoderRegistry","registerDecoder","typeName","decoder","rhino","data","d","findDecoder","rhinoType","key","dec","extractPayload","parsedData","decodeRhinoGeometry","payload","SYSTEM_TYPES","EXCLUDED_TYPES","RHINO_GEOMETRY_PREFIX","FILE_DATA_TYPE","isExcludedType","type","t","tryDecodeJSON","value","trimmed","first","decodeBySystemType","raw","extractItemValue","parseValues","forEachTreeItem","tree","handler","list","item","getValues","response","byId","options","stringOnly","param","extractFileData","output","parsed","getValue","parseOptions","targetParam","p","found","collected","v","GrasshopperResponseProcessor","debug","paramName","paramId","mergedOptions","getThreeMeshesFromComputeResponse","folderName","additionalFiles","files","downloadFileData","warnIfClientSide","functionName","suppress","args","prepareGrasshopperArgs","applyOptionalComputeSettings","fetchRhinoCompute","base64ByteArray","isBase64","encodeStringToBase64","arglist","toCamelCase","str","preserveSpaces","s","_","c","m","camelcaseKeys","obj","camelKey","init_error_codes","ValidationErrors","inputName","reason"],"mappings":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A,CCAAC,iCAAAA,CAAAA,CACAoG,iCAAAA,CAAAA,CAyBO,IAAMC,CAAAA,CAAmB,CAI/B,OAAA,CAAS,CAACC,CAAAA,CAAmBC,CAAAA,CAAgB/C,CAAAA,CAAAA,EAC5C,IAAIhD,wBAAAA,CAAkB,CAAA,OAAA,EAAU8F,CAAS,CAAA,GAAA,EAAMC,CAAM,CAAA,CAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-PNG3L5TM.cjs","sourcesContent":[null,"import { ErrorCodes } from '@/core/errors';\nimport { RhinoComputeError } from '@/core/errors/base';\nimport { getLogger } from '@/core/utils/logger';\nimport ComputeServerStats from '@/core/server/compute-server-stats';\nimport { ComputeConfig } from '@/core/types';\n\nimport { fetchDefinitionIO, fetchParsedDefinitionIO, solveGrasshopperDefinition } from '..';\nimport { GrasshopperComputeConfig, GrasshopperComputeResponse, DataTree } from '../types';\n\n/**\n * GrasshopperClient provides a simple API for interacting with a Rhino Compute server and grasshopper.\n *\n * @public This is the recommended high-level API for Rhino Compute operations.\n *\n * **Security Warning:**\n * Using this client in a browser environment exposes your server URL and API key to users.\n * For production, use this library server-side or proxy requests through your own backend.\n *\n * @example\n * ```typescript\n * const client = await GrasshopperClient.create({\n * serverUrl: 'http://localhost:6500',\n * apiKey: 'your-api-key'\n * });\n *\n * try {\n * const result = await client.solve(definitionUrl, { x: 1, y: 2 });\n * } finally {\n * await client.dispose(); // Clean up resources\n * }\n * ```\n */\nexport default class GrasshopperClient {\n\tprivate readonly config: GrasshopperComputeConfig;\n\tpublic readonly serverStats: ComputeServerStats;\n\tprivate disposed = false;\n\n\tprivate constructor(config: GrasshopperComputeConfig) {\n\t\tthis.config = this.normalizeComputeConfig(config);\n\t\tthis.serverStats = new ComputeServerStats(this.config.serverUrl, this.config.apiKey);\n\t}\n\n\t/**\n\t * Creates and initializes a GrasshopperClient with server validation.\n\t *\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tstatic async create(config: GrasshopperComputeConfig): Promise<GrasshopperClient> {\n\t\tconst client = new GrasshopperClient(config);\n\n\t\t// Check server is online before returning\n\t\tif (!(await client.serverStats.isServerOnline())) {\n\t\t\tthrow new RhinoComputeError('Rhino Compute server is not online', ErrorCodes.NETWORK_ERROR, {\n\t\t\t\tcontext: { serverUrl: client.config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\treturn client;\n\t}\n\n\t/**\n\t * Gets the client's configuration.\n\t * Useful for passing to lower-level functions.\n\t */\n\tpublic getConfig(): GrasshopperComputeConfig {\n\t\tthis.ensureNotDisposed();\n\t\treturn { ...this.config };\n\t}\n\n\t/**\n\t * Get input/output parameters of a Grasshopper definition.\n\t */\n\tpublic async getIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchParsedDefinitionIO(definition, this.config);\n\t}\n\n\tpublic async getRawIO(definition: string | Uint8Array) {\n\t\tthis.ensureNotDisposed();\n\t\treturn fetchDefinitionIO(definition, this.config);\n\t}\n\n\t/**\n\t * Run a compute job with a Grasshopper definition.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_INPUT if definition is empty\n\t * @throws {RhinoComputeError} with code NETWORK_ERROR if server is offline\n\t * @throws {RhinoComputeError} with code COMPUTATION_ERROR if computation fails\n\t */\n\tpublic async solve(\n\t\tdefinition: string | Uint8Array,\n\t\tdataTree: DataTree[]\n\t): Promise<GrasshopperComputeResponse> {\n\t\tthis.ensureNotDisposed();\n\n\t\ttry {\n\t\t\t// Validate inputs\n\t\t\tif (typeof definition === 'string' && !definition?.trim()) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Definition URL/content is required',\n\t\t\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: { receivedUrl: definition }\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} else if (definition instanceof Uint8Array && definition.length === 0) {\n\t\t\t\tthrow new RhinoComputeError('Definition content is empty', ErrorCodes.INVALID_INPUT);\n\t\t\t}\n\n\t\t\t// Check server\n\t\t\tif (!(await this.serverStats.isServerOnline())) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t'Rhino Compute server is not online',\n\t\t\t\t\tErrorCodes.NETWORK_ERROR,\n\t\t\t\t\t{ context: { serverUrl: this.config.serverUrl } }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Run computation\n\t\t\tconst result = await solveGrasshopperDefinition(dataTree, definition, this.config);\n\n\t\t\t// Check for errors\n\t\t\tif (result && typeof result === 'object' && 'message' in result && !('fileData' in result)) {\n\t\t\t\tthrow new RhinoComputeError(\n\t\t\t\t\t(result as { message: string }).message || 'Computation failed',\n\t\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontext: {\n\t\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (this.config.debug) {\n\t\t\t\tgetLogger().error('Compute failed:', error);\n\t\t\t}\n\n\t\t\tif (error instanceof RhinoComputeError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t\t{\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\tdefinition:\n\t\t\t\t\t\t\ttypeof definition === 'string' && definition.length < 200\n\t\t\t\t\t\t\t\t? definition\n\t\t\t\t\t\t\t\t: '...content...',\n\t\t\t\t\t\tinputs: dataTree\n\t\t\t\t\t},\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}\n\n\t/**\n\t * Disposes of client resources.\n\t * Call this when you're done using the client.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (this.disposed) return;\n\n\t\tthis.disposed = true;\n\n\t\t// If serverStats has a dispose method, call it\n\t\tif ('dispose' in this.serverStats && typeof this.serverStats.dispose === 'function') {\n\t\t\tawait this.serverStats.dispose();\n\t\t}\n\n\t\t// Clear any cached data or connections if needed\n\t}\n\n\t/**\n\t * Ensures the client hasn't been disposed.\n\t */\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'GrasshopperClient has been disposed and cannot be used',\n\t\t\t\tErrorCodes.INVALID_STATE\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validates and normalizes a compute configuration.\n\t *\n\t * @throws {RhinoComputeError} with code INVALID_CONFIG if configuration is invalid\n\t */\n\tprivate normalizeComputeConfig<T extends ComputeConfig | GrasshopperComputeConfig>(config: T): T {\n\t\tif (!config.serverUrl?.trim()) {\n\t\t\tthrow new RhinoComputeError('serverUrl is required', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate URL format\n\t\ttry {\n\t\t\tnew URL(config.serverUrl);\n\t\t} catch {\n\t\t\tthrow new RhinoComputeError('serverUrl must be a valid URL', ErrorCodes.INVALID_CONFIG, {\n\t\t\t\tcontext: { receivedServerUrl: config.serverUrl }\n\t\t\t});\n\t\t}\n\n\t\t// Validate that it's not the default public endpoint\n\t\tif (config.serverUrl === '' || config.serverUrl === 'https://compute.rhino3d.com/') {\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'serverUrl must be set to your Compute server URL. The default public endpoint is not allowed.',\n\t\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t\t{ context: { receivedServerUrl: config.serverUrl } }\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\t...config,\n\t\t\tserverUrl: config.serverUrl.replace(/\\/+$/, ''), // Remove trailing slashes\n\t\t\tapiKey: config.apiKey,\n\t\t\tauthToken: config.authToken,\n\t\t\tdebug: config.debug ?? false,\n\t\t\tsuppressClientSideWarning: config.suppressClientSideWarning\n\t\t} as T;\n\t}\n}\n","import type { RhinoModule } from 'rhino3dm';\nimport { getLogger } from '@/core';\n\n// -----------------------------------------------------------------------------\n// Decoder Types\n// -----------------------------------------------------------------------------\n\ntype RhinoDecoder = (rhino: RhinoModule, data: unknown) => unknown;\n\nconst decoderRegistry = new Map<string, RhinoDecoder>();\n\n// -----------------------------------------------------------------------------\n// Registration\n// -----------------------------------------------------------------------------\n\nexport function registerDecoder(typeName: string, decoder: RhinoDecoder): void {\n\tdecoderRegistry.set(typeName, decoder);\n}\n\nregisterDecoder('Rhino.Geometry.Point3d', (rhino, data) => {\n\tconst d = data as any;\n\tif (!d || typeof d.X !== 'number') return null;\n\treturn new rhino.Point([d.X, d.Y, d.Z]);\n});\n\nregisterDecoder('Rhino.Geometry.Line', (rhino, data) => {\n\tconst d = data as any;\n\tif (!d || !d.From || !d.To) return null;\n\treturn new rhino.Line([d.From.X, d.From.Y, d.From.Z], [d.To.X, d.To.Y, d.To.Z]);\n});\n\n// -----------------------------------------------------------------------------\n// Utility Functions\n// -----------------------------------------------------------------------------\n\nfunction findDecoder(rhinoType: string): RhinoDecoder | undefined {\n\tif (decoderRegistry.has(rhinoType)) return decoderRegistry.get(rhinoType);\n\tfor (const [key, dec] of decoderRegistry) {\n\t\tif (rhinoType.startsWith(key)) return dec;\n\t}\n\treturn undefined;\n}\n\nfunction extractPayload(parsedData: any): any {\n\tif (!parsedData || typeof parsedData !== 'object') return null;\n\treturn (parsedData as any).data ?? (parsedData as any).value ?? null;\n}\n\n// -----------------------------------------------------------------------------\n// Geometry Decoding\n// -----------------------------------------------------------------------------\n\nexport function decodeRhinoGeometry(\n\tparsedData: unknown,\n\trhinoType: string,\n\trhino: RhinoModule\n): unknown {\n\tconst decoder = findDecoder(rhinoType);\n\tif (decoder) {\n\t\ttry {\n\t\t\treturn decoder(rhino, parsedData);\n\t\t} catch (error) {\n\t\t\tgetLogger().warn(`Failed to decode Rhino type ${rhinoType}:`, error);\n\t\t}\n\t}\n\n\t// Fallback using CommonObject.decode\n\ttry {\n\t\tconst payload = extractPayload(parsedData);\n\t\tif (payload) return rhino.CommonObject.decode(payload);\n\t} catch (error) {\n\t\tgetLogger().warn(`Failed to decode ${rhinoType} with CommonObject:`, error);\n\t\treturn { __decodeError: true, type: rhinoType, raw: parsedData };\n\t}\n\n\treturn parsedData;\n}\n\n// -----------------------------------------------------------------------------\n// Object Decoder\n// -----------------------------------------------------------------------------\n\nexport interface DecodeRhinoOptions {\n\tkeys?: string[];\n\tskipKeys?: string[];\n\tdeep?: boolean;\n}\n\nexport function decodeRhinoObject<T extends Record<string, unknown>>(\n\tobj: T,\n\trhino: RhinoModule,\n\toptions: DecodeRhinoOptions = {}\n): T {\n\tconst { keys, skipKeys, deep } = options;\n\tconst out: Record<string, unknown> = { ...obj };\n\n\tconst shouldProcessKey = (k: string) => {\n\t\tif (skipKeys?.includes(k)) return false;\n\t\tif (keys && !keys.includes(k)) return false;\n\t\treturn true;\n\t};\n\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tif (!shouldProcessKey(key)) continue;\n\t\tif (!value || typeof value !== 'object') continue;\n\n\t\tconst v: any = value;\n\t\tconst maybeType = typeof v.type === 'string' ? v.type : undefined;\n\n\t\tif (maybeType) {\n\t\t\tout[key] = decodeRhinoGeometry(v, maybeType, rhino);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (deep && typeof v === 'object') {\n\t\t\tout[key] = decodeRhinoObject(v as any, rhino, options);\n\t\t}\n\t}\n\n\treturn out as T;\n}\n","import { FileData } from '../../../file-handling/types';\nimport { GrasshopperComputeResponse, DataItem } from '../../types';\nimport { decodeRhinoGeometry } from './rhino-decoder';\n\nexport interface ParsedContext {\n\t[key: string]: any;\n}\n\nexport interface GetValuesOptions {\n\tparseValues?: boolean;\n\trhino?: any;\n\t/**\n\t * If true, only include values of type System.String in the result.\n\t * Non-string types are filtered out.\n\t */\n\tstringOnly?: boolean;\n}\n\nexport interface GetValuesResult<T = ParsedContext> {\n\tvalues: T;\n}\n\n// -----------------------------------------------------------------------------\n// Constants\n// -----------------------------------------------------------------------------\n\nconst SYSTEM_TYPES = {\n\tSTRING: 'System.String',\n\tINT: 'System.Int32',\n\tDOUBLE: 'System.Double',\n\tBOOL: 'System.Boolean'\n};\n\nconst EXCLUDED_TYPES = ['WebDisplay'];\nconst RHINO_GEOMETRY_PREFIX = 'Rhino.Geometry.';\nconst FILE_DATA_TYPE = 'FileData';\n\n// -----------------------------------------------------------------------------\n// Utilities\n// -----------------------------------------------------------------------------\n\nfunction isExcludedType(type: string): boolean {\n\treturn EXCLUDED_TYPES.some((t) => type.includes(t));\n}\n\nfunction tryDecodeJSON(value: string): any {\n\tif (typeof value !== 'string') return value;\n\n\tconst trimmed = value.trim();\n\tconst looksJson = trimmed.startsWith('{') || trimmed.startsWith('[') || trimmed.startsWith('\"');\n\tif (!looksJson) return value;\n\n\ttry {\n\t\tconst first = JSON.parse(trimmed);\n\t\tif (typeof first === 'string') {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(first);\n\t\t\t} catch {\n\t\t\t\treturn first;\n\t\t\t}\n\t\t}\n\t\treturn first;\n\t} catch {\n\t\treturn value;\n\t}\n}\n\nfunction decodeBySystemType(raw: any, type: string, rhino?: any): any {\n\tswitch (type) {\n\t\tcase SYSTEM_TYPES.STRING:\n\t\t\tif (typeof raw !== 'string') return raw;\n\t\t\treturn raw.replace(/^\"(.*)\"$/, '$1');\n\n\t\tcase SYSTEM_TYPES.INT:\n\t\t\treturn Number.parseInt(raw, 10);\n\n\t\tcase SYSTEM_TYPES.DOUBLE:\n\t\t\treturn Number.parseFloat(raw);\n\n\t\tcase SYSTEM_TYPES.BOOL: {\n\t\t\tconst str = String(raw).toLowerCase();\n\t\t\treturn str === 'true';\n\t\t}\n\n\t\tdefault:\n\t\t\tif (rhino && type.startsWith(RHINO_GEOMETRY_PREFIX)) {\n\t\t\t\treturn decodeRhinoGeometry(raw, type, rhino);\n\t\t\t}\n\t\t\treturn raw;\n\t}\n}\n\n// Main extractor\nfunction extractItemValue(data: any, type: string, parseValues: boolean, rhino?: any): any {\n\tif (isExcludedType(type)) return null;\n\n\tif (typeof data !== 'string') return data;\n\n\tconst raw = parseValues ? tryDecodeJSON(data) : data;\n\treturn decodeBySystemType(raw, type, rhino);\n}\n\n// Traversal helper\nfunction forEachTreeItem(\n\ttree: GrasshopperComputeResponse['values'][0]['InnerTree'],\n\thandler: (item: DataItem) => void\n) {\n\tfor (const list of Object.values(tree)) {\n\t\tif (Array.isArray(list)) {\n\t\t\tfor (const item of list) handler(item);\n\t\t}\n\t}\n}\n\n// -----------------------------------------------------------------------------\n// Public API\n// -----------------------------------------------------------------------------\n\nexport function getValues<T = ParsedContext>(\n\tresponse: GrasshopperComputeResponse,\n\tbyId: boolean = false,\n\toptions: GetValuesOptions = {}\n): GetValuesResult<T> {\n\tconst { parseValues = true, rhino, stringOnly = false } = options;\n\tconst result: ParsedContext = {};\n\n\tfor (const param of response.values) {\n\t\tforEachTreeItem(param.InnerTree, (item) => {\n\t\t\t// Skip non-string types if stringOnly is enabled\n\t\t\tif (stringOnly && item.type !== SYSTEM_TYPES.STRING) return;\n\n\t\t\tconst key = byId ? item.id : param.ParamName;\n\t\t\tif (!key) return;\n\n\t\t\tconst value = extractItemValue(item.data, item.type, parseValues, rhino);\n\n\t\t\tif (result[key] === undefined) {\n\t\t\t\tresult[key] = value;\n\t\t\t} else if (Array.isArray(result[key])) {\n\t\t\t\tresult[key].push(value);\n\t\t\t} else {\n\t\t\t\tresult[key] = [result[key], value];\n\t\t\t}\n\t\t});\n\t}\n\n\treturn { values: result as T };\n}\n\nexport function extractFileData(response: GrasshopperComputeResponse): FileData[] {\n\tconst output: FileData[] = [];\n\n\tfor (const param of response.values) {\n\t\tforEachTreeItem(param.InnerTree, (item) => {\n\t\t\tif (!item.type.includes(FILE_DATA_TYPE)) return;\n\n\t\t\tconst parsed = tryDecodeJSON(item.data);\n\t\t\tif (parsed && parsed.FileName && parsed.FileType && parsed.Data) {\n\t\t\t\toutput.push(parsed as FileData);\n\t\t\t}\n\t\t});\n\t}\n\n\treturn output;\n}\n\nexport function getValue(\n\tresponse: GrasshopperComputeResponse,\n\toptions: { byName: string } | { byId: string },\n\tparseOptions: GetValuesOptions = {}\n): any {\n\tconst { parseValues = true, rhino, stringOnly = false } = parseOptions;\n\n\tlet targetParam: GrasshopperComputeResponse['values'][0] | undefined;\n\n\tif ('byName' in options) {\n\t\ttargetParam = response.values.find((p) => p.ParamName === options.byName);\n\t} else {\n\t\ttargetParam = response.values.find((p) => {\n\t\t\tlet found = false;\n\t\t\tforEachTreeItem(p.InnerTree, (item) => {\n\t\t\t\tif (item.id === options.byId) found = true;\n\t\t\t});\n\t\t\treturn found;\n\t\t});\n\t}\n\n\tif (!targetParam) return undefined;\n\n\tconst collected: any[] = [];\n\n\tforEachTreeItem(targetParam.InnerTree, (item) => {\n\t\tif ('byId' in options && item.id !== options.byId) return;\n\t\t// Skip non-string types if stringOnly is enabled\n\t\tif (stringOnly && item.type !== SYSTEM_TYPES.STRING) return;\n\t\tconst v = extractItemValue(item.data, item.type, parseValues, rhino);\n\t\tcollected.push(v);\n\t});\n\n\tif (collected.length === 0) return undefined;\n\tif (collected.length === 1) return collected[0];\n\treturn collected;\n}\n","import { downloadFileData } from '@/features/file-handling';\nimport { FileBaseInfo, FileData } from '@/features/file-handling/types';\nimport type { MeshExtractionOptions } from '@/features/visualization/webdisplay/types';\n\nimport { GrasshopperComputeResponse } from '../types';\n\nimport {\n\textractFileData,\n\tgetValue,\n\tgetValues,\n\tGetValuesOptions,\n\tGetValuesResult,\n\tParsedContext\n} from '../io/output/response-processors';\n\n/**\n * High-level wrapper for interacting with Grasshopper Compute responses.\n *\n * This class exposes a clean, consistent API for accessing parsed values,\n * geometry, and produced files. It is designed to be the primary interface\n * when working with Grasshopper results in client applications.\n */\nexport default class GrasshopperResponseProcessor {\n\t/**\n\t * Store the compute response for reuse.\n\t */\n\tconstructor(\n\t\tprivate readonly response: GrasshopperComputeResponse,\n\t\tprivate readonly debug: boolean = false\n\t) { }\n\n\t/**\n\t * Extract all values in the response.\n\t *\n\t * @typeParam T - Expected structure of the return value. Defaults to a simple key/value map. (later cast as needed)\n\t * @param byId - If true, keys are parameter IDs; if false, keys are parameter names.\n\t * @param options - Controls parsing behavior such as Rhino geometry decoding.\n\t * @returns Parsed Grasshopper output values.\n\t *\n\t * @example\n\t * ```ts\n\t * const processor = new GrasshopperResponseProcessor(response);\n\t * const { values } = processor.getValues();\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const { values } = processor.getValues(true); // keyed by param ID\n\t * ```\n\t */\n\tpublic getValues<T = ParsedContext>(\n\t\tbyId: boolean = false,\n\t\toptions: GetValuesOptions = {}\n\t): GetValuesResult<T> {\n\t\treturn getValues<T>(this.response, byId, options);\n\t}\n\n\t/**\n\t * Retrieve a specific value using the parameter name.\n\t *\n\t * @param paramName - Human-readable parameter name from the Grasshopper definition.\n\t * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).\n\t * @returns Single parsed value, array of values, or undefined if the parameter is absent.\n\t *\n\t * @example\n\t * ```ts\n\t * const schema = processor.getValueByParamName('Schema');\n\t * ```\n\t */\n\tpublic getValueByParamName(paramName: string, options?: GetValuesOptions): any {\n\t\treturn getValue(this.response, { byName: paramName }, options);\n\t}\n\n\t/**\n\t * Retrieve a specific value using the parameter ID.\n\t *\n\t * @param paramId - Parameter GUID from the Grasshopper definition.\n\t * @param options - Parsing configuration (e.g. disable parsing or enable Rhino).\n\t * @returns Parsed value, array of values, or undefined if not present.\n\t *\n\t * @example\n\t * ```ts\n\t * const output = processor.getValueByParamId('a4be1c1e-23f9-4c27-b942-7f3bb2c45c6f');\n\t * ```\n\t */\n\tpublic getValueByParamId(paramId: string, options?: GetValuesOptions): any {\n\t\treturn getValue(this.response, { byId: paramId }, options);\n\t}\n\n\t/**\n\t * Convert all geometry results into Three.js mesh objects.\n\t *\n\t * This uses internal helpers to decode Rhino geometry into Three.js\n\t * primitives such as meshes and lines, making them ready for rendering.\n\t *\n\t * All processing options (scaling, positioning, compression, etc.) can be customized.\n\t * The processor's debug flag is merged with options - explicit options take precedence.\n\t *\n\t * **Note:** This method dynamically imports three.js visualization modules. Ensure\n\t * three.js is installed as a peer dependency if you use this feature.\n\t *\n\t * @param options - Configuration for mesh extraction and parsing. Overrides processor's debug flag if provided.\n\t * @returns Promise resolving to an array of Three.js mesh objects.\n\t * @throws {RhinoComputeError} If three.js visualization module cannot be loaded.\n\t *\n\t * @example\n\t * ```ts\n\t * const meshes = await processor.extractMeshesFromResponse();\n\t * scene.add(...meshes);\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const meshes = await processor.extractMeshesFromResponse({\n\t * debug: true,\n\t * allowScaling: true,\n\t * allowAutoPosition: false,\n\t * parsing: {\n\t * mergeByMaterial: false,\n\t * applyTransforms: true,\n\t * debug: true,\n\t * },\n\t * });\n\t * ```\n\t */\n\tpublic async extractMeshesFromResponse(options?: MeshExtractionOptions) {\n\t\tconst mergedOptions: MeshExtractionOptions = {\n\t\t\tdebug: this.debug,\n\t\t\t...options\n\t\t};\n\n\t\t// Dynamically import visualization module to avoid coupling three.js at module load time\n\t\ttry {\n\t\t\tconst { getThreeMeshesFromComputeResponse } = await import('@/features/visualization');\n\t\t\treturn getThreeMeshesFromComputeResponse(this.response, mergedOptions);\n\t\t} catch (error) {\n\t\t\t// Import here to avoid circular dependencies at top level\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\t\tconst { RhinoComputeError, ErrorCodes } = require('@/core/errors');\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\t'Failed to load three.js visualization module. Ensure three.js is installed as a peer dependency.',\n\t\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t\t{\n\t\t\t\t\tcontext: { originalError: error instanceof Error ? error.message : String(error) }\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Extract internal file data structures from the response.\n\t * This includes Grasshopper-generated textures, JSON exports,\n\t * CAD formats, or any file structure packaged in the response.\n\t *\n\t * @returns Raw file data entries.\n\t */\n\tprivate getFileData(): FileData[] {\n\t\treturn extractFileData(this.response);\n\t}\n\n\t/**\n\t * Download all files generated by Grasshopper, optionally including\n\t * additional user-provided files.\n\t *\n\t * Files are grouped under the specified folder name when downloaded.\n\t *\n\t * @param folderName - Name for the download directory.\n\t * @param additionalFiles - Extra files to package (single file, array, or null).\n\t *\n\t * @example\n\t * ```ts\n\t * processor.getAndDownloadFiles('gh-output');\n\t * ```\n\t *\n\t * @example\n\t * ```ts\n\t * const extra = { name: 'notes.txt', data: 'Example' };\n\t * processor.getAndDownloadFiles('project', extra);\n\t * ```\n\t */\n\tpublic getAndDownloadFiles(\n\t\tfolderName: string,\n\t\tadditionalFiles?: FileBaseInfo[] | FileBaseInfo | null\n\t) {\n\t\tconst files = this.getFileData();\n\t\tdownloadFileData(files, folderName, additionalFiles);\n\t}\n}\n","import { getLogger } from './logger';\n\nexport function warnIfClientSide(functionName: string, suppress?: boolean): void {\n\tif (suppress) {\n\t\treturn;\n\t}\n\n\tif (typeof window !== 'undefined') {\n\t\tgetLogger().warn(\n\t\t\t`Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`\n\t\t);\n\t}\n}\n","import { fetchRhinoCompute } from '@/core';\nimport { base64ByteArray, encodeStringToBase64, isBase64 } from '@/core/utils/encoding';\nimport { warnIfClientSide } from '@/core/utils/warnings';\n\nimport {\n\tGrasshopperRequestSchema,\n\tGrasshopperComputeConfig,\n\tGrasshopperComputeResponse,\n\tDataTree\n} from '../types';\n\n/**\n * Runs a Rhino Compute job using the provided tree prototypes and Grasshopper definition.\n *\n * @public Use this for direct compute control. For high-level API, use `GrasshopperClient.solve()`.\n *\n * @param dataTree - An array of `DataTree` objects representing the input data for the compute job.\n * @param definition - The Grasshopper definition, which can be:\n * - A URL string (e.g., 'https://example.com/definition.gh')\n * - A base64-encoded string of the .gh file\n * - A plain string (will be base64-encoded)\n * - A Uint8Array of the .gh file (will be base64-encoded)\n * @param config - Compute configuration (server URL, API key, etc.)\n * @param options - Optional compute options (timeout, cachesolve, model units, tolerances, etc.).\n * @returns An object containing the compute result and extracted file data.\n *\n * @example\n * // Using a URL\n * await solveGrasshopperDefinition(trees, 'https://example.com/definition.gh', config);\n *\n * // Using a base64 string\n * await solveGrasshopperDefinition(trees, 'UEsDBBQAAAAIAL...', config);\n *\n * // Using binary data\n * const fileData = new Uint8Array([...]);\n * await solveGrasshopperDefinition(trees, fileData, config);\n */\nexport async function solveGrasshopperDefinition(\n\tdataTree: DataTree[],\n\tdefinition: string | Uint8Array,\n\tconfig: GrasshopperComputeConfig\n): Promise<GrasshopperComputeResponse> {\n\tif (config.debug) {\n\t\twarnIfClientSide('solveGrasshopperDefinition', config.suppressClientSideWarning);\n\t}\n\n\tconst args = prepareGrasshopperArgs(definition, dataTree);\n\tapplyOptionalComputeSettings(args, config);\n\n\tconst result = await fetchRhinoCompute('grasshopper', args, config);\n\n\tif ('pointer' in result) {\n\t\tdelete (result as any).pointer;\n\t}\n\n\treturn result;\n}\n\n// ============================================================================\n// Grasshopper Arguments\n// ============================================================================\n\n/**\n * Prepares Grasshopper arguments from a definition and data tree.\n * Automatically detects the definition format and converts it appropriately.\n *\n * @param definition - Can be a URL, base64 string, plain string, or Uint8Array\n * @param dataTree - Array of DataTree objects for compute inputs\n * @internal\n */\nexport function prepareGrasshopperArgs(\n\tdefinition: string | Uint8Array,\n\tdataTree: DataTree[]\n): GrasshopperRequestSchema {\n\tconst args: GrasshopperRequestSchema = {\n\t\talgo: null,\n\t\tpointer: null,\n\t\tvalues: dataTree\n\t};\n\n\tif (definition instanceof Uint8Array) {\n\t\t// Binary data → convert to base64\n\t\targs.algo = base64ByteArray(definition);\n\t} else if (definition.startsWith('http')) {\n\t\t// URL → use as pointer reference\n\t\targs.pointer = definition;\n\t} else if (isBase64(definition)) {\n\t\t// Already base64 → use as-is\n\t\targs.algo = definition;\n\t} else {\n\t\t// Plain string → encode to base64\n\t\targs.algo = encodeStringToBase64(definition);\n\t}\n\n\treturn args;\n}\n\n\n/**\n * @internal\n */\nexport function applyOptionalComputeSettings(\n\targlist: GrasshopperRequestSchema,\n\toptions: GrasshopperComputeConfig\n): void {\n\tif (options.cachesolve !== null) arglist.cachesolve = options.cachesolve;\n\tif (options.modelunits !== null) arglist.modelunits = options.modelunits;\n\tif (options.angletolerance !== null) arglist.angletolerance = options.angletolerance;\n\tif (options.absolutetolerance !== null) arglist.absolutetolerance = options.absolutetolerance;\n\tif (options.dataversion !== null) arglist.dataversion = options.dataversion;\n\tif (options.filename !== null) arglist.filename = options.filename;\n}\n","/**\n * Converts a string to camelCase.\n * @param str - The string to convert\n * @param options - Options object\n * - preserveSpaces: If true, spaces are preserved (default: false)\n */\nexport function toCamelCase(str: string, options: { preserveSpaces?: boolean } = {}): string {\n\tconst { preserveSpaces = false } = options;\n\tlet s = str.trim();\n\tif (!preserveSpaces) {\n\t\t// Remove spaces, dashes, and underscores, camelCase the next letter\n\t\ts = s\n\t\t\t.replace(/^[A-Z]/, (m) => m.toLowerCase())\n\t\t\t.replace(/[\\s-_]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t} else {\n\t\t// Only camelCase after dashes/underscores, preserve spaces\n\t\ts =\n\t\t\ts.charAt(0).toLowerCase() +\n\t\t\ts.slice(1).replace(/[-_](.)/g, (_, c) => (c ? c.toUpperCase() : ''));\n\t\treturn s;\n\t}\n}\n\n/**\n * Recursively converts all object keys to camelCase.\n * @param obj - The object to process\n * @param options - Options object\n * - deep: If true, process deeply\n * - preserveSpaces: If true, spaces are preserved in keys\n * @returns The new object with camelCased keys\n * @internal\n */\nexport function camelcaseKeys(\n\tobj: unknown,\n\toptions: { deep?: boolean; preserveSpaces?: boolean } = {}\n): unknown {\n\tif (!obj || typeof obj !== 'object') {\n\t\treturn obj;\n\t}\n\n\tif (Array.isArray(obj)) {\n\t\treturn options.deep ? obj.map((item) => camelcaseKeys(item, options)) : obj;\n\t}\n\n\treturn Object.keys(obj).reduce(\n\t\t(result, key) => {\n\t\t\tconst camelKey = toCamelCase(key, { preserveSpaces: options.preserveSpaces });\n\t\t\tconst value = (obj as any)[key];\n\t\t\t(result as any)[camelKey] = options.deep ? camelcaseKeys(value, options) : value;\n\t\t\treturn result;\n\t\t},\n\t\t{} as Record<string, unknown>\n\t);\n}\n","import { RhinoComputeError } from '@/core/errors';\nimport { ValidationErrors } from '@/core/errors/error-factory';\n\nimport { preProcessInputDefault } from './input-validators';\nimport { PARSERS } from './input-parsers';\nimport { getLogger } from '@/core/utils/logger';\n\nimport type {\n\tBaseInputType,\n\tBooleanInputType,\n\tGeometryInputType,\n\tInputParam,\n\tNumericInputType,\n\tInputParamSchema,\n\tTextInputType,\n\tValueListInputType,\n\tFileInputType\n} from '../../types';\n\n/**\n * Creates a safe default InputType when processing fails\n */\nfunction createSafeDefault(rawInput: InputParamSchema, baseInput: BaseInputType): InputParam {\n\tswitch (rawInput.paramType) {\n\t\tcase 'Number':\n\t\tcase 'Integer':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: rawInput.paramType,\n\t\t\t\tminimum: rawInput.minimum,\n\t\t\t\tmaximum: rawInput.maximum,\n\t\t\t\tatLeast: rawInput.atLeast,\n\t\t\t\tatMost: rawInput.atMost,\n\t\t\t\tdefault: rawInput.atMost > 1 ? [0] : 0\n\t\t\t} as NumericInputType;\n\t\tcase 'Boolean':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Boolean',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [false] : false\n\t\t\t} as BooleanInputType;\n\t\tcase 'Text':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Text',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [''] : ''\n\t\t\t} as TextInputType;\n\t\tcase 'ValueList':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'ValueList',\n\t\t\t\tvalues: rawInput.values ?? {},\n\t\t\t\tdefault: rawInput.atMost > 1 ? [rawInput.default] : rawInput.default\n\t\t\t} as ValueListInputType;\n\t\tcase 'File':\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'File',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [null] : null\n\t\t\t} as FileInputType;\n\t\tdefault:\n\t\t\treturn {\n\t\t\t\t...baseInput,\n\t\t\t\tparamType: 'Geometry',\n\t\t\t\tdefault: rawInput.atMost > 1 ? [null] : null\n\t\t\t} as GeometryInputType;\n\t}\n}\n\n/**\n * Processes a raw input parameter schema and converts it into a typed InputParam object.\n *\n * @internal This is an internal processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.\n *\n * This function handles the transformation of raw input parameter data from Grasshopper into\n * a structured, type-safe format. It performs validation, type-specific processing, and error\n * handling for various parameter types including numeric, boolean, text, geometry, point, and line inputs.\n *\n * @param rawInput - The raw input parameter schema to process\n * @returns A fully processed and typed InputParam object with appropriate type-specific properties\n *\n * @throws {RhinoComputeError} When an unknown paramType is encountered\n * @throws {Error} Re-throws any non-RhinoComputeError exceptions\n *\n * @remarks\n * The function performs the following operations:\n * - Extracts base properties common to all input types\n * - Preprocesses the raw input data\n * - Applies type-specific validation and transformation\n * - Handles errors gracefully by creating safe default values for validation errors\n *\n * Supported parameter types:\n * - `Number` and `Integer`: Numeric inputs with optional min/max constraints\n * - `Boolean`: Boolean flag inputs\n * - `Text`: String inputs\n * - `Geometry`: Generic geometry objects\n * - `Point`: 3D point objects\n * - `Line`: Line objects\n *\n * @example\n * ```typescript\n * const rawInput = {\n * name: 'Length',\n * paramType: 'Number',\n * minimum: 0,\n * maximum: 100,\n * default: 50\n * };\n * const processedInput = processInput(rawInput);\n * ```\n */\nexport function processInput(rawInput: InputParamSchema): InputParam {\n\t// Create base properties outside try-catch so it's accessible in catch block\n\tconst baseInput: BaseInputType = {\n\t\tdescription: rawInput.description,\n\t\tname: rawInput.name,\n\t\tnickname: rawInput.nickname,\n\t\ttreeAccess: rawInput.treeAccess,\n\t\tgroupName: rawInput.groupName ?? '',\n\t\tid: rawInput.id\n\t};\n\n\ttry {\n\t\t// Handle default object processing\n\t\tpreProcessInputDefault(rawInput);\n\n\t\t// Get parser for this type\n\t\tconst parser = PARSERS[rawInput.paramType];\n\t\tif (!parser) {\n\t\t\tthrow ValidationErrors.unknownParamType(rawInput.paramType, rawInput.name);\n\t\t}\n\n\t\t// Apply type-specific parsing\n\t\tparser(rawInput);\n\n\t\t// Return typed result based on paramType\n\t\tswitch (rawInput.paramType) {\n\t\t\tcase 'Number':\n\t\t\tcase 'Integer':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType,\n\t\t\t\t\tminimum: rawInput.minimum,\n\t\t\t\t\tmaximum: rawInput.maximum,\n\t\t\t\t\tatLeast: rawInput.atLeast,\n\t\t\t\t\tatMost: rawInput.atMost,\n\t\t\t\t\tstepSize: rawInput.stepSize,\n\t\t\t\t\tdefault: rawInput.default as number | undefined\n\t\t\t\t} as NumericInputType;\n\t\t\tcase 'Boolean':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'Boolean',\n\t\t\t\t\tdefault: rawInput.default as boolean | undefined\n\t\t\t\t} as BooleanInputType;\n\t\t\tcase 'Text':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'Text',\n\t\t\t\t\tdefault: rawInput.default as string | undefined\n\t\t\t\t} as TextInputType;\n\t\t\tcase 'ValueList':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: 'ValueList',\n\t\t\t\t\tvalues: rawInput.values as Record<string, string>,\n\t\t\t\t\tdefault: rawInput.default as string | undefined\n\t\t\t\t} as ValueListInputType;\n\t\t\tcase 'Geometry':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType as 'Geometry',\n\t\t\t\t\tdefault: rawInput.default as object | string | undefined\n\t\t\t\t} as GeometryInputType;\n\t\t\tcase 'File':\n\t\t\t\treturn {\n\t\t\t\t\t...baseInput,\n\t\t\t\t\tparamType: rawInput.paramType as 'File',\n\t\t\t\t\tacceptedFormats: rawInput.acceptedFormats,\n\t\t\t\t\tdefault: rawInput.default as object | string | undefined\n\t\t\t\t} as FileInputType;\n\t\t\tdefault:\n\t\t\t\t// This should be unreachable due to parser registry check above\n\t\t\t\tthrow ValidationErrors.unknownParamType(rawInput.paramType, rawInput.name);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof RhinoComputeError) {\n\t\t\tgetLogger().error(`Validation error for input ${rawInput.name || 'unknown'}:`, error.message);\n\t\t\t// Return a safe default based on paramType\n\t\t\treturn createSafeDefault(rawInput, baseInput);\n\t\t} else {\n\t\t\t// Transform unexpected errors\n\t\t\tthrow new RhinoComputeError(\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t'VALIDATION_ERROR',\n\t\t\t\t{\n\t\t\t\t\tcontext: { paramName: rawInput.name, paramType: rawInput.paramType },\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}\n}\n\n/**\n * Processes raw Grasshopper input schemas into strongly-typed TypeScript interfaces.\n *\n * @internal This is an internal batch processor. Use `fetchParsedDefinitionIO()` to get processed inputs instead.\n *\n * Transforms each raw input parameter by:\n * - Normalizing default values (flattening data trees, parsing primitives)\n * - Applying type-specific parsing (Number, Text, Boolean, Geometry, etc.)\n * - Validating constraints (min/max, required fields)\n * - Converting to discriminated union types for type safety\n *\n * @param rawInputs - Array of raw input schemas from Rhino Compute API\n * @returns Array of processed, strongly-typed input parameters\n *\n * @remarks\n * - Empty data trees are converted to `undefined`\n * - Single values are extracted from arrays when appropriate\n * - Tree structures are preserved for list/tree access parameters\n * - Invalid inputs fall back to safe defaults with console warnings\n *\n * @example\n * ```typescript\n * const rawInputs = [\n * { paramType: 'Number', name: 'radius', minimum: 0, default: 10 },\n * { paramType: 'Text', name: 'label', default: 'Hello' }\n * ];\n *\n * const processed = processInputs(rawInputs);\n * // Result: [\n * // { paramType: 'Number', name: 'radius', minimum: 0, default: 10, ... },\n * // { paramType: 'Text', name: 'label', default: 'Hello', ... }\n * // ]\n *\n * // Now type-safe:\n * if (processed[0].paramType === 'Number') {\n * console.log(processed[0].minimum); // TypeScript knows this exists\n * }\n * ```\n *\n * @see {@link processInput} for individual input processing logic\n * @see {@link preProcessRawInput} for default value normalization\n */\nexport function processInputs(rawInputs: InputParamSchema[]): InputParam[] {\n\treturn rawInputs.map((rawInput) => processInput(rawInput));\n}\n","import { RhinoComputeError } from './base';\nimport { ErrorCodes } from './error-codes';\n\n/**\n * Factory functions for creating consistent error instances across the codebase.\n * Standardizes error creation patterns and reduces duplication.\n *\n * @internal This is an internal error factory module.\n */\n\nexport interface ValidationErrorOptions {\n\tinputName?: string;\n\tparamType?: string;\n\treceivedValue?: unknown;\n\treason?: string;\n}\n\nexport interface ErrorOptions {\n\tcontext?: Record<string, unknown>;\n\tstatusCode?: number;\n\toriginalError?: Error;\n}\n\n/**\n * Validation error factory - creates standardized validation errors\n */\nexport const ValidationErrors = {\n\t/**\n\t * Create a generic validation error with custom reason\n\t */\n\tinvalid: (inputName: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(`Input \"${inputName}\": ${reason}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { inputName, reason, ...options?.context },\n\t\t\t...options\n\t\t}),\n\n\t/**\n\t * Create an error for missing/empty values\n\t */\n\tmissingValues: (inputName: string, expectedType?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Input \"${inputName}\" has no values defined${expectedType ? ` (expected ${expectedType})` : ''}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedType, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid boolean value\n\t */\n\tinvalidBoolean: (value: unknown, inputName?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid boolean value: ${value}${inputName ? ` in input \"${inputName}\"` : ''}`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\treceivedValue: value,\n\t\t\t\t\tinputName,\n\t\t\t\t\texpectedValues: ['true', 'false'],\n\t\t\t\t\t...options?.context\n\t\t\t\t},\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid default value in value list\n\t */\n\tinvalidDefault: (\n\t\tinputName: string,\n\t\tdefaultValue: unknown,\n\t\tavailableValues: unknown[],\n\t\toptions?: ErrorOptions\n\t) =>\n\t\tnew 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{\n\t\t\t\tcontext: { inputName, defaultValue, availableValues, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for unknown parameter type\n\t */\n\tunknownParamType: (paramType: string, paramName?: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(`Unknown paramType: ${paramType}`, ErrorCodes.VALIDATION_ERROR, {\n\t\t\tcontext: { receivedParamType: paramType, paramName, ...options?.context },\n\t\t\t...options\n\t\t}),\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tinvalidStructure: (inputName: string, expectedStructure: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedStructure, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Input processing error factory\n */\nexport const InputErrors = {\n\t/**\n\t * Create an error for failed input parsing\n\t */\n\tparseError: (inputName: string, inputType: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Failed to parse ${inputType} input \"${inputName}\": ${reason}`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, inputType, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid input structure\n\t */\n\tinvalidStructure: (inputName: string, expectedStructure: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid input structure for \"${inputName}\" (expected ${expectedStructure})`,\n\t\t\tErrorCodes.INVALID_INPUT,\n\t\t\t{\n\t\t\t\tcontext: { inputName, expectedStructure, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Data transformation error factory\n */\nexport const DataErrors = {\n\t/**\n\t * Create an error for failed data transformation\n\t */\n\ttransformError: (dataType: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Data transformation error for ${dataType}: ${reason}`,\n\t\t\tErrorCodes.COMPUTATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { dataType, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for invalid data type\n\t */\n\tinvalidType: (expectedType: string, receivedType: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid data type: expected ${expectedType}, received ${receivedType}`,\n\t\t\tErrorCodes.VALIDATION_ERROR,\n\t\t\t{\n\t\t\t\tcontext: { expectedType, receivedType, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n\n/**\n * Configuration error factory\n */\nexport const ConfigErrors = {\n\t/**\n\t * Create an error for invalid configuration\n\t */\n\tinvalid: (configName: string, reason: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Invalid configuration \"${configName}\": ${reason}`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{\n\t\t\t\tcontext: { configName, reason, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t),\n\n\t/**\n\t * Create an error for missing required config property\n\t */\n\tmissingRequired: (configName: string, propertyName: string, options?: ErrorOptions) =>\n\t\tnew RhinoComputeError(\n\t\t\t`Configuration \"${configName}\" is missing required property \"${propertyName}\"`,\n\t\t\tErrorCodes.INVALID_CONFIG,\n\t\t\t{\n\t\t\t\tcontext: { configName, propertyName, ...options?.context },\n\t\t\t\t...options\n\t\t\t}\n\t\t)\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/chunk-TVCJBLSW.cjs","../src/features/file-handling/handle-files.ts"],"names":["extractFilesFromComputeResponse","downloadableFiles","additionalFiles","processFiles","err","RhinoComputeError","ErrorCodes","downloadFileData","fileFoldername","processedFiles","createAndDownloadZip","dataItems","item","filePath"],"mappings":"AAAA,mZAAwC,wDAAuD,ICoBlFA,CAAAA,CAAkC,KAAA,CAC9CC,CAAAA,CACAC,CAAAA,CAAwD,IAAA,CAAA,EAC1B,CAC9B,GAAI,CACH,OAAO,MAAMC,CAAAA,CAAaF,CAAAA,CAAmBC,CAAe,CAC7D,CAAA,KAAA,CAASE,CAAAA,CAAK,CACb,MAAM,IAAIC,wBAAAA,CACT,+CAAA,CACAC,mBAAAA,CAAW,aAAA,CACX,CACC,OAAA,CAAS,CAAE,aAAA,CAAeF,EAAAA,WAAe,KAAA,CAAQA,CAAAA,CAAI,OAAA,CAAU,MAAA,CAAOA,CAAG,CAAE,C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AAA,EAAA","file":"/Users/felix/coding/selva-compute/dist/chunk-TVCJBLSW.cjs","sourcesContent":[null,"import { RhinoComputeError, ErrorCodes, getLogger } from '@/core';\nimport { decodeBase64ToBinary } from '@/core/utils/encoding';\n\nimport { FileBaseInfo, FileData, ProcessedFile } from './types';\n\n/**\n * Extracts and processes files from compute response data without downloading them.\n * Returns an array of ProcessedFile objects that can be used programmatically.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include (fetched from URLs).\n * @returns A Promise resolving to an array of ProcessedFile objects.\n * @throws Will throw an error if file processing fails.\n *\n * @example\n * const files = await extractFilesFromComputeResponse(fileData);\n * files.forEach(file => {\n * console.log(`File: ${file.fileName}, Size: ${file.content.length}`);\n * });\n */\nexport const extractFilesFromComputeResponse = async (\n\tdownloadableFiles: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<ProcessedFile[]> => {\n\ttry {\n\t\treturn await processFiles(downloadableFiles, additionalFiles);\n\t} catch (err) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to extract files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Downloads files from a compute response as a ZIP archive.\n * Packages multiple files into a single ZIP file and triggers a browser download.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).\n * @param fileFoldername - The name of the ZIP file (without extension).\n * @throws Will throw an error if the file handling or download fails.\n *\n * @example\n * await downloadDataFromComputeResponse(fileData, null, 'my-export');\n * // Downloads 'my-export.zip'\n */\nexport const downloadFileData = async (\n\tdownloadableFiles: FileData[],\n\tfileFoldername: string,\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<void> => {\n\t// Check if we're in a browser environment\n\tif (typeof document === 'undefined' || typeof Blob === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\tenvironment: typeof window !== 'undefined' ? 'browser (SSR)' : 'Node.js',\n\t\t\t\t\tdocumentAvailable: typeof document !== 'undefined',\n\t\t\t\t\tblobAvailable: typeof Blob !== 'undefined'\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\ttry {\n\t\tconst processedFiles = await processFiles(downloadableFiles, additionalFiles);\n\t\tawait createAndDownloadZip(processedFiles, fileFoldername);\n\t} catch (err) {\n\t\t// Re-throw if it's already a RhinoComputeError\n\t\tif (err instanceof RhinoComputeError) {\n\t\t\tthrow err;\n\t\t}\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to download files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Processes files from compute response data and additional files.\n * Converts base64-encoded data to binary and fetches additional files from URLs.\n *\n * @param dataItems - An array of FileData items to process.\n * @param additionalFiles - Optional additional files to fetch and include.\n * @returns A Promise resolving to an array of ProcessedFile objects.\n */\nconst processFiles = async (\n\tdataItems: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null\n): Promise<ProcessedFile[]> => {\n\tconst processedFiles: ProcessedFile[] = [];\n\n\t// Process compute response files\n\tdataItems.forEach((item) => {\n\t\tlet filePath = `${item.FileName}${item.FileType}`;\n\n\t\tif (item.SubFolder && item.SubFolder.trim() !== '') {\n\t\t\tfilePath = `${item.SubFolder}/${filePath}`;\n\t\t}\n\n\t\tif (item.IsBase64Encoded === true && item.Data) {\n\t\t\tconst bites = decodeBase64ToBinary(item.Data);\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.FileName}${item.FileType}`,\n\t\t\t\tcontent: new Uint8Array(bites.buffer),\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t} else if (item.IsBase64Encoded === false && item.Data) {\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.FileName}${item.FileType}`,\n\t\t\t\tcontent: item.Data,\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t}\n\t});\n\n\tif (additionalFiles) {\n\t\tconst filesArray = Array.isArray(additionalFiles) ? additionalFiles : [additionalFiles];\n\t\tconst additionalProcessed = await Promise.all(\n\t\t\tfilesArray.map(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(file.FilePath);\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\tgetLogger().warn(`Failed to fetch additional file from URL: ${file.FilePath}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst fileBlob = await response.blob();\n\t\t\t\t\tconst arrayBuffer = await fileBlob.arrayBuffer();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tfileName: file.FileName,\n\t\t\t\t\t\tcontent: new Uint8Array(arrayBuffer),\n\t\t\t\t\t\tpath: file.FileName\n\t\t\t\t\t} as ProcessedFile;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().error(`Error fetching additional file from URL: ${file.FilePath}`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\n\t\tprocessedFiles.push(...additionalProcessed.filter((f): f is ProcessedFile => f !== null));\n\t}\n\n\treturn processedFiles;\n};\n\n/**\n * Creates a ZIP archive from processed files and triggers a browser download.\n *\n * @param files - An array of ProcessedFile objects to include in the ZIP.\n * @param zipName - The name of the ZIP file (without extension).\n * @returns A Promise that resolves when the ZIP is generated and download is triggered.\n */\nasync function createAndDownloadZip(files: ProcessedFile[], zipName: string): Promise<void> {\n\tconst { zipSync, strToU8 } = await import('fflate');\n\n\t// Convert files to fflate format\n\tconst zipData: Record<string, Uint8Array> = {};\n\tfiles.forEach((file) => {\n\t\tzipData[file.path] = typeof file.content === 'string' ? strToU8(file.content) : file.content;\n\t});\n\n\tconst zipped = zipSync(zipData, { level: 6 });\n\n\tconst blob = new Blob([zipped as BlobPart], { type: 'application/zip' });\n\tsaveFile(blob, `${zipName}.zip`);\n}\n\n/**\n * Saves a Blob object as a file in the user's browser.\n *\n * @param blob - The Blob object representing the file content.\n * @param filename - The name to give the downloaded file (including extension).\n * @throws {RhinoComputeError} If not running in a browser environment.\n */\nfunction saveFile(blob: Blob, filename: string) {\n\tif (typeof document === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'saveFile requires a browser environment with DOM API access.',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: { function: 'saveFile', requiredAPI: 'document' }\n\t\t\t}\n\t\t);\n\t}\n\n\tconst a = document.createElement('a');\n\ta.href = URL.createObjectURL(blob);\n\ta.download = filename;\n\ta.click();\n\tURL.revokeObjectURL(a.href);\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/chunk-TVCJBLSW.cjs","../src/features/file-handling/handle-files.ts"],"names":["extractFilesFromComputeResponse","downloadableFiles","additionalFiles","processFiles","err","RhinoComputeError","ErrorCodes","downloadFileData","fileFoldername","processedFiles","createAndDownloadZip","dataItems","item","filePath"],"mappings":"AAAA,mZAAwC,wDAAuD,ICoBlFA,CAAAA,CAAkC,KAAA,CAC9CC,CAAAA,CACAC,CAAAA,CAAwD,IAAA,CAAA,EAC1B,CAC9B,GAAI,CACH,OAAO,MAAMC,CAAAA,CAAaF,CAAAA,CAAmBC,CAAe,CAC7D,CAAA,KAAA,CAASE,CAAAA,CAAK,CACb,MAAM,IAAIC,wBAAAA,CACT,+CAAA,CACAC,mBAAAA,CAAW,aAAA,CACX,CACC,OAAA,CAAS,CAAE,aAAA,CAAeF,EAAAA,WAA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CAAAA,CAAU,OAAA,CAASC,CAAAA,EAAS,CAC3B,IAAIC,CAAAA,CAAW,CAAA,EAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/chunk-TVCJBLSW.cjs","sourcesContent":[null,"import { RhinoComputeError, ErrorCodes, getLogger } from '@/core';\nimport { decodeBase64ToBinary } from '@/core/utils/encoding';\n\nimport { FileBaseInfo, FileData, ProcessedFile } from './types';\n\n/**\n * Extracts and processes files from compute response data without downloading them.\n * Returns an array of ProcessedFile objects that can be used programmatically.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include (fetched from URLs).\n * @returns A Promise resolving to an array of ProcessedFile objects.\n * @throws Will throw an error if file processing fails.\n *\n * @example\n * const files = await extractFilesFromComputeResponse(fileData);\n * files.forEach(file => {\n * console.log(`File: ${file.fileName}, Size: ${file.content.length}`);\n * });\n */\nexport const extractFilesFromComputeResponse = async (\n\tdownloadableFiles: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<ProcessedFile[]> => {\n\ttry {\n\t\treturn await processFiles(downloadableFiles, additionalFiles);\n\t} catch (err) {\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to extract files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Downloads files from a compute response as a ZIP archive.\n * Packages multiple files into a single ZIP file and triggers a browser download.\n *\n * @param downloadableFiles - An array of FileData items from the compute response.\n * @param additionalFiles - Optional additional files to include in the ZIP (fetched from URLs).\n * @param fileFoldername - The name of the ZIP file (without extension).\n * @throws Will throw an error if the file handling or download fails.\n *\n * @example\n * await downloadDataFromComputeResponse(fileData, null, 'my-export');\n * // Downloads 'my-export.zip'\n */\nexport const downloadFileData = async (\n\tdownloadableFiles: FileData[],\n\tfileFoldername: string,\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null = null\n): Promise<void> => {\n\t// Check if we're in a browser environment\n\tif (typeof document === 'undefined' || typeof Blob === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'File download functionality is only available in browser environments. This function requires the DOM API (document, Blob).',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: {\n\t\t\t\t\tenvironment: typeof window !== 'undefined' ? 'browser (SSR)' : 'Node.js',\n\t\t\t\t\tdocumentAvailable: typeof document !== 'undefined',\n\t\t\t\t\tblobAvailable: typeof Blob !== 'undefined'\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\ttry {\n\t\tconst processedFiles = await processFiles(downloadableFiles, additionalFiles);\n\t\tawait createAndDownloadZip(processedFiles, fileFoldername);\n\t} catch (err) {\n\t\t// Re-throw if it's already a RhinoComputeError\n\t\tif (err instanceof RhinoComputeError) {\n\t\t\tthrow err;\n\t\t}\n\t\tthrow new RhinoComputeError(\n\t\t\t'Failed to download files from compute response',\n\t\t\tErrorCodes.INVALID_STATE,\n\t\t\t{\n\t\t\t\tcontext: { originalError: err instanceof Error ? err.message : String(err) },\n\t\t\t\toriginalError: err instanceof Error ? err : undefined\n\t\t\t}\n\t\t);\n\t}\n};\n\n/**\n * Processes files from compute response data and additional files.\n * Converts base64-encoded data to binary and fetches additional files from URLs.\n *\n * @param dataItems - An array of FileData items to process.\n * @param additionalFiles - Optional additional files to fetch and include.\n * @returns A Promise resolving to an array of ProcessedFile objects.\n */\nconst processFiles = async (\n\tdataItems: FileData[],\n\tadditionalFiles: FileBaseInfo[] | FileBaseInfo | null\n): Promise<ProcessedFile[]> => {\n\tconst processedFiles: ProcessedFile[] = [];\n\n\t// Process compute response files\n\tdataItems.forEach((item) => {\n\t\tlet filePath = `${item.FileName}${item.FileType}`;\n\n\t\tif (item.SubFolder && item.SubFolder.trim() !== '') {\n\t\t\tfilePath = `${item.SubFolder}/${filePath}`;\n\t\t}\n\n\t\tif (item.IsBase64Encoded === true && item.Data) {\n\t\t\tconst bites = decodeBase64ToBinary(item.Data);\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.FileName}${item.FileType}`,\n\t\t\t\tcontent: new Uint8Array(bites.buffer),\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t} else if (item.IsBase64Encoded === false && item.Data) {\n\t\t\tprocessedFiles.push({\n\t\t\t\tfileName: `${item.FileName}${item.FileType}`,\n\t\t\t\tcontent: item.Data,\n\t\t\t\tpath: filePath\n\t\t\t});\n\t\t}\n\t});\n\n\tif (additionalFiles) {\n\t\tconst filesArray = Array.isArray(additionalFiles) ? additionalFiles : [additionalFiles];\n\t\tconst additionalProcessed = await Promise.all(\n\t\t\tfilesArray.map(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(file.FilePath);\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\tgetLogger().warn(`Failed to fetch additional file from URL: ${file.FilePath}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst fileBlob = await response.blob();\n\t\t\t\t\tconst arrayBuffer = await fileBlob.arrayBuffer();\n\t\t\t\t\treturn {\n\t\t\t\t\t\tfileName: file.FileName,\n\t\t\t\t\t\tcontent: new Uint8Array(arrayBuffer),\n\t\t\t\t\t\tpath: file.FileName\n\t\t\t\t\t} as ProcessedFile;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgetLogger().error(`Error fetching additional file from URL: ${file.FilePath}`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t})\n\t\t);\n\n\t\tprocessedFiles.push(...additionalProcessed.filter((f): f is ProcessedFile => f !== null));\n\t}\n\n\treturn processedFiles;\n};\n\n/**\n * Creates a ZIP archive from processed files and triggers a browser download.\n *\n * @param files - An array of ProcessedFile objects to include in the ZIP.\n * @param zipName - The name of the ZIP file (without extension).\n * @returns A Promise that resolves when the ZIP is generated and download is triggered.\n */\nasync function createAndDownloadZip(files: ProcessedFile[], zipName: string): Promise<void> {\n\tconst { zipSync, strToU8 } = await import('fflate');\n\n\t// Convert files to fflate format\n\tconst zipData: Record<string, Uint8Array> = {};\n\tfiles.forEach((file) => {\n\t\tzipData[file.path] = typeof file.content === 'string' ? strToU8(file.content) : file.content;\n\t});\n\n\tconst zipped = zipSync(zipData, { level: 6 });\n\n\tconst blob = new Blob([zipped as BlobPart], { type: 'application/zip' });\n\tsaveFile(blob, `${zipName}.zip`);\n}\n\n/**\n * Saves a Blob object as a file in the user's browser.\n *\n * @param blob - The Blob object representing the file content.\n * @param filename - The name to give the downloaded file (including extension).\n * @throws {RhinoComputeError} If not running in a browser environment.\n */\nfunction saveFile(blob: Blob, filename: string) {\n\tif (typeof document === 'undefined') {\n\t\tthrow new RhinoComputeError(\n\t\t\t'saveFile requires a browser environment with DOM API access.',\n\t\t\tErrorCodes.BROWSER_ONLY,\n\t\t\t{\n\t\t\t\tcontext: { function: 'saveFile', requiredAPI: 'document' }\n\t\t\t}\n\t\t);\n\t}\n\n\tconst a = document.createElement('a');\n\ta.href = URL.createObjectURL(blob);\n\ta.download = filename;\n\ta.click();\n\tURL.revokeObjectURL(a.href);\n}\n"]}
package/dist/core.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/core.cjs"],"names":[],"mappings":"AAAA,iIAAkF,iUAAoJ","file":"/Users/felix/coding/selva-compute/dist/core.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/core.cjs"],"names":[],"mappings":"AAAA,iIAAkF,iUAAoJ","file":"/home/runner/work/selva-compute/selva-compute/dist/core.cjs"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/files.cjs"],"names":[],"mappings":"AAAA,iIAAqC,gCAA6B,gCAA6B,8GAAmE","file":"/Users/felix/coding/selva-compute/dist/files.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/files.cjs"],"names":[],"mappings":"AAAA,iIAAqC,gCAA6B,gCAA6B,8GAAmE","file":"/home/runner/work/selva-compute/selva-compute/dist/files.cjs"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/grasshopper.cjs"],"names":[],"mappings":"AAAA,iIAAyF,gCAA6B,gCAA6B,wDAAyC,mcAAkO","file":"/Users/felix/coding/selva-compute/dist/grasshopper.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/grasshopper.cjs"],"names":[],"mappings":"AAAA,iIAAyF,gCAA6B,gCAA6B,wDAAyC,mcAAkO","file":"/home/runner/work/selva-compute/selva-compute/dist/grasshopper.cjs"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAAyF,wDAAsC,gCAA6B,wDAAmF,m0BAAkZ","file":"/Users/felix/coding/selva-compute/dist/index.cjs"}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAAyF,wDAAsC,gCAA6B,wDAAmF,m0BAAkZ","file":"/home/runner/work/selva-compute/selva-compute/dist/index.cjs"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/felix/coding/selva-compute/dist/visualization.cjs","../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts"],"names":["defaultUp","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","resize","disposeResize","setupResponsiveResize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","scale","defaults","child","bgColor","animationId","parent","resizeTimeout","resizeObserver","getSize","handleResize","width","height","RGBELoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","clickedObject","clonedMaterial","handleKeydown","OrbitControls","target","updateScene","meshes","initialPositionSet","clearScene","unionBoundingBox","mesh","boundingBox","parseColor","colorString","trimmed","hex"],"mappings":"AAAA,2/BAAwC,wDAAqE,kMCAtF,yEACO,kEACH,IAKrBA,CAAAA,CAAY,IAAU,CAAA,CAAA,OAAA,CAAQ,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAS9BC,CAAAA,qBAAY,QAAA,CACxBC,CAAAA,CACAC,CAAAA,CAUC,CACD,IAAMC,CAAAA,CAASC,CAAAA,CAAcF,CAAAA,EAAW,CAAC,CAAC,CAAA,CAGpCG,CAAAA,CAAQC,CAAAA,CAAYH,CAAM,CAAA,CAC1BI,CAAAA,CAASC,EAAAA,CAAaL,CAAM,CAAA,CAC5BM,CAAAA,CAAWC,EAAAA,CAAcT,CAAAA,CAAQE,CAAM,CAAA,CACvCQ,CAAAA,CAAWC,EAAAA,CAAcL,CAAAA,CAAQN,CAAAA,CAAQE,CAAM,CAAA,CAGrDU,EAAAA,CAAiBR,CAAAA,CAAOF,CAAM,CAAA,CAC9BW,EAAAA,CAAcT,CAAAA,CAAOF,CAAM,CAAA,iBAGvBA,CAAAA,qBAAO,KAAA,6BAAO,SAAA,EACjBY,EAAAA,CAASV,CAAAA,CAAOF,CAAM,CAAA,CAGvB,IAAMa,CAAAA,CAAgBb,CAAAA,CAAO,MAAA,CAAO,mBAAA,GAAwB,CAAA,CAAA,CACzDc,EAAAA,CAAmBhB,CAAAA,CAAQI,CAAAA,CAAOE,CAAAA,CAAQI,CAAAA,CAAUR,CAAM,CAAA,CAC1D,CAAE,OAAA,CAAS,CAAA,CAAA,EAAM,CAAE,CAAA,CAAG,SAAA,CAAW,CAAA,CAAA,EAAM,CAAE,CAAA,CAAG,cAAA,CAAgB,CAAA,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A,CAAKJ,CAAAA,CAAO,CAAA,CAAII,CAAAA,CAAUJ,CAAAA,CAAO,CAAA,CAAII,CAAAA,CAAW,GAAG,CAAA,CAC7FtD,CAAAA,CAAS,MAAA,CAASkD,CAAAA,CAClBlD,CAAAA,CAAS,WAAA,CAAcJ,CAAAA,CAAO,IAAA,CAAO,CAAA,CACrCI,CAAAA,CAAS,WAAA,CAAcJ,CAAAA,CAAO,GAAA,CAAM,EAAA,CAEpCI,CAAAA,CAAS,MAAA,CAAO,CACjB,CAKD,CAeO,SAAS6E,CAAAA,CAAWC,CAAAA,CAAkC,CAC5D,EAAA,CAAI,CAACA,CAAAA,EAAe,OAAOA,CAAAA,EAAgB,QAAA,CAC1C,OAAA/C,iCAAAA,CAAU,CAAE,IAAA,CAAK,CAAA,qBAAA,EAAwB+C,CAAW,CAAA,aAAA,CAAe,CAAA,CAC5D,IAAU,CAAA,CAAA,KAAA,CAAM,QAAQ,CAAA,CAGhC,IAAMC,CAAAA,CAAUD,CAAAA,CAAY,IAAA,CAAK,CAAA,CAGjC,EAAA,CAAIC,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,EAAK,kBAAA,CAAmB,IAAA,CAAKA,CAAO,CAAA,CAC7D,GAAI,CACH,IAAMC,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA","file":"/Users/felix/coding/selva-compute/dist/visualization.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { RGBELoader } from 'three/addons/loaders/RGBELoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n/**\n * Initializes a comprehensive Three.js environment with enhanced render quality and flexible configuration.\n *\n * @param canvas - The HTML canvas element to render the scene on.\n * @param options - Configuration options for the Three.js environment.\n * @returns An object containing the scene, camera, controls, renderer, and utility methods.\n */\nexport const initThree = function (\n\tcanvas: HTMLCanvasElement,\n\toptions?: ThreeInitializerOptions\n): {\n\tscene: THREE.Scene;\n\tcamera: THREE.PerspectiveCamera;\n\tcontrols: OrbitControls;\n\trenderer: THREE.WebGLRenderer;\n\tdispose: () => void;\n\tresize: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst config = applyDefaults(options || {});\n\n\t// Initialize core components\n\tconst scene = createScene(config);\n\tconst camera = createCamera(config);\n\tconst renderer = setupRenderer(canvas, config);\n\tconst controls = setupControls(camera, canvas, config);\n\n\t// Setup environment and lighting\n\tsetupEnvironment(scene, config);\n\tsetupLighting(scene, config);\n\n\t// Add floor if enabled\n\tif (config.floor?.enabled) {\n\t\taddFloor(scene, config);\n\t}\n\n\tconst eventHandlers = config.events.enableEventHandlers !== false\n\t\t? setupEventHandlers(canvas, scene, camera, controls, config)\n\t\t: { dispose: () => { }, fitToView: () => { }, clearSelection: () => { } };\n\n\t// Handle resizing\n\tconst { resize, dispose: disposeResize } = setupResponsiveResize(canvas, renderer, camera);\n\n\t// Animation loop\n\tconst { animate, dispose: disposeAnimation } = createAnimationLoop(\n\t\trenderer,\n\t\tscene,\n\t\tcamera,\n\t\tcontrols\n\t);\n\tanimate();\n\n\t// Set scene up vector\n\tconst sceneUp = config.environment?.sceneUp || defaultUp;\n\tscene.up.set(sceneUp.x, sceneUp.y, sceneUp.z);\n\n\t// Comprehensive disposal\n\tconst dispose = () => {\n\t\tdisposeAnimation(); // Stop animation loop\n\t\tdisposeResize(); // Remove resize listeners\n\t\teventHandlers.dispose(); // Remove click/keyboard listeners\n\t\tcontrols.dispose(); // Dispose controls\n\t\trenderer.dispose(); // Dispose renderer\n\n\t\t// Dispose geometries and materials\n\t\tscene.traverse((object) => {\n\t\t\tif (object instanceof THREE.Mesh) {\n\t\t\t\tobject.geometry?.dispose();\n\t\t\t\tif (Array.isArray(object.material)) {\n\t\t\t\t\tobject.material.forEach((material) => material.dispose());\n\t\t\t\t} else {\n\t\t\t\t\tobject.material?.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\n\treturn {\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\trenderer,\n\t\tdispose,\n\t\tresize,\n\t\tfitToView: eventHandlers.fitToView,\n\t\tclearSelection: eventHandlers.clearSelection\n\t};\n};\n\nfunction applyDefaults(options: ThreeInitializerOptions): Required<ThreeInitializerOptions> {\n\tconst scale = options.sceneScale || 'm';\n\n\t// Define sensible defaults for each scale\n\t// Note: All Rhino geometry is normalized to METERS (1 unit = 1 meter), sceneScale just changes the viewing perspective\n\tconst scaleDefaults = {\n\t\tmm: {\n\t\t\t// Geometry scaled UP by 1000x (mm to m conversion for better precision)\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 10,\n\t\t\tlightHeight: 20,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1000\n\t\t},\n\t\tcm: {\n\t\t\t// Geometry scaled UP by 100x (cm to m conversion)\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 100\n\t\t},\n\t\tm: {\n\t\t\t// Natural Three.js scale (1 unit = 1 meter)\n\t\t\tcameraDistance: 10,\n\t\t\tnear: 0.01,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 50,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.001,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1\n\t\t},\n\t\tinches: {\n\t\t\t// Geometry scaled UP by ~39.37x (inches to m conversion)\n\t\t\tcameraDistance: 15,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 80,\n\t\t\tlightDistance: 20,\n\t\t\tlightHeight: 40,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 80,\n\t\t\tscaleFactor: 39.37\n\t\t},\n\t\tfeet: {\n\t\t\t// Geometry scaled UP by ~3.28x (feet to m conversion)\n\t\t\tcameraDistance: 8,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 40,\n\t\t\tlightDistance: 15,\n\t\t\tlightHeight: 30,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 60,\n\t\t\tscaleFactor: 3.28084\n\t\t}\n\t};\n\n\tconst defaults = scaleDefaults[scale];\n\n\treturn {\n\t\tsceneScale: scale,\n\t\tcamera: {\n\t\t\tposition:\n\t\t\t\toptions.camera?.position ||\n\t\t\t\tnew THREE.Vector3(\n\t\t\t\t\t-defaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance\n\t\t\t\t),\n\t\t\tfov: options.camera?.fov || 20,\n\t\t\tnear: options.camera?.near || defaults.near,\n\t\t\tfar: options.camera?.far || defaults.far,\n\t\t\ttarget: options.camera?.target || new THREE.Vector3(0, 0, 0)\n\t\t},\n\t\tlighting: {\n\t\t\tenableSunlight: options.lighting?.enableSunlight ?? true,\n\t\t\tsunlightIntensity: options.lighting?.sunlightIntensity || 1,\n\t\t\tsunlightPosition:\n\t\t\t\toptions.lighting?.sunlightPosition ||\n\t\t\t\tnew THREE.Vector3(defaults.lightDistance, defaults.lightHeight, defaults.lightDistance),\n\t\t\tambientLightColor: options.lighting?.ambientLightColor || new THREE.Color(0x404040),\n\t\t\tambientLightIntensity: options.lighting?.ambientLightIntensity || 1,\n\t\t\tsunlightColor: options.lighting?.sunlightColor || 0xffffff // Default to white sunlight\n\t\t},\n\t\tenvironment: {\n\t\t\thdrPath: options.environment?.hdrPath || '/baseHDR.hdr',\n\t\t\tbackgroundColor: options.environment?.backgroundColor || new THREE.Color(0xf0f0f0),\n\t\t\tenableEnvironmentLighting: options.environment?.enableEnvironmentLighting ?? true,\n\t\t\tsceneUp: options.environment?.sceneUp || defaultUp,\n\t\t\tshowEnvironment: options.environment?.showEnvironment ?? false\n\t\t},\n\t\tfloor: {\n\t\t\tenabled: options.floor?.enabled ?? false,\n\t\t\tsize: options.floor?.size || defaults.floorSize,\n\t\t\tcolor: options.floor?.color || new THREE.Color(0x808080),\n\t\t\troughness: options.floor?.roughness || 0.7,\n\t\t\tmetalness: options.floor?.metalness || 0.0,\n\t\t\treceiveShadow: options.floor?.receiveShadow ?? true\n\t\t},\n\t\trender: {\n\t\t\tenableShadows: options.render?.enableShadows ?? true,\n\t\t\tshadowMapSize: options.render?.shadowMapSize || 2048,\n\t\t\tantialias: options.render?.antialias ?? true,\n\t\t\tpixelRatio: options.render?.pixelRatio || Math.min(window.devicePixelRatio, 2),\n\t\t\ttoneMapping: options.render?.toneMapping || THREE.NeutralToneMapping,\n\t\t\ttoneMappingExposure: options.render?.toneMappingExposure || 1,\n\t\t\tpreserveDrawingBuffer: options.render?.preserveDrawingBuffer ?? false\n\t\t},\n\t\tcontrols: {\n\t\t\tenableDamping: options.controls?.enableDamping ?? false,\n\t\t\tdampingFactor: options.controls?.dampingFactor || 0.05,\n\t\t\tautoRotate: options.controls?.autoRotate ?? false,\n\t\t\tautoRotateSpeed: options.controls?.autoRotateSpeed || 0.5,\n\t\t\tenableZoom: options.controls?.enableZoom ?? true,\n\t\t\tenablePan: options.controls?.enablePan ?? true,\n\t\t\tminDistance: options.controls?.minDistance || defaults.minDistance,\n\t\t\tmaxDistance: options.controls?.maxDistance || Infinity\n\t\t},\n\t\tevents: {\n\t\t\tonBackgroundClicked: options.events?.onBackgroundClicked,\n\t\t\tonObjectSelected: options.events?.onObjectSelected,\n\t\t\tonMeshMetadataClicked: options.events?.onMeshMetadataClicked,\n\t\t\tselectionColor: options.events?.selectionColor || '#ff0000', // Default to red\n\t\t\tenableEventHandlers: options.events?.enableEventHandlers ?? true,\n\t\t\tenableKeyboardControls: options.events?.enableKeyboardControls ?? true,\n\t\t\tenableClickToFocus: options.events?.enableClickToFocus ?? true\n\t\t}\n\t};\n}\n\n/**\n * Creates and configures the scene.\n */\nfunction createScene(config: Required<ThreeInitializerOptions>): THREE.Scene {\n\tconst scene = new THREE.Scene();\n\n\t// Clear existing children except floor\n\tscene.children.forEach((child) => {\n\t\tif (child.userData.id !== 'floor') {\n\t\t\tscene.remove(child);\n\t\t}\n\t});\n\n\t// Set background color\n\tconst bgColor =\n\t\ttypeof config.environment.backgroundColor === 'string'\n\t\t\t? new THREE.Color(config.environment.backgroundColor)\n\t\t\t: config.environment.backgroundColor;\n\tscene.background = bgColor || null;\n\n\treturn scene;\n}\n\n/**\n * Creates an optimized animation loop with proper disposal.\n */\nfunction createAnimationLoop(\n\trenderer: THREE.WebGLRenderer,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls\n): { animate: () => void; dispose: () => void } {\n\tlet animationId: number | null = null;\n\n\tconst animate = function () {\n\t\tanimationId = requestAnimationFrame(animate);\n\n\t\t// Update controls if damping is enabled\n\t\tif (controls.enableDamping) {\n\t\t\tcontrols.update();\n\t\t}\n\n\t\trenderer.render(scene, camera);\n\t};\n\n\tconst dispose = () => {\n\t\tif (animationId !== null) {\n\t\t\tcancelAnimationFrame(animationId);\n\t\t\tanimationId = null;\n\t\t}\n\t};\n\n\treturn { animate, dispose };\n}\n\n/**\n * Sets up responsive resizing with improved performance and proper parent handling.\n */\nfunction setupResponsiveResize(\n\tcanvas: HTMLCanvasElement,\n\trenderer: THREE.WebGLRenderer,\n\tcamera: THREE.PerspectiveCamera\n): { resize: () => void; dispose: () => void } {\n\tconst parent = canvas.parentElement;\n\tlet resizeTimeout: NodeJS.Timeout;\n\tlet resizeObserver: ResizeObserver | null = null;\n\n\tconst getSize = () => {\n\t\tif (parent) {\n\t\t\treturn {\n\t\t\t\twidth: parent.clientWidth,\n\t\t\t\theight: parent.clientHeight\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\twidth: window.innerWidth,\n\t\t\t\theight: window.innerHeight\n\t\t\t};\n\t\t}\n\t};\n\n\tconst handleResize = () => {\n\t\tif (resizeTimeout) {\n\t\t\tclearTimeout(resizeTimeout);\n\t\t}\n\n\t\tresizeTimeout = setTimeout(() => {\n\t\t\tconst { width, height } = getSize();\n\n\t\t\t// Only update if size actually changed\n\t\t\tif (renderer.domElement.width !== width || renderer.domElement.height !== height) {\n\t\t\t\trenderer.setSize(width, height, false);\n\t\t\t\tcamera.aspect = width / height;\n\t\t\t\tcamera.updateProjectionMatrix();\n\t\t\t}\n\t\t}, 16); // ~60fps throttling\n\t};\n\n\t// Set up the appropriate resize observer\n\tif (parent && typeof ResizeObserver !== 'undefined') {\n\t\t// Use ResizeObserver for parent container\n\t\tresizeObserver = new ResizeObserver(handleResize);\n\t\tresizeObserver.observe(parent);\n\t} else {\n\t\t// Fallback to window resize for fullscreen or older browsers\n\t\twindow.addEventListener('resize', handleResize);\n\t}\n\n\tconst dispose = () => {\n\t\tif (resizeTimeout) {\n\t\t\tclearTimeout(resizeTimeout);\n\t\t}\n\t\tif (resizeObserver) {\n\t\t\tresizeObserver.disconnect();\n\t\t} else {\n\t\t\twindow.removeEventListener('resize', handleResize);\n\t\t}\n\t};\n\n\treturn { resize: handleResize, dispose };\n}\n\n/**\n * Sets up environment lighting and HDR.\n */\nfunction setupEnvironment(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tif (config.environment.enableEnvironmentLighting) {\n\t\tnew RGBELoader().load(\n\t\t\tconfig.environment.hdrPath || '/baseHDR.hdr',\n\t\t\tfunction (envMap) {\n\t\t\t\tenvMap.mapping = THREE.EquirectangularReflectionMapping;\n\t\t\t\tscene.environment = envMap;\n\t\t\t\tif (config.environment.showEnvironment) {\n\t\t\t\t\tscene.background = envMap;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfunction (error) {\n\t\t\t\tgetLogger().warn('HDR texture could not be loaded, falling back to basic lighting:', error);\n\t\t\t\t// Add basic ambient light as fallback\n\t\t\t\tconst ambientLight = new THREE.AmbientLight(0x404040, 0.4);\n\t\t\t\tscene.add(ambientLight);\n\t\t\t}\n\t\t);\n\t}\n}\n\nfunction setupLighting(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\t// Add ambient light\n\tconst ambientLight = new THREE.AmbientLight(\n\t\tconfig.lighting.ambientLightColor,\n\t\tconfig.lighting.ambientLightIntensity\n\t);\n\tscene.add(ambientLight);\n\n\t// Add directional light (sunlight)\n\tif (config.lighting.enableSunlight) {\n\t\tconst sunlight = new THREE.DirectionalLight(\n\t\t\tconfig.lighting.sunlightColor ?? 0xffffff,\n\t\t\tconfig.lighting.sunlightIntensity\n\t\t);\n\t\tconst pos = config.lighting.sunlightPosition;\n\t\tif (pos) {\n\t\t\tsunlight.position.set(pos.x, pos.y, pos.z);\n\t\t}\n\n\t\tif (config.render.enableShadows) {\n\t\t\tsunlight.castShadow = true;\n\t\t\tconst shadowSize = config.sceneScale === 'mm' ? 0.1 : config.sceneScale === 'cm' ? 10 : 100;\n\n\t\t\tsunlight.shadow.camera.left = -shadowSize;\n\t\t\tsunlight.shadow.camera.right = shadowSize;\n\t\t\tsunlight.shadow.camera.top = shadowSize;\n\t\t\tsunlight.shadow.camera.bottom = -shadowSize;\n\n\t\t\tconst shadowNear =\n\t\t\t\tconfig.sceneScale === 'mm' ? 0.001 : config.sceneScale === 'cm' ? 0.1 : 0.5;\n\n\t\t\tconst shadowFar = config.sceneScale === 'mm' ? 1 : config.sceneScale === 'cm' ? 100 : 500;\n\n\t\t\tsunlight.shadow.camera.near = shadowNear;\n\t\t\tsunlight.shadow.camera.far = shadowFar;\n\n\t\t\tsunlight.shadow.mapSize.width = config.render.shadowMapSize || 2048;\n\t\t\tsunlight.shadow.mapSize.height = config.render.shadowMapSize || 2048;\n\n\t\t\t// Improved shadow quality\n\t\t\tsunlight.shadow.bias = -0.0001;\n\t\t\tsunlight.shadow.normalBias = 0.02;\n\t\t}\n\n\t\tscene.add(sunlight);\n\t}\n}\n\n/**\n * Adds a floor to the scene with scale-aware sizing.\n */\nfunction addFloor(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst floorSize = config.floor.size;\n\tconst floorGeometry = new THREE.PlaneGeometry(floorSize, floorSize);\n\n\tconst floorColor =\n\t\ttypeof config.floor.color === 'string'\n\t\t\t? new THREE.Color(config.floor.color)\n\t\t\t: config.floor.color;\n\n\tconst floorMaterial = new THREE.MeshStandardMaterial({\n\t\tcolor: floorColor,\n\t\troughness: config.floor.roughness,\n\t\tmetalness: config.floor.metalness,\n\t\tside: THREE.DoubleSide\n\t});\n\n\tconst floor = new THREE.Mesh(floorGeometry, floorMaterial);\n\tfloor.userData.id = 'floor';\n\tfloor.name = 'floor';\n\tfloor.rotation.x = -Math.PI / 2;\n\tfloor.position.y = 0;\n\n\tif (config.floor.receiveShadow && config.render.enableShadows) {\n\t\tfloor.receiveShadow = true;\n\t}\n\n\tscene.add(floor);\n}\n\n/**\n * Creates and configures the camera with proper aspect ratio.\n */\nfunction createCamera(config: Required<ThreeInitializerOptions>): THREE.PerspectiveCamera {\n\t// Get proper aspect ratio from canvas parent or window\n\tconst canvas = document.querySelector('canvas');\n\tconst parent = canvas?.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tconst camera = new THREE.PerspectiveCamera(\n\t\tconfig.camera.fov,\n\t\twidth / height,\n\t\tconfig.camera.near,\n\t\tconfig.camera.far\n\t);\n\n\tconst pos = config.camera.position;\n\tif (pos) {\n\t\tcamera.position.set(pos.x, pos.y, pos.z);\n\t}\n\n\treturn camera;\n}\n\n/**\n * Sets up enhanced WebGL renderer with improved quality settings.\n */\nfunction setupRenderer(\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): THREE.WebGLRenderer {\n\tconst renderer = new THREE.WebGLRenderer({\n\t\tantialias: config.render.antialias,\n\t\tcanvas,\n\t\talpha: true,\n\t\tpowerPreference: 'high-performance',\n\t\tpreserveDrawingBuffer: config.render.preserveDrawingBuffer,\n\t\t// Enable logarithmic depth buffer for extreme scale ranges\n\t\t// This dramatically improves depth precision for mixed scales (mm to km)\n\t\tlogarithmicDepthBuffer: true\n\t});\n\n\t// Get proper dimensions - parent container or window\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\t// Set canvas style to fill parent if it exists\n\tif (parent) {\n\t\tcanvas.style.width = '100%';\n\t\tcanvas.style.height = '100%';\n\t\tcanvas.style.display = 'block';\n\t}\n\n\trenderer.setSize(width, height, false);\n\trenderer.setPixelRatio(config.render.pixelRatio || Math.min(window.devicePixelRatio, 2));\n\n\t// Enhanced shadow settings\n\tif (config.render.enableShadows) {\n\t\trenderer.shadowMap.enabled = true;\n\t\t// Use VSM for better quality with extreme scales\n\t\trenderer.shadowMap.type = THREE.VSMShadowMap;\n\t}\n\n\t// Improved tone mapping and color management\n\trenderer.toneMapping = config.render.toneMapping || THREE.ACESFilmicToneMapping;\n\trenderer.toneMappingExposure = config.render.toneMappingExposure || 1.0;\n\trenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\t// Additional quality settings for depth rendering\n\trenderer.sortObjects = true; // Ensure proper render order\n\n\treturn renderer;\n}\n\n// Add event handler setup function\nfunction setupEventHandlers(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tconfig: Required<ThreeInitializerOptions>\n): {\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst selectedObjects = new Set<THREE.Object3D>();\n\tconst originalMaterials = new Map<THREE.Object3D, THREE.Material | THREE.Material[]>();\n\tconst raycaster = new THREE.Raycaster();\n\tconst mouse = new THREE.Vector2();\n\tconst mouseDownPosition = new THREE.Vector2();\n\n\t// Fit scene to view\n\tconst fitToView = () => {\n\t\tconst box = new THREE.Box3();\n\n\t\t// Calculate bounding box of all visible objects (excluding floor)\n\t\tscene.traverse((object) => {\n\t\t\tif (object.visible && object.userData.id !== 'floor' && object instanceof THREE.Mesh) {\n\t\t\t\tbox.expandByObject(object);\n\t\t\t}\n\t\t});\n\n\t\tif (box.isEmpty()) {\n\t\t\tgetLogger().warn('No objects to fit to view');\n\t\t\treturn;\n\t\t}\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\n\t\t// Calculate distance needed to fit the object\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tlet distance = maxDim / (2 * Math.tan(fov / 2));\n\n\t\t// Add some padding\n\t\tdistance *= 1.5;\n\n\t\t// Position camera\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tcamera.position.copy(center.clone().add(direction.multiplyScalar(distance)));\n\n\t\t// Update controls target\n\t\tcontrols.target.copy(center);\n\t\tcontrols.update();\n\t};\n\n\t// Parse selection color\n\tconst selectionColorObj = typeof config.events.selectionColor === 'string'\n\t\t? new THREE.Color(config.events.selectionColor)\n\t\t: config.events.selectionColor instanceof THREE.Color\n\t\t\t? config.events.selectionColor\n\t\t\t: new THREE.Color('#ff0000');\n\n\t// Clear selection\n\tconst clearSelection = () => {\n\t\tselectedObjects.forEach((obj) => {\n\t\t\t// Restore original material\n\t\t\tif (obj instanceof THREE.Mesh && originalMaterials.has(obj)) {\n\t\t\t\tobj.material = originalMaterials.get(obj)!;\n\t\t\t\toriginalMaterials.delete(obj);\n\t\t\t}\n\t\t});\n\t\tselectedObjects.clear();\n\t};\n\n\tconst handleMouseDown = (event: MouseEvent) => {\n\t\tmouseDownPosition.set(event.clientX, event.clientY);\n\t};\n\n\t// Handle canvas clicks\n\tconst handleCanvasClick = (event: MouseEvent) => {\n\t\t// Ignore if mouse has moved significantly (drag)\n\t\tconst currentMousePosition = new THREE.Vector2(event.clientX, event.clientY);\n\t\tif (mouseDownPosition.distanceTo(currentMousePosition) > 5) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Calculate mouse position in normalized device coordinates\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\t// Raycast to find intersected objects\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster.intersectObjects(scene.children, true);\n\n\t\tif (intersects.length > 0) {\n\t\t\tconst clickedObject = intersects[0].object;\n\n\t\t\t// Handle object selection\n\t\t\tif (!selectedObjects.has(clickedObject)) {\n\t\t\t\tclearSelection();\n\t\t\t\tselectedObjects.add(clickedObject);\n\n\t\t\t\t// Clone material and apply selection color only to this mesh\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && clickedObject.material instanceof THREE.Material) {\n\t\t\t\t\t// Store original material\n\t\t\t\t\toriginalMaterials.set(clickedObject, clickedObject.material);\n\n\t\t\t\t\t// Clone the material so we don't affect other meshes\n\t\t\t\t\tconst clonedMaterial = clickedObject.material.clone();\n\t\t\t\t\t(clonedMaterial as any).emissive = selectionColorObj.clone();\n\t\t\t\t\tclickedObject.material = clonedMaterial;\n\t\t\t\t}\n\n\t\t\t\tconfig.events?.onObjectSelected?.(clickedObject);\n\n\t\t\t\t// Call metadata callback if the mesh has metadata\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && Object.keys(clickedObject.userData).length > 0) {\n\t\t\t\t\tconfig.events?.onMeshMetadataClicked?.(clickedObject.userData);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Background clicked\n\t\t\tclearSelection();\n\t\t\tconfig.events?.onBackgroundClicked?.({ x: mouse.x, y: mouse.y });\n\t\t}\n\t};\n\n\t// Handle keyboard events\n\tconst handleKeydown = (event: KeyboardEvent) => {\n\t\tif (!config.events?.enableKeyboardControls) return;\n\n\t\tswitch (event.key.toLowerCase()) {\n\t\t\tcase 'f':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t\tcase 'escape':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclearSelection();\n\t\t\t\tbreak;\n\t\t\tcase ' ':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\t// Add event listeners\n\tif (config.events?.enableClickToFocus) {\n\t\tcanvas.addEventListener('mousedown', handleMouseDown);\n\t\tcanvas.addEventListener('click', handleCanvasClick);\n\t}\n\n\tif (config.events?.enableKeyboardControls) {\n\t\t// Make canvas focusable\n\t\tcanvas.setAttribute('tabindex', '0');\n\t\t// Only listen for keydown when canvas has focus\n\t\tcanvas.addEventListener('keydown', handleKeydown);\n\t}\n\n\t// Disposal function\n\tconst dispose = () => {\n\t\tcanvas.removeEventListener('mousedown', handleMouseDown);\n\t\tcanvas.removeEventListener('click', handleCanvasClick);\n\t\tcanvas.removeEventListener('keydown', handleKeydown);\n\t\tclearSelection();\n\t};\n\n\treturn { dispose, fitToView, clearSelection };\n}\n\n/**\n * Sets up enhanced orbit controls with scale-aware distances.\n */\nfunction setupControls(\n\tcamera: THREE.PerspectiveCamera,\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): OrbitControls {\n\tconst controls = new OrbitControls(camera, canvas);\n\n\t// Set target\n\tconst target = config.camera.target;\n\tif (target) {\n\t\tcontrols.target.set(target.x, target.y, target.z);\n\t}\n\n\t// Configure damping\n\tcontrols.enableDamping = config.controls.enableDamping || false;\n\tcontrols.dampingFactor = config.controls.dampingFactor || 0.05;\n\n\t// Configure auto rotation\n\tcontrols.autoRotate = config.controls.autoRotate || false;\n\tcontrols.autoRotateSpeed = config.controls.autoRotateSpeed || 0.5;\n\n\t// Configure interaction limits\n\tcontrols.enableZoom = config.controls.enableZoom || true;\n\tcontrols.enablePan = config.controls.enablePan || true;\n\tcontrols.minDistance = config.controls.minDistance || 0.001;\n\tcontrols.maxDistance = config.controls.maxDistance || Infinity;\n\n\t// Smooth controls\n\tcontrols.screenSpacePanning = false;\n\tcontrols.maxPolarAngle = Math.PI;\n\n\tcontrols.update();\n\treturn controls;\n}\n","import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { getLogger } from '@/core';\n\n/**\n * Updates the scene with the given meshes and camera settings.\n * If initialPositionSet is false, it positions the camera and sets the controls target based on the bounding boxes of the meshes.\n * @param scene - The THREE.Scene object to update.\n * @param meshes - An array of THREE.Mesh objects to add to the scene.\n * @param camera - The THREE.PerspectiveCamera object to position.\n * @param controls - The OrbitControls object to update.\n * @param initialPositionSet - A boolean indicating whether the initial position of the camera and controls have been set.\n */\nexport function updateScene(\n\tscene: THREE.Scene,\n\tmeshes: THREE.Mesh[],\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tinitialPositionSet: boolean\n) {\n\tclearScene(scene);\n\n\tif (meshes.length === 0) return;\n\n\tconst unionBoundingBox = new THREE.Box3();\n\n\tmeshes.forEach((mesh) => {\n\t\tscene.add(mesh);\n\t\tconst boundingBox = new THREE.Box3().setFromObject(mesh);\n\t\tunionBoundingBox.union(boundingBox);\n\t});\n\n\t// Get the center of the union bounding box\n\tconst center = unionBoundingBox.getCenter(new THREE.Vector3());\n\tconst size = unionBoundingBox.getSize(new THREE.Vector3());\n\n\t// Calculate a distance that is slightly larger than the largest dimension of the union bounding box\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Always update camera frustum to ensure geometry is visible\n\t// This prevents clipping when geometry size changes significantly\n\tconst scaleRatio = maxDim / Math.min(size.x || 1, size.y || 1, size.z || 1);\n\n\tif (scaleRatio > 100 || maxDim > 10000) {\n\t\t// Large scale range detected - use logarithmic depth buffer approach\n\t\tcamera.near = maxDim * 0.0001; // 0.01% of max dimension\n\t\tcamera.far = maxDim * 100; // 100x max dimension\n\t} else if (maxDim > 1000) {\n\t\t// Large scene\n\t\tcamera.near = maxDim * 0.001;\n\t\tcamera.far = maxDim * 50;\n\t} else {\n\t\t// Normal scene\n\t\tcamera.near = Math.max(0.01, maxDim * 0.01);\n\t\tcamera.far = Math.max(2000, maxDim * 20);\n\t}\n\n\tcamera.updateProjectionMatrix();\n\n\t// Only reposition camera and controls on first frame\n\tif (!initialPositionSet) {\n\t\tconst distance = maxDim * 4;\n\n\t\tcamera.position.set(center.x + distance * 0.8, center.y + distance, center.z + distance * 1.2);\n\t\tcontrols.target = center;\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\n\t\tcontrols.update();\n\t} else {\n\t\t// Update control constraints to match new frustum\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\t}\n}\n\n// =========================\n// Helper functions\n// =========================\n\n/**\n * Parses a color string in multiple formats to a THREE.Color object.\n * Supported formats:\n * - Hex: \"#C7A5A5\", \"C7A5A5\"\n * - RGB: \"199, 165, 165\"\n * - CSS named colors: \"red\", \"blue\", etc.\n * @param colorString - The color string to parse.\n * @returns A THREE.Color object.\n */\nexport function parseColor(colorString: string): THREE.Color {\n\tif (!colorString || typeof colorString !== 'string') {\n\t\tgetLogger().warn(`Invalid color input: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n\n\tconst trimmed = colorString.trim();\n\n\t// Try hex format (#C7A5A5 or C7A5A5)\n\tif (trimmed.startsWith('#') || /^[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\t// Try RGB format (R, G, B)\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// Try CSS named color\n\ttry {\n\t\treturn new THREE.Color(trimmed.toLowerCase());\n\t} catch {\n\t\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n}\n\nexport function applyOffset(meshes: THREE.Mesh[], offsetY: number): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position.y -= offsetY;\n\t});\n}\n\nexport function computeCombinedBoundingBox(meshes: THREE.Mesh[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tmeshes.forEach((mesh) => {\n\t\tmesh.geometry.computeBoundingBox();\n\t\tif (mesh.geometry.boundingBox) {\n\t\t\tcombinedBoundingBox.union(mesh.geometry.boundingBox);\n\t\t}\n\t});\n\treturn combinedBoundingBox;\n}\n\n/**\n * Updates shadow camera bounds to match scene geometry.\n * This prevents shadow artifacts and ensures proper shadow coverage.\n */\nexport function updateShadowCameraBounds(\n\tscene: THREE.Scene,\n\tdirectionalLight: THREE.DirectionalLight\n): void {\n\tconst bbox = new THREE.Box3();\n\n\tscene.traverse((object) => {\n\t\tif (object instanceof THREE.Mesh && object.userData.id !== 'floor') {\n\t\t\tbbox.expandByObject(object);\n\t\t}\n\t});\n\n\tif (bbox.isEmpty()) return;\n\n\tconst size = bbox.getSize(new THREE.Vector3());\n\tconst center = bbox.getCenter(new THREE.Vector3());\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Position light relative to scene center\n\tconst lightDistance = maxDim * 2;\n\tdirectionalLight.position.set(\n\t\tcenter.x + lightDistance * 0.5,\n\t\tcenter.y + lightDistance,\n\t\tcenter.z + lightDistance * 0.5\n\t);\n\tdirectionalLight.target.position.copy(center);\n\n\t// Adjust shadow camera bounds to scene size with padding\n\tconst padding = maxDim * 0.2;\n\tdirectionalLight.shadow.camera.left = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.right = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.top = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.bottom = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.near = 0.1;\n\tdirectionalLight.shadow.camera.far = lightDistance * 3;\n\n\t// Improve shadow quality for extreme scales\n\tif (maxDim > 1000) {\n\t\tdirectionalLight.shadow.bias = -0.001;\n\t\tdirectionalLight.shadow.normalBias = 0.05;\n\t} else {\n\t\tdirectionalLight.shadow.bias = -0.0001;\n\t\tdirectionalLight.shadow.normalBias = 0.02;\n\t}\n\n\tdirectionalLight.shadow.camera.updateProjectionMatrix();\n}\n\n/**\n * Clears the given THREE.Scene by removing all meshes and disposing of associated resources.\n * @param scene - The THREE.Scene to clear.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\tconst objectsToRemove: THREE.Object3D[] = [];\n\n\t// Collect all meshes except the floor\n\tscene.traverse((child: THREE.Object3D) => {\n\t\tif (child instanceof THREE.Mesh && child.userData.id !== 'floor') {\n\t\t\tobjectsToRemove.push(child);\n\t\t}\n\t});\n\n\t// Remove and dispose of each object\n\tobjectsToRemove.forEach((object: THREE.Object3D) => {\n\t\tif (object instanceof THREE.Mesh) {\n\t\t\tobject.geometry?.dispose();\n\n\t\t\tconst materials = Array.isArray(object.material) ? object.material : [object.material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\tObject.values(material).forEach((value) => {\n\t\t\t\t\tif (value instanceof THREE.Texture) {\n\t\t\t\t\t\tvalue.dispose();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tmaterial.dispose();\n\t\t\t});\n\t\t}\n\n\t\tobject.removeFromParent();\n\t});\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","../src/features/visualization/threejs/three-initializer.ts","../src/features/visualization/threejs/three-helpers.ts"],"names":["defaultUp","initThree","canvas","options","config","applyDefaults","scene","createScene","camera","createCamera","renderer","setupRenderer","controls","setupControls","setupEnvironment","setupLighting","addFloor","eventHandlers","setupEventHandlers","resize","disposeResize","setupResponsiveResize","animate","disposeAnimation","createAnimationLoop","sceneUp","object","material","scale","defaults","child","bgColor","animationId","parent","resizeTimeout","resizeObserver","getSize","handleResize","width","height","RGBELoader","envMap","error","getLogger","ambientLight","sunlight","pos","shadowSize","shadowNear","shadowFar","floorSize","floorGeometry","floorColor","floorMaterial","floor","selectedObjects","originalMaterials","raycaster","mouse","mouseDownPosition","fitToView","box","center","size","maxDim","fov","distance","direction","selectionColorObj","clearSelection","obj","handleMouseDown","event","handleCanvasClick","currentMousePosition","rect","intersects","clickedObject","clonedMaterial","handleKeydown","OrbitControls","target","updateScene","meshes","initialPositionSet","clearScene","unionBoundingBox","mesh","boundingBox","parseColor","colorString","trimmed","hex"],"mappings":"AAAA,2/BAAwC,wDAAqE,kMCAtF,yEACO,kEACH,IAKrBA,CAAAA,CAAY,IAAU,CAAA,CAAA,OAAA,CAAQ,CAAA,CAAG,CAAA,CAAG,CAAC,CAAA,CAS9BC,CAAAA,qBAAY,QAAA,CACxBC,CAAAA,CACAC,CAAAA,CAUC,CACD,IAAMC,CAAAA,CAASC,CAAAA,CAAcF,CAAAA,EAAW,CAAC,CAAC,CAAA,CAGpCG,CAAAA,CAAQC,CAAAA,CAAYH,CAAM,CAAA,CAC1BI,CAAAA,CAASC,EAAAA,CAAaL,CAAM,CAAA,CAC5BM,CAAAA,CAAWC,EAAAA,CAAcT,CAAAA,CAAQE,CAAM,CAAA,CACvCQ,CAAAA,CAAWC,EAAAA,CAAcL,CAAAA,CAAQN,CAAAA,CAAQE,CAAM,CAAA,CAGrDU,EAAAA,CAAiBR,CAAAA,CAAOF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,CAAAA,CAAMD,CAAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,CAAIA,CAAAA,CAAU,CAAA,CAAA,EAAIA,CAAO,CAAA,CAAA","file":"/home/runner/work/selva-compute/selva-compute/dist/visualization.cjs","sourcesContent":[null,"import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { RGBELoader } from 'three/addons/loaders/RGBELoader.js';\n\nimport { getLogger } from '@/core';\nimport { ThreeInitializerOptions } from '../types';\n\nconst defaultUp = new THREE.Vector3(0, 0, 1);\n\n/**\n * Initializes a comprehensive Three.js environment with enhanced render quality and flexible configuration.\n *\n * @param canvas - The HTML canvas element to render the scene on.\n * @param options - Configuration options for the Three.js environment.\n * @returns An object containing the scene, camera, controls, renderer, and utility methods.\n */\nexport const initThree = function (\n\tcanvas: HTMLCanvasElement,\n\toptions?: ThreeInitializerOptions\n): {\n\tscene: THREE.Scene;\n\tcamera: THREE.PerspectiveCamera;\n\tcontrols: OrbitControls;\n\trenderer: THREE.WebGLRenderer;\n\tdispose: () => void;\n\tresize: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst config = applyDefaults(options || {});\n\n\t// Initialize core components\n\tconst scene = createScene(config);\n\tconst camera = createCamera(config);\n\tconst renderer = setupRenderer(canvas, config);\n\tconst controls = setupControls(camera, canvas, config);\n\n\t// Setup environment and lighting\n\tsetupEnvironment(scene, config);\n\tsetupLighting(scene, config);\n\n\t// Add floor if enabled\n\tif (config.floor?.enabled) {\n\t\taddFloor(scene, config);\n\t}\n\n\tconst eventHandlers = config.events.enableEventHandlers !== false\n\t\t? setupEventHandlers(canvas, scene, camera, controls, config)\n\t\t: { dispose: () => { }, fitToView: () => { }, clearSelection: () => { } };\n\n\t// Handle resizing\n\tconst { resize, dispose: disposeResize } = setupResponsiveResize(canvas, renderer, camera);\n\n\t// Animation loop\n\tconst { animate, dispose: disposeAnimation } = createAnimationLoop(\n\t\trenderer,\n\t\tscene,\n\t\tcamera,\n\t\tcontrols\n\t);\n\tanimate();\n\n\t// Set scene up vector\n\tconst sceneUp = config.environment?.sceneUp || defaultUp;\n\tscene.up.set(sceneUp.x, sceneUp.y, sceneUp.z);\n\n\t// Comprehensive disposal\n\tconst dispose = () => {\n\t\tdisposeAnimation(); // Stop animation loop\n\t\tdisposeResize(); // Remove resize listeners\n\t\teventHandlers.dispose(); // Remove click/keyboard listeners\n\t\tcontrols.dispose(); // Dispose controls\n\t\trenderer.dispose(); // Dispose renderer\n\n\t\t// Dispose geometries and materials\n\t\tscene.traverse((object) => {\n\t\t\tif (object instanceof THREE.Mesh) {\n\t\t\t\tobject.geometry?.dispose();\n\t\t\t\tif (Array.isArray(object.material)) {\n\t\t\t\t\tobject.material.forEach((material) => material.dispose());\n\t\t\t\t} else {\n\t\t\t\t\tobject.material?.dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t};\n\n\treturn {\n\t\tscene,\n\t\tcamera,\n\t\tcontrols,\n\t\trenderer,\n\t\tdispose,\n\t\tresize,\n\t\tfitToView: eventHandlers.fitToView,\n\t\tclearSelection: eventHandlers.clearSelection\n\t};\n};\n\nfunction applyDefaults(options: ThreeInitializerOptions): Required<ThreeInitializerOptions> {\n\tconst scale = options.sceneScale || 'm';\n\n\t// Define sensible defaults for each scale\n\t// Note: All Rhino geometry is normalized to METERS (1 unit = 1 meter), sceneScale just changes the viewing perspective\n\tconst scaleDefaults = {\n\t\tmm: {\n\t\t\t// Geometry scaled UP by 1000x (mm to m conversion for better precision)\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 10,\n\t\t\tlightHeight: 20,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1000\n\t\t},\n\t\tcm: {\n\t\t\t// Geometry scaled UP by 100x (cm to m conversion)\n\t\t\tcameraDistance: 20,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 100,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 100\n\t\t},\n\t\tm: {\n\t\t\t// Natural Three.js scale (1 unit = 1 meter)\n\t\t\tcameraDistance: 10,\n\t\t\tnear: 0.01,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 50,\n\t\t\tlightDistance: 25,\n\t\t\tlightHeight: 50,\n\t\t\tminDistance: 0.001,\n\t\t\tshadowSize: 100,\n\t\t\tscaleFactor: 1\n\t\t},\n\t\tinches: {\n\t\t\t// Geometry scaled UP by ~39.37x (inches to m conversion)\n\t\t\tcameraDistance: 15,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 80,\n\t\t\tlightDistance: 20,\n\t\t\tlightHeight: 40,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 80,\n\t\t\tscaleFactor: 39.37\n\t\t},\n\t\tfeet: {\n\t\t\t// Geometry scaled UP by ~3.28x (feet to m conversion)\n\t\t\tcameraDistance: 8,\n\t\t\tnear: 0.1,\n\t\t\tfar: 2000,\n\t\t\tfloorSize: 40,\n\t\t\tlightDistance: 15,\n\t\t\tlightHeight: 30,\n\t\t\tminDistance: 0.1,\n\t\t\tshadowSize: 60,\n\t\t\tscaleFactor: 3.28084\n\t\t}\n\t};\n\n\tconst defaults = scaleDefaults[scale];\n\n\treturn {\n\t\tsceneScale: scale,\n\t\tcamera: {\n\t\t\tposition:\n\t\t\t\toptions.camera?.position ||\n\t\t\t\tnew THREE.Vector3(\n\t\t\t\t\t-defaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance,\n\t\t\t\t\tdefaults.cameraDistance\n\t\t\t\t),\n\t\t\tfov: options.camera?.fov || 20,\n\t\t\tnear: options.camera?.near || defaults.near,\n\t\t\tfar: options.camera?.far || defaults.far,\n\t\t\ttarget: options.camera?.target || new THREE.Vector3(0, 0, 0)\n\t\t},\n\t\tlighting: {\n\t\t\tenableSunlight: options.lighting?.enableSunlight ?? true,\n\t\t\tsunlightIntensity: options.lighting?.sunlightIntensity || 1,\n\t\t\tsunlightPosition:\n\t\t\t\toptions.lighting?.sunlightPosition ||\n\t\t\t\tnew THREE.Vector3(defaults.lightDistance, defaults.lightHeight, defaults.lightDistance),\n\t\t\tambientLightColor: options.lighting?.ambientLightColor || new THREE.Color(0x404040),\n\t\t\tambientLightIntensity: options.lighting?.ambientLightIntensity || 1,\n\t\t\tsunlightColor: options.lighting?.sunlightColor || 0xffffff // Default to white sunlight\n\t\t},\n\t\tenvironment: {\n\t\t\thdrPath: options.environment?.hdrPath || '/baseHDR.hdr',\n\t\t\tbackgroundColor: options.environment?.backgroundColor || new THREE.Color(0xf0f0f0),\n\t\t\tenableEnvironmentLighting: options.environment?.enableEnvironmentLighting ?? true,\n\t\t\tsceneUp: options.environment?.sceneUp || defaultUp,\n\t\t\tshowEnvironment: options.environment?.showEnvironment ?? false\n\t\t},\n\t\tfloor: {\n\t\t\tenabled: options.floor?.enabled ?? false,\n\t\t\tsize: options.floor?.size || defaults.floorSize,\n\t\t\tcolor: options.floor?.color || new THREE.Color(0x808080),\n\t\t\troughness: options.floor?.roughness || 0.7,\n\t\t\tmetalness: options.floor?.metalness || 0.0,\n\t\t\treceiveShadow: options.floor?.receiveShadow ?? true\n\t\t},\n\t\trender: {\n\t\t\tenableShadows: options.render?.enableShadows ?? true,\n\t\t\tshadowMapSize: options.render?.shadowMapSize || 2048,\n\t\t\tantialias: options.render?.antialias ?? true,\n\t\t\tpixelRatio: options.render?.pixelRatio || Math.min(window.devicePixelRatio, 2),\n\t\t\ttoneMapping: options.render?.toneMapping || THREE.NeutralToneMapping,\n\t\t\ttoneMappingExposure: options.render?.toneMappingExposure || 1,\n\t\t\tpreserveDrawingBuffer: options.render?.preserveDrawingBuffer ?? false\n\t\t},\n\t\tcontrols: {\n\t\t\tenableDamping: options.controls?.enableDamping ?? false,\n\t\t\tdampingFactor: options.controls?.dampingFactor || 0.05,\n\t\t\tautoRotate: options.controls?.autoRotate ?? false,\n\t\t\tautoRotateSpeed: options.controls?.autoRotateSpeed || 0.5,\n\t\t\tenableZoom: options.controls?.enableZoom ?? true,\n\t\t\tenablePan: options.controls?.enablePan ?? true,\n\t\t\tminDistance: options.controls?.minDistance || defaults.minDistance,\n\t\t\tmaxDistance: options.controls?.maxDistance || Infinity\n\t\t},\n\t\tevents: {\n\t\t\tonBackgroundClicked: options.events?.onBackgroundClicked,\n\t\t\tonObjectSelected: options.events?.onObjectSelected,\n\t\t\tonMeshMetadataClicked: options.events?.onMeshMetadataClicked,\n\t\t\tselectionColor: options.events?.selectionColor || '#ff0000', // Default to red\n\t\t\tenableEventHandlers: options.events?.enableEventHandlers ?? true,\n\t\t\tenableKeyboardControls: options.events?.enableKeyboardControls ?? true,\n\t\t\tenableClickToFocus: options.events?.enableClickToFocus ?? true\n\t\t}\n\t};\n}\n\n/**\n * Creates and configures the scene.\n */\nfunction createScene(config: Required<ThreeInitializerOptions>): THREE.Scene {\n\tconst scene = new THREE.Scene();\n\n\t// Clear existing children except floor\n\tscene.children.forEach((child) => {\n\t\tif (child.userData.id !== 'floor') {\n\t\t\tscene.remove(child);\n\t\t}\n\t});\n\n\t// Set background color\n\tconst bgColor =\n\t\ttypeof config.environment.backgroundColor === 'string'\n\t\t\t? new THREE.Color(config.environment.backgroundColor)\n\t\t\t: config.environment.backgroundColor;\n\tscene.background = bgColor || null;\n\n\treturn scene;\n}\n\n/**\n * Creates an optimized animation loop with proper disposal.\n */\nfunction createAnimationLoop(\n\trenderer: THREE.WebGLRenderer,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls\n): { animate: () => void; dispose: () => void } {\n\tlet animationId: number | null = null;\n\n\tconst animate = function () {\n\t\tanimationId = requestAnimationFrame(animate);\n\n\t\t// Update controls if damping is enabled\n\t\tif (controls.enableDamping) {\n\t\t\tcontrols.update();\n\t\t}\n\n\t\trenderer.render(scene, camera);\n\t};\n\n\tconst dispose = () => {\n\t\tif (animationId !== null) {\n\t\t\tcancelAnimationFrame(animationId);\n\t\t\tanimationId = null;\n\t\t}\n\t};\n\n\treturn { animate, dispose };\n}\n\n/**\n * Sets up responsive resizing with improved performance and proper parent handling.\n */\nfunction setupResponsiveResize(\n\tcanvas: HTMLCanvasElement,\n\trenderer: THREE.WebGLRenderer,\n\tcamera: THREE.PerspectiveCamera\n): { resize: () => void; dispose: () => void } {\n\tconst parent = canvas.parentElement;\n\tlet resizeTimeout: NodeJS.Timeout;\n\tlet resizeObserver: ResizeObserver | null = null;\n\n\tconst getSize = () => {\n\t\tif (parent) {\n\t\t\treturn {\n\t\t\t\twidth: parent.clientWidth,\n\t\t\t\theight: parent.clientHeight\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\twidth: window.innerWidth,\n\t\t\t\theight: window.innerHeight\n\t\t\t};\n\t\t}\n\t};\n\n\tconst handleResize = () => {\n\t\tif (resizeTimeout) {\n\t\t\tclearTimeout(resizeTimeout);\n\t\t}\n\n\t\tresizeTimeout = setTimeout(() => {\n\t\t\tconst { width, height } = getSize();\n\n\t\t\t// Only update if size actually changed\n\t\t\tif (renderer.domElement.width !== width || renderer.domElement.height !== height) {\n\t\t\t\trenderer.setSize(width, height, false);\n\t\t\t\tcamera.aspect = width / height;\n\t\t\t\tcamera.updateProjectionMatrix();\n\t\t\t}\n\t\t}, 16); // ~60fps throttling\n\t};\n\n\t// Set up the appropriate resize observer\n\tif (parent && typeof ResizeObserver !== 'undefined') {\n\t\t// Use ResizeObserver for parent container\n\t\tresizeObserver = new ResizeObserver(handleResize);\n\t\tresizeObserver.observe(parent);\n\t} else {\n\t\t// Fallback to window resize for fullscreen or older browsers\n\t\twindow.addEventListener('resize', handleResize);\n\t}\n\n\tconst dispose = () => {\n\t\tif (resizeTimeout) {\n\t\t\tclearTimeout(resizeTimeout);\n\t\t}\n\t\tif (resizeObserver) {\n\t\t\tresizeObserver.disconnect();\n\t\t} else {\n\t\t\twindow.removeEventListener('resize', handleResize);\n\t\t}\n\t};\n\n\treturn { resize: handleResize, dispose };\n}\n\n/**\n * Sets up environment lighting and HDR.\n */\nfunction setupEnvironment(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tif (config.environment.enableEnvironmentLighting) {\n\t\tnew RGBELoader().load(\n\t\t\tconfig.environment.hdrPath || '/baseHDR.hdr',\n\t\t\tfunction (envMap) {\n\t\t\t\tenvMap.mapping = THREE.EquirectangularReflectionMapping;\n\t\t\t\tscene.environment = envMap;\n\t\t\t\tif (config.environment.showEnvironment) {\n\t\t\t\t\tscene.background = envMap;\n\t\t\t\t}\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfunction (error) {\n\t\t\t\tgetLogger().warn('HDR texture could not be loaded, falling back to basic lighting:', error);\n\t\t\t\t// Add basic ambient light as fallback\n\t\t\t\tconst ambientLight = new THREE.AmbientLight(0x404040, 0.4);\n\t\t\t\tscene.add(ambientLight);\n\t\t\t}\n\t\t);\n\t}\n}\n\nfunction setupLighting(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\t// Add ambient light\n\tconst ambientLight = new THREE.AmbientLight(\n\t\tconfig.lighting.ambientLightColor,\n\t\tconfig.lighting.ambientLightIntensity\n\t);\n\tscene.add(ambientLight);\n\n\t// Add directional light (sunlight)\n\tif (config.lighting.enableSunlight) {\n\t\tconst sunlight = new THREE.DirectionalLight(\n\t\t\tconfig.lighting.sunlightColor ?? 0xffffff,\n\t\t\tconfig.lighting.sunlightIntensity\n\t\t);\n\t\tconst pos = config.lighting.sunlightPosition;\n\t\tif (pos) {\n\t\t\tsunlight.position.set(pos.x, pos.y, pos.z);\n\t\t}\n\n\t\tif (config.render.enableShadows) {\n\t\t\tsunlight.castShadow = true;\n\t\t\tconst shadowSize = config.sceneScale === 'mm' ? 0.1 : config.sceneScale === 'cm' ? 10 : 100;\n\n\t\t\tsunlight.shadow.camera.left = -shadowSize;\n\t\t\tsunlight.shadow.camera.right = shadowSize;\n\t\t\tsunlight.shadow.camera.top = shadowSize;\n\t\t\tsunlight.shadow.camera.bottom = -shadowSize;\n\n\t\t\tconst shadowNear =\n\t\t\t\tconfig.sceneScale === 'mm' ? 0.001 : config.sceneScale === 'cm' ? 0.1 : 0.5;\n\n\t\t\tconst shadowFar = config.sceneScale === 'mm' ? 1 : config.sceneScale === 'cm' ? 100 : 500;\n\n\t\t\tsunlight.shadow.camera.near = shadowNear;\n\t\t\tsunlight.shadow.camera.far = shadowFar;\n\n\t\t\tsunlight.shadow.mapSize.width = config.render.shadowMapSize || 2048;\n\t\t\tsunlight.shadow.mapSize.height = config.render.shadowMapSize || 2048;\n\n\t\t\t// Improved shadow quality\n\t\t\tsunlight.shadow.bias = -0.0001;\n\t\t\tsunlight.shadow.normalBias = 0.02;\n\t\t}\n\n\t\tscene.add(sunlight);\n\t}\n}\n\n/**\n * Adds a floor to the scene with scale-aware sizing.\n */\nfunction addFloor(scene: THREE.Scene, config: Required<ThreeInitializerOptions>) {\n\tconst floorSize = config.floor.size;\n\tconst floorGeometry = new THREE.PlaneGeometry(floorSize, floorSize);\n\n\tconst floorColor =\n\t\ttypeof config.floor.color === 'string'\n\t\t\t? new THREE.Color(config.floor.color)\n\t\t\t: config.floor.color;\n\n\tconst floorMaterial = new THREE.MeshStandardMaterial({\n\t\tcolor: floorColor,\n\t\troughness: config.floor.roughness,\n\t\tmetalness: config.floor.metalness,\n\t\tside: THREE.DoubleSide\n\t});\n\n\tconst floor = new THREE.Mesh(floorGeometry, floorMaterial);\n\tfloor.userData.id = 'floor';\n\tfloor.name = 'floor';\n\tfloor.rotation.x = -Math.PI / 2;\n\tfloor.position.y = 0;\n\n\tif (config.floor.receiveShadow && config.render.enableShadows) {\n\t\tfloor.receiveShadow = true;\n\t}\n\n\tscene.add(floor);\n}\n\n/**\n * Creates and configures the camera with proper aspect ratio.\n */\nfunction createCamera(config: Required<ThreeInitializerOptions>): THREE.PerspectiveCamera {\n\t// Get proper aspect ratio from canvas parent or window\n\tconst canvas = document.querySelector('canvas');\n\tconst parent = canvas?.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\tconst camera = new THREE.PerspectiveCamera(\n\t\tconfig.camera.fov,\n\t\twidth / height,\n\t\tconfig.camera.near,\n\t\tconfig.camera.far\n\t);\n\n\tconst pos = config.camera.position;\n\tif (pos) {\n\t\tcamera.position.set(pos.x, pos.y, pos.z);\n\t}\n\n\treturn camera;\n}\n\n/**\n * Sets up enhanced WebGL renderer with improved quality settings.\n */\nfunction setupRenderer(\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): THREE.WebGLRenderer {\n\tconst renderer = new THREE.WebGLRenderer({\n\t\tantialias: config.render.antialias,\n\t\tcanvas,\n\t\talpha: true,\n\t\tpowerPreference: 'high-performance',\n\t\tpreserveDrawingBuffer: config.render.preserveDrawingBuffer,\n\t\t// Enable logarithmic depth buffer for extreme scale ranges\n\t\t// This dramatically improves depth precision for mixed scales (mm to km)\n\t\tlogarithmicDepthBuffer: true\n\t});\n\n\t// Get proper dimensions - parent container or window\n\tconst parent = canvas.parentElement;\n\tconst width = parent ? parent.clientWidth : window.innerWidth;\n\tconst height = parent ? parent.clientHeight : window.innerHeight;\n\n\t// Set canvas style to fill parent if it exists\n\tif (parent) {\n\t\tcanvas.style.width = '100%';\n\t\tcanvas.style.height = '100%';\n\t\tcanvas.style.display = 'block';\n\t}\n\n\trenderer.setSize(width, height, false);\n\trenderer.setPixelRatio(config.render.pixelRatio || Math.min(window.devicePixelRatio, 2));\n\n\t// Enhanced shadow settings\n\tif (config.render.enableShadows) {\n\t\trenderer.shadowMap.enabled = true;\n\t\t// Use VSM for better quality with extreme scales\n\t\trenderer.shadowMap.type = THREE.VSMShadowMap;\n\t}\n\n\t// Improved tone mapping and color management\n\trenderer.toneMapping = config.render.toneMapping || THREE.ACESFilmicToneMapping;\n\trenderer.toneMappingExposure = config.render.toneMappingExposure || 1.0;\n\trenderer.outputColorSpace = THREE.SRGBColorSpace;\n\n\t// Additional quality settings for depth rendering\n\trenderer.sortObjects = true; // Ensure proper render order\n\n\treturn renderer;\n}\n\n// Add event handler setup function\nfunction setupEventHandlers(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Scene,\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tconfig: Required<ThreeInitializerOptions>\n): {\n\tdispose: () => void;\n\tfitToView: () => void;\n\tclearSelection: () => void;\n} {\n\tconst selectedObjects = new Set<THREE.Object3D>();\n\tconst originalMaterials = new Map<THREE.Object3D, THREE.Material | THREE.Material[]>();\n\tconst raycaster = new THREE.Raycaster();\n\tconst mouse = new THREE.Vector2();\n\tconst mouseDownPosition = new THREE.Vector2();\n\n\t// Fit scene to view\n\tconst fitToView = () => {\n\t\tconst box = new THREE.Box3();\n\n\t\t// Calculate bounding box of all visible objects (excluding floor)\n\t\tscene.traverse((object) => {\n\t\t\tif (object.visible && object.userData.id !== 'floor' && object instanceof THREE.Mesh) {\n\t\t\t\tbox.expandByObject(object);\n\t\t\t}\n\t\t});\n\n\t\tif (box.isEmpty()) {\n\t\t\tgetLogger().warn('No objects to fit to view');\n\t\t\treturn;\n\t\t}\n\n\t\tconst center = box.getCenter(new THREE.Vector3());\n\t\tconst size = box.getSize(new THREE.Vector3());\n\n\t\t// Calculate distance needed to fit the object\n\t\tconst maxDim = Math.max(size.x, size.y, size.z);\n\t\tconst fov = camera.fov * (Math.PI / 180);\n\t\tlet distance = maxDim / (2 * Math.tan(fov / 2));\n\n\t\t// Add some padding\n\t\tdistance *= 1.5;\n\n\t\t// Position camera\n\t\tconst direction = camera.position.clone().sub(controls.target).normalize();\n\t\tcamera.position.copy(center.clone().add(direction.multiplyScalar(distance)));\n\n\t\t// Update controls target\n\t\tcontrols.target.copy(center);\n\t\tcontrols.update();\n\t};\n\n\t// Parse selection color\n\tconst selectionColorObj = typeof config.events.selectionColor === 'string'\n\t\t? new THREE.Color(config.events.selectionColor)\n\t\t: config.events.selectionColor instanceof THREE.Color\n\t\t\t? config.events.selectionColor\n\t\t\t: new THREE.Color('#ff0000');\n\n\t// Clear selection\n\tconst clearSelection = () => {\n\t\tselectedObjects.forEach((obj) => {\n\t\t\t// Restore original material\n\t\t\tif (obj instanceof THREE.Mesh && originalMaterials.has(obj)) {\n\t\t\t\tobj.material = originalMaterials.get(obj)!;\n\t\t\t\toriginalMaterials.delete(obj);\n\t\t\t}\n\t\t});\n\t\tselectedObjects.clear();\n\t};\n\n\tconst handleMouseDown = (event: MouseEvent) => {\n\t\tmouseDownPosition.set(event.clientX, event.clientY);\n\t};\n\n\t// Handle canvas clicks\n\tconst handleCanvasClick = (event: MouseEvent) => {\n\t\t// Ignore if mouse has moved significantly (drag)\n\t\tconst currentMousePosition = new THREE.Vector2(event.clientX, event.clientY);\n\t\tif (mouseDownPosition.distanceTo(currentMousePosition) > 5) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Calculate mouse position in normalized device coordinates\n\t\tconst rect = canvas.getBoundingClientRect();\n\t\tmouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n\t\tmouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n\n\t\t// Raycast to find intersected objects\n\t\traycaster.setFromCamera(mouse, camera);\n\t\tconst intersects = raycaster.intersectObjects(scene.children, true);\n\n\t\tif (intersects.length > 0) {\n\t\t\tconst clickedObject = intersects[0].object;\n\n\t\t\t// Handle object selection\n\t\t\tif (!selectedObjects.has(clickedObject)) {\n\t\t\t\tclearSelection();\n\t\t\t\tselectedObjects.add(clickedObject);\n\n\t\t\t\t// Clone material and apply selection color only to this mesh\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && clickedObject.material instanceof THREE.Material) {\n\t\t\t\t\t// Store original material\n\t\t\t\t\toriginalMaterials.set(clickedObject, clickedObject.material);\n\n\t\t\t\t\t// Clone the material so we don't affect other meshes\n\t\t\t\t\tconst clonedMaterial = clickedObject.material.clone();\n\t\t\t\t\t(clonedMaterial as any).emissive = selectionColorObj.clone();\n\t\t\t\t\tclickedObject.material = clonedMaterial;\n\t\t\t\t}\n\n\t\t\t\tconfig.events?.onObjectSelected?.(clickedObject);\n\n\t\t\t\t// Call metadata callback if the mesh has metadata\n\t\t\t\tif (clickedObject instanceof THREE.Mesh && Object.keys(clickedObject.userData).length > 0) {\n\t\t\t\t\tconfig.events?.onMeshMetadataClicked?.(clickedObject.userData);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Background clicked\n\t\t\tclearSelection();\n\t\t\tconfig.events?.onBackgroundClicked?.({ x: mouse.x, y: mouse.y });\n\t\t}\n\t};\n\n\t// Handle keyboard events\n\tconst handleKeydown = (event: KeyboardEvent) => {\n\t\tif (!config.events?.enableKeyboardControls) return;\n\n\t\tswitch (event.key.toLowerCase()) {\n\t\t\tcase 'f':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t\tcase 'escape':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tclearSelection();\n\t\t\t\tbreak;\n\t\t\tcase ' ':\n\t\t\t\tevent.preventDefault();\n\t\t\t\tfitToView();\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\t// Add event listeners\n\tif (config.events?.enableClickToFocus) {\n\t\tcanvas.addEventListener('mousedown', handleMouseDown);\n\t\tcanvas.addEventListener('click', handleCanvasClick);\n\t}\n\n\tif (config.events?.enableKeyboardControls) {\n\t\t// Make canvas focusable\n\t\tcanvas.setAttribute('tabindex', '0');\n\t\t// Only listen for keydown when canvas has focus\n\t\tcanvas.addEventListener('keydown', handleKeydown);\n\t}\n\n\t// Disposal function\n\tconst dispose = () => {\n\t\tcanvas.removeEventListener('mousedown', handleMouseDown);\n\t\tcanvas.removeEventListener('click', handleCanvasClick);\n\t\tcanvas.removeEventListener('keydown', handleKeydown);\n\t\tclearSelection();\n\t};\n\n\treturn { dispose, fitToView, clearSelection };\n}\n\n/**\n * Sets up enhanced orbit controls with scale-aware distances.\n */\nfunction setupControls(\n\tcamera: THREE.PerspectiveCamera,\n\tcanvas: HTMLCanvasElement,\n\tconfig: Required<ThreeInitializerOptions>\n): OrbitControls {\n\tconst controls = new OrbitControls(camera, canvas);\n\n\t// Set target\n\tconst target = config.camera.target;\n\tif (target) {\n\t\tcontrols.target.set(target.x, target.y, target.z);\n\t}\n\n\t// Configure damping\n\tcontrols.enableDamping = config.controls.enableDamping || false;\n\tcontrols.dampingFactor = config.controls.dampingFactor || 0.05;\n\n\t// Configure auto rotation\n\tcontrols.autoRotate = config.controls.autoRotate || false;\n\tcontrols.autoRotateSpeed = config.controls.autoRotateSpeed || 0.5;\n\n\t// Configure interaction limits\n\tcontrols.enableZoom = config.controls.enableZoom || true;\n\tcontrols.enablePan = config.controls.enablePan || true;\n\tcontrols.minDistance = config.controls.minDistance || 0.001;\n\tcontrols.maxDistance = config.controls.maxDistance || Infinity;\n\n\t// Smooth controls\n\tcontrols.screenSpacePanning = false;\n\tcontrols.maxPolarAngle = Math.PI;\n\n\tcontrols.update();\n\treturn controls;\n}\n","import * as THREE from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\nimport { getLogger } from '@/core';\n\n/**\n * Updates the scene with the given meshes and camera settings.\n * If initialPositionSet is false, it positions the camera and sets the controls target based on the bounding boxes of the meshes.\n * @param scene - The THREE.Scene object to update.\n * @param meshes - An array of THREE.Mesh objects to add to the scene.\n * @param camera - The THREE.PerspectiveCamera object to position.\n * @param controls - The OrbitControls object to update.\n * @param initialPositionSet - A boolean indicating whether the initial position of the camera and controls have been set.\n */\nexport function updateScene(\n\tscene: THREE.Scene,\n\tmeshes: THREE.Mesh[],\n\tcamera: THREE.PerspectiveCamera,\n\tcontrols: OrbitControls,\n\tinitialPositionSet: boolean\n) {\n\tclearScene(scene);\n\n\tif (meshes.length === 0) return;\n\n\tconst unionBoundingBox = new THREE.Box3();\n\n\tmeshes.forEach((mesh) => {\n\t\tscene.add(mesh);\n\t\tconst boundingBox = new THREE.Box3().setFromObject(mesh);\n\t\tunionBoundingBox.union(boundingBox);\n\t});\n\n\t// Get the center of the union bounding box\n\tconst center = unionBoundingBox.getCenter(new THREE.Vector3());\n\tconst size = unionBoundingBox.getSize(new THREE.Vector3());\n\n\t// Calculate a distance that is slightly larger than the largest dimension of the union bounding box\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Always update camera frustum to ensure geometry is visible\n\t// This prevents clipping when geometry size changes significantly\n\tconst scaleRatio = maxDim / Math.min(size.x || 1, size.y || 1, size.z || 1);\n\n\tif (scaleRatio > 100 || maxDim > 10000) {\n\t\t// Large scale range detected - use logarithmic depth buffer approach\n\t\tcamera.near = maxDim * 0.0001; // 0.01% of max dimension\n\t\tcamera.far = maxDim * 100; // 100x max dimension\n\t} else if (maxDim > 1000) {\n\t\t// Large scene\n\t\tcamera.near = maxDim * 0.001;\n\t\tcamera.far = maxDim * 50;\n\t} else {\n\t\t// Normal scene\n\t\tcamera.near = Math.max(0.01, maxDim * 0.01);\n\t\tcamera.far = Math.max(2000, maxDim * 20);\n\t}\n\n\tcamera.updateProjectionMatrix();\n\n\t// Only reposition camera and controls on first frame\n\tif (!initialPositionSet) {\n\t\tconst distance = maxDim * 4;\n\n\t\tcamera.position.set(center.x + distance * 0.8, center.y + distance, center.z + distance * 1.2);\n\t\tcontrols.target = center;\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\n\t\tcontrols.update();\n\t} else {\n\t\t// Update control constraints to match new frustum\n\t\tcontrols.minDistance = camera.near * 2;\n\t\tcontrols.maxDistance = camera.far * 0.9;\n\t}\n}\n\n// =========================\n// Helper functions\n// =========================\n\n/**\n * Parses a color string in multiple formats to a THREE.Color object.\n * Supported formats:\n * - Hex: \"#C7A5A5\", \"C7A5A5\"\n * - RGB: \"199, 165, 165\"\n * - CSS named colors: \"red\", \"blue\", etc.\n * @param colorString - The color string to parse.\n * @returns A THREE.Color object.\n */\nexport function parseColor(colorString: string): THREE.Color {\n\tif (!colorString || typeof colorString !== 'string') {\n\t\tgetLogger().warn(`Invalid color input: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n\n\tconst trimmed = colorString.trim();\n\n\t// Try hex format (#C7A5A5 or C7A5A5)\n\tif (trimmed.startsWith('#') || /^[0-9A-Fa-f]{6}$/.test(trimmed)) {\n\t\ttry {\n\t\t\tconst hex = trimmed.startsWith('#') ? trimmed : `#${trimmed}`;\n\t\t\treturn new THREE.Color(hex);\n\t\t} catch {\n\t\t\tgetLogger().warn(`Invalid hex color: ${colorString}, using white`);\n\t\t\treturn new THREE.Color(0xffffff);\n\t\t}\n\t}\n\n\t// Try RGB format (R, G, B)\n\tif (trimmed.includes(',')) {\n\t\tconst rgb = trimmed.split(',').map((c) => parseInt(c.trim(), 10));\n\t\tif (rgb.length === 3 && rgb.every((n) => !isNaN(n) && n >= 0 && n <= 255)) {\n\t\t\treturn new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);\n\t\t}\n\t}\n\n\t// Try CSS named color\n\ttry {\n\t\treturn new THREE.Color(trimmed.toLowerCase());\n\t} catch {\n\t\tgetLogger().warn(`Invalid color string: ${colorString}, using white`);\n\t\treturn new THREE.Color(0xffffff);\n\t}\n}\n\nexport function applyOffset(meshes: THREE.Mesh[], offsetY: number): void {\n\tmeshes.forEach((mesh) => {\n\t\tmesh.position.y -= offsetY;\n\t});\n}\n\nexport function computeCombinedBoundingBox(meshes: THREE.Mesh[]): THREE.Box3 {\n\tconst combinedBoundingBox = new THREE.Box3();\n\tmeshes.forEach((mesh) => {\n\t\tmesh.geometry.computeBoundingBox();\n\t\tif (mesh.geometry.boundingBox) {\n\t\t\tcombinedBoundingBox.union(mesh.geometry.boundingBox);\n\t\t}\n\t});\n\treturn combinedBoundingBox;\n}\n\n/**\n * Updates shadow camera bounds to match scene geometry.\n * This prevents shadow artifacts and ensures proper shadow coverage.\n */\nexport function updateShadowCameraBounds(\n\tscene: THREE.Scene,\n\tdirectionalLight: THREE.DirectionalLight\n): void {\n\tconst bbox = new THREE.Box3();\n\n\tscene.traverse((object) => {\n\t\tif (object instanceof THREE.Mesh && object.userData.id !== 'floor') {\n\t\t\tbbox.expandByObject(object);\n\t\t}\n\t});\n\n\tif (bbox.isEmpty()) return;\n\n\tconst size = bbox.getSize(new THREE.Vector3());\n\tconst center = bbox.getCenter(new THREE.Vector3());\n\tconst maxDim = Math.max(size.x, size.y, size.z);\n\n\t// Position light relative to scene center\n\tconst lightDistance = maxDim * 2;\n\tdirectionalLight.position.set(\n\t\tcenter.x + lightDistance * 0.5,\n\t\tcenter.y + lightDistance,\n\t\tcenter.z + lightDistance * 0.5\n\t);\n\tdirectionalLight.target.position.copy(center);\n\n\t// Adjust shadow camera bounds to scene size with padding\n\tconst padding = maxDim * 0.2;\n\tdirectionalLight.shadow.camera.left = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.right = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.top = maxDim / 2 + padding;\n\tdirectionalLight.shadow.camera.bottom = -maxDim / 2 - padding;\n\tdirectionalLight.shadow.camera.near = 0.1;\n\tdirectionalLight.shadow.camera.far = lightDistance * 3;\n\n\t// Improve shadow quality for extreme scales\n\tif (maxDim > 1000) {\n\t\tdirectionalLight.shadow.bias = -0.001;\n\t\tdirectionalLight.shadow.normalBias = 0.05;\n\t} else {\n\t\tdirectionalLight.shadow.bias = -0.0001;\n\t\tdirectionalLight.shadow.normalBias = 0.02;\n\t}\n\n\tdirectionalLight.shadow.camera.updateProjectionMatrix();\n}\n\n/**\n * Clears the given THREE.Scene by removing all meshes and disposing of associated resources.\n * @param scene - The THREE.Scene to clear.\n */\nfunction clearScene(scene: THREE.Scene): void {\n\tconst objectsToRemove: THREE.Object3D[] = [];\n\n\t// Collect all meshes except the floor\n\tscene.traverse((child: THREE.Object3D) => {\n\t\tif (child instanceof THREE.Mesh && child.userData.id !== 'floor') {\n\t\t\tobjectsToRemove.push(child);\n\t\t}\n\t});\n\n\t// Remove and dispose of each object\n\tobjectsToRemove.forEach((object: THREE.Object3D) => {\n\t\tif (object instanceof THREE.Mesh) {\n\t\t\tobject.geometry?.dispose();\n\n\t\t\tconst materials = Array.isArray(object.material) ? object.material : [object.material];\n\t\t\tmaterials.forEach((material) => {\n\t\t\t\tObject.values(material).forEach((value) => {\n\t\t\t\t\tif (value instanceof THREE.Texture) {\n\t\t\t\t\t\tvalue.dispose();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tmaterial.dispose();\n\t\t\t});\n\t\t}\n\n\t\tobject.removeFromParent();\n\t});\n}\n"]}
package/package.json CHANGED
@@ -1,117 +1,109 @@
1
1
  {
2
- "name": "selva-compute",
3
- "version": "1.0.0",
4
- "packageManager": "pnpm@10.18.0",
5
- "description": "TypeScript library for Rhino Compute Server - Grasshopper and RhinoCommon",
6
- "author": "VektorNode",
7
- "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/TheVessen/selva-compute.git"
11
- },
12
- "bugs": "https://github.com/TheVessen/selva-compute/issues",
13
- "homepage": "https://github.com/TheVessen/selva-compute#readme",
14
- "type": "module",
15
- "keywords": [
16
- "compute",
17
- "rhino",
18
- "grasshopper",
19
- "geometry",
20
- "3d",
21
- "cad",
22
- "parametric",
23
- "modeling",
24
- "rhino3dm",
25
- "automation",
26
- "geometry-processing",
27
- "design",
28
- "cloud",
29
- "gh",
30
- "rhino.compute",
31
- "computational-design"
32
- ],
33
- "main": "./dist/index.js",
34
- "module": "./dist/index.js",
35
- "types": "./dist/index.d.ts",
36
- "exports": {
37
- ".": {
38
- "types": "./dist/index.d.ts",
39
- "import": "./dist/index.js",
40
- "require": "./dist/index.cjs"
41
- },
42
- "./grasshopper": {
43
- "types": "./dist/grasshopper.d.ts",
44
- "import": "./dist/grasshopper.js",
45
- "require": "./dist/grasshopper.cjs"
46
- },
47
- "./visualization": {
48
- "types": "./dist/visualization.d.ts",
49
- "import": "./dist/visualization.js",
50
- "require": "./dist/visualization.cjs"
51
- },
52
- "./files": {
53
- "types": "./dist/files.d.ts",
54
- "import": "./dist/files.js",
55
- "require": "./dist/files.cjs"
56
- },
57
- "./core": {
58
- "types": "./dist/core.d.ts",
59
- "import": "./dist/core.js",
60
- "require": "./dist/core.cjs"
61
- }
62
- },
63
- "files": [
64
- "dist",
65
- "README.md",
66
- "LICENSE.md"
67
- ],
68
- "engines": {
69
- "node": ">=20.0.0"
70
- },
71
- "publishConfig": {
72
- "access": "public"
73
- },
74
- "sideEffects": false,
75
- "scripts": {
76
- "build": " pnpm type-check && pnpm clean && tsup",
77
- "dev": "tsup --watch",
78
- "clean": "node --input-type=module -e \"import fs from 'fs'; fs.rmSync('dist', { recursive: true, force: true })\"",
79
- "test": "vitest",
80
- "test:watch": "vitest watch",
81
- "type-check": "tsc --noEmit",
82
- "prepublishOnly": "pnpm build",
83
- "release": "changeset publish"
84
- },
85
- "dependencies": {
86
- "compute-rhino3d": "0.13.0-beta",
87
- "fflate": "^0.8.2",
88
- "rhino3dm": "8.9.0"
89
- },
90
- "peerDependencies": {
91
- "three": ">=0.179.0"
92
- },
93
- "peerDependenciesMeta": {
94
- "three": {
95
- "optional": true
96
- }
97
- },
98
- "devDependencies": {
99
- "@changesets/cli": "^2.29.8",
100
- "@eslint/js": "^9.39.2",
101
- "@types/node": "^25.0.8",
102
- "@types/three": "^0.182.0",
103
- "esbuild-plugin-file-path-extensions": "^2.1.4",
104
- "eslint": "^9.39.2",
105
- "eslint-config-prettier": "^10.1.8",
106
- "eslint-plugin-svelte": "^3.14.0",
107
- "globals": "^17.0.0",
108
- "prettier": "^3.7.4",
109
- "prettier-plugin-svelte": "^3.4.1",
110
- "prettier-plugin-tailwindcss": "^0.7.2",
111
- "svelte": "^5.46.3",
112
- "three": "^0.182.0",
113
- "tsup": "^8.5.0",
114
- "typescript-eslint": "^8.53.0",
115
- "vitest": "^3.2.4"
116
- }
117
- }
2
+ "name": "selva-compute",
3
+ "version": "1.0.1",
4
+ "description": "TypeScript library for Rhino Compute Server - Grasshopper and RhinoCommon",
5
+ "author": "VektorNode",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "keywords": [
9
+ "compute",
10
+ "rhino",
11
+ "grasshopper",
12
+ "geometry",
13
+ "3d",
14
+ "cad",
15
+ "parametric",
16
+ "modeling",
17
+ "rhino3dm",
18
+ "automation",
19
+ "geometry-processing",
20
+ "design",
21
+ "cloud",
22
+ "gh",
23
+ "rhino.compute",
24
+ "computational-design"
25
+ ],
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.cjs"
34
+ },
35
+ "./grasshopper": {
36
+ "types": "./dist/grasshopper.d.ts",
37
+ "import": "./dist/grasshopper.js",
38
+ "require": "./dist/grasshopper.cjs"
39
+ },
40
+ "./visualization": {
41
+ "types": "./dist/visualization.d.ts",
42
+ "import": "./dist/visualization.js",
43
+ "require": "./dist/visualization.cjs"
44
+ },
45
+ "./files": {
46
+ "types": "./dist/files.d.ts",
47
+ "import": "./dist/files.js",
48
+ "require": "./dist/files.cjs"
49
+ },
50
+ "./core": {
51
+ "types": "./dist/core.d.ts",
52
+ "import": "./dist/core.js",
53
+ "require": "./dist/core.cjs"
54
+ }
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "README.md",
59
+ "LICENSE.md"
60
+ ],
61
+ "engines": {
62
+ "node": ">=20.0.0"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "sideEffects": false,
68
+ "dependencies": {
69
+ "compute-rhino3d": "0.13.0-beta",
70
+ "fflate": "^0.8.2",
71
+ "rhino3dm": "8.9.0"
72
+ },
73
+ "peerDependencies": {
74
+ "three": ">=0.179.0"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "three": {
78
+ "optional": true
79
+ }
80
+ },
81
+ "devDependencies": {
82
+ "@changesets/cli": "^2.29.8",
83
+ "@eslint/js": "^9.39.2",
84
+ "@types/node": "^25.0.8",
85
+ "@types/three": "^0.182.0",
86
+ "esbuild-plugin-file-path-extensions": "^2.1.4",
87
+ "eslint": "^9.39.2",
88
+ "eslint-config-prettier": "^10.1.8",
89
+ "eslint-plugin-svelte": "^3.14.0",
90
+ "globals": "^17.0.0",
91
+ "prettier": "^3.7.4",
92
+ "prettier-plugin-svelte": "^3.4.1",
93
+ "prettier-plugin-tailwindcss": "^0.7.2",
94
+ "svelte": "^5.46.3",
95
+ "three": "^0.182.0",
96
+ "tsup": "^8.5.0",
97
+ "typescript-eslint": "^8.53.0",
98
+ "vitest": "^3.2.4"
99
+ },
100
+ "scripts": {
101
+ "build": " pnpm type-check && pnpm clean && tsup",
102
+ "dev": "tsup --watch",
103
+ "clean": "node --input-type=module -e \"import fs from 'fs'; fs.rmSync('dist', { recursive: true, force: true })\"",
104
+ "test": "vitest",
105
+ "test:watch": "vitest watch",
106
+ "type-check": "tsc --noEmit",
107
+ "release": "changeset publish"
108
+ }
109
+ }