@holoscript/core 2.0.0 → 2.0.2

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunk-3N67RLQP.cjs +1298 -0
  3. package/dist/chunk-3N67RLQP.cjs.map +1 -0
  4. package/dist/chunk-3X2EGU7Z.cjs +52 -0
  5. package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
  6. package/dist/chunk-4CV4JOE5.js +24 -0
  7. package/dist/chunk-4CV4JOE5.js.map +1 -0
  8. package/dist/chunk-4OHVW4XR.cjs +1027 -0
  9. package/dist/chunk-4OHVW4XR.cjs.map +1 -0
  10. package/dist/chunk-CZLDE2OZ.cjs +28 -0
  11. package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
  12. package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
  13. package/dist/chunk-EU6CZMGJ.js.map +1 -0
  14. package/dist/chunk-KWYIVRIH.js +344 -0
  15. package/dist/chunk-KWYIVRIH.js.map +1 -0
  16. package/dist/chunk-MCP6D4LT.js +1025 -0
  17. package/dist/chunk-MCP6D4LT.js.map +1 -0
  18. package/dist/chunk-SATNCODL.js +45 -0
  19. package/dist/chunk-SATNCODL.js.map +1 -0
  20. package/dist/chunk-VMZN4EVR.cjs +347 -0
  21. package/dist/chunk-VMZN4EVR.cjs.map +1 -0
  22. package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
  23. package/dist/chunk-VYIDLUCV.js.map +1 -0
  24. package/dist/chunk-WFI4T3XB.cjs +424 -0
  25. package/dist/chunk-WFI4T3XB.cjs.map +1 -0
  26. package/dist/debugger.cjs +20 -0
  27. package/dist/debugger.cjs.map +1 -0
  28. package/dist/debugger.d.cts +171 -0
  29. package/dist/debugger.d.ts +171 -0
  30. package/dist/debugger.js +7 -0
  31. package/dist/debugger.js.map +1 -0
  32. package/dist/index.cjs +6006 -0
  33. package/dist/index.cjs.map +1 -0
  34. package/dist/index.d.cts +2482 -0
  35. package/dist/index.d.ts +2482 -0
  36. package/dist/index.js +5926 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/parser.cjs +14 -0
  39. package/dist/parser.cjs.map +1 -0
  40. package/dist/parser.d.cts +139 -0
  41. package/dist/parser.d.ts +139 -0
  42. package/dist/parser.js +5 -0
  43. package/dist/parser.js.map +1 -0
  44. package/dist/runtime.cjs +14 -0
  45. package/dist/runtime.cjs.map +1 -0
  46. package/dist/runtime.d.cts +180 -0
  47. package/dist/runtime.d.ts +180 -0
  48. package/dist/runtime.js +5 -0
  49. package/dist/runtime.js.map +1 -0
  50. package/dist/type-checker.cjs +17 -0
  51. package/dist/type-checker.cjs.map +1 -0
  52. package/dist/type-checker.d.cts +105 -0
  53. package/dist/type-checker.d.ts +105 -0
  54. package/dist/type-checker.js +4 -0
  55. package/dist/type-checker.js.map +1 -0
  56. package/dist/types-D6g4ACjP.d.cts +262 -0
  57. package/dist/types-D6g4ACjP.d.ts +262 -0
  58. package/package.json +11 -8
  59. package/src/HoloScript2DParser.js +0 -227
  60. package/src/HoloScript2DParser.ts +0 -261
  61. package/src/HoloScriptCodeParser.js +0 -1102
  62. package/src/HoloScriptCodeParser.ts +0 -1188
  63. package/src/HoloScriptDebugger.js +0 -458
  64. package/src/HoloScriptParser.js +0 -338
  65. package/src/HoloScriptParser.ts +0 -397
  66. package/src/HoloScriptPlusParser.js +0 -371
  67. package/src/HoloScriptPlusParser.ts +0 -543
  68. package/src/HoloScriptRuntime.js +0 -1399
  69. package/src/HoloScriptRuntime.test.js +0 -351
  70. package/src/HoloScriptRuntime.test.ts +0 -436
  71. package/src/HoloScriptTypeChecker.js +0 -356
  72. package/src/HoloScriptTypeChecker.ts +0 -475
  73. package/src/__tests__/GraphicsServices.test.js +0 -357
  74. package/src/__tests__/GraphicsServices.test.ts +0 -427
  75. package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
  76. package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
  77. package/src/__tests__/integration.test.js +0 -336
  78. package/src/__tests__/integration.test.ts +0 -416
  79. package/src/__tests__/performance.bench.js +0 -218
  80. package/src/__tests__/performance.bench.ts +0 -262
  81. package/src/__tests__/type-checker.test.js +0 -60
  82. package/src/__tests__/type-checker.test.ts +0 -73
  83. package/src/index.js +0 -217
  84. package/src/index.ts +0 -426
  85. package/src/interop/Interoperability.js +0 -413
  86. package/src/interop/Interoperability.ts +0 -494
  87. package/src/logger.js +0 -42
  88. package/src/logger.ts +0 -57
  89. package/src/parser/EnhancedParser.js +0 -205
  90. package/src/parser/EnhancedParser.ts +0 -251
  91. package/src/parser/HoloScriptPlusParser.js +0 -928
  92. package/src/parser/HoloScriptPlusParser.ts +0 -1089
  93. package/src/runtime/HoloScriptPlusRuntime.js +0 -674
  94. package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
  95. package/src/runtime/PerformanceTelemetry.js +0 -323
  96. package/src/runtime/PerformanceTelemetry.ts +0 -467
  97. package/src/runtime/RuntimeOptimization.js +0 -361
  98. package/src/runtime/RuntimeOptimization.ts +0 -416
  99. package/src/services/HololandGraphicsPipelineService.js +0 -506
  100. package/src/services/HololandGraphicsPipelineService.ts +0 -662
  101. package/src/services/PlatformPerformanceOptimizer.js +0 -356
  102. package/src/services/PlatformPerformanceOptimizer.ts +0 -503
  103. package/src/state/ReactiveState.js +0 -427
  104. package/src/state/ReactiveState.ts +0 -572
  105. package/src/tools/DeveloperExperience.js +0 -376
  106. package/src/tools/DeveloperExperience.ts +0 -438
  107. package/src/traits/AIDriverTrait.js +0 -322
  108. package/src/traits/AIDriverTrait.test.js +0 -329
  109. package/src/traits/AIDriverTrait.test.ts +0 -357
  110. package/src/traits/AIDriverTrait.ts +0 -474
  111. package/src/traits/LightingTrait.js +0 -313
  112. package/src/traits/LightingTrait.test.js +0 -410
  113. package/src/traits/LightingTrait.test.ts +0 -462
  114. package/src/traits/LightingTrait.ts +0 -505
  115. package/src/traits/MaterialTrait.js +0 -194
  116. package/src/traits/MaterialTrait.test.js +0 -286
  117. package/src/traits/MaterialTrait.test.ts +0 -329
  118. package/src/traits/MaterialTrait.ts +0 -324
  119. package/src/traits/RenderingTrait.js +0 -356
  120. package/src/traits/RenderingTrait.test.js +0 -363
  121. package/src/traits/RenderingTrait.test.ts +0 -427
  122. package/src/traits/RenderingTrait.ts +0 -555
  123. package/src/traits/VRTraitSystem.js +0 -740
  124. package/src/traits/VRTraitSystem.ts +0 -1040
  125. package/src/traits/VoiceInputTrait.js +0 -284
  126. package/src/traits/VoiceInputTrait.test.js +0 -226
  127. package/src/traits/VoiceInputTrait.test.ts +0 -252
  128. package/src/traits/VoiceInputTrait.ts +0 -401
  129. package/src/types/AdvancedTypeSystem.js +0 -226
  130. package/src/types/AdvancedTypeSystem.ts +0 -494
  131. package/src/types/HoloScriptPlus.d.ts +0 -853
  132. package/src/types.js +0 -6
  133. package/src/types.ts +0 -369
  134. package/tsconfig.json +0 -23
  135. package/tsup.config.d.ts +0 -2
  136. package/tsup.config.js +0 -18
  137. package/tsup.config.ts +0 -19
@@ -1,427 +0,0 @@
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, };