@carbonenginejs/runtime-resource 0.1.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FORMAT-PROVENANCE.md +155 -135
- package/LICENSE +21 -21
- package/NOTICE +29 -29
- package/README.md +548 -241
- package/dist/CjsMotherLode.js +1271 -56
- package/dist/CjsMotherLode.js.map +1 -1
- package/dist/CjsResMan.js +3005 -740
- package/dist/CjsResMan.js.map +1 -1
- package/dist/CjsResManQueue.js +214 -214
- package/dist/CjsResource.js +566 -366
- package/dist/CjsResource.js.map +1 -1
- package/dist/CjsResourceSource.js +59 -59
- package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -153
- package/dist/format/CjsBlueReader.js +269 -0
- package/dist/format/CjsBlueReader.js.map +1 -0
- package/dist/format/CjsFormat.js +192 -178
- package/dist/format/CjsFormat.js.map +1 -1
- package/dist/format/CjsReader.js +18 -0
- package/dist/format/CjsReader.js.map +1 -0
- package/dist/format/CjsResourceProbe.js +277 -269
- package/dist/format/CjsResourceProbe.js.map +1 -1
- package/dist/format/payloadContract.js +173 -173
- package/dist/formats/black/CjsBlackFormat.js +278 -272
- package/dist/formats/black/CjsBlackFormat.js.map +1 -1
- package/dist/formats/black/core/CjsBlackBinaryReader.js +153 -153
- package/dist/formats/black/core/CjsBlackPropertyReaders.js +382 -382
- package/dist/formats/black/core/CjsBlackReader.js +639 -760
- package/dist/formats/black/core/CjsBlackReader.js.map +1 -1
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js +433 -433
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +4 -4
- package/dist/formats/black/core/blackConstants.js +7 -7
- package/dist/formats/black/core/blackDefinitions.js +10 -10
- package/dist/formats/black/core/blackEnums.js +6 -6
- package/dist/formats/black/core/blackSchema.js +3 -3
- package/dist/formats/black/core/blackVersion.js +22 -22
- package/dist/formats/black/core/helpers.js +182 -182
- package/dist/formats/black/core/schema.js +4 -4
- package/dist/formats/black/index.js +2 -2
- package/dist/formats/bnk/CjsBnkFormat.js +238 -245
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/graph.js +140 -0
- package/dist/formats/bnk/core/graph.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +409 -354
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/musicNodes.js +521 -0
- package/dist/formats/bnk/core/musicNodes.js.map +1 -0
- package/dist/formats/bnk/core/soundbanksInfo.js +246 -246
- package/dist/formats/bnk/index.js +2 -3
- package/dist/formats/bnk/index.js.map +1 -1
- package/dist/formats/cmf/CjsCmfFormat.js +497 -491
- package/dist/formats/cmf/CjsCmfFormat.js.map +1 -1
- package/dist/formats/cmf/core/binary.js +118 -118
- package/dist/formats/cmf/core/buffers.js +233 -233
- package/dist/formats/cmf/core/constants.js +47 -47
- package/dist/formats/cmf/core/gr2Anim.js +453 -453
- package/dist/formats/cmf/core/helpers.js +287 -287
- package/dist/formats/cmf/core/pack.js +276 -276
- package/dist/formats/cmf/core/schema.js +364 -364
- package/dist/formats/cmf/core/shared.js +268 -268
- package/dist/formats/cmf/core/writer.js +517 -517
- package/dist/formats/cmf/index.js +2 -2
- package/dist/formats/dds/CjsDdsFormat.js +193 -187
- package/dist/formats/dds/CjsDdsFormat.js.map +1 -1
- package/dist/formats/dds/core/bc6h.js +288 -0
- package/dist/formats/dds/core/bc6h.js.map +1 -0
- package/dist/formats/dds/core/bc7.js +251 -0
- package/dist/formats/dds/core/bc7.js.map +1 -0
- package/dist/formats/dds/core/helpers.js +815 -812
- package/dist/formats/dds/core/helpers.js.map +1 -1
- package/dist/formats/dds/index.js +2 -2
- package/dist/formats/fbx/CjsFbxFormat.js +266 -260
- package/dist/formats/fbx/CjsFbxFormat.js.map +1 -1
- package/dist/formats/fbx/core/helpers.js +3901 -3901
- package/dist/formats/fbx/index.js +2 -2
- package/dist/formats/flac/CjsFlacFormat.js +87 -81
- package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
- package/dist/formats/flac/core/helpers.js +295 -295
- package/dist/formats/flac/index.js +2 -2
- package/dist/formats/gif/CjsGifFormat.js +87 -81
- package/dist/formats/gif/CjsGifFormat.js.map +1 -1
- package/dist/formats/gif/core/helpers.js +360 -360
- package/dist/formats/gif/index.js +2 -2
- package/dist/formats/gltf/CjsGltfFormat.js +290 -284
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -1
- package/dist/formats/gltf/core/helpers.js +292 -292
- package/dist/formats/gltf/core/json.js +79 -79
- package/dist/formats/gltf/core/parser.js +666 -666
- package/dist/formats/gltf/core/targets.js +163 -163
- package/dist/formats/gltf/index.js +2 -2
- package/dist/formats/index.js +23 -23
- package/dist/formats/jpeg/CjsJpegFormat.js +206 -200
- package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -1
- package/dist/formats/jpeg/core/helpers.js +350 -350
- package/dist/formats/jpeg/core/jpeg.js +377 -377
- package/dist/formats/jpeg/index.js +2 -2
- package/dist/formats/mp3/CjsMp3Format.js +192 -186
- package/dist/formats/mp3/CjsMp3Format.js.map +1 -1
- package/dist/formats/mp3/core/helpers.js +338 -338
- package/dist/formats/mp3/index.js +2 -2
- package/dist/formats/mp4/CjsMp4Format.js +191 -185
- package/dist/formats/mp4/CjsMp4Format.js.map +1 -1
- package/dist/formats/mp4/core/helpers.js +449 -449
- package/dist/formats/mp4/index.js +2 -2
- package/dist/formats/obj/CjsObjFormat.js +253 -247
- package/dist/formats/obj/CjsObjFormat.js.map +1 -1
- package/dist/formats/obj/core/helpers.js +573 -573
- package/dist/formats/obj/core/json.js +64 -64
- package/dist/formats/obj/core/parser.js +321 -321
- package/dist/formats/obj/index.js +2 -2
- package/dist/formats/ogg/CjsOggFormat.js +88 -82
- package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
- package/dist/formats/ogg/core/helpers.js +387 -387
- package/dist/formats/ogg/core/imdct.js +178 -178
- package/dist/formats/ogg/core/vorbis.js +999 -999
- package/dist/formats/ogg/index.js +2 -2
- package/dist/formats/png/CjsPngFormat.js +195 -189
- package/dist/formats/png/CjsPngFormat.js.map +1 -1
- package/dist/formats/png/core/helpers.js +583 -583
- package/dist/formats/png/index.js +2 -2
- package/dist/formats/red/CjsRedFormat.js +261 -247
- package/dist/formats/red/CjsRedFormat.js.map +1 -1
- package/dist/formats/red/core/CjsRedReader.js +194 -201
- package/dist/formats/red/core/CjsRedReader.js.map +1 -1
- package/dist/formats/red/core/blackDefinitions.js +3 -3
- package/dist/formats/red/core/helpers.js +139 -136
- package/dist/formats/red/core/helpers.js.map +1 -1
- package/dist/formats/red/core/redGraph.js +68 -68
- package/dist/formats/red/core/schema.js +4 -4
- package/dist/formats/red/index.js +2 -2
- package/dist/formats/stl/CjsStlFormat.js +365 -304
- package/dist/formats/stl/CjsStlFormat.js.map +1 -1
- package/dist/formats/stl/core/helpers.js +261 -257
- package/dist/formats/stl/core/helpers.js.map +1 -1
- package/dist/formats/stl/core/json.js +51 -51
- package/dist/formats/stl/core/stl.js +629 -544
- package/dist/formats/stl/core/stl.js.map +1 -1
- package/dist/formats/stl/core/targets.js +163 -163
- package/dist/formats/stl/index.js +2 -2
- package/dist/formats/tga/CjsTgaFormat.js +192 -186
- package/dist/formats/tga/CjsTgaFormat.js.map +1 -1
- package/dist/formats/tga/core/helpers.js +446 -446
- package/dist/formats/tga/index.js +2 -2
- package/dist/formats/wav/CjsWavFormat.js +192 -186
- package/dist/formats/wav/CjsWavFormat.js.map +1 -1
- package/dist/formats/wav/core/helpers.js +328 -328
- package/dist/formats/wav/index.js +2 -2
- package/dist/formats/webm/CjsWebmFormat.js +191 -185
- package/dist/formats/webm/CjsWebmFormat.js.map +1 -1
- package/dist/formats/webm/core/helpers.js +537 -537
- package/dist/formats/webm/index.js +2 -2
- package/dist/formats/webp/CjsWebpFormat.js +86 -80
- package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
- package/dist/formats/webp/core/helpers.js +214 -214
- package/dist/formats/webp/index.js +2 -2
- package/dist/formats/wem/CjsWemFormat.js +241 -197
- package/dist/formats/wem/CjsWemFormat.js.map +1 -1
- package/dist/formats/wem/core/bitStream.js +259 -259
- package/dist/formats/wem/core/codebookLibrary.js +164 -164
- package/dist/formats/wem/core/helpers.js +417 -336
- package/dist/formats/wem/core/helpers.js.map +1 -1
- package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
- package/dist/formats/wem/core/ptadpcm.js +77 -0
- package/dist/formats/wem/core/ptadpcm.js.map +1 -0
- package/dist/formats/wem/core/resolve.js +121 -0
- package/dist/formats/wem/core/resolve.js.map +1 -0
- package/dist/formats/wem/core/wemToOgg.js +485 -485
- package/dist/formats/wem/index.js +2 -2
- package/dist/formats/yaml/CjsYamlFormat.js +83 -77
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
- package/dist/formats/yaml/core/CjsYamlReader.js +305 -304
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
- package/dist/formats/yaml/core/helpers.js +160 -160
- package/dist/formats/yaml/index.js +2 -2
- package/dist/index.js +48 -52
- package/dist/index.js.map +1 -1
- package/dist/resourcePath.js +18 -18
- package/dist/resourceStates.js +9 -9
- package/dist/{generated/resources → resources}/AudioGeometryResData.js +47 -47
- package/dist/resources/AudioGeometryResData.js.map +1 -0
- package/dist/{generated/resources → resources}/GStateBindingCallbackData.js +31 -31
- package/dist/resources/GStateBindingCallbackData.js.map +1 -0
- package/dist/{generated/resources → resources}/MeshDecalData.js +37 -37
- package/dist/resources/MeshDecalData.js.map +1 -0
- package/dist/{generated/resources → resources}/MeshDecalLodData.js +34 -34
- package/dist/resources/MeshDecalLodData.js.map +1 -0
- package/dist/resources/Tr2EffectRes.js +71 -71
- package/dist/resources/Tr2GrannyIntersectionResult.js +60 -0
- package/dist/resources/Tr2GrannyIntersectionResult.js.map +1 -0
- package/dist/resources/Tr2GrannyStateRes.js +44 -44
- package/dist/resources/Tr2ImageRes.js +114 -114
- package/dist/resources/Tr2LightProfileRes.js +40 -40
- package/dist/{generated/resources → resources}/Tr2MaterialArea.js +34 -34
- package/dist/resources/Tr2MaterialArea.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2MaterialMesh.js +31 -31
- package/dist/resources/Tr2MaterialMesh.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2MaterialRes.js +34 -34
- package/dist/resources/Tr2MaterialRes.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2ShaderPermutation.js +43 -43
- package/dist/resources/Tr2ShaderPermutation.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TextureLodManager.js +100 -60
- package/dist/resources/Tr2TextureLodManager.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TextureLodUpdateRequest.js +37 -37
- package/dist/resources/Tr2TextureLodUpdateRequest.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePackChannel.js +37 -37
- package/dist/resources/Tr2TexturePackChannel.js.map +1 -0
- package/dist/resources/Tr2TexturePipeline.js +68 -0
- package/dist/resources/Tr2TexturePipeline.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePipelineParams.js +34 -34
- package/dist/resources/Tr2TexturePipelineParams.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePipelineStepCompress.js +40 -40
- package/dist/resources/Tr2TexturePipelineStepCompress.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePipelineStepLimitSize.js +34 -34
- package/dist/resources/Tr2TexturePipelineStepLimitSize.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePipelineStepLoad.js +31 -31
- package/dist/resources/Tr2TexturePipelineStepLoad.js.map +1 -0
- package/dist/{generated/resources → resources}/Tr2TexturePipelineStepPack.js +43 -43
- package/dist/resources/Tr2TexturePipelineStepPack.js.map +1 -0
- package/dist/resources/TriGeometryRes.js +239 -216
- package/dist/resources/TriGeometryRes.js.map +1 -1
- package/dist/{generated/resources → resources}/TriGeometryResAreaData.js +59 -59
- package/dist/resources/TriGeometryResAreaData.js.map +1 -0
- package/dist/{generated/resources → resources}/TriGeometryResJointData.js +38 -38
- package/dist/resources/TriGeometryResJointData.js.map +1 -0
- package/dist/{generated/resources → resources}/TriGeometryResLodData.js +88 -88
- package/dist/resources/TriGeometryResLodData.js.map +1 -0
- package/dist/{generated/resources → resources}/TriGeometryResMeshData.js +63 -63
- package/dist/resources/TriGeometryResMeshData.js.map +1 -0
- package/dist/{generated/resources → resources}/TriGeometryResSkeletonData.js +34 -34
- package/dist/resources/TriGeometryResSkeletonData.js.map +1 -0
- package/dist/resources/TriGrannyRes.js +43 -43
- package/dist/{generated/resources → resources}/TriJointBinding.js +38 -38
- package/dist/resources/TriJointBinding.js.map +1 -0
- package/dist/{generated/resources → resources}/TriMorphTargetGeometryConstants.js +46 -46
- package/dist/resources/TriMorphTargetGeometryConstants.js.map +1 -0
- package/dist/{generated/resources → resources}/TriRtGeometryConstants.js +88 -88
- package/dist/resources/TriRtGeometryConstants.js.map +1 -0
- package/dist/resources/TriTextureRes.js +304 -304
- package/dist/{generated/resources → resources}/enums.js +18 -18
- package/dist/resources/enums.js.map +1 -0
- package/dist/resources/resourceBoundary.js +47 -47
- package/dist/resources/texturePipelineBehavior.js +320 -0
- package/dist/resources/texturePipelineBehavior.js.map +1 -0
- package/dist/texture/CjsTextureArrayRes.js +406 -406
- package/dist/texture/CjsTextureParameterProxy.js +133 -133
- package/format-notices/black/LICENSE +21 -21
- package/format-notices/black/NOTICE +47 -47
- package/format-notices/bnk/LICENSE +21 -21
- package/format-notices/bnk/NOTICE +20 -17
- package/format-notices/cmf/LICENSE +21 -21
- package/format-notices/cmf/NOTICE +36 -36
- package/format-notices/dds/LICENSE +21 -21
- package/format-notices/dds/NOTICE +14 -14
- package/format-notices/fbx/LICENSE +21 -21
- package/format-notices/fbx/NOTICE +14 -14
- package/format-notices/flac/LICENSE +21 -21
- package/format-notices/flac/NOTICE +14 -14
- package/format-notices/gif/LICENSE +21 -21
- package/format-notices/gif/NOTICE +14 -14
- package/format-notices/gltf/LICENSE +21 -21
- package/format-notices/gltf/NOTICE +27 -27
- package/format-notices/jpeg/LICENSE +21 -21
- package/format-notices/jpeg/NOTICE +14 -14
- package/format-notices/mp3/LICENSE +21 -21
- package/format-notices/mp3/NOTICE +14 -14
- package/format-notices/mp4/LICENSE +21 -21
- package/format-notices/mp4/NOTICE +14 -14
- package/format-notices/obj/LICENSE +21 -21
- package/format-notices/obj/NOTICE +26 -26
- package/format-notices/ogg/LICENSE +21 -21
- package/format-notices/ogg/NOTICE +28 -28
- package/format-notices/png/LICENSE +21 -21
- package/format-notices/png/NOTICE +14 -14
- package/format-notices/red/LICENSE +21 -21
- package/format-notices/red/NOTICE +31 -31
- package/format-notices/stl/LICENSE +21 -21
- package/format-notices/stl/NOTICE +21 -21
- package/format-notices/tga/LICENSE +21 -21
- package/format-notices/tga/NOTICE +14 -14
- package/format-notices/wav/LICENSE +21 -21
- package/format-notices/wav/NOTICE +14 -14
- package/format-notices/webm/LICENSE +21 -21
- package/format-notices/webm/NOTICE +14 -14
- package/format-notices/webp/LICENSE +21 -21
- package/format-notices/webp/NOTICE +14 -14
- package/format-notices/wem/LICENSE +57 -57
- package/format-notices/wem/NOTICE +33 -33
- package/format-notices/yaml/LICENSE +21 -21
- package/format-notices/yaml/NOTICE +44 -44
- package/package.json +51 -51
- package/resource-lifecycle.md +679 -487
- package/dist/generated/resources/AudioGeometryResData.js.map +0 -1
- package/dist/generated/resources/CmfVertexReader.js +0 -46
- package/dist/generated/resources/CmfVertexReader.js.map +0 -1
- package/dist/generated/resources/GStateBindingCallbackData.js.map +0 -1
- package/dist/generated/resources/MeshDecalData.js.map +0 -1
- package/dist/generated/resources/MeshDecalLodData.js.map +0 -1
- package/dist/generated/resources/Tr2AsyncSave.js +0 -46
- package/dist/generated/resources/Tr2AsyncSave.js.map +0 -1
- package/dist/generated/resources/Tr2CmfContents.js +0 -37
- package/dist/generated/resources/Tr2CmfContents.js.map +0 -1
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js +0 -58
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js.map +0 -1
- package/dist/generated/resources/Tr2LoadPrepareFence.js +0 -37
- package/dist/generated/resources/Tr2LoadPrepareFence.js.map +0 -1
- package/dist/generated/resources/Tr2MaterialArea.js.map +0 -1
- package/dist/generated/resources/Tr2MaterialMesh.js.map +0 -1
- package/dist/generated/resources/Tr2MaterialRes.js.map +0 -1
- package/dist/generated/resources/Tr2ShaderPermutation.js.map +0 -1
- package/dist/generated/resources/Tr2TextureLodManager.js.map +0 -1
- package/dist/generated/resources/Tr2TextureLodUpdateRequest.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePackChannel.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipeline.js +0 -44
- package/dist/generated/resources/Tr2TexturePipeline.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipelineParams.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipelineStepCompress.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipelineStepLoad.js.map +0 -1
- package/dist/generated/resources/Tr2TexturePipelineStepPack.js.map +0 -1
- package/dist/generated/resources/TriGeometryResAreaData.js.map +0 -1
- package/dist/generated/resources/TriGeometryResJointData.js.map +0 -1
- package/dist/generated/resources/TriGeometryResLodData.js.map +0 -1
- package/dist/generated/resources/TriGeometryResMeshData.js.map +0 -1
- package/dist/generated/resources/TriGeometryResSkeletonData.js.map +0 -1
- package/dist/generated/resources/TriJointBinding.js.map +0 -1
- package/dist/generated/resources/TriMorphTargetGeometryConstants.js.map +0 -1
- package/dist/generated/resources/TriRtGeometryConstants.js.map +0 -1
- package/dist/generated/resources/enums.js.map +0 -1
- package/dist/generated/resources/index.js +0 -32
- package/dist/generated/resources/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CjsStlFormat.js","sources":["../../../../src/formats/stl/CjsStlFormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing STL format class.\n *\n * Keep this file small and reviewable: STL parsing, writing, printability\n * inspection, option normalization, and JSON hydration live under src/core.\n */\n\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GR2,\n OUTPUT_JSON,\n OUTPUT_SHARED,\n OUTPUT_STL_JSON,\n importNodeModule,\n inspectWithValues,\n isBinaryStl,\n isStl,\n normalizeValues,\n readWithValues,\n toJsonValue,\n validateClass,\n validateClassKey,\n writeWithValues\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsStlFormat\";\n\n/**\n * CarbonEngineJS-facing STL format surface.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * STL is a triangle-only import/export format; the JSON contract is the shared\n * CarbonEngineJS mesh schema.\n */\nexport class CjsStlFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #binary = DEFAULT_VALUES.binary;\n #solidName = DEFAULT_VALUES.solidName;\n #scale = DEFAULT_VALUES.scale;\n #recalculateNormals = DEFAULT_VALUES.recalculateNormals;\n #weldVertices = DEFAULT_VALUES.weldVertices;\n #weldTolerance = DEFAULT_VALUES.weldTolerance;\n #skipDegenerate = DEFAULT_VALUES.skipDegenerate;\n #requireWatertight = DEFAULT_VALUES.requireWatertight;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * @param {object} [options] Default format values.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {object} [options] Values to merge into the profile.\n * @returns {CjsStlFormat} This format profile.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#binary = values.binary;\n this.#solidName = values.solidName;\n this.#scale = values.scale;\n this.#recalculateNormals = values.recalculateNormals;\n this.#weldVertices = values.weldVertices;\n this.#weldTolerance = values.weldTolerance;\n this.#skipDegenerate = values.skipDegenerate;\n this.#requireWatertight = values.requireWatertight;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {object} [options] Optional values to merge into a copy.\n * @returns {object} A copy of the effective values.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n binary: this.#binary,\n solidName: this.#solidName,\n scale: this.#scale,\n recalculateNormals: this.#recalculateNormals,\n weldVertices: this.#weldVertices,\n weldTolerance: this.#weldTolerance,\n skipDegenerate: this.#skipDegenerate,\n requireWatertight: this.#requireWatertight,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this format profile has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read STL text/bytes with this profile's values.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Write shared JSON geometry as STL with this profile's values.\n *\n * @param {object} input Shared JSON root or mesh.\n * @param {object} [options] Per-call value overrides.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n */\n Write(input, options = {})\n {\n return writeWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect STL text/bytes or shared JSON geometry for printability blockers.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain printability report.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static one-shot read. Static methods use camelCase by convention.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Format values.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n static read(input, options = {})\n {\n return readWithValues(CjsStlFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot write.\n *\n * @param {object} input Shared JSON root or mesh.\n * @param {object} [options] Format values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n */\n static write(input, options = {})\n {\n return writeWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Format values.\n * @returns {object} Plain printability report.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Node-only convenience: reads an STL file from disk.\n *\n * @param {string} path Path to an STL file.\n * @param {object} [options] Format values.\n * @returns {Promise<object>} The shared CarbonEngineJS JSON mesh schema.\n */\n static async readFile(path, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);\n }\n\n const { readFile } = await importNodeModule(\"node:fs/promises\");\n const input = await readFile(path);\n return CjsStlFormat.read(input, { source: path, ...options });\n }\n\n /**\n * Node-only convenience: writes an STL file to disk.\n *\n * @param {string} path Path to write.\n * @param {object} input Shared JSON root or mesh.\n * @param {object} [options] Format values.\n * @returns {Promise<string>} The written path.\n */\n static async writeFile(path, input, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: writeFile path must be a non-empty string`);\n }\n\n const { writeFile } = await importNodeModule(\"node:fs/promises\");\n const output = CjsStlFormat.write(input, options);\n await writeFile(path, output);\n return path;\n }\n\n /**\n * Cheap sniff for STL-like input.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input looks like STL.\n */\n static isStl(input)\n {\n return isStl(input);\n }\n\n /**\n * Check whether byte-like input has an exact binary STL layout.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input is binary STL bytes.\n */\n static isBinaryStl(input)\n {\n return isBinaryStl(input);\n }\n\n static OUTPUT_JSON = OUTPUT_JSON;\n static OUTPUT_STL_JSON = OUTPUT_STL_JSON;\n static OUTPUT_SHARED = OUTPUT_SHARED;\n static OUTPUT_GR2 = OUTPUT_GR2;\n static OUTPUT_CMF = OUTPUT_CMF;\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"stl\" ]);\n static outputTypes = Object.freeze([ OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_STL_JSON ]);\n\n}\n\nexport default CjsStlFormat;\n"],"names":["FORMAT_NAME","CjsStlFormat","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Write","writeWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","read","write","inspect","toJSON","readFile","path","TypeError","importNodeModule","writeFile","output","isStl","isBinaryStl","OUTPUT_JSON","OUTPUT_STL_JSON","OUTPUT_SHARED","OUTPUT_GR2","OUTPUT_CMF","CLASS_KEYS","Object","freeze","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAsBA,MAAMA,WAAW,GAAG,cAAc;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,YAAY,CACzB;AAEI,EAAA,KAAK,GAAGC,cAAc,CAACC,IAAI;AAC3B,EAAA,OAAO,GAAGD,cAAc,CAACE,MAAM;AAC/B,EAAA,OAAO,GAAGF,cAAc,CAACG,MAAM;AAC/B,EAAA,UAAU,GAAGH,cAAc,CAACI,SAAS;AACrC,EAAA,MAAM,GAAGJ,cAAc,CAACK,KAAK;AAC7B,EAAA,mBAAmB,GAAGL,cAAc,CAACM,kBAAkB;AACvD,EAAA,aAAa,GAAGN,cAAc,CAACO,YAAY;AAC3C,EAAA,cAAc,GAAGP,cAAc,CAACQ,aAAa;AAC7C,EAAA,eAAe,GAAGR,cAAc,CAACS,cAAc;AAC/C,EAAA,kBAAkB,GAAGT,cAAc,CAACU,iBAAiB;AACrD,EAAA,QAAQ,GAAGV,cAAc,CAACW,OAAO;;AAEjC;AACJ;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;AACI,IAAA,IAAI,CAACC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ormat.js"],"sourcesContent":["/**\n * Exposed CarbonEngineJS-facing STL format class.\n *\n * Keep this file small and reviewable: STL parsing, writing, printability\n * inspection, option normalization, and JSON hydration live under src/core.\n */\n\nimport {\n CLASS_KEYS,\n DEFAULT_VALUES,\n OUTPUT_CMF,\n OUTPUT_GR2,\n OUTPUT_JSON,\n OUTPUT_SHARED,\n OUTPUT_STL_JSON,\n importNodeModule,\n inspectWithValues,\n isBinaryStl,\n isStl,\n normalizeValues,\n readWithValues,\n toJsonValue,\n validateClass,\n validateClassKey,\n writeWithValues\n} from \"./core/helpers.js\";\n\nconst FORMAT_NAME = \"CjsStlFormat\";\n\n/**\n * Shared mesh accepted by the STL writer. STL exports only `vertex.position`\n * and triangular `indices[].faces`; all other shared channels are ignored.\n *\n * @typedef {object} CjsStlSharedMesh\n * @property {string} [name] Diagnostic mesh name; `solidName` controls the STL header.\n * @property {{position: ArrayLike<number>, normal?: ArrayLike<number>}} vertex Shared vertex channels.\n * @property {Array<{name?: string, faces: ArrayLike<number>}>} indices Triangle index groups.\n */\n\n/**\n * Shared geometry root accepted by the STL writer.\n *\n * @typedef {object} CjsStlSharedRoot\n * @property {Array<CjsStlSharedMesh>} meshes Meshes flattened into one STL solid.\n * @property {string} [grannyFileSource] Optional source label used by inspection.\n */\n\n/**\n * Reusable STL read, write, and inspection options.\n *\n * @typedef {object} CjsStlFormatOptions\n * @property {\"shared\"|\"stlJson\"|\"json\"|\"gr2\"|\"cmf\"} [emit=\"stlJson\"] Read output contract.\n * @property {string} [source=\"memory\"] Source label stored in read/inspection output.\n * @property {boolean} [binary=true] Whether writes return binary bytes instead of ASCII text.\n * @property {string} [solidName=\"carbonenginejs\"] Sanitized ASCII solid name and binary header label.\n * @property {number} [scale=1] Positive finite multiplier applied to exported positions.\n * @property {boolean} [recalculateNormals=true] Derive facet normals from winding instead of vertex normals.\n * @property {boolean} [weldVertices=false] Weld equal positions while reading STL.\n * @property {number} [weldTolerance=1e-5] Non-negative read/inspection position tolerance.\n * @property {boolean} [skipDegenerate=true] Omit degenerate shared triangles during writes.\n * @property {boolean} [requireWatertight=false] Reject writes with printability topology issues.\n * @property {Record<string, Function>} [classes] Caller constructors used for read hydration.\n */\n\n/**\n * CarbonEngineJS-facing STL format surface.\n *\n * The Cjs prefix marks this as a JavaScript format/construction boundary.\n * STL is a triangle-only import/export format; the JSON contract is the shared\n * CarbonEngineJS mesh schema.\n */\nexport class CjsStlFormat\n{\n\n #emit = DEFAULT_VALUES.emit;\n #source = DEFAULT_VALUES.source;\n #binary = DEFAULT_VALUES.binary;\n #solidName = DEFAULT_VALUES.solidName;\n #scale = DEFAULT_VALUES.scale;\n #recalculateNormals = DEFAULT_VALUES.recalculateNormals;\n #weldVertices = DEFAULT_VALUES.weldVertices;\n #weldTolerance = DEFAULT_VALUES.weldTolerance;\n #skipDegenerate = DEFAULT_VALUES.skipDegenerate;\n #requireWatertight = DEFAULT_VALUES.requireWatertight;\n #classes = DEFAULT_VALUES.classes;\n\n /**\n * Create a reusable format profile.\n *\n * The instance stores only normalized options; each `Read`, `Write`, or\n * `Inspect` call may provide non-mutating overrides.\n *\n * @param {CjsStlFormatOptions} [options={}] Default format values.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n constructor(options = {})\n {\n this.SetValues(options);\n }\n\n /**\n * Set format values for this reusable profile.\n *\n * @param {CjsStlFormatOptions} [options={}] Values to merge into the profile.\n * @returns {CjsStlFormat} This format profile.\n * @throws {TypeError} If an option, output mode, numeric value, or class map is invalid.\n */\n SetValues(options = {})\n {\n const values = normalizeValues(this.GetValues(), options, FORMAT_NAME);\n\n this.#emit = values.emit;\n this.#source = values.source;\n this.#binary = values.binary;\n this.#solidName = values.solidName;\n this.#scale = values.scale;\n this.#recalculateNormals = values.recalculateNormals;\n this.#weldVertices = values.weldVertices;\n this.#weldTolerance = values.weldTolerance;\n this.#skipDegenerate = values.skipDegenerate;\n this.#requireWatertight = values.requireWatertight;\n this.#classes = values.classes;\n\n return this;\n }\n\n /**\n * Get this profile's current values, optionally with per-call overrides.\n *\n * @param {CjsStlFormatOptions} [options={}] Optional values to merge into a copy.\n * @returns {CjsStlFormatOptions} A validated copy of the effective values.\n * @throws {TypeError} If an override is invalid.\n */\n GetValues(options = {})\n {\n return normalizeValues({\n emit: this.#emit,\n source: this.#source,\n binary: this.#binary,\n solidName: this.#solidName,\n scale: this.#scale,\n recalculateNormals: this.#recalculateNormals,\n weldVertices: this.#weldVertices,\n weldTolerance: this.#weldTolerance,\n skipDegenerate: this.#skipDegenerate,\n requireWatertight: this.#requireWatertight,\n classes: this.#classes\n }, options, FORMAT_NAME);\n }\n\n /**\n * Set multiple node-class constructors for this profile.\n *\n * @param {object} [classes] Map of node class keys to constructors.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClasses(classes = {})\n {\n return this.SetValues({ classes });\n }\n\n /**\n * Set one node-class constructor for this profile.\n *\n * @param {string} type Node class key.\n * @param {Function|null|undefined} Class Constructor to use, or nullish to delete.\n * @returns {CjsStlFormat} This format profile.\n */\n SetClass(type, Class)\n {\n if (Class === null || Class === undefined)\n {\n validateClassKey(type, FORMAT_NAME);\n const classes = { ...this.#classes };\n delete classes[type];\n this.#classes = classes;\n return this;\n }\n\n validateClass(type, Class, FORMAT_NAME);\n return this.SetValues({ classes: { [type]: Class } });\n }\n\n /**\n * Get a configured node-class constructor.\n *\n * @param {string} type Node class key.\n * @returns {Function|undefined} The registered constructor, if any.\n */\n GetClass(type)\n {\n validateClassKey(type, FORMAT_NAME);\n return this.#classes[type];\n }\n\n /**\n * Whether this format profile has a constructor registered for a node class key.\n *\n * @param {string} type Node class key.\n * @returns {boolean} True when a constructor is registered.\n */\n HasClass(type)\n {\n return !!this.GetClass(type);\n }\n\n /**\n * Read STL text/bytes with this profile's values.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n Read(input, options = {})\n {\n return readWithValues(this, input, this.GetValues(options));\n }\n\n /**\n * Write shared JSON geometry as STL with this profile's values.\n *\n * Multiple meshes and index groups are flattened in encounter order because\n * STL has no portable material or scene hierarchy. Degenerate triangles are\n * skipped by default. Binary output validates that every coordinate is\n * representable as float32 rather than silently writing infinities.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Per-call writer overrides.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n Write(input, options = {})\n {\n return writeWithValues(input, this.GetValues(options));\n }\n\n /**\n * Inspect STL text/bytes or shared JSON geometry for printability blockers.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Per-call value overrides.\n * @returns {object} Plain printability report.\n */\n Inspect(input, options = {})\n {\n return inspectWithValues(input, this.GetValues(options));\n }\n\n /**\n * Convert format output to JSON-compatible data.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n ToJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Static one-shot read. Static methods use camelCase by convention.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.\n * @param {object} [options] Format values.\n * @returns {object} The shared CarbonEngineJS JSON mesh schema.\n */\n static read(input, options = {})\n {\n return readWithValues(CjsStlFormat, input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot write.\n *\n * The call is one-shot and does not mutate `input`. Multiple meshes and\n * index groups are flattened into a single STL solid in encounter order.\n *\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Writer values.\n * @returns {string|Uint8Array} ASCII STL text or binary STL bytes.\n * @throws {TypeError|RangeError|Error} If geometry, indices, coordinates, topology, or options are invalid.\n */\n static write(input, options = {})\n {\n return writeWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static one-shot inspection.\n *\n * @param {any} input STL text/bytes or shared JSON root/mesh.\n * @param {object} [options] Format values.\n * @returns {object} Plain printability report.\n */\n static inspect(input, options = {})\n {\n return inspectWithValues(input, normalizeValues(DEFAULT_VALUES, options, FORMAT_NAME));\n }\n\n /**\n * Static JSON-compatible conversion.\n *\n * @param {any} value Format output to convert.\n * @returns {any} Plain JSON-compatible data.\n */\n static toJSON(value)\n {\n return toJsonValue(value);\n }\n\n /**\n * Node-only convenience: reads an STL file from disk.\n *\n * @param {string} path Path to an STL file.\n * @param {object} [options] Format values.\n * @returns {Promise<object>} The shared CarbonEngineJS JSON mesh schema.\n */\n static async readFile(path, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: readFile path must be a non-empty string`);\n }\n\n const { readFile } = await importNodeModule(\"node:fs/promises\");\n const input = await readFile(path);\n return CjsStlFormat.read(input, { source: path, ...options });\n }\n\n /**\n * Node-only convenience: writes an STL file to disk.\n *\n * The file is encoded entirely in memory before the Node-only filesystem\n * write starts. Browser bundles do not include the filesystem module.\n *\n * @param {string} path Path to write.\n * @param {CjsStlSharedRoot|CjsStlSharedMesh} input Shared JSON root or mesh.\n * @param {CjsStlFormatOptions} [options={}] Writer values.\n * @returns {Promise<string>} The written path.\n * @throws {TypeError|RangeError|Error} If the path, geometry, topology, or options are invalid, or writing fails.\n */\n static async writeFile(path, input, options = {})\n {\n if (typeof path !== \"string\" || !path)\n {\n throw new TypeError(`${FORMAT_NAME}: writeFile path must be a non-empty string`);\n }\n\n const { writeFile } = await importNodeModule(\"node:fs/promises\");\n const output = CjsStlFormat.write(input, options);\n await writeFile(path, output);\n return path;\n }\n\n /**\n * Cheap sniff for STL-like input.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input looks like STL.\n */\n static isStl(input)\n {\n return isStl(input);\n }\n\n /**\n * Check whether byte-like input has an exact binary STL layout.\n *\n * @param {string|Uint8Array|ArrayBuffer|DataView} input Candidate STL input.\n * @returns {boolean} True when input is binary STL bytes.\n */\n static isBinaryStl(input)\n {\n return isBinaryStl(input);\n }\n\n /**\n * Emit targets for this format (canonical frozen enum).\n */\n static Output = Object.freeze({\n JSON: OUTPUT_JSON,\n STL_JSON: OUTPUT_STL_JSON,\n SHARED: OUTPUT_SHARED,\n GR2: OUTPUT_GR2,\n CMF: OUTPUT_CMF\n });\n static CLASS_KEYS = CLASS_KEYS;\n static type = Object.freeze([ \"geometry\" ]);\n static mediaTypes = Object.freeze([ \"geometry\" ]);\n static inputTypes = Object.freeze([ \"stl\" ]);\n static outputTypes = Object.freeze([ OUTPUT_SHARED, OUTPUT_GR2, OUTPUT_CMF ]);\n static debugOutputTypes = Object.freeze([ OUTPUT_JSON, OUTPUT_STL_JSON ]);\n\n}\n\nexport default CjsStlFormat;\n"],"names":["FORMAT_NAME","CjsStlFormat","DEFAULT_VALUES","emit","source","binary","solidName","scale","recalculateNormals","weldVertices","weldTolerance","skipDegenerate","requireWatertight","classes","constructor","options","SetValues","values","normalizeValues","GetValues","SetClasses","SetClass","type","Class","undefined","validateClassKey","validateClass","GetClass","HasClass","Read","input","readWithValues","Write","writeWithValues","Inspect","inspectWithValues","ToJSON","value","toJsonValue","read","write","inspect","toJSON","readFile","path","TypeError","importNodeModule","writeFile","output","isStl","isBinaryStl","Output","Object","freeze","JSON","OUTPUT_JSON","STL_JSON","OUTPUT_STL_JSON","SHARED","OUTPUT_SHARED","GR2","OUTPUT_GR2","CMF","OUTPUT_CMF","CLASS_KEYS","mediaTypes","inputTypes","outputTypes","debugOutputTypes"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAsBA,MAAMA,WAAW,GAAG,cAAc;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;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ACI,OAAOoB,WAAWA,CAACpB,KAAK,EACxB;IACI,OAAOoB,WAAW,CAACpB,KAAK,CAAC;AAC7B,EAAA;;AAEA;AACJ;AACA;AACI,EAAA,OAAOqB,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC1BC,IAAAA,IAAI,EAAEC,WAAW;AACjBC,IAAAA,QAAQ,EAAEC,eAAe;AACzBC,IAAAA,MAAM,EAAEC,aAAa;AACrBC,IAAAA,GAAG,EAAEC,UAAU;AACfC,IAAAA,GAAG,EAAEC;AACT,GAAC,CAAC;EACF,OAAOC,UAAU,GAAGA,UAAU;EAC9B,OAAO1C,IAAI,GAAG8B,MAAM,CAACC,MAAM,CAAC,CAAE,UAAU,CAAE,CAAC;EAC3C,OAAOY,UAAU,GAAGb,MAAM,CAACC,MAAM,CAAC,CAAE,UAAU,CAAE,CAAC;EACjD,OAAOa,UAAU,GAAGd,MAAM,CAACC,MAAM,CAAC,CAAE,KAAK,CAAE,CAAC;AAC5C,EAAA,OAAOc,WAAW,GAAGf,MAAM,CAACC,MAAM,CAAC,CAAEM,aAAa,EAAEE,UAAU,EAAEE,UAAU,CAAE,CAAC;EAC7E,OAAOK,gBAAgB,GAAGhB,MAAM,CAACC,MAAM,CAAC,CAAEE,WAAW,EAAEE,eAAe,CAAE,CAAC;AAE7E;;;;"}
|
|
@@ -1,257 +1,261 @@
|
|
|
1
|
-
import { hydrateJson } from './json.js';
|
|
2
|
-
import { CMF_CLASS_KEYS, hydrateCmf, buildCmfFromShared } from './targets.js';
|
|
3
|
-
import { parseStl, trianglesToJson, jsonToTriangles, inspectTriangles, writeBinaryStl, writeAsciiStl, trianglesFromInput } from './stl.js';
|
|
4
|
-
export { isBinaryStl, isStl, toText } from './stl.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal pipeline glue for CjsStlFormat.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const GR2_CLASS_KEYS = Object.freeze(["Root", "Mesh", "BoneBinding", "IndexGroup", "MorphTarget", "Model", "Skeleton", "Bone", "Animation", "TrackGroup", "TransformTrack", "Curve"]);
|
|
11
|
-
const CLASS_KEYS = Object.freeze(Array.from(new Set([...GR2_CLASS_KEYS, ...CMF_CLASS_KEYS])));
|
|
12
|
-
const OUTPUT_JSON = "json";
|
|
13
|
-
const OUTPUT_STL_JSON = "stlJson";
|
|
14
|
-
const OUTPUT_SHARED = "shared";
|
|
15
|
-
const OUTPUT_GR2 = "gr2";
|
|
16
|
-
const OUTPUT_CMF = "cmf";
|
|
17
|
-
const DEFAULT_VALUES = Object.freeze({
|
|
18
|
-
emit: OUTPUT_STL_JSON,
|
|
19
|
-
source: "memory",
|
|
20
|
-
binary: true,
|
|
21
|
-
solidName: "carbonenginejs",
|
|
22
|
-
scale: 1,
|
|
23
|
-
recalculateNormals: true,
|
|
24
|
-
weldVertices: false,
|
|
25
|
-
weldTolerance: 1e-5,
|
|
26
|
-
skipDegenerate: true,
|
|
27
|
-
requireWatertight: false,
|
|
28
|
-
classes: Object.freeze({})
|
|
29
|
-
});
|
|
30
|
-
const OPTION_KEYS = new Set(["emit", "source", "binary", "solidName", "scale", "recalculateNormals", "weldVertices", "weldTolerance", "skipDegenerate", "requireWatertight", "classes"]);
|
|
31
|
-
function validateBoolean(name, value, readerName) {
|
|
32
|
-
if (typeof value === "boolean") return value;
|
|
33
|
-
throw new TypeError(`${readerName}: ${name} must be true or false`);
|
|
34
|
-
}
|
|
35
|
-
function validateNumber(name, value, readerName, {
|
|
36
|
-
minExclusive = null,
|
|
37
|
-
minInclusive = null
|
|
38
|
-
} = {}) {
|
|
39
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
40
|
-
throw new TypeError(`${readerName}: ${name} must be a finite number`);
|
|
41
|
-
}
|
|
42
|
-
if (minExclusive !== null && value <= minExclusive) {
|
|
43
|
-
throw new TypeError(`${readerName}: ${name} must be greater than ${minExclusive}`);
|
|
44
|
-
}
|
|
45
|
-
if (minInclusive !== null && value < minInclusive) {
|
|
46
|
-
throw new TypeError(`${readerName}: ${name} must be at least ${minInclusive}`);
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Validate a `classes` node key against {@link CLASS_KEYS}.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} key Candidate node key.
|
|
55
|
-
* @param {string} [readerName] Format name used in thrown errors.
|
|
56
|
-
*/
|
|
57
|
-
function validateClassKey(key, readerName = "CjsStlFormat") {
|
|
58
|
-
if (!CLASS_KEYS.includes(key)) {
|
|
59
|
-
throw new Error(`${readerName}: unknown class key ${JSON.stringify(key)}; expected one of ${CLASS_KEYS.join(", ")}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Validate a single `classes` entry.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} key Node key.
|
|
67
|
-
* @param {Function} Class Candidate constructor.
|
|
68
|
-
* @param {string} [readerName] Format name used in thrown errors.
|
|
69
|
-
*/
|
|
70
|
-
function validateClass(key, Class, readerName = "CjsStlFormat") {
|
|
71
|
-
validateClassKey(key, readerName);
|
|
72
|
-
if (typeof Class !== "function") {
|
|
73
|
-
throw new TypeError(`${readerName}: class ${JSON.stringify(key)} must be a constructor`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function mergeClasses(base, classes, readerName) {
|
|
77
|
-
if (!classes || typeof classes !== "object") {
|
|
78
|
-
throw new TypeError(`${readerName}: classes option must be an object`);
|
|
79
|
-
}
|
|
80
|
-
const next = {
|
|
81
|
-
...base
|
|
82
|
-
};
|
|
83
|
-
for (const [key, Class] of Object.entries(classes)) {
|
|
84
|
-
if (Class === null || Class === undefined) {
|
|
85
|
-
delete next[key];
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
validateClass(key, Class, readerName);
|
|
89
|
-
next[key] = Class;
|
|
90
|
-
}
|
|
91
|
-
return next;
|
|
92
|
-
}
|
|
93
|
-
function sanitizeName(value) {
|
|
94
|
-
if (typeof value !== "string" || !value.trim()) return DEFAULT_VALUES.solidName;
|
|
95
|
-
return value.trim();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Merge format values over a base set and validate them.
|
|
100
|
-
*
|
|
101
|
-
* @param {object} base Current values.
|
|
102
|
-
* @param {object} [options] Values to merge in.
|
|
103
|
-
* @param {string} [readerName] Format name used in error messages.
|
|
104
|
-
* @returns {object} A validated copy of the merged values.
|
|
105
|
-
*/
|
|
106
|
-
function normalizeValues(base, options = {}, readerName = "CjsStlFormat") {
|
|
107
|
-
if (!options || typeof options !== "object") {
|
|
108
|
-
throw new TypeError(`${readerName}: options must be an object`);
|
|
109
|
-
}
|
|
110
|
-
for (const key of Object.keys(options)) {
|
|
111
|
-
if (!OPTION_KEYS.has(key)) {
|
|
112
|
-
throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const values = {
|
|
116
|
-
...base,
|
|
117
|
-
...options
|
|
118
|
-
};
|
|
119
|
-
const emit = normalizeEmit(values.emit, readerName);
|
|
120
|
-
const classes = Object.prototype.hasOwnProperty.call(options, "classes") ? mergeClasses(base.classes || {}, options.classes, readerName) : {
|
|
121
|
-
...(base.classes || {})
|
|
122
|
-
};
|
|
123
|
-
if ((emit === OUTPUT_GR2 || emit === OUTPUT_CMF) && !hasClasses(classes)) {
|
|
124
|
-
throw new TypeError(`${readerName}: emit "${emit}" requires explicit classes`);
|
|
125
|
-
}
|
|
126
|
-
if (typeof values.source !== "string" || !values.source) {
|
|
127
|
-
values.source = DEFAULT_VALUES.source;
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
emit,
|
|
131
|
-
source: values.source,
|
|
132
|
-
binary: validateBoolean("binary", values.binary, readerName),
|
|
133
|
-
solidName: sanitizeName(values.solidName),
|
|
134
|
-
scale: validateNumber("scale", values.scale, readerName, {
|
|
135
|
-
minExclusive: 0
|
|
136
|
-
}),
|
|
137
|
-
recalculateNormals: validateBoolean("recalculateNormals", values.recalculateNormals, readerName),
|
|
138
|
-
weldVertices: validateBoolean("weldVertices", values.weldVertices, readerName),
|
|
139
|
-
weldTolerance: validateNumber("weldTolerance", values.weldTolerance, readerName, {
|
|
140
|
-
minInclusive: 0
|
|
141
|
-
}),
|
|
142
|
-
skipDegenerate: validateBoolean("skipDegenerate", values.skipDegenerate, readerName),
|
|
143
|
-
requireWatertight: validateBoolean("requireWatertight", values.requireWatertight, readerName),
|
|
144
|
-
classes
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function normalizeEmit(emit, readerName) {
|
|
148
|
-
if (emit === undefined || emit === null || emit === OUTPUT_JSON || emit === OUTPUT_STL_JSON || emit === OUTPUT_SHARED) {
|
|
149
|
-
return OUTPUT_STL_JSON;
|
|
150
|
-
}
|
|
151
|
-
if (emit === OUTPUT_GR2 || emit === OUTPUT_CMF) return emit;
|
|
152
|
-
throw new TypeError(`${readerName}: emit must be "${OUTPUT_SHARED}", "${OUTPUT_STL_JSON}", "${OUTPUT_GR2}", or "${OUTPUT_CMF}", got ${JSON.stringify(emit)}`);
|
|
153
|
-
}
|
|
154
|
-
function hasClasses(classes) {
|
|
155
|
-
return !!classes && Object.values(classes).some(Class => typeof Class === "function");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Read STL text/bytes and return the shared JSON schema.
|
|
160
|
-
*
|
|
161
|
-
* @param {object|Function} format Format instance or constructor.
|
|
162
|
-
* @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.
|
|
163
|
-
* @param {object} values Normalized format values.
|
|
164
|
-
* @returns {object} Shared JSON graph.
|
|
165
|
-
*/
|
|
166
|
-
function readWithValues(format, input, values) {
|
|
167
|
-
const parsed = parseStl(input);
|
|
168
|
-
const json = trianglesToJson(parsed.triangles, values, parsed);
|
|
169
|
-
if (values.emit === OUTPUT_CMF) return hydrateCmf(buildCmfFromShared(json), values.classes, {
|
|
170
|
-
source: values.source
|
|
171
|
-
});
|
|
172
|
-
return hydrateJson(json, {
|
|
173
|
-
classes: values.classes,
|
|
174
|
-
source: values.source
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Write the shared JSON geometry schema to STL.
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
1
|
+
import { hydrateJson } from './json.js';
|
|
2
|
+
import { CMF_CLASS_KEYS, hydrateCmf, buildCmfFromShared } from './targets.js';
|
|
3
|
+
import { parseStl, trianglesToJson, jsonToTriangles, inspectTriangles, writeBinaryStl, writeAsciiStl, trianglesFromInput } from './stl.js';
|
|
4
|
+
export { isBinaryStl, isStl, toText } from './stl.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal pipeline glue for CjsStlFormat.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const GR2_CLASS_KEYS = Object.freeze(["Root", "Mesh", "BoneBinding", "IndexGroup", "MorphTarget", "Model", "Skeleton", "Bone", "Animation", "TrackGroup", "TransformTrack", "Curve"]);
|
|
11
|
+
const CLASS_KEYS = Object.freeze(Array.from(new Set([...GR2_CLASS_KEYS, ...CMF_CLASS_KEYS])));
|
|
12
|
+
const OUTPUT_JSON = "json";
|
|
13
|
+
const OUTPUT_STL_JSON = "stlJson";
|
|
14
|
+
const OUTPUT_SHARED = "shared";
|
|
15
|
+
const OUTPUT_GR2 = "gr2";
|
|
16
|
+
const OUTPUT_CMF = "cmf";
|
|
17
|
+
const DEFAULT_VALUES = Object.freeze({
|
|
18
|
+
emit: OUTPUT_STL_JSON,
|
|
19
|
+
source: "memory",
|
|
20
|
+
binary: true,
|
|
21
|
+
solidName: "carbonenginejs",
|
|
22
|
+
scale: 1,
|
|
23
|
+
recalculateNormals: true,
|
|
24
|
+
weldVertices: false,
|
|
25
|
+
weldTolerance: 1e-5,
|
|
26
|
+
skipDegenerate: true,
|
|
27
|
+
requireWatertight: false,
|
|
28
|
+
classes: Object.freeze({})
|
|
29
|
+
});
|
|
30
|
+
const OPTION_KEYS = new Set(["emit", "source", "binary", "solidName", "scale", "recalculateNormals", "weldVertices", "weldTolerance", "skipDegenerate", "requireWatertight", "classes"]);
|
|
31
|
+
function validateBoolean(name, value, readerName) {
|
|
32
|
+
if (typeof value === "boolean") return value;
|
|
33
|
+
throw new TypeError(`${readerName}: ${name} must be true or false`);
|
|
34
|
+
}
|
|
35
|
+
function validateNumber(name, value, readerName, {
|
|
36
|
+
minExclusive = null,
|
|
37
|
+
minInclusive = null
|
|
38
|
+
} = {}) {
|
|
39
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
40
|
+
throw new TypeError(`${readerName}: ${name} must be a finite number`);
|
|
41
|
+
}
|
|
42
|
+
if (minExclusive !== null && value <= minExclusive) {
|
|
43
|
+
throw new TypeError(`${readerName}: ${name} must be greater than ${minExclusive}`);
|
|
44
|
+
}
|
|
45
|
+
if (minInclusive !== null && value < minInclusive) {
|
|
46
|
+
throw new TypeError(`${readerName}: ${name} must be at least ${minInclusive}`);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Validate a `classes` node key against {@link CLASS_KEYS}.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} key Candidate node key.
|
|
55
|
+
* @param {string} [readerName] Format name used in thrown errors.
|
|
56
|
+
*/
|
|
57
|
+
function validateClassKey(key, readerName = "CjsStlFormat") {
|
|
58
|
+
if (!CLASS_KEYS.includes(key)) {
|
|
59
|
+
throw new Error(`${readerName}: unknown class key ${JSON.stringify(key)}; expected one of ${CLASS_KEYS.join(", ")}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validate a single `classes` entry.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} key Node key.
|
|
67
|
+
* @param {Function} Class Candidate constructor.
|
|
68
|
+
* @param {string} [readerName] Format name used in thrown errors.
|
|
69
|
+
*/
|
|
70
|
+
function validateClass(key, Class, readerName = "CjsStlFormat") {
|
|
71
|
+
validateClassKey(key, readerName);
|
|
72
|
+
if (typeof Class !== "function") {
|
|
73
|
+
throw new TypeError(`${readerName}: class ${JSON.stringify(key)} must be a constructor`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function mergeClasses(base, classes, readerName) {
|
|
77
|
+
if (!classes || typeof classes !== "object") {
|
|
78
|
+
throw new TypeError(`${readerName}: classes option must be an object`);
|
|
79
|
+
}
|
|
80
|
+
const next = {
|
|
81
|
+
...base
|
|
82
|
+
};
|
|
83
|
+
for (const [key, Class] of Object.entries(classes)) {
|
|
84
|
+
if (Class === null || Class === undefined) {
|
|
85
|
+
delete next[key];
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
validateClass(key, Class, readerName);
|
|
89
|
+
next[key] = Class;
|
|
90
|
+
}
|
|
91
|
+
return next;
|
|
92
|
+
}
|
|
93
|
+
function sanitizeName(value) {
|
|
94
|
+
if (typeof value !== "string" || !value.trim()) return DEFAULT_VALUES.solidName;
|
|
95
|
+
return value.trim();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Merge format values over a base set and validate them.
|
|
100
|
+
*
|
|
101
|
+
* @param {object} base Current values.
|
|
102
|
+
* @param {object} [options] Values to merge in.
|
|
103
|
+
* @param {string} [readerName] Format name used in error messages.
|
|
104
|
+
* @returns {object} A validated copy of the merged values.
|
|
105
|
+
*/
|
|
106
|
+
function normalizeValues(base, options = {}, readerName = "CjsStlFormat") {
|
|
107
|
+
if (!options || typeof options !== "object") {
|
|
108
|
+
throw new TypeError(`${readerName}: options must be an object`);
|
|
109
|
+
}
|
|
110
|
+
for (const key of Object.keys(options)) {
|
|
111
|
+
if (!OPTION_KEYS.has(key)) {
|
|
112
|
+
throw new TypeError(`${readerName}: unknown option ${JSON.stringify(key)}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const values = {
|
|
116
|
+
...base,
|
|
117
|
+
...options
|
|
118
|
+
};
|
|
119
|
+
const emit = normalizeEmit(values.emit, readerName);
|
|
120
|
+
const classes = Object.prototype.hasOwnProperty.call(options, "classes") ? mergeClasses(base.classes || {}, options.classes, readerName) : {
|
|
121
|
+
...(base.classes || {})
|
|
122
|
+
};
|
|
123
|
+
if ((emit === OUTPUT_GR2 || emit === OUTPUT_CMF) && !hasClasses(classes)) {
|
|
124
|
+
throw new TypeError(`${readerName}: emit "${emit}" requires explicit classes`);
|
|
125
|
+
}
|
|
126
|
+
if (typeof values.source !== "string" || !values.source) {
|
|
127
|
+
values.source = DEFAULT_VALUES.source;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
emit,
|
|
131
|
+
source: values.source,
|
|
132
|
+
binary: validateBoolean("binary", values.binary, readerName),
|
|
133
|
+
solidName: sanitizeName(values.solidName),
|
|
134
|
+
scale: validateNumber("scale", values.scale, readerName, {
|
|
135
|
+
minExclusive: 0
|
|
136
|
+
}),
|
|
137
|
+
recalculateNormals: validateBoolean("recalculateNormals", values.recalculateNormals, readerName),
|
|
138
|
+
weldVertices: validateBoolean("weldVertices", values.weldVertices, readerName),
|
|
139
|
+
weldTolerance: validateNumber("weldTolerance", values.weldTolerance, readerName, {
|
|
140
|
+
minInclusive: 0
|
|
141
|
+
}),
|
|
142
|
+
skipDegenerate: validateBoolean("skipDegenerate", values.skipDegenerate, readerName),
|
|
143
|
+
requireWatertight: validateBoolean("requireWatertight", values.requireWatertight, readerName),
|
|
144
|
+
classes
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function normalizeEmit(emit, readerName) {
|
|
148
|
+
if (emit === undefined || emit === null || emit === OUTPUT_JSON || emit === OUTPUT_STL_JSON || emit === OUTPUT_SHARED) {
|
|
149
|
+
return OUTPUT_STL_JSON;
|
|
150
|
+
}
|
|
151
|
+
if (emit === OUTPUT_GR2 || emit === OUTPUT_CMF) return emit;
|
|
152
|
+
throw new TypeError(`${readerName}: emit must be "${OUTPUT_SHARED}", "${OUTPUT_STL_JSON}", "${OUTPUT_GR2}", or "${OUTPUT_CMF}", got ${JSON.stringify(emit)}`);
|
|
153
|
+
}
|
|
154
|
+
function hasClasses(classes) {
|
|
155
|
+
return !!classes && Object.values(classes).some(Class => typeof Class === "function");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Read STL text/bytes and return the shared JSON schema.
|
|
160
|
+
*
|
|
161
|
+
* @param {object|Function} format Format instance or constructor.
|
|
162
|
+
* @param {string|Uint8Array|ArrayBuffer|DataView} input STL text or bytes.
|
|
163
|
+
* @param {object} values Normalized format values.
|
|
164
|
+
* @returns {object} Shared JSON graph.
|
|
165
|
+
*/
|
|
166
|
+
function readWithValues(format, input, values) {
|
|
167
|
+
const parsed = parseStl(input);
|
|
168
|
+
const json = trianglesToJson(parsed.triangles, values, parsed);
|
|
169
|
+
if (values.emit === OUTPUT_CMF) return hydrateCmf(buildCmfFromShared(json), values.classes, {
|
|
170
|
+
source: values.source
|
|
171
|
+
});
|
|
172
|
+
return hydrateJson(json, {
|
|
173
|
+
classes: values.classes,
|
|
174
|
+
source: values.source
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Write the shared JSON geometry schema to STL.
|
|
180
|
+
* The input is read-only. Meshes and index groups are flattened by
|
|
181
|
+
* {@link jsonToTriangles}; optional topology enforcement runs against that
|
|
182
|
+
* exact scaled triangle stream before encoding begins.
|
|
183
|
+
*
|
|
184
|
+
* @param {object} input Shared JSON root or mesh.
|
|
185
|
+
* @param {object} values Normalized format values.
|
|
186
|
+
* @returns {string|Uint8Array} ASCII STL text or binary STL bytes.
|
|
187
|
+
* @throws {TypeError|RangeError|Error} If geometry, numeric values, indices, topology, or binary range are invalid.
|
|
188
|
+
*/
|
|
189
|
+
function writeWithValues(input, values) {
|
|
190
|
+
const triangles = jsonToTriangles(input, values);
|
|
191
|
+
if (!triangles.length) {
|
|
192
|
+
throw new Error("CjsStlFormat: write input did not produce any triangles");
|
|
193
|
+
}
|
|
194
|
+
if (values.requireWatertight) {
|
|
195
|
+
const report = inspectTriangles(triangles, values, {
|
|
196
|
+
format: "json",
|
|
197
|
+
source: input.grannyFileSource || values.source
|
|
198
|
+
});
|
|
199
|
+
if (!report.printable) {
|
|
200
|
+
throw new Error(`CjsStlFormat: requireWatertight failed (${report.issues.map(issue => issue.key).join(", ")})`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return values.binary ? writeBinaryStl(triangles, values.solidName) : writeAsciiStl(triangles, values.solidName);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Inspect STL or shared JSON geometry without class hydration.
|
|
208
|
+
*
|
|
209
|
+
* @param {any} input STL text/bytes or shared JSON.
|
|
210
|
+
* @param {object} values Normalized format values.
|
|
211
|
+
* @returns {object} Plain printability report.
|
|
212
|
+
*/
|
|
213
|
+
function inspectWithValues(input, values) {
|
|
214
|
+
const source = trianglesFromInput(input, values);
|
|
215
|
+
return inspectTriangles(source.triangles, values, source);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Convert format output to plain JSON-compatible data.
|
|
220
|
+
*
|
|
221
|
+
* @param {any} value Format output.
|
|
222
|
+
* @returns {any} JSON-compatible value.
|
|
223
|
+
*/
|
|
224
|
+
function toJsonValue(value) {
|
|
225
|
+
if (value === null || value === undefined) return value;
|
|
226
|
+
if (typeof value !== "object") return value;
|
|
227
|
+
if (typeof value.toJSON === "function") {
|
|
228
|
+
const next = value.toJSON();
|
|
229
|
+
if (next !== value) return toJsonValue(next);
|
|
230
|
+
}
|
|
231
|
+
if (Array.isArray(value)) return value.map(toJsonValue);
|
|
232
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) return Array.from(value);
|
|
233
|
+
const out = {};
|
|
234
|
+
for (const key of Object.keys(value)) {
|
|
235
|
+
out[key] = toJsonValue(value[key]);
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Imports a Node built-in module without exposing the specifier to any
|
|
242
|
+
* bundler's static import graph.
|
|
243
|
+
*
|
|
244
|
+
* `await import("node:fs/promises")` written as a literal is resolved
|
|
245
|
+
* eagerly by webpack/Rollup/esbuild alike when they walk the module
|
|
246
|
+
* graph, breaking browser builds even though this path only ever runs
|
|
247
|
+
* under Node (readFile/writeFile are Node-only conveniences). Building
|
|
248
|
+
* the specifier inside a `Function` body hides it from every bundler's
|
|
249
|
+
* static analysis - it only exists at runtime, in the Node process that
|
|
250
|
+
* actually calls readFile/writeFile.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} specifier Node built-in module specifier, e.g. "node:fs/promises".
|
|
253
|
+
* @returns {Promise<any>} The imported module namespace.
|
|
254
|
+
*/
|
|
255
|
+
function importNodeModule(specifier) {
|
|
256
|
+
// eslint-disable-next-line no-new-func
|
|
257
|
+
return new Function("s", "return import(s)")(specifier);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { CLASS_KEYS, DEFAULT_VALUES, GR2_CLASS_KEYS, OUTPUT_CMF, OUTPUT_GR2, OUTPUT_JSON, OUTPUT_SHARED, OUTPUT_STL_JSON, importNodeModule, inspectWithValues, normalizeValues, readWithValues, toJsonValue, validateClass, validateClassKey, writeWithValues };
|
|
261
|
+
//# sourceMappingURL=helpers.js.map
|