makelabs
Version:
Component tagging toolkit for visual editing
1 lines • 8.21 kB
JavaScript
;var e,t=Object.create,r=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty,l=(e,t,i,l)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let s of o(t))n.call(e,s)||s===i||r(e,s,{get:()=>t[s],enumerable:!(l=a(t,s))||l.enumerable});return e},s=(e,a,o)=>(o=null!=e?t(i(e)):{},l(!a&&e&&e.__esModule?o:r(o,"default",{value:e,enumerable:!0}),e)),c={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(c,{findProjectRoot:()=>findProjectRoot,shouldTagElement:()=>shouldTagElement,viteTagger:()=>S}),module.exports=(e=c,l(r({},"__esModule",{value:!0}),e));var u=s(require("path"),1),d=require("fs");function findProjectRoot(e=process.cwd()){try{let t=e,r=0;for(;t!==u.default.parse(t).root&&r<20;){if((0,d.existsSync)(u.default.join(t,"package.json")))return t;t=u.default.dirname(t),r++}return process.cwd()}catch(e){return console.error("Error finding project root:",e),process.cwd()}}var m=["object3D","audioListener","positionalAudio","mesh","batchedMesh","instancedMesh","scene","sprite","lOD","skinnedMesh","skeleton","bone","lineSegments","lineLoop","points","group","camera","perspectiveCamera","orthographicCamera","cubeCamera","arrayCamera","instancedBufferGeometry","bufferGeometry","boxBufferGeometry","circleBufferGeometry","coneBufferGeometry","cylinderBufferGeometry","dodecahedronBufferGeometry","extrudeBufferGeometry","icosahedronBufferGeometry","latheBufferGeometry","octahedronBufferGeometry","planeBufferGeometry","polyhedronBufferGeometry","ringBufferGeometry","shapeBufferGeometry","sphereBufferGeometry","tetrahedronBufferGeometry","torusBufferGeometry","torusKnotBufferGeometry","tubeBufferGeometry","wireframeGeometry","tetrahedronGeometry","octahedronGeometry","icosahedronGeometry","dodecahedronGeometry","polyhedronGeometry","tubeGeometry","torusKnotGeometry","torusGeometry","sphereGeometry","ringGeometry","planeGeometry","latheGeometry","shapeGeometry","extrudeGeometry","edgesGeometry","coneGeometry","cylinderGeometry","circleGeometry","boxGeometry","capsuleGeometry","material","shadowMaterial","spriteMaterial","rawShaderMaterial","shaderMaterial","pointsMaterial","meshPhysicalMaterial","meshStandardMaterial","meshPhongMaterial","meshToonMaterial","meshNormalMaterial","meshLambertMaterial","meshDepthMaterial","meshDistanceMaterial","meshBasicMaterial","meshMatcapMaterial","lineDashedMaterial","lineBasicMaterial","primitive","light","spotLightShadow","spotLight","pointLight","rectAreaLight","hemisphereLight","directionalLightShadow","directionalLight","ambientLight","lightShadow","ambientLightProbe","hemisphereLightProbe","lightProbe","texture","videoTexture","dataTexture","dataTexture3D","compressedTexture","cubeTexture","canvasTexture","depthTexture","raycaster","vector2","vector3","vector4","euler","matrix3","matrix4","quaternion","bufferAttribute","color","fog","fogExp2","shape"],p=["AsciiRenderer","Billboard","Clone","ComputedAttribute","Decal","Edges","Effects","GradientTexture","Image","MarchingCubes","Outlines","PositionalAudio","Sampler","ScreenSizer","ScreenSpace","Splat","Svg","Text","Text3D","Trail","CubeCamera","OrthographicCamera","PerspectiveCamera","CameraControls","FaceControls","KeyboardControls","MotionPathControls","PresentationControls","ScrollControls","DragControls","GizmoHelper","Grid","Helper","PivotControls","TransformControls","CubeTexture","Fbx","Gltf","Ktx2","Loader","Progress","ScreenVideoTexture","Texture","TrailTexture","VideoTexture","WebcamVideoTexture","CycleRaycast","DetectGPU","Example","FaceLandmarker","Fbo","Html","Select","SpriteAnimator","StatsGl","Stats","Trail","Wireframe","CurveModifier","AdaptiveDpr","AdaptiveEvents","BakeShadows","Bvh","Detailed","Instances","Merged","meshBounds","PerformanceMonitor","Points","Preload","Segments","Fisheye","Hud","Mask","MeshPortalMaterial","RenderCubeTexture","RenderTexture","View","MeshDiscardMaterial","MeshDistortMaterial","MeshReflectorMaterial","MeshRefractionMaterial","MeshTransmissionMaterial","MeshWobbleMaterial","PointMaterial","shaderMaterial","SoftShadows","CatmullRomLine","CubicBezierLine","Facemesh","Line","Mesh","QuadraticBezierLine","RoundedBox","ScreenQuad","AccumulativeShadows","Backdrop","BBAnchor","Bounds","CameraShake","Caustics","Center","Cloud","ContactShadows","Environment","Float","Lightformer","MatcapTexture","NormalTexture","RandomizedLight","Resize","ShadowAlpha","Shadow","Sky","Sparkles","SpotLightShadow","SpotLight","Stage","Stars","OrbitControls"];function shouldTagElement(e,t={}){const{excludeElements:r=["Fragment","React.Fragment"],excludeThreeFiber:a=!0,excludeDrei:o=!0,customExcludes:i=[]}=t;return!r.includes(e)&&(!i.includes(e)&&((!a||!m.includes(e))&&(!o||!p.includes(e))))}var f=require("@babel/parser"),h=s(require("esbuild"),1),y=s(require("fs/promises"),1),g=s(require("magic-string"),1),b=s(require("path"),1),x=s(require("tailwindcss/resolveConfig.js"),1),w=new Set([".jsx",".tsx"]);function S(e={}){const t={include:[".jsx",".tsx"],excludeElements:["Fragment","React.Fragment"],excludeThreeFiber:!0,excludeDrei:!0,customExcludes:[],generateTailwindConfig:!1,tailwindConfigPath:"./tailwind.config.ts",tailwindOutputPath:"./src/tailwind.config.ml.json",...e},r=findProjectRoot(),a=process.cwd(),o={totalFiles:0,processedFiles:0,totalElements:0},i=b.default.resolve(r,t.tailwindConfigPath),n=b.default.resolve(r,t.tailwindOutputPath),l=b.default.resolve(r,"./.ml.tailwind.config.js");return{name:"makelabs-visual-editor-plugin",enforce:"pre",async transform(e,r){if(!w.has(b.default.extname(r))||r.includes("node_modules"))return null;o.totalFiles++;const i=b.default.relative(a,r);try{const a={sourceType:"module",plugins:["jsx","typescript"]},n=(0,f.parse)(e,a),l=new g.default(e);let s=0,c=null;const{walk:u}=await import("estree-walker");return u(n,{enter(e){if("JSXElement"===e.type&&(c=e),"JSXOpeningElement"===e.type){const a=e;let o;if("JSXIdentifier"===a.name.type)o=a.name.name;else{if("JSXMemberExpression"!==a.name.type)return;{const e=a.name;o=`${e.object.name}.${e.property.name}`}}if(!shouldTagElement(o,t))return;const n=a.attributes.reduce((e,t)=>("JSXAttribute"===t.type&&("StringLiteral"===t.value?.type?e[t.name.name]=t.value.value:"JSXExpressionContainer"===t.value?.type&&"StringLiteral"===t.value.expression?.type&&(e[t.name.name]=t.value.expression.value)),e),{});let u="";c&&c.children&&(u=c.children.map(e=>"JSXText"===e.type?e.value.trim():"JSXExpressionContainer"===e.type&&"StringLiteral"===e.expression?.type?e.expression.value:"").filter(Boolean).join(" ").trim());const d={};u&&(d.text=u),n.placeholder&&(d.placeholder=n.placeholder),n.className&&(d.className=n.className);const m=a.loc?.start?.line??0,p=a.loc?.start?.column??0,f=`${i}:${m}:${p}`,h=b.default.basename(r),y=[`data-ml-id="${f}"`,`data-ml-name="${o}"`,[`data-component-path="${i}"`,`data-component-line="${m}"`,`data-component-file="${h}"`,`data-component-name="${o}"`,`data-component-content="${encodeURIComponent(JSON.stringify(d))}"`].join(" ")].join(" ");l.appendLeft(a.name.end??0,` ${y}`),s++}}}),o.processedFiles++,o.totalElements+=s,{code:l.toString(),map:l.generateMap({hires:!0})}}catch(e){return console.error(`MakeLabs: Error processing file ${i}:`,e),o.processedFiles++,null}},async buildStart(){if(t.generateTailwindConfig)try{await s()}catch(e){console.error("MakeLabs: Error generating tailwind config:",e)}},configureServer(e){if(t.generateTailwindConfig)try{e.watcher.add(i),e.watcher.on("change",async e=>{b.default.normalize(e)===b.default.normalize(i)&&await s()})}catch(e){console.error("MakeLabs: Error adding watcher:",e)}},buildEnd(){o.totalElements,o.processedFiles}};async function s(){try{await h.build({entryPoints:[i],outfile:l,bundle:!0,format:"esm",banner:{js:'import { createRequire } from "module"; const _0 = createRequire(import.meta.url);'}});const e=await import(l+"?update="+Date.now());if(!e||!e.default)throw new Error("Invalid Tailwind config structure");const t=(0,x.default)(e.default);await y.default.writeFile(n,JSON.stringify(t,null,2)),await y.default.unlink(l).catch(()=>{})}catch(e){throw console.error("MakeLabs: Error in generateTailwindConfig:",e),e}}}