@carbonenginejs/runtime-resource 0.9.2 → 0.10.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.
Files changed (324) hide show
  1. package/NOTICE +3 -2
  2. package/README.md +47 -6
  3. package/dist/CjsMotherLode.js +88 -88
  4. package/dist/CjsMotherLode.js.map +1 -1
  5. package/dist/CjsResMan.js +717 -228
  6. package/dist/CjsResMan.js.map +1 -1
  7. package/dist/CjsResManFetchProvider.js +94 -0
  8. package/dist/CjsResManFetchProvider.js.map +1 -0
  9. package/dist/{CjsResManQueue.js → CjsResManWorkQueue.js} +112 -25
  10. package/dist/CjsResManWorkQueue.js.map +1 -0
  11. package/dist/format/CjsBlueReader.js +89 -0
  12. package/dist/format/CjsBlueReader.js.map +1 -1
  13. package/dist/format/CjsFormat.js +42 -16
  14. package/dist/format/CjsFormat.js.map +1 -1
  15. package/dist/format/CjsReader.js +4 -0
  16. package/dist/format/CjsReader.js.map +1 -1
  17. package/dist/format/CjsResourceProbe.js +2 -0
  18. package/dist/format/CjsResourceProbe.js.map +1 -1
  19. package/dist/format/payloadContract.js +20 -0
  20. package/dist/format/payloadContract.js.map +1 -1
  21. package/dist/formats/black/CjsBlackFormat.js +15 -1
  22. package/dist/formats/black/CjsBlackFormat.js.map +1 -1
  23. package/dist/formats/black/core/CjsBlackBinaryReader.js +103 -0
  24. package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -1
  25. package/dist/formats/black/core/CjsBlackPropertyReaders.js +61 -0
  26. package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -1
  27. package/dist/formats/black/core/CjsBlackReader.js +125 -0
  28. package/dist/formats/black/core/CjsBlackReader.js.map +1 -1
  29. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +103 -0
  30. package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -1
  31. package/dist/formats/black/core/helpers.js +17 -0
  32. package/dist/formats/black/core/helpers.js.map +1 -1
  33. package/dist/formats/bnk/CjsBnkFormat.js +8 -0
  34. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  35. package/dist/formats/bnk/core/helpers.js +20 -0
  36. package/dist/formats/bnk/core/helpers.js.map +1 -1
  37. package/dist/formats/bnk/core/musicNodes.js +40 -3
  38. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  39. package/dist/formats/bnk/core/soundbanksInfo.js +2 -0
  40. package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
  41. package/dist/formats/cmf/core/binary.js +71 -0
  42. package/dist/formats/cmf/core/binary.js.map +1 -1
  43. package/dist/formats/cmf/core/buffers.js +4 -0
  44. package/dist/formats/cmf/core/buffers.js.map +1 -1
  45. package/dist/formats/cmf/core/helpers.js +31 -0
  46. package/dist/formats/cmf/core/helpers.js.map +1 -1
  47. package/dist/formats/cmf/core/schema.js +10 -0
  48. package/dist/formats/cmf/core/schema.js.map +1 -1
  49. package/dist/formats/cmf/core/shared.js +9 -0
  50. package/dist/formats/cmf/core/shared.js.map +1 -1
  51. package/dist/formats/cmf/core/writer.js +54 -0
  52. package/dist/formats/cmf/core/writer.js.map +1 -1
  53. package/dist/formats/dds/core/bc6h.js +10 -0
  54. package/dist/formats/dds/core/bc6h.js.map +1 -1
  55. package/dist/formats/dds/core/bc7.js +16 -0
  56. package/dist/formats/dds/core/bc7.js.map +1 -1
  57. package/dist/formats/dds/core/helpers.js +47 -0
  58. package/dist/formats/dds/core/helpers.js.map +1 -1
  59. package/dist/formats/fbx/core/helpers.js +21 -0
  60. package/dist/formats/fbx/core/helpers.js.map +1 -1
  61. package/dist/formats/flac/CjsFlacFormat.js +49 -0
  62. package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
  63. package/dist/formats/flac/core/helpers.js +20 -0
  64. package/dist/formats/flac/core/helpers.js.map +1 -1
  65. package/dist/formats/gif/CjsGifFormat.js +49 -0
  66. package/dist/formats/gif/CjsGifFormat.js.map +1 -1
  67. package/dist/formats/gif/core/helpers.js +20 -0
  68. package/dist/formats/gif/core/helpers.js.map +1 -1
  69. package/dist/formats/gltf/core/helpers.js +15 -0
  70. package/dist/formats/gltf/core/helpers.js.map +1 -1
  71. package/dist/formats/gltf/core/parser.js +13 -0
  72. package/dist/formats/gltf/core/parser.js.map +1 -1
  73. package/dist/formats/gltf/core/targets.js +10 -0
  74. package/dist/formats/gltf/core/targets.js.map +1 -1
  75. package/dist/formats/gr2/core/bitknit2.js +2 -0
  76. package/dist/formats/gr2/core/bitknit2.js.map +1 -1
  77. package/dist/formats/gr2/core/helpers.js +20 -0
  78. package/dist/formats/gr2/core/helpers.js.map +1 -1
  79. package/dist/formats/gr2/core/targets.js +10 -0
  80. package/dist/formats/gr2/core/targets.js.map +1 -1
  81. package/dist/formats/jpeg/core/helpers.js +52 -0
  82. package/dist/formats/jpeg/core/helpers.js.map +1 -1
  83. package/dist/formats/jpeg/core/jpeg.js +93 -0
  84. package/dist/formats/jpeg/core/jpeg.js.map +1 -1
  85. package/dist/formats/mp3/core/helpers.js +37 -0
  86. package/dist/formats/mp3/core/helpers.js.map +1 -1
  87. package/dist/formats/mp4/core/helpers.js +35 -0
  88. package/dist/formats/mp4/core/helpers.js.map +1 -1
  89. package/dist/formats/ogg/CjsOggFormat.js +49 -0
  90. package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
  91. package/dist/formats/ogg/core/helpers.js +23 -0
  92. package/dist/formats/ogg/core/helpers.js.map +1 -1
  93. package/dist/formats/ogg/core/vorbis.js +13 -0
  94. package/dist/formats/ogg/core/vorbis.js.map +1 -1
  95. package/dist/formats/png/core/helpers.js +52 -0
  96. package/dist/formats/png/core/helpers.js.map +1 -1
  97. package/dist/formats/red/CjsRedFormat.js +2 -0
  98. package/dist/formats/red/CjsRedFormat.js.map +1 -1
  99. package/dist/formats/red/core/CjsRedReader.js +52 -0
  100. package/dist/formats/red/core/CjsRedReader.js.map +1 -1
  101. package/dist/formats/red/core/helpers.js +19 -0
  102. package/dist/formats/red/core/helpers.js.map +1 -1
  103. package/dist/formats/stl/core/stl.js +8 -0
  104. package/dist/formats/stl/core/stl.js.map +1 -1
  105. package/dist/formats/stl/core/targets.js +10 -0
  106. package/dist/formats/stl/core/targets.js.map +1 -1
  107. package/dist/formats/tga/core/helpers.js +47 -0
  108. package/dist/formats/tga/core/helpers.js.map +1 -1
  109. package/dist/formats/wav/core/helpers.js +37 -0
  110. package/dist/formats/wav/core/helpers.js.map +1 -1
  111. package/dist/formats/webm/core/helpers.js +35 -0
  112. package/dist/formats/webm/core/helpers.js.map +1 -1
  113. package/dist/formats/webp/CjsWebpFormat.js +49 -0
  114. package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
  115. package/dist/formats/webp/core/helpers.js +23 -0
  116. package/dist/formats/webp/core/helpers.js.map +1 -1
  117. package/dist/formats/wem/CjsWemFormat.js +8 -0
  118. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  119. package/dist/formats/wem/core/bitStream.js +2 -0
  120. package/dist/formats/wem/core/bitStream.js.map +1 -1
  121. package/dist/formats/wem/core/helpers.js +20 -0
  122. package/dist/formats/wem/core/helpers.js.map +1 -1
  123. package/dist/formats/yaml/CjsYamlFormat.js +45 -0
  124. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  125. package/dist/formats/yaml/core/CjsYamlReader.js +91 -0
  126. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  127. package/dist/formats/yaml/core/helpers.js +10 -0
  128. package/dist/formats/yaml/core/helpers.js.map +1 -1
  129. package/dist/index.js +56 -43
  130. package/dist/index.js.map +1 -1
  131. package/dist/{CjsResource.js → resource/CjsResource.js} +232 -17
  132. package/dist/resource/CjsResource.js.map +1 -0
  133. package/dist/{resources → resource}/Tr2LightProfileRes.js +4 -3
  134. package/dist/resource/Tr2LightProfileRes.js.map +1 -0
  135. package/dist/{resources → resource/audio}/AudioGeometryResData.js +1 -1
  136. package/dist/resource/audio/AudioGeometryResData.js.map +1 -0
  137. package/dist/resource/audio/CjsAudioBufferRes.js +86 -0
  138. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -0
  139. package/dist/resource/audio/CjsAudioRes.js +213 -0
  140. package/dist/resource/audio/CjsAudioRes.js.map +1 -0
  141. package/dist/resource/audio/index.js +4 -0
  142. package/dist/resource/audio/index.js.map +1 -0
  143. package/dist/{resources → resource/geometry}/MeshDecalData.js +1 -1
  144. package/dist/resource/geometry/MeshDecalData.js.map +1 -0
  145. package/dist/{resources → resource/geometry}/MeshDecalLodData.js +1 -1
  146. package/dist/resource/geometry/MeshDecalLodData.js.map +1 -0
  147. package/dist/resource/geometry/TriGeometryRes.js +656 -0
  148. package/dist/resource/geometry/TriGeometryRes.js.map +1 -0
  149. package/dist/{resources → resource/geometry}/TriGeometryResAreaData.js +1 -1
  150. package/dist/resource/geometry/TriGeometryResAreaData.js.map +1 -0
  151. package/dist/{resources → resource/geometry}/TriGeometryResJointData.js +1 -1
  152. package/dist/resource/geometry/TriGeometryResJointData.js.map +1 -0
  153. package/dist/{resources → resource/geometry}/TriGeometryResLodData.js +1 -1
  154. package/dist/resource/geometry/TriGeometryResLodData.js.map +1 -0
  155. package/dist/{resources → resource/geometry}/TriGeometryResMeshData.js +1 -1
  156. package/dist/resource/geometry/TriGeometryResMeshData.js.map +1 -0
  157. package/dist/{resources → resource/geometry}/TriGeometryResSkeletonData.js +1 -1
  158. package/dist/resource/geometry/TriGeometryResSkeletonData.js.map +1 -0
  159. package/dist/{resources → resource/geometry}/TriJointBinding.js +1 -1
  160. package/dist/resource/geometry/TriJointBinding.js.map +1 -0
  161. package/dist/{resources → resource/geometry}/TriMorphTargetGeometryConstants.js +1 -1
  162. package/dist/resource/geometry/TriMorphTargetGeometryConstants.js.map +1 -0
  163. package/dist/{resources → resource/geometry}/TriRtGeometryConstants.js +1 -1
  164. package/dist/resource/geometry/TriRtGeometryConstants.js.map +1 -0
  165. package/dist/{resources → resource/geometry/granny}/GStateBindingCallbackData.js +1 -1
  166. package/dist/resource/geometry/granny/GStateBindingCallbackData.js.map +1 -0
  167. package/dist/{resources → resource/geometry/granny}/Tr2GrannyIntersectionResult.js +1 -1
  168. package/dist/resource/geometry/granny/Tr2GrannyIntersectionResult.js.map +1 -0
  169. package/dist/{resources → resource/geometry/granny}/Tr2GrannyStateRes.js +6 -5
  170. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -0
  171. package/dist/{resources → resource/geometry/granny}/TriGrannyRes.js +6 -5
  172. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -0
  173. package/dist/{resources → resource/geometry/granny}/enums.js +1 -9
  174. package/dist/resource/geometry/granny/enums.js.map +1 -0
  175. package/dist/resource/geometry/granny/index.js +6 -0
  176. package/dist/resource/geometry/granny/index.js.map +1 -0
  177. package/dist/resource/geometry/index.js +17 -0
  178. package/dist/resource/geometry/index.js.map +1 -0
  179. package/dist/resource/index.js +52 -0
  180. package/dist/resource/index.js.map +1 -0
  181. package/dist/resource/resourceBoundary.js +64 -0
  182. package/dist/resource/resourceBoundary.js.map +1 -0
  183. package/dist/resource/shader/Tr2EffectRes.js +420 -0
  184. package/dist/resource/shader/Tr2EffectRes.js.map +1 -0
  185. package/dist/{resources → resource/shader}/Tr2MaterialArea.js +9 -4
  186. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -0
  187. package/dist/{resources → resource/shader}/Tr2MaterialMesh.js +8 -3
  188. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -0
  189. package/dist/{resources → resource/shader}/Tr2MaterialRes.js +10 -4
  190. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -0
  191. package/dist/resource/shader/Tr2Shader.js +250 -0
  192. package/dist/resource/shader/Tr2Shader.js.map +1 -0
  193. package/dist/{resources → resource/shader}/Tr2ShaderPermutation.js +13 -7
  194. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -0
  195. package/dist/resource/shader/index.js +17 -0
  196. package/dist/resource/shader/index.js.map +1 -0
  197. package/dist/resource/shader/portable.js +33 -0
  198. package/dist/resource/shader/portable.js.map +1 -0
  199. package/dist/resource/shader/portableValidation.js +461 -0
  200. package/dist/resource/shader/portableValidation.js.map +1 -0
  201. package/dist/resource/shader/reflection/Tr2EffectConstant.js +100 -0
  202. package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -0
  203. package/dist/resource/shader/reflection/Tr2EffectDefine.js +34 -0
  204. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -0
  205. package/dist/resource/shader/reflection/Tr2EffectDescription.js +113 -0
  206. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -0
  207. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +141 -0
  208. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -0
  209. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +107 -0
  210. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -0
  211. package/dist/resource/shader/reflection/Tr2EffectResource.js +90 -0
  212. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -0
  213. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +235 -0
  214. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -0
  215. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +71 -0
  216. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -0
  217. package/dist/resource/shader/reflection/Tr2Pass.js +111 -0
  218. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -0
  219. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +80 -0
  220. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -0
  221. package/dist/{texture → resource/texture}/CjsTextureArrayRes.js +83 -6
  222. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -0
  223. package/dist/{texture/CjsTextureParameterProxy.js → resource/texture/CjsTextureArrayResParameterProxy.js} +56 -10
  224. package/dist/resource/texture/CjsTextureArrayResParameterProxy.js.map +1 -0
  225. package/dist/{resources → resource/texture}/Tr2ImageRes.js +6 -4
  226. package/dist/resource/texture/Tr2ImageRes.js.map +1 -0
  227. package/dist/{resources → resource/texture}/Tr2TextureLodManager.js +3 -1
  228. package/dist/resource/texture/Tr2TextureLodManager.js.map +1 -0
  229. package/dist/{resources → resource/texture}/Tr2TextureLodUpdateRequest.js +1 -1
  230. package/dist/resource/texture/Tr2TextureLodUpdateRequest.js.map +1 -0
  231. package/dist/{resources → resource/texture}/Tr2TexturePackChannel.js +1 -1
  232. package/dist/resource/texture/Tr2TexturePackChannel.js.map +1 -0
  233. package/dist/{resources → resource/texture}/Tr2TexturePipeline.js +6 -4
  234. package/dist/resource/texture/Tr2TexturePipeline.js.map +1 -0
  235. package/dist/{resources → resource/texture}/Tr2TexturePipelineParams.js +1 -1
  236. package/dist/resource/texture/Tr2TexturePipelineParams.js.map +1 -0
  237. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepCompress.js +1 -1
  238. package/dist/resource/texture/Tr2TexturePipelineStepCompress.js.map +1 -0
  239. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepGenerateMips.js +1 -1
  240. package/dist/resource/texture/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
  241. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepLimitSize.js +1 -1
  242. package/dist/resource/texture/Tr2TexturePipelineStepLimitSize.js.map +1 -0
  243. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepLoad.js +1 -1
  244. package/dist/resource/texture/Tr2TexturePipelineStepLoad.js.map +1 -0
  245. package/dist/{resources → resource/texture}/Tr2TexturePipelineStepPack.js +1 -1
  246. package/dist/resource/texture/Tr2TexturePipelineStepPack.js.map +1 -0
  247. package/dist/{resources → resource/texture}/TriTextureRes.js +42 -26
  248. package/dist/resource/texture/TriTextureRes.js.map +1 -0
  249. package/dist/resource/texture/index.js +15 -0
  250. package/dist/resource/texture/index.js.map +1 -0
  251. package/dist/{resources → resource/texture}/texturePipelineBehavior.js +59 -59
  252. package/dist/resource/texture/texturePipelineBehavior.js.map +1 -0
  253. package/dist/worker/CjsResManMainThreadLoader.js +87 -0
  254. package/dist/worker/CjsResManMainThreadLoader.js.map +1 -0
  255. package/dist/worker/CjsResManWorker.js +217 -0
  256. package/dist/worker/CjsResManWorker.js.map +1 -0
  257. package/dist/worker/CjsResManWorkerLoader.js +434 -0
  258. package/dist/worker/CjsResManWorkerLoader.js.map +1 -0
  259. package/dist/worker/protocol.js +12 -0
  260. package/dist/worker/protocol.js.map +1 -0
  261. package/docs/README.md +16 -3
  262. package/docs/architecture.md +39 -16
  263. package/docs/concepts/resource-lifecycle.md +2 -1
  264. package/docs/formats/README.md +4 -0
  265. package/docs/reference/classes/README.md +6 -4
  266. package/docs/reference/classes/audio.md +30 -0
  267. package/docs/reference/classes/core.md +31 -11
  268. package/docs/reference/classes/resources.md +151 -41
  269. package/docs/reference/classes/texture.md +7 -7
  270. package/docs/reference/motherlode-cache.md +17 -0
  271. package/docs/reference/queues.md +9 -1
  272. package/docs/reference/workers.md +135 -0
  273. package/docs/roadmap.md +27 -1
  274. package/package.json +8 -1
  275. package/dist/CjsResManQueue.js.map +0 -1
  276. package/dist/CjsResource.js.map +0 -1
  277. package/dist/CjsResourceSource.js +0 -68
  278. package/dist/CjsResourceSource.js.map +0 -1
  279. package/dist/resourcePath.js +0 -18
  280. package/dist/resourcePath.js.map +0 -1
  281. package/dist/resourceStates.js +0 -9
  282. package/dist/resourceStates.js.map +0 -1
  283. package/dist/resources/AudioGeometryResData.js.map +0 -1
  284. package/dist/resources/GStateBindingCallbackData.js.map +0 -1
  285. package/dist/resources/MeshDecalData.js.map +0 -1
  286. package/dist/resources/MeshDecalLodData.js.map +0 -1
  287. package/dist/resources/Tr2EffectRes.js +0 -71
  288. package/dist/resources/Tr2EffectRes.js.map +0 -1
  289. package/dist/resources/Tr2GrannyIntersectionResult.js.map +0 -1
  290. package/dist/resources/Tr2GrannyStateRes.js.map +0 -1
  291. package/dist/resources/Tr2ImageRes.js.map +0 -1
  292. package/dist/resources/Tr2LightProfileRes.js.map +0 -1
  293. package/dist/resources/Tr2MaterialArea.js.map +0 -1
  294. package/dist/resources/Tr2MaterialMesh.js.map +0 -1
  295. package/dist/resources/Tr2MaterialRes.js.map +0 -1
  296. package/dist/resources/Tr2ShaderPermutation.js.map +0 -1
  297. package/dist/resources/Tr2TextureLodManager.js.map +0 -1
  298. package/dist/resources/Tr2TextureLodUpdateRequest.js.map +0 -1
  299. package/dist/resources/Tr2TexturePackChannel.js.map +0 -1
  300. package/dist/resources/Tr2TexturePipeline.js.map +0 -1
  301. package/dist/resources/Tr2TexturePipelineParams.js.map +0 -1
  302. package/dist/resources/Tr2TexturePipelineStepCompress.js.map +0 -1
  303. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +0 -1
  304. package/dist/resources/Tr2TexturePipelineStepLimitSize.js.map +0 -1
  305. package/dist/resources/Tr2TexturePipelineStepLoad.js.map +0 -1
  306. package/dist/resources/Tr2TexturePipelineStepPack.js.map +0 -1
  307. package/dist/resources/TriGeometryRes.js +0 -239
  308. package/dist/resources/TriGeometryRes.js.map +0 -1
  309. package/dist/resources/TriGeometryResAreaData.js.map +0 -1
  310. package/dist/resources/TriGeometryResJointData.js.map +0 -1
  311. package/dist/resources/TriGeometryResLodData.js.map +0 -1
  312. package/dist/resources/TriGeometryResMeshData.js.map +0 -1
  313. package/dist/resources/TriGeometryResSkeletonData.js.map +0 -1
  314. package/dist/resources/TriGrannyRes.js.map +0 -1
  315. package/dist/resources/TriJointBinding.js.map +0 -1
  316. package/dist/resources/TriMorphTargetGeometryConstants.js.map +0 -1
  317. package/dist/resources/TriRtGeometryConstants.js.map +0 -1
  318. package/dist/resources/TriTextureRes.js.map +0 -1
  319. package/dist/resources/enums.js.map +0 -1
  320. package/dist/resources/resourceBoundary.js +0 -47
  321. package/dist/resources/resourceBoundary.js.map +0 -1
  322. package/dist/resources/texturePipelineBehavior.js.map +0 -1
  323. package/dist/texture/CjsTextureArrayRes.js.map +0 -1
  324. package/dist/texture/CjsTextureParameterProxy.js.map +0 -1
@@ -0,0 +1,94 @@
1
+ import { Operation } from './worker/protocol.js';
2
+
3
+ const FETCH_OPTION_KEYS = Object.freeze(["body", "cache", "credentials", "duplex", "headers", "integrity", "keepalive", "method", "mode", "priority", "redirect", "referrer", "referrerPolicy", "window"]);
4
+
5
+ /**
6
+ * `CjsResMan` provider that fetches an already-resolved URL on the caller
7
+ * thread or through the resource worker.
8
+ */
9
+ class CjsResManFetchProvider {
10
+ /** Creates a CjsResManFetchProvider with caller-provided fetch policy. */
11
+ constructor(options = {}) {
12
+ this.fetch = options.fetch || globalThis.fetch;
13
+ this.fetchOptions = options.fetchOptions || null;
14
+ this.workerEnabled = options.worker !== false && (options.fetch === undefined || options.worker === true);
15
+ }
16
+
17
+ /**
18
+ * Fetches bytes for a URL already resolved by CjsResMan.
19
+ *
20
+ * @param {string} url Resolved source URL.
21
+ * @param {object} [options={}] Resource and fetch options.
22
+ * @returns {Promise<ArrayBuffer>} Response bytes.
23
+ */
24
+ async Read(url, options = {}) {
25
+ if (typeof this.fetch !== "function") {
26
+ throw new TypeError("CjsResManFetchProvider requires a fetch implementation.");
27
+ }
28
+ const fetchOptions = getCloneableFetchOptions(this.fetchOptions, options.fetchOptions || options);
29
+ if (options.signal) fetchOptions.signal = options.signal;
30
+ const response = await this.fetch(url, fetchOptions);
31
+ if (!response.ok) {
32
+ const error = new Error(`Resource fetch failed: ${response.status} ${response.statusText}`);
33
+ error.code = "CJS_RESOURCE_FETCH_FAILED";
34
+ error.path = options.resourcePath || url;
35
+ error.url = url;
36
+ error.status = response.status;
37
+ throw error;
38
+ }
39
+ return response.arrayBuffer();
40
+ }
41
+
42
+ /**
43
+ * Describe the equivalent cloneable worker fetch operation.
44
+ *
45
+ * An injected fetch implementation stays on the caller thread unless the
46
+ * source explicitly opts into worker fetch with `{ worker: true }`.
47
+ *
48
+ * @param {string} url URL already resolved by CjsResMan.
49
+ * @param {object} [options={}] Resource and fetch options.
50
+ * @returns {object|null} Worker operation, or `null` when worker fetch is disabled.
51
+ */
52
+ CreateWorkerRequest(url, options = {}) {
53
+ if (!this.workerEnabled) return null;
54
+ return {
55
+ operation: Operation.FETCH,
56
+ payload: {
57
+ url,
58
+ path: options.resourcePath || url,
59
+ responseType: "arraybuffer",
60
+ options: getCloneableFetchOptions(this.fetchOptions, options.fetchOptions || options)
61
+ },
62
+ signal: options.signal || null
63
+ };
64
+ }
65
+
66
+ /** Signals that CjsResMan must resolve resource paths before provider reads. */
67
+ static requiresUrl = true;
68
+ }
69
+ function getCloneableFetchOptions(defaults, options) {
70
+ const result = {};
71
+ for (const source of [defaults, options]) {
72
+ if (!source || typeof source !== "object") continue;
73
+ for (const key of FETCH_OPTION_KEYS) {
74
+ if (source[key] === undefined) continue;
75
+ result[key] = key === "headers" ? normalizeFetchHeaders(source[key]) : source[key];
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ function normalizeFetchHeaders(value) {
81
+ if (!value || typeof value !== "object") return value;
82
+ if (Array.isArray(value)) {
83
+ return value.map(entry => Array.isArray(entry) ? [...entry] : entry);
84
+ }
85
+ if (typeof value.entries === "function") {
86
+ return [...value.entries()];
87
+ }
88
+ return {
89
+ ...value
90
+ };
91
+ }
92
+
93
+ export { CjsResManFetchProvider };
94
+ //# sourceMappingURL=CjsResManFetchProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CjsResManFetchProvider.js","sources":["../../src/CjsResManFetchProvider.js"],"sourcesContent":["import { Operation } from \"./worker/protocol.js\";\n\nconst FETCH_OPTION_KEYS = Object.freeze([\n \"body\",\n \"cache\",\n \"credentials\",\n \"duplex\",\n \"headers\",\n \"integrity\",\n \"keepalive\",\n \"method\",\n \"mode\",\n \"priority\",\n \"redirect\",\n \"referrer\",\n \"referrerPolicy\",\n \"window\"\n]);\n\n/**\n * `CjsResMan` provider that fetches an already-resolved URL on the caller\n * thread or through the resource worker.\n */\nexport class CjsResManFetchProvider\n{\n /** Creates a CjsResManFetchProvider with caller-provided fetch policy. */\n constructor(options = {})\n {\n this.fetch = options.fetch || globalThis.fetch;\n this.fetchOptions = options.fetchOptions || null;\n this.workerEnabled = options.worker !== false\n && (options.fetch === undefined || options.worker === true);\n }\n\n /**\n * Fetches bytes for a URL already resolved by CjsResMan.\n *\n * @param {string} url Resolved source URL.\n * @param {object} [options={}] Resource and fetch options.\n * @returns {Promise<ArrayBuffer>} Response bytes.\n */\n async Read(url, options = {})\n {\n if (typeof this.fetch !== \"function\")\n {\n throw new TypeError(\"CjsResManFetchProvider requires a fetch implementation.\");\n }\n\n const fetchOptions = getCloneableFetchOptions(\n this.fetchOptions,\n options.fetchOptions || options\n );\n if (options.signal) fetchOptions.signal = options.signal;\n const response = await this.fetch(url, fetchOptions);\n if (!response.ok)\n {\n const error = new Error(`Resource fetch failed: ${response.status} ${response.statusText}`);\n error.code = \"CJS_RESOURCE_FETCH_FAILED\";\n error.path = options.resourcePath || url;\n error.url = url;\n error.status = response.status;\n throw error;\n }\n\n return response.arrayBuffer();\n }\n\n /**\n * Describe the equivalent cloneable worker fetch operation.\n *\n * An injected fetch implementation stays on the caller thread unless the\n * source explicitly opts into worker fetch with `{ worker: true }`.\n *\n * @param {string} url URL already resolved by CjsResMan.\n * @param {object} [options={}] Resource and fetch options.\n * @returns {object|null} Worker operation, or `null` when worker fetch is disabled.\n */\n CreateWorkerRequest(url, options = {})\n {\n if (!this.workerEnabled) return null;\n return {\n operation: Operation.FETCH,\n payload: {\n url,\n path: options.resourcePath || url,\n responseType: \"arraybuffer\",\n options: getCloneableFetchOptions(this.fetchOptions, options.fetchOptions || options)\n },\n signal: options.signal || null\n };\n }\n\n /** Signals that CjsResMan must resolve resource paths before provider reads. */\n static requiresUrl = true;\n}\n\nfunction getCloneableFetchOptions(defaults, options) {\n const result = {};\n for (const source of [ defaults, options ]) {\n if (!source || typeof source !== \"object\") continue;\n for (const key of FETCH_OPTION_KEYS) {\n if (source[key] === undefined) continue;\n result[key] = key === \"headers\"\n ? normalizeFetchHeaders(source[key])\n : source[key];\n }\n }\n return result;\n}\n\nfunction normalizeFetchHeaders(value) {\n if (!value || typeof value !== \"object\") return value;\n if (Array.isArray(value)) {\n return value.map(entry => Array.isArray(entry) ? [ ...entry ] : entry);\n }\n if (typeof value.entries === \"function\") {\n return [ ...value.entries() ];\n }\n return { ...value };\n}\n"],"names":["FETCH_OPTION_KEYS","Object","freeze","CjsResManFetchProvider","constructor","options","fetch","globalThis","fetchOptions","workerEnabled","worker","undefined","Read","url","TypeError","getCloneableFetchOptions","signal","response","ok","error","Error","status","statusText","code","path","resourcePath","arrayBuffer","CreateWorkerRequest","operation","Operation","FETCH","payload","responseType","requiresUrl","defaults","result","source","key","normalizeFetchHeaders","value","Array","isArray","map","entry","entries"],"mappings":";;AAEA,MAAMA,iBAAiB,GAAGC,MAAM,CAACC,MAAM,CAAC,CACtC,MAAM,EACN,OAAO,EACP,aAAa,EACb,QAAQ,EACR,SAAS,EACT,WAAW,EACX,WAAW,EACX,QAAQ,EACR,MAAM,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,QAAQ,CACT,CAAC;;AAEF;AACA;AACA;AACA;AACO,MAAMC,sBAAsB,CACnC;AACE;AACAC,EAAAA,WAAWA,CAACC,OAAO,GAAG,EAAE,EACxB;IACE,IAAI,CAACC,KAAK,GAAGD,OAAO,CAACC,KAAK,IAAIC,UAAU,CAACD,KAAK;AAC9C,IAAA,IAAI,CAACE,YAAY,GAAGH,OAAO,CAACG,YAAY,IAAI,IAAI;IAChD,IAAI,CAACC,aAAa,GAAGJ,OAAO,CAACK,MAAM,KAAK,KAAK,KACvCL,OAAO,CAACC,KAAK,KAAKK,SAAS,IAAIN,OAAO,CAACK,MAAM,KAAK,IAAI,CAAC;AAC/D,EAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE,MAAME,IAAIA,CAACC,GAAG,EAAER,OAAO,GAAG,EAAE,EAC5B;AACE,IAAA,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU,EACpC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GAAO;AACrB;;;;"}
@@ -4,25 +4,13 @@ const CjsResManQueue = Object.freeze({
4
4
  PREPARE: "main",
5
5
  LOAD: "background"
6
6
  });
7
- function NormalizeCjsResManQueue(value) {
8
- const name = String(value ?? "").trim().toLowerCase();
9
- if (name === "main" || name === "prepare") return CjsResManQueue.MAIN;
10
- if (name === "background" || name === "load") return CjsResManQueue.BACKGROUND;
11
- throw new TypeError(`Unknown CjsResMan queue: ${value}`);
12
- }
13
- function CjsResManQueueCancelledError(queue, id, reason = "") {
14
- const error = new Error(`CjsResMan ${queue} queue item ${id} was cancelled.${reason ? ` ${reason}` : ""}`);
15
- error.code = "CJS_RESMAN_QUEUE_CANCELLED";
16
- error.queue = queue;
17
- error.id = id;
18
- return error;
19
- }
20
7
 
21
8
  /**
22
- * Small FIFO executor used internally by CjsResMan.
9
+ * Small FIFO executor used inside `CjsResMan` that tracks item ids, pause
10
+ * state, concurrency, cancellation, and sync/async completion while queue
11
+ * policy stays in the manager.
23
12
  *
24
- * Queue policy stays in the manager. This class only tracks ids, pause state,
25
- * concurrency, cancellation, and sync/async completion.
13
+ * The queue deliberately does not choose task priority or resource policy.
26
14
  */
27
15
  class CjsResManWorkQueue {
28
16
  #active = new Map();
@@ -34,11 +22,18 @@ class CjsResManWorkQueue {
34
22
  #onReady;
35
23
  #paused = false;
36
24
  #queued = new Map();
25
+
26
+ /** Creates a CjsResManWorkQueue with caller-provided initial state. */
37
27
  constructor(name, options = {}) {
38
- this.#name = NormalizeCjsResManQueue(name);
28
+ this.#name = CjsResManWorkQueue.normalizeName(name);
39
29
  this.#onReady = typeof options.onReady === "function" ? options.onReady : null;
40
30
  this.SetConcurrency(options.concurrency ?? 1);
41
31
  }
32
+
33
+ /**
34
+ * Updates the maximum number of tasks that may run together for the resource
35
+ * work queue.
36
+ */
42
37
  SetConcurrency(value) {
43
38
  if (!Number.isInteger(value) || value < 1) {
44
39
  throw new TypeError("CjsResMan queue concurrency must be a positive integer.");
@@ -47,24 +42,53 @@ class CjsResManWorkQueue {
47
42
  this.#NotifyReady();
48
43
  return this;
49
44
  }
45
+
46
+ /**
47
+ * Returns the maximum number of tasks allowed to run together for the resource
48
+ * work queue.
49
+ */
50
50
  GetConcurrency() {
51
51
  return this.#concurrency;
52
52
  }
53
+
54
+ /**
55
+ * Allocates the next monotonically increasing task identifier for the resource
56
+ * work queue.
57
+ */
53
58
  GetNextId() {
54
59
  return this.#nextId;
55
60
  }
61
+
62
+ /** Returns the number of tasks waiting to start for the resource work queue. */
56
63
  GetQueuedCount() {
57
64
  return this.#queued.size;
58
65
  }
66
+
67
+ /** Returns the number of tasks currently executing for the resource work queue. */
59
68
  GetActiveCount() {
60
69
  return this.#active.size;
61
70
  }
71
+
72
+ /**
73
+ * Returns the combined number of waiting and active tasks for the resource
74
+ * work queue.
75
+ */
62
76
  GetPendingCount() {
63
77
  return this.#queued.size + this.#active.size;
64
78
  }
79
+
80
+ /**
81
+ * Reports whether the queue is prevented from starting work for the resource
82
+ * work queue.
83
+ */
65
84
  IsPaused() {
66
85
  return this.#paused;
67
86
  }
87
+
88
+ /**
89
+ * Enqueues one task and returns its cancellation-aware promise for the
90
+ * resource work queue.
91
+ */
68
92
  Add(callback, context = null, metadata = null) {
69
93
  if (typeof callback !== "function") {
70
94
  throw new TypeError("CjsResMan queue items require a callback.");
@@ -92,35 +116,51 @@ class CjsResManWorkQueue {
92
116
  this.#NotifyReady();
93
117
  return item;
94
118
  }
119
+
120
+ /**
121
+ * Cancels a queued task selected by its identifier for the resource work
122
+ * queue.
123
+ */
95
124
  Cancel(id, reason = "") {
96
125
  const item = this.#queued.get(id);
97
126
  if (!item) return false;
98
127
  this.#queued.delete(id);
99
128
  item.state = "cancelled";
100
- item.reject(CjsResManQueueCancelledError(this.#name, id, reason));
129
+ item.reject(CjsResManWorkQueue.createCancelledError(this.#name, id, reason));
101
130
  this.#Compact();
102
131
  return true;
103
132
  }
133
+
134
+ /**
135
+ * Prevents queued tasks from starting until resumed for the resource work
136
+ * queue.
137
+ */
104
138
  Pause() {
105
139
  this.#paused = true;
106
140
  return this;
107
141
  }
142
+
143
+ /** Allows queued tasks to start after a pause for the resource work queue. */
108
144
  Resume() {
109
145
  if (!this.#paused) return this;
110
146
  this.#paused = false;
111
147
  this.#NotifyReady();
112
148
  return this;
113
149
  }
150
+
151
+ /** Cancels every task that has not started for the resource work queue. */
114
152
  Clear(reason = "Queue cleared.") {
115
153
  const ids = [...this.#queued.keys()];
116
154
  for (const id of ids) this.Cancel(id, reason);
117
155
  this.#Compact(true);
118
156
  return ids.length;
119
157
  }
158
+
159
+ /** Starts queued work while concurrency permits for the resource work queue. */
120
160
  Pump(options = {}) {
121
- const maxItems = NormalizeLimit(options.maxItems);
122
- const maxTime = NormalizeLimit(options.maxTime);
123
- const now = typeof options.now === "function" ? options.now : DefaultNow;
161
+ const maxItems = normalizeLimit(options.maxItems);
162
+ const maxTime = normalizeLimit(options.maxTime);
163
+ const now = typeof options.now === "function" ? options.now : defaultNow;
124
164
  const startedAt = now();
125
165
  let processed = 0;
126
166
  if (!this.#paused) {
@@ -141,6 +181,11 @@ class CjsResManWorkQueue {
141
181
  paused: this.#paused
142
182
  });
143
183
  }
184
+
185
+ /**
186
+ * Returns an immutable snapshot of queue counts and policy for the resource
187
+ * work queue.
188
+ */
144
189
  GetStats() {
145
190
  return Object.freeze({
146
191
  name: this.#name,
@@ -152,6 +197,8 @@ class CjsResManWorkQueue {
152
197
  paused: this.#paused
153
198
  });
154
199
  }
200
+
201
+ /** Removes and returns the next runnable work item for the resource work queue. */
155
202
  #TakeNext() {
156
203
  while (this.#head < this.#items.length) {
157
204
  const item = this.#items[this.#head++];
@@ -161,6 +208,8 @@ class CjsResManWorkQueue {
161
208
  }
162
209
  return null;
163
210
  }
211
+
212
+ /** Starts one queued work item for the resource work queue. */
164
213
  #Start(item) {
165
214
  item.state = "active";
166
215
  this.#active.set(item.id, item);
@@ -181,34 +230,72 @@ class CjsResManWorkQueue {
181
230
  }
182
231
  this.#Settle(item, true, result);
183
232
  }
233
+
234
+ /**
235
+ * Settles one active work item and advances the queue for the resource work
236
+ * queue.
237
+ */
184
238
  #Settle(item, didResolve, value) {
185
239
  if (!this.#active.delete(item.id)) return;
186
240
  item.state = didResolve ? "resolved" : "rejected";
187
241
  if (didResolve) item.resolve(value);else item.reject(value);
188
242
  this.#NotifyReady();
189
243
  }
244
+
245
+ /** Removes settled work items from the queue for the resource work queue. */
190
246
  #Compact(force = false) {
191
247
  if (force || this.#head > 256 && this.#head > this.#items.length * 0.5) {
192
248
  this.#items = this.#items.slice(this.#head);
193
249
  this.#head = 0;
194
250
  }
195
251
  }
252
+
253
+ /** Notifies waiters when the queue becomes ready for the resource work queue. */
196
254
  #NotifyReady() {
197
255
  if (this.#onReady && !this.#paused && this.GetQueuedCount() > 0) {
198
256
  this.#onReady(this);
199
257
  }
200
258
  }
259
+
260
+ /**
261
+ * Resolves a queue name or alias to its canonical execution lane.
262
+ *
263
+ * @param {*} value
264
+ * @returns {string}
265
+ */
266
+ static normalizeName(value) {
267
+ const name = String(value ?? "").trim().toLowerCase();
268
+ if (name === "main" || name === "prepare") return CjsResManQueue.MAIN;
269
+ if (name === "background" || name === "load") return CjsResManQueue.BACKGROUND;
270
+ throw new TypeError(`Unknown CjsResMan queue: ${value}`);
271
+ }
272
+
273
+ /**
274
+ * Creates the structured error used when queued work is cancelled.
275
+ *
276
+ * @param {string} queue
277
+ * @param {number} id
278
+ * @param {string} reason
279
+ * @returns {Error}
280
+ */
281
+ static createCancelledError(queue, id, reason = "") {
282
+ const error = new Error(`CjsResMan ${queue} queue item ${id} was cancelled.${reason ? ` ${reason}` : ""}`);
283
+ error.code = "CJS_RESMAN_QUEUE_CANCELLED";
284
+ error.queue = queue;
285
+ error.id = id;
286
+ return error;
287
+ }
201
288
  }
202
- function NormalizeLimit(value) {
289
+ function normalizeLimit(value) {
203
290
  if (value === undefined || value === null || value === 0) return Number.POSITIVE_INFINITY;
204
291
  if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
205
292
  throw new TypeError("CjsResMan queue limits must be non-negative numbers.");
206
293
  }
207
294
  return value;
208
295
  }
209
- function DefaultNow() {
296
+ function defaultNow() {
210
297
  return globalThis.performance?.now?.() ?? Date.now();
211
298
  }
212
299
 
213
- export { CjsResManQueue, CjsResManQueueCancelledError, CjsResManWorkQueue, NormalizeCjsResManQueue };
214
- //# sourceMappingURL=CjsResManQueue.js.map
300
+ export { CjsResManQueue, CjsResManWorkQueue };
301
+ //# sourceMappingURL=CjsResManWorkQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CjsResManWorkQueue.js","sources":["../../src/CjsResManWorkQueue.js"],"sourcesContent":["export const CjsResManQueue = Object.freeze({\n MAIN: \"main\",\n BACKGROUND: \"background\",\n PREPARE: \"main\",\n LOAD: \"background\"\n});\n\n/**\n * Small FIFO executor used inside `CjsResMan` that tracks item ids, pause\n * state, concurrency, cancellation, and sync/async completion while queue\n * policy stays in the manager.\n *\n * The queue deliberately does not choose task priority or resource policy.\n */\nexport class CjsResManWorkQueue\n{\n #active = new Map();\n #concurrency = 1;\n #head = 0;\n #items = [];\n #name;\n #nextId = 1;\n #onReady;\n #paused = false;\n #queued = new Map();\n\n /** Creates a CjsResManWorkQueue with caller-provided initial state. */\n constructor(name, options = {}) {\n this.#name = CjsResManWorkQueue.normalizeName(name);\n this.#onReady = typeof options.onReady === \"function\" ? options.onReady : null;\n this.SetConcurrency(options.concurrency ?? 1);\n }\n\n /**\n * Updates the maximum number of tasks that may run together for the resource\n * work queue.\n */\n SetConcurrency(value) {\n if (!Number.isInteger(value) || value < 1) {\n throw new TypeError(\"CjsResMan queue concurrency must be a positive integer.\");\n }\n this.#concurrency = value;\n this.#NotifyReady();\n return this;\n }\n\n /**\n * Returns the maximum number of tasks allowed to run together for the resource\n * work queue.\n */\n GetConcurrency() {\n return this.#concurrency;\n }\n\n /**\n * Allocates the next monotonically increasing task identifier for the resource\n * work queue.\n */\n GetNextId() {\n return this.#nextId;\n }\n\n /** Returns the number of tasks waiting to start for the resource work queue. */\n GetQueuedCount() {\n return this.#queued.size;\n }\n\n /** Returns the number of tasks currently executing for the resource work queue. */\n GetActiveCount() {\n return this.#active.size;\n }\n\n /**\n * Returns the combined number of waiting and active tasks for the resource\n * work queue.\n */\n GetPendingCount() {\n return this.#queued.size + this.#active.size;\n }\n\n /**\n * Reports whether the queue is prevented from starting work for the resource\n * work queue.\n */\n IsPaused() {\n return this.#paused;\n }\n\n /**\n * Enqueues one task and returns its cancellation-aware promise for the\n * resource work queue.\n */\n Add(callback, context = null, metadata = null) {\n if (typeof callback !== \"function\") {\n throw new TypeError(\"CjsResMan queue items require a callback.\");\n }\n\n const id = this.#nextId++;\n let resolve;\n let reject;\n const promise = new Promise((onResolve, onReject) => {\n resolve = onResolve;\n reject = onReject;\n });\n const item = {\n id,\n queue: this.#name,\n callback,\n context,\n metadata,\n promise,\n resolve,\n reject,\n state: \"queued\"\n };\n\n this.#items.push(item);\n this.#queued.set(id, item);\n this.#NotifyReady();\n return item;\n }\n\n /**\n * Cancels a queued task selected by its identifier for the resource work\n * queue.\n */\n Cancel(id, reason = \"\") {\n const item = this.#queued.get(id);\n if (!item) return false;\n this.#queued.delete(id);\n item.state = \"cancelled\";\n item.reject(CjsResManWorkQueue.createCancelledError(this.#name, id, reason));\n this.#Compact();\n return true;\n }\n\n /**\n * Prevents queued tasks from starting until resumed for the resource work\n * queue.\n */\n Pause() {\n this.#paused = true;\n return this;\n }\n\n /** Allows queued tasks to start after a pause for the resource work queue. */\n Resume() {\n if (!this.#paused) return this;\n this.#paused = false;\n this.#NotifyReady();\n return this;\n }\n\n /** Cancels every task that has not started for the resource work queue. */\n Clear(reason = \"Queue cleared.\") {\n const ids = [ ...this.#queued.keys() ];\n for (const id of ids) this.Cancel(id, reason);\n this.#Compact(true);\n return ids.length;\n }\n\n /** Starts queued work while concurrency permits for the resource work queue. */\n Pump(options = {}) {\n const maxItems = normalizeLimit(options.maxItems);\n const maxTime = normalizeLimit(options.maxTime);\n const now = typeof options.now === \"function\" ? options.now : defaultNow;\n const startedAt = now();\n let processed = 0;\n\n if (!this.#paused) {\n while (this.#active.size < this.#concurrency && processed < maxItems) {\n const item = this.#TakeNext();\n if (!item) break;\n this.#Start(item);\n processed++;\n if (processed > 0 && now() - startedAt >= maxTime) break;\n }\n }\n\n this.#Compact();\n return Object.freeze({\n processed,\n queued: this.GetQueuedCount(),\n active: this.GetActiveCount(),\n pending: this.GetPendingCount(),\n paused: this.#paused\n });\n }\n\n /**\n * Returns an immutable snapshot of queue counts and policy for the resource\n * work queue.\n */\n GetStats() {\n return Object.freeze({\n name: this.#name,\n nextId: this.#nextId,\n concurrency: this.#concurrency,\n queued: this.GetQueuedCount(),\n active: this.GetActiveCount(),\n pending: this.GetPendingCount(),\n paused: this.#paused\n });\n }\n\n /** Removes and returns the next runnable work item for the resource work queue. */\n #TakeNext() {\n while (this.#head < this.#items.length) {\n const item = this.#items[this.#head++];\n if (item.state !== \"queued\") continue;\n this.#queued.delete(item.id);\n return item;\n }\n return null;\n }\n\n /** Starts one queued work item for the resource work queue. */\n #Start(item) {\n item.state = \"active\";\n this.#active.set(item.id, item);\n\n let result;\n try {\n result = item.callback.call(item.context, Object.freeze({\n id: item.id,\n queue: item.queue,\n metadata: item.metadata\n }));\n } catch (error) {\n this.#Settle(item, false, error);\n return;\n }\n\n if (result && typeof result.then === \"function\") {\n Promise.resolve(result).then(\n value => this.#Settle(item, true, value),\n error => this.#Settle(item, false, error)\n );\n return;\n }\n this.#Settle(item, true, result);\n }\n\n /**\n * Settles one active work item and advances the queue for the resource work\n * queue.\n */\n #Settle(item, didResolve, value) {\n if (!this.#active.delete(item.id)) return;\n item.state = didResolve ? \"resolved\" : \"rejected\";\n if (didResolve) item.resolve(value);\n else item.reject(value);\n this.#NotifyReady();\n }\n\n /** Removes settled work items from the queue for the resource work queue. */\n #Compact(force = false) {\n if (force || (this.#head > 256 && this.#head > this.#items.length * 0.5)) {\n this.#items = this.#items.slice(this.#head);\n this.#head = 0;\n }\n }\n\n /** Notifies waiters when the queue becomes ready for the resource work queue. */\n #NotifyReady() {\n if (this.#onReady && !this.#paused && this.GetQueuedCount() > 0) {\n this.#onReady(this);\n }\n }\n\n /**\n * Resolves a queue name or alias to its canonical execution lane.\n *\n * @param {*} value\n * @returns {string}\n */\n static normalizeName(value)\n {\n const name = String(value ?? \"\").trim().toLowerCase();\n if (name === \"main\" || name === \"prepare\") return CjsResManQueue.MAIN;\n if (name === \"background\" || name === \"load\") return CjsResManQueue.BACKGROUND;\n throw new TypeError(`Unknown CjsResMan queue: ${value}`);\n }\n\n /**\n * Creates the structured error used when queued work is cancelled.\n *\n * @param {string} queue\n * @param {number} id\n * @param {string} reason\n * @returns {Error}\n */\n static createCancelledError(queue, id, reason = \"\")\n {\n const error = new Error(`CjsResMan ${queue} queue item ${id} was cancelled.${reason ? ` ${reason}` : \"\"}`);\n error.code = \"CJS_RESMAN_QUEUE_CANCELLED\";\n error.queue = queue;\n error.id = id;\n return error;\n }\n}\n\nfunction normalizeLimit(value) {\n if (value === undefined || value === null || value === 0) return Number.POSITIVE_INFINITY;\n if (typeof value !== \"number\" || Number.isNaN(value) || value < 0) {\n throw new TypeError(\"CjsResMan queue limits must be non-negative numbers.\");\n }\n return value;\n}\n\nfunction defaultNow() {\n return globalThis.performance?.now?.() ?? Date.now();\n}\n"],"names":["CjsResManQueue","Object","freeze","MAIN","BACKGROUND","PREPARE","LOAD","CjsResManWorkQueue","Map","constructor","name","options","normalizeName","onReady","SetConcurrency","concurrency","value","Number","isInteger","TypeError","GetConcurrency","GetNextId","GetQueuedCount","size","GetActiveCount","GetPendingCount","IsPaused","Add","callback","context","metadata","id","resolve","reject","promise","Promise","onResolve","onReject","item","queue","state","push","set","Cancel","reason","get","delete","createCancelledError","Pause","Resume","Clear","ids","keys","length","Pump","maxItems","normalizeLimit","maxTime","now","defaultNow","startedAt","processed","queued","active","pending","paused","GetStats","nextId","#TakeNext","#Start","result","call","error","then","#Settle","didResolve","#Compact","force","slice","#NotifyReady","String","trim","toLowerCase","Error","code","undefined","POSITIVE_INFINITY","isNaN","globalThis","performance","Date"],"mappings":"MAAaA,cAAc,GAAGC,MAAM,CAACC,MAAM,CAAC;AAC1CC,EAAAA,IAAI,EAAE,MAAM;AACZC,EAAAA,UAAU,EAAE,YAAY;AACxBC,EAAAA,OAAO,EAAE,MAAM;AACfC,EAAAA,IAAI,EAAE;AACR,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,CAC/B;AACE,EAAA,OAAO,GAAG,IAAIC,GAAG,EAAE;EACnB,YAAY,GAAG,CAAC;EAChB,KAAK,GAAG,CAAC;EACT,MAAM,GAAG,EAAE;AACX,EAAA,KAAK;EACL,OAAO,GAAG,CAAC;AACX,EAAA,QAAQ;EACR,OAAO,GAAG,KAAK;AACf,EAAA,OAAO,GAAG,IAAIA,GAAG,EAAE;;AAEnB;AACAC,EAAAA,WAAWA,CAACC,IAAI,EAAEC,OAAO,GAAG,EAAE,EAAE;IAC9B,IAAI,CAAC,KAAK,GAAGJ,kBAAkB,CAACK,aAAa,CAACF,IAAI,CAAC;AACnD,IAAA,IAAI,CAAC,QAAQ,GAAG,OAAOC,OAAO,CAACE,OAAO,KAAK,UAAU,GAAGF,OAAO,CAACE,OAAO,GAAG,IAAI;IAC9E,IAAI,CAACC,cAAc,CAACH,OAAO,CAACI,WAAW,IAAI,CAAC,CAAC;AAC/C,EAAA;;AAEA;AACF;AACA;AACA;EACED,cAAcA,CAACE,KAAK,EAAE;IACpB,IAAI,CAACC,MAAM,CAACC,SAAS,CAACF,KAAK,CAAC,IAAIA,KAAK,GAAG,CAAC,EAAE;AACzC,MAAA,MAAM,IAAIG,SAAS,CAAC,yDAAyD,CAAC;AAChF,IAAA;AACA,IAAA,IAAI,CAAC,YAAY,GAAGH,KAAK;AACzB,IAAA,IAAI,CAAC,YAAY,EAAE;AACnB,IAAA,OAAO,IAAI;AACb,EAAA;;AAEA;AAC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G,4BAA4B;IACzCZ,KAAK,CAACjC,KAAK,GAAGA,KAAK;IACnBiC,KAAK,CAACzC,EAAE,GAAGA,EAAE;AACb,IAAA,OAAOyC,KAAK;AACd,EAAA;AACF;AAEA,SAAShB,cAAcA,CAACxC,KAAK,EAAE;AAC7B,EAAA,IAAIA,KAAK,KAAKqE,SAAS,IAAIrE,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAK,CAAC,EAAE,OAAOC,MAAM,CAACqE,iBAAiB;AACzF,EAAA,IAAI,OAAOtE,KAAK,KAAK,QAAQ,IAAIC,MAAM,CAACsE,KAAK,CAACvE,KAAK,CAAC,IAAIA,KAAK,GAAG,CAAC,EAAE;AACjE,IAAA,MAAM,IAAIG,SAAS,CAAC,sDAAsD,CAAC;AAC7E,EAAA;AACA,EAAA,OAAOH,KAAK;AACd;AAEA,SAAS2C,UAAUA,GAAG;AACpB,EAAA,OAAO6B,UAAU,CAACC,WAAW,EAAE/B,GAAG,IAAI,IAAIgC,IAAI,CAAChC,GAAG,EAAE;AACtD;;;;"}
@@ -14,6 +14,10 @@ import { CjsReader } from './CjsReader.js';
14
14
  * path yet and retains its lenient named-field behavior.
15
15
  */
16
16
  class CjsBlueReader extends CjsReader {
17
+ /**
18
+ * Creates a CjsBlueReader over caller-provided resource bytes and reader
19
+ * options.
20
+ */
17
21
  constructor(options = {}, config = {}) {
18
22
  super({
19
23
  ...options
@@ -37,15 +41,24 @@ class CjsBlueReader extends CjsReader {
37
41
  };
38
42
  this.ResetBlueReadState();
39
43
  }
44
+
45
+ /** Clears blue read state before reusing the current Blue graph reader. */
40
46
  ResetBlueReadState() {
41
47
  this.reports = [];
42
48
  this.runtimeInstances = [];
43
49
  }
50
+
51
+ /**
52
+ * Finalizes runtime instances after the current Blue graph reader has been
53
+ * read.
54
+ */
44
55
  FinalizeRuntimeInstances() {
45
56
  for (const record of this.runtimeInstances) {
46
57
  this.adapter.finalize(record.instance, this.CreateRuntimeContext(record.kind, record.shape, false));
47
58
  }
48
59
  }
60
+
61
+ /** Creates runtime target for the current Blue graph reader. */
49
62
  CreateRuntimeTarget(kind, shape = null) {
50
63
  const built = this.adapter.construct(kind, this.CreateRuntimeContext(kind, shape, true, this.options));
51
64
  if (built !== undefined) return built;
@@ -53,6 +66,8 @@ class CjsBlueReader extends CjsReader {
53
66
  if (ClassConstructor) return new ClassConstructor();
54
67
  return this.CreateRuntimeFallback(kind, shape);
55
68
  }
69
+
70
+ /** Creates runtime fallback for the current Blue graph reader. */
56
71
  CreateRuntimeFallback(kind, shape = null) {
57
72
  const target = {
58
73
  _sourceClassName: this.includeSourceShape ? kind : kind || null
@@ -60,6 +75,8 @@ class CjsBlueReader extends CjsReader {
60
75
  if (this.includeSourceShape) target._sourceShape = shape || null;
61
76
  return target;
62
77
  }
78
+
79
+ /** Applies runtime values to the current Blue graph reader. */
63
80
  ApplyRuntimeValues(target, values, kind, shape = null) {
64
81
  this.adapter.applyValues(target, values, this.CreateRuntimeContext(kind, shape, true, this.hydrationOptions));
65
82
  this.runtimeInstances.push({
@@ -68,6 +85,8 @@ class CjsBlueReader extends CjsReader {
68
85
  shape
69
86
  });
70
87
  }
88
+
89
+ /** Creates runtime context for the current Blue graph reader. */
71
90
  CreateRuntimeContext(kind, shape, includeOptions, options = null) {
72
91
  const context = {
73
92
  kind
@@ -76,12 +95,16 @@ class CjsBlueReader extends CjsReader {
76
95
  if (includeOptions) context.options = options;
77
96
  return context;
78
97
  }
98
+
99
+ /** Creates payload target for the current Blue graph reader. */
79
100
  CreatePayloadTarget(kind) {
80
101
  const typeField = this.GetPayloadTypeField();
81
102
  return typeField && (kind || this.includeEmptyPayloadType) ? {
82
103
  [typeField]: kind
83
104
  } : {};
84
105
  }
106
+
107
+ /** Creates payload reference for the current Blue graph reader. */
85
108
  CreatePayloadReference(targetObject, referenceId) {
86
109
  const idField = this.GetPayloadIdField();
87
110
  const referenceField = this.GetPayloadReferenceField();
@@ -94,18 +117,28 @@ class CjsBlueReader extends CjsReader {
94
117
  [referenceField]: referenceId
95
118
  } : targetObject;
96
119
  }
120
+
121
+ /** Returns payload type field from the current Blue graph reader. */
97
122
  GetPayloadTypeField() {
98
123
  return this.GetPayloadField("payloadTypeField", "_type");
99
124
  }
125
+
126
+ /** Returns payload ID field from the current Blue graph reader. */
100
127
  GetPayloadIdField() {
101
128
  return this.GetPayloadField("payloadIdField", "_id");
102
129
  }
130
+
131
+ /** Returns payload reference field from the current Blue graph reader. */
103
132
  GetPayloadReferenceField() {
104
133
  return this.GetPayloadField("payloadReferenceField", "_reference");
105
134
  }
135
+
136
+ /** Returns payload values field from the current Blue graph reader. */
106
137
  GetPayloadValuesField() {
107
138
  return this.GetPayloadField("payloadValuesField", "_values");
108
139
  }
140
+
141
+ /** Returns payload field from the current Blue graph reader. */
109
142
  GetPayloadField(name, fallback) {
110
143
  const value = this.options[name];
111
144
  if (!this.validatePayloadReservedFields) {
@@ -116,6 +149,11 @@ class CjsBlueReader extends CjsReader {
116
149
  if (typeof value === "string" && value) return value;
117
150
  throw this.PayloadError("PAYLOAD_MARKER_CONFIGURATION", `${name} must be a non-empty string or false`);
118
151
  }
152
+
153
+ /**
154
+ * Validates payload configuration against Blue graph reader constraints and
155
+ * throws on failure.
156
+ */
119
157
  ValidatePayloadConfiguration() {
120
158
  if (!this.validatePayloadReservedFields) {
121
159
  this.payloadReservedFields = null;
@@ -142,6 +180,11 @@ class CjsBlueReader extends CjsReader {
142
180
  }
143
181
  this.payloadReservedFields = reserved;
144
182
  }
183
+
184
+ /**
185
+ * Validates payload field available against Blue graph reader constraints
186
+ * and throws on failure.
187
+ */
145
188
  AssertPayloadFieldAvailable(field) {
146
189
  if (!this.validatePayloadReservedFields) return;
147
190
  if (!this.payloadReservedFields) this.ValidatePayloadConfiguration();
@@ -149,12 +192,22 @@ class CjsBlueReader extends CjsReader {
149
192
  if (!role) return;
150
193
  throw this.PayloadError("PAYLOAD_RESERVED_FIELD_COLLISION", `payload field "${field}" is reserved for the ${role} marker`);
151
194
  }
195
+
196
+ /**
197
+ * Assigns payload values while preserving the current Blue graph reader
198
+ * contract.
199
+ */
152
200
  AssignPayloadValues(targetObject, values) {
153
201
  for (const [field, value] of Object.entries(values)) {
154
202
  this.AssertPayloadFieldAvailable(field);
155
203
  this.DefinePayloadProperty(targetObject, field, value);
156
204
  }
157
205
  }
206
+
207
+ /**
208
+ * Assigns payload reference ID while preserving the current Blue graph
209
+ * reader contract.
210
+ */
158
211
  AssignPayloadReferenceId(targetObject, idField, referenceId) {
159
212
  if (!Object.hasOwn(targetObject, idField)) {
160
213
  this.DefinePayloadProperty(targetObject, idField, referenceId);
@@ -164,11 +217,18 @@ class CjsBlueReader extends CjsReader {
164
217
  if (targetObject[idField] === referenceId) return;
165
218
  throw this.PayloadError("PAYLOAD_RESERVED_FIELD_COLLISION", `payload ID field "${idField}" conflicts with reference ${referenceId}`);
166
219
  }
220
+
221
+ /**
222
+ * Creates a payload error annotated with the current graph context for the
223
+ * Blue graph reader.
224
+ */
167
225
  PayloadError(code, message) {
168
226
  const error = new TypeError(`${code}: ${message}`);
169
227
  error.code = code;
170
228
  return error;
171
229
  }
230
+
231
+ /** Defines payload property on the current Blue graph reader result. */
172
232
  DefinePayloadProperty(targetObject, field, value) {
173
233
  Object.defineProperty(targetObject, field, {
174
234
  value,
@@ -177,6 +237,11 @@ class CjsBlueReader extends CjsReader {
177
237
  writable: true
178
238
  });
179
239
  }
240
+
241
+ /**
242
+ * Assigns runtime field value while preserving the current Blue graph reader
243
+ * contract.
244
+ */
180
245
  AssignRuntimeFieldValue(targetObject, target, value) {
181
246
  if (target.unknown) {
182
247
  targetObject[target.wireName] = value;
@@ -193,6 +258,11 @@ class CjsBlueReader extends CjsReader {
193
258
  }
194
259
  targetObject[target.field.name] = this.NormalizeRuntimeFieldValue(value, target.field);
195
260
  }
261
+
262
+ /**
263
+ * Assigns payload field value while preserving the current Blue graph reader
264
+ * contract.
265
+ */
196
266
  AssignPayloadFieldValue(targetObject, target, value) {
197
267
  this.AssertPayloadFieldAvailable(target.unknown ? target.wireName : target.field.name);
198
268
  if (target.unknown) {
@@ -222,6 +292,11 @@ class CjsBlueReader extends CjsReader {
222
292
  targetObject[target.field.name] = value;
223
293
  }
224
294
  }
295
+
296
+ /**
297
+ * Converts runtime field value into the canonical Blue graph reader
298
+ * representation.
299
+ */
225
300
  NormalizeRuntimeFieldValue(value, field) {
226
301
  if (!field) return value;
227
302
 
@@ -236,6 +311,8 @@ class CjsBlueReader extends CjsReader {
236
311
  if (CjsBlueReader.isShapeIncompatibleMathArray(value, descriptor)) return value;
237
312
  return normalizeCarbonValue(value, field);
238
313
  }
314
+
315
+ /** Resolves source shape against the current Blue graph reader. */
239
316
  ResolveSourceShape(kind) {
240
317
  const registry = this.options.registry || null;
241
318
  if (registry?.GetSourceShape) return registry.GetSourceShape(kind);
@@ -249,16 +326,28 @@ class CjsBlueReader extends CjsReader {
249
326
  }
250
327
  return this.schemaShapes.get(kind) || null;
251
328
  }
329
+
330
+ /** Resolves class against the current Blue graph reader. */
252
331
  ResolveClass(kind) {
253
332
  if (!kind) return null;
254
333
  const classes = this.options.classes || {};
255
334
  const Registry = this.options.registry || this.defaultRegistry;
256
335
  return classes[kind] || (Registry ? Registry.GetConstructor(kind) : null);
257
336
  }
337
+
338
+ /**
339
+ * Applies the configured resource-path transform to a decoded field value
340
+ * for the Blue graph reader.
341
+ */
258
342
  TransformPath(value) {
259
343
  const handler = this.options.pathHandler;
260
344
  return typeof handler === "function" ? handler(value) : value;
261
345
  }
346
+
347
+ /**
348
+ * Reports whether the current Blue graph reader satisfies shape incompatible
349
+ * math array.
350
+ */
262
351
  static isShapeIncompatibleMathArray(value, descriptor) {
263
352
  const expectedLength = descriptor?.length;
264
353
  return Array.isArray(value) && Number.isInteger(expectedLength) && value.length !== expectedLength;