@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,338 @@
1
+ /**
2
+ * HoloScript Parser
3
+ *
4
+ * Parses voice commands, gestures, and code into HoloScript AST.
5
+ * Supports both 3D VR and 2D UI elements.
6
+ */
7
+ import { logger } from './logger';
8
+ import { HoloScript2DParser } from './HoloScript2DParser';
9
+ const HOLOSCRIPT_SECURITY_CONFIG = {
10
+ maxCommandLength: 1000,
11
+ maxTokens: 100,
12
+ maxHologramsPerUser: 50,
13
+ suspiciousKeywords: [
14
+ 'process', 'require', 'eval', 'import', 'constructor',
15
+ 'prototype', '__proto__', 'fs', 'child_process', 'exec',
16
+ 'spawn', 'fetch', 'xmlhttprequest',
17
+ ],
18
+ allowedShapes: ['orb', 'cube', 'cylinder', 'pyramid', 'sphere', 'function', 'gate', 'stream'],
19
+ allowedUIElements: [
20
+ 'canvas', 'button', 'textinput', 'panel', 'text', 'image',
21
+ 'list', 'modal', 'slider', 'toggle', 'dropdown',
22
+ 'flex-container', 'grid-container', 'scroll-view'
23
+ ],
24
+ };
25
+ export class HoloScriptParser {
26
+ constructor() {
27
+ this.ast = [];
28
+ this.parser2D = new HoloScript2DParser();
29
+ }
30
+ /**
31
+ * Parse voice command into AST nodes
32
+ */
33
+ parseVoiceCommand(command) {
34
+ if (command.command.length > HOLOSCRIPT_SECURITY_CONFIG.maxCommandLength) {
35
+ logger.warn('Command too long', {
36
+ length: command.command.length,
37
+ limit: HOLOSCRIPT_SECURITY_CONFIG.maxCommandLength,
38
+ });
39
+ return [];
40
+ }
41
+ const rawTokens = this.tokenizeCommand(command.command.toLowerCase());
42
+ const tokens = this.sanitizeTokens(rawTokens);
43
+ if (tokens.length === 0)
44
+ return [];
45
+ if (tokens.length > HOLOSCRIPT_SECURITY_CONFIG.maxTokens) {
46
+ logger.warn('Too many tokens in command', {
47
+ tokenCount: tokens.length,
48
+ limit: HOLOSCRIPT_SECURITY_CONFIG.maxTokens,
49
+ });
50
+ return [];
51
+ }
52
+ const commandType = tokens[0];
53
+ // Check if this is a 2D UI command
54
+ if ((commandType === 'create' || commandType === 'add') && tokens.length > 1) {
55
+ const elementType = tokens[1];
56
+ if (HOLOSCRIPT_SECURITY_CONFIG.allowedUIElements.includes(elementType)) {
57
+ return this.parse2DUICommand(command.command);
58
+ }
59
+ }
60
+ switch (commandType) {
61
+ case 'create':
62
+ case 'summon':
63
+ return this.parseCreateCommand(tokens.slice(1), command.spatialContext);
64
+ case 'connect':
65
+ return this.parseConnectCommand(tokens.slice(1));
66
+ case 'execute':
67
+ case 'run':
68
+ return this.parseExecuteCommand(tokens.slice(1));
69
+ case 'debug':
70
+ return this.parseDebugCommand(tokens.slice(1));
71
+ case 'visualize':
72
+ return this.parseVisualizeCommand(tokens.slice(1));
73
+ default:
74
+ return this.parseGenericCommand(tokens);
75
+ }
76
+ }
77
+ parse2DUICommand(command) {
78
+ const ui2DNode = this.parser2D.parse2DVoiceCommand(command);
79
+ if (!ui2DNode)
80
+ return [];
81
+ const astNode = {
82
+ type: '2d-ui',
83
+ uiElementType: ui2DNode.elementType,
84
+ name: ui2DNode.name,
85
+ properties: ui2DNode.properties,
86
+ events: ui2DNode.events,
87
+ children: ui2DNode.children,
88
+ };
89
+ return [astNode];
90
+ }
91
+ /**
92
+ * Parse gesture input
93
+ */
94
+ parseGesture(gesture) {
95
+ switch (gesture.type) {
96
+ case 'pinch':
97
+ return this.parsePinchGesture(gesture);
98
+ case 'swipe':
99
+ return this.parseSwipeGesture(gesture);
100
+ case 'rotate':
101
+ return this.parseRotateGesture(gesture);
102
+ case 'grab':
103
+ return this.parseGrabGesture(gesture);
104
+ default:
105
+ return [];
106
+ }
107
+ }
108
+ parseCreateCommand(tokens, position) {
109
+ if (tokens.length < 2)
110
+ return [];
111
+ const shape = tokens[0];
112
+ const name = tokens[1];
113
+ switch (shape) {
114
+ case 'orb':
115
+ case 'sphere':
116
+ return [this.createOrbNode(name, position)];
117
+ case 'function':
118
+ return [this.createFunctionNode(name, tokens.slice(2), position)];
119
+ case 'gate':
120
+ return [this.createGateNode(name, tokens.slice(2), position)];
121
+ case 'stream':
122
+ return [this.createStreamNode(name, tokens.slice(2), position)];
123
+ default:
124
+ return [this.createGenericNode(shape, name, position)];
125
+ }
126
+ }
127
+ parseConnectCommand(tokens) {
128
+ if (tokens.length < 3)
129
+ return [];
130
+ const from = tokens[0];
131
+ const to = tokens[2];
132
+ const dataType = tokens.length > 3 ? tokens[3] : 'any';
133
+ return [{
134
+ type: 'connection',
135
+ from,
136
+ to,
137
+ dataType,
138
+ bidirectional: tokens.includes('bidirectional') || tokens.includes('both'),
139
+ }];
140
+ }
141
+ createOrbNode(name, position) {
142
+ return {
143
+ type: 'orb',
144
+ name,
145
+ position: position || { x: 0, y: 0, z: 0 },
146
+ hologram: {
147
+ shape: 'orb',
148
+ color: '#00ffff',
149
+ size: 1,
150
+ glow: true,
151
+ interactive: true,
152
+ },
153
+ properties: {},
154
+ methods: [],
155
+ };
156
+ }
157
+ createFunctionNode(name, params, position) {
158
+ const parameters = [];
159
+ let inParams = false;
160
+ for (const param of params) {
161
+ if (param === 'with' || param === 'parameters') {
162
+ inParams = true;
163
+ continue;
164
+ }
165
+ if (inParams && param !== 'do' && param !== 'execute') {
166
+ parameters.push({
167
+ type: 'parameter',
168
+ name: param,
169
+ dataType: 'any',
170
+ });
171
+ }
172
+ }
173
+ return {
174
+ type: 'function',
175
+ name,
176
+ parameters,
177
+ body: [],
178
+ position: position || { x: 0, y: 0, z: 0 },
179
+ hologram: {
180
+ shape: 'cube',
181
+ color: '#ff6b35',
182
+ size: 1.5,
183
+ glow: true,
184
+ interactive: true,
185
+ },
186
+ };
187
+ }
188
+ createGateNode(_name, params, position) {
189
+ const condition = params.join(' ').replace('condition', '').trim();
190
+ return {
191
+ type: 'gate',
192
+ condition,
193
+ truePath: [],
194
+ falsePath: [],
195
+ position: position || { x: 0, y: 0, z: 0 },
196
+ hologram: {
197
+ shape: 'pyramid',
198
+ color: '#4ecdc4',
199
+ size: 1,
200
+ glow: true,
201
+ interactive: true,
202
+ },
203
+ };
204
+ }
205
+ createStreamNode(name, params, position) {
206
+ return {
207
+ type: 'stream',
208
+ name,
209
+ source: params[0] || 'unknown',
210
+ transformations: [],
211
+ position: position || { x: 0, y: 0, z: 0 },
212
+ hologram: {
213
+ shape: 'cylinder',
214
+ color: '#45b7d1',
215
+ size: 2,
216
+ glow: true,
217
+ interactive: true,
218
+ },
219
+ };
220
+ }
221
+ createGenericNode(shape, name, position) {
222
+ return {
223
+ type: shape,
224
+ name,
225
+ position: position || { x: 0, y: 0, z: 0 },
226
+ hologram: {
227
+ shape: shape,
228
+ color: '#ffffff',
229
+ size: 1,
230
+ glow: false,
231
+ interactive: true,
232
+ },
233
+ };
234
+ }
235
+ parsePinchGesture(gesture) {
236
+ return [{
237
+ type: 'create',
238
+ position: gesture.position,
239
+ hologram: { shape: 'orb', color: '#ff0000', size: 0.5, glow: true, interactive: true },
240
+ }];
241
+ }
242
+ parseSwipeGesture(gesture) {
243
+ if (!gesture.direction)
244
+ return [];
245
+ return [{
246
+ type: 'connect',
247
+ position: gesture.position,
248
+ hologram: { shape: 'cylinder', color: '#00ff00', size: gesture.magnitude, glow: true, interactive: false },
249
+ }];
250
+ }
251
+ parseRotateGesture(gesture) {
252
+ return [{
253
+ type: 'modify',
254
+ position: gesture.position,
255
+ hologram: { shape: 'sphere', color: '#ffff00', size: 0.8, glow: true, interactive: true },
256
+ }];
257
+ }
258
+ parseGrabGesture(gesture) {
259
+ return [{
260
+ type: 'select',
261
+ position: gesture.position,
262
+ hologram: { shape: 'cube', color: '#ff00ff', size: 0.3, glow: true, interactive: true },
263
+ }];
264
+ }
265
+ tokenizeCommand(command) {
266
+ return command
267
+ .toLowerCase()
268
+ .replace(/[^\w\s]/g, ' ')
269
+ .split(/\s+/)
270
+ .filter(token => token.length > 0);
271
+ }
272
+ sanitizeTokens(tokens) {
273
+ return tokens.filter(token => {
274
+ const isSuspicious = HOLOSCRIPT_SECURITY_CONFIG.suspiciousKeywords.some(keyword => token.includes(keyword));
275
+ if (isSuspicious) {
276
+ logger.warn('Suspicious token blocked', { token });
277
+ return false;
278
+ }
279
+ return true;
280
+ });
281
+ }
282
+ parseExecuteCommand(tokens) {
283
+ return [{
284
+ type: 'execute',
285
+ target: tokens[0] || 'unknown',
286
+ hologram: { shape: 'sphere', color: '#ff4500', size: 1.2, glow: true, interactive: false },
287
+ }];
288
+ }
289
+ parseDebugCommand(tokens) {
290
+ return [{
291
+ type: 'debug',
292
+ target: tokens[0] || 'program',
293
+ hologram: { shape: 'pyramid', color: '#ff1493', size: 0.8, glow: true, interactive: true },
294
+ }];
295
+ }
296
+ parseVisualizeCommand(tokens) {
297
+ return [{
298
+ type: 'visualize',
299
+ target: tokens[0] || 'data',
300
+ hologram: { shape: 'cylinder', color: '#32cd32', size: 1.5, glow: true, interactive: true },
301
+ }];
302
+ }
303
+ parseGenericCommand(tokens) {
304
+ return [{
305
+ type: 'generic',
306
+ command: tokens.join(' '),
307
+ hologram: { shape: 'orb', color: '#808080', size: 0.5, glow: false, interactive: true },
308
+ }];
309
+ }
310
+ getAST() {
311
+ return [...this.ast];
312
+ }
313
+ addNode(node) {
314
+ this.ast.push(node);
315
+ }
316
+ clear() {
317
+ this.ast = [];
318
+ }
319
+ findNode(name) {
320
+ return this.ast.find(node => 'name' in node && node.name === name) || null;
321
+ }
322
+ getNodesAtPosition(position, radius = 1) {
323
+ return this.ast.filter(node => {
324
+ if (!node.position)
325
+ return false;
326
+ const distance = Math.sqrt(Math.pow(node.position.x - position.x, 2) +
327
+ Math.pow(node.position.y - position.y, 2) +
328
+ Math.pow(node.position.z - position.z, 2));
329
+ return distance <= radius;
330
+ });
331
+ }
332
+ parse2DCode(code) {
333
+ return this.parser2D.parse2DElement(code);
334
+ }
335
+ get2DParser() {
336
+ return this.parser2D;
337
+ }
338
+ }
@@ -0,0 +1,371 @@
1
+ /**
2
+ * HoloScriptPlus Parser - Extended DSL with Trait Annotations
3
+ *
4
+ * Extends HoloScript with support for:
5
+ * - @material trait annotations for PBR materials
6
+ * - @lighting trait annotations for dynamic lighting
7
+ * - @rendering trait annotations for GPU optimization
8
+ *
9
+ * Syntax:
10
+ * orb#sphere {
11
+ * @material { type: pbr, metallic: 0.5, roughness: 0.4 }
12
+ * @lighting { preset: studio, shadows: true }
13
+ * @rendering { quality: high, lod: true }
14
+ * }
15
+ */
16
+ import { HoloScriptCodeParser } from './HoloScriptCodeParser';
17
+ // ============================================================================
18
+ // HoloScriptPlus Parser
19
+ // ============================================================================
20
+ export class HoloScriptPlusParser {
21
+ constructor() {
22
+ this.baseParser = new HoloScriptCodeParser();
23
+ }
24
+ /**
25
+ * Parse HoloScript+ code with trait annotations
26
+ */
27
+ parse(code) {
28
+ // First, parse with base parser
29
+ const baseResult = this.baseParser.parse(code);
30
+ const ast = (Array.isArray(baseResult) ? baseResult : [baseResult]);
31
+ // Then enhance with trait annotations
32
+ return this.enhanceWithTraits(ast, code);
33
+ }
34
+ /**
35
+ * Enhance AST nodes with trait annotations
36
+ */
37
+ enhanceWithTraits(ast, code) {
38
+ return ast.map((node) => {
39
+ if (node.type === 'orb') {
40
+ return this.enhanceOrbNodeWithTraits(node, code);
41
+ }
42
+ return node;
43
+ });
44
+ }
45
+ /**
46
+ * Enhance OrbNode with trait annotations
47
+ */
48
+ enhanceOrbNodeWithTraits(node, code) {
49
+ const orbNode = node;
50
+ const enhanced = {
51
+ ...orbNode,
52
+ traits: [],
53
+ graphics: {},
54
+ };
55
+ // Find trait annotations in the code near this node
56
+ const traits = this.extractTraitAnnotations(code, node.line);
57
+ enhanced.traits = traits;
58
+ // Build graphics configuration from traits
59
+ if (traits.length > 0) {
60
+ enhanced.graphics = this.buildGraphicsConfig(traits);
61
+ }
62
+ return enhanced;
63
+ }
64
+ /**
65
+ * Extract trait annotations from code
66
+ */
67
+ extractTraitAnnotations(code, _orbLine) {
68
+ const traits = [];
69
+ const traitRegex = /@(material|lighting|rendering)\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/g;
70
+ let match;
71
+ while ((match = traitRegex.exec(code)) !== null) {
72
+ const type = match[1];
73
+ const configStr = match[2];
74
+ try {
75
+ const config = this.parseObjectLiteral(configStr);
76
+ switch (type) {
77
+ case 'material':
78
+ traits.push({
79
+ type: 'material',
80
+ config: config,
81
+ });
82
+ break;
83
+ case 'lighting':
84
+ traits.push({
85
+ type: 'lighting',
86
+ config: config,
87
+ });
88
+ break;
89
+ case 'rendering':
90
+ traits.push({
91
+ type: 'rendering',
92
+ config: config,
93
+ });
94
+ break;
95
+ }
96
+ }
97
+ catch (e) {
98
+ console.warn(`Failed to parse ${type} trait annotation:`, e);
99
+ }
100
+ }
101
+ return traits;
102
+ }
103
+ /**
104
+ * Parse object literal from string
105
+ * Supports nested objects and arrays
106
+ */
107
+ parseObjectLiteral(str) {
108
+ const config = {};
109
+ // Split by comma, but respect nested braces and brackets
110
+ let depth = 0;
111
+ let current = '';
112
+ let pairs = [];
113
+ for (let i = 0; i < str.length; i++) {
114
+ const char = str[i];
115
+ if (char === '{' || char === '[') {
116
+ depth++;
117
+ }
118
+ else if (char === '}' || char === ']') {
119
+ depth--;
120
+ }
121
+ else if (char === ',' && depth === 0) {
122
+ pairs.push(current.trim());
123
+ current = '';
124
+ continue;
125
+ }
126
+ current += char;
127
+ }
128
+ if (current.trim()) {
129
+ pairs.push(current.trim());
130
+ }
131
+ // Parse each key:value pair
132
+ for (const pair of pairs) {
133
+ const colonIndex = pair.indexOf(':');
134
+ if (colonIndex === -1)
135
+ continue;
136
+ const key = pair.substring(0, colonIndex).trim();
137
+ const value = pair.substring(colonIndex + 1).trim();
138
+ config[key] = this.parseValue(value);
139
+ }
140
+ return config;
141
+ }
142
+ /**
143
+ * Parse individual values
144
+ */
145
+ parseValue(str) {
146
+ str = str.trim();
147
+ // Boolean
148
+ if (str === 'true')
149
+ return true;
150
+ if (str === 'false')
151
+ return false;
152
+ // Number
153
+ if (/^-?\d+(\.\d+)?$/.test(str))
154
+ return parseFloat(str);
155
+ // String
156
+ if ((str.startsWith('"') && str.endsWith('"')) || (str.startsWith("'") && str.endsWith("'"))) {
157
+ return str.slice(1, -1);
158
+ }
159
+ // Color object: { r: 0.8, g: 0.2, b: 0.2 }
160
+ if (str.startsWith('{') && str.endsWith('}')) {
161
+ return this.parseObjectLiteral(str.slice(1, -1));
162
+ }
163
+ // Array: [1, 2, 3]
164
+ if (str.startsWith('[') && str.endsWith(']')) {
165
+ const items = str.slice(1, -1).split(',');
166
+ return items.map((item) => this.parseValue(item));
167
+ }
168
+ return str;
169
+ }
170
+ /**
171
+ * Build GraphicsConfiguration from trait annotations
172
+ */
173
+ buildGraphicsConfig(traits) {
174
+ const config = {};
175
+ for (const trait of traits) {
176
+ switch (trait.type) {
177
+ case 'material':
178
+ config.material = trait.config;
179
+ break;
180
+ case 'lighting':
181
+ config.lighting = trait.config;
182
+ break;
183
+ case 'rendering':
184
+ config.rendering = trait.config;
185
+ break;
186
+ }
187
+ }
188
+ return config;
189
+ }
190
+ /**
191
+ * Validate trait annotation configuration
192
+ */
193
+ validateTraitAnnotation(trait) {
194
+ const errors = [];
195
+ switch (trait.type) {
196
+ case 'material':
197
+ errors.push(...this.validateMaterialTrait(trait));
198
+ break;
199
+ case 'lighting':
200
+ errors.push(...this.validateLightingTrait(trait));
201
+ break;
202
+ case 'rendering':
203
+ errors.push(...this.validateRenderingTrait(trait));
204
+ break;
205
+ }
206
+ return {
207
+ valid: errors.length === 0,
208
+ errors,
209
+ };
210
+ }
211
+ /**
212
+ * Validate material trait configuration
213
+ */
214
+ validateMaterialTrait(trait) {
215
+ const errors = [];
216
+ const { config } = trait;
217
+ if (config.pbr) {
218
+ if (config.pbr.metallic !== undefined && (config.pbr.metallic < 0 || config.pbr.metallic > 1)) {
219
+ errors.push('material.pbr.metallic must be between 0 and 1');
220
+ }
221
+ if (config.pbr.roughness !== undefined && (config.pbr.roughness < 0 || config.pbr.roughness > 1)) {
222
+ errors.push('material.pbr.roughness must be between 0 and 1');
223
+ }
224
+ }
225
+ if (config.compression && !['none', 'dxt', 'astc', 'basis'].includes(config.compression)) {
226
+ errors.push(`material.compression must be one of: none, dxt, astc, basis`);
227
+ }
228
+ return errors;
229
+ }
230
+ /**
231
+ * Validate lighting trait configuration
232
+ */
233
+ validateLightingTrait(trait) {
234
+ const errors = [];
235
+ const { config } = trait;
236
+ if (config.preset && !['studio', 'outdoor', 'interior', 'night', 'sunset'].includes(config.preset)) {
237
+ errors.push('lighting.preset must be one of: studio, outdoor, interior, night, sunset');
238
+ }
239
+ if (config.lights) {
240
+ config.lights.forEach((light, index) => {
241
+ if (!['directional', 'point', 'spot', 'area', 'ambient'].includes(light.type)) {
242
+ errors.push(`lighting.lights[${index}].type must be a valid light type`);
243
+ }
244
+ if (light.intensity !== undefined && light.intensity < 0) {
245
+ errors.push(`lighting.lights[${index}].intensity must be >= 0`);
246
+ }
247
+ });
248
+ }
249
+ return errors;
250
+ }
251
+ /**
252
+ * Validate rendering trait configuration
253
+ */
254
+ validateRenderingTrait(trait) {
255
+ const errors = [];
256
+ const { config } = trait;
257
+ if (config.quality && !['low', 'medium', 'high', 'ultra'].includes(config.quality)) {
258
+ errors.push('rendering.quality must be one of: low, medium, high, ultra');
259
+ }
260
+ if (config.platform && !['mobile', 'vr', 'desktop'].includes(config.platform)) {
261
+ errors.push('rendering.platform must be one of: mobile, vr, desktop');
262
+ }
263
+ if (config.compression && !['none', 'dxt', 'astc', 'basis'].includes(config.compression)) {
264
+ errors.push('rendering.compression must be one of: none, dxt, astc, basis');
265
+ }
266
+ if (config.maxTextureResolution && config.maxTextureResolution < 128) {
267
+ errors.push('rendering.maxTextureResolution must be >= 128');
268
+ }
269
+ if (config.targetFPS && (config.targetFPS < 24 || config.targetFPS > 240)) {
270
+ errors.push('rendering.targetFPS must be between 24 and 240');
271
+ }
272
+ return errors;
273
+ }
274
+ /**
275
+ * Get trait annotations as graphics traits
276
+ */
277
+ createGraphicsTraits(config) {
278
+ // This will be called by the runtime to create actual trait instances
279
+ return {
280
+ material: config.material ? this.createMaterialTrait(config.material) : null,
281
+ lighting: config.lighting ? this.createLightingTrait(config.lighting) : null,
282
+ rendering: config.rendering ? this.createRenderingTrait(config.rendering) : null,
283
+ };
284
+ }
285
+ /**
286
+ * Create MaterialTrait from config
287
+ */
288
+ createMaterialTrait(config) {
289
+ // Lazy import to avoid circular dependencies
290
+ const { MaterialTrait } = require('./traits/MaterialTrait');
291
+ const material = new MaterialTrait({
292
+ type: config.type || 'pbr',
293
+ pbr: config.pbr,
294
+ });
295
+ if (config.compression) {
296
+ material.setCompression(config.compression);
297
+ }
298
+ if (config.instancing) {
299
+ material.setInstanced(true);
300
+ }
301
+ if (config.streaming) {
302
+ material.setTextureStreaming(true);
303
+ }
304
+ if (config.textures) {
305
+ config.textures.forEach((tex) => {
306
+ material.addTexture(tex);
307
+ });
308
+ }
309
+ return material;
310
+ }
311
+ /**
312
+ * Create LightingTrait from config
313
+ */
314
+ createLightingTrait(config) {
315
+ const { LightingTrait, LIGHTING_PRESETS } = require('./traits/LightingTrait');
316
+ let lighting;
317
+ if (config.preset) {
318
+ const preset = LIGHTING_PRESETS[config.preset];
319
+ lighting = new LightingTrait(preset);
320
+ }
321
+ else {
322
+ lighting = new LightingTrait();
323
+ }
324
+ if (config.globalIllumination) {
325
+ lighting.setGlobalIllumination(config.globalIllumination);
326
+ }
327
+ if (config.lights) {
328
+ config.lights.forEach((light) => {
329
+ lighting.addLight(light);
330
+ });
331
+ }
332
+ return lighting;
333
+ }
334
+ /**
335
+ * Create RenderingTrait from config
336
+ */
337
+ createRenderingTrait(config) {
338
+ const { RenderingTrait } = require('./traits/RenderingTrait');
339
+ const rendering = new RenderingTrait();
340
+ if (config.quality) {
341
+ rendering.applyQualityPreset(config.quality);
342
+ }
343
+ if (config.platform) {
344
+ switch (config.platform) {
345
+ case 'mobile':
346
+ rendering.optimizeForMobile();
347
+ break;
348
+ case 'vr':
349
+ rendering.optimizeForVRAR(config.targetFPS || 90);
350
+ break;
351
+ case 'desktop':
352
+ rendering.optimizeForDesktop();
353
+ break;
354
+ }
355
+ }
356
+ if (config.lod !== false) {
357
+ rendering.setupLODLevels('automatic');
358
+ }
359
+ if (config.culling !== false) {
360
+ rendering.setFrustumCulling(true);
361
+ }
362
+ if (config.compression) {
363
+ rendering.setTextureCompression(config.compression);
364
+ }
365
+ if (config.maxTextureResolution) {
366
+ rendering.setMaxTextureResolution(config.maxTextureResolution);
367
+ }
368
+ return rendering;
369
+ }
370
+ }
371
+ export default HoloScriptPlusParser;