@motion-core/motion-gpu 0.4.1 → 0.5.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 (228) hide show
  1. package/README.md +99 -0
  2. package/dist/advanced.d.ts +1 -0
  3. package/dist/advanced.d.ts.map +1 -0
  4. package/dist/advanced.js +14 -6
  5. package/dist/core/advanced.d.ts +1 -0
  6. package/dist/core/advanced.d.ts.map +1 -0
  7. package/dist/core/advanced.js +14 -5
  8. package/dist/core/compute-shader.d.ts +87 -0
  9. package/dist/core/compute-shader.d.ts.map +1 -0
  10. package/dist/core/compute-shader.js +205 -0
  11. package/dist/core/compute-shader.js.map +1 -0
  12. package/dist/core/current-value.d.ts +1 -0
  13. package/dist/core/current-value.d.ts.map +1 -0
  14. package/dist/core/current-value.js +35 -34
  15. package/dist/core/current-value.js.map +1 -0
  16. package/dist/core/error-diagnostics.d.ts +1 -0
  17. package/dist/core/error-diagnostics.d.ts.map +1 -0
  18. package/dist/core/error-diagnostics.js +70 -137
  19. package/dist/core/error-diagnostics.js.map +1 -0
  20. package/dist/core/error-report.d.ts +2 -1
  21. package/dist/core/error-report.d.ts.map +1 -0
  22. package/dist/core/error-report.js +247 -233
  23. package/dist/core/error-report.js.map +1 -0
  24. package/dist/core/frame-registry.d.ts +1 -0
  25. package/dist/core/frame-registry.d.ts.map +1 -0
  26. package/dist/core/frame-registry.js +546 -662
  27. package/dist/core/frame-registry.js.map +1 -0
  28. package/dist/core/index.d.ts +6 -2
  29. package/dist/core/index.d.ts.map +1 -0
  30. package/dist/core/index.js +13 -12
  31. package/dist/core/material-preprocess.d.ts +1 -0
  32. package/dist/core/material-preprocess.d.ts.map +1 -0
  33. package/dist/core/material-preprocess.js +131 -152
  34. package/dist/core/material-preprocess.js.map +1 -0
  35. package/dist/core/material.d.ts +23 -6
  36. package/dist/core/material.d.ts.map +1 -0
  37. package/dist/core/material.js +290 -317
  38. package/dist/core/material.js.map +1 -0
  39. package/dist/core/recompile-policy.d.ts +1 -0
  40. package/dist/core/recompile-policy.d.ts.map +1 -0
  41. package/dist/core/recompile-policy.js +18 -13
  42. package/dist/core/recompile-policy.js.map +1 -0
  43. package/dist/core/render-graph.d.ts +8 -3
  44. package/dist/core/render-graph.d.ts.map +1 -0
  45. package/dist/core/render-graph.js +77 -68
  46. package/dist/core/render-graph.js.map +1 -0
  47. package/dist/core/render-targets.d.ts +1 -0
  48. package/dist/core/render-targets.d.ts.map +1 -0
  49. package/dist/core/render-targets.js +52 -53
  50. package/dist/core/render-targets.js.map +1 -0
  51. package/dist/core/renderer.d.ts +1 -0
  52. package/dist/core/renderer.d.ts.map +1 -0
  53. package/dist/core/renderer.js +1337 -1081
  54. package/dist/core/renderer.js.map +1 -0
  55. package/dist/core/runtime-loop.d.ts +3 -2
  56. package/dist/core/runtime-loop.d.ts.map +1 -0
  57. package/dist/core/runtime-loop.js +353 -362
  58. package/dist/core/runtime-loop.js.map +1 -0
  59. package/dist/core/scheduler-helpers.d.ts +1 -0
  60. package/dist/core/scheduler-helpers.d.ts.map +1 -0
  61. package/dist/core/scheduler-helpers.js +52 -51
  62. package/dist/core/scheduler-helpers.js.map +1 -0
  63. package/dist/core/shader.d.ts +10 -1
  64. package/dist/core/shader.d.ts.map +1 -0
  65. package/dist/core/shader.js +109 -115
  66. package/dist/core/shader.js.map +1 -0
  67. package/dist/core/storage-buffers.d.ts +37 -0
  68. package/dist/core/storage-buffers.d.ts.map +1 -0
  69. package/dist/core/storage-buffers.js +95 -0
  70. package/dist/core/storage-buffers.js.map +1 -0
  71. package/dist/core/texture-loader.d.ts +1 -0
  72. package/dist/core/texture-loader.d.ts.map +1 -0
  73. package/dist/core/texture-loader.js +209 -273
  74. package/dist/core/texture-loader.js.map +1 -0
  75. package/dist/core/textures.d.ts +13 -0
  76. package/dist/core/textures.d.ts.map +1 -0
  77. package/dist/core/textures.js +111 -116
  78. package/dist/core/textures.js.map +1 -0
  79. package/dist/core/types.d.ts +147 -4
  80. package/dist/core/types.d.ts.map +1 -0
  81. package/dist/core/types.js +0 -4
  82. package/dist/core/uniforms.d.ts +1 -0
  83. package/dist/core/uniforms.d.ts.map +1 -0
  84. package/dist/core/uniforms.js +170 -191
  85. package/dist/core/uniforms.js.map +1 -0
  86. package/dist/index.d.ts +1 -0
  87. package/dist/index.d.ts.map +1 -0
  88. package/dist/index.js +13 -6
  89. package/dist/passes/BlitPass.d.ts +1 -0
  90. package/dist/passes/BlitPass.d.ts.map +1 -0
  91. package/dist/passes/BlitPass.js +23 -18
  92. package/dist/passes/BlitPass.js.map +1 -0
  93. package/dist/passes/ComputePass.d.ts +83 -0
  94. package/dist/passes/ComputePass.d.ts.map +1 -0
  95. package/dist/passes/ComputePass.js +92 -0
  96. package/dist/passes/ComputePass.js.map +1 -0
  97. package/dist/passes/CopyPass.d.ts +1 -0
  98. package/dist/passes/CopyPass.d.ts.map +1 -0
  99. package/dist/passes/CopyPass.js +58 -52
  100. package/dist/passes/CopyPass.js.map +1 -0
  101. package/dist/passes/FullscreenPass.d.ts +1 -0
  102. package/dist/passes/FullscreenPass.d.ts.map +1 -0
  103. package/dist/passes/FullscreenPass.js +127 -130
  104. package/dist/passes/FullscreenPass.js.map +1 -0
  105. package/dist/passes/PingPongComputePass.d.ts +104 -0
  106. package/dist/passes/PingPongComputePass.d.ts.map +1 -0
  107. package/dist/passes/PingPongComputePass.js +132 -0
  108. package/dist/passes/PingPongComputePass.js.map +1 -0
  109. package/dist/passes/ShaderPass.d.ts +1 -0
  110. package/dist/passes/ShaderPass.d.ts.map +1 -0
  111. package/dist/passes/ShaderPass.js +41 -37
  112. package/dist/passes/ShaderPass.js.map +1 -0
  113. package/dist/passes/index.d.ts +3 -0
  114. package/dist/passes/index.d.ts.map +1 -0
  115. package/dist/passes/index.js +6 -3
  116. package/dist/react/FragCanvas.d.ts +3 -2
  117. package/dist/react/FragCanvas.d.ts.map +1 -0
  118. package/dist/react/FragCanvas.js +234 -211
  119. package/dist/react/FragCanvas.js.map +1 -0
  120. package/dist/react/MotionGPUErrorOverlay.d.ts +1 -0
  121. package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -0
  122. package/dist/react/MotionGPUErrorOverlay.js +200 -14
  123. package/dist/react/MotionGPUErrorOverlay.js.map +1 -0
  124. package/dist/react/Portal.d.ts +1 -0
  125. package/dist/react/Portal.d.ts.map +1 -0
  126. package/dist/react/Portal.js +18 -21
  127. package/dist/react/Portal.js.map +1 -0
  128. package/dist/react/advanced.d.ts +1 -0
  129. package/dist/react/advanced.d.ts.map +1 -0
  130. package/dist/react/advanced.js +14 -6
  131. package/dist/react/frame-context.d.ts +1 -0
  132. package/dist/react/frame-context.d.ts.map +1 -0
  133. package/dist/react/frame-context.js +88 -94
  134. package/dist/react/frame-context.js.map +1 -0
  135. package/dist/react/index.d.ts +6 -2
  136. package/dist/react/index.d.ts.map +1 -0
  137. package/dist/react/index.js +12 -9
  138. package/dist/react/motiongpu-context.d.ts +1 -0
  139. package/dist/react/motiongpu-context.d.ts.map +1 -0
  140. package/dist/react/motiongpu-context.js +18 -15
  141. package/dist/react/motiongpu-context.js.map +1 -0
  142. package/dist/react/use-motiongpu-user-context.d.ts +1 -0
  143. package/dist/react/use-motiongpu-user-context.d.ts.map +1 -0
  144. package/dist/react/use-motiongpu-user-context.js +83 -82
  145. package/dist/react/use-motiongpu-user-context.js.map +1 -0
  146. package/dist/react/use-texture.d.ts +1 -0
  147. package/dist/react/use-texture.d.ts.map +1 -0
  148. package/dist/react/use-texture.js +132 -152
  149. package/dist/react/use-texture.js.map +1 -0
  150. package/dist/svelte/FragCanvas.svelte +2 -2
  151. package/dist/svelte/FragCanvas.svelte.d.ts +3 -2
  152. package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
  153. package/dist/svelte/MotionGPUErrorOverlay.svelte +137 -7
  154. package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts +1 -0
  155. package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -0
  156. package/dist/svelte/Portal.svelte.d.ts +1 -0
  157. package/dist/svelte/Portal.svelte.d.ts.map +1 -0
  158. package/dist/svelte/advanced.d.ts +1 -0
  159. package/dist/svelte/advanced.d.ts.map +1 -0
  160. package/dist/svelte/advanced.js +13 -6
  161. package/dist/svelte/frame-context.d.ts +1 -0
  162. package/dist/svelte/frame-context.d.ts.map +1 -0
  163. package/dist/svelte/frame-context.js +27 -27
  164. package/dist/svelte/frame-context.js.map +1 -0
  165. package/dist/svelte/index.d.ts +6 -2
  166. package/dist/svelte/index.d.ts.map +1 -0
  167. package/dist/svelte/index.js +12 -9
  168. package/dist/svelte/motiongpu-context.d.ts +1 -0
  169. package/dist/svelte/motiongpu-context.d.ts.map +1 -0
  170. package/dist/svelte/motiongpu-context.js +24 -21
  171. package/dist/svelte/motiongpu-context.js.map +1 -0
  172. package/dist/svelte/use-motiongpu-user-context.d.ts +1 -0
  173. package/dist/svelte/use-motiongpu-user-context.d.ts.map +1 -0
  174. package/dist/svelte/use-motiongpu-user-context.js +69 -70
  175. package/dist/svelte/use-motiongpu-user-context.js.map +1 -0
  176. package/dist/svelte/use-texture.d.ts +1 -0
  177. package/dist/svelte/use-texture.d.ts.map +1 -0
  178. package/dist/svelte/use-texture.js +125 -147
  179. package/dist/svelte/use-texture.js.map +1 -0
  180. package/package.json +12 -7
  181. package/src/lib/advanced.ts +6 -0
  182. package/src/lib/core/advanced.ts +12 -0
  183. package/src/lib/core/compute-shader.ts +326 -0
  184. package/src/lib/core/current-value.ts +64 -0
  185. package/src/lib/core/error-diagnostics.ts +236 -0
  186. package/src/lib/core/error-report.ts +535 -0
  187. package/src/lib/core/frame-registry.ts +1190 -0
  188. package/src/lib/core/index.ts +94 -0
  189. package/src/lib/core/material-preprocess.ts +295 -0
  190. package/src/lib/core/material.ts +748 -0
  191. package/src/lib/core/recompile-policy.ts +31 -0
  192. package/src/lib/core/render-graph.ts +173 -0
  193. package/src/lib/core/render-targets.ts +107 -0
  194. package/src/lib/core/renderer.ts +2161 -0
  195. package/src/lib/core/runtime-loop.ts +537 -0
  196. package/src/lib/core/scheduler-helpers.ts +136 -0
  197. package/src/lib/core/shader.ts +301 -0
  198. package/src/lib/core/storage-buffers.ts +142 -0
  199. package/src/lib/core/texture-loader.ts +482 -0
  200. package/src/lib/core/textures.ts +257 -0
  201. package/src/lib/core/types.ts +743 -0
  202. package/src/lib/core/uniforms.ts +282 -0
  203. package/src/lib/index.ts +6 -0
  204. package/src/lib/passes/BlitPass.ts +54 -0
  205. package/src/lib/passes/ComputePass.ts +136 -0
  206. package/src/lib/passes/CopyPass.ts +80 -0
  207. package/src/lib/passes/FullscreenPass.ts +173 -0
  208. package/src/lib/passes/PingPongComputePass.ts +180 -0
  209. package/src/lib/passes/ShaderPass.ts +89 -0
  210. package/src/lib/passes/index.ts +9 -0
  211. package/src/lib/react/FragCanvas.tsx +345 -0
  212. package/src/lib/react/MotionGPUErrorOverlay.tsx +524 -0
  213. package/src/lib/react/Portal.tsx +34 -0
  214. package/src/lib/react/advanced.ts +36 -0
  215. package/src/lib/react/frame-context.ts +169 -0
  216. package/src/lib/react/index.ts +68 -0
  217. package/src/lib/react/motiongpu-context.ts +88 -0
  218. package/src/lib/react/use-motiongpu-user-context.ts +186 -0
  219. package/src/lib/react/use-texture.ts +233 -0
  220. package/src/lib/svelte/FragCanvas.svelte +249 -0
  221. package/src/lib/svelte/MotionGPUErrorOverlay.svelte +512 -0
  222. package/src/lib/svelte/Portal.svelte +31 -0
  223. package/src/lib/svelte/advanced.ts +32 -0
  224. package/src/lib/svelte/frame-context.ts +87 -0
  225. package/src/lib/svelte/index.ts +68 -0
  226. package/src/lib/svelte/motiongpu-context.ts +97 -0
  227. package/src/lib/svelte/use-motiongpu-user-context.ts +145 -0
  228. package/src/lib/svelte/use-texture.ts +232 -0
@@ -3,13 +3,17 @@
3
3
  */
4
4
  export { FragCanvas } from './FragCanvas.js';
5
5
  export { defineMaterial } from '../core/material.js';
6
- export { BlitPass, CopyPass, ShaderPass } from '../passes/index.js';
6
+ export { BlitPass, CopyPass, ShaderPass, ComputePass, PingPongComputePass } from '../passes/index.js';
7
7
  export { useMotionGPU } from './motiongpu-context.js';
8
8
  export { useFrame } from './frame-context.js';
9
9
  export { useTexture } from './use-texture.js';
10
- export type { FrameInvalidationToken, FrameState, OutputColorSpace, RenderPass, RenderPassContext, RenderPassFlags, RenderPassInputSlot, RenderPassOutputSlot, RenderMode, RenderTarget, RenderTargetDefinition, RenderTargetDefinitionMap, TextureData, TextureDefinition, TextureDefinitionMap, TextureUpdateMode, TextureMap, TextureSource, TextureValue, TypedUniform, UniformMat4Value, UniformMap, UniformType, UniformValue } from '../core/types.js';
10
+ export type { FrameInvalidationToken, FrameState, OutputColorSpace, AnyPass, ComputePassLike, RenderPass, RenderPassContext, RenderPassFlags, RenderPassInputSlot, RenderPassOutputSlot, RenderMode, RenderTarget, RenderTargetDefinition, RenderTargetDefinitionMap, TextureData, TextureDefinition, TextureDefinitionMap, TextureUpdateMode, TextureMap, TextureSource, TextureValue, TypedUniform, UniformMat4Value, UniformMap, UniformType, UniformValue } from '../core/types.js';
11
11
  export type { LoadedTexture, TextureDecodeOptions, TextureLoadOptions } from '../core/texture-loader.js';
12
12
  export type { FragMaterial, FragMaterialInput, MaterialIncludes, MaterialDefineValue, MaterialDefines, TypedMaterialDefineValue } from '../core/material.js';
13
13
  export type { MotionGPUContext } from './motiongpu-context.js';
14
14
  export type { UseFrameOptions, UseFrameResult } from './frame-context.js';
15
15
  export type { TextureUrlInput, UseTextureResult } from './use-texture.js';
16
+ export type { StorageBufferAccess, StorageBufferDefinition, StorageBufferDefinitionMap, StorageBufferType, ComputePassContext } from '../core/types.js';
17
+ export type { ComputePassOptions, ComputeDispatchContext } from '../passes/ComputePass.js';
18
+ export type { PingPongComputePassOptions } from '../passes/PingPongComputePass.js';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/react/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACN,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACX,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACX,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACX,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC1E,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,YAAY,EACX,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,YAAY,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC"}
@@ -1,9 +1,12 @@
1
- /**
2
- * React adapter entrypoint for MotionGPU.
3
- */
4
- export { FragCanvas } from './FragCanvas.js';
5
- export { defineMaterial } from '../core/material.js';
6
- export { BlitPass, CopyPass, ShaderPass } from '../passes/index.js';
7
- export { useMotionGPU } from './motiongpu-context.js';
8
- export { useFrame } from './frame-context.js';
9
- export { useTexture } from './use-texture.js';
1
+ import { defineMaterial } from "../core/material.js";
2
+ import { BlitPass } from "../passes/BlitPass.js";
3
+ import { CopyPass } from "../passes/CopyPass.js";
4
+ import { ShaderPass } from "../passes/ShaderPass.js";
5
+ import { ComputePass } from "../passes/ComputePass.js";
6
+ import { PingPongComputePass } from "../passes/PingPongComputePass.js";
7
+ import "../passes/index.js";
8
+ import { useMotionGPU } from "./motiongpu-context.js";
9
+ import { useFrame } from "./frame-context.js";
10
+ import { FragCanvas } from "./FragCanvas.js";
11
+ import { useTexture } from "./use-texture.js";
12
+ export { BlitPass, ComputePass, CopyPass, FragCanvas, PingPongComputePass, ShaderPass, defineMaterial, useFrame, useMotionGPU, useTexture };
@@ -71,3 +71,4 @@ export declare const MotionGPUReactContext: import("react").Context<MotionGPUCon
71
71
  * @throws {Error} When called outside `<FragCanvas>`.
72
72
  */
73
73
  export declare function useMotionGPU(): MotionGPUContext;
74
+ //# sourceMappingURL=motiongpu-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motiongpu-context.d.ts","sourceRoot":"","sources":["../../src/lib/react/motiongpu-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,kBAAkB,IAAI,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtC;;OAEG;IACH,IAAI,EAAE,eAAe,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzD;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;IACxC;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACrC;;OAEG;IACH,IAAI,EAAE,oBAAoB,CAAC;IAC3B;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;CAC9B;AAED,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAAC,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5F;;GAEG;AACH,eAAO,MAAM,qBAAqB,kDAA+C,CAAC;AAElF;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,gBAAgB,CAO/C"}
@@ -1,18 +1,21 @@
1
- import { createContext, useContext } from 'react';
1
+ import { createContext, useContext } from "react";
2
+ //#region src/lib/react/motiongpu-context.ts
2
3
  /**
3
- * Internal React context container.
4
- */
5
- export const MotionGPUReactContext = createContext(null);
4
+ * Internal React context container.
5
+ */
6
+ var MotionGPUReactContext = createContext(null);
6
7
  /**
7
- * Returns active MotionGPU runtime context.
8
- *
9
- * @returns Active context.
10
- * @throws {Error} When called outside `<FragCanvas>`.
11
- */
12
- export function useMotionGPU() {
13
- const context = useContext(MotionGPUReactContext);
14
- if (!context) {
15
- throw new Error('useMotionGPU must be used inside <FragCanvas>');
16
- }
17
- return context;
8
+ * Returns active MotionGPU runtime context.
9
+ *
10
+ * @returns Active context.
11
+ * @throws {Error} When called outside `<FragCanvas>`.
12
+ */
13
+ function useMotionGPU() {
14
+ const context = useContext(MotionGPUReactContext);
15
+ if (!context) throw new Error("useMotionGPU must be used inside <FragCanvas>");
16
+ return context;
18
17
  }
18
+ //#endregion
19
+ export { MotionGPUReactContext, useMotionGPU };
20
+
21
+ //# sourceMappingURL=motiongpu-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motiongpu-context.js","names":[],"sources":["../../src/lib/react/motiongpu-context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { RenderMode } from '../core/types.js';\nimport type { CurrentReadable, CurrentWritable } from '../core/current-value.js';\nimport type {\n\tFrameProfilingSnapshot,\n\tFrameRunTimings,\n\tFrameScheduleSnapshot\n} from '../core/frame-registry.js';\nimport type { MotionGPUScheduler as CoreMotionGPUScheduler } from '../core/scheduler-helpers.js';\n\n/**\n * React context payload exposed by `<FragCanvas>`.\n */\nexport interface MotionGPUContext {\n\t/**\n\t * Underlying canvas element used by the renderer.\n\t */\n\tcanvas: HTMLCanvasElement | undefined;\n\t/**\n\t * Reactive canvas pixel size.\n\t */\n\tsize: CurrentReadable<{ width: number; height: number }>;\n\t/**\n\t * Device pixel ratio multiplier.\n\t */\n\tdpr: CurrentWritable<number>;\n\t/**\n\t * Max frame delta clamp passed to scheduled callbacks.\n\t */\n\tmaxDelta: CurrentWritable<number>;\n\t/**\n\t * Scheduler render mode (`always`, `on-demand`, `manual`).\n\t */\n\trenderMode: CurrentWritable<RenderMode>;\n\t/**\n\t * Global toggle for automatic rendering.\n\t */\n\tautoRender: CurrentWritable<boolean>;\n\t/**\n\t * Namespaced user context store shared within the canvas subtree.\n\t */\n\tuser: MotionGPUUserContext;\n\t/**\n\t * Marks current frame as invalidated.\n\t */\n\tinvalidate: () => void;\n\t/**\n\t * Requests one manual frame advance.\n\t */\n\tadvance: () => void;\n\t/**\n\t * Public scheduler API.\n\t */\n\tscheduler: MotionGPUScheduler;\n}\n\nexport type MotionGPUScheduler = CoreMotionGPUScheduler;\nexport type { FrameProfilingSnapshot, FrameRunTimings, FrameScheduleSnapshot };\n\n/**\n * Namespace identifier for user-owned context entries.\n */\nexport type MotionGPUUserNamespace = string | symbol;\n\n/**\n * Shared user context store exposed by `FragCanvas`.\n */\nexport type MotionGPUUserContext = CurrentWritable<Record<MotionGPUUserNamespace, unknown>>;\n\n/**\n * Internal React context container.\n */\nexport const MotionGPUReactContext = createContext<MotionGPUContext | null>(null);\n\n/**\n * Returns active MotionGPU runtime context.\n *\n * @returns Active context.\n * @throws {Error} When called outside `<FragCanvas>`.\n */\nexport function useMotionGPU(): MotionGPUContext {\n\tconst context = useContext(MotionGPUReactContext);\n\tif (!context) {\n\t\tthrow new Error('useMotionGPU must be used inside <FragCanvas>');\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;;AAwEA,IAAa,wBAAwB,cAAuC,KAAK;;;;;;;AAQjF,SAAgB,eAAiC;CAChD,MAAM,UAAU,WAAW,sBAAsB;AACjD,KAAI,CAAC,QACJ,OAAM,IAAI,MAAM,gDAAgD;AAGjE,QAAO"}
@@ -47,3 +47,4 @@ export declare function useSetMotionGPUUserContext(): <UCT = unknown>(namespace:
47
47
  */
48
48
  export declare function setMotionGPUUserContext<UCT = unknown>(namespace: MotionGPUUserNamespace, value: UCT | (() => UCT), options?: SetMotionGPUUserContextOptions): UCT | undefined;
49
49
  export {};
50
+ //# sourceMappingURL=use-motiongpu-user-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-motiongpu-user-context.d.ts","sourceRoot":"","sources":["../../src/lib/react/use-motiongpu-user-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAGN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,gBAAgB,GAAG,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAOhE;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACxC;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CACpC;AA2DD;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,EAAE,SAAS,gBAAgB,GAAG,gBAAgB,KAC1C,eAAe,CAAC,EAAE,CAAC,CAAC;AAEzB;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,EAAE,SAAS,gBAAgB,GAAG,gBAAgB,EAC9C,CAAC,SAAS,MAAM,EAAE,GAAG,sBAAsB,GAAG,MAAM,EAAE,GAAG,sBAAsB,EAC9E,SAAS,EAAE,CAAC,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AA8CpD;;;;GAIG;AACH,wBAAgB,0BAA0B,KAGvC,GAAG,uBACQ,sBAAsB,SAC1B,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,YACd,8BAA8B,KACtC,GAAG,GAAG,SAAS,CAGnB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAG,OAAO,EACpD,SAAS,EAAE,sBAAsB,EACjC,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EACxB,OAAO,CAAC,EAAE,8BAA8B,GACtC,GAAG,GAAG,SAAS,CAEjB"}
@@ -1,94 +1,95 @@
1
- import { useCallback, useMemo } from 'react';
2
- import { useMotionGPU } from './motiongpu-context.js';
1
+ import { useMotionGPU } from "./motiongpu-context.js";
2
+ import { useCallback, useMemo } from "react";
3
+ //#region src/lib/react/use-motiongpu-user-context.ts
3
4
  /**
4
- * Checks whether a value is a non-array object suitable for shallow merge.
5
- */
5
+ * Checks whether a value is a non-array object suitable for shallow merge.
6
+ */
6
7
  function isObjectEntry(value) {
7
- return typeof value === 'object' && value !== null && !Array.isArray(value);
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
9
  }
9
10
  /**
10
- * Sets a namespaced user context value in the provided user store.
11
- *
12
- * Returns the effective value stored under the namespace.
13
- */
11
+ * Sets a namespaced user context value in the provided user store.
12
+ *
13
+ * Returns the effective value stored under the namespace.
14
+ */
14
15
  function setMotionGPUUserContextInStore(userStore, namespace, value, options) {
15
- const mode = options?.existing ?? 'skip';
16
- const functionValueMode = options?.functionValue ?? 'factory';
17
- let resolvedValue;
18
- userStore.update((context) => {
19
- const hasExisting = namespace in context;
20
- if (hasExisting && mode === 'skip') {
21
- resolvedValue = context[namespace];
22
- return context;
23
- }
24
- const nextValue = typeof value === 'function' && functionValueMode === 'factory'
25
- ? value()
26
- : value;
27
- if (hasExisting && mode === 'merge') {
28
- const currentValue = context[namespace];
29
- if (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {
30
- resolvedValue = {
31
- ...currentValue,
32
- ...nextValue
33
- };
34
- return {
35
- ...context,
36
- [namespace]: resolvedValue
37
- };
38
- }
39
- }
40
- resolvedValue = nextValue;
41
- return {
42
- ...context,
43
- [namespace]: nextValue
44
- };
45
- });
46
- return resolvedValue;
16
+ const mode = options?.existing ?? "skip";
17
+ const functionValueMode = options?.functionValue ?? "factory";
18
+ let resolvedValue;
19
+ userStore.update((context) => {
20
+ const hasExisting = namespace in context;
21
+ if (hasExisting && mode === "skip") {
22
+ resolvedValue = context[namespace];
23
+ return context;
24
+ }
25
+ const nextValue = typeof value === "function" && functionValueMode === "factory" ? value() : value;
26
+ if (hasExisting && mode === "merge") {
27
+ const currentValue = context[namespace];
28
+ if (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {
29
+ resolvedValue = {
30
+ ...currentValue,
31
+ ...nextValue
32
+ };
33
+ return {
34
+ ...context,
35
+ [namespace]: resolvedValue
36
+ };
37
+ }
38
+ }
39
+ resolvedValue = nextValue;
40
+ return {
41
+ ...context,
42
+ [namespace]: nextValue
43
+ };
44
+ });
45
+ return resolvedValue;
47
46
  }
48
47
  /**
49
- * Read-only user context hook:
50
- * - no args: returns full user context store
51
- * - namespace: returns namespaced store view
52
- *
53
- * @param namespace - Optional namespace key.
54
- */
55
- export function useMotionGPUUserContext(namespace) {
56
- const userStore = useMotionGPU().user;
57
- const allStore = useMemo(() => ({
58
- get current() {
59
- return userStore.current;
60
- },
61
- subscribe(run) {
62
- return userStore.subscribe((context) => run(context));
63
- }
64
- }), [userStore]);
65
- const scopedStore = useMemo(() => ({
66
- get current() {
67
- return userStore.current[namespace];
68
- },
69
- subscribe(run) {
70
- return userStore.subscribe((context) => run(context[namespace]));
71
- }
72
- }), [namespace, userStore]);
73
- if (namespace === undefined) {
74
- return allStore;
75
- }
76
- return scopedStore;
48
+ * Read-only user context hook:
49
+ * - no args: returns full user context store
50
+ * - namespace: returns namespaced store view
51
+ *
52
+ * @param namespace - Optional namespace key.
53
+ */
54
+ function useMotionGPUUserContext(namespace) {
55
+ const userStore = useMotionGPU().user;
56
+ const allStore = useMemo(() => ({
57
+ get current() {
58
+ return userStore.current;
59
+ },
60
+ subscribe(run) {
61
+ return userStore.subscribe((context) => run(context));
62
+ }
63
+ }), [userStore]);
64
+ const scopedStore = useMemo(() => ({
65
+ get current() {
66
+ return userStore.current[namespace];
67
+ },
68
+ subscribe(run) {
69
+ return userStore.subscribe((context) => run(context[namespace]));
70
+ }
71
+ }), [namespace, userStore]);
72
+ if (namespace === void 0) return allStore;
73
+ return scopedStore;
77
74
  }
78
75
  /**
79
- * Returns a stable setter bound to the active MotionGPU user context store.
80
- *
81
- * @returns Setter function that preserves namespace write semantics.
82
- */
83
- export function useSetMotionGPUUserContext() {
84
- const userStore = useMotionGPU().user;
85
- return useCallback((namespace, value, options) => setMotionGPUUserContextInStore(userStore, namespace, value, options), [userStore]);
76
+ * Returns a stable setter bound to the active MotionGPU user context store.
77
+ *
78
+ * @returns Setter function that preserves namespace write semantics.
79
+ */
80
+ function useSetMotionGPUUserContext() {
81
+ const userStore = useMotionGPU().user;
82
+ return useCallback((namespace, value, options) => setMotionGPUUserContextInStore(userStore, namespace, value, options), [userStore]);
86
83
  }
87
84
  /**
88
- * Sets a namespaced user context value with explicit write semantics.
89
- *
90
- * Returns the effective value stored under the namespace.
91
- */
92
- export function setMotionGPUUserContext(namespace, value, options) {
93
- return setMotionGPUUserContextInStore(useMotionGPU().user, namespace, value, options);
85
+ * Sets a namespaced user context value with explicit write semantics.
86
+ *
87
+ * Returns the effective value stored under the namespace.
88
+ */
89
+ function setMotionGPUUserContext(namespace, value, options) {
90
+ return setMotionGPUUserContextInStore(useMotionGPU().user, namespace, value, options);
94
91
  }
92
+ //#endregion
93
+ export { setMotionGPUUserContext, useMotionGPUUserContext, useSetMotionGPUUserContext };
94
+
95
+ //# sourceMappingURL=use-motiongpu-user-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-motiongpu-user-context.js","names":[],"sources":["../../src/lib/react/use-motiongpu-user-context.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type { CurrentReadable } from '../core/current-value.js';\nimport {\n\tuseMotionGPU,\n\ttype MotionGPUUserContext,\n\ttype MotionGPUUserNamespace\n} from './motiongpu-context.js';\n\n/**\n * Internal shape of the user context store.\n */\ntype UserContextStore = Record<MotionGPUUserNamespace, unknown>;\n\n/**\n * Object-like context payload used by merge semantics.\n */\ntype UserContextEntry = Record<string, unknown>;\n\n/**\n * Controls how a namespaced user context value behaves when already present.\n */\nexport interface SetMotionGPUUserContextOptions {\n\t/**\n\t * Conflict strategy when namespace already exists:\n\t * - `skip`: keep current value\n\t * - `replace`: replace current value\n\t * - `merge`: shallow merge object values, fallback to replace otherwise\n\t *\n\t * @default 'skip'\n\t */\n\texisting?: 'merge' | 'replace' | 'skip';\n\t/**\n\t * How function inputs should be interpreted:\n\t * - `factory`: call function and store its return value\n\t * - `value`: store function itself\n\t *\n\t * @default 'factory'\n\t */\n\tfunctionValue?: 'factory' | 'value';\n}\n\n/**\n * Checks whether a value is a non-array object suitable for shallow merge.\n */\nfunction isObjectEntry(value: unknown): value is UserContextEntry {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Sets a namespaced user context value in the provided user store.\n *\n * Returns the effective value stored under the namespace.\n */\nfunction setMotionGPUUserContextInStore<UCT = unknown>(\n\tuserStore: MotionGPUUserContext,\n\tnamespace: MotionGPUUserNamespace,\n\tvalue: UCT | (() => UCT),\n\toptions?: SetMotionGPUUserContextOptions\n): UCT | undefined {\n\tconst mode = options?.existing ?? 'skip';\n\tconst functionValueMode = options?.functionValue ?? 'factory';\n\tlet resolvedValue: UCT | undefined;\n\n\tuserStore.update((context) => {\n\t\tconst hasExisting = namespace in context;\n\t\tif (hasExisting && mode === 'skip') {\n\t\t\tresolvedValue = context[namespace] as UCT | undefined;\n\t\t\treturn context;\n\t\t}\n\n\t\tconst nextValue =\n\t\t\ttypeof value === 'function' && functionValueMode === 'factory'\n\t\t\t\t? (value as () => UCT)()\n\t\t\t\t: (value as UCT);\n\t\tif (hasExisting && mode === 'merge') {\n\t\t\tconst currentValue = context[namespace];\n\t\t\tif (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {\n\t\t\t\tresolvedValue = {\n\t\t\t\t\t...currentValue,\n\t\t\t\t\t...nextValue\n\t\t\t\t} as UCT;\n\t\t\t\treturn {\n\t\t\t\t\t...context,\n\t\t\t\t\t[namespace]: resolvedValue\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tresolvedValue = nextValue;\n\t\treturn {\n\t\t\t...context,\n\t\t\t[namespace]: nextValue\n\t\t};\n\t});\n\n\treturn resolvedValue;\n}\n\n/**\n * Returns a read-only view of the entire motiongpu user context store.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore\n>(): CurrentReadable<UC>;\n\n/**\n * Reads a namespaced user context value as a reactive readable store.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore,\n\tK extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace\n>(namespace: K): CurrentReadable<UC[K] | undefined>;\n\n/**\n * Read-only user context hook:\n * - no args: returns full user context store\n * - namespace: returns namespaced store view\n *\n * @param namespace - Optional namespace key.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore,\n\tK extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace\n>(namespace?: K): CurrentReadable<UC> | CurrentReadable<UC[K] | undefined> {\n\tconst userStore = useMotionGPU().user;\n\tconst allStore = useMemo<CurrentReadable<UC>>(\n\t\t() => ({\n\t\t\tget current() {\n\t\t\t\treturn userStore.current as UC;\n\t\t\t},\n\t\t\tsubscribe(run) {\n\t\t\t\treturn userStore.subscribe((context) => run(context as UC));\n\t\t\t}\n\t\t}),\n\t\t[userStore]\n\t);\n\tconst scopedStore = useMemo<CurrentReadable<UC[K] | undefined>>(\n\t\t() => ({\n\t\t\tget current() {\n\t\t\t\treturn userStore.current[namespace as MotionGPUUserNamespace] as UC[K] | undefined;\n\t\t\t},\n\t\t\tsubscribe(run) {\n\t\t\t\treturn userStore.subscribe((context) =>\n\t\t\t\t\trun(context[namespace as MotionGPUUserNamespace] as UC[K] | undefined)\n\t\t\t\t);\n\t\t\t}\n\t\t}),\n\t\t[namespace, userStore]\n\t);\n\n\tif (namespace === undefined) {\n\t\treturn allStore;\n\t}\n\n\treturn scopedStore;\n}\n\n/**\n * Returns a stable setter bound to the active MotionGPU user context store.\n *\n * @returns Setter function that preserves namespace write semantics.\n */\nexport function useSetMotionGPUUserContext() {\n\tconst userStore = useMotionGPU().user;\n\treturn useCallback(\n\t\t<UCT = unknown>(\n\t\t\tnamespace: MotionGPUUserNamespace,\n\t\t\tvalue: UCT | (() => UCT),\n\t\t\toptions?: SetMotionGPUUserContextOptions\n\t\t): UCT | undefined => setMotionGPUUserContextInStore(userStore, namespace, value, options),\n\t\t[userStore]\n\t);\n}\n\n/**\n * Sets a namespaced user context value with explicit write semantics.\n *\n * Returns the effective value stored under the namespace.\n */\nexport function setMotionGPUUserContext<UCT = unknown>(\n\tnamespace: MotionGPUUserNamespace,\n\tvalue: UCT | (() => UCT),\n\toptions?: SetMotionGPUUserContextOptions\n): UCT | undefined {\n\treturn setMotionGPUUserContextInStore(useMotionGPU().user, namespace, value, options);\n}\n"],"mappings":";;;;;;AA4CA,SAAS,cAAc,OAA2C;AACjE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;AAQ5E,SAAS,+BACR,WACA,WACA,OACA,SACkB;CAClB,MAAM,OAAO,SAAS,YAAY;CAClC,MAAM,oBAAoB,SAAS,iBAAiB;CACpD,IAAI;AAEJ,WAAU,QAAQ,YAAY;EAC7B,MAAM,cAAc,aAAa;AACjC,MAAI,eAAe,SAAS,QAAQ;AACnC,mBAAgB,QAAQ;AACxB,UAAO;;EAGR,MAAM,YACL,OAAO,UAAU,cAAc,sBAAsB,YACjD,OAAqB,GACrB;AACL,MAAI,eAAe,SAAS,SAAS;GACpC,MAAM,eAAe,QAAQ;AAC7B,OAAI,cAAc,aAAa,IAAI,cAAc,UAAU,EAAE;AAC5D,oBAAgB;KACf,GAAG;KACH,GAAG;KACH;AACD,WAAO;KACN,GAAG;MACF,YAAY;KACb;;;AAIH,kBAAgB;AAChB,SAAO;GACN,GAAG;IACF,YAAY;GACb;GACA;AAEF,QAAO;;;;;;;;;AAyBR,SAAgB,wBAGd,WAAyE;CAC1E,MAAM,YAAY,cAAc,CAAC;CACjC,MAAM,WAAW,eACT;EACN,IAAI,UAAU;AACb,UAAO,UAAU;;EAElB,UAAU,KAAK;AACd,UAAO,UAAU,WAAW,YAAY,IAAI,QAAc,CAAC;;EAE5D,GACD,CAAC,UAAU,CACX;CACD,MAAM,cAAc,eACZ;EACN,IAAI,UAAU;AACb,UAAO,UAAU,QAAQ;;EAE1B,UAAU,KAAK;AACd,UAAO,UAAU,WAAW,YAC3B,IAAI,QAAQ,WAA0D,CACtE;;EAEF,GACD,CAAC,WAAW,UAAU,CACtB;AAED,KAAI,cAAc,OACjB,QAAO;AAGR,QAAO;;;;;;;AAQR,SAAgB,6BAA6B;CAC5C,MAAM,YAAY,cAAc,CAAC;AACjC,QAAO,aAEL,WACA,OACA,YACqB,+BAA+B,WAAW,WAAW,OAAO,QAAQ,EAC1F,CAAC,UAAU,CACX;;;;;;;AAQF,SAAgB,wBACf,WACA,OACA,SACkB;AAClB,QAAO,+BAA+B,cAAc,CAAC,MAAM,WAAW,OAAO,QAAQ"}
@@ -38,3 +38,4 @@ export type TextureUrlInput = string[] | (() => string[]);
38
38
  * @returns Reactive texture loading state with reload support.
39
39
  */
40
40
  export declare function useTexture(urlInput: TextureUrlInput, options?: TextureLoadOptions): UseTextureResult;
41
+ //# sourceMappingURL=use-texture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-texture.d.ts","sourceRoot":"","sources":["../../src/lib/react/use-texture.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,eAAe,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD;;OAEG;IACH,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACrC;;OAEG;IACH,WAAW,EAAE,eAAe,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IAC1D;;OAEG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC;AAkE1D;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,eAAe,EACzB,OAAO,GAAE,kBAAuB,GAC9B,gBAAgB,CAkHlB"}
@@ -1,162 +1,142 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { createCurrentWritable as currentWritable } from '../core/current-value.js';
3
- import { isAbortError, loadTexturesFromUrls } from '../core/texture-loader.js';
4
- import { toMotionGPUErrorReport } from '../core/error-report.js';
1
+ import { toMotionGPUErrorReport } from "../core/error-report.js";
2
+ import { createCurrentWritable } from "../core/current-value.js";
3
+ import { isAbortError, loadTexturesFromUrls } from "../core/texture-loader.js";
4
+ import { useCallback, useEffect, useRef } from "react";
5
+ //#region src/lib/react/use-texture.ts
5
6
  /**
6
- * Normalizes unknown thrown values to an `Error` instance.
7
- */
7
+ * Normalizes unknown thrown values to an `Error` instance.
8
+ */
8
9
  function toError(error) {
9
- if (error instanceof Error) {
10
- return error;
11
- }
12
- return new Error('Unknown texture loading error');
10
+ if (error instanceof Error) return error;
11
+ return /* @__PURE__ */ new Error("Unknown texture loading error");
13
12
  }
14
13
  /**
15
- * Releases GPU-side resources for a list of loaded textures.
16
- */
14
+ * Releases GPU-side resources for a list of loaded textures.
15
+ */
17
16
  function disposeTextures(list) {
18
- for (const texture of list ?? []) {
19
- texture.dispose();
20
- }
17
+ for (const texture of list ?? []) texture.dispose();
21
18
  }
22
19
  function mergeAbortSignals(primary, secondary) {
23
- if (!secondary) {
24
- return {
25
- signal: primary,
26
- dispose: () => { }
27
- };
28
- }
29
- if (typeof AbortSignal.any === 'function') {
30
- return {
31
- signal: AbortSignal.any([primary, secondary]),
32
- dispose: () => { }
33
- };
34
- }
35
- const fallback = new AbortController();
36
- let disposed = false;
37
- const cleanup = () => {
38
- if (disposed) {
39
- return;
40
- }
41
- disposed = true;
42
- primary.removeEventListener('abort', abort);
43
- secondary.removeEventListener('abort', abort);
44
- };
45
- const abort = () => fallback.abort();
46
- primary.addEventListener('abort', abort, { once: true });
47
- secondary.addEventListener('abort', abort, { once: true });
48
- return {
49
- signal: fallback.signal,
50
- dispose: cleanup
51
- };
20
+ if (!secondary) return {
21
+ signal: primary,
22
+ dispose: () => {}
23
+ };
24
+ if (typeof AbortSignal.any === "function") return {
25
+ signal: AbortSignal.any([primary, secondary]),
26
+ dispose: () => {}
27
+ };
28
+ const fallback = new AbortController();
29
+ let disposed = false;
30
+ const cleanup = () => {
31
+ if (disposed) return;
32
+ disposed = true;
33
+ primary.removeEventListener("abort", abort);
34
+ secondary.removeEventListener("abort", abort);
35
+ };
36
+ const abort = () => fallback.abort();
37
+ primary.addEventListener("abort", abort, { once: true });
38
+ secondary.addEventListener("abort", abort, { once: true });
39
+ return {
40
+ signal: fallback.signal,
41
+ dispose: cleanup
42
+ };
52
43
  }
53
44
  /**
54
- * Loads textures from URLs and exposes reactive loading/error state.
55
- *
56
- * @param urlInput - URLs array or lazy URL provider.
57
- * @param options - Loader options passed to URL fetch/decode pipeline.
58
- * @returns Reactive texture loading state with reload support.
59
- */
60
- export function useTexture(urlInput, options = {}) {
61
- const texturesRef = useRef(currentWritable(null));
62
- const loadingRef = useRef(currentWritable(true));
63
- const errorRef = useRef(currentWritable(null));
64
- const errorReportRef = useRef(currentWritable(null));
65
- const activeControllerRef = useRef(null);
66
- const runningLoadRef = useRef(null);
67
- const reloadQueuedRef = useRef(false);
68
- const requestVersionRef = useRef(0);
69
- const disposedRef = useRef(false);
70
- const optionsRef = useRef(options);
71
- const urlInputRef = useRef(urlInput);
72
- optionsRef.current = options;
73
- urlInputRef.current = urlInput;
74
- const getUrls = useCallback(() => {
75
- const currentInput = urlInputRef.current;
76
- return typeof currentInput === 'function' ? currentInput() : currentInput;
77
- }, []);
78
- const executeLoad = useCallback(async () => {
79
- if (disposedRef.current) {
80
- return;
81
- }
82
- const version = ++requestVersionRef.current;
83
- const controller = new AbortController();
84
- activeControllerRef.current = controller;
85
- loadingRef.current.set(true);
86
- errorRef.current.set(null);
87
- errorReportRef.current.set(null);
88
- const previous = texturesRef.current.current;
89
- const mergedSignal = mergeAbortSignals(controller.signal, optionsRef.current.signal);
90
- try {
91
- const loaded = await loadTexturesFromUrls(getUrls(), {
92
- ...optionsRef.current,
93
- signal: mergedSignal.signal
94
- });
95
- if (disposedRef.current || version !== requestVersionRef.current) {
96
- disposeTextures(loaded);
97
- return;
98
- }
99
- texturesRef.current.set(loaded);
100
- disposeTextures(previous);
101
- }
102
- catch (nextError) {
103
- if (disposedRef.current || version !== requestVersionRef.current) {
104
- return;
105
- }
106
- if (isAbortError(nextError)) {
107
- return;
108
- }
109
- disposeTextures(previous);
110
- texturesRef.current.set(null);
111
- const normalizedError = toError(nextError);
112
- errorRef.current.set(normalizedError);
113
- errorReportRef.current.set(toMotionGPUErrorReport(normalizedError, 'initialization'));
114
- }
115
- finally {
116
- if (!disposedRef.current && version === requestVersionRef.current) {
117
- loadingRef.current.set(false);
118
- }
119
- if (activeControllerRef.current === controller) {
120
- activeControllerRef.current = null;
121
- }
122
- mergedSignal.dispose();
123
- }
124
- }, [getUrls]);
125
- const runLoadLoop = useCallback(async () => {
126
- do {
127
- reloadQueuedRef.current = false;
128
- await executeLoad();
129
- } while (reloadQueuedRef.current && !disposedRef.current);
130
- }, [executeLoad]);
131
- const load = useCallback(() => {
132
- activeControllerRef.current?.abort();
133
- if (runningLoadRef.current) {
134
- reloadQueuedRef.current = true;
135
- return runningLoadRef.current;
136
- }
137
- const pending = runLoadLoop();
138
- const trackedPending = pending.finally(() => {
139
- if (runningLoadRef.current === trackedPending) {
140
- runningLoadRef.current = null;
141
- }
142
- });
143
- runningLoadRef.current = trackedPending;
144
- return trackedPending;
145
- }, [runLoadLoop]);
146
- useEffect(() => {
147
- void load();
148
- return () => {
149
- disposedRef.current = true;
150
- requestVersionRef.current += 1;
151
- activeControllerRef.current?.abort();
152
- disposeTextures(texturesRef.current.current);
153
- };
154
- }, [load]);
155
- return {
156
- textures: texturesRef.current,
157
- loading: loadingRef.current,
158
- error: errorRef.current,
159
- errorReport: errorReportRef.current,
160
- reload: load
161
- };
45
+ * Loads textures from URLs and exposes reactive loading/error state.
46
+ *
47
+ * @param urlInput - URLs array or lazy URL provider.
48
+ * @param options - Loader options passed to URL fetch/decode pipeline.
49
+ * @returns Reactive texture loading state with reload support.
50
+ */
51
+ function useTexture(urlInput, options = {}) {
52
+ const texturesRef = useRef(createCurrentWritable(null));
53
+ const loadingRef = useRef(createCurrentWritable(true));
54
+ const errorRef = useRef(createCurrentWritable(null));
55
+ const errorReportRef = useRef(createCurrentWritable(null));
56
+ const activeControllerRef = useRef(null);
57
+ const runningLoadRef = useRef(null);
58
+ const reloadQueuedRef = useRef(false);
59
+ const requestVersionRef = useRef(0);
60
+ const disposedRef = useRef(false);
61
+ const optionsRef = useRef(options);
62
+ const urlInputRef = useRef(urlInput);
63
+ optionsRef.current = options;
64
+ urlInputRef.current = urlInput;
65
+ const getUrls = useCallback(() => {
66
+ const currentInput = urlInputRef.current;
67
+ return typeof currentInput === "function" ? currentInput() : currentInput;
68
+ }, []);
69
+ const executeLoad = useCallback(async () => {
70
+ if (disposedRef.current) return;
71
+ const version = ++requestVersionRef.current;
72
+ const controller = new AbortController();
73
+ activeControllerRef.current = controller;
74
+ loadingRef.current.set(true);
75
+ errorRef.current.set(null);
76
+ errorReportRef.current.set(null);
77
+ const previous = texturesRef.current.current;
78
+ const mergedSignal = mergeAbortSignals(controller.signal, optionsRef.current.signal);
79
+ try {
80
+ const loaded = await loadTexturesFromUrls(getUrls(), {
81
+ ...optionsRef.current,
82
+ signal: mergedSignal.signal
83
+ });
84
+ if (disposedRef.current || version !== requestVersionRef.current) {
85
+ disposeTextures(loaded);
86
+ return;
87
+ }
88
+ texturesRef.current.set(loaded);
89
+ disposeTextures(previous);
90
+ } catch (nextError) {
91
+ if (disposedRef.current || version !== requestVersionRef.current) return;
92
+ if (isAbortError(nextError)) return;
93
+ disposeTextures(previous);
94
+ texturesRef.current.set(null);
95
+ const normalizedError = toError(nextError);
96
+ errorRef.current.set(normalizedError);
97
+ errorReportRef.current.set(toMotionGPUErrorReport(normalizedError, "initialization"));
98
+ } finally {
99
+ if (!disposedRef.current && version === requestVersionRef.current) loadingRef.current.set(false);
100
+ if (activeControllerRef.current === controller) activeControllerRef.current = null;
101
+ mergedSignal.dispose();
102
+ }
103
+ }, [getUrls]);
104
+ const runLoadLoop = useCallback(async () => {
105
+ do {
106
+ reloadQueuedRef.current = false;
107
+ await executeLoad();
108
+ } while (reloadQueuedRef.current && !disposedRef.current);
109
+ }, [executeLoad]);
110
+ const load = useCallback(() => {
111
+ activeControllerRef.current?.abort();
112
+ if (runningLoadRef.current) {
113
+ reloadQueuedRef.current = true;
114
+ return runningLoadRef.current;
115
+ }
116
+ const trackedPending = runLoadLoop().finally(() => {
117
+ if (runningLoadRef.current === trackedPending) runningLoadRef.current = null;
118
+ });
119
+ runningLoadRef.current = trackedPending;
120
+ return trackedPending;
121
+ }, [runLoadLoop]);
122
+ useEffect(() => {
123
+ load();
124
+ return () => {
125
+ disposedRef.current = true;
126
+ requestVersionRef.current += 1;
127
+ activeControllerRef.current?.abort();
128
+ disposeTextures(texturesRef.current.current);
129
+ };
130
+ }, [load]);
131
+ return {
132
+ textures: texturesRef.current,
133
+ loading: loadingRef.current,
134
+ error: errorRef.current,
135
+ errorReport: errorReportRef.current,
136
+ reload: load
137
+ };
162
138
  }
139
+ //#endregion
140
+ export { useTexture };
141
+
142
+ //# sourceMappingURL=use-texture.js.map