@buley/hexgrid-3d 1.0.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 (46) hide show
  1. package/.eslintrc.json +28 -0
  2. package/LICENSE +39 -0
  3. package/README.md +291 -0
  4. package/examples/basic-usage.tsx +52 -0
  5. package/package.json +65 -0
  6. package/public/hexgrid-worker.js +1763 -0
  7. package/rust/Cargo.toml +41 -0
  8. package/rust/src/lib.rs +740 -0
  9. package/rust/src/math.rs +574 -0
  10. package/rust/src/spatial.rs +245 -0
  11. package/rust/src/statistics.rs +496 -0
  12. package/src/HexGridEnhanced.ts +16 -0
  13. package/src/Snapshot.ts +1402 -0
  14. package/src/adapters.ts +65 -0
  15. package/src/algorithms/AdvancedStatistics.ts +328 -0
  16. package/src/algorithms/BayesianStatistics.ts +317 -0
  17. package/src/algorithms/FlowField.ts +126 -0
  18. package/src/algorithms/FluidSimulation.ts +99 -0
  19. package/src/algorithms/GraphAlgorithms.ts +184 -0
  20. package/src/algorithms/OutlierDetection.ts +391 -0
  21. package/src/algorithms/ParticleSystem.ts +85 -0
  22. package/src/algorithms/index.ts +13 -0
  23. package/src/compat.ts +96 -0
  24. package/src/components/HexGrid.tsx +31 -0
  25. package/src/components/NarrationOverlay.tsx +221 -0
  26. package/src/components/index.ts +2 -0
  27. package/src/features.ts +125 -0
  28. package/src/index.ts +30 -0
  29. package/src/math/HexCoordinates.ts +15 -0
  30. package/src/math/Matrix4.ts +35 -0
  31. package/src/math/Quaternion.ts +37 -0
  32. package/src/math/SpatialIndex.ts +114 -0
  33. package/src/math/Vector3.ts +69 -0
  34. package/src/math/index.ts +11 -0
  35. package/src/note-adapter.ts +124 -0
  36. package/src/ontology-adapter.ts +77 -0
  37. package/src/stores/index.ts +1 -0
  38. package/src/stores/uiStore.ts +85 -0
  39. package/src/types/index.ts +3 -0
  40. package/src/types.ts +152 -0
  41. package/src/utils/image-utils.ts +25 -0
  42. package/src/wasm/HexGridWasmWrapper.ts +753 -0
  43. package/src/wasm/index.ts +7 -0
  44. package/src/workers/hexgrid-math.ts +177 -0
  45. package/src/workers/hexgrid-worker.worker.ts +1807 -0
  46. package/tsconfig.json +18 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "ecmaVersion": 2020,
6
+ "sourceType": "module",
7
+ "ecmaFeatures": {
8
+ "jsx": true
9
+ }
10
+ },
11
+ "settings": {
12
+ "react": {
13
+ "version": "detect"
14
+ }
15
+ },
16
+ "extends": [
17
+ "eslint:recommended",
18
+ "plugin:@typescript-eslint/recommended",
19
+ "plugin:react/recommended",
20
+ "plugin:react-hooks/recommended"
21
+ ],
22
+ "rules": {
23
+ "@typescript-eslint/no-explicit-any": "warn",
24
+ "@typescript-eslint/explicit-module-boundary-types": "off",
25
+ "react/react-in-jsx-scope": "off",
26
+ "react/prop-types": "off"
27
+ }
28
+ }
package/LICENSE ADDED
@@ -0,0 +1,39 @@
1
+ Personal Use Only License
2
+
3
+ Copyright (c) 2026 buley
4
+
5
+ All rights reserved.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to use
9
+ the Software for personal, non-commercial purposes only, subject to the
10
+ following conditions:
11
+
12
+ 1. Personal Use Only: The Software may be used for personal, non-commercial
13
+ purposes only. Commercial use, including but not limited to use in
14
+ commercial products, services, or applications, is strictly prohibited.
15
+
16
+ 2. No Redistribution: You may not distribute, publish, or sublicense the
17
+ Software or any derivative works based on the Software.
18
+
19
+ 3. No Modification for Distribution: You may modify the Software for your
20
+ personal use, but you may not distribute, publish, or sublicense any
21
+ modified versions.
22
+
23
+ 4. Intellectual Property: All intellectual property rights in the Software
24
+ remain with the copyright holder. This license does not grant any rights
25
+ to patents, trademarks, or other intellectual property.
26
+
27
+ 5. Viewing and Learning: You may view, study, and learn from the Software's
28
+ source code for educational purposes, but you may not use it in any
29
+ commercial capacity.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ SOFTWARE.
38
+
39
+ For commercial licensing inquiries, please contact the copyright holder.
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # HexGrid 3D
2
+
3
+ A reusable 3D hexagonal grid visualization component for displaying content in an immersive spherical layout.
4
+
5
+ ## Features
6
+
7
+ - **3D Hexagonal Grid Layout** - Spherical projection with customizable curvature
8
+ - **Interactive Camera Controls** - Pan, zoom, inside/outside views with smooth transitions
9
+ - **Image Texture Mapping** - Automatic texture loading and caching
10
+ - **Real-time Statistics** - Live telemetry and performance metrics
11
+ - **Narration System** - Play-by-play commentary overlay
12
+ - **Web Worker Rendering** - High-performance offloaded calculations
13
+ - **Multi-Input Support** - Touch gestures, mouse, and keyboard controls
14
+ - **Responsive Design** - Adapts to mobile and desktop viewports
15
+ - **Dynamic Theming** - Accent color extraction from images
16
+ - **Autoplay Mode** - Queue-based content cycling
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @buley/hexgrid-3d
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Basic Example
27
+
28
+ ```tsx
29
+ import { HexGrid, Photo } from '@buley/hexgrid-3d'
30
+
31
+ function MyComponent() {
32
+ const photos: Photo[] = [
33
+ {
34
+ id: '1',
35
+ url: 'https://example.com/photo.jpg',
36
+ source: 'example',
37
+ createdAt: new Date().toISOString()
38
+ }
39
+ ]
40
+
41
+ return (
42
+ <HexGrid
43
+ photos={photos}
44
+ onHexClick={(photo) => console.log('Clicked:', photo)}
45
+ />
46
+ )
47
+ }
48
+ ```
49
+
50
+ ### Advanced Example with Controls
51
+
52
+ ```tsx
53
+ import { HexGrid, Photo, uiStore } from '@buley/hexgrid-3d'
54
+ import { useRef, useState } from 'react'
55
+
56
+ function AdvancedExample() {
57
+ const canvasRef = useRef<HTMLCanvasElement>(null)
58
+ const [modalOpen, setModalOpen] = useState(false)
59
+
60
+ return (
61
+ <div>
62
+ {/* Control buttons */}
63
+ <button onClick={() => uiStore.toggleDebug()}>
64
+ Toggle Debug
65
+ </button>
66
+ <button onClick={() => uiStore.toggleCamera()}>
67
+ Camera Controls
68
+ </button>
69
+
70
+ {/* Visualization */}
71
+ <HexGrid
72
+ photos={photos}
73
+ canvasRef={canvasRef}
74
+ spacing={1.2}
75
+ modalOpen={modalOpen}
76
+ onHexClick={(photo) => setModalOpen(true)}
77
+ autoplayQueueLimit={100}
78
+ />
79
+ </div>
80
+ )
81
+ }
82
+ ```
83
+
84
+ ## Components
85
+
86
+ ### HexGrid
87
+
88
+ Main visualization component that renders a 3D hexagonal grid on a spherical surface.
89
+
90
+ **Props:**
91
+
92
+ | Prop | Type | Default | Description |
93
+ |------|------|---------|-------------|
94
+ | `photos` | `Photo[]` | `[]` | Array of photos to display in the grid |
95
+ | `onHexClick` | `(photo: Photo) => void` | - | Callback when a hex tile is clicked |
96
+ | `spacing` | `number` | `1.0` | Grid spacing multiplier (affects tile density) |
97
+ | `canvasRef` | `React.RefObject<HTMLCanvasElement>` | - | Optional external canvas reference |
98
+ | `onLeaderboardUpdate` | `(leaderboard: any) => void` | - | Callback for leaderboard statistics updates |
99
+ | `autoplayQueueLimit` | `number` | - | Maximum items in autoplay queue |
100
+ | `onAutoplayQueueLimitChange` | `(limit: number) => void` | - | Callback when autoplay limit changes |
101
+ | `modalOpen` | `boolean` | `false` | Whether a modal is currently open |
102
+ | `userId` | `string` | - | Current user ID for personalization |
103
+ | `username` | `string` | - | Current username for display |
104
+
105
+ ### NarrationOverlay
106
+
107
+ Displays narration messages and real-time statistics in a dashboard-style overlay.
108
+
109
+ **Props:**
110
+
111
+ | Prop | Type | Description |
112
+ |------|------|-------------|
113
+ | `messages` | `NarrationMessage[]` | Array of narration messages to display |
114
+ | `statsTracker` | `StatsTracker` | Statistics tracker instance |
115
+ | `isVisible` | `boolean` | Whether overlay is visible |
116
+ | `onClose` | `() => void` | Callback when overlay is closed |
117
+
118
+ ## Types
119
+
120
+ ### Photo
121
+
122
+ ```typescript
123
+ interface Photo {
124
+ id: string
125
+ url: string
126
+ thumbnailUrl?: string
127
+ title?: string
128
+ description?: string
129
+ source: string
130
+ createdAt: string
131
+ userId?: string
132
+ username?: string
133
+ videoUrl?: string
134
+ platform?: string
135
+ author?: string
136
+ authorUrl?: string
137
+ likes?: number
138
+ views?: number
139
+ comments?: number
140
+ dominantColor?: string
141
+ }
142
+ ```
143
+
144
+ ## Stores
145
+
146
+ ### uiStore
147
+
148
+ Global UI state management for visualization components.
149
+
150
+ **Methods:**
151
+
152
+ - `uiStore.toggleDebug()` - Toggle debug panel
153
+ - `uiStore.toggleStats()` - Toggle statistics overlay
154
+ - `uiStore.toggleCamera()` - Toggle camera controls
155
+ - `uiStore.toggleNarration()` - Toggle narration overlay
156
+ - `uiStore.set(state)` - Update multiple state values
157
+ - `uiStore.subscribe(callback)` - Subscribe to state changes
158
+
159
+ **State:**
160
+
161
+ ```typescript
162
+ interface UIState {
163
+ debugOpen: boolean
164
+ showStats: boolean
165
+ cameraOpen: boolean
166
+ showNarration: boolean
167
+ }
168
+ ```
169
+
170
+ ## Camera Controls
171
+
172
+ ### Mouse/Trackpad
173
+ - **Left Click + Drag** - Rotate camera (yaw and pitch)
174
+ - **Scroll** - Zoom in/out
175
+ - **Click on Hex** - Select photo
176
+
177
+ ### Touch
178
+ - **Single Touch Drag** - Rotate camera
179
+ - **Pinch** - Zoom in/out
180
+ - **Tap on Hex** - Select photo
181
+
182
+ ### Keyboard
183
+ - **D** - Toggle debug panel
184
+ - **Escape** - Close debug panel
185
+
186
+ ## Performance
187
+
188
+ The component uses a Web Worker for heavy calculations to maintain 60fps rendering:
189
+
190
+ - **Streaming Rendering** - Progressively renders tiles
191
+ - **Texture Caching** - Reuses loaded images
192
+ - **Adaptive Quality** - Adjusts detail based on performance
193
+ - **Low-Res Mode** - Optional reduced quality for slower devices
194
+
195
+ ## Theming
196
+
197
+ The component integrates with your app's theme system and can extract accent colors from images:
198
+
199
+ ```tsx
200
+ import { getAccentRgba, setCustomAccentColor } from '@/lib/theme-colors'
201
+
202
+ // Custom accent color from image
203
+ setCustomAccentColor('#ff00ff')
204
+ ```
205
+
206
+ ## Dependencies
207
+
208
+ ### Peer Dependencies
209
+ - `react` ^18.0.0
210
+ - `react-dom` ^18.0.0
211
+ - `next` ^14.0.0
212
+ - `three` (Three.js for 3D calculations)
213
+
214
+ ### Internal Dependencies
215
+ - `@/lib/stats-tracker` - Statistics tracking
216
+ - `@/lib/narration` - Narration engine
217
+ - `@/lib/logger` - Logging utilities
218
+ - `@/lib/theme-colors` - Theme system integration
219
+ - `@/lib/html-utils` - HTML utilities
220
+
221
+ ## Development
222
+
223
+ ### Build
224
+
225
+ ```bash
226
+ npm run build
227
+ ```
228
+
229
+ ### Watch Mode
230
+
231
+ ```bash
232
+ npm run dev
233
+ ```
234
+
235
+ ## Architecture
236
+
237
+ ```
238
+ hexgrid-3d/
239
+ ├── src/
240
+ │ ├── components/ # React components
241
+ │ │ ├── HexGrid.tsx
242
+ │ │ └── NarrationOverlay.tsx
243
+ │ ├── stores/ # State management
244
+ │ │ └── uiStore.ts
245
+ │ ├── workers/ # Web Workers
246
+ │ │ └── hexgrid-worker.worker.ts
247
+ │ ├── types.ts # TypeScript definitions
248
+ │ └── index.ts # Main exports
249
+ ├── public/ # Static assets
250
+ │ └── hexgrid-worker.js
251
+ ├── examples/ # Usage examples
252
+ │ └── basic-usage.tsx
253
+ └── tests/ # Test suites
254
+ ├── unit/
255
+ ├── integration/
256
+ └── e2e/
257
+ ```
258
+
259
+ ## Testing
260
+
261
+ ### Run Tests
262
+
263
+ ```bash
264
+ npm test
265
+ ```
266
+
267
+ ### Run Tests in Watch Mode
268
+
269
+ ```bash
270
+ npm run test:watch
271
+ ```
272
+
273
+ ### Run Coverage
274
+
275
+ ```bash
276
+ npm run test:coverage
277
+ ```
278
+
279
+ ### Run E2E Tests
280
+
281
+ ```bash
282
+ npm run test:e2e
283
+ ```
284
+
285
+ ## License
286
+
287
+ Personal Use Only - See LICENSE file for full terms.
288
+
289
+ This software is provided for personal, non-commercial use only. Commercial use,
290
+ redistribution, and sublicensing are prohibited. All intellectual property
291
+ rights are reserved by the copyright holder.
@@ -0,0 +1,52 @@
1
+ import React, { useState } from 'react'
2
+ import { HexGrid, Photo } from '@buley/hexgrid-3d'
3
+
4
+ /**
5
+ * Example usage of the HexGrid visualization component
6
+ */
7
+ export default function HexGridExample() {
8
+ const [photos, setPhotos] = useState<Photo[]>([
9
+ {
10
+ id: '1',
11
+ url: 'https://example.com/photo1.jpg',
12
+ thumbnailUrl: 'https://example.com/photo1_thumb.jpg',
13
+ title: 'Example Photo 1',
14
+ description: 'First example photo',
15
+ source: 'example',
16
+ createdAt: new Date().toISOString(),
17
+ userId: 'user123'
18
+ },
19
+ {
20
+ id: '2',
21
+ url: 'https://example.com/photo2.jpg',
22
+ thumbnailUrl: 'https://example.com/photo2_thumb.jpg',
23
+ title: 'Example Photo 2',
24
+ description: 'Second example photo',
25
+ source: 'example',
26
+ createdAt: new Date().toISOString(),
27
+ userId: 'user123'
28
+ }
29
+ ])
30
+
31
+ const handleHexClick = (photo: Photo) => {
32
+ console.log('Clicked photo:', photo)
33
+ // Handle photo click - open modal, navigate, etc.
34
+ }
35
+
36
+ const handleLeaderboardUpdate = (leaderboard: any) => {
37
+ console.log('Leaderboard updated:', leaderboard)
38
+ }
39
+
40
+ return (
41
+ <div style={{ width: '100vw', height: '100vh' }}>
42
+ <HexGrid
43
+ photos={photos}
44
+ onHexClick={handleHexClick}
45
+ spacing={1.0}
46
+ onLeaderboardUpdate={handleLeaderboardUpdate}
47
+ autoplayQueueLimit={100}
48
+ modalOpen={false}
49
+ />
50
+ </div>
51
+ )
52
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@buley/hexgrid-3d",
3
+ "version": "1.0.0",
4
+ "description": "3D hexagonal grid visualization component for React",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+ssh://git@github.com/buley/hexgrid-3d.git"
10
+ },
11
+ "author": "buley",
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.ts",
18
+ "./components": "./src/components/index.ts",
19
+ "./stores": "./src/stores/index.ts"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "dev": "tsc --watch",
24
+ "test": "bun test",
25
+ "test:watch": "bun test --watch",
26
+ "test:coverage": "bun test --coverage",
27
+ "test:e2e": "playwright test",
28
+ "lint": "eslint src/**/*.{ts,tsx}",
29
+ "type-check": "tsc --noEmit"
30
+ },
31
+ "keywords": [
32
+ "3d",
33
+ "visualization",
34
+ "hexgrid",
35
+ "hexagonal",
36
+ "grid",
37
+ "sphere",
38
+ "react",
39
+ "canvas",
40
+ "webgl",
41
+ "three"
42
+ ],
43
+ "peerDependencies": {
44
+ "next": "^14.0.0",
45
+ "react": "^18.0.0",
46
+ "react-dom": "^18.0.0"
47
+ },
48
+ "devDependencies": {
49
+ "@happy-dom/global-registrator": "^20.3.3",
50
+ "@playwright/test": "^1.40.0",
51
+ "@testing-library/jest-dom": "^6.9.1",
52
+ "@testing-library/react": "^14.3.1",
53
+ "@testing-library/user-event": "^14.6.1",
54
+ "@types/jest": "^29.5.14",
55
+ "@types/react": "^18.3.27",
56
+ "@types/react-dom": "^18.3.7",
57
+ "happy-dom": "^20.3.3",
58
+ "jest": "^29.7.0",
59
+ "jest-environment-jsdom": "^29.7.0",
60
+ "react": "^19.2.3",
61
+ "react-dom": "^19.2.3",
62
+ "ts-jest": "^29.4.6",
63
+ "typescript": "^5.0.0"
64
+ }
65
+ }