freddyaboulton HF Staff commited on
Commit
dcdc07a
·
verified ·
1 Parent(s): 069b6da

Add manifest.json and individual component files

Browse files

Migration from monolithic components.json to manifest + individual files.

- manifest.json: 13 entries
- components/*.json: 13 files

components/audio-gallery.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "audio-gallery",
3
+ "name": "Audio Gallery",
4
+ "description": "Grid of audio players with waveform visualization and selection",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "display",
8
+ "audio",
9
+ "gallery",
10
+ "media"
11
+ ],
12
+ "category": "display",
13
+ "html_template": "<div class=\"audio-gallery-container\">\n ${label ? `<label class=\"container-label\">${label}</label>` : ''}\n <div class=\"audio-gallery-grid\" style=\"grid-template-columns: repeat(${columns}, 1fr);\">\n ${audio_urls.map((url, i) => `\n <div class=\"audio-item\" data-index=\"${i}\">\n <div class=\"audio-label\">${labels && labels[i] ? labels[i] : 'Audio ' + (i + 1)}</div>\n <canvas class=\"waveform-canvas\" data-url=\"${url}\" width=\"300\" height=\"80\"></canvas>\n <audio src=\"${url}\" preload=\"metadata\" ${value === url ? 'data-selected=\"true\"' : ''}></audio>\n <div class=\"audio-controls\">\n <button class=\"play-btn\">\u25b6</button>\n <div class=\"time-display\">0:00</div>\n </div>\n </div>\n `).join('')}\n </div>\n</div>",
14
+ "css_template": ".audio-gallery-container { padding: 8px; }\n.container-label { display: block; margin-bottom: 12px; font-weight: 600; }\n.audio-gallery-grid { display: grid; gap: 12px; }\n.audio-item { border: 2px solid #e5e7eb; border-radius: 10px; padding: 12px; cursor: pointer; transition: all 0.2s; }\n.audio-item:hover { border-color: #f97316; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }\n.audio-item[data-selected=\"true\"] { border-color: #f97316; background-color: #fff7ed; }\n.audio-label { margin-bottom: 8px; text-align: center; font-size: 13px; font-weight: 500; }\n.waveform-canvas { width: 100%; height: 80px; background: #f9fafb; border-radius: 6px; margin-bottom: 8px; }\n.audio-controls { display: flex; align-items: center; gap: 8px; }\n.play-btn { width: 32px; height: 32px; border-radius: 50%; border: none; background: #f97316; color: white; cursor: pointer; font-size: 14px; }\n.play-btn:hover { opacity: 0.8; }\n.time-display { font-size: 12px; color: #6b7280; }",
15
+ "js_on_load": "const audioItems = element.querySelectorAll('.audio-item');\naudioItems.forEach((item, index) => {\n const canvas = item.querySelector('.waveform-canvas');\n const audio = item.querySelector('audio');\n const playBtn = item.querySelector('.play-btn');\n const timeDisplay = item.querySelector('.time-display');\n const ctx = canvas.getContext('2d');\n drawWaveform(canvas, ctx);\n item.addEventListener('click', (e) => {\n if (e.target === playBtn) return;\n audioItems.forEach(i => i.removeAttribute('data-selected'));\n item.setAttribute('data-selected', 'true');\n props.value = audio.src;\n });\n playBtn.addEventListener('click', (e) => {\n e.stopPropagation();\n if (audio.paused) {\n element.querySelectorAll('audio').forEach(a => a.pause());\n element.querySelectorAll('.play-btn').forEach(b => b.textContent = '\u25b6');\n audio.play();\n playBtn.textContent = '\u23f8';\n } else {\n audio.pause();\n playBtn.textContent = '\u25b6';\n }\n });\n audio.addEventListener('timeupdate', () => {\n const currentTime = Math.floor(audio.currentTime);\n const minutes = Math.floor(currentTime / 60);\n const seconds = currentTime % 60;\n timeDisplay.textContent = minutes + ':' + seconds.toString().padStart(2, '0');\n const progress = audio.currentTime / audio.duration;\n drawWaveform(canvas, ctx, progress);\n });\n audio.addEventListener('ended', () => {\n playBtn.textContent = '\u25b6';\n drawWaveform(canvas, ctx, 0);\n });\n});\nfunction drawWaveform(canvas, ctx, progress) {\n progress = progress || 0;\n const width = canvas.width;\n const height = canvas.height;\n const bars = 50;\n const barWidth = width / bars;\n ctx.clearRect(0, 0, width, height);\n for (let i = 0; i < bars; i++) {\n const barHeight = (Math.sin(i * 0.5) * 0.3 + 0.5) * height * 0.8;\n const x = i * barWidth;\n const y = (height - barHeight) / 2;\n ctx.fillStyle = i / bars < progress ? '#f97316' : '#d1d5db';\n ctx.fillRect(x, y, barWidth - 2, barHeight);\n }\n}",
16
+ "default_props": {
17
+ "value": null,
18
+ "audio_urls": [
19
+ "https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav",
20
+ "https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample-1-4.wav",
21
+ "https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/audio/cantina.wav"
22
+ ],
23
+ "labels": [
24
+ "Sample 1",
25
+ "Sample 2",
26
+ "Cantina"
27
+ ],
28
+ "columns": 3,
29
+ "label": "Select an audio file"
30
+ },
31
+ "python_code": "class AudioGallery(gr.HTML):\n def __init__(self, audio_urls, *, value=None, labels=None,\n columns=3, label=None, **kwargs):\n html_template = \"\"\"\n <div class=\"audio-gallery-container\">\n ${label ? `<label>${label}</label>` : ''}\n <div class=\"audio-gallery-grid\"\n style=\"grid-template-columns: repeat(${columns}, 1fr);\">\n ${audio_urls.map((url, i) => `\n <div class=\"audio-item\" data-index=\"${i}\">\n <div class=\"audio-label\">\n ${labels && labels[i] ? labels[i] : 'Audio ' + (i+1)}\n </div>\n <canvas class=\"waveform-canvas\" width=\"300\" height=\"80\"></canvas>\n <audio src=\"${url}\" preload=\"metadata\"></audio>\n <div class=\"audio-controls\">\n <button class=\"play-btn\">\u25b6</button>\n <div class=\"time-display\">0:00</div>\n </div>\n </div>\n `).join('')}\n </div>\n </div>\n \"\"\"\n super().__init__(\n value=value, audio_urls=audio_urls,\n labels=labels, columns=columns, label=label,\n html_template=html_template,\n css_template=CSS_TEMPLATE,\n js_on_load=JS_ON_LOAD, **kwargs\n )"
32
+ }
components/button-set.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "button-set",
3
+ "name": "Button Set",
4
+ "description": "Multiple buttons that trigger events with click data",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "buttons",
9
+ "events"
10
+ ],
11
+ "category": "input",
12
+ "html_template": "<button id='A'>A</button>\n<button id='B'>B</button>\n<button id='C'>C</button>",
13
+ "css_template": "button {\n padding: 10px 20px;\n background-color: #f97316;\n color: white;\n border: none;\n border-radius: 8px;\n cursor: pointer;\n font-weight: 600;\n margin-right: 8px;\n transition: background 0.15s;\n}\nbutton:hover { background-color: #ea580c; }",
14
+ "js_on_load": "const buttons = element.querySelectorAll('button');\nbuttons.forEach(button => {\n button.addEventListener('click', () => {\n trigger('click', {clicked: button.innerText});\n });\n});",
15
+ "default_props": {},
16
+ "python_code": "button_set = gr.HTML(\n html_template=\"\"\"\n <button id='A'>A</button>\n <button id='B'>B</button>\n <button id='C'>C</button>\n \"\"\",\n css_template=\"\"\"\n button {\n padding: 10px 20px;\n background-color: #f97316;\n color: white; border: none;\n border-radius: 8px; cursor: pointer;\n }\n button:hover { background-color: #ea580c; }\n \"\"\",\n js_on_load=\"\"\"\n const buttons = element.querySelectorAll('button');\n buttons.forEach(button => {\n button.addEventListener('click', () => {\n trigger('click', {clicked: button.innerText});\n });\n });\n \"\"\"\n)\n\ndef on_button_click(evt: gr.EventData):\n return evt.clicked\n\nbutton_set.click(on_button_click, outputs=clicked_box)"
17
+ }
components/camera-control3-d.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "camera-control3-d",
3
+ "name": "Camera Control3 D",
4
+ "description": "A 3D camera control component using Three.js.",
5
+ "author": "multimodalart",
6
+ "tags": [
7
+ "3D",
8
+ "Image"
9
+ ],
10
+ "category": "Input",
11
+ "html_template": "\n <div id=\"camera-control-wrapper\" style=\"width: 100%; height: 450px; position: relative; background: #1a1a1a; border-radius: 12px; overflow: hidden;\">\n <div id=\"prompt-overlay\" style=\"position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.8); padding: 8px 16px; border-radius: 8px; font-family: monospace; font-size: 12px; color: #00ff88; white-space: nowrap; z-index: 10;\"></div>\n </div>\n ",
12
+ "css_template": "",
13
+ "js_on_load": "\n (() => {\n const wrapper = element.querySelector('#camera-control-wrapper');\n const promptOverlay = element.querySelector('#prompt-overlay');\n \n // Wait for THREE to load\n const initScene = () => {\n if (typeof THREE === 'undefined') {\n setTimeout(initScene, 100);\n return;\n }\n \n // Scene setup\n const scene = new THREE.Scene();\n scene.background = new THREE.Color(0x1a1a1a);\n \n const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);\n camera.position.set(4.5, 3, 4.5);\n camera.lookAt(0, 0.75, 0);\n \n const renderer = new THREE.WebGLRenderer({ antialias: true });\n renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);\n renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n wrapper.insertBefore(renderer.domElement, promptOverlay);\n \n // Lighting\n scene.add(new THREE.AmbientLight(0xffffff, 0.6));\n const dirLight = new THREE.DirectionalLight(0xffffff, 0.6);\n dirLight.position.set(5, 10, 5);\n scene.add(dirLight);\n \n // Grid\n scene.add(new THREE.GridHelper(8, 16, 0x333333, 0x222222));\n \n // Constants - reduced distances for tighter framing\n const CENTER = new THREE.Vector3(0, 0.75, 0);\n const BASE_DISTANCE = 1.6;\n const AZIMUTH_RADIUS = 2.4;\n const ELEVATION_RADIUS = 1.8;\n \n // State\n let azimuthAngle = props.value?.azimuth || 0;\n let elevationAngle = props.value?.elevation || 0;\n let distanceFactor = props.value?.distance || 1.0;\n \n // Mappings - reduced wide shot multiplier\n const azimuthSteps = [0, 45, 90, 135, 180, 225, 270, 315];\n const elevationSteps = [-30, 0, 30, 60];\n const distanceSteps = [0.6, 1.0, 1.4];\n \n const azimuthNames = {\n 0: 'front view', 45: 'front-right quarter view', 90: 'right side view',\n 135: 'back-right quarter view', 180: 'back view', 225: 'back-left quarter view',\n 270: 'left side view', 315: 'front-left quarter view'\n };\n const elevationNames = { '-30': 'low-angle shot', '0': 'eye-level shot', '30': 'elevated shot', '60': 'high-angle shot' };\n const distanceNames = { '0.6': 'close-up', '1': 'medium shot', '1.4': 'wide shot' };\n \n function snapToNearest(value, steps) {\n return steps.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev);\n }\n \n // Create placeholder texture (smiley face)\n function createPlaceholderTexture() {\n const canvas = document.createElement('canvas');\n canvas.width = 256;\n canvas.height = 256;\n const ctx = canvas.getContext('2d');\n ctx.fillStyle = '#3a3a4a';\n ctx.fillRect(0, 0, 256, 256);\n ctx.fillStyle = '#ffcc99';\n ctx.beginPath();\n ctx.arc(128, 128, 80, 0, Math.PI * 2);\n ctx.fill();\n ctx.fillStyle = '#333';\n ctx.beginPath();\n ctx.arc(100, 110, 10, 0, Math.PI * 2);\n ctx.arc(156, 110, 10, 0, Math.PI * 2);\n ctx.fill();\n ctx.strokeStyle = '#333';\n ctx.lineWidth = 3;\n ctx.beginPath();\n ctx.arc(128, 130, 35, 0.2, Math.PI - 0.2);\n ctx.stroke();\n return new THREE.CanvasTexture(canvas);\n }\n \n // Target image plane\n let currentTexture = createPlaceholderTexture();\n const planeMaterial = new THREE.MeshBasicMaterial({ map: currentTexture, side: THREE.DoubleSide });\n let targetPlane = new THREE.Mesh(new THREE.PlaneGeometry(1.2, 1.2), planeMaterial);\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n \n // Function to update texture from image URL\n function updateTextureFromUrl(url) {\n if (!url) {\n // Reset to placeholder\n planeMaterial.map = createPlaceholderTexture();\n planeMaterial.needsUpdate = true;\n // Reset plane to square\n scene.remove(targetPlane);\n targetPlane = new THREE.Mesh(new THREE.PlaneGeometry(1.2, 1.2), planeMaterial);\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n return;\n }\n \n const loader = new THREE.TextureLoader();\n loader.crossOrigin = 'anonymous';\n loader.load(url, (texture) => {\n texture.minFilter = THREE.LinearFilter;\n texture.magFilter = THREE.LinearFilter;\n planeMaterial.map = texture;\n planeMaterial.needsUpdate = true;\n \n // Adjust plane aspect ratio to match image\n const img = texture.image;\n if (img && img.width && img.height) {\n const aspect = img.width / img.height;\n const maxSize = 1.5;\n let planeWidth, planeHeight;\n if (aspect > 1) {\n planeWidth = maxSize;\n planeHeight = maxSize / aspect;\n } else {\n planeHeight = maxSize;\n planeWidth = maxSize * aspect;\n }\n scene.remove(targetPlane);\n targetPlane = new THREE.Mesh(\n new THREE.PlaneGeometry(planeWidth, planeHeight),\n planeMaterial\n );\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n }\n }, undefined, (err) => {\n console.error('Failed to load texture:', err);\n });\n }\n \n // Check for initial imageUrl\n if (props.imageUrl) {\n updateTextureFromUrl(props.imageUrl);\n }\n \n // Camera model\n const cameraGroup = new THREE.Group();\n const bodyMat = new THREE.MeshStandardMaterial({ color: 0x6699cc, metalness: 0.5, roughness: 0.3 });\n const body = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.22, 0.38), bodyMat);\n cameraGroup.add(body);\n const lens = new THREE.Mesh(\n new THREE.CylinderGeometry(0.09, 0.11, 0.18, 16),\n new THREE.MeshStandardMaterial({ color: 0x6699cc, metalness: 0.5, roughness: 0.3 })\n );\n lens.rotation.x = Math.PI / 2;\n lens.position.z = 0.26;\n cameraGroup.add(lens);\n scene.add(cameraGroup);\n \n // GREEN: Azimuth ring\n const azimuthRing = new THREE.Mesh(\n new THREE.TorusGeometry(AZIMUTH_RADIUS, 0.04, 16, 64),\n new THREE.MeshStandardMaterial({ color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 0.3 })\n );\n azimuthRing.rotation.x = Math.PI / 2;\n azimuthRing.position.y = 0.05;\n scene.add(azimuthRing);\n \n const azimuthHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 0.5 })\n );\n azimuthHandle.userData.type = 'azimuth';\n scene.add(azimuthHandle);\n \n // PINK: Elevation arc\n const arcPoints = [];\n for (let i = 0; i <= 32; i++) {\n const angle = THREE.MathUtils.degToRad(-30 + (90 * i / 32));\n arcPoints.push(new THREE.Vector3(-0.8, ELEVATION_RADIUS * Math.sin(angle) + CENTER.y, ELEVATION_RADIUS * Math.cos(angle)));\n }\n const arcCurve = new THREE.CatmullRomCurve3(arcPoints);\n const elevationArc = new THREE.Mesh(\n new THREE.TubeGeometry(arcCurve, 32, 0.04, 8, false),\n new THREE.MeshStandardMaterial({ color: 0xff69b4, emissive: 0xff69b4, emissiveIntensity: 0.3 })\n );\n scene.add(elevationArc);\n \n const elevationHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0xff69b4, emissive: 0xff69b4, emissiveIntensity: 0.5 })\n );\n elevationHandle.userData.type = 'elevation';\n scene.add(elevationHandle);\n \n // ORANGE: Distance line & handle\n const distanceLineGeo = new THREE.BufferGeometry();\n const distanceLine = new THREE.Line(distanceLineGeo, new THREE.LineBasicMaterial({ color: 0xffa500 }));\n scene.add(distanceLine);\n \n const distanceHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0xffa500, emissive: 0xffa500, emissiveIntensity: 0.5 })\n );\n distanceHandle.userData.type = 'distance';\n scene.add(distanceHandle);\n \n function updatePositions() {\n const distance = BASE_DISTANCE * distanceFactor;\n const azRad = THREE.MathUtils.degToRad(azimuthAngle);\n const elRad = THREE.MathUtils.degToRad(elevationAngle);\n \n const camX = distance * Math.sin(azRad) * Math.cos(elRad);\n const camY = distance * Math.sin(elRad) + CENTER.y;\n const camZ = distance * Math.cos(azRad) * Math.cos(elRad);\n \n cameraGroup.position.set(camX, camY, camZ);\n cameraGroup.lookAt(CENTER);\n \n azimuthHandle.position.set(AZIMUTH_RADIUS * Math.sin(azRad), 0.05, AZIMUTH_RADIUS * Math.cos(azRad));\n elevationHandle.position.set(-0.8, ELEVATION_RADIUS * Math.sin(elRad) + CENTER.y, ELEVATION_RADIUS * Math.cos(elRad));\n \n const orangeDist = distance - 0.5;\n distanceHandle.position.set(\n orangeDist * Math.sin(azRad) * Math.cos(elRad),\n orangeDist * Math.sin(elRad) + CENTER.y,\n orangeDist * Math.cos(azRad) * Math.cos(elRad)\n );\n distanceLineGeo.setFromPoints([cameraGroup.position.clone(), CENTER.clone()]);\n \n // Update prompt\n const azSnap = snapToNearest(azimuthAngle, azimuthSteps);\n const elSnap = snapToNearest(elevationAngle, elevationSteps);\n const distSnap = snapToNearest(distanceFactor, distanceSteps);\n const distKey = distSnap === 1 ? '1' : distSnap.toFixed(1);\n const prompt = '<sks> ' + azimuthNames[azSnap] + ' ' + elevationNames[String(elSnap)] + ' ' + distanceNames[distKey];\n promptOverlay.textContent = prompt;\n }\n \n function updatePropsAndTrigger() {\n const azSnap = snapToNearest(azimuthAngle, azimuthSteps);\n const elSnap = snapToNearest(elevationAngle, elevationSteps);\n const distSnap = snapToNearest(distanceFactor, distanceSteps);\n \n props.value = { azimuth: azSnap, elevation: elSnap, distance: distSnap };\n trigger('change', props.value);\n }\n \n // Raycasting\n const raycaster = new THREE.Raycaster();\n const mouse = new THREE.Vector2();\n let isDragging = false;\n let dragTarget = null;\n let dragStartMouse = new THREE.Vector2();\n let dragStartDistance = 1.0;\n const intersection = new THREE.Vector3();\n \n const canvas = renderer.domElement;\n \n canvas.addEventListener('mousedown', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;\n \n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n \n if (intersects.length > 0) {\n isDragging = true;\n dragTarget = intersects[0].object;\n dragTarget.material.emissiveIntensity = 1.0;\n dragTarget.scale.setScalar(1.3);\n dragStartMouse.copy(mouse);\n dragStartDistance = distanceFactor;\n canvas.style.cursor = 'grabbing';\n }\n });\n \n canvas.addEventListener('mousemove', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;\n \n if (isDragging && dragTarget) {\n raycaster.setFromCamera(mouse, camera);\n \n if (dragTarget.userData.type === 'azimuth') {\n const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.05);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n azimuthAngle = THREE.MathUtils.radToDeg(Math.atan2(intersection.x, intersection.z));\n if (azimuthAngle < 0) azimuthAngle += 360;\n }\n } else if (dragTarget.userData.type === 'elevation') {\n const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), -0.8);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n const relY = intersection.y - CENTER.y;\n const relZ = intersection.z;\n elevationAngle = THREE.MathUtils.clamp(THREE.MathUtils.radToDeg(Math.atan2(relY, relZ)), -30, 60);\n }\n } else if (dragTarget.userData.type === 'distance') {\n const deltaY = mouse.y - dragStartMouse.y;\n distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.4);\n }\n updatePositions();\n } else {\n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n [azimuthHandle, elevationHandle, distanceHandle].forEach(h => {\n h.material.emissiveIntensity = 0.5;\n h.scale.setScalar(1);\n });\n if (intersects.length > 0) {\n intersects[0].object.material.emissiveIntensity = 0.8;\n intersects[0].object.scale.setScalar(1.1);\n canvas.style.cursor = 'grab';\n } else {\n canvas.style.cursor = 'default';\n }\n }\n });\n \n const onMouseUp = () => {\n if (dragTarget) {\n dragTarget.material.emissiveIntensity = 0.5;\n dragTarget.scale.setScalar(1);\n \n // Snap and animate\n const targetAz = snapToNearest(azimuthAngle, azimuthSteps);\n const targetEl = snapToNearest(elevationAngle, elevationSteps);\n const targetDist = snapToNearest(distanceFactor, distanceSteps);\n \n const startAz = azimuthAngle, startEl = elevationAngle, startDist = distanceFactor;\n const startTime = Date.now();\n \n function animateSnap() {\n const t = Math.min((Date.now() - startTime) / 200, 1);\n const ease = 1 - Math.pow(1 - t, 3);\n \n let azDiff = targetAz - startAz;\n if (azDiff > 180) azDiff -= 360;\n if (azDiff < -180) azDiff += 360;\n azimuthAngle = startAz + azDiff * ease;\n if (azimuthAngle < 0) azimuthAngle += 360;\n if (azimuthAngle >= 360) azimuthAngle -= 360;\n \n elevationAngle = startEl + (targetEl - startEl) * ease;\n distanceFactor = startDist + (targetDist - startDist) * ease;\n \n updatePositions();\n if (t < 1) requestAnimationFrame(animateSnap);\n else updatePropsAndTrigger();\n }\n animateSnap();\n }\n isDragging = false;\n dragTarget = null;\n canvas.style.cursor = 'default';\n };\n \n canvas.addEventListener('mouseup', onMouseUp);\n canvas.addEventListener('mouseleave', onMouseUp);\n // Touch support for mobile\n canvas.addEventListener('touchstart', (e) => {\n e.preventDefault();\n const touch = e.touches[0];\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((touch.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((touch.clientY - rect.top) / rect.height) * 2 + 1;\n \n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n \n if (intersects.length > 0) {\n isDragging = true;\n dragTarget = intersects[0].object;\n dragTarget.material.emissiveIntensity = 1.0;\n dragTarget.scale.setScalar(1.3);\n dragStartMouse.copy(mouse);\n dragStartDistance = distanceFactor;\n }\n }, { passive: false });\n \n canvas.addEventListener('touchmove', (e) => {\n e.preventDefault();\n const touch = e.touches[0];\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((touch.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((touch.clientY - rect.top) / rect.height) * 2 + 1;\n \n if (isDragging && dragTarget) {\n raycaster.setFromCamera(mouse, camera);\n \n if (dragTarget.userData.type === 'azimuth') {\n const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.05);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n azimuthAngle = THREE.MathUtils.radToDeg(Math.atan2(intersection.x, intersection.z));\n if (azimuthAngle < 0) azimuthAngle += 360;\n }\n } else if (dragTarget.userData.type === 'elevation') {\n const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), -0.8);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n const relY = intersection.y - CENTER.y;\n const relZ = intersection.z;\n elevationAngle = THREE.MathUtils.clamp(THREE.MathUtils.radToDeg(Math.atan2(relY, relZ)), -30, 60);\n }\n } else if (dragTarget.userData.type === 'distance') {\n const deltaY = mouse.y - dragStartMouse.y;\n distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.4);\n }\n updatePositions();\n }\n }, { passive: false });\n \n canvas.addEventListener('touchend', (e) => {\n e.preventDefault();\n onMouseUp();\n }, { passive: false });\n \n canvas.addEventListener('touchcancel', (e) => {\n e.preventDefault();\n onMouseUp();\n }, { passive: false });\n \n // Initial update\n updatePositions();\n \n // Render loop\n function render() {\n requestAnimationFrame(render);\n renderer.render(scene, camera);\n }\n render();\n \n // Handle resize\n new ResizeObserver(() => {\n camera.aspect = wrapper.clientWidth / wrapper.clientHeight;\n camera.updateProjectionMatrix();\n renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);\n }).observe(wrapper);\n \n // Store update functions for external calls\n wrapper._updateFromProps = (newVal) => {\n if (newVal && typeof newVal === 'object') {\n azimuthAngle = newVal.azimuth ?? azimuthAngle;\n elevationAngle = newVal.elevation ?? elevationAngle;\n distanceFactor = newVal.distance ?? distanceFactor;\n updatePositions();\n }\n };\n \n wrapper._updateTexture = updateTextureFromUrl;\n \n // Watch for prop changes (imageUrl and value)\n let lastImageUrl = props.imageUrl;\n let lastValue = JSON.stringify(props.value);\n setInterval(() => {\n // Check imageUrl changes\n if (props.imageUrl !== lastImageUrl) {\n lastImageUrl = props.imageUrl;\n updateTextureFromUrl(props.imageUrl);\n }\n // Check value changes (from sliders)\n const currentValue = JSON.stringify(props.value);\n if (currentValue !== lastValue) {\n lastValue = currentValue;\n if (props.value && typeof props.value === 'object') {\n azimuthAngle = props.value.azimuth ?? azimuthAngle;\n elevationAngle = props.value.elevation ?? elevationAngle;\n distanceFactor = props.value.distance ?? distanceFactor;\n updatePositions();\n }\n }\n }, 100);\n };\n \n initScene();\n })();\n ",
14
+ "default_props": {
15
+ "value": {
16
+ "azimuth": 0,
17
+ "elevation": 0,
18
+ "distance": 1.0
19
+ },
20
+ "imageUrl": null
21
+ },
22
+ "head": "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js\"></script>",
23
+ "python_code": "class CameraControl3D(gr.HTML):\n \"\"\"\n A 3D camera control component using Three.js.\n Outputs: { azimuth: number, elevation: number, distance: number }\n Accepts imageUrl prop to display user's uploaded image on the plane.\n \"\"\"\n def __init__(self, value=None, imageUrl=None, **kwargs):\n if value is None:\n value = {\"azimuth\": 0, \"elevation\": 0, \"distance\": 1.0}\n\n html_template = \"\"\"\n <div id=\"camera-control-wrapper\" style=\"width: 100%; height: 450px; position: relative; background: #1a1a1a; border-radius: 12px; overflow: hidden;\">\n <div id=\"prompt-overlay\" style=\"position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.8); padding: 8px 16px; border-radius: 8px; font-family: monospace; font-size: 12px; color: #00ff88; white-space: nowrap; z-index: 10;\"></div>\n </div>\n \"\"\"\n\n js_on_load = \"\"\"\n (() => {\n const wrapper = element.querySelector('#camera-control-wrapper');\n const promptOverlay = element.querySelector('#prompt-overlay');\n\n // Wait for THREE to load\n const initScene = () => {\n if (typeof THREE === 'undefined') {\n setTimeout(initScene, 100);\n return;\n }\n\n // Scene setup\n const scene = new THREE.Scene();\n scene.background = new THREE.Color(0x1a1a1a);\n\n const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);\n camera.position.set(4.5, 3, 4.5);\n camera.lookAt(0, 0.75, 0);\n\n const renderer = new THREE.WebGLRenderer({ antialias: true });\n renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);\n renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n wrapper.insertBefore(renderer.domElement, promptOverlay);\n\n // Lighting\n scene.add(new THREE.AmbientLight(0xffffff, 0.6));\n const dirLight = new THREE.DirectionalLight(0xffffff, 0.6);\n dirLight.position.set(5, 10, 5);\n scene.add(dirLight);\n\n // Grid\n scene.add(new THREE.GridHelper(8, 16, 0x333333, 0x222222));\n\n // Constants - reduced distances for tighter framing\n const CENTER = new THREE.Vector3(0, 0.75, 0);\n const BASE_DISTANCE = 1.6;\n const AZIMUTH_RADIUS = 2.4;\n const ELEVATION_RADIUS = 1.8;\n\n // State\n let azimuthAngle = props.value?.azimuth || 0;\n let elevationAngle = props.value?.elevation || 0;\n let distanceFactor = props.value?.distance || 1.0;\n\n // Mappings - reduced wide shot multiplier\n const azimuthSteps = [0, 45, 90, 135, 180, 225, 270, 315];\n const elevationSteps = [-30, 0, 30, 60];\n const distanceSteps = [0.6, 1.0, 1.4];\n\n const azimuthNames = {\n 0: 'front view', 45: 'front-right quarter view', 90: 'right side view',\n 135: 'back-right quarter view', 180: 'back view', 225: 'back-left quarter view',\n 270: 'left side view', 315: 'front-left quarter view'\n };\n const elevationNames = { '-30': 'low-angle shot', '0': 'eye-level shot', '30': 'elevated shot', '60': 'high-angle shot' };\n const distanceNames = { '0.6': 'close-up', '1': 'medium shot', '1.4': 'wide shot' };\n\n function snapToNearest(value, steps) {\n return steps.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev);\n }\n\n // Create placeholder texture (smiley face)\n function createPlaceholderTexture() {\n const canvas = document.createElement('canvas');\n canvas.width = 256;\n canvas.height = 256;\n const ctx = canvas.getContext('2d');\n ctx.fillStyle = '#3a3a4a';\n ctx.fillRect(0, 0, 256, 256);\n ctx.fillStyle = '#ffcc99';\n ctx.beginPath();\n ctx.arc(128, 128, 80, 0, Math.PI * 2);\n ctx.fill();\n ctx.fillStyle = '#333';\n ctx.beginPath();\n ctx.arc(100, 110, 10, 0, Math.PI * 2);\n ctx.arc(156, 110, 10, 0, Math.PI * 2);\n ctx.fill();\n ctx.strokeStyle = '#333';\n ctx.lineWidth = 3;\n ctx.beginPath();\n ctx.arc(128, 130, 35, 0.2, Math.PI - 0.2);\n ctx.stroke();\n return new THREE.CanvasTexture(canvas);\n }\n\n // Target image plane\n let currentTexture = createPlaceholderTexture();\n const planeMaterial = new THREE.MeshBasicMaterial({ map: currentTexture, side: THREE.DoubleSide });\n let targetPlane = new THREE.Mesh(new THREE.PlaneGeometry(1.2, 1.2), planeMaterial);\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n\n // Function to update texture from image URL\n function updateTextureFromUrl(url) {\n if (!url) {\n // Reset to placeholder\n planeMaterial.map = createPlaceholderTexture();\n planeMaterial.needsUpdate = true;\n // Reset plane to square\n scene.remove(targetPlane);\n targetPlane = new THREE.Mesh(new THREE.PlaneGeometry(1.2, 1.2), planeMaterial);\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n return;\n }\n\n const loader = new THREE.TextureLoader();\n loader.crossOrigin = 'anonymous';\n loader.load(url, (texture) => {\n texture.minFilter = THREE.LinearFilter;\n texture.magFilter = THREE.LinearFilter;\n planeMaterial.map = texture;\n planeMaterial.needsUpdate = true;\n\n // Adjust plane aspect ratio to match image\n const img = texture.image;\n if (img && img.width && img.height) {\n const aspect = img.width / img.height;\n const maxSize = 1.5;\n let planeWidth, planeHeight;\n if (aspect > 1) {\n planeWidth = maxSize;\n planeHeight = maxSize / aspect;\n } else {\n planeHeight = maxSize;\n planeWidth = maxSize * aspect;\n }\n scene.remove(targetPlane);\n targetPlane = new THREE.Mesh(\n new THREE.PlaneGeometry(planeWidth, planeHeight),\n planeMaterial\n );\n targetPlane.position.copy(CENTER);\n scene.add(targetPlane);\n }\n }, undefined, (err) => {\n console.error('Failed to load texture:', err);\n });\n }\n\n // Check for initial imageUrl\n if (props.imageUrl) {\n updateTextureFromUrl(props.imageUrl);\n }\n\n // Camera model\n const cameraGroup = new THREE.Group();\n const bodyMat = new THREE.MeshStandardMaterial({ color: 0x6699cc, metalness: 0.5, roughness: 0.3 });\n const body = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.22, 0.38), bodyMat);\n cameraGroup.add(body);\n const lens = new THREE.Mesh(\n new THREE.CylinderGeometry(0.09, 0.11, 0.18, 16),\n new THREE.MeshStandardMaterial({ color: 0x6699cc, metalness: 0.5, roughness: 0.3 })\n );\n lens.rotation.x = Math.PI / 2;\n lens.position.z = 0.26;\n cameraGroup.add(lens);\n scene.add(cameraGroup);\n\n // GREEN: Azimuth ring\n const azimuthRing = new THREE.Mesh(\n new THREE.TorusGeometry(AZIMUTH_RADIUS, 0.04, 16, 64),\n new THREE.MeshStandardMaterial({ color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 0.3 })\n );\n azimuthRing.rotation.x = Math.PI / 2;\n azimuthRing.position.y = 0.05;\n scene.add(azimuthRing);\n\n const azimuthHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0x00ff88, emissive: 0x00ff88, emissiveIntensity: 0.5 })\n );\n azimuthHandle.userData.type = 'azimuth';\n scene.add(azimuthHandle);\n\n // PINK: Elevation arc\n const arcPoints = [];\n for (let i = 0; i <= 32; i++) {\n const angle = THREE.MathUtils.degToRad(-30 + (90 * i / 32));\n arcPoints.push(new THREE.Vector3(-0.8, ELEVATION_RADIUS * Math.sin(angle) + CENTER.y, ELEVATION_RADIUS * Math.cos(angle)));\n }\n const arcCurve = new THREE.CatmullRomCurve3(arcPoints);\n const elevationArc = new THREE.Mesh(\n new THREE.TubeGeometry(arcCurve, 32, 0.04, 8, false),\n new THREE.MeshStandardMaterial({ color: 0xff69b4, emissive: 0xff69b4, emissiveIntensity: 0.3 })\n );\n scene.add(elevationArc);\n\n const elevationHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0xff69b4, emissive: 0xff69b4, emissiveIntensity: 0.5 })\n );\n elevationHandle.userData.type = 'elevation';\n scene.add(elevationHandle);\n\n // ORANGE: Distance line & handle\n const distanceLineGeo = new THREE.BufferGeometry();\n const distanceLine = new THREE.Line(distanceLineGeo, new THREE.LineBasicMaterial({ color: 0xffa500 }));\n scene.add(distanceLine);\n\n const distanceHandle = new THREE.Mesh(\n new THREE.SphereGeometry(0.18, 16, 16),\n new THREE.MeshStandardMaterial({ color: 0xffa500, emissive: 0xffa500, emissiveIntensity: 0.5 })\n );\n distanceHandle.userData.type = 'distance';\n scene.add(distanceHandle);\n\n function updatePositions() {\n const distance = BASE_DISTANCE * distanceFactor;\n const azRad = THREE.MathUtils.degToRad(azimuthAngle);\n const elRad = THREE.MathUtils.degToRad(elevationAngle);\n\n const camX = distance * Math.sin(azRad) * Math.cos(elRad);\n const camY = distance * Math.sin(elRad) + CENTER.y;\n const camZ = distance * Math.cos(azRad) * Math.cos(elRad);\n\n cameraGroup.position.set(camX, camY, camZ);\n cameraGroup.lookAt(CENTER);\n\n azimuthHandle.position.set(AZIMUTH_RADIUS * Math.sin(azRad), 0.05, AZIMUTH_RADIUS * Math.cos(azRad));\n elevationHandle.position.set(-0.8, ELEVATION_RADIUS * Math.sin(elRad) + CENTER.y, ELEVATION_RADIUS * Math.cos(elRad));\n\n const orangeDist = distance - 0.5;\n distanceHandle.position.set(\n orangeDist * Math.sin(azRad) * Math.cos(elRad),\n orangeDist * Math.sin(elRad) + CENTER.y,\n orangeDist * Math.cos(azRad) * Math.cos(elRad)\n );\n distanceLineGeo.setFromPoints([cameraGroup.position.clone(), CENTER.clone()]);\n\n // Update prompt\n const azSnap = snapToNearest(azimuthAngle, azimuthSteps);\n const elSnap = snapToNearest(elevationAngle, elevationSteps);\n const distSnap = snapToNearest(distanceFactor, distanceSteps);\n const distKey = distSnap === 1 ? '1' : distSnap.toFixed(1);\n const prompt = '<sks> ' + azimuthNames[azSnap] + ' ' + elevationNames[String(elSnap)] + ' ' + distanceNames[distKey];\n promptOverlay.textContent = prompt;\n }\n\n function updatePropsAndTrigger() {\n const azSnap = snapToNearest(azimuthAngle, azimuthSteps);\n const elSnap = snapToNearest(elevationAngle, elevationSteps);\n const distSnap = snapToNearest(distanceFactor, distanceSteps);\n\n props.value = { azimuth: azSnap, elevation: elSnap, distance: distSnap };\n trigger('change', props.value);\n }\n\n // Raycasting\n const raycaster = new THREE.Raycaster();\n const mouse = new THREE.Vector2();\n let isDragging = false;\n let dragTarget = null;\n let dragStartMouse = new THREE.Vector2();\n let dragStartDistance = 1.0;\n const intersection = new THREE.Vector3();\n\n const canvas = renderer.domElement;\n\n canvas.addEventListener('mousedown', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;\n\n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n\n if (intersects.length > 0) {\n isDragging = true;\n dragTarget = intersects[0].object;\n dragTarget.material.emissiveIntensity = 1.0;\n dragTarget.scale.setScalar(1.3);\n dragStartMouse.copy(mouse);\n dragStartDistance = distanceFactor;\n canvas.style.cursor = 'grabbing';\n }\n });\n\n canvas.addEventListener('mousemove', (e) => {\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;\n\n if (isDragging && dragTarget) {\n raycaster.setFromCamera(mouse, camera);\n\n if (dragTarget.userData.type === 'azimuth') {\n const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.05);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n azimuthAngle = THREE.MathUtils.radToDeg(Math.atan2(intersection.x, intersection.z));\n if (azimuthAngle < 0) azimuthAngle += 360;\n }\n } else if (dragTarget.userData.type === 'elevation') {\n const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), -0.8);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n const relY = intersection.y - CENTER.y;\n const relZ = intersection.z;\n elevationAngle = THREE.MathUtils.clamp(THREE.MathUtils.radToDeg(Math.atan2(relY, relZ)), -30, 60);\n }\n } else if (dragTarget.userData.type === 'distance') {\n const deltaY = mouse.y - dragStartMouse.y;\n distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.4);\n }\n updatePositions();\n } else {\n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n [azimuthHandle, elevationHandle, distanceHandle].forEach(h => {\n h.material.emissiveIntensity = 0.5;\n h.scale.setScalar(1);\n });\n if (intersects.length > 0) {\n intersects[0].object.material.emissiveIntensity = 0.8;\n intersects[0].object.scale.setScalar(1.1);\n canvas.style.cursor = 'grab';\n } else {\n canvas.style.cursor = 'default';\n }\n }\n });\n\n const onMouseUp = () => {\n if (dragTarget) {\n dragTarget.material.emissiveIntensity = 0.5;\n dragTarget.scale.setScalar(1);\n\n // Snap and animate\n const targetAz = snapToNearest(azimuthAngle, azimuthSteps);\n const targetEl = snapToNearest(elevationAngle, elevationSteps);\n const targetDist = snapToNearest(distanceFactor, distanceSteps);\n\n const startAz = azimuthAngle, startEl = elevationAngle, startDist = distanceFactor;\n const startTime = Date.now();\n\n function animateSnap() {\n const t = Math.min((Date.now() - startTime) / 200, 1);\n const ease = 1 - Math.pow(1 - t, 3);\n\n let azDiff = targetAz - startAz;\n if (azDiff > 180) azDiff -= 360;\n if (azDiff < -180) azDiff += 360;\n azimuthAngle = startAz + azDiff * ease;\n if (azimuthAngle < 0) azimuthAngle += 360;\n if (azimuthAngle >= 360) azimuthAngle -= 360;\n\n elevationAngle = startEl + (targetEl - startEl) * ease;\n distanceFactor = startDist + (targetDist - startDist) * ease;\n\n updatePositions();\n if (t < 1) requestAnimationFrame(animateSnap);\n else updatePropsAndTrigger();\n }\n animateSnap();\n }\n isDragging = false;\n dragTarget = null;\n canvas.style.cursor = 'default';\n };\n\n canvas.addEventListener('mouseup', onMouseUp);\n canvas.addEventListener('mouseleave', onMouseUp);\n // Touch support for mobile\n canvas.addEventListener('touchstart', (e) => {\n e.preventDefault();\n const touch = e.touches[0];\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((touch.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((touch.clientY - rect.top) / rect.height) * 2 + 1;\n\n raycaster.setFromCamera(mouse, camera);\n const intersects = raycaster.intersectObjects([azimuthHandle, elevationHandle, distanceHandle]);\n\n if (intersects.length > 0) {\n isDragging = true;\n dragTarget = intersects[0].object;\n dragTarget.material.emissiveIntensity = 1.0;\n dragTarget.scale.setScalar(1.3);\n dragStartMouse.copy(mouse);\n dragStartDistance = distanceFactor;\n }\n }, { passive: false });\n\n canvas.addEventListener('touchmove', (e) => {\n e.preventDefault();\n const touch = e.touches[0];\n const rect = canvas.getBoundingClientRect();\n mouse.x = ((touch.clientX - rect.left) / rect.width) * 2 - 1;\n mouse.y = -((touch.clientY - rect.top) / rect.height) * 2 + 1;\n\n if (isDragging && dragTarget) {\n raycaster.setFromCamera(mouse, camera);\n\n if (dragTarget.userData.type === 'azimuth') {\n const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.05);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n azimuthAngle = THREE.MathUtils.radToDeg(Math.atan2(intersection.x, intersection.z));\n if (azimuthAngle < 0) azimuthAngle += 360;\n }\n } else if (dragTarget.userData.type === 'elevation') {\n const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), -0.8);\n if (raycaster.ray.intersectPlane(plane, intersection)) {\n const relY = intersection.y - CENTER.y;\n const relZ = intersection.z;\n elevationAngle = THREE.MathUtils.clamp(THREE.MathUtils.radToDeg(Math.atan2(relY, relZ)), -30, 60);\n }\n } else if (dragTarget.userData.type === 'distance') {\n const deltaY = mouse.y - dragStartMouse.y;\n distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.4);\n }\n updatePositions();\n }\n }, { passive: false });\n\n canvas.addEventListener('touchend', (e) => {\n e.preventDefault();\n onMouseUp();\n }, { passive: false });\n\n canvas.addEventListener('touchcancel', (e) => {\n e.preventDefault();\n onMouseUp();\n }, { passive: false });\n\n // Initial update\n updatePositions();\n\n // Render loop\n function render() {\n requestAnimationFrame(render);\n renderer.render(scene, camera);\n }\n render();\n\n // Handle resize\n new ResizeObserver(() => {\n camera.aspect = wrapper.clientWidth / wrapper.clientHeight;\n camera.updateProjectionMatrix();\n renderer.setSize(wrapper.clientWidth, wrapper.clientHeight);\n }).observe(wrapper);\n\n // Store update functions for external calls\n wrapper._updateFromProps = (newVal) => {\n if (newVal && typeof newVal === 'object') {\n azimuthAngle = newVal.azimuth ?? azimuthAngle;\n elevationAngle = newVal.elevation ?? elevationAngle;\n distanceFactor = newVal.distance ?? distanceFactor;\n updatePositions();\n }\n };\n\n wrapper._updateTexture = updateTextureFromUrl;\n\n // Watch for prop changes (imageUrl and value)\n let lastImageUrl = props.imageUrl;\n let lastValue = JSON.stringify(props.value);\n setInterval(() => {\n // Check imageUrl changes\n if (props.imageUrl !== lastImageUrl) {\n lastImageUrl = props.imageUrl;\n updateTextureFromUrl(props.imageUrl);\n }\n // Check value changes (from sliders)\n const currentValue = JSON.stringify(props.value);\n if (currentValue !== lastValue) {\n lastValue = currentValue;\n if (props.value && typeof props.value === 'object') {\n azimuthAngle = props.value.azimuth ?? azimuthAngle;\n elevationAngle = props.value.elevation ?? elevationAngle;\n distanceFactor = props.value.distance ?? distanceFactor;\n updatePositions();\n }\n }\n }, 100);\n };\n\n initScene();\n })();\n \"\"\"\n\n super().__init__(\n value=value,\n html_template=html_template,\n js_on_load=js_on_load,\n imageUrl=imageUrl,\n **kwargs\n )\n",
24
+ "repo_url": "https://huggingface.co/spaces/multimodalart/qwen-image-multiple-angles-3d-camera/"
25
+ }
components/colored-checkbox-group.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "colored-checkbox-group",
3
+ "name": "Colored Checkbox Group",
4
+ "description": "Multi-select checkbox group with custom colors per option",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "checkbox",
9
+ "color"
10
+ ],
11
+ "category": "input",
12
+ "html_template": "<div class=\"colored-checkbox-container\">\n ${label ? `<label class=\"container-label\">${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\" ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n</div>",
13
+ "css_template": ".colored-checkbox-container { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; }\n.container-label { display: block; margin-bottom: 12px; font-weight: 600; }\n.colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n.checkbox-label { display: flex; align-items: center; cursor: pointer; padding: 4px 0; }\n.checkbox-label input { margin-right: 8px; }\n${choices.map((choice, i) => `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`).join(' ')}",
14
+ "js_on_load": "const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\ncheckboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n});",
15
+ "default_props": {
16
+ "value": [],
17
+ "choices": [
18
+ "Apple",
19
+ "Banana",
20
+ "Cherry"
21
+ ],
22
+ "colors": [
23
+ "#dc2626",
24
+ "#eab308",
25
+ "#dc2626"
26
+ ],
27
+ "label": "Select fruits"
28
+ },
29
+ "python_code": "class ColoredCheckboxGroup(gr.HTML):\n def __init__(self, choices, *, value=None, colors, label=None, **kwargs):\n html_template = \"\"\"\n <div class=\"colored-checkbox-container\">\n ${label ? `<label>${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\"\n ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n .checkbox-label { display: flex; align-items: center; cursor: pointer; }\n ${choices.map((choice, i) =>\n `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`\n ).join(' ')}\n \"\"\"\n js_on_load = \"\"\"\n const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\n checkboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value or [], choices=choices,\n colors=colors, label=label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )"
30
+ }
components/contribution-heatmap.json ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "contribution-heatmap",
3
+ "name": "Contribution Heatmap",
4
+ "description": "Reusable GitHub-style contribution heatmap",
5
+ "author": "ysharma",
6
+ "tags": [
7
+ "Business"
8
+ ],
9
+ "category": "Display",
10
+ "html_template": "\n<div class=\"heatmap-container\">\n <div class=\"heatmap-header\">\n <h2>${(() => {\n const total = Object.values(value || {}).reduce((a, b) => a + b, 0);\n return '\ud83d\udcca ' + total.toLocaleString() + ' contributions in ' + year;\n })()}</h2>\n <div class=\"legend\">\n <span>Less</span>\n <div class=\"legend-box\" style=\"background:${c0}\"></div>\n <div class=\"legend-box\" style=\"background:${c1}\"></div>\n <div class=\"legend-box\" style=\"background:${c2}\"></div>\n <div class=\"legend-box\" style=\"background:${c3}\"></div>\n <div class=\"legend-box\" style=\"background:${c4}\"></div>\n <span>More</span>\n </div>\n </div>\n <div class=\"month-labels\">\n ${(() => {\n const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n return months.map((m, i) =>\n '<span style=\"grid-column:' + (Math.floor(i * 4.33) + 2) + '\">' + m + '</span>'\n ).join('');\n })()}\n </div>\n <div class=\"heatmap-grid\">\n <div class=\"day-labels\">\n <span></span><span>Mon</span><span></span><span>Wed</span><span></span><span>Fri</span><span></span>\n </div>\n <div class=\"cells\">\n ${(() => {\n const v = value || {};\n const sd = new Date(year, 0, 1);\n const pad = sd.getDay();\n const cells = [];\n for (let i = 0; i < pad; i++) cells.push('<div class=\"cell empty\"></div>');\n const totalDays = Math.floor((new Date(year, 11, 31) - sd) / 86400000) + 1;\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const count = v[key] || 0;\n let lv = 0;\n if (count > 0) lv = 1;\n if (count >= 3) lv = 2;\n if (count >= 6) lv = 3;\n if (count >= 10) lv = 4;\n const mn = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n const tip = count + ' contributions on ' + mn[dt.getMonth()] + ' ' + dt.getDate() + ', ' + year;\n cells.push('<div class=\"cell level-' + lv + '\" data-date=\"' + key + '\" data-count=\"' + count + '\" title=\"' + tip + '\"></div>');\n }\n return cells.join('');\n })()}\n </div>\n </div>\n <div class=\"stats-bar\">\n ${(() => {\n const v = value || {};\n const totalDays = Math.floor((new Date(year, 11, 31) - new Date(year, 0, 1)) / 86400000) + 1;\n let streak = 0, maxStreak = 0, total = 0, active = 0, best = 0;\n const vals = [];\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const c = v[key] || 0;\n total += c;\n if (c > 0) { streak++; maxStreak = Math.max(maxStreak, streak); active++; best = Math.max(best, c); vals.push(c); }\n else { streak = 0; }\n }\n const avg = vals.length ? (total / vals.length).toFixed(1) : '0';\n const stats = [\n ['\ud83d\udd25', maxStreak, 'Longest Streak'],\n ['\ud83d\udcc5', active, 'Active Days'],\n ['\u26a1', best, 'Best Day'],\n ['\ud83d\udcc8', avg, 'Avg / Active Day'],\n ['\ud83c\udfc6', total.toLocaleString(), 'Total'],\n ];\n return stats.map(s =>\n '<div class=\"stat\"><span class=\"stat-value\">' + s[1] + '</span><span class=\"stat-label\">' + s[0] + ' ' + s[2] + '</span></div>'\n ).join('');\n })()}\n </div>\n</div>\n",
11
+ "css_template": "\n .heatmap-container {\n background: #0d1117;\n border-radius: 12px;\n padding: 24px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n color: #c9d1d9;\n overflow-x: auto;\n }\n .heatmap-header {\n display: flex; justify-content: space-between; align-items: center;\n margin-bottom: 12px; flex-wrap: wrap; gap: 10px;\n }\n .heatmap-header h2 { margin: 0; font-size: 16px; font-weight: 500; color: #f0f6fc; }\n .legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #8b949e; }\n .legend-box { width: 12px; height: 12px; border-radius: 2px; }\n .month-labels {\n display: grid; grid-template-columns: 30px repeat(53, 1fr);\n font-size: 11px; color: #8b949e; margin-bottom: 4px; padding-left: 2px;\n }\n .heatmap-grid { display: flex; gap: 4px; }\n .day-labels {\n display: grid; grid-template-rows: repeat(7, 1fr);\n font-size: 11px; color: #8b949e; width: 30px; gap: 2px;\n }\n .day-labels span { height: 13px; display: flex; align-items: center; }\n .cells {\n display: grid; grid-template-rows: repeat(7, 1fr);\n grid-auto-flow: column; gap: 2px; flex: 1;\n }\n .cell {\n width: 13px; height: 13px; border-radius: 2px; cursor: pointer;\n transition: all 0.15s ease; outline: 1px solid rgba(27,31,35,0.06);\n }\n .cell:hover {\n outline: 2px solid #58a6ff; outline-offset: -1px;\n transform: scale(1.3); z-index: 1;\n }\n .cell.empty { visibility: hidden; }\n .level-0 { background: ${c0}; }\n .level-1 { background: ${c1}; }\n .level-2 { background: ${c2}; }\n .level-3 { background: ${c3}; }\n .level-4 { background: ${c4}; }\n .stats-bar {\n display: flex; justify-content: space-around; margin-top: 20px;\n padding-top: 16px; border-top: 1px solid #21262d;\n flex-wrap: wrap; gap: 12px;\n }\n .stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }\n .stat-value { font-size: 22px; font-weight: 700; color: ${c4}; }\n .stat-label { font-size: 12px; color: #8b949e; }\n",
12
+ "js_on_load": "\n element.addEventListener('click', (e) => {\n if (e.target && e.target.classList.contains('cell') && !e.target.classList.contains('empty')) {\n const date = e.target.dataset.date;\n const cur = parseInt(e.target.dataset.count) || 0;\n const next = cur >= 12 ? 0 : cur + 1;\n const nv = {...(props.value || {})};\n if (next === 0) delete nv[date]; else nv[date] = next;\n props.value = nv;\n trigger('change');\n }\n });\n",
13
+ "default_props": {
14
+ "value": {
15
+ "2025-01-01": 15,
16
+ "2025-01-02": 10,
17
+ "2025-01-05": 2,
18
+ "2025-01-06": 2,
19
+ "2025-01-07": 3,
20
+ "2025-01-08": 7,
21
+ "2025-01-13": 1,
22
+ "2025-01-14": 3,
23
+ "2025-01-15": 1,
24
+ "2025-01-17": 1,
25
+ "2025-01-19": 5,
26
+ "2025-01-20": 4,
27
+ "2025-01-22": 1,
28
+ "2025-01-26": 2,
29
+ "2025-01-27": 11,
30
+ "2025-01-28": 1,
31
+ "2025-01-29": 2,
32
+ "2025-02-02": 2,
33
+ "2025-02-04": 8,
34
+ "2025-02-05": 2,
35
+ "2025-02-07": 2,
36
+ "2025-02-09": 7,
37
+ "2025-02-10": 2,
38
+ "2025-02-11": 6,
39
+ "2025-02-12": 15,
40
+ "2025-02-13": 1,
41
+ "2025-02-15": 1,
42
+ "2025-02-19": 1,
43
+ "2025-02-21": 9,
44
+ "2025-02-22": 9,
45
+ "2025-02-26": 1,
46
+ "2025-02-27": 1,
47
+ "2025-02-28": 8,
48
+ "2025-03-01": 8,
49
+ "2025-03-02": 7,
50
+ "2025-03-05": 1,
51
+ "2025-03-07": 13,
52
+ "2025-03-08": 5,
53
+ "2025-03-09": 2,
54
+ "2025-03-11": 2,
55
+ "2025-03-12": 4,
56
+ "2025-03-14": 3,
57
+ "2025-03-15": 3,
58
+ "2025-03-16": 3,
59
+ "2025-03-18": 3,
60
+ "2025-03-20": 5,
61
+ "2025-03-21": 5,
62
+ "2025-03-22": 15,
63
+ "2025-03-25": 2,
64
+ "2025-03-27": 1,
65
+ "2025-03-28": 3,
66
+ "2025-04-03": 2,
67
+ "2025-04-04": 1,
68
+ "2025-04-07": 1,
69
+ "2025-04-11": 1,
70
+ "2025-04-13": 7,
71
+ "2025-04-14": 2,
72
+ "2025-04-17": 1,
73
+ "2025-04-19": 1,
74
+ "2025-04-21": 4,
75
+ "2025-04-22": 2,
76
+ "2025-04-23": 3,
77
+ "2025-04-24": 1,
78
+ "2025-04-27": 1,
79
+ "2025-04-29": 6,
80
+ "2025-04-30": 1,
81
+ "2025-05-01": 8,
82
+ "2025-05-05": 4,
83
+ "2025-05-07": 2,
84
+ "2025-05-09": 1,
85
+ "2025-05-11": 3,
86
+ "2025-05-12": 1,
87
+ "2025-05-13": 5,
88
+ "2025-05-16": 13,
89
+ "2025-05-17": 8,
90
+ "2025-05-18": 2,
91
+ "2025-05-19": 11,
92
+ "2025-05-21": 1,
93
+ "2025-05-24": 4,
94
+ "2025-05-27": 8,
95
+ "2025-05-28": 2,
96
+ "2025-05-29": 1,
97
+ "2025-05-30": 1,
98
+ "2025-06-01": 5,
99
+ "2025-06-02": 3,
100
+ "2025-06-04": 3,
101
+ "2025-06-05": 2,
102
+ "2025-06-07": 5,
103
+ "2025-06-14": 11,
104
+ "2025-06-15": 5,
105
+ "2025-06-19": 6,
106
+ "2025-06-20": 5,
107
+ "2025-06-22": 8,
108
+ "2025-06-24": 5,
109
+ "2025-06-25": 9,
110
+ "2025-06-27": 5,
111
+ "2025-06-28": 5,
112
+ "2025-06-29": 6,
113
+ "2025-06-30": 3,
114
+ "2025-07-01": 1,
115
+ "2025-07-02": 5,
116
+ "2025-07-05": 2,
117
+ "2025-07-08": 1,
118
+ "2025-07-10": 2,
119
+ "2025-07-12": 3,
120
+ "2025-07-13": 2,
121
+ "2025-07-14": 5,
122
+ "2025-07-15": 5,
123
+ "2025-07-16": 1,
124
+ "2025-07-18": 9,
125
+ "2025-07-19": 9,
126
+ "2025-07-20": 2,
127
+ "2025-07-22": 3,
128
+ "2025-07-24": 5,
129
+ "2025-07-25": 1,
130
+ "2025-07-27": 5,
131
+ "2025-07-30": 2,
132
+ "2025-08-01": 13,
133
+ "2025-08-02": 3,
134
+ "2025-08-03": 2,
135
+ "2025-08-04": 9,
136
+ "2025-08-05": 4,
137
+ "2025-08-07": 1,
138
+ "2025-08-09": 5,
139
+ "2025-08-12": 2,
140
+ "2025-08-13": 5,
141
+ "2025-08-14": 4,
142
+ "2025-08-15": 4,
143
+ "2025-08-18": 6,
144
+ "2025-08-19": 6,
145
+ "2025-08-20": 2,
146
+ "2025-08-24": 6,
147
+ "2025-08-25": 3,
148
+ "2025-08-26": 12,
149
+ "2025-08-27": 14,
150
+ "2025-08-29": 1,
151
+ "2025-08-31": 5,
152
+ "2025-09-01": 1,
153
+ "2025-09-02": 3,
154
+ "2025-09-03": 2,
155
+ "2025-09-04": 14,
156
+ "2025-09-05": 6,
157
+ "2025-09-06": 9,
158
+ "2025-09-07": 4,
159
+ "2025-09-08": 1,
160
+ "2025-09-10": 1,
161
+ "2025-09-16": 4,
162
+ "2025-09-18": 4,
163
+ "2025-09-19": 2,
164
+ "2025-09-20": 3,
165
+ "2025-09-23": 2,
166
+ "2025-09-24": 6,
167
+ "2025-09-25": 3,
168
+ "2025-09-27": 1,
169
+ "2025-09-28": 5,
170
+ "2025-09-29": 5,
171
+ "2025-10-02": 2,
172
+ "2025-10-03": 2,
173
+ "2025-10-06": 8,
174
+ "2025-10-07": 8,
175
+ "2025-10-08": 8,
176
+ "2025-10-09": 3,
177
+ "2025-10-10": 15,
178
+ "2025-10-13": 2,
179
+ "2025-10-14": 9,
180
+ "2025-10-15": 1,
181
+ "2025-10-16": 2,
182
+ "2025-10-17": 1,
183
+ "2025-10-20": 6,
184
+ "2025-10-23": 9,
185
+ "2025-10-26": 1,
186
+ "2025-10-28": 2,
187
+ "2025-10-31": 1,
188
+ "2025-11-01": 2,
189
+ "2025-11-02": 1,
190
+ "2025-11-03": 1,
191
+ "2025-11-05": 1,
192
+ "2025-11-06": 5,
193
+ "2025-11-07": 2,
194
+ "2025-11-09": 3,
195
+ "2025-11-10": 2,
196
+ "2025-11-11": 1,
197
+ "2025-11-13": 2,
198
+ "2025-11-14": 1,
199
+ "2025-11-15": 1,
200
+ "2025-11-17": 4,
201
+ "2025-11-19": 2,
202
+ "2025-11-20": 11,
203
+ "2025-11-21": 9,
204
+ "2025-11-23": 1,
205
+ "2025-11-24": 3,
206
+ "2025-11-27": 7,
207
+ "2025-11-28": 1,
208
+ "2025-11-29": 5,
209
+ "2025-12-01": 2,
210
+ "2025-12-03": 1,
211
+ "2025-12-05": 1,
212
+ "2025-12-07": 6,
213
+ "2025-12-08": 1,
214
+ "2025-12-09": 3,
215
+ "2025-12-10": 4,
216
+ "2025-12-15": 2,
217
+ "2025-12-19": 3,
218
+ "2025-12-20": 15,
219
+ "2025-12-23": 5,
220
+ "2025-12-25": 2,
221
+ "2025-12-26": 1,
222
+ "2025-12-28": 4,
223
+ "2025-12-29": 2
224
+ },
225
+ "year": 2025,
226
+ "c0": "#161b22",
227
+ "c1": "#0e4429",
228
+ "c2": "#006d32",
229
+ "c3": "#26a641",
230
+ "c4": "#39d353"
231
+ },
232
+ "python_code": "class ContributionHeatmap(gr.HTML):\n \"\"\"Reusable GitHub-style contribution heatmap built on gr.HTML.\"\"\"\n\n def __init__(self, value=None, year=2025, theme=\"green\",\n c0=None, c1=None, c2=None, c3=None, c4=None, **kwargs):\n if value is None:\n value = {}\n # Use explicit c0-c4 if provided (from gr.HTML updates), else derive from theme\n colors = COLOR_SCHEMES.get(theme, COLOR_SCHEMES[\"green\"])\n super().__init__(\n value=value,\n year=year,\n c0=c0 or colors[0],\n c1=c1 or colors[1],\n c2=c2 or colors[2],\n c3=c3 or colors[3],\n c4=c4 or colors[4],\n html_template=HEATMAP_HTML,\n css_template=HEATMAP_CSS,\n js_on_load=HEATMAP_JS,\n **kwargs,\n )\n\n def api_info(self):\n return {\"type\": \"object\", \"description\": \"Dict mapping YYYY-MM-DD to int counts\"}\n",
233
+ "head": "",
234
+ "repo_url": "https://huggingface.co/spaces/ysharma/github-contribution-heatmap"
235
+ }
components/detection-viewer.json ADDED
The diff for this file is too large to render. See raw diff
 
components/kanban-board.json ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "kanban-board",
3
+ "name": "Kanban Board",
4
+ "description": "Drag-and-drop Kanban board with inline editing, priority labels, and search",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "kanban",
9
+ "drag-drop",
10
+ "project-management"
11
+ ],
12
+ "category": "input",
13
+ "html_template": "<div class=\"kanban-wrapper\">\n <div class=\"kanban-header\">\n <h2>${board_title}</h2>\n <div class=\"header-right\">\n <div class=\"search-box\">\n <span class=\"search-icon\">\ud83d\udd0d</span>\n <input type=\"text\" class=\"search-input\" placeholder=\"Search cards...\" />\n </div>\n <div class=\"header-stats\">\n ${(() => {\n const cols = (value && value.columns) || [];\n const total = cols.reduce((sum, col) => sum + col.cards.length, 0);\n const done = cols.find(c => c.id === 'done');\n const doneCount = done ? done.cards.length : 0;\n const pct = total > 0 ? Math.round((doneCount / total) * 100) : 0;\n return '<span class=\"stat-pill\">\ud83d\udcca ' + total + ' tasks</span>' +\n '<span class=\"stat-pill done-pill\">\u2705 ' + doneCount + ' done (' + pct + '%)</span>';\n })()}\n </div>\n </div>\n </div>\n <div class=\"kb-progress-track\">\n ${(() => {\n const cols = (value && value.columns) || [];\n const total = cols.reduce((sum, col) => sum + col.cards.length, 0);\n const done = cols.find(c => c.id === 'done');\n const doneCount = done ? done.cards.length : 0;\n const pct = total > 0 ? Math.round((doneCount / total) * 100) : 0;\n return '<div class=\"kb-progress-bar\" style=\"width: ' + pct + '%\"></div>';\n })()}\n </div>\n <div class=\"kanban-board\">\n ${((value && value.columns) || []).map((col, colIdx) => `\n <div class=\"kanban-column ${col.collapsed ? 'collapsed' : ''}\" data-col-idx=\"${colIdx}\" data-col-id=\"${col.id}\">\n <div class=\"column-header\" style=\"border-top: 3px solid ${col.color}\">\n <div class=\"col-header-left\">\n <button class=\"collapse-btn\" data-col-idx=\"${colIdx}\">${col.collapsed ? '\u25b6' : '\u25bc'}</button>\n <span class=\"col-title\">${col.title}</span>\n </div>\n <span class=\"col-count\" style=\"background: ${col.color}22; color: ${col.color}\">${col.cards.length}</span>\n </div>\n <div class=\"card-list ${col.collapsed ? 'hidden' : ''}\" data-col-idx=\"${colIdx}\">\n ${col.cards.map((card, cardIdx) => `\n <div class=\"kanban-card\" draggable=\"true\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" data-card-id=\"${card.id}\">\n <div class=\"card-priority priority-${card.priority}\"></div>\n <div class=\"card-content\">\n <div class=\"card-text\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\">${card.text}</div>\n <div class=\"card-footer\">\n <div class=\"card-tags\">\n ${(card.tags || []).map(t => '<span class=\"kb-tag\">' + t + '</span>').join('')}\n </div>\n <div class=\"card-actions\">\n <button class=\"priority-cycle\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" title=\"Cycle priority\">\n ${card.priority === 'high' ? '\ud83d\udd34' : card.priority === 'medium' ? '\ud83d\udfe1' : '\ud83d\udfe2'}\n </button>\n <button class=\"delete-card\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" title=\"Delete card\">\u2715</button>\n </div>\n </div>\n </div>\n </div>\n `).join('')}\n </div>\n <div class=\"add-card-area ${col.collapsed ? 'hidden' : ''}\">\n <input type=\"text\" class=\"add-card-input\" data-col-idx=\"${colIdx}\" placeholder=\"+ Add a card\u2026 \u23ce\" />\n </div>\n </div>\n `).join('')}\n </div>\n</div>",
14
+ "css_template": ".kanban-wrapper {\n background: linear-gradient(135deg, #0f172a 0%, #1a1a2e 100%);\n border-radius: 16px;\n padding: 24px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n color: #e2e8f0;\n overflow-x: auto;\n}\n.kanban-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 12px; }\n.kanban-header h2 { margin: 0; font-size: 22px; color: #f8fafc; letter-spacing: -0.3px; }\n.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }\n.search-box { display: flex; align-items: center; background: rgba(255,255,255,0.06); border: 1px solid #334155; border-radius: 10px; padding: 4px 12px; transition: all 0.2s; }\n.search-box:focus-within { border-color: #6366f1; background: rgba(99, 102, 241, 0.06); }\n.search-icon { font-size: 13px; margin-right: 6px; }\n.search-input { background: none; border: none; color: #e2e8f0; font-size: 13px; outline: none; width: 140px; }\n.search-input::placeholder { color: #475569; }\n.header-stats { display: flex; gap: 8px; }\n.stat-pill { background: rgba(255,255,255,0.08); padding: 5px 14px; border-radius: 12px; font-size: 13px; color: #94a3b8; font-weight: 500; }\n.done-pill { color: #10b981; }\n.kb-progress-track { height: 4px; background: rgba(255,255,255,0.08); border-radius: 4px; margin-bottom: 20px; overflow: hidden; }\n.kb-progress-bar { height: 100%; background: linear-gradient(90deg, #6366f1, #10b981); border-radius: 4px; transition: width 0.5s ease; }\n.kanban-board { display: flex; gap: 16px; min-height: 400px; padding-bottom: 8px; }\n.kanban-column { background: #1e293b; border-radius: 12px; min-width: 270px; max-width: 310px; flex: 1; display: flex; flex-direction: column; transition: min-width 0.3s, max-width 0.3s; }\n.kanban-column.collapsed { min-width: 60px; max-width: 60px; }\n.column-header { padding: 14px 14px 10px; display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0; user-select: none; }\n.col-header-left { display: flex; align-items: center; gap: 8px; }\n.collapse-btn { background: none; border: none; color: #64748b; cursor: pointer; font-size: 10px; padding: 2px 4px; border-radius: 4px; transition: color 0.2s; }\n.collapse-btn:hover { color: #e2e8f0; }\n.col-title { font-weight: 600; font-size: 14px; white-space: nowrap; }\n.col-count { min-width: 26px; height: 26px; border-radius: 13px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }\n.card-list { flex: 1; padding: 6px 10px; min-height: 60px; transition: background 0.2s; }\n.card-list.hidden, .add-card-area.hidden { display: none; }\n.card-list.drag-over { background: rgba(99, 102, 241, 0.08); border-radius: 8px; }\n.kanban-card { background: #0f172a; border: 1px solid #334155; border-radius: 10px; padding: 12px 12px 12px 16px; margin-bottom: 8px; cursor: grab; transition: all 0.15s ease; position: relative; overflow: hidden; animation: cardIn 0.2s ease; }\n.kanban-card:hover { border-color: #6366f1; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }\n.kanban-card.dragging { opacity: 0.4; transform: rotate(2deg) scale(0.97); }\n.kanban-card.search-hidden { display: none; }\n.kanban-card.search-highlight { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b44; }\n.card-priority { width: 4px; height: 100%; position: absolute; left: 0; top: 0; border-radius: 10px 0 0 10px; }\n.priority-high { background: #ef4444; }\n.priority-medium { background: #f59e0b; }\n.priority-low { background: #10b981; }\n.card-content { padding-left: 4px; }\n.card-text { font-size: 13px; line-height: 1.5; color: #e2e8f0; cursor: text; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; transition: background 0.15s; }\n.card-text:hover { background: rgba(255,255,255,0.04); }\n.card-text.editing { background: rgba(99, 102, 241, 0.1); outline: 1px solid #6366f1; min-height: 1.5em; }\n.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }\n.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }\n.kb-tag { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 500; }\n.card-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }\n.kanban-card:hover .card-actions { opacity: 1; }\n.priority-cycle, .delete-card { background: none; border: none; cursor: pointer; font-size: 13px; padding: 3px 6px; border-radius: 6px; transition: all 0.15s; color: #475569; }\n.delete-card:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }\n.priority-cycle:hover { background: rgba(255,255,255,0.08); }\n.add-card-area { padding: 6px 10px 14px; }\n.add-card-input { width: 100%; background: rgba(255,255,255,0.04); border: 1px dashed #334155; border-radius: 10px; padding: 10px 14px; color: #94a3b8; font-size: 13px; outline: none; transition: all 0.2s; box-sizing: border-box; }\n.add-card-input:focus { border-color: #6366f1; border-style: solid; background: rgba(99, 102, 241, 0.05); color: #e2e8f0; }\n.add-card-input::placeholder { color: #475569; }\n@keyframes cardIn { from { opacity: 0; transform: translateY(-8px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }",
15
+ "js_on_load": "let dragSrcColIdx = null;\nlet dragSrcCardIdx = null;\nelement.addEventListener('dragstart', (e) => {\n const card = e.target.closest('.kanban-card');\n if (!card) return;\n dragSrcColIdx = parseInt(card.dataset.colIdx);\n dragSrcCardIdx = parseInt(card.dataset.cardIdx);\n card.classList.add('dragging');\n e.dataTransfer.effectAllowed = 'move';\n});\nelement.addEventListener('dragend', (e) => {\n const card = e.target.closest('.kanban-card');\n if (card) card.classList.remove('dragging');\n element.querySelectorAll('.card-list').forEach(cl => cl.classList.remove('drag-over'));\n});\nelement.addEventListener('dragover', (e) => {\n e.preventDefault();\n const cardList = e.target.closest('.card-list');\n if (cardList) cardList.classList.add('drag-over');\n});\nelement.addEventListener('dragleave', (e) => {\n const cardList = e.target.closest('.card-list');\n if (cardList && !cardList.contains(e.relatedTarget)) {\n cardList.classList.remove('drag-over');\n }\n});\nelement.addEventListener('drop', (e) => {\n e.preventDefault();\n const cardList = e.target.closest('.card-list');\n if (!cardList || dragSrcColIdx === null) return;\n cardList.classList.remove('drag-over');\n const destColIdx = parseInt(cardList.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n const card = nv.columns[dragSrcColIdx].cards.splice(dragSrcCardIdx, 1)[0];\n const cardElements = cardList.querySelectorAll('.kanban-card:not(.dragging)');\n let insertIdx = nv.columns[destColIdx].cards.length;\n for (let i = 0; i < cardElements.length; i++) {\n const rect = cardElements[i].getBoundingClientRect();\n if (e.clientY < rect.top + rect.height / 2) { insertIdx = i; break; }\n }\n nv.columns[destColIdx].cards.splice(insertIdx, 0, card);\n props.value = nv;\n trigger('change');\n dragSrcColIdx = null;\n dragSrcCardIdx = null;\n});\nelement.addEventListener('click', (e) => {\n const delBtn = e.target.closest('.delete-card');\n if (!delBtn) return;\n e.stopPropagation();\n const colIdx = parseInt(delBtn.dataset.colIdx);\n const cardIdx = parseInt(delBtn.dataset.cardIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards.splice(cardIdx, 1);\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.priority-cycle');\n if (!btn) return;\n e.stopPropagation();\n const colIdx = parseInt(btn.dataset.colIdx);\n const cardIdx = parseInt(btn.dataset.cardIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n const card = nv.columns[colIdx].cards[cardIdx];\n const cycle = { low: 'medium', medium: 'high', high: 'low' };\n card.priority = cycle[card.priority] || 'low';\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.collapse-btn');\n if (!btn) return;\n const colIdx = parseInt(btn.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].collapsed = !nv.columns[colIdx].collapsed;\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('dblclick', (e) => {\n const textEl = e.target.closest('.card-text');\n if (!textEl) return;\n textEl.contentEditable = 'true';\n textEl.classList.add('editing');\n textEl.focus();\n const range = document.createRange();\n range.selectNodeContents(textEl);\n const sel = window.getSelection();\n sel.removeAllRanges();\n sel.addRange(range);\n});\nfunction commitEdit(textEl) {\n textEl.contentEditable = 'false';\n textEl.classList.remove('editing');\n const colIdx = parseInt(textEl.dataset.colIdx);\n const cardIdx = parseInt(textEl.dataset.cardIdx);\n const newText = textEl.innerText.trim();\n if (!newText) return;\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards[cardIdx].text = newText;\n props.value = nv;\n trigger('change');\n}\nelement.addEventListener('blur', (e) => {\n if (e.target.classList && e.target.classList.contains('editing')) {\n commitEdit(e.target);\n }\n}, true);\nelement.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && e.target.classList.contains('editing')) {\n e.preventDefault();\n e.target.blur();\n return;\n }\n if (e.key === 'Enter' && e.target.classList.contains('add-card-input')) {\n const text = e.target.value.trim();\n if (!text) return;\n const colIdx = parseInt(e.target.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards.push({\n id: String(Date.now()),\n text: text,\n priority: 'medium',\n tags: []\n });\n props.value = nv;\n e.target.value = '';\n trigger('change');\n }\n});\nelement.addEventListener('input', (e) => {\n if (!e.target.classList.contains('search-input')) return;\n const q = e.target.value.toLowerCase().trim();\n element.querySelectorAll('.kanban-card').forEach(card => {\n const text = card.querySelector('.card-text').innerText.toLowerCase();\n const tags = Array.from(card.querySelectorAll('.kb-tag')).map(t => t.innerText.toLowerCase()).join(' ');\n const match = !q || text.includes(q) || tags.includes(q);\n card.classList.toggle('search-hidden', !match);\n card.classList.toggle('search-highlight', !!q && match);\n });\n});",
16
+ "default_props": {
17
+ "board_title": "My Board",
18
+ "value": {
19
+ "columns": [
20
+ {
21
+ "id": "todo",
22
+ "title": "\ud83d\udccb To Do",
23
+ "color": "#6366f1",
24
+ "cards": [
25
+ {
26
+ "id": "1",
27
+ "text": "Research gr.HTML component",
28
+ "priority": "high",
29
+ "tags": [
30
+ "gradio"
31
+ ]
32
+ },
33
+ {
34
+ "id": "2",
35
+ "text": "Design the UI layout",
36
+ "priority": "medium",
37
+ "tags": [
38
+ "design"
39
+ ]
40
+ },
41
+ {
42
+ "id": "3",
43
+ "text": "Write documentation",
44
+ "priority": "low",
45
+ "tags": [
46
+ "docs"
47
+ ]
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "id": "progress",
53
+ "title": "\ud83d\udd28 In Progress",
54
+ "color": "#f59e0b",
55
+ "cards": [
56
+ {
57
+ "id": "4",
58
+ "text": "Build Kanban prototype",
59
+ "priority": "high",
60
+ "tags": [
61
+ "dev"
62
+ ]
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "id": "review",
68
+ "title": "\ud83d\udc40 Review",
69
+ "color": "#8b5cf6",
70
+ "cards": []
71
+ },
72
+ {
73
+ "id": "done",
74
+ "title": "\u2705 Done",
75
+ "color": "#10b981",
76
+ "cards": [
77
+ {
78
+ "id": "5",
79
+ "text": "Set up Gradio project",
80
+ "priority": "medium",
81
+ "tags": [
82
+ "setup"
83
+ ]
84
+ }
85
+ ]
86
+ }
87
+ ]
88
+ }
89
+ },
90
+ "python_code": "class KanbanBoard(gr.HTML):\n \"\"\"A drag-and-drop Kanban board component.\"\"\"\n\n def __init__(self, value=None, board_title=\"My Board\", **kwargs):\n if value is None:\n value = {\n \"columns\": [\n {\n \"id\": \"todo\", \"title\": \"To Do\", \"color\": \"#6366f1\",\n \"cards\": [\n {\"id\": \"1\", \"text\": \"Research gr.HTML\", \"priority\": \"high\", \"tags\": [\"gradio\"]},\n {\"id\": \"2\", \"text\": \"Design UI layout\", \"priority\": \"medium\", \"tags\": [\"design\"]},\n ],\n },\n {\n \"id\": \"progress\", \"title\": \"In Progress\", \"color\": \"#f59e0b\",\n \"cards\": [\n {\"id\": \"3\", \"text\": \"Build prototype\", \"priority\": \"high\", \"tags\": [\"dev\"]},\n ],\n },\n {\"id\": \"review\", \"title\": \"Review\", \"color\": \"#8b5cf6\", \"cards\": []},\n {\n \"id\": \"done\", \"title\": \"Done\", \"color\": \"#10b981\",\n \"cards\": [\n {\"id\": \"4\", \"text\": \"Set up project\", \"priority\": \"medium\", \"tags\": [\"setup\"]},\n ],\n },\n ],\n }\n super().__init__(\n value=value, board_title=board_title,\n html_template=HTML_TEMPLATE,\n css_template=CSS_TEMPLATE,\n js_on_load=JS_ON_LOAD, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"object\", \"description\": \"Kanban board state\"}"
91
+ }
components/likert-scale.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "likert-scale",
3
+ "name": "Likert Scale",
4
+ "description": "Agreement scale from Strongly Disagree to Strongly Agree",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "survey",
9
+ "scale"
10
+ ],
11
+ "category": "input",
12
+ "html_template": "<div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n</div>",
13
+ "css_template": ".likert-container { padding: 8px 0; }\n.likert-question { font-weight: 600; margin-bottom: 16px; font-size: 15px; }\n.likert-scale { display: flex; justify-content: space-between; gap: 4px; }\n.likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; flex: 1; gap: 8px; }\n.likert-option input { display: none; }\n.likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; transition: all 0.2s; }\n.likert-option:hover .likert-dot { border-color: #f97316; }\n.likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n.likert-label { font-size: 11px; text-align: center; color: #6b7280; line-height: 1.3; }",
14
+ "js_on_load": "const radios = element.querySelectorAll('input[type=\"radio\"]');\nradios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n});",
15
+ "default_props": {
16
+ "value": 0,
17
+ "question": "This component is easy to use"
18
+ },
19
+ "python_code": "class LikertScale(gr.HTML):\n def __init__(self, question=\"Rate this item\", value=0, **kwargs):\n html_template = \"\"\"\n <div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .likert-scale { display: flex; justify-content: space-between; }\n .likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; }\n .likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; }\n .likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n \"\"\"\n js_on_load = \"\"\"\n const radios = element.querySelectorAll('input[type=\"radio\"]');\n radios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value, question=question,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"integer\", \"minimum\": 0, \"maximum\": 5}"
20
+ }
components/progress-bar.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "progress-bar",
3
+ "name": "Progress Bar",
4
+ "description": "Interactive progress bar - click the track to set progress",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "display",
8
+ "progress",
9
+ "animation"
10
+ ],
11
+ "category": "display",
12
+ "html_template": "<div class=\"progress-container\">\n <div class=\"progress-label\">${label}</div>\n <div class=\"progress-track\">\n <div class=\"progress-fill\" style=\"width: ${value}%\"></div>\n </div>\n <div class=\"progress-text\">${value}%</div>\n</div>",
13
+ "css_template": ".progress-container { padding: 8px 0; }\n.progress-label { font-weight: 600; margin-bottom: 8px; font-size: 15px; }\n.progress-track { width: 100%; height: 24px; background: #e5e7eb; border-radius: 12px; overflow: hidden; cursor: pointer; }\n.progress-fill { height: 100%; background: linear-gradient(90deg, #f97316, #fb923c); border-radius: 12px; transition: width 0.4s ease; }\n.progress-text { margin-top: 6px; font-size: 14px; color: #6b7280; text-align: right; font-variant-numeric: tabular-nums; }",
14
+ "js_on_load": "const track = element.querySelector('.progress-track');\ntrack.addEventListener('click', (e) => {\n const rect = track.getBoundingClientRect();\n const pct = Math.round(((e.clientX - rect.left) / rect.width) * 100);\n props.value = Math.max(0, Math.min(100, pct));\n});",
15
+ "default_props": {
16
+ "value": 65,
17
+ "label": "Upload Progress"
18
+ },
19
+ "python_code": "progress = gr.HTML(\n value=65,\n label=\"Upload Progress\",\n html_template=\"\"\"\n <div class=\"progress-container\">\n <div class=\"progress-label\">${label}</div>\n <div class=\"progress-track\">\n <div class=\"progress-fill\" style=\"width: ${value}%\"></div>\n </div>\n <div class=\"progress-text\">${value}%</div>\n </div>\n \"\"\",\n css_template=\"\"\"\n .progress-track {\n width: 100%; height: 24px;\n background: #e5e7eb; border-radius: 12px;\n overflow: hidden; cursor: pointer;\n }\n .progress-fill {\n height: 100%;\n background: linear-gradient(90deg, #f97316, #fb923c);\n border-radius: 12px; transition: width 0.4s ease;\n }\n \"\"\",\n js_on_load=\"\"\"\n const track = element.querySelector('.progress-track');\n track.addEventListener('click', (e) => {\n const rect = track.getBoundingClientRect();\n const pct = Math.round(\n ((e.clientX - rect.left) / rect.width) * 100\n );\n props.value = Math.max(0, Math.min(100, pct));\n });\n \"\"\"\n)"
20
+ }
components/spin-wheel.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "spin-wheel",
3
+ "name": "Spin Wheel",
4
+ "description": "Spin the wheel to win a prize!",
5
+ "author": "ysharma",
6
+ "tags": [],
7
+ "category": "display",
8
+ "html_template": "\n<div class=\"wheel-container\">\n <div class=\"wheel-wrapper\">\n <!-- Pointer -->\n <div class=\"wheel-pointer\">\u25bc</div>\n \n <!-- Wheel - rotation prop preserves position across re-renders -->\n <div class=\"wheel\" id=\"prize-wheel\" style=\"transform: rotate(${rotation || 0}deg);\">\n <svg viewBox=\"0 0 400 400\" class=\"wheel-svg\">\n ${(() => {\n const segments = JSON.parse(segments_json || '[]');\n const cx = 200, cy = 200, r = 180;\n let html = '';\n \n segments.forEach((seg, i) => {\n const startRad = (seg.startAngle - 90) * Math.PI / 180;\n const endRad = (seg.endAngle - 90) * Math.PI / 180;\n const x1 = cx + r * Math.cos(startRad);\n const y1 = cy + r * Math.sin(startRad);\n const x2 = cx + r * Math.cos(endRad);\n const y2 = cy + r * Math.sin(endRad);\n const largeArc = seg.endAngle - seg.startAngle > 180 ? 1 : 0;\n \n const d = `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} Z`;\n html += `<path d=\"${d}\" fill=\"${seg.color}\" stroke=\"#fff\" stroke-width=\"2\" class=\"segment\" data-index=\"${i}\"/>`;\n \n // Text label\n const midRad = (seg.midAngle - 90) * Math.PI / 180;\n const textR = r * 0.65;\n const tx = cx + textR * Math.cos(midRad);\n const ty = cy + textR * Math.sin(midRad);\n const rotation = seg.midAngle;\n html += `<text x=\"${tx}\" y=\"${ty}\" fill=\"#fff\" font-size=\"11\" font-weight=\"bold\" \n text-anchor=\"middle\" dominant-baseline=\"middle\" \n transform=\"rotate(${rotation}, ${tx}, ${ty})\"\n style=\"text-shadow: 1px 1px 2px rgba(0,0,0,0.5); pointer-events: none;\">${seg.label}</text>`;\n });\n \n // Center circle\n html += `<circle cx=\"200\" cy=\"200\" r=\"35\" fill=\"#1a1a2e\" stroke=\"#FFD700\" stroke-width=\"4\" class=\"center-btn\"/>`;\n html += `<text x=\"200\" y=\"200\" fill=\"#FFD700\" font-size=\"14\" font-weight=\"bold\" text-anchor=\"middle\" dominant-baseline=\"middle\" style=\"pointer-events: none;\">SPIN</text>`;\n \n return html;\n })()}\n </svg>\n </div>\n \n <!-- Decorative lights -->\n <div class=\"wheel-lights\">\n ${Array.from({length: 16}, (_, i) => `<div class=\"light\" style=\"--i: ${i}\"></div>`).join('')}\n </div>\n </div>\n \n <!-- Result Display -->\n <div class=\"result-display ${value ? 'show' : ''}\" id=\"result-display\">\n ${value ? `<div class=\"result-text\">\ud83c\udf89 You won: <strong>${value}</strong></div>` : '<div class=\"result-text\">Spin to win!</div>'}\n </div>\n \n <!-- Spin Button -->\n <button class=\"spin-button\" id=\"spin-btn\">\n \ud83c\udfb0 SPIN TO WIN!\n </button>\n \n <!-- Confetti container -->\n <div class=\"confetti-container\" id=\"confetti\"></div>\n</div>\n",
9
+ "css_template": "\n .wheel-container {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n display: flex;\n flex-direction: column;\n align-items: center;\n padding: 24px;\n background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);\n border-radius: 24px;\n position: relative;\n overflow: hidden;\n min-height: 500px;\n }\n \n .wheel-wrapper {\n position: relative;\n width: 320px;\n height: 320px;\n }\n \n .wheel {\n width: 100%;\n height: 100%;\n transform: rotate(0deg);\n }\n \n .wheel-svg {\n width: 100%;\n height: 100%;\n filter: drop-shadow(0 10px 30px rgba(0,0,0,0.4));\n }\n \n .segment {\n cursor: pointer;\n transition: filter 0.2s;\n }\n \n .segment:hover {\n filter: brightness(1.1);\n }\n \n .center-btn {\n cursor: pointer;\n transition: all 0.2s;\n }\n \n .center-btn:hover {\n filter: brightness(1.2);\n }\n \n /* Pointer */\n .wheel-pointer {\n position: absolute;\n top: -10px;\n left: 50%;\n transform: translateX(-50%);\n font-size: 48px;\n color: #FFD700;\n z-index: 10;\n filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));\n animation: bounce 0.6s ease-in-out infinite;\n }\n \n @keyframes bounce {\n 0%, 100% { transform: translateX(-50%) translateY(0); }\n 50% { transform: translateX(-50%) translateY(8px); }\n }\n \n /* Decorative lights */\n .wheel-lights {\n position: absolute;\n top: 50%;\n left: 50%;\n width: 360px;\n height: 360px;\n transform: translate(-50%, -50%);\n pointer-events: none;\n }\n \n .light {\n position: absolute;\n width: 14px;\n height: 14px;\n background: #FFD700;\n border-radius: 50%;\n top: 50%;\n left: 50%;\n transform-origin: center;\n transform: rotate(calc(var(--i) * 22.5deg)) translateY(-180px);\n box-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700;\n animation: blink 0.5s ease-in-out infinite alternate;\n animation-delay: calc(var(--i) * 0.08s);\n }\n \n @keyframes blink {\n 0% { opacity: 0.4; transform: rotate(calc(var(--i) * 22.5deg)) translateY(-180px) scale(0.8); }\n 100% { opacity: 1; transform: rotate(calc(var(--i) * 22.5deg)) translateY(-180px) scale(1); box-shadow: 0 0 15px #FFD700, 0 0 30px #FFD700; }\n }\n \n /* Spin Button */\n .spin-button {\n margin-top: 24px;\n padding: 18px 56px;\n font-size: 20px;\n font-weight: 700;\n color: white;\n background: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%);\n border: none;\n border-radius: 50px;\n cursor: pointer;\n box-shadow: 0 8px 25px rgba(255, 107, 107, 0.4);\n transition: all 0.3s ease;\n text-transform: uppercase;\n letter-spacing: 2px;\n }\n \n .spin-button:hover:not(:disabled) {\n transform: translateY(-3px);\n box-shadow: 0 12px 35px rgba(255, 107, 107, 0.5);\n }\n \n .spin-button:active:not(:disabled) {\n transform: translateY(0);\n }\n \n .spin-button:disabled {\n background: linear-gradient(135deg, #666 0%, #888 100%);\n cursor: not-allowed;\n box-shadow: none;\n transform: none;\n }\n \n /* Result Display */\n .result-display {\n margin-top: 20px;\n padding: 16px 32px;\n background: rgba(255,255,255,0.1);\n border-radius: 12px;\n backdrop-filter: blur(10px);\n border: 1px solid rgba(255,255,255,0.1);\n opacity: 0.7;\n transform: scale(0.95);\n transition: all 0.5s ease;\n }\n \n .result-display.show {\n opacity: 1;\n transform: scale(1);\n background: rgba(255,215,0,0.15);\n border-color: rgba(255,215,0,0.3);\n }\n \n .result-text {\n font-size: 18px;\n color: #fff;\n text-align: center;\n }\n \n .result-text strong {\n color: #FFD700;\n font-size: 22px;\n display: block;\n margin-top: 4px;\n }\n \n /* Confetti */\n .confetti-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n overflow: hidden;\n }\n \n .confetti {\n position: absolute;\n width: 10px;\n height: 10px;\n animation: fall 3s ease-out forwards;\n }\n \n @keyframes fall {\n 0% {\n transform: translateY(-100px) rotate(0deg);\n opacity: 1;\n }\n 100% {\n transform: translateY(600px) rotate(720deg);\n opacity: 0;\n }\n }\n \n /* Spinning state indicator */\n .wheel-container.spinning .wheel-pointer {\n animation: none;\n color: #fff;\n }\n \n .wheel-container.spinning .light {\n animation: rapid-blink 0.1s ease-in-out infinite alternate;\n }\n \n @keyframes rapid-blink {\n 0% { opacity: 0.3; }\n 100% { opacity: 1; }\n }\n",
10
+ "js_on_load": "\n const container = element.querySelector('.wheel-container');\n const wheel = element.querySelector('#prize-wheel');\n const spinBtn = element.querySelector('#spin-btn');\n const confettiContainer = element.querySelector('#confetti');\n const resultDisplay = element.querySelector('#result-display');\n \n let isSpinning = false;\n \n // Initialize totalRotation from the rotation prop (persists across re-renders)\n let totalRotation = parseFloat(props.rotation) || 0;\n \n function getSegments() {\n try {\n return JSON.parse(props.segments_json || '[]');\n } catch (e) {\n return [];\n }\n }\n \n function createConfetti() {\n const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFEAA7', '#DDA0DD', '#FFD700', '#FF8E53', '#96CEB4'];\n for (let i = 0; i < 150; i++) {\n setTimeout(() => {\n const confetti = document.createElement('div');\n confetti.className = 'confetti';\n confetti.style.left = Math.random() * 100 + '%';\n confetti.style.background = colors[Math.floor(Math.random() * colors.length)];\n confetti.style.animationDelay = Math.random() * 0.3 + 's';\n confetti.style.animationDuration = (2 + Math.random() * 2) + 's';\n const size = 6 + Math.random() * 10;\n confetti.style.width = size + 'px';\n confetti.style.height = size + 'px';\n confetti.style.borderRadius = Math.random() > 0.5 ? '50%' : Math.random() > 0.5 ? '0' : '2px';\n confettiContainer.appendChild(confetti);\n \n setTimeout(() => confetti.remove(), 4000);\n }, i * 15);\n }\n }\n \n function spinWheel() {\n if (isSpinning) return;\n \n const segments = getSegments();\n if (segments.length === 0) return;\n \n isSpinning = true;\n container.classList.add('spinning');\n spinBtn.disabled = true;\n spinBtn.textContent = '\ud83c\udfb0 SPINNING...';\n \n // Pick a random winning segment\n const winningIndex = Math.floor(Math.random() * segments.length);\n const winningSegment = segments[winningIndex];\n \n // === ROTATION MATH ===\n // The pointer is fixed at TOP (0\u00b0). Segments are drawn with 0\u00b0 at top.\n // For pointer to hit segment, we need rotation where segment's midAngle aligns with top.\n \n // Add random offset within segment bounds\n const segmentSize = winningSegment.endAngle - winningSegment.startAngle;\n const randomOffset = (Math.random() - 0.5) * segmentSize * 0.7;\n \n // Target position (mod 360) where wheel should stop\n const targetMod = ((360 - winningSegment.midAngle + randomOffset) % 360 + 360) % 360;\n \n // Current wheel position (mod 360)\n const currentMod = ((totalRotation % 360) + 360) % 360;\n \n // Calculate additional rotation needed (always spin forward)\n let additionalRotation = targetMod - currentMod;\n if (additionalRotation <= 0) additionalRotation += 360;\n \n // Add extra full spins for dramatic effect (5-7 spins)\n const extraSpins = 5 + Math.floor(Math.random() * 3);\n const finalRotation = totalRotation + extraSpins * 360 + additionalRotation;\n \n // Apply rotation with CSS transition\n wheel.style.transition = 'transform 4s cubic-bezier(0.17, 0.67, 0.12, 0.99)';\n wheel.style.transform = `rotate(${finalRotation}deg)`;\n \n // Store FULL rotation for next spin\n totalRotation = finalRotation;\n \n // After spin completes, determine winner from ACTUAL landing position\n setTimeout(() => {\n isSpinning = false;\n container.classList.remove('spinning');\n spinBtn.disabled = false;\n spinBtn.textContent = '\ud83c\udfb0 SPIN AGAIN!';\n \n // Verify which segment the pointer actually landed on\n const landedRotation = ((totalRotation % 360) + 360) % 360;\n const pointerAngle = ((360 - landedRotation) % 360 + 360) % 360;\n \n // Find which segment contains this angle\n let actualWinner = winningSegment;\n for (const seg of segments) {\n if (pointerAngle >= seg.startAngle && pointerAngle < seg.endAngle) {\n actualWinner = seg;\n break;\n }\n }\n // Handle wrap-around edge case\n if (pointerAngle >= segments[segments.length - 1].endAngle || pointerAngle < segments[0].startAngle) {\n if (segments[0].startAngle === 0) {\n actualWinner = segments[0];\n }\n }\n \n // Persist rotation as prop so it survives re-renders\n props.rotation = totalRotation;\n \n // Update value - this automatically triggers 'change' event\n // Do NOT call trigger('change') separately or you'll get duplicate events!\n props.value = actualWinner.label;\n \n createConfetti();\n \n console.log('Spin complete:', {\n finalRotation: totalRotation,\n pointerAngle,\n winner: actualWinner.label\n });\n }, 4100);\n }\n \n // Button click\n spinBtn.addEventListener('click', spinWheel);\n \n // Click on wheel center\n element.addEventListener('click', (e) => {\n if (e.target && e.target.classList.contains('center-btn')) {\n spinWheel();\n }\n });\n \n // Keyboard support\n element.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n spinWheel();\n }\n });\n",
11
+ "default_props": {
12
+ "value": "",
13
+ "segments_json": "[{\"label\": \"\\ud83c\\udf81 Grand Prize\", \"color\": \"#FF6B6B\", \"startAngle\": 0, \"endAngle\": 45.0, \"midAngle\": 22.5}, {\"label\": \"\\ud83d\\udc8e 50 Gems\", \"color\": \"#4ECDC4\", \"startAngle\": 45.0, \"endAngle\": 90.0, \"midAngle\": 67.5}, {\"label\": \"\\u2b50 100 XP\", \"color\": \"#45B7D1\", \"startAngle\": 90.0, \"endAngle\": 135.0, \"midAngle\": 112.5}, {\"label\": \"\\ud83c\\udfab Free Trial\", \"color\": \"#96CEB4\", \"startAngle\": 135.0, \"endAngle\": 180.0, \"midAngle\": 157.5}, {\"label\": \"\\ud83d\\udd25 Double Points\", \"color\": \"#FFEAA7\", \"startAngle\": 180.0, \"endAngle\": 225.0, \"midAngle\": 202.5}, {\"label\": \"\\ud83d\\udcb0 10% Off\", \"color\": \"#DDA0DD\", \"startAngle\": 225.0, \"endAngle\": 270.0, \"midAngle\": 247.5}, {\"label\": \"\\ud83c\\udfae Bonus Round\", \"color\": \"#98D8C8\", \"startAngle\": 270.0, \"endAngle\": 315.0, \"midAngle\": 292.5}, {\"label\": \"\\ud83c\\udf40 Try Again\", \"color\": \"#F7DC6F\", \"startAngle\": 315.0, \"endAngle\": 360.0, \"midAngle\": 337.5}]",
14
+ "rotation": 0
15
+ },
16
+ "python_code": "class SpinWheel(gr.HTML):\n \"\"\"\n An interactive prize wheel component with:\n - Smooth CSS spinning animation\n - Customizable segments with colors\n - Win detection with callbacks\n - Confetti celebration effect\n \"\"\"\n def __init__(\n self,\n value=None, # Currently selected/won prize (string)\n segments=None, # List of {\"label\": str, \"color\": str, \"weight\": int}\n segments_json=None, # JSON string of computed segments (for updates)\n rotation=0, # Current wheel rotation in degrees (persists position)\n **kwargs\n ):\n # Use provided segments or default\n if segments is None:\n segments = DEFAULT_SEGMENTS\n\n # Compute segment data if not provided as JSON\n if segments_json is None:\n segment_data = compute_segment_data(segments)\n segments_json = json.dumps(segment_data)\n\n super().__init__(\n value=value,\n segments_json=segments_json,\n rotation=rotation,\n html_template=HTML_TEMPLATE,\n css_template=CSS_TEMPLATE,\n js_on_load=JS_ON_LOAD,\n **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"string\", \"description\": \"The label of the winning segment\"}\n"
17
+ }
components/star-rating.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "star-rating",
3
+ "name": "Star Rating",
4
+ "description": "Click stars to set a rating from 1 to 5",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "rating",
9
+ "stars"
10
+ ],
11
+ "category": "input",
12
+ "html_template": "<h2>${label} rating:</h2>\n${Array.from({length: 5}, (_, i) => `<img class='${i < value ? '' : 'faded'}' src='https://upload.wikimedia.org/wikipedia/commons/d/df/Award-star-gold-3d.svg'>`).join('')}",
13
+ "css_template": "img { height: 50px; display: inline-block; cursor: pointer; }\n.faded { filter: grayscale(100%); opacity: 0.3; }",
14
+ "js_on_load": "const imgs = element.querySelectorAll('img');\nimgs.forEach((img, index) => {\n img.addEventListener('click', () => {\n props.value = index + 1;\n });\n});",
15
+ "default_props": {
16
+ "value": 3,
17
+ "label": "Food"
18
+ },
19
+ "python_code": "class StarRating(gr.HTML):\n def __init__(self, label, value=0, **kwargs):\n html_template = \"\"\"\n <h2>${label} rating:</h2>\n ${Array.from({length: 5}, (_, i) => `<img class='${i < value ? '' : 'faded'}' src='https://upload.wikimedia.org/wikipedia/commons/d/df/Award-star-gold-3d.svg'>`).join('')}\n \"\"\"\n css_template = \"\"\"\n img { height: 50px; display: inline-block; cursor: pointer; }\n .faded { filter: grayscale(100%); opacity: 0.3; }\n \"\"\"\n js_on_load = \"\"\"\n const imgs = element.querySelectorAll('img');\n imgs.forEach((img, index) => {\n img.addEventListener('click', () => {\n props.value = index + 1;\n });\n });\n \"\"\"\n super().__init__(\n value=value, label=label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"integer\", \"minimum\": 0, \"maximum\": 5}"
20
+ }
components/tag-input.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "tag-input",
3
+ "name": "Tag Input",
4
+ "description": "Add and remove tags with keyboard input",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "input",
8
+ "tags",
9
+ "text"
10
+ ],
11
+ "category": "input",
12
+ "html_template": "<div class=\"tag-input-container\">\n <div class=\"tag-list\">\n ${(value || []).map((tag, i) => `\n <span class=\"tag-pill\">\n ${tag}\n <button class=\"tag-remove\" data-index=\"${i}\">&times;</button>\n </span>\n `).join('')}\n <input type=\"text\" class=\"tag-text-input\" placeholder=\"${(value || []).length === 0 ? 'Type a tag and press Enter...' : 'Add more...'}\" />\n </div>\n</div>",
13
+ "css_template": ".tag-input-container { padding: 4px 0; }\n.tag-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; border: 1px solid #e5e7eb; border-radius: 8px; min-height: 42px; }\n.tag-pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: #fff7ed; color: #ea580c; border-radius: 16px; font-size: 13px; font-weight: 500; border: 1px solid #fed7aa; }\n.tag-remove { background: none; border: none; color: #ea580c; cursor: pointer; font-size: 16px; padding: 0 2px; line-height: 1; opacity: 0.6; }\n.tag-remove:hover { opacity: 1; }\n.tag-text-input { border: none; outline: none; flex: 1; min-width: 120px; font-size: 14px; padding: 4px; background: transparent; }",
14
+ "js_on_load": "const input = element.querySelector('.tag-text-input');\ninput.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && input.value.trim()) {\n e.preventDefault();\n const tags = [...(props.value || []), input.value.trim()];\n props.value = tags;\n input.value = '';\n }\n if (e.key === 'Backspace' && !input.value && props.value && props.value.length > 0) {\n props.value = props.value.slice(0, -1);\n }\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.tag-remove');\n if (!btn) return;\n const idx = parseInt(btn.dataset.index);\n const tags = [...(props.value || [])];\n tags.splice(idx, 1);\n props.value = tags;\n});",
15
+ "default_props": {
16
+ "value": [
17
+ "python",
18
+ "gradio",
19
+ "html"
20
+ ]
21
+ },
22
+ "python_code": "class TagInput(gr.HTML):\n def __init__(self, value=None, **kwargs):\n html_template = \"\"\"\n <div class=\"tag-input-container\">\n <div class=\"tag-list\">\n ${(value || []).map((tag, i) => `\n <span class=\"tag-pill\">\n ${tag}\n <button class=\"tag-remove\" data-index=\"${i}\">&times;</button>\n </span>\n `).join('')}\n <input type=\"text\" class=\"tag-text-input\"\n placeholder=\"Type a tag and press Enter...\" />\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .tag-list {\n display: flex; flex-wrap: wrap; gap: 6px;\n padding: 8px; border: 1px solid #e5e7eb;\n border-radius: 8px;\n }\n .tag-pill {\n padding: 4px 10px; background: #fff7ed;\n color: #ea580c; border-radius: 16px;\n font-size: 13px; border: 1px solid #fed7aa;\n }\n \"\"\"\n js_on_load = \"\"\"\n const input = element.querySelector('.tag-text-input');\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && input.value.trim()) {\n e.preventDefault();\n props.value = [...(props.value || []), input.value.trim()];\n input.value = '';\n }\n });\n element.addEventListener('click', (e) => {\n const btn = e.target.closest('.tag-remove');\n if (!btn) return;\n const idx = parseInt(btn.dataset.index);\n const tags = [...(props.value || [])];\n tags.splice(idx, 1);\n props.value = tags;\n });\n \"\"\"\n super().__init__(\n value=value or [],\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"array\", \"items\": {\"type\": \"string\"}}"
23
+ }
components/todo-list.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "todo-list",
3
+ "name": "Todo List",
4
+ "description": "Interactive checklist with strikethrough on completed items",
5
+ "author": "gradio",
6
+ "tags": [
7
+ "form",
8
+ "todo",
9
+ "checklist"
10
+ ],
11
+ "category": "form",
12
+ "html_template": "<h2>Todo List</h2>\n<ul>\n ${value.map((item, index) => `\n <li style=\"text-decoration: ${completed.includes(index) ? 'line-through' : 'none'}; list-style: none; padding: 6px 0;\">\n <input type=\"checkbox\" ${completed.includes(index) ? 'checked' : ''} data-index=\"${index}\" />\n ${item}\n </li>\n `).join('')}\n</ul>",
13
+ "css_template": "h2 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }\nul { padding: 0; margin: 0; }\nli { font-size: 14px; transition: opacity 0.2s; }\nli input { margin-right: 8px; cursor: pointer; }",
14
+ "js_on_load": "const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\ncheckboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n const index = parseInt(checkbox.getAttribute('data-index'));\n let completed = props.completed || [];\n if (checkbox.checked) {\n if (!completed.includes(index)) {\n completed.push(index);\n }\n } else {\n completed = completed.filter(i => i !== index);\n }\n props.completed = [...completed];\n });\n});",
15
+ "default_props": {
16
+ "value": [
17
+ "Buy groceries",
18
+ "Walk the dog",
19
+ "Read a book",
20
+ "Write code"
21
+ ],
22
+ "completed": [
23
+ 1
24
+ ]
25
+ },
26
+ "python_code": "class TodoList(gr.HTML):\n def __init__(self, value=None, completed=None, **kwargs):\n html_template = \"\"\"\n <h2>Todo List</h2>\n <ul>\n ${value.map((item, index) => `\n <li style=\"text-decoration: ${completed.includes(index) ? 'line-through' : 'none'};\">\n <input type=\"checkbox\" ${completed.includes(index) ? 'checked' : ''} data-index=\"${index}\" />\n ${item}\n </li>\n `).join('')}\n </ul>\n \"\"\"\n js_on_load = \"\"\"\n const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\n checkboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n const index = parseInt(checkbox.getAttribute('data-index'));\n let completed = props.completed || [];\n if (checkbox.checked) {\n if (!completed.includes(index)) completed.push(index);\n } else {\n completed = completed.filter(i => i !== index);\n }\n props.completed = [...completed];\n });\n });\n \"\"\"\n super().__init__(\n value=value or [], completed=completed or [],\n html_template=html_template,\n js_on_load=js_on_load, **kwargs\n )"
27
+ }
manifest.json ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "camera-control3-d",
4
+ "name": "Camera Control3 D",
5
+ "description": "A 3D camera control component using Three.js.",
6
+ "author": "multimodalart",
7
+ "tags": [
8
+ "3D",
9
+ "Image"
10
+ ],
11
+ "category": "Input",
12
+ "repo_url": "https://huggingface.co/spaces/multimodalart/qwen-image-multiple-angles-3d-camera/"
13
+ },
14
+ {
15
+ "id": "detection-viewer",
16
+ "name": "Detection Viewer",
17
+ "description": "Rich viewer for object detection model outputs",
18
+ "author": "hysts",
19
+ "tags": [],
20
+ "category": "display",
21
+ "repo_url": "https://github.com/hysts/gradio-detection-viewer/"
22
+ },
23
+ {
24
+ "id": "contribution-heatmap",
25
+ "name": "Contribution Heatmap",
26
+ "description": "Reusable GitHub-style contribution heatmap",
27
+ "author": "ysharma",
28
+ "tags": [
29
+ "Business"
30
+ ],
31
+ "category": "Display",
32
+ "repo_url": "https://huggingface.co/spaces/ysharma/github-contribution-heatmap"
33
+ },
34
+ {
35
+ "id": "spin-wheel",
36
+ "name": "Spin Wheel",
37
+ "description": "Spin the wheel to win a prize!",
38
+ "author": "ysharma",
39
+ "tags": [],
40
+ "category": "display"
41
+ },
42
+ {
43
+ "id": "star-rating",
44
+ "name": "Star Rating",
45
+ "description": "Click stars to set a rating from 1 to 5",
46
+ "author": "gradio",
47
+ "tags": [
48
+ "input",
49
+ "rating",
50
+ "stars"
51
+ ],
52
+ "category": "input"
53
+ },
54
+ {
55
+ "id": "button-set",
56
+ "name": "Button Set",
57
+ "description": "Multiple buttons that trigger events with click data",
58
+ "author": "gradio",
59
+ "tags": [
60
+ "input",
61
+ "buttons",
62
+ "events"
63
+ ],
64
+ "category": "input"
65
+ },
66
+ {
67
+ "id": "progress-bar",
68
+ "name": "Progress Bar",
69
+ "description": "Interactive progress bar - click the track to set progress",
70
+ "author": "gradio",
71
+ "tags": [
72
+ "display",
73
+ "progress",
74
+ "animation"
75
+ ],
76
+ "category": "display"
77
+ },
78
+ {
79
+ "id": "likert-scale",
80
+ "name": "Likert Scale",
81
+ "description": "Agreement scale from Strongly Disagree to Strongly Agree",
82
+ "author": "gradio",
83
+ "tags": [
84
+ "input",
85
+ "survey",
86
+ "scale"
87
+ ],
88
+ "category": "input"
89
+ },
90
+ {
91
+ "id": "tag-input",
92
+ "name": "Tag Input",
93
+ "description": "Add and remove tags with keyboard input",
94
+ "author": "gradio",
95
+ "tags": [
96
+ "input",
97
+ "tags",
98
+ "text"
99
+ ],
100
+ "category": "input"
101
+ },
102
+ {
103
+ "id": "colored-checkbox-group",
104
+ "name": "Colored Checkbox Group",
105
+ "description": "Multi-select checkbox group with custom colors per option",
106
+ "author": "gradio",
107
+ "tags": [
108
+ "input",
109
+ "checkbox",
110
+ "color"
111
+ ],
112
+ "category": "input"
113
+ },
114
+ {
115
+ "id": "todo-list",
116
+ "name": "Todo List",
117
+ "description": "Interactive checklist with strikethrough on completed items",
118
+ "author": "gradio",
119
+ "tags": [
120
+ "form",
121
+ "todo",
122
+ "checklist"
123
+ ],
124
+ "category": "form"
125
+ },
126
+ {
127
+ "id": "audio-gallery",
128
+ "name": "Audio Gallery",
129
+ "description": "Grid of audio players with waveform visualization and selection",
130
+ "author": "gradio",
131
+ "tags": [
132
+ "display",
133
+ "audio",
134
+ "gallery",
135
+ "media"
136
+ ],
137
+ "category": "display"
138
+ },
139
+ {
140
+ "id": "kanban-board",
141
+ "name": "Kanban Board",
142
+ "description": "Drag-and-drop Kanban board with inline editing, priority labels, and search",
143
+ "author": "gradio",
144
+ "tags": [
145
+ "input",
146
+ "kanban",
147
+ "drag-drop",
148
+ "project-management"
149
+ ],
150
+ "category": "input"
151
+ }
152
+ ]