@holoscript/core 2.0.1 → 2.1.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 (137) hide show
  1. package/dist/chunk-2XXE34KS.js +344 -0
  2. package/dist/chunk-2XXE34KS.js.map +1 -0
  3. package/dist/chunk-3X2EGU7Z.cjs +52 -0
  4. package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
  5. package/dist/chunk-AFFVFO4D.js +1689 -0
  6. package/dist/chunk-AFFVFO4D.js.map +1 -0
  7. package/dist/chunk-DGUM43GV.js +10 -0
  8. package/dist/chunk-DGUM43GV.js.map +1 -0
  9. package/{src/HoloScriptDebugger.ts → dist/chunk-DOY73HDH.js} +118 -257
  10. package/dist/chunk-DOY73HDH.js.map +1 -0
  11. package/dist/chunk-JEQ2X3Z6.cjs +12 -0
  12. package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
  13. package/dist/chunk-L6VLNVKP.cjs +1691 -0
  14. package/dist/chunk-L6VLNVKP.cjs.map +1 -0
  15. package/dist/chunk-MFNO57XL.cjs +347 -0
  16. package/dist/chunk-MFNO57XL.cjs.map +1 -0
  17. package/dist/chunk-R75MREOS.cjs +424 -0
  18. package/dist/chunk-R75MREOS.cjs.map +1 -0
  19. package/dist/chunk-SATNCODL.js +45 -0
  20. package/dist/chunk-SATNCODL.js.map +1 -0
  21. package/dist/chunk-T57ZL7KR.cjs +1281 -0
  22. package/dist/chunk-T57ZL7KR.cjs.map +1 -0
  23. package/dist/chunk-U72GEJZT.js +1279 -0
  24. package/dist/chunk-U72GEJZT.js.map +1 -0
  25. package/dist/debugger.cjs +20 -0
  26. package/dist/debugger.cjs.map +1 -0
  27. package/dist/debugger.d.cts +171 -0
  28. package/dist/debugger.d.ts +171 -0
  29. package/dist/debugger.js +7 -0
  30. package/dist/debugger.js.map +1 -0
  31. package/dist/index.cjs +6803 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +4093 -0
  34. package/dist/index.d.ts +4093 -0
  35. package/dist/index.js +6715 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/parser.cjs +14 -0
  38. package/dist/parser.cjs.map +1 -0
  39. package/dist/parser.d.cts +172 -0
  40. package/dist/parser.d.ts +172 -0
  41. package/dist/parser.js +5 -0
  42. package/dist/parser.js.map +1 -0
  43. package/dist/runtime.cjs +14 -0
  44. package/dist/runtime.cjs.map +1 -0
  45. package/dist/runtime.d.cts +200 -0
  46. package/dist/runtime.d.ts +200 -0
  47. package/dist/runtime.js +5 -0
  48. package/dist/runtime.js.map +1 -0
  49. package/dist/type-checker.cjs +17 -0
  50. package/dist/type-checker.cjs.map +1 -0
  51. package/dist/type-checker.d.cts +105 -0
  52. package/dist/type-checker.d.ts +105 -0
  53. package/dist/type-checker.js +4 -0
  54. package/dist/type-checker.js.map +1 -0
  55. package/dist/types-4h8cbtF_.d.cts +329 -0
  56. package/dist/types-4h8cbtF_.d.ts +329 -0
  57. package/package.json +17 -13
  58. package/src/HoloScript2DParser.js +0 -227
  59. package/src/HoloScript2DParser.ts +0 -261
  60. package/src/HoloScriptCodeParser.js +0 -1102
  61. package/src/HoloScriptCodeParser.ts +0 -1188
  62. package/src/HoloScriptDebugger.js +0 -458
  63. package/src/HoloScriptParser.js +0 -338
  64. package/src/HoloScriptParser.ts +0 -397
  65. package/src/HoloScriptPlusParser.js +0 -371
  66. package/src/HoloScriptPlusParser.ts +0 -543
  67. package/src/HoloScriptRuntime.js +0 -1399
  68. package/src/HoloScriptRuntime.test.js +0 -351
  69. package/src/HoloScriptRuntime.test.ts +0 -436
  70. package/src/HoloScriptRuntime.ts +0 -1653
  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
package/package.json CHANGED
@@ -1,37 +1,40 @@
1
1
  {
2
2
  "name": "@holoscript/core",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "HoloScript+: VR language with declarative syntax, state management, reactive traits, and VR interactions. Full backward compatible with original HoloScript.",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "sideEffects": false,
10
+ "files": [
11
+ "dist"
12
+ ],
10
13
  "exports": {
11
14
  ".": {
12
15
  "types": "./dist/index.d.ts",
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js"
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
15
18
  },
16
19
  "./parser": {
17
20
  "types": "./dist/parser.d.ts",
18
- "import": "./dist/parser.mjs",
19
- "require": "./dist/parser.js"
21
+ "import": "./dist/parser.js",
22
+ "require": "./dist/parser.cjs"
20
23
  },
21
24
  "./runtime": {
22
25
  "types": "./dist/runtime.d.ts",
23
- "import": "./dist/runtime.mjs",
24
- "require": "./dist/runtime.js"
26
+ "import": "./dist/runtime.js",
27
+ "require": "./dist/runtime.cjs"
25
28
  },
26
29
  "./type-checker": {
27
30
  "types": "./dist/type-checker.d.ts",
28
- "import": "./dist/type-checker.mjs",
29
- "require": "./dist/type-checker.js"
31
+ "import": "./dist/type-checker.js",
32
+ "require": "./dist/type-checker.cjs"
30
33
  },
31
34
  "./debugger": {
32
35
  "types": "./dist/debugger.d.ts",
33
- "import": "./dist/debugger.mjs",
34
- "require": "./dist/debugger.js"
36
+ "import": "./dist/debugger.js",
37
+ "require": "./dist/debugger.cjs"
35
38
  }
36
39
  },
37
40
  "scripts": {
@@ -59,6 +62,7 @@
59
62
  "directory": "packages/core"
60
63
  },
61
64
  "devDependencies": {
65
+ "@hololand/network": "link:c:/Users/josep/Documents/GitHub/Hololand/packages/network",
62
66
  "tsup": "^8.0.1",
63
67
  "typedoc": "^0.28.16",
64
68
  "typescript": "^5.3.3",
@@ -1,227 +0,0 @@
1
- /**
2
- * HoloScript 2D Parser Extension
3
- *
4
- * Adds support for 2D UI elements to HoloScript for desktop/mobile apps.
5
- * Works alongside 3D VR syntax for hybrid applications.
6
- */
7
- import { logger } from './logger';
8
- const UI_SECURITY_CONFIG = {
9
- maxUIElements: 500,
10
- maxNestingDepth: 10,
11
- maxPropertyLength: 500,
12
- allowedEventHandlers: ['onClick', 'onChange', 'onSubmit', 'onFocus', 'onBlur', 'onHover'],
13
- };
14
- export class HoloScript2DParser {
15
- constructor() {
16
- this.uiElements = new Map();
17
- }
18
- /**
19
- * Parse 2D UI element from HoloScript code
20
- */
21
- parse2DElement(code, depth = 0) {
22
- if (depth > UI_SECURITY_CONFIG.maxNestingDepth) {
23
- logger.warn('Max nesting depth exceeded', { depth });
24
- return null;
25
- }
26
- const trimmedCode = code.trim();
27
- const lines = trimmedCode.split('\n');
28
- if (lines.length === 0)
29
- return null;
30
- const firstLine = lines[0].trim();
31
- const headerMatch = firstLine.match(/^([\w-]+)\s+(\w+)\s*\{/);
32
- if (!headerMatch) {
33
- logger.warn('Invalid 2D element syntax', { line: firstLine });
34
- return null;
35
- }
36
- const [, elementType, name] = headerMatch;
37
- if (!this.isValidUIElementType(elementType)) {
38
- logger.warn('Invalid UI element type', { elementType });
39
- return null;
40
- }
41
- const startIndex = trimmedCode.indexOf('{');
42
- const endIndex = trimmedCode.lastIndexOf('}');
43
- if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
44
- return null;
45
- }
46
- const innerContent = trimmedCode.slice(startIndex + 1, endIndex).trim();
47
- const innerLines = this.splitIntoLogicalBlocks(innerContent);
48
- const properties = {};
49
- const events = {};
50
- const children = [];
51
- for (const block of innerLines) {
52
- const line = block.trim();
53
- if (!line)
54
- continue;
55
- if (line.includes('{')) {
56
- const childNode = this.parse2DElement(line, depth + 1);
57
- if (childNode)
58
- children.push(childNode);
59
- continue;
60
- }
61
- const propMatch = line.match(/^(\w+):\s*(.+)$/);
62
- if (propMatch) {
63
- const [, key, rawValue] = propMatch;
64
- if (UI_SECURITY_CONFIG.allowedEventHandlers.includes(key)) {
65
- events[key] = rawValue.trim();
66
- }
67
- else {
68
- properties[key] = this.parsePropertyValue(rawValue);
69
- }
70
- }
71
- }
72
- const node = {
73
- type: '2d-element',
74
- elementType: elementType,
75
- name,
76
- properties: { ...this.getDefaultProperties(elementType), ...properties },
77
- events: Object.keys(events).length > 0 ? events : undefined,
78
- children: children.length > 0 ? children : undefined,
79
- };
80
- if (depth === 0) {
81
- if (this.uiElements.size >= UI_SECURITY_CONFIG.maxUIElements) {
82
- logger.warn('Max UI elements limit reached');
83
- return null;
84
- }
85
- this.uiElements.set(name, node);
86
- }
87
- return node;
88
- }
89
- splitIntoLogicalBlocks(content) {
90
- const blocks = [];
91
- let currentBlock = '';
92
- let bracketDepth = 0;
93
- for (let i = 0; i < content.length; i++) {
94
- const char = content[i];
95
- if (char === '{')
96
- bracketDepth++;
97
- if (char === '}')
98
- bracketDepth--;
99
- currentBlock += char;
100
- if (bracketDepth === 0) {
101
- if (char === '\n' || i === content.length - 1) {
102
- const trimmed = currentBlock.trim();
103
- if (trimmed)
104
- blocks.push(trimmed);
105
- currentBlock = '';
106
- }
107
- }
108
- }
109
- const finalTrimmed = currentBlock.trim();
110
- if (finalTrimmed)
111
- blocks.push(finalTrimmed);
112
- return blocks;
113
- }
114
- /**
115
- * Parse voice command for 2D UI creation
116
- */
117
- parse2DVoiceCommand(command) {
118
- const tokens = command.toLowerCase().trim().split(/\s+/);
119
- if (tokens.length < 3)
120
- return null;
121
- const action = tokens[0];
122
- const elementType = tokens[1];
123
- const name = tokens[2];
124
- if (action !== 'create' && action !== 'add')
125
- return null;
126
- if (!this.isValidUIElementType(elementType))
127
- return null;
128
- const node = {
129
- type: '2d-element',
130
- elementType: elementType,
131
- name,
132
- properties: this.getDefaultProperties(elementType),
133
- };
134
- this.uiElements.set(name, node);
135
- return node;
136
- }
137
- /**
138
- * Parse gesture for 2D UI interaction
139
- */
140
- parse2DGesture(gestureType, position) {
141
- switch (gestureType) {
142
- case 'tap':
143
- return this.createQuick2DElement('button', `button_${Date.now()}`, position);
144
- case 'double-tap':
145
- return this.createQuick2DElement('textinput', `input_${Date.now()}`, position);
146
- case 'long-press':
147
- return this.createQuick2DElement('panel', `panel_${Date.now()}`, position);
148
- default:
149
- return null;
150
- }
151
- }
152
- createQuick2DElement(elementType, name, position) {
153
- const node = {
154
- type: '2d-element',
155
- elementType,
156
- name,
157
- properties: {
158
- ...this.getDefaultProperties(elementType),
159
- x: position.x,
160
- y: position.y,
161
- },
162
- };
163
- this.uiElements.set(name, node);
164
- return node;
165
- }
166
- isValidUIElementType(type) {
167
- const validTypes = [
168
- 'canvas', 'button', 'textinput', 'panel', 'text', 'image',
169
- 'list', 'modal', 'slider', 'toggle', 'dropdown',
170
- 'flex-container', 'grid-container', 'scroll-view', 'tab-view'
171
- ];
172
- return validTypes.includes(type);
173
- }
174
- parsePropertyValue(value) {
175
- const trimmed = value.trim();
176
- if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
177
- (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
178
- return trimmed.slice(1, -1);
179
- }
180
- if (!isNaN(parseFloat(trimmed)) && isFinite(parseFloat(trimmed))) {
181
- return parseFloat(trimmed);
182
- }
183
- if (trimmed === 'true')
184
- return true;
185
- if (trimmed === 'false')
186
- return false;
187
- if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
188
- const items = trimmed.slice(1, -1).split(',').map(item => this.parsePropertyValue(item.trim()));
189
- return items;
190
- }
191
- return trimmed;
192
- }
193
- getDefaultProperties(elementType) {
194
- const defaults = {
195
- 'canvas': { width: 800, height: 600, backgroundColor: '#ffffff' },
196
- 'button': { text: 'Button', width: 120, height: 40, backgroundColor: '#007bff', color: '#ffffff', borderRadius: 4 },
197
- 'textinput': { placeholder: '', width: 200, height: 36, fontSize: 14, borderColor: '#cccccc', borderWidth: 1, borderRadius: 4 },
198
- 'panel': { width: 200, height: 200, backgroundColor: '#f0f0f0', borderRadius: 0 },
199
- 'text': { content: 'Text', fontSize: 16, color: '#000000', fontFamily: 'sans-serif' },
200
- 'image': { src: '', width: 100, height: 100, fit: 'cover' },
201
- 'list': { items: [], itemHeight: 40, width: 200, height: 300 },
202
- 'modal': { title: 'Modal', width: 400, height: 300, visible: false, backgroundColor: '#ffffff' },
203
- 'slider': { min: 0, max: 100, value: 50, width: 200 },
204
- 'toggle': { checked: false, width: 50, height: 24 },
205
- 'dropdown': { options: [], selected: null, width: 200 },
206
- 'flex-container': { direction: 'row', gap: 10, padding: 10 },
207
- 'grid-container': { columns: 3, gap: 10, padding: 10 },
208
- 'scroll-view': { width: 300, height: 400, scrollDirection: 'vertical' },
209
- 'tab-view': { tabs: [], activeTabId: null, tabPosition: 'top', width: 400, height: 300 },
210
- 'dashboard': { title: 'Dashboard', width: 1200, height: 800, layout: 'grid', columns: 4 },
211
- 'card': { title: '', width: 300, height: 200, backgroundColor: '#ffffff', elevation: 2 },
212
- 'metric': { label: '', value: 0, unit: '', fontSize: 24, color: '#000000' },
213
- 'row': { height: 'auto', gap: 10, alignItems: 'center' },
214
- 'col': { width: 'auto', gap: 10, alignItems: 'stretch' },
215
- };
216
- return { ...defaults[elementType] };
217
- }
218
- getUIElements() {
219
- return new Map(this.uiElements);
220
- }
221
- findElement(name) {
222
- return this.uiElements.get(name) || null;
223
- }
224
- clear() {
225
- this.uiElements.clear();
226
- }
227
- }
@@ -1,261 +0,0 @@
1
- /**
2
- * HoloScript 2D Parser Extension
3
- *
4
- * Adds support for 2D UI elements to HoloScript for desktop/mobile apps.
5
- * Works alongside 3D VR syntax for hybrid applications.
6
- */
7
-
8
- import { logger } from './logger';
9
- import type { UI2DNode, UIElementType, Position2D } from './types';
10
-
11
- const UI_SECURITY_CONFIG = {
12
- maxUIElements: 500,
13
- maxNestingDepth: 10,
14
- maxPropertyLength: 500,
15
- allowedEventHandlers: ['onClick', 'onChange', 'onSubmit', 'onFocus', 'onBlur', 'onHover'],
16
- };
17
-
18
- export class HoloScript2DParser {
19
- private uiElements: Map<string, UI2DNode> = new Map();
20
-
21
- /**
22
- * Parse 2D UI element from HoloScript code
23
- */
24
- parse2DElement(code: string, depth: number = 0): UI2DNode | null {
25
- if (depth > UI_SECURITY_CONFIG.maxNestingDepth) {
26
- logger.warn('Max nesting depth exceeded', { depth });
27
- return null;
28
- }
29
-
30
- const trimmedCode = code.trim();
31
- const lines = trimmedCode.split('\n');
32
- if (lines.length === 0) return null;
33
-
34
- const firstLine = lines[0].trim();
35
- const headerMatch = firstLine.match(/^([\w-]+)\s+(\w+)\s*\{/);
36
-
37
- if (!headerMatch) {
38
- logger.warn('Invalid 2D element syntax', { line: firstLine });
39
- return null;
40
- }
41
-
42
- const [, elementType, name] = headerMatch;
43
-
44
- if (!this.isValidUIElementType(elementType)) {
45
- logger.warn('Invalid UI element type', { elementType });
46
- return null;
47
- }
48
-
49
- const startIndex = trimmedCode.indexOf('{');
50
- const endIndex = trimmedCode.lastIndexOf('}');
51
- if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
52
- return null;
53
- }
54
-
55
- const innerContent = trimmedCode.slice(startIndex + 1, endIndex).trim();
56
- const innerLines = this.splitIntoLogicalBlocks(innerContent);
57
-
58
- const properties: Record<string, unknown> = {};
59
- const events: Record<string, string> = {};
60
- const children: UI2DNode[] = [];
61
-
62
- for (const block of innerLines) {
63
- const line = block.trim();
64
- if (!line) continue;
65
-
66
- if (line.includes('{')) {
67
- const childNode = this.parse2DElement(line, depth + 1);
68
- if (childNode) children.push(childNode);
69
- continue;
70
- }
71
-
72
- const propMatch = line.match(/^(\w+):\s*(.+)$/);
73
- if (propMatch) {
74
- const [, key, rawValue] = propMatch;
75
- if (UI_SECURITY_CONFIG.allowedEventHandlers.includes(key)) {
76
- events[key] = rawValue.trim();
77
- } else {
78
- properties[key] = this.parsePropertyValue(rawValue);
79
- }
80
- }
81
- }
82
-
83
- const node: UI2DNode = {
84
- type: '2d-element',
85
- elementType: elementType as UIElementType,
86
- name,
87
- properties: { ...this.getDefaultProperties(elementType as UIElementType), ...properties },
88
- events: Object.keys(events).length > 0 ? events : undefined,
89
- children: children.length > 0 ? children : undefined,
90
- };
91
-
92
- if (depth === 0) {
93
- if (this.uiElements.size >= UI_SECURITY_CONFIG.maxUIElements) {
94
- logger.warn('Max UI elements limit reached');
95
- return null;
96
- }
97
- this.uiElements.set(name, node);
98
- }
99
-
100
- return node;
101
- }
102
-
103
- private splitIntoLogicalBlocks(content: string): string[] {
104
- const blocks: string[] = [];
105
- let currentBlock = '';
106
- let bracketDepth = 0;
107
-
108
- for (let i = 0; i < content.length; i++) {
109
- const char = content[i];
110
- if (char === '{') bracketDepth++;
111
- if (char === '}') bracketDepth--;
112
-
113
- currentBlock += char;
114
-
115
- if (bracketDepth === 0) {
116
- if (char === '\n' || i === content.length - 1) {
117
- const trimmed = currentBlock.trim();
118
- if (trimmed) blocks.push(trimmed);
119
- currentBlock = '';
120
- }
121
- }
122
- }
123
-
124
- const finalTrimmed = currentBlock.trim();
125
- if (finalTrimmed) blocks.push(finalTrimmed);
126
-
127
- return blocks;
128
- }
129
-
130
- /**
131
- * Parse voice command for 2D UI creation
132
- */
133
- parse2DVoiceCommand(command: string): UI2DNode | null {
134
- const tokens = command.toLowerCase().trim().split(/\s+/);
135
-
136
- if (tokens.length < 3) return null;
137
-
138
- const action = tokens[0];
139
- const elementType = tokens[1];
140
- const name = tokens[2];
141
-
142
- if (action !== 'create' && action !== 'add') return null;
143
- if (!this.isValidUIElementType(elementType)) return null;
144
-
145
- const node: UI2DNode = {
146
- type: '2d-element',
147
- elementType: elementType as UIElementType,
148
- name,
149
- properties: this.getDefaultProperties(elementType as UIElementType),
150
- };
151
-
152
- this.uiElements.set(name, node);
153
- return node;
154
- }
155
-
156
- /**
157
- * Parse gesture for 2D UI interaction
158
- */
159
- parse2DGesture(gestureType: string, position: Position2D): UI2DNode | null {
160
- switch (gestureType) {
161
- case 'tap':
162
- return this.createQuick2DElement('button', `button_${Date.now()}`, position);
163
- case 'double-tap':
164
- return this.createQuick2DElement('textinput', `input_${Date.now()}`, position);
165
- case 'long-press':
166
- return this.createQuick2DElement('panel', `panel_${Date.now()}`, position);
167
- default:
168
- return null;
169
- }
170
- }
171
-
172
- private createQuick2DElement(elementType: UIElementType, name: string, position: Position2D): UI2DNode {
173
- const node: UI2DNode = {
174
- type: '2d-element',
175
- elementType,
176
- name,
177
- properties: {
178
- ...this.getDefaultProperties(elementType),
179
- x: position.x,
180
- y: position.y,
181
- },
182
- };
183
-
184
- this.uiElements.set(name, node);
185
- return node;
186
- }
187
-
188
- private isValidUIElementType(type: string): boolean {
189
- const validTypes: UIElementType[] = [
190
- 'canvas', 'button', 'textinput', 'panel', 'text', 'image',
191
- 'list', 'modal', 'slider', 'toggle', 'dropdown',
192
- 'flex-container', 'grid-container', 'scroll-view', 'tab-view'
193
- ];
194
- return validTypes.includes(type as UIElementType);
195
- }
196
-
197
- private parsePropertyValue(value: string): unknown {
198
- const trimmed = value.trim();
199
-
200
- if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
201
- (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
202
- return trimmed.slice(1, -1);
203
- }
204
-
205
- if (!isNaN(parseFloat(trimmed)) && isFinite(parseFloat(trimmed))) {
206
- return parseFloat(trimmed);
207
- }
208
-
209
- if (trimmed === 'true') return true;
210
- if (trimmed === 'false') return false;
211
-
212
- if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
213
- const items = trimmed.slice(1, -1).split(',').map(item =>
214
- this.parsePropertyValue(item.trim())
215
- );
216
- return items;
217
- }
218
-
219
- return trimmed;
220
- }
221
-
222
- private getDefaultProperties(elementType: UIElementType): Record<string, unknown> {
223
- const defaults: Record<UIElementType, Record<string, unknown>> = {
224
- 'canvas': { width: 800, height: 600, backgroundColor: '#ffffff' },
225
- 'button': { text: 'Button', width: 120, height: 40, backgroundColor: '#007bff', color: '#ffffff', borderRadius: 4 },
226
- 'textinput': { placeholder: '', width: 200, height: 36, fontSize: 14, borderColor: '#cccccc', borderWidth: 1, borderRadius: 4 },
227
- 'panel': { width: 200, height: 200, backgroundColor: '#f0f0f0', borderRadius: 0 },
228
- 'text': { content: 'Text', fontSize: 16, color: '#000000', fontFamily: 'sans-serif' },
229
- 'image': { src: '', width: 100, height: 100, fit: 'cover' },
230
- 'list': { items: [], itemHeight: 40, width: 200, height: 300 },
231
- 'modal': { title: 'Modal', width: 400, height: 300, visible: false, backgroundColor: '#ffffff' },
232
- 'slider': { min: 0, max: 100, value: 50, width: 200 },
233
- 'toggle': { checked: false, width: 50, height: 24 },
234
- 'dropdown': { options: [], selected: null, width: 200 },
235
- 'flex-container': { direction: 'row', gap: 10, padding: 10 },
236
- 'grid-container': { columns: 3, gap: 10, padding: 10 },
237
- 'scroll-view': { width: 300, height: 400, scrollDirection: 'vertical' },
238
- 'tab-view': { tabs: [], activeTabId: null, tabPosition: 'top', width: 400, height: 300 },
239
- 'dashboard': { title: 'Dashboard', width: 1200, height: 800, layout: 'grid', columns: 4 },
240
- 'card': { title: '', width: 300, height: 200, backgroundColor: '#ffffff', elevation: 2 },
241
- 'metric': { label: '', value: 0, unit: '', fontSize: 24, color: '#000000' },
242
- 'row': { height: 'auto', gap: 10, alignItems: 'center' },
243
- 'col': { width: 'auto', gap: 10, alignItems: 'stretch' },
244
- };
245
- return { ...defaults[elementType] };
246
- }
247
-
248
- getUIElements(): Map<string, UI2DNode> {
249
- return new Map(this.uiElements);
250
- }
251
-
252
- findElement(name: string): UI2DNode | null {
253
- return this.uiElements.get(name) || null;
254
- }
255
-
256
- clear(): void {
257
- this.uiElements.clear();
258
- }
259
- }
260
-
261
- export type { UI2DNode, UIElementType, Position2D };