@holoscript/core 1.0.0-alpha.1 → 2.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 (127) hide show
  1. package/package.json +10 -9
  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 +257 -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
  75. package/LICENSE +0 -21
  76. package/dist/chunk-3X2EGU7Z.cjs +0 -52
  77. package/dist/chunk-3X2EGU7Z.cjs.map +0 -1
  78. package/dist/chunk-723TPVHD.js +0 -1074
  79. package/dist/chunk-723TPVHD.js.map +0 -1
  80. package/dist/chunk-EOKNAVDO.cjs +0 -424
  81. package/dist/chunk-EOKNAVDO.cjs.map +0 -1
  82. package/dist/chunk-HQZ3HUMY.js +0 -1087
  83. package/dist/chunk-HQZ3HUMY.js.map +0 -1
  84. package/dist/chunk-KWYIVRIH.js +0 -344
  85. package/dist/chunk-KWYIVRIH.js.map +0 -1
  86. package/dist/chunk-LKH4ZAN6.js +0 -421
  87. package/dist/chunk-LKH4ZAN6.js.map +0 -1
  88. package/dist/chunk-SATNCODL.js +0 -45
  89. package/dist/chunk-SATNCODL.js.map +0 -1
  90. package/dist/chunk-VMZN4EVR.cjs +0 -347
  91. package/dist/chunk-VMZN4EVR.cjs.map +0 -1
  92. package/dist/chunk-VV3UUUYP.cjs +0 -1089
  93. package/dist/chunk-VV3UUUYP.cjs.map +0 -1
  94. package/dist/chunk-XRYTSQHZ.cjs +0 -1076
  95. package/dist/chunk-XRYTSQHZ.cjs.map +0 -1
  96. package/dist/debugger.cjs +0 -19
  97. package/dist/debugger.cjs.map +0 -1
  98. package/dist/debugger.d.cts +0 -171
  99. package/dist/debugger.d.ts +0 -171
  100. package/dist/debugger.js +0 -6
  101. package/dist/debugger.js.map +0 -1
  102. package/dist/index.cjs +0 -755
  103. package/dist/index.cjs.map +0 -1
  104. package/dist/index.d.cts +0 -169
  105. package/dist/index.d.ts +0 -169
  106. package/dist/index.js +0 -699
  107. package/dist/index.js.map +0 -1
  108. package/dist/parser.cjs +0 -13
  109. package/dist/parser.cjs.map +0 -1
  110. package/dist/parser.d.cts +0 -154
  111. package/dist/parser.d.ts +0 -154
  112. package/dist/parser.js +0 -4
  113. package/dist/parser.js.map +0 -1
  114. package/dist/runtime.cjs +0 -13
  115. package/dist/runtime.cjs.map +0 -1
  116. package/dist/runtime.d.cts +0 -147
  117. package/dist/runtime.d.ts +0 -147
  118. package/dist/runtime.js +0 -4
  119. package/dist/runtime.js.map +0 -1
  120. package/dist/type-checker.cjs +0 -16
  121. package/dist/type-checker.cjs.map +0 -1
  122. package/dist/type-checker.d.cts +0 -105
  123. package/dist/type-checker.d.ts +0 -105
  124. package/dist/type-checker.js +0 -3
  125. package/dist/type-checker.js.map +0 -1
  126. package/dist/types-WQSk1Qs2.d.cts +0 -238
  127. package/dist/types-WQSk1Qs2.d.ts +0 -238
@@ -0,0 +1,427 @@
1
+ /**
2
+ * Reactive State System for HoloScript+
3
+ *
4
+ * Provides reactive state management with:
5
+ * - Proxy-based reactivity
6
+ * - Computed properties
7
+ * - Effect system for side effects
8
+ * - Batched updates for performance
9
+ *
10
+ * @version 1.0.0
11
+ */
12
+ // interface WatchOptions<T> extends EffectOptions {
13
+ // handler: (newValue: T, oldValue: T) => void;
14
+ // }
15
+ // =============================================================================
16
+ // DEPENDENCY TRACKING
17
+ // =============================================================================
18
+ let activeEffect = null;
19
+ const targetMap = new WeakMap();
20
+ function track(target, key) {
21
+ if (!activeEffect)
22
+ return;
23
+ let depsMap = targetMap.get(target);
24
+ if (!depsMap) {
25
+ depsMap = new Map();
26
+ targetMap.set(target, depsMap);
27
+ }
28
+ let dep = depsMap.get(key);
29
+ if (!dep) {
30
+ dep = new Set();
31
+ depsMap.set(key, dep);
32
+ }
33
+ dep.add(activeEffect);
34
+ }
35
+ function trigger(target, key) {
36
+ const depsMap = targetMap.get(target);
37
+ if (!depsMap)
38
+ return;
39
+ const dep = depsMap.get(key);
40
+ if (!dep)
41
+ return;
42
+ // Create a copy to avoid infinite loops if effects modify dependencies
43
+ const effectsToRun = new Set(dep);
44
+ effectsToRun.forEach((effect) => {
45
+ // Avoid running effect if it's the active one
46
+ if (effect !== activeEffect) {
47
+ queueEffect(effect);
48
+ }
49
+ });
50
+ }
51
+ // =============================================================================
52
+ // EFFECT BATCHING
53
+ // =============================================================================
54
+ const pendingEffects = new Set();
55
+ let isFlushing = false;
56
+ function queueEffect(effect) {
57
+ pendingEffects.add(effect);
58
+ if (!isFlushing) {
59
+ isFlushing = true;
60
+ Promise.resolve().then(flushEffects);
61
+ }
62
+ }
63
+ function flushEffects() {
64
+ pendingEffects.forEach((effect) => {
65
+ try {
66
+ runEffect(effect);
67
+ }
68
+ catch (error) {
69
+ console.error('Error running effect:', error);
70
+ }
71
+ });
72
+ pendingEffects.clear();
73
+ isFlushing = false;
74
+ }
75
+ function runEffect(effect) {
76
+ const prevEffect = activeEffect;
77
+ activeEffect = effect;
78
+ try {
79
+ effect();
80
+ }
81
+ finally {
82
+ activeEffect = prevEffect;
83
+ }
84
+ }
85
+ // =============================================================================
86
+ // REACTIVE PROXY
87
+ // =============================================================================
88
+ function createReactiveProxy(target) {
89
+ return new Proxy(target, {
90
+ get(obj, key) {
91
+ track(obj, key);
92
+ const value = Reflect.get(obj, key);
93
+ // Deep reactivity for nested objects
94
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
95
+ return createReactiveProxy(value);
96
+ }
97
+ return value;
98
+ },
99
+ set(obj, key, value) {
100
+ const oldValue = Reflect.get(obj, key);
101
+ const result = Reflect.set(obj, key, value);
102
+ if (oldValue !== value) {
103
+ trigger(obj, key);
104
+ }
105
+ return result;
106
+ },
107
+ deleteProperty(obj, key) {
108
+ const hadKey = Reflect.has(obj, key);
109
+ const result = Reflect.deleteProperty(obj, key);
110
+ if (hadKey) {
111
+ trigger(obj, key);
112
+ }
113
+ return result;
114
+ },
115
+ });
116
+ }
117
+ // =============================================================================
118
+ // REACTIVE STATE CLASS
119
+ // =============================================================================
120
+ export class ReactiveState {
121
+ constructor(initialState) {
122
+ this.subscribers = new Set();
123
+ this.computedCache = new Map();
124
+ this.watchCleanups = new Map();
125
+ this.state = { ...initialState };
126
+ this.proxy = createReactiveProxy(this.state);
127
+ }
128
+ get(key) {
129
+ return this.proxy[key];
130
+ }
131
+ set(key, value) {
132
+ const oldValue = this.state[key];
133
+ this.proxy[key] = value;
134
+ if (oldValue !== value) {
135
+ this.notifySubscribers(key);
136
+ }
137
+ }
138
+ update(updates) {
139
+ const changedKeys = [];
140
+ for (const key in updates) {
141
+ if (Object.prototype.hasOwnProperty.call(updates, key)) {
142
+ const oldValue = this.state[key];
143
+ const newValue = updates[key];
144
+ if (oldValue !== newValue) {
145
+ this.proxy[key] = newValue;
146
+ changedKeys.push(key);
147
+ }
148
+ }
149
+ }
150
+ if (changedKeys.length > 0) {
151
+ // Batch notify for all changes
152
+ this.subscribers.forEach((callback) => {
153
+ callback(this.state);
154
+ });
155
+ }
156
+ }
157
+ subscribe(callback) {
158
+ this.subscribers.add(callback);
159
+ return () => {
160
+ this.subscribers.delete(callback);
161
+ };
162
+ }
163
+ notifySubscribers(changedKey) {
164
+ this.subscribers.forEach((callback) => {
165
+ callback(this.state, changedKey);
166
+ });
167
+ }
168
+ // ==========================================================================
169
+ // COMPUTED PROPERTIES
170
+ // ==========================================================================
171
+ computed(key, getter) {
172
+ const cached = this.computedCache.get(key);
173
+ if (cached && !cached.dirty) {
174
+ return cached.value;
175
+ }
176
+ // Track dependencies
177
+ const prevEffect = activeEffect;
178
+ activeEffect = () => {
179
+ // Mark cached value as dirty
180
+ const entry = this.computedCache.get(key);
181
+ if (entry) {
182
+ entry.dirty = true;
183
+ }
184
+ };
185
+ try {
186
+ const value = getter();
187
+ this.computedCache.set(key, { value, dirty: false });
188
+ return value;
189
+ }
190
+ finally {
191
+ activeEffect = prevEffect;
192
+ }
193
+ }
194
+ // ==========================================================================
195
+ // WATCHERS
196
+ // ==========================================================================
197
+ watch(key, handler, options = {}) {
198
+ let oldValue = this.state[key];
199
+ const effect = () => {
200
+ const newValue = this.proxy[key];
201
+ if (newValue !== oldValue) {
202
+ handler(newValue, oldValue);
203
+ oldValue = newValue;
204
+ }
205
+ };
206
+ // Run immediately if requested
207
+ if (options.immediate) {
208
+ handler(this.state[key], undefined);
209
+ }
210
+ // Subscribe to changes
211
+ return this.subscribe((_state, changedKey) => {
212
+ if (changedKey === key) {
213
+ effect();
214
+ }
215
+ });
216
+ }
217
+ watchEffect(effect, _options = {}) {
218
+ let cleanup;
219
+ const wrappedEffect = () => {
220
+ // Run cleanup from previous run
221
+ if (cleanup) {
222
+ cleanup();
223
+ }
224
+ cleanup = effect();
225
+ };
226
+ // Run immediately
227
+ runEffect(wrappedEffect);
228
+ return () => {
229
+ if (cleanup) {
230
+ cleanup();
231
+ }
232
+ // Note: Would need to remove from dependency tracking
233
+ };
234
+ }
235
+ // ==========================================================================
236
+ // SNAPSHOT / RESET
237
+ // ==========================================================================
238
+ getSnapshot() {
239
+ return { ...this.state };
240
+ }
241
+ reset(newState) {
242
+ const stateToSet = newState || {};
243
+ // Clear all keys
244
+ for (const key in this.state) {
245
+ if (Object.prototype.hasOwnProperty.call(this.state, key)) {
246
+ delete this.state[key];
247
+ }
248
+ }
249
+ // Set new state
250
+ for (const key in stateToSet) {
251
+ if (Object.prototype.hasOwnProperty.call(stateToSet, key)) {
252
+ this.state[key] = stateToSet[key];
253
+ }
254
+ }
255
+ // Notify all subscribers
256
+ this.subscribers.forEach((callback) => {
257
+ callback(this.state);
258
+ });
259
+ }
260
+ // ==========================================================================
261
+ // DESTROY
262
+ // ==========================================================================
263
+ destroy() {
264
+ this.subscribers.clear();
265
+ this.computedCache.clear();
266
+ this.watchCleanups.forEach((cleanup) => cleanup());
267
+ this.watchCleanups.clear();
268
+ }
269
+ }
270
+ // =============================================================================
271
+ // FACTORY FUNCTIONS
272
+ // =============================================================================
273
+ export function createState(initialState) {
274
+ return new ReactiveState(initialState);
275
+ }
276
+ export function ref(value) {
277
+ return createReactiveProxy({ value });
278
+ }
279
+ export function reactive(target) {
280
+ return createReactiveProxy(target);
281
+ }
282
+ export function effect(fn, _options) {
283
+ let cleanup;
284
+ const wrappedEffect = () => {
285
+ if (cleanup) {
286
+ cleanup();
287
+ }
288
+ cleanup = fn();
289
+ };
290
+ runEffect(wrappedEffect);
291
+ return () => {
292
+ if (cleanup) {
293
+ cleanup();
294
+ }
295
+ };
296
+ }
297
+ export function computed(getter) {
298
+ let value;
299
+ let dirty = true;
300
+ const runner = () => {
301
+ dirty = true;
302
+ };
303
+ return {
304
+ get value() {
305
+ if (dirty) {
306
+ const prevEffect = activeEffect;
307
+ activeEffect = runner;
308
+ try {
309
+ value = getter();
310
+ dirty = false;
311
+ }
312
+ finally {
313
+ activeEffect = prevEffect;
314
+ }
315
+ }
316
+ return value;
317
+ },
318
+ };
319
+ }
320
+ export function bind(state, key) {
321
+ return {
322
+ get: () => state.get(key),
323
+ set: (value) => state.set(key, value),
324
+ subscribe: (callback) => {
325
+ return state.subscribe((s, changedKey) => {
326
+ if (changedKey === key || changedKey === undefined) {
327
+ callback(s[key]);
328
+ }
329
+ });
330
+ },
331
+ };
332
+ }
333
+ // =============================================================================
334
+ // EXPRESSION EVALUATOR
335
+ // =============================================================================
336
+ export class ExpressionEvaluator {
337
+ constructor(context = {}, builtins = {}) {
338
+ this.context = context;
339
+ this.builtins = {
340
+ Math,
341
+ parseInt,
342
+ parseFloat,
343
+ String,
344
+ Number,
345
+ Boolean,
346
+ Array,
347
+ Object,
348
+ JSON,
349
+ Date,
350
+ ...builtins,
351
+ };
352
+ }
353
+ evaluate(expression) {
354
+ // Security: Create safe evaluation context
355
+ const contextKeys = Object.keys(this.context);
356
+ const contextValues = Object.values(this.context);
357
+ const builtinKeys = Object.keys(this.builtins);
358
+ const builtinValues = Object.values(this.builtins);
359
+ try {
360
+ // Create function with context variables as parameters
361
+ const fn = new Function(...contextKeys, ...builtinKeys, `"use strict"; return (${expression})`);
362
+ return fn(...contextValues, ...builtinValues);
363
+ }
364
+ catch (error) {
365
+ console.error(`Error evaluating expression: ${expression}`, error);
366
+ return undefined;
367
+ }
368
+ }
369
+ updateContext(updates) {
370
+ Object.assign(this.context, updates);
371
+ }
372
+ setContext(context) {
373
+ this.context = context;
374
+ }
375
+ }
376
+ export class StateDOMBinder {
377
+ constructor(state) {
378
+ this.bindings = [];
379
+ this.state = state;
380
+ this.evaluator = new ExpressionEvaluator();
381
+ }
382
+ bind(element, property, expression) {
383
+ // Update evaluator context with state
384
+ this.evaluator.setContext(this.state.getSnapshot());
385
+ // Initial evaluation
386
+ const value = this.evaluator.evaluate(expression);
387
+ this.applyValue(element, property, value);
388
+ // Subscribe to state changes
389
+ const unsubscribe = this.state.subscribe((newState) => {
390
+ this.evaluator.setContext(newState);
391
+ const newValue = this.evaluator.evaluate(expression);
392
+ this.applyValue(element, property, newValue);
393
+ });
394
+ const binding = { element, property, expression, unsubscribe };
395
+ this.bindings.push(binding);
396
+ return binding;
397
+ }
398
+ unbind(binding) {
399
+ binding.unsubscribe();
400
+ const index = this.bindings.indexOf(binding);
401
+ if (index > -1) {
402
+ this.bindings.splice(index, 1);
403
+ }
404
+ }
405
+ unbindAll() {
406
+ this.bindings.forEach((binding) => binding.unsubscribe());
407
+ this.bindings = [];
408
+ }
409
+ applyValue(element, property, value) {
410
+ // Abstract - actual implementation depends on renderer (Three.js, DOM, etc.)
411
+ if (element && typeof element === 'object') {
412
+ const el = element;
413
+ const props = property.split('.');
414
+ let target = el;
415
+ for (let i = 0; i < props.length - 1; i++) {
416
+ target = target[props[i]];
417
+ if (!target)
418
+ return;
419
+ }
420
+ target[props[props.length - 1]] = value;
421
+ }
422
+ }
423
+ }
424
+ // =============================================================================
425
+ // EXPORTS
426
+ // =============================================================================
427
+ export { track, trigger, runEffect, flushEffects, createReactiveProxy, };