@holoscript/core 1.0.0-alpha.2 → 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 (74) hide show
  1. package/package.json +2 -2
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +17 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
@@ -0,0 +1,357 @@
1
+ /**
2
+ * Graphics Services Tests
3
+ *
4
+ * Tests for HololandGraphicsPipelineService and PlatformPerformanceOptimizer
5
+ */
6
+ import { describe, it, expect } from 'vitest';
7
+ import { HololandGraphicsPipelineService } from '../services/HololandGraphicsPipelineService';
8
+ import { PlatformPerformanceOptimizer } from '../services/PlatformPerformanceOptimizer';
9
+ // ============================================================================
10
+ // Hololand Graphics Pipeline Service Tests
11
+ // ============================================================================
12
+ describe('HololandGraphicsPipelineService', () => {
13
+ describe('Initialization', () => {
14
+ it('should create instance with default settings', () => {
15
+ const service = new HololandGraphicsPipelineService('desktop');
16
+ expect(service).toBeDefined();
17
+ });
18
+ it('should initialize for mobile platform', () => {
19
+ const service = new HololandGraphicsPipelineService('mobile');
20
+ const estimate = service.getGPUMemoryEstimate();
21
+ expect(estimate.budget).toBe(256); // Mobile budget
22
+ });
23
+ it('should initialize for VR platform', () => {
24
+ const service = new HololandGraphicsPipelineService('vr');
25
+ const estimate = service.getGPUMemoryEstimate();
26
+ expect(estimate.budget).toBe(512); // VR budget
27
+ });
28
+ it('should initialize for desktop platform', () => {
29
+ const service = new HololandGraphicsPipelineService('desktop');
30
+ const estimate = service.getGPUMemoryEstimate();
31
+ expect(estimate.budget).toBe(2048); // Desktop budget
32
+ });
33
+ });
34
+ describe('GPU Memory Management', () => {
35
+ it('should estimate GPU memory correctly', () => {
36
+ const service = new HololandGraphicsPipelineService('desktop');
37
+ const estimate = service.getGPUMemoryEstimate();
38
+ expect(estimate.textureMemory).toBeGreaterThanOrEqual(0);
39
+ expect(estimate.geometryMemory).toBeGreaterThanOrEqual(0);
40
+ expect(estimate.estimatedTotal).toBeGreaterThanOrEqual(0);
41
+ expect(estimate.utilization).toBeGreaterThanOrEqual(0);
42
+ });
43
+ it('should track memory utilization', () => {
44
+ const service = new HololandGraphicsPipelineService('mobile');
45
+ const estimate = service.getGPUMemoryEstimate();
46
+ // Should not exceed budget
47
+ expect(estimate.utilization).toBeLessThanOrEqual(100);
48
+ });
49
+ it('should allow setting memory budget', () => {
50
+ const service = new HololandGraphicsPipelineService('desktop');
51
+ service.setMemoryBudget(1024);
52
+ const estimate = service.getGPUMemoryEstimate();
53
+ expect(estimate.budget).toBe(1024);
54
+ });
55
+ });
56
+ describe('Platform Optimization', () => {
57
+ it('should optimize for mobile', () => {
58
+ const service = new HololandGraphicsPipelineService('desktop');
59
+ service.optimizePlatform('mobile');
60
+ const estimate = service.getGPUMemoryEstimate();
61
+ expect(estimate.budget).toBe(256);
62
+ });
63
+ it('should optimize for VR', () => {
64
+ const service = new HololandGraphicsPipelineService('desktop');
65
+ service.optimizePlatform('vr');
66
+ const estimate = service.getGPUMemoryEstimate();
67
+ expect(estimate.budget).toBe(512);
68
+ });
69
+ it('should optimize for desktop', () => {
70
+ const service = new HololandGraphicsPipelineService('mobile');
71
+ service.optimizePlatform('desktop');
72
+ const estimate = service.getGPUMemoryEstimate();
73
+ expect(estimate.budget).toBe(2048);
74
+ });
75
+ });
76
+ describe('Performance Metrics', () => {
77
+ it('should return performance metrics', () => {
78
+ const service = new HololandGraphicsPipelineService('desktop');
79
+ const metrics = service.getPerformanceMetrics();
80
+ expect(metrics).toBeDefined();
81
+ expect(metrics.drawCalls).toBeGreaterThanOrEqual(0);
82
+ expect(metrics.fps).toBeGreaterThanOrEqual(0);
83
+ expect(metrics.gpuMemoryUsed).toBeGreaterThanOrEqual(0);
84
+ });
85
+ });
86
+ describe('Graphics Configuration', () => {
87
+ it('should initialize from graphics configuration', () => {
88
+ const service = new HololandGraphicsPipelineService('desktop');
89
+ const config = {
90
+ material: { type: 'pbr', pbr: { metallic: 0.5 } },
91
+ lighting: { preset: 'studio' },
92
+ rendering: { quality: 'high' },
93
+ };
94
+ service.initialize(config);
95
+ const estimate = service.getGPUMemoryEstimate();
96
+ expect(estimate.estimatedTotal).toBeGreaterThanOrEqual(0);
97
+ });
98
+ });
99
+ });
100
+ // ============================================================================
101
+ // Platform Performance Optimizer Tests
102
+ // ============================================================================
103
+ describe('PlatformPerformanceOptimizer', () => {
104
+ describe('Device Capabilities Detection', () => {
105
+ it('should detect mobile device capabilities', () => {
106
+ const device = {
107
+ platform: 'mobile',
108
+ gpuVendor: 'Qualcomm',
109
+ gpuModel: 'Adreno 640',
110
+ gpuMemory: 1024,
111
+ cpuCores: 4,
112
+ ramTotal: 4096,
113
+ screenResolution: { width: 1080, height: 2220 },
114
+ refreshRate: 90,
115
+ };
116
+ const optimizer = new PlatformPerformanceOptimizer(device);
117
+ const profile = optimizer.getProfile();
118
+ expect(profile.qualityLevel).toBe('low');
119
+ expect(profile.fpsTarget).toBe(30);
120
+ });
121
+ it('should detect VR device capabilities', () => {
122
+ const device = {
123
+ platform: 'vr',
124
+ gpuVendor: 'NVIDIA',
125
+ gpuModel: 'RTX 2070',
126
+ gpuMemory: 8192,
127
+ cpuCores: 8,
128
+ ramTotal: 16384,
129
+ screenResolution: { width: 1832, height: 1920 },
130
+ refreshRate: 90,
131
+ };
132
+ const optimizer = new PlatformPerformanceOptimizer(device);
133
+ const profile = optimizer.getProfile();
134
+ expect(profile.fpsTarget).toBe(90);
135
+ expect(profile.qualityLevel).toBe('high');
136
+ });
137
+ it('should detect desktop device capabilities', () => {
138
+ const device = {
139
+ platform: 'desktop',
140
+ gpuVendor: 'NVIDIA',
141
+ gpuModel: 'RTX 3090',
142
+ gpuMemory: 24576,
143
+ cpuCores: 16,
144
+ ramTotal: 32768,
145
+ screenResolution: { width: 3440, height: 1440 },
146
+ refreshRate: 165,
147
+ };
148
+ const optimizer = new PlatformPerformanceOptimizer(device);
149
+ const profile = optimizer.getProfile();
150
+ expect(profile.qualityLevel).toBe('ultra');
151
+ expect(profile.fpsTarget).toBe(165);
152
+ });
153
+ });
154
+ describe('Device Optimization', () => {
155
+ it('should generate mobile optimization settings', () => {
156
+ const device = {
157
+ platform: 'mobile',
158
+ gpuVendor: 'Qualcomm',
159
+ gpuModel: 'Adreno 640',
160
+ gpuMemory: 1024,
161
+ cpuCores: 4,
162
+ ramTotal: 4096,
163
+ screenResolution: { width: 1080, height: 2220 },
164
+ refreshRate: 90,
165
+ };
166
+ const optimizer = new PlatformPerformanceOptimizer(device);
167
+ const settings = optimizer.optimizeForDevice();
168
+ expect(settings.platform).toBe('mobile');
169
+ expect(settings.quality).toBe('low');
170
+ expect(settings.textureResolution).toBeLessThanOrEqual(512);
171
+ });
172
+ it('should generate VR optimization settings', () => {
173
+ const device = {
174
+ platform: 'vr',
175
+ gpuVendor: 'NVIDIA',
176
+ gpuModel: 'RTX 2070',
177
+ gpuMemory: 8192,
178
+ cpuCores: 8,
179
+ ramTotal: 16384,
180
+ screenResolution: { width: 1832, height: 1920 },
181
+ refreshRate: 90,
182
+ };
183
+ const optimizer = new PlatformPerformanceOptimizer(device);
184
+ const settings = optimizer.optimizeForDevice();
185
+ expect(settings.platform).toBe('vr');
186
+ expect(settings.quality).toBe('high');
187
+ });
188
+ it('should generate desktop optimization settings', () => {
189
+ const device = {
190
+ platform: 'desktop',
191
+ gpuVendor: 'NVIDIA',
192
+ gpuModel: 'RTX 3090',
193
+ gpuMemory: 24576,
194
+ cpuCores: 16,
195
+ ramTotal: 32768,
196
+ screenResolution: { width: 3440, height: 1440 },
197
+ refreshRate: 165,
198
+ };
199
+ const optimizer = new PlatformPerformanceOptimizer(device);
200
+ const settings = optimizer.optimizeForDevice();
201
+ expect(settings.platform).toBe('desktop');
202
+ expect(settings.quality).toBe('ultra');
203
+ expect(settings.textureResolution).toBe(4096);
204
+ });
205
+ });
206
+ describe('Adaptive Quality', () => {
207
+ it('should track frame metrics', () => {
208
+ const device = {
209
+ platform: 'mobile',
210
+ gpuVendor: 'Qualcomm',
211
+ gpuModel: 'Adreno 640',
212
+ gpuMemory: 1024,
213
+ cpuCores: 4,
214
+ ramTotal: 4096,
215
+ screenResolution: { width: 1080, height: 2220 },
216
+ refreshRate: 90,
217
+ };
218
+ const optimizer = new PlatformPerformanceOptimizer(device);
219
+ // Simulate frame updates
220
+ optimizer.updateFrameMetrics(30, 500, 16.67);
221
+ optimizer.updateFrameMetrics(28, 520, 17.5);
222
+ optimizer.updateFrameMetrics(25, 550, 20);
223
+ // Should track without errors
224
+ expect(true).toBe(true);
225
+ });
226
+ it('should provide recommendations for low FPS', () => {
227
+ const device = {
228
+ platform: 'mobile',
229
+ gpuVendor: 'Qualcomm',
230
+ gpuModel: 'Adreno 640',
231
+ gpuMemory: 1024,
232
+ cpuCores: 4,
233
+ ramTotal: 4096,
234
+ screenResolution: { width: 1080, height: 2220 },
235
+ refreshRate: 90,
236
+ };
237
+ const optimizer = new PlatformPerformanceOptimizer(device);
238
+ // Simulate low FPS frames
239
+ for (let i = 0; i < 10; i++) {
240
+ optimizer.updateFrameMetrics(20, 600, 50);
241
+ }
242
+ const recommendations = optimizer.getRecommendations();
243
+ expect(recommendations.length).toBeGreaterThan(0);
244
+ });
245
+ it('should provide recommendations for low power mode', () => {
246
+ const device = {
247
+ platform: 'mobile',
248
+ gpuVendor: 'Qualcomm',
249
+ gpuModel: 'Adreno 640',
250
+ gpuMemory: 1024,
251
+ cpuCores: 4,
252
+ ramTotal: 4096,
253
+ screenResolution: { width: 1080, height: 2220 },
254
+ refreshRate: 90,
255
+ isLowPowerMode: true,
256
+ };
257
+ const optimizer = new PlatformPerformanceOptimizer(device);
258
+ const recommendations = optimizer.getRecommendations();
259
+ expect(recommendations.length).toBeGreaterThan(0);
260
+ expect(recommendations.some((r) => r.includes('low power'))).toBe(true);
261
+ });
262
+ });
263
+ describe('Performance Profiling', () => {
264
+ it('should create performance profile for device', () => {
265
+ const device = {
266
+ platform: 'desktop',
267
+ gpuVendor: 'NVIDIA',
268
+ gpuModel: 'RTX 3090',
269
+ gpuMemory: 24576,
270
+ cpuCores: 16,
271
+ ramTotal: 32768,
272
+ screenResolution: { width: 3440, height: 1440 },
273
+ refreshRate: 165,
274
+ };
275
+ const optimizer = new PlatformPerformanceOptimizer(device);
276
+ const profile = optimizer.getProfile();
277
+ expect(profile.device).toEqual(device);
278
+ expect(profile.capabilities).toBeDefined();
279
+ expect(profile.qualityLevel).toBe('ultra');
280
+ });
281
+ it('should have appropriate CPU budget for platform', () => {
282
+ const mobileDevice = {
283
+ platform: 'mobile',
284
+ gpuVendor: 'Qualcomm',
285
+ gpuModel: 'Adreno 640',
286
+ gpuMemory: 1024,
287
+ cpuCores: 4,
288
+ ramTotal: 4096,
289
+ screenResolution: { width: 1080, height: 2220 },
290
+ refreshRate: 90,
291
+ };
292
+ const vrDevice = {
293
+ platform: 'vr',
294
+ gpuVendor: 'NVIDIA',
295
+ gpuModel: 'RTX 2070',
296
+ gpuMemory: 8192,
297
+ cpuCores: 8,
298
+ ramTotal: 16384,
299
+ screenResolution: { width: 1832, height: 1920 },
300
+ refreshRate: 90,
301
+ };
302
+ const mobileOptimizer = new PlatformPerformanceOptimizer(mobileDevice);
303
+ const vrOptimizer = new PlatformPerformanceOptimizer(vrDevice);
304
+ const mobileProfile = mobileOptimizer.getProfile();
305
+ const vrProfile = vrOptimizer.getProfile();
306
+ // VR should have tighter budget (90 FPS)
307
+ expect(vrProfile.cpuBudget).toBeLessThan(mobileProfile.cpuBudget);
308
+ });
309
+ });
310
+ describe('Compression Selection', () => {
311
+ it('should select ASTC for mobile', () => {
312
+ const device = {
313
+ platform: 'mobile',
314
+ gpuVendor: 'Qualcomm',
315
+ gpuModel: 'Adreno 640',
316
+ gpuMemory: 1024,
317
+ cpuCores: 4,
318
+ ramTotal: 4096,
319
+ screenResolution: { width: 1080, height: 2220 },
320
+ refreshRate: 90,
321
+ };
322
+ const optimizer = new PlatformPerformanceOptimizer(device);
323
+ const settings = optimizer.optimizeForDevice();
324
+ expect(settings.compression).toMatch(/astc|pvrtc/);
325
+ });
326
+ it('should select Basis for VR', () => {
327
+ const device = {
328
+ platform: 'vr',
329
+ gpuVendor: 'NVIDIA',
330
+ gpuModel: 'RTX 2070',
331
+ gpuMemory: 8192,
332
+ cpuCores: 8,
333
+ ramTotal: 16384,
334
+ screenResolution: { width: 1832, height: 1920 },
335
+ refreshRate: 90,
336
+ };
337
+ const optimizer = new PlatformPerformanceOptimizer(device);
338
+ const settings = optimizer.optimizeForDevice();
339
+ expect(settings.compression).toBe('basis');
340
+ });
341
+ it('should select no compression for desktop', () => {
342
+ const device = {
343
+ platform: 'desktop',
344
+ gpuVendor: 'NVIDIA',
345
+ gpuModel: 'RTX 3090',
346
+ gpuMemory: 24576,
347
+ cpuCores: 16,
348
+ ramTotal: 32768,
349
+ screenResolution: { width: 3440, height: 1440 },
350
+ refreshRate: 165,
351
+ };
352
+ const optimizer = new PlatformPerformanceOptimizer(device);
353
+ const settings = optimizer.optimizeForDevice();
354
+ expect(settings.compression).toBe('none');
355
+ });
356
+ });
357
+ });