@vibexdotnew/inspector 0.0.10 → 0.0.12

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.
@@ -1,461 +0,0 @@
1
-
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.default = componentTagger;
5
- const parser_1 = require("@babel/parser");
6
- const magic_string_1 = require("magic-string");
7
- const estree_walker_1 = require("estree-walker");
8
- const path = require("path");
9
- /* ───────────────────────────────────────────── Blacklists */
10
- const threeFiberElems = [
11
- "object3D",
12
- "audioListener",
13
- "positionalAudio",
14
- "mesh",
15
- "batchedMesh",
16
- "instancedMesh",
17
- "scene",
18
- "sprite",
19
- "lOD",
20
- "skinnedMesh",
21
- "skeleton",
22
- "bone",
23
- "lineSegments",
24
- "lineLoop",
25
- "points",
26
- "group",
27
- "camera",
28
- "perspectiveCamera",
29
- "orthographicCamera",
30
- "cubeCamera",
31
- "arrayCamera",
32
- "instancedBufferGeometry",
33
- "bufferGeometry",
34
- "boxBufferGeometry",
35
- "circleBufferGeometry",
36
- "coneBufferGeometry",
37
- "cylinderBufferGeometry",
38
- "dodecahedronBufferGeometry",
39
- "extrudeBufferGeometry",
40
- "icosahedronBufferGeometry",
41
- "latheBufferGeometry",
42
- "octahedronBufferGeometry",
43
- "planeBufferGeometry",
44
- "polyhedronBufferGeometry",
45
- "ringBufferGeometry",
46
- "shapeBufferGeometry",
47
- "sphereBufferGeometry",
48
- "tetrahedronBufferGeometry",
49
- "torusBufferGeometry",
50
- "torusKnotBufferGeometry",
51
- "tubeBufferGeometry",
52
- "wireframeGeometry",
53
- "tetrahedronGeometry",
54
- "octahedronGeometry",
55
- "icosahedronGeometry",
56
- "dodecahedronGeometry",
57
- "polyhedronGeometry",
58
- "tubeGeometry",
59
- "torusKnotGeometry",
60
- "torusGeometry",
61
- "sphereGeometry",
62
- "ringGeometry",
63
- "planeGeometry",
64
- "latheGeometry",
65
- "shapeGeometry",
66
- "extrudeGeometry",
67
- "edgesGeometry",
68
- "coneGeometry",
69
- "cylinderGeometry",
70
- "circleGeometry",
71
- "boxGeometry",
72
- "capsuleGeometry",
73
- "material",
74
- "shadowMaterial",
75
- "spriteMaterial",
76
- "rawShaderMaterial",
77
- "shaderMaterial",
78
- "pointsMaterial",
79
- "meshPhysicalMaterial",
80
- "meshStandardMaterial",
81
- "meshPhongMaterial",
82
- "meshToonMaterial",
83
- "meshNormalMaterial",
84
- "meshLambertMaterial",
85
- "meshDepthMaterial",
86
- "meshDistanceMaterial",
87
- "meshBasicMaterial",
88
- "meshMatcapMaterial",
89
- "lineDashedMaterial",
90
- "lineBasicMaterial",
91
- "primitive",
92
- "light",
93
- "spotLightShadow",
94
- "spotLight",
95
- "pointLight",
96
- "rectAreaLight",
97
- "hemisphereLight",
98
- "directionalLightShadow",
99
- "directionalLight",
100
- "ambientLight",
101
- "lightShadow",
102
- "ambientLightProbe",
103
- "hemisphereLightProbe",
104
- "lightProbe",
105
- "spotLightHelper",
106
- "skeletonHelper",
107
- "pointLightHelper",
108
- "hemisphereLightHelper",
109
- "gridHelper",
110
- "polarGridHelper",
111
- "directionalLightHelper",
112
- "cameraHelper",
113
- "boxHelper",
114
- "box3Helper",
115
- "planeHelper",
116
- "arrowHelper",
117
- "axesHelper",
118
- "texture",
119
- "videoTexture",
120
- "dataTexture",
121
- "dataTexture3D",
122
- "compressedTexture",
123
- "cubeTexture",
124
- "canvasTexture",
125
- "depthTexture",
126
- "raycaster",
127
- "vector2",
128
- "vector3",
129
- "vector4",
130
- "euler",
131
- "matrix3",
132
- "matrix4",
133
- "quaternion",
134
- "bufferAttribute",
135
- "float16BufferAttribute",
136
- "float32BufferAttribute",
137
- "float64BufferAttribute",
138
- "int8BufferAttribute",
139
- "int16BufferAttribute",
140
- "int32BufferAttribute",
141
- "uint8BufferAttribute",
142
- "uint16BufferAttribute",
143
- "uint32BufferAttribute",
144
- "instancedBufferAttribute",
145
- "color",
146
- "fog",
147
- "fogExp2",
148
- "shape",
149
- "colorShiftMaterial"
150
- ];
151
- const dreiElems = [
152
- "AsciiRenderer",
153
- "Billboard",
154
- "Clone",
155
- "ComputedAttribute",
156
- "Decal",
157
- "Edges",
158
- "Effects",
159
- "GradientTexture",
160
- "MarchingCubes",
161
- "Outlines",
162
- "PositionalAudio",
163
- "Sampler",
164
- "ScreenSizer",
165
- "ScreenSpace",
166
- "Splat",
167
- "Svg",
168
- "Text",
169
- "Text3D",
170
- "Trail",
171
- "CubeCamera",
172
- "OrthographicCamera",
173
- "PerspectiveCamera",
174
- "CameraControls",
175
- "FaceControls",
176
- "KeyboardControls",
177
- "MotionPathControls",
178
- "PresentationControls",
179
- "ScrollControls",
180
- "DragControls",
181
- "GizmoHelper",
182
- "Grid",
183
- "Helper",
184
- "PivotControls",
185
- "TransformControls",
186
- "CubeTexture",
187
- "Fbx",
188
- "Gltf",
189
- "Ktx2",
190
- "Loader",
191
- "Progress",
192
- "ScreenVideoTexture",
193
- "Texture",
194
- "TrailTexture",
195
- "VideoTexture",
196
- "WebcamVideoTexture",
197
- "CycleRaycast",
198
- "DetectGPU",
199
- "Example",
200
- "FaceLandmarker",
201
- "Fbo",
202
- "Html",
203
- "Select",
204
- "SpriteAnimator",
205
- "StatsGl",
206
- "Stats",
207
- "Trail",
208
- "Wireframe",
209
- "CurveModifier",
210
- "AdaptiveDpr",
211
- "AdaptiveEvents",
212
- "BakeShadows",
213
- "Bvh",
214
- "Detailed",
215
- "Instances",
216
- "Merged",
217
- "meshBounds",
218
- "PerformanceMonitor",
219
- "Points",
220
- "Preload",
221
- "Segments",
222
- "Fisheye",
223
- "Hud",
224
- "Mask",
225
- "MeshPortalMaterial",
226
- "RenderCubeTexture",
227
- "RenderTexture",
228
- "View",
229
- "MeshDiscardMaterial",
230
- "MeshDistortMaterial",
231
- "MeshReflectorMaterial",
232
- "MeshRefractionMaterial",
233
- "MeshTransmissionMaterial",
234
- "MeshWobbleMaterial",
235
- "PointMaterial",
236
- "shaderMaterial",
237
- "SoftShadows",
238
- "CatmullRomLine",
239
- "CubicBezierLine",
240
- "Facemesh",
241
- "Line",
242
- "Mesh",
243
- "QuadraticBezierLine",
244
- "RoundedBox",
245
- "ScreenQuad",
246
- "AccumulativeShadows",
247
- "Backdrop",
248
- "BBAnchor",
249
- "Bounds",
250
- "CameraShake",
251
- "Caustics",
252
- "Center",
253
- "Cloud",
254
- "ContactShadows",
255
- "Environment",
256
- "Float",
257
- "Lightformer",
258
- "MatcapTexture",
259
- "NormalTexture",
260
- "RandomizedLight",
261
- "Resize",
262
- "ShadowAlpha",
263
- "Shadow",
264
- "Sky",
265
- "Sparkles",
266
- "SpotLightShadow",
267
- "SpotLight",
268
- "Stage",
269
- "Stars",
270
- "OrbitControls"
271
- ];
272
- const shouldTag = (name) => !threeFiberElems.includes(name) && !dreiElems.includes(name);
273
- // ➕ Collect aliases of the Next.js <Image> component so we can reliably tag it even if it was renamed.
274
- const isNextImageAlias = (aliases, name) => aliases.has(name);
275
- const extractLiteralValue = (node) => {
276
- if (!node)
277
- return undefined;
278
- switch (node.type) {
279
- case 'StringLiteral':
280
- return node.value;
281
- case 'NumericLiteral':
282
- return node.value;
283
- case 'BooleanLiteral':
284
- return node.value;
285
- case 'ObjectExpression':
286
- const obj = {};
287
- for (const prop of node.properties) {
288
- if (prop.type === 'ObjectProperty' && !prop.computed) {
289
- const key = prop.key.type === 'Identifier' ? prop.key.name : prop.key.value;
290
- obj[key] = extractLiteralValue(prop.value);
291
- }
292
- }
293
- return obj;
294
- case 'ArrayExpression':
295
- return node.elements.map((el) => extractLiteralValue(el));
296
- default:
297
- return undefined;
298
- }
299
- };
300
- const findVariableDeclarations = (ast) => {
301
- const variables = new Map();
302
- (0, estree_walker_1.walk)(ast, {
303
- enter(node) {
304
- var _a;
305
- // Handle const/let/var declarations
306
- if (node.type === 'VariableDeclaration') {
307
- for (const declarator of node.declarations) {
308
- if (declarator.id.type === 'Identifier' && declarator.init) {
309
- const varName = declarator.id.name;
310
- const value = extractLiteralValue(declarator.init);
311
- variables.set(varName, {
312
- name: varName,
313
- type: Array.isArray(value) ? 'array' : typeof value === 'object' ? 'object' : 'primitive',
314
- value,
315
- arrayItems: Array.isArray(value) ? value : undefined,
316
- loc: (_a = declarator.loc) === null || _a === void 0 ? void 0 : _a.start
317
- });
318
- }
319
- }
320
- }
321
- }
322
- });
323
- return variables;
324
- };
325
- const findMapContext = (node, variables) => {
326
- var _a, _b, _c, _d, _e, _f, _g;
327
- // Walk up the tree to find if this JSX element is inside a map call
328
- let current = node;
329
- let depth = 0;
330
- const maxDepth = 10; // Prevent infinite loops
331
- while (current && depth < maxDepth) {
332
- if (current.type === 'CallExpression' &&
333
- ((_a = current.callee) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' &&
334
- ((_c = (_b = current.callee) === null || _b === void 0 ? void 0 : _b.property) === null || _c === void 0 ? void 0 : _c.name) === 'map') {
335
- // Found a .map() call, check if it's on a known array
336
- const arrayName = (_d = current.callee.object) === null || _d === void 0 ? void 0 : _d.name;
337
- const mapCallback = (_e = current.arguments) === null || _e === void 0 ? void 0 : _e[0];
338
- if (arrayName && (mapCallback === null || mapCallback === void 0 ? void 0 : mapCallback.type) === 'ArrowFunctionExpression') {
339
- const itemParam = (_f = mapCallback.params) === null || _f === void 0 ? void 0 : _f[0];
340
- const indexParam = (_g = mapCallback.params) === null || _g === void 0 ? void 0 : _g[1];
341
- if ((itemParam === null || itemParam === void 0 ? void 0 : itemParam.type) === 'Identifier') {
342
- const varInfo = variables.get(arrayName);
343
- return {
344
- arrayName,
345
- itemVarName: itemParam.name,
346
- arrayItems: varInfo === null || varInfo === void 0 ? void 0 : varInfo.arrayItems,
347
- arrayLoc: varInfo === null || varInfo === void 0 ? void 0 : varInfo.loc,
348
- indexVarName: (indexParam === null || indexParam === void 0 ? void 0 : indexParam.type) === 'Identifier' ? indexParam.name : undefined
349
- };
350
- }
351
- }
352
- }
353
- current = current.parent;
354
- depth++;
355
- }
356
- return null;
357
- };
358
- const getSemanticName = (node, mapContext, imageAliases) => {
359
- const getName = () => {
360
- if (node.name.type === 'JSXIdentifier')
361
- return node.name.name;
362
- if (node.name.type === 'JSXMemberExpression')
363
- return `${node.name.object.name}.${node.name.property.name}`;
364
- return null;
365
- };
366
- const tagName = getName();
367
- if (!tagName)
368
- return null;
369
- // For Next.js Image components, always return 'img' so the name is a valid HTML tag.
370
- if (isNextImageAlias(imageAliases, tagName)) {
371
- return 'img';
372
- }
373
- return isNextImageAlias(imageAliases, tagName) ? 'img' : tagName;
374
- };
375
- /* ───────────────────────────────────────────── Loader */
376
- function componentTagger(src, map) {
377
- const done = this.async();
378
- try {
379
- if (/node_modules/.test(this.resourcePath))
380
- return done(null, src, map);
381
- const ast = (0, parser_1.parse)(src, {
382
- sourceType: 'module',
383
- plugins: ['jsx', 'typescript'],
384
- });
385
- const ms = new magic_string_1.default(src);
386
- const rel = path.relative(process.cwd(), this.resourcePath);
387
- let mutated = false;
388
- // Add parent references to AST nodes for upward traversal (non-enumerable to avoid infinite recursion)
389
- (0, estree_walker_1.walk)(ast, {
390
- enter(node, parent) {
391
- if (parent && !Object.prototype.hasOwnProperty.call(node, 'parent')) {
392
- Object.defineProperty(node, 'parent', { value: parent, enumerable: false });
393
- }
394
- }
395
- });
396
- // 0️⃣ Collect variable declarations first
397
- const variables = findVariableDeclarations(ast);
398
- // 1️⃣ Gather local identifiers that reference `next/image`.
399
- const imageAliases = new Set();
400
- (0, estree_walker_1.walk)(ast, {
401
- enter(node) {
402
- if (node.type === 'ImportDeclaration' &&
403
- node.source.value === 'next/image') {
404
- for (const spec of node.specifiers) {
405
- imageAliases.add(spec.local.name);
406
- }
407
- }
408
- },
409
- });
410
- // 2️⃣ Inject attributes with enhanced semantic context.
411
- (0, estree_walker_1.walk)(ast, {
412
- enter(node) {
413
- var _a;
414
- if (node.type !== 'JSXOpeningElement')
415
- return;
416
- const mapContext = findMapContext(node, variables);
417
- const semanticName = getSemanticName(node, mapContext, imageAliases);
418
- if (!semanticName ||
419
- ['Fragment', 'React.Fragment'].includes(semanticName) ||
420
- (!isNextImageAlias(imageAliases, semanticName.split('-')[0]) &&
421
- !shouldTag(semanticName)))
422
- return;
423
- const { line, column } = node.loc.start;
424
- let orchidsId = `${rel}:${line}:${column}`;
425
- // Enhance the ID with context if we have map information
426
- if (mapContext) {
427
- orchidsId += `@${mapContext.arrayName}`;
428
- }
429
- // 🔍 Append referenced variable locations for simple identifier references in props
430
- (_a = node.attributes) === null || _a === void 0 ? void 0 : _a.forEach((attr) => {
431
- var _a, _b;
432
- if (attr.type === 'JSXAttribute' &&
433
- ((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer' &&
434
- ((_b = attr.value.expression) === null || _b === void 0 ? void 0 : _b.type) === 'Identifier') {
435
- const refName = attr.value.expression.name;
436
- const varInfo = variables.get(refName);
437
- if (varInfo) {
438
- orchidsId += `@${refName}`;
439
- }
440
- }
441
- });
442
- // 📍 If inside a map context and we have an index variable, inject data-map-index
443
- if (mapContext === null || mapContext === void 0 ? void 0 : mapContext.indexVarName) {
444
- ms.appendLeft(node.name.end, ` data-map-index={${mapContext.indexVarName}}`);
445
- }
446
- ms.appendLeft(node.name.end, ` data-orchids-id="${orchidsId}" data-orchids-name="${semanticName}"`);
447
- mutated = true;
448
- },
449
- });
450
- if (!mutated)
451
- return done(null, src, map);
452
- const out = ms.toString();
453
- const outMap = ms.generateMap({ hires: true });
454
- /* Turbopack expects the sourcemap as a JSON *string*. */
455
- done(null, out, JSON.stringify(outMap));
456
- }
457
- catch (err) {
458
- done(err);
459
- }
460
- }
461
-