@holoscript/core 2.0.1 → 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.
- package/LICENSE +21 -0
- package/dist/chunk-3N67RLQP.cjs +1298 -0
- package/dist/chunk-3N67RLQP.cjs.map +1 -0
- package/dist/chunk-3X2EGU7Z.cjs +52 -0
- package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
- package/dist/chunk-4CV4JOE5.js +24 -0
- package/dist/chunk-4CV4JOE5.js.map +1 -0
- package/dist/chunk-4OHVW4XR.cjs +1027 -0
- package/dist/chunk-4OHVW4XR.cjs.map +1 -0
- package/dist/chunk-CZLDE2OZ.cjs +28 -0
- package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
- package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
- package/dist/chunk-EU6CZMGJ.js.map +1 -0
- package/dist/chunk-KWYIVRIH.js +344 -0
- package/dist/chunk-KWYIVRIH.js.map +1 -0
- package/dist/chunk-MCP6D4LT.js +1025 -0
- package/dist/chunk-MCP6D4LT.js.map +1 -0
- package/dist/chunk-SATNCODL.js +45 -0
- package/dist/chunk-SATNCODL.js.map +1 -0
- package/dist/chunk-VMZN4EVR.cjs +347 -0
- package/dist/chunk-VMZN4EVR.cjs.map +1 -0
- package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
- package/dist/chunk-VYIDLUCV.js.map +1 -0
- package/dist/chunk-WFI4T3XB.cjs +424 -0
- package/dist/chunk-WFI4T3XB.cjs.map +1 -0
- package/dist/debugger.cjs +20 -0
- package/dist/debugger.cjs.map +1 -0
- package/dist/debugger.d.cts +171 -0
- package/dist/debugger.d.ts +171 -0
- package/dist/debugger.js +7 -0
- package/dist/debugger.js.map +1 -0
- package/dist/index.cjs +6006 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2482 -0
- package/dist/index.d.ts +2482 -0
- package/dist/index.js +5926 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.cjs +14 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +139 -0
- package/dist/parser.d.ts +139 -0
- package/dist/parser.js +5 -0
- package/dist/parser.js.map +1 -0
- package/dist/runtime.cjs +14 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +180 -0
- package/dist/runtime.d.ts +180 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/type-checker.cjs +17 -0
- package/dist/type-checker.cjs.map +1 -0
- package/dist/type-checker.d.cts +105 -0
- package/dist/type-checker.d.ts +105 -0
- package/dist/type-checker.js +4 -0
- package/dist/type-checker.js.map +1 -0
- package/dist/types-D6g4ACjP.d.cts +262 -0
- package/dist/types-D6g4ACjP.d.ts +262 -0
- package/package.json +11 -8
- package/src/HoloScript2DParser.js +0 -227
- package/src/HoloScript2DParser.ts +0 -261
- package/src/HoloScriptCodeParser.js +0 -1102
- package/src/HoloScriptCodeParser.ts +0 -1188
- package/src/HoloScriptDebugger.js +0 -458
- package/src/HoloScriptParser.js +0 -338
- package/src/HoloScriptParser.ts +0 -397
- package/src/HoloScriptPlusParser.js +0 -371
- package/src/HoloScriptPlusParser.ts +0 -543
- package/src/HoloScriptRuntime.js +0 -1399
- package/src/HoloScriptRuntime.test.js +0 -351
- package/src/HoloScriptRuntime.test.ts +0 -436
- package/src/HoloScriptTypeChecker.js +0 -356
- package/src/HoloScriptTypeChecker.ts +0 -475
- package/src/__tests__/GraphicsServices.test.js +0 -357
- package/src/__tests__/GraphicsServices.test.ts +0 -427
- package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
- package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
- package/src/__tests__/integration.test.js +0 -336
- package/src/__tests__/integration.test.ts +0 -416
- package/src/__tests__/performance.bench.js +0 -218
- package/src/__tests__/performance.bench.ts +0 -262
- package/src/__tests__/type-checker.test.js +0 -60
- package/src/__tests__/type-checker.test.ts +0 -73
- package/src/index.js +0 -217
- package/src/index.ts +0 -426
- package/src/interop/Interoperability.js +0 -413
- package/src/interop/Interoperability.ts +0 -494
- package/src/logger.js +0 -42
- package/src/logger.ts +0 -57
- package/src/parser/EnhancedParser.js +0 -205
- package/src/parser/EnhancedParser.ts +0 -251
- package/src/parser/HoloScriptPlusParser.js +0 -928
- package/src/parser/HoloScriptPlusParser.ts +0 -1089
- package/src/runtime/HoloScriptPlusRuntime.js +0 -674
- package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
- package/src/runtime/PerformanceTelemetry.js +0 -323
- package/src/runtime/PerformanceTelemetry.ts +0 -467
- package/src/runtime/RuntimeOptimization.js +0 -361
- package/src/runtime/RuntimeOptimization.ts +0 -416
- package/src/services/HololandGraphicsPipelineService.js +0 -506
- package/src/services/HololandGraphicsPipelineService.ts +0 -662
- package/src/services/PlatformPerformanceOptimizer.js +0 -356
- package/src/services/PlatformPerformanceOptimizer.ts +0 -503
- package/src/state/ReactiveState.js +0 -427
- package/src/state/ReactiveState.ts +0 -572
- package/src/tools/DeveloperExperience.js +0 -376
- package/src/tools/DeveloperExperience.ts +0 -438
- package/src/traits/AIDriverTrait.js +0 -322
- package/src/traits/AIDriverTrait.test.js +0 -329
- package/src/traits/AIDriverTrait.test.ts +0 -357
- package/src/traits/AIDriverTrait.ts +0 -474
- package/src/traits/LightingTrait.js +0 -313
- package/src/traits/LightingTrait.test.js +0 -410
- package/src/traits/LightingTrait.test.ts +0 -462
- package/src/traits/LightingTrait.ts +0 -505
- package/src/traits/MaterialTrait.js +0 -194
- package/src/traits/MaterialTrait.test.js +0 -286
- package/src/traits/MaterialTrait.test.ts +0 -329
- package/src/traits/MaterialTrait.ts +0 -324
- package/src/traits/RenderingTrait.js +0 -356
- package/src/traits/RenderingTrait.test.js +0 -363
- package/src/traits/RenderingTrait.test.ts +0 -427
- package/src/traits/RenderingTrait.ts +0 -555
- package/src/traits/VRTraitSystem.js +0 -740
- package/src/traits/VRTraitSystem.ts +0 -1040
- package/src/traits/VoiceInputTrait.js +0 -284
- package/src/traits/VoiceInputTrait.test.js +0 -226
- package/src/traits/VoiceInputTrait.test.ts +0 -252
- package/src/traits/VoiceInputTrait.ts +0 -401
- package/src/types/AdvancedTypeSystem.js +0 -226
- package/src/types/AdvancedTypeSystem.ts +0 -494
- package/src/types/HoloScriptPlus.d.ts +0 -853
- package/src/types.js +0 -6
- package/src/types.ts +0 -369
- package/tsconfig.json +0 -23
- package/tsup.config.d.ts +0 -2
- package/tsup.config.js +0 -18
- package/tsup.config.ts +0 -19
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @holoscript/core Types
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions for HoloScript AST and runtime
|
|
5
|
+
*/
|
|
6
|
+
interface SpatialPosition {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
z: number;
|
|
10
|
+
}
|
|
11
|
+
interface Position2D {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
interface Size2D {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
type HologramShape = 'orb' | 'cube' | 'cylinder' | 'pyramid' | 'sphere';
|
|
20
|
+
interface HologramProperties {
|
|
21
|
+
shape: HologramShape;
|
|
22
|
+
color: string;
|
|
23
|
+
size: number;
|
|
24
|
+
glow: boolean;
|
|
25
|
+
interactive: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface VoiceCommand {
|
|
28
|
+
command: string;
|
|
29
|
+
confidence: number;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
spatialContext?: SpatialPosition;
|
|
32
|
+
}
|
|
33
|
+
type GestureType = 'pinch' | 'swipe' | 'rotate' | 'grab' | 'release';
|
|
34
|
+
type HandType = 'left' | 'right';
|
|
35
|
+
interface GestureData {
|
|
36
|
+
type: GestureType;
|
|
37
|
+
position: SpatialPosition;
|
|
38
|
+
direction?: SpatialPosition;
|
|
39
|
+
magnitude: number;
|
|
40
|
+
hand: HandType;
|
|
41
|
+
}
|
|
42
|
+
interface ASTNode {
|
|
43
|
+
type: string;
|
|
44
|
+
position?: SpatialPosition;
|
|
45
|
+
hologram?: HologramProperties;
|
|
46
|
+
/** Source line number (1-indexed) */
|
|
47
|
+
line?: number;
|
|
48
|
+
/** Source column number (0-indexed) */
|
|
49
|
+
column?: number;
|
|
50
|
+
}
|
|
51
|
+
interface OrbNode extends ASTNode {
|
|
52
|
+
type: 'orb';
|
|
53
|
+
name: string;
|
|
54
|
+
properties: Record<string, unknown>;
|
|
55
|
+
methods: MethodNode[];
|
|
56
|
+
}
|
|
57
|
+
interface MethodNode extends ASTNode {
|
|
58
|
+
type: 'method';
|
|
59
|
+
name: string;
|
|
60
|
+
parameters: ParameterNode[];
|
|
61
|
+
body: ASTNode[];
|
|
62
|
+
returnType?: string;
|
|
63
|
+
}
|
|
64
|
+
interface ParameterNode extends ASTNode {
|
|
65
|
+
type: 'parameter';
|
|
66
|
+
name: string;
|
|
67
|
+
dataType: string;
|
|
68
|
+
defaultValue?: unknown;
|
|
69
|
+
}
|
|
70
|
+
interface ConnectionNode extends ASTNode {
|
|
71
|
+
type: 'connection';
|
|
72
|
+
from: string;
|
|
73
|
+
to: string;
|
|
74
|
+
dataType: string;
|
|
75
|
+
bidirectional: boolean;
|
|
76
|
+
}
|
|
77
|
+
interface GateNode extends ASTNode {
|
|
78
|
+
type: 'gate';
|
|
79
|
+
condition: string;
|
|
80
|
+
truePath: ASTNode[];
|
|
81
|
+
falsePath: ASTNode[];
|
|
82
|
+
}
|
|
83
|
+
interface StreamNode extends ASTNode {
|
|
84
|
+
type: 'stream';
|
|
85
|
+
name: string;
|
|
86
|
+
source: string;
|
|
87
|
+
transformations: TransformationNode[];
|
|
88
|
+
}
|
|
89
|
+
interface TransformationNode extends ASTNode {
|
|
90
|
+
type: 'transformation';
|
|
91
|
+
operation: string;
|
|
92
|
+
parameters: Record<string, unknown>;
|
|
93
|
+
}
|
|
94
|
+
interface GenericASTNode extends ASTNode {
|
|
95
|
+
[key: string]: unknown;
|
|
96
|
+
}
|
|
97
|
+
interface ForLoopNode extends ASTNode {
|
|
98
|
+
type: 'for-loop';
|
|
99
|
+
init: string;
|
|
100
|
+
condition: string;
|
|
101
|
+
update: string;
|
|
102
|
+
body: ASTNode[];
|
|
103
|
+
}
|
|
104
|
+
interface WhileLoopNode extends ASTNode {
|
|
105
|
+
type: 'while-loop';
|
|
106
|
+
condition: string;
|
|
107
|
+
body: ASTNode[];
|
|
108
|
+
}
|
|
109
|
+
interface ForEachLoopNode extends ASTNode {
|
|
110
|
+
type: 'foreach-loop';
|
|
111
|
+
variable: string;
|
|
112
|
+
collection: string;
|
|
113
|
+
body: ASTNode[];
|
|
114
|
+
}
|
|
115
|
+
interface ImportNode extends ASTNode {
|
|
116
|
+
type: 'import';
|
|
117
|
+
imports: string[];
|
|
118
|
+
defaultImport?: string;
|
|
119
|
+
modulePath: string;
|
|
120
|
+
}
|
|
121
|
+
type ImportLoader = (path: string) => Promise<string>;
|
|
122
|
+
interface ExportNode extends ASTNode {
|
|
123
|
+
type: 'export';
|
|
124
|
+
exports?: string[];
|
|
125
|
+
declaration?: ASTNode;
|
|
126
|
+
}
|
|
127
|
+
interface VariableDeclarationNode extends ASTNode {
|
|
128
|
+
type: 'variable-declaration';
|
|
129
|
+
kind: 'const' | 'let' | 'var';
|
|
130
|
+
name: string;
|
|
131
|
+
dataType?: string;
|
|
132
|
+
value?: unknown;
|
|
133
|
+
isExpression?: boolean;
|
|
134
|
+
}
|
|
135
|
+
type UIElementType = 'canvas' | 'button' | 'textinput' | 'panel' | 'text' | 'image' | 'list' | 'modal' | 'slider' | 'toggle' | 'dropdown' | 'flex-container' | 'grid-container' | 'scroll-view' | 'tab-view' | 'dashboard' | 'card' | 'metric' | 'row' | 'col';
|
|
136
|
+
interface UI2DNode {
|
|
137
|
+
type: '2d-element';
|
|
138
|
+
elementType: UIElementType;
|
|
139
|
+
name: string;
|
|
140
|
+
properties: Record<string, unknown>;
|
|
141
|
+
children?: UI2DNode[];
|
|
142
|
+
events?: Record<string, string>;
|
|
143
|
+
}
|
|
144
|
+
interface UIStyle {
|
|
145
|
+
backgroundColor?: string;
|
|
146
|
+
color?: string;
|
|
147
|
+
fontSize?: number;
|
|
148
|
+
fontFamily?: string;
|
|
149
|
+
borderColor?: string;
|
|
150
|
+
borderWidth?: number;
|
|
151
|
+
borderRadius?: number;
|
|
152
|
+
padding?: number;
|
|
153
|
+
margin?: number;
|
|
154
|
+
}
|
|
155
|
+
interface RuntimeContext {
|
|
156
|
+
variables: Map<string, unknown>;
|
|
157
|
+
functions: Map<string, MethodNode>;
|
|
158
|
+
exports: Map<string, unknown>;
|
|
159
|
+
connections: ConnectionNode[];
|
|
160
|
+
spatialMemory: Map<string, SpatialPosition>;
|
|
161
|
+
hologramState: Map<string, HologramProperties>;
|
|
162
|
+
executionStack: ASTNode[];
|
|
163
|
+
}
|
|
164
|
+
interface ExecutionResult {
|
|
165
|
+
success: boolean;
|
|
166
|
+
output?: unknown;
|
|
167
|
+
hologram?: HologramProperties;
|
|
168
|
+
spatialPosition?: SpatialPosition;
|
|
169
|
+
error?: string;
|
|
170
|
+
executionTime?: number;
|
|
171
|
+
learningSignals?: any;
|
|
172
|
+
}
|
|
173
|
+
interface ParticleSystem {
|
|
174
|
+
particles: SpatialPosition[];
|
|
175
|
+
color: string;
|
|
176
|
+
lifetime: number;
|
|
177
|
+
speed: number;
|
|
178
|
+
}
|
|
179
|
+
interface SecurityConfig {
|
|
180
|
+
maxCommandLength: number;
|
|
181
|
+
maxTokens: number;
|
|
182
|
+
maxHologramsPerUser: number;
|
|
183
|
+
suspiciousKeywords: string[];
|
|
184
|
+
allowedShapes: string[];
|
|
185
|
+
allowedUIElements: string[];
|
|
186
|
+
}
|
|
187
|
+
interface RuntimeSecurityLimits {
|
|
188
|
+
maxExecutionDepth: number;
|
|
189
|
+
maxTotalNodes: number;
|
|
190
|
+
maxExecutionTimeMs: number;
|
|
191
|
+
maxParticlesPerSystem: number;
|
|
192
|
+
}
|
|
193
|
+
interface Vector3 {
|
|
194
|
+
x: number;
|
|
195
|
+
y: number;
|
|
196
|
+
z: number;
|
|
197
|
+
}
|
|
198
|
+
interface Vector2 {
|
|
199
|
+
x: number;
|
|
200
|
+
y: number;
|
|
201
|
+
}
|
|
202
|
+
interface Color {
|
|
203
|
+
r: number;
|
|
204
|
+
g: number;
|
|
205
|
+
b: number;
|
|
206
|
+
a?: number;
|
|
207
|
+
}
|
|
208
|
+
interface Duration {
|
|
209
|
+
milliseconds: number;
|
|
210
|
+
}
|
|
211
|
+
interface Transform {
|
|
212
|
+
position: Vector3;
|
|
213
|
+
rotation: Vector3;
|
|
214
|
+
scale: Vector3;
|
|
215
|
+
}
|
|
216
|
+
type VRHand = 'left' | 'right' | 'both';
|
|
217
|
+
interface ThrowVelocity {
|
|
218
|
+
magnitude: number;
|
|
219
|
+
direction: Vector3;
|
|
220
|
+
spin?: Vector3;
|
|
221
|
+
}
|
|
222
|
+
interface CollisionEvent {
|
|
223
|
+
object1: string;
|
|
224
|
+
object2: string;
|
|
225
|
+
position: Vector3;
|
|
226
|
+
normal: Vector3;
|
|
227
|
+
force: number;
|
|
228
|
+
timestamp: number;
|
|
229
|
+
}
|
|
230
|
+
interface GrabbableTrait {
|
|
231
|
+
snapToHand: boolean;
|
|
232
|
+
grip_type: 'palm' | 'pinch' | 'full';
|
|
233
|
+
haptic_feedback: boolean;
|
|
234
|
+
}
|
|
235
|
+
interface ThrowableTrait {
|
|
236
|
+
velocityMultiplier: number;
|
|
237
|
+
enableSpin: boolean;
|
|
238
|
+
gravityScale: number;
|
|
239
|
+
}
|
|
240
|
+
interface PointableTrait {
|
|
241
|
+
maxPointDistance: number;
|
|
242
|
+
interactionRadius: number;
|
|
243
|
+
hapticFeedback: boolean;
|
|
244
|
+
}
|
|
245
|
+
interface HoverableTrait {
|
|
246
|
+
hoverDistance: number;
|
|
247
|
+
hoverColor: Color;
|
|
248
|
+
hoverScale: number;
|
|
249
|
+
enableHighlight: boolean;
|
|
250
|
+
}
|
|
251
|
+
interface ScalableTrait {
|
|
252
|
+
minScale: number;
|
|
253
|
+
maxScale: number;
|
|
254
|
+
scaleSpeed: number;
|
|
255
|
+
}
|
|
256
|
+
interface RotatableTrait {
|
|
257
|
+
rotationSpeed: number;
|
|
258
|
+
freeRotation: boolean;
|
|
259
|
+
snapAngles?: number[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export type { ASTNode as A, ExecutionResult as B, ConnectionNode as C, Duration as D, ExportNode as E, ForLoopNode as F, GestureData as G, HologramShape as H, ImportNode as I, ParticleSystem as J, SecurityConfig as K, RuntimeSecurityLimits as L, MethodNode as M, OrbNode as O, Position2D as P, RotatableTrait as R, SpatialPosition as S, TransformationNode as T, UI2DNode as U, VoiceCommand as V, WhileLoopNode as W, Size2D as a, HologramProperties as b, GestureType as c, HandType as d, ParameterNode as e, GateNode as f, StreamNode as g, GenericASTNode as h, Vector3 as i, Vector2 as j, Color as k, Transform as l, VRHand as m, ThrowVelocity as n, CollisionEvent as o, GrabbableTrait as p, ThrowableTrait as q, PointableTrait as r, HoverableTrait as s, ScalableTrait as t, ForEachLoopNode as u, ImportLoader as v, VariableDeclarationNode as w, UIElementType as x, UIStyle as y, RuntimeContext as z };
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holoscript/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
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",
|
|
@@ -34,12 +37,6 @@
|
|
|
34
37
|
"require": "./dist/debugger.js"
|
|
35
38
|
}
|
|
36
39
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsup",
|
|
39
|
-
"dev": "tsup --watch",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:watch": "vitest"
|
|
42
|
-
},
|
|
43
40
|
"keywords": [
|
|
44
41
|
"holoscript",
|
|
45
42
|
"vr",
|
|
@@ -63,5 +60,11 @@
|
|
|
63
60
|
"typedoc": "^0.28.16",
|
|
64
61
|
"typescript": "^5.3.3",
|
|
65
62
|
"vitest": "^1.0.0"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup",
|
|
66
|
+
"dev": "tsup --watch",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"test:watch": "vitest"
|
|
66
69
|
}
|
|
67
|
-
}
|
|
70
|
+
}
|
|
@@ -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
|
-
}
|