@vib3code/sdk 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
  3. package/DOCS/CI_TESTING.md +38 -0
  4. package/DOCS/CLI_ONBOARDING.md +75 -0
  5. package/DOCS/CONTROL_REFERENCE.md +64 -0
  6. package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
  7. package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
  8. package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
  9. package/DOCS/ENV_SETUP.md +189 -0
  10. package/DOCS/EXPORT_FORMATS.md +417 -0
  11. package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
  12. package/DOCS/LICENSING_TIERS.md +275 -0
  13. package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
  14. package/DOCS/OBS_SETUP_GUIDE.md +98 -0
  15. package/DOCS/PROJECT_SETUP.md +66 -0
  16. package/DOCS/RENDERER_LIFECYCLE.md +40 -0
  17. package/DOCS/REPO_MANIFEST.md +121 -0
  18. package/DOCS/SESSION_014_PLAN.md +195 -0
  19. package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
  20. package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
  21. package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
  22. package/DOCS/SYSTEM_INVENTORY.md +520 -0
  23. package/DOCS/TELEMETRY_EXPORTS.md +34 -0
  24. package/DOCS/WEBGPU_STATUS.md +38 -0
  25. package/DOCS/XR_BENCHMARKS.md +608 -0
  26. package/LICENSE +21 -0
  27. package/README.md +426 -0
  28. package/docs/.nojekyll +0 -0
  29. package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
  30. package/docs/02-hyperspatial_ego_death.html +346 -0
  31. package/docs/03-post_cartesian_sublime.html +346 -0
  32. package/docs/04-crystalline_void_meditation.html +346 -0
  33. package/docs/05-quantum_decoherence_ballet.html +346 -0
  34. package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
  35. package/docs/07-hyperspatial_ego_death.html +346 -0
  36. package/docs/08-post_cartesian_sublime.html +346 -0
  37. package/docs/09-crystalline_void_meditation.html +346 -0
  38. package/docs/10-quantum_decoherence_ballet.html +346 -0
  39. package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
  40. package/docs/12-hyperspatial_ego_death.html +346 -0
  41. package/docs/13-post_cartesian_sublime.html +346 -0
  42. package/docs/index.html +794 -0
  43. package/docs/test-hub.html +441 -0
  44. package/docs/url-state.js +102 -0
  45. package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
  46. package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
  47. package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
  48. package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
  49. package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
  50. package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
  51. package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
  52. package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
  53. package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
  54. package/docs/vib3-exports/index.html +238 -0
  55. package/docs/webgpu-live.html +702 -0
  56. package/package.json +367 -0
  57. package/src/advanced/AIPresetGenerator.js +777 -0
  58. package/src/advanced/MIDIController.js +703 -0
  59. package/src/advanced/OffscreenWorker.js +1051 -0
  60. package/src/advanced/WebGPUCompute.js +1051 -0
  61. package/src/advanced/WebXRRenderer.js +680 -0
  62. package/src/agent/cli/AgentCLI.js +615 -0
  63. package/src/agent/cli/index.js +14 -0
  64. package/src/agent/index.js +73 -0
  65. package/src/agent/mcp/MCPServer.js +950 -0
  66. package/src/agent/mcp/index.js +9 -0
  67. package/src/agent/mcp/tools.js +548 -0
  68. package/src/agent/telemetry/EventStream.js +669 -0
  69. package/src/agent/telemetry/Instrumentation.js +618 -0
  70. package/src/agent/telemetry/TelemetryExporters.js +427 -0
  71. package/src/agent/telemetry/TelemetryService.js +464 -0
  72. package/src/agent/telemetry/index.js +52 -0
  73. package/src/benchmarks/BenchmarkRunner.js +381 -0
  74. package/src/benchmarks/MetricsCollector.js +299 -0
  75. package/src/benchmarks/index.js +9 -0
  76. package/src/benchmarks/scenes.js +259 -0
  77. package/src/cli/index.js +675 -0
  78. package/src/config/ApiConfig.js +88 -0
  79. package/src/core/CanvasManager.js +217 -0
  80. package/src/core/ErrorReporter.js +117 -0
  81. package/src/core/ParameterMapper.js +333 -0
  82. package/src/core/Parameters.js +396 -0
  83. package/src/core/RendererContracts.js +200 -0
  84. package/src/core/UnifiedResourceManager.js +370 -0
  85. package/src/core/VIB3Engine.js +636 -0
  86. package/src/core/renderers/FacetedRendererAdapter.js +32 -0
  87. package/src/core/renderers/HolographicRendererAdapter.js +29 -0
  88. package/src/core/renderers/QuantumRendererAdapter.js +29 -0
  89. package/src/core/renderers/RendererLifecycleManager.js +63 -0
  90. package/src/creative/ColorPresetsSystem.js +980 -0
  91. package/src/creative/ParameterTimeline.js +1061 -0
  92. package/src/creative/PostProcessingPipeline.js +1113 -0
  93. package/src/creative/TransitionAnimator.js +683 -0
  94. package/src/export/CSSExporter.js +226 -0
  95. package/src/export/CardGeneratorBase.js +279 -0
  96. package/src/export/ExportManager.js +580 -0
  97. package/src/export/FacetedCardGenerator.js +279 -0
  98. package/src/export/HolographicCardGenerator.js +543 -0
  99. package/src/export/LottieExporter.js +552 -0
  100. package/src/export/QuantumCardGenerator.js +315 -0
  101. package/src/export/SVGExporter.js +519 -0
  102. package/src/export/ShaderExporter.js +903 -0
  103. package/src/export/TradingCardGenerator.js +3055 -0
  104. package/src/export/TradingCardManager.js +181 -0
  105. package/src/export/VIB3PackageExporter.js +559 -0
  106. package/src/export/index.js +14 -0
  107. package/src/export/systems/TradingCardSystemFaceted.js +494 -0
  108. package/src/export/systems/TradingCardSystemHolographic.js +452 -0
  109. package/src/export/systems/TradingCardSystemQuantum.js +411 -0
  110. package/src/faceted/FacetedSystem.js +963 -0
  111. package/src/features/CollectionManager.js +433 -0
  112. package/src/gallery/CollectionManager.js +240 -0
  113. package/src/gallery/GallerySystem.js +485 -0
  114. package/src/geometry/GeometryFactory.js +314 -0
  115. package/src/geometry/GeometryLibrary.js +72 -0
  116. package/src/geometry/buffers/BufferBuilder.js +338 -0
  117. package/src/geometry/buffers/index.js +18 -0
  118. package/src/geometry/generators/Crystal.js +420 -0
  119. package/src/geometry/generators/Fractal.js +298 -0
  120. package/src/geometry/generators/KleinBottle.js +197 -0
  121. package/src/geometry/generators/Sphere.js +192 -0
  122. package/src/geometry/generators/Tesseract.js +160 -0
  123. package/src/geometry/generators/Tetrahedron.js +225 -0
  124. package/src/geometry/generators/Torus.js +304 -0
  125. package/src/geometry/generators/Wave.js +341 -0
  126. package/src/geometry/index.js +142 -0
  127. package/src/geometry/warp/HypersphereCore.js +211 -0
  128. package/src/geometry/warp/HypertetraCore.js +386 -0
  129. package/src/geometry/warp/index.js +57 -0
  130. package/src/holograms/HolographicVisualizer.js +1073 -0
  131. package/src/holograms/RealHolographicSystem.js +966 -0
  132. package/src/holograms/variantRegistry.js +69 -0
  133. package/src/integrations/FigmaPlugin.js +854 -0
  134. package/src/integrations/OBSMode.js +754 -0
  135. package/src/integrations/ThreeJsPackage.js +660 -0
  136. package/src/integrations/TouchDesignerExport.js +552 -0
  137. package/src/integrations/frameworks/Vib3React.js +591 -0
  138. package/src/integrations/frameworks/Vib3Svelte.js +654 -0
  139. package/src/integrations/frameworks/Vib3Vue.js +628 -0
  140. package/src/llm/LLMParameterInterface.js +240 -0
  141. package/src/llm/LLMParameterUI.js +577 -0
  142. package/src/math/Mat4x4.js +708 -0
  143. package/src/math/Projection.js +341 -0
  144. package/src/math/Rotor4D.js +637 -0
  145. package/src/math/Vec4.js +476 -0
  146. package/src/math/constants.js +164 -0
  147. package/src/math/index.js +68 -0
  148. package/src/math/projections.js +54 -0
  149. package/src/math/rotations.js +196 -0
  150. package/src/quantum/QuantumEngine.js +906 -0
  151. package/src/quantum/QuantumVisualizer.js +1103 -0
  152. package/src/reactivity/ReactivityConfig.js +499 -0
  153. package/src/reactivity/ReactivityManager.js +586 -0
  154. package/src/reactivity/SpatialInputSystem.js +1783 -0
  155. package/src/reactivity/index.js +93 -0
  156. package/src/render/CommandBuffer.js +465 -0
  157. package/src/render/MultiCanvasBridge.js +340 -0
  158. package/src/render/RenderCommand.js +514 -0
  159. package/src/render/RenderResourceRegistry.js +523 -0
  160. package/src/render/RenderState.js +552 -0
  161. package/src/render/RenderTarget.js +512 -0
  162. package/src/render/ShaderLoader.js +253 -0
  163. package/src/render/ShaderProgram.js +599 -0
  164. package/src/render/UnifiedRenderBridge.js +496 -0
  165. package/src/render/backends/WebGLBackend.js +1108 -0
  166. package/src/render/backends/WebGPUBackend.js +1409 -0
  167. package/src/render/commands/CommandBufferExecutor.js +607 -0
  168. package/src/render/commands/RenderCommandBuffer.js +661 -0
  169. package/src/render/commands/index.js +17 -0
  170. package/src/render/index.js +367 -0
  171. package/src/scene/Disposable.js +498 -0
  172. package/src/scene/MemoryPool.js +618 -0
  173. package/src/scene/Node4D.js +697 -0
  174. package/src/scene/ResourceManager.js +599 -0
  175. package/src/scene/Scene4D.js +540 -0
  176. package/src/scene/index.js +98 -0
  177. package/src/schemas/error.schema.json +84 -0
  178. package/src/schemas/extension.schema.json +88 -0
  179. package/src/schemas/index.js +214 -0
  180. package/src/schemas/parameters.schema.json +142 -0
  181. package/src/schemas/tool-pack.schema.json +44 -0
  182. package/src/schemas/tool-response.schema.json +127 -0
  183. package/src/shaders/common/fullscreen.vert.glsl +5 -0
  184. package/src/shaders/common/fullscreen.vert.wgsl +17 -0
  185. package/src/shaders/common/geometry24.glsl +65 -0
  186. package/src/shaders/common/geometry24.wgsl +54 -0
  187. package/src/shaders/common/rotation4d.glsl +85 -0
  188. package/src/shaders/common/rotation4d.wgsl +86 -0
  189. package/src/shaders/common/uniforms.glsl +44 -0
  190. package/src/shaders/common/uniforms.wgsl +48 -0
  191. package/src/shaders/faceted/faceted.frag.glsl +129 -0
  192. package/src/shaders/faceted/faceted.frag.wgsl +164 -0
  193. package/src/shaders/holographic/holographic.frag.glsl +406 -0
  194. package/src/shaders/holographic/holographic.frag.wgsl +185 -0
  195. package/src/shaders/quantum/quantum.frag.glsl +513 -0
  196. package/src/shaders/quantum/quantum.frag.wgsl +361 -0
  197. package/src/testing/ParallelTestFramework.js +519 -0
  198. package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
  199. package/src/testing/exportFormats.test.js +8 -0
  200. package/src/testing/projections.test.js +14 -0
  201. package/src/testing/rotations.test.js +37 -0
  202. package/src/ui/InteractivityMenu.js +516 -0
  203. package/src/ui/StatusManager.js +96 -0
  204. package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
  205. package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
  206. package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
  207. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
  208. package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
  209. package/src/variations/VariationManager.js +431 -0
  210. package/src/viewer/AudioReactivity.js +505 -0
  211. package/src/viewer/CardBending.js +481 -0
  212. package/src/viewer/GalleryUI.js +832 -0
  213. package/src/viewer/ReactivityManager.js +590 -0
  214. package/src/viewer/TradingCardExporter.js +600 -0
  215. package/src/viewer/ViewerPortal.js +374 -0
  216. package/src/viewer/index.js +12 -0
  217. package/src/wasm/WasmLoader.js +296 -0
  218. package/src/wasm/index.js +132 -0
  219. package/tools/agentic/mcpTools.js +88 -0
  220. package/tools/cli/agent-cli.js +92 -0
  221. package/tools/export/formats.js +24 -0
  222. package/tools/math/rotation-baseline.mjs +64 -0
  223. package/tools/shader-sync-verify.js +937 -0
  224. package/tools/telemetry/manifestPipeline.js +141 -0
  225. package/tools/telemetry/telemetryEvents.js +35 -0
  226. package/types/adaptive-sdk.d.ts +185 -0
  227. package/types/advanced/AIPresetGenerator.d.ts +81 -0
  228. package/types/advanced/MIDIController.d.ts +100 -0
  229. package/types/advanced/OffscreenWorker.d.ts +82 -0
  230. package/types/advanced/WebGPUCompute.d.ts +52 -0
  231. package/types/advanced/WebXRRenderer.d.ts +77 -0
  232. package/types/advanced/index.d.ts +46 -0
  233. package/types/core/ErrorReporter.d.ts +50 -0
  234. package/types/core/VIB3Engine.d.ts +204 -0
  235. package/types/creative/ColorPresetsSystem.d.ts +91 -0
  236. package/types/creative/ParameterTimeline.d.ts +74 -0
  237. package/types/creative/PostProcessingPipeline.d.ts +109 -0
  238. package/types/creative/TransitionAnimator.d.ts +71 -0
  239. package/types/creative/index.d.ts +35 -0
  240. package/types/integrations/FigmaPlugin.d.ts +46 -0
  241. package/types/integrations/OBSMode.d.ts +74 -0
  242. package/types/integrations/ThreeJsPackage.d.ts +62 -0
  243. package/types/integrations/TouchDesignerExport.d.ts +36 -0
  244. package/types/integrations/Vib3React.d.ts +74 -0
  245. package/types/integrations/Vib3Svelte.d.ts +63 -0
  246. package/types/integrations/Vib3Vue.d.ts +55 -0
  247. package/types/integrations/index.d.ts +52 -0
  248. package/types/reactivity/SpatialInputSystem.d.ts +173 -0
  249. package/types/reactivity/index.d.ts +394 -0
  250. package/types/render/CommandBuffer.d.ts +169 -0
  251. package/types/render/RenderCommand.d.ts +312 -0
  252. package/types/render/RenderState.d.ts +279 -0
  253. package/types/render/RenderTarget.d.ts +254 -0
  254. package/types/render/ShaderProgram.d.ts +277 -0
  255. package/types/render/UnifiedRenderBridge.d.ts +143 -0
  256. package/types/render/WebGLBackend.d.ts +168 -0
  257. package/types/render/WebGPUBackend.d.ts +186 -0
  258. package/types/render/index.d.ts +141 -0
@@ -0,0 +1,591 @@
1
+ /**
2
+ * VIB3+ React Component Wrapper
3
+ *
4
+ * Generates React-compatible component definitions and hooks for embedding
5
+ * VIB3+ 4D visualizations in React applications. This module produces
6
+ * source code strings and package structures suitable for NPM publishing.
7
+ *
8
+ * Usage (generated component):
9
+ * <Vib3Visualizer system="quantum" hue={200} saturation={0.8} />
10
+ *
11
+ * Usage (generated hook):
12
+ * const { engine, setParameter, switchSystem } = useVib3(containerRef);
13
+ *
14
+ * NOTE: This is a vanilla JS wrapper that generates React-compatible code.
15
+ * Users import this and use with React.createElement or JSX after building
16
+ * the generated package.
17
+ *
18
+ * @module Vib3ReactWrapper
19
+ * @version 1.0.0
20
+ * @license All Rights Reserved - Clear Seas Solutions LLC
21
+ */
22
+
23
+ /**
24
+ * Default VIB3+ parameter definitions with types and ranges.
25
+ * Used for prop type generation and validation.
26
+ * @constant {Object}
27
+ */
28
+ const VIB3_PARAM_DEFS = {
29
+ system: { type: 'string', default: 'quantum', options: ['quantum', 'faceted', 'holographic'] },
30
+ geometry: { type: 'number', min: 0, max: 23, default: 0 },
31
+ hue: { type: 'number', min: 0, max: 360, default: 200 },
32
+ saturation: { type: 'number', min: 0, max: 1, default: 0.8 },
33
+ intensity: { type: 'number', min: 0, max: 1, default: 0.5 },
34
+ speed: { type: 'number', min: 0.1, max: 3, default: 1.0 },
35
+ gridDensity: { type: 'number', min: 4, max: 100, default: 15 },
36
+ morphFactor: { type: 'number', min: 0, max: 2, default: 1.0 },
37
+ chaos: { type: 'number', min: 0, max: 1, default: 0.2 },
38
+ dimension: { type: 'number', min: 3.0, max: 4.5, default: 3.5 },
39
+ rot4dXY: { type: 'number', min: -6.28, max: 6.28, default: 0.0 },
40
+ rot4dXZ: { type: 'number', min: -6.28, max: 6.28, default: 0.0 },
41
+ rot4dYZ: { type: 'number', min: -6.28, max: 6.28, default: 0.0 },
42
+ rot4dXW: { type: 'number', min: -2, max: 2, default: 0.0 },
43
+ rot4dYW: { type: 'number', min: -2, max: 2, default: 0.0 },
44
+ rot4dZW: { type: 'number', min: -2, max: 2, default: 0.0 }
45
+ };
46
+
47
+ /**
48
+ * Numeric parameter keys (excludes 'system' which is a string).
49
+ * @constant {string[]}
50
+ */
51
+ const NUMERIC_PARAM_KEYS = Object.keys(VIB3_PARAM_DEFS).filter(k => VIB3_PARAM_DEFS[k].type === 'number');
52
+
53
+ /**
54
+ * React wrapper for VIB3+ visualization engine.
55
+ *
56
+ * Provides static methods that generate React component source code,
57
+ * hook definitions, and full NPM package structures for the @vib3/react package.
58
+ *
59
+ * @class
60
+ */
61
+ export class Vib3ReactWrapper {
62
+ /**
63
+ * Returns a React function component definition as a source code string.
64
+ *
65
+ * The generated component:
66
+ * - Creates a container div with a unique ID
67
+ * - Initializes VIB3Engine on mount via useEffect
68
+ * - Syncs all VIB3 parameter props to the engine on change
69
+ * - Handles system switching when the `system` prop changes
70
+ * - Properly destroys the engine on unmount
71
+ *
72
+ * @returns {string} Complete React function component source code (JSX)
73
+ * @example
74
+ * const componentCode = Vib3ReactWrapper.getComponent();
75
+ * // Write to src/Vib3Visualizer.jsx in your React project
76
+ */
77
+ static getComponent() {
78
+ return `import React, { useRef, useEffect, useId } from 'react';
79
+ import { VIB3Engine } from '@vib3/core';
80
+
81
+ /**
82
+ * VIB3+ Visualizer React Component
83
+ *
84
+ * Renders a VIB3+ 4D visualization inside a container div.
85
+ * Supports all VIB3 parameters as props and handles lifecycle automatically.
86
+ *
87
+ * @param {object} props
88
+ * @param {string} [props.system='quantum'] - Active system: 'quantum' | 'faceted' | 'holographic'
89
+ * @param {number} [props.geometry=0] - Geometry variant index (0-23)
90
+ * @param {number} [props.hue=200] - Color hue (0-360)
91
+ * @param {number} [props.saturation=0.8] - Color saturation (0-1)
92
+ * @param {number} [props.intensity=0.5] - Visual intensity (0-1)
93
+ * @param {number} [props.speed=1.0] - Animation speed (0.1-3)
94
+ * @param {number} [props.gridDensity=15] - Pattern density (4-100)
95
+ * @param {number} [props.morphFactor=1.0] - Shape interpolation (0-2)
96
+ * @param {number} [props.chaos=0.2] - Randomness level (0-1)
97
+ * @param {number} [props.dimension=3.5] - Projection distance (3.0-4.5)
98
+ * @param {number} [props.rot4dXY=0] - XY plane rotation (radians)
99
+ * @param {number} [props.rot4dXZ=0] - XZ plane rotation (radians)
100
+ * @param {number} [props.rot4dYZ=0] - YZ plane rotation (radians)
101
+ * @param {number} [props.rot4dXW=0] - XW hyperplane rotation (radians)
102
+ * @param {number} [props.rot4dYW=0] - YW hyperplane rotation (radians)
103
+ * @param {number} [props.rot4dZW=0] - ZW hyperplane rotation (radians)
104
+ * @param {string} [props.width='100%'] - Container width CSS value
105
+ * @param {string} [props.height='400px'] - Container height CSS value
106
+ * @param {string} [props.className] - Additional CSS class names
107
+ * @param {object} [props.style] - Additional inline styles
108
+ * @param {function} [props.onReady] - Callback fired when engine is initialized
109
+ * @param {function} [props.onError] - Callback fired on initialization error
110
+ * @param {React.Ref} [props.engineRef] - Ref to receive the VIB3Engine instance
111
+ * @returns {React.ReactElement}
112
+ */
113
+ export default function Vib3Visualizer({
114
+ system = 'quantum',
115
+ geometry = 0,
116
+ hue = 200,
117
+ saturation = 0.8,
118
+ intensity = 0.5,
119
+ speed = 1.0,
120
+ gridDensity = 15,
121
+ morphFactor = 1.0,
122
+ chaos = 0.2,
123
+ dimension = 3.5,
124
+ rot4dXY = 0,
125
+ rot4dXZ = 0,
126
+ rot4dYZ = 0,
127
+ rot4dXW = 0,
128
+ rot4dYW = 0,
129
+ rot4dZW = 0,
130
+ width = '100%',
131
+ height = '400px',
132
+ className = '',
133
+ style = {},
134
+ onReady,
135
+ onError,
136
+ engineRef
137
+ }) {
138
+ const containerRef = useRef(null);
139
+ const engineInstance = useRef(null);
140
+ const uniqueId = useId();
141
+ const containerId = \`vib3-container-\${uniqueId.replace(/:/g, '')}\`;
142
+
143
+ // Initialize engine on mount
144
+ useEffect(() => {
145
+ let mounted = true;
146
+
147
+ async function init() {
148
+ try {
149
+ const engine = new VIB3Engine();
150
+ const success = await engine.initialize(containerId);
151
+ if (!mounted) {
152
+ engine.destroy();
153
+ return;
154
+ }
155
+ if (!success) {
156
+ throw new Error('VIB3Engine initialization failed');
157
+ }
158
+ engineInstance.current = engine;
159
+ if (engineRef) {
160
+ if (typeof engineRef === 'function') engineRef(engine);
161
+ else engineRef.current = engine;
162
+ }
163
+ if (onReady) onReady(engine);
164
+ } catch (err) {
165
+ console.error('[Vib3Visualizer] Initialization error:', err);
166
+ if (onError) onError(err);
167
+ }
168
+ }
169
+
170
+ init();
171
+
172
+ return () => {
173
+ mounted = false;
174
+ if (engineInstance.current) {
175
+ engineInstance.current.destroy();
176
+ engineInstance.current = null;
177
+ }
178
+ };
179
+ }, [containerId]);
180
+
181
+ // Sync system prop
182
+ useEffect(() => {
183
+ const engine = engineInstance.current;
184
+ if (engine && engine.initialized) {
185
+ engine.switchSystem(system);
186
+ }
187
+ }, [system]);
188
+
189
+ // Sync numeric parameter props
190
+ useEffect(() => {
191
+ const engine = engineInstance.current;
192
+ if (engine && engine.initialized) {
193
+ engine.setParameters({
194
+ geometry, hue, saturation, intensity, speed,
195
+ gridDensity, morphFactor, chaos, dimension,
196
+ rot4dXY, rot4dXZ, rot4dYZ, rot4dXW, rot4dYW, rot4dZW
197
+ });
198
+ }
199
+ }, [geometry, hue, saturation, intensity, speed, gridDensity,
200
+ morphFactor, chaos, dimension, rot4dXY, rot4dXZ, rot4dYZ,
201
+ rot4dXW, rot4dYW, rot4dZW]);
202
+
203
+ const containerStyle = {
204
+ width,
205
+ height,
206
+ position: 'relative',
207
+ overflow: 'hidden',
208
+ background: '#000',
209
+ ...style
210
+ };
211
+
212
+ return React.createElement('div', {
213
+ id: containerId,
214
+ ref: containerRef,
215
+ className: \`vib3-visualizer \${className}\`.trim(),
216
+ style: containerStyle
217
+ });
218
+ }
219
+ `;
220
+ }
221
+
222
+ /**
223
+ * Returns the useVib3() custom hook definition as a source code string.
224
+ *
225
+ * The generated hook:
226
+ * - Accepts a container element ref
227
+ * - Manages VIB3Engine lifecycle (create, initialize, destroy)
228
+ * - Provides setParameter, setParameters, switchSystem, randomize, reset functions
229
+ * - Exposes current parameter state via a React state object
230
+ * - Returns an API object for imperative control
231
+ *
232
+ * @returns {string} Complete React hook source code
233
+ * @example
234
+ * const hookCode = Vib3ReactWrapper.getHookDefinition();
235
+ * // Write to src/useVib3.js in your React project
236
+ */
237
+ static getHookDefinition() {
238
+ return `import { useState, useEffect, useRef, useCallback } from 'react';
239
+ import { VIB3Engine } from '@vib3/core';
240
+
241
+ /**
242
+ * useVib3 - React hook for VIB3+ engine lifecycle management
243
+ *
244
+ * @param {string} containerId - DOM element ID to mount VIB3 into
245
+ * @param {object} [initialOptions={}] - Engine constructor options
246
+ * @param {boolean} [initialOptions.preferWebGPU=false] - Prefer WebGPU backend
247
+ * @param {boolean} [initialOptions.debug=false] - Enable debug logging
248
+ * @returns {{
249
+ * engine: VIB3Engine | null,
250
+ * initialized: boolean,
251
+ * system: string,
252
+ * parameters: object,
253
+ * setParameter: (name: string, value: number) => void,
254
+ * setParameters: (params: object) => void,
255
+ * switchSystem: (system: string) => Promise<boolean>,
256
+ * randomize: () => void,
257
+ * reset: () => void,
258
+ * exportState: () => object | null,
259
+ * importState: (state: object) => Promise<void>,
260
+ * startReactivity: () => void,
261
+ * stopReactivity: () => void,
262
+ * setAudioInput: (bass: number, mid: number, high: number) => void
263
+ * }}
264
+ */
265
+ export function useVib3(containerId, initialOptions = {}) {
266
+ const engineRef = useRef(null);
267
+ const [initialized, setInitialized] = useState(false);
268
+ const [system, setSystem] = useState(initialOptions.system || 'quantum');
269
+ const [parameters, setParameters] = useState({});
270
+
271
+ // Initialize engine
272
+ useEffect(() => {
273
+ let mounted = true;
274
+
275
+ async function init() {
276
+ const engine = new VIB3Engine({
277
+ preferWebGPU: initialOptions.preferWebGPU || false,
278
+ debug: initialOptions.debug || false
279
+ });
280
+
281
+ const success = await engine.initialize(containerId);
282
+ if (!mounted) {
283
+ engine.destroy();
284
+ return;
285
+ }
286
+
287
+ if (success) {
288
+ engineRef.current = engine;
289
+ setInitialized(true);
290
+ setParameters(engine.getAllParameters());
291
+ setSystem(engine.getCurrentSystem());
292
+ }
293
+ }
294
+
295
+ init();
296
+
297
+ return () => {
298
+ mounted = false;
299
+ if (engineRef.current) {
300
+ engineRef.current.destroy();
301
+ engineRef.current = null;
302
+ }
303
+ setInitialized(false);
304
+ };
305
+ }, [containerId]);
306
+
307
+ const setParam = useCallback((name, value) => {
308
+ if (engineRef.current && engineRef.current.initialized) {
309
+ engineRef.current.setParameter(name, value);
310
+ setParameters(prev => ({ ...prev, [name]: value }));
311
+ }
312
+ }, []);
313
+
314
+ const setParams = useCallback((params) => {
315
+ if (engineRef.current && engineRef.current.initialized) {
316
+ engineRef.current.setParameters(params);
317
+ setParameters(prev => ({ ...prev, ...params }));
318
+ }
319
+ }, []);
320
+
321
+ const doSwitchSystem = useCallback(async (newSystem) => {
322
+ if (engineRef.current && engineRef.current.initialized) {
323
+ const success = await engineRef.current.switchSystem(newSystem);
324
+ if (success) {
325
+ setSystem(newSystem);
326
+ setParameters(engineRef.current.getAllParameters());
327
+ }
328
+ return success;
329
+ }
330
+ return false;
331
+ }, []);
332
+
333
+ const randomize = useCallback(() => {
334
+ if (engineRef.current && engineRef.current.initialized) {
335
+ engineRef.current.randomizeAll();
336
+ setParameters(engineRef.current.getAllParameters());
337
+ }
338
+ }, []);
339
+
340
+ const reset = useCallback(() => {
341
+ if (engineRef.current && engineRef.current.initialized) {
342
+ engineRef.current.resetAll();
343
+ setParameters(engineRef.current.getAllParameters());
344
+ }
345
+ }, []);
346
+
347
+ const exportState = useCallback(() => {
348
+ if (engineRef.current && engineRef.current.initialized) {
349
+ return engineRef.current.exportState();
350
+ }
351
+ return null;
352
+ }, []);
353
+
354
+ const importState = useCallback(async (state) => {
355
+ if (engineRef.current && engineRef.current.initialized) {
356
+ await engineRef.current.importState(state);
357
+ setParameters(engineRef.current.getAllParameters());
358
+ setSystem(engineRef.current.getCurrentSystem());
359
+ }
360
+ }, []);
361
+
362
+ const startReactivity = useCallback(() => {
363
+ if (engineRef.current) engineRef.current.startReactivity();
364
+ }, []);
365
+
366
+ const stopReactivity = useCallback(() => {
367
+ if (engineRef.current) engineRef.current.stopReactivity();
368
+ }, []);
369
+
370
+ const setAudioInput = useCallback((bass, mid, high) => {
371
+ if (engineRef.current) engineRef.current.setAudioInput(bass, mid, high);
372
+ }, []);
373
+
374
+ return {
375
+ engine: engineRef.current,
376
+ initialized,
377
+ system,
378
+ parameters,
379
+ setParameter: setParam,
380
+ setParameters: setParams,
381
+ switchSystem: doSwitchSystem,
382
+ randomize,
383
+ reset,
384
+ exportState,
385
+ importState,
386
+ startReactivity,
387
+ stopReactivity,
388
+ setAudioInput
389
+ };
390
+ }
391
+ `;
392
+ }
393
+
394
+ /**
395
+ * Generates a complete NPM package structure for @vib3/react.
396
+ *
397
+ * The returned object maps file paths to their contents, suitable
398
+ * for writing to disk or bundling into a tarball.
399
+ *
400
+ * Package includes:
401
+ * - package.json with peer dependencies on react and @vib3/core
402
+ * - Main entry point re-exporting component and hook
403
+ * - Vib3Visualizer.jsx component file
404
+ * - useVib3.js hook file
405
+ * - README.md with usage documentation
406
+ *
407
+ * @returns {Object.<string, string|object>} Map of file path to file content
408
+ * @example
409
+ * const pkg = Vib3ReactWrapper.generatePackage();
410
+ * Object.entries(pkg).forEach(([path, content]) => {
411
+ * const data = typeof content === 'object' ? JSON.stringify(content, null, 2) : content;
412
+ * fs.writeFileSync(path, data);
413
+ * });
414
+ */
415
+ static generatePackage() {
416
+ return {
417
+ 'package.json': {
418
+ name: '@vib3/react',
419
+ version: '1.0.0',
420
+ description: 'React components for VIB3+ 4D Visualization Engine',
421
+ main: 'dist/index.js',
422
+ module: 'src/index.js',
423
+ types: 'dist/index.d.ts',
424
+ files: ['dist/', 'src/'],
425
+ scripts: {
426
+ build: 'rollup -c',
427
+ dev: 'rollup -c -w',
428
+ prepublishOnly: 'npm run build'
429
+ },
430
+ peerDependencies: {
431
+ react: '>=18.0.0',
432
+ 'react-dom': '>=18.0.0',
433
+ '@vib3/core': '>=1.0.0'
434
+ },
435
+ devDependencies: {
436
+ '@rollup/plugin-babel': '^6.0.0',
437
+ '@rollup/plugin-node-resolve': '^15.0.0',
438
+ rollup: '^4.0.0'
439
+ },
440
+ keywords: ['vib3', 'react', '4d', 'visualization', 'webgl', 'webgpu', 'shader'],
441
+ license: 'MIT',
442
+ repository: {
443
+ type: 'git',
444
+ url: 'https://github.com/clear-seas/vib3-react'
445
+ },
446
+ author: 'Clear Seas Solutions LLC'
447
+ },
448
+
449
+ 'src/index.js': `/**
450
+ * @vib3/react - React bindings for VIB3+ 4D Visualization Engine
451
+ * @module @vib3/react
452
+ */
453
+ export { default as Vib3Visualizer } from './Vib3Visualizer.jsx';
454
+ export { useVib3 } from './useVib3.js';
455
+ `,
456
+
457
+ 'src/Vib3Visualizer.jsx': Vib3ReactWrapper.getComponent(),
458
+
459
+ 'src/useVib3.js': Vib3ReactWrapper.getHookDefinition(),
460
+
461
+ 'README.md': `# @vib3/react
462
+
463
+ React components and hooks for the VIB3+ 4D Visualization Engine.
464
+
465
+ ## Installation
466
+
467
+ \`\`\`bash
468
+ npm install @vib3/react @vib3/core react react-dom
469
+ \`\`\`
470
+
471
+ ## Quick Start
472
+
473
+ ### Component Usage
474
+
475
+ \`\`\`jsx
476
+ import { Vib3Visualizer } from '@vib3/react';
477
+
478
+ function App() {
479
+ return (
480
+ <Vib3Visualizer
481
+ system="quantum"
482
+ hue={200}
483
+ saturation={0.8}
484
+ intensity={0.7}
485
+ geometry={5}
486
+ width="100%"
487
+ height="600px"
488
+ onReady={(engine) => console.log('VIB3 ready:', engine)}
489
+ />
490
+ );
491
+ }
492
+ \`\`\`
493
+
494
+ ### Hook Usage
495
+
496
+ \`\`\`jsx
497
+ import { useVib3 } from '@vib3/react';
498
+
499
+ function VisualizerController() {
500
+ const {
501
+ initialized,
502
+ system,
503
+ parameters,
504
+ setParameter,
505
+ switchSystem,
506
+ randomize,
507
+ reset
508
+ } = useVib3('vib3-container');
509
+
510
+ return (
511
+ <div>
512
+ <div id="vib3-container" style={{ width: '100%', height: '400px' }} />
513
+ {initialized && (
514
+ <div>
515
+ <button onClick={() => switchSystem('quantum')}>Quantum</button>
516
+ <button onClick={() => switchSystem('faceted')}>Faceted</button>
517
+ <button onClick={() => switchSystem('holographic')}>Holographic</button>
518
+ <button onClick={randomize}>Randomize</button>
519
+ <button onClick={reset}>Reset</button>
520
+ <input
521
+ type="range"
522
+ min="0"
523
+ max="360"
524
+ value={parameters.hue || 200}
525
+ onChange={(e) => setParameter('hue', Number(e.target.value))}
526
+ />
527
+ </div>
528
+ )}
529
+ </div>
530
+ );
531
+ }
532
+ \`\`\`
533
+
534
+ ## Props (Vib3Visualizer)
535
+
536
+ | Prop | Type | Default | Description |
537
+ |------|------|---------|-------------|
538
+ | system | string | 'quantum' | Active system: quantum, faceted, holographic |
539
+ | geometry | number | 0 | Geometry variant (0-23) |
540
+ | hue | number | 200 | Color hue (0-360) |
541
+ | saturation | number | 0.8 | Color saturation (0-1) |
542
+ | intensity | number | 0.5 | Visual intensity (0-1) |
543
+ | speed | number | 1.0 | Animation speed (0.1-3) |
544
+ | gridDensity | number | 15 | Pattern density (4-100) |
545
+ | morphFactor | number | 1.0 | Shape interpolation (0-2) |
546
+ | chaos | number | 0.2 | Randomness (0-1) |
547
+ | dimension | number | 3.5 | 4D projection distance (3.0-4.5) |
548
+ | rot4dXY-ZW | number | 0 | 6D rotation angles (radians) |
549
+ | width | string | '100%' | Container CSS width |
550
+ | height | string | '400px' | Container CSS height |
551
+ | onReady | function | - | Callback when engine initializes |
552
+ | onError | function | - | Callback on initialization error |
553
+ | engineRef | ref | - | Ref to receive VIB3Engine instance |
554
+
555
+ ## Systems
556
+
557
+ - **Quantum** - Complex lattice visualizations with quantum-inspired patterns
558
+ - **Faceted** - Clean 2D geometric patterns with 4D rotation projection
559
+ - **Holographic** - 5-layer glassmorphic audio-reactive effects
560
+
561
+ ## 24 Geometry Variants
562
+
563
+ 8 base geometries x 3 core types = 24 variants
564
+
565
+ **Base (0-7):** Tetrahedron, Hypercube, Sphere, Torus, Klein Bottle, Fractal, Wave, Crystal
566
+ **Hypersphere Core (8-15):** Base geometries warped through S3 projection
567
+ **Hypertetrahedron Core (16-23):** Base geometries warped through pentatope mapping
568
+
569
+ ## License
570
+
571
+ MIT - Clear Seas Solutions LLC
572
+ `
573
+ };
574
+ }
575
+
576
+ /**
577
+ * Returns the parameter definitions used for prop types and validation.
578
+ * @returns {Object} Parameter definition map
579
+ */
580
+ static getParameterDefs() {
581
+ return { ...VIB3_PARAM_DEFS };
582
+ }
583
+
584
+ /**
585
+ * Returns a list of all numeric parameter keys.
586
+ * @returns {string[]} Array of numeric parameter names
587
+ */
588
+ static getNumericParamKeys() {
589
+ return [...NUMERIC_PARAM_KEYS];
590
+ }
591
+ }