UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: icon cloud without any dependency (#488)
Arghya Das2808f3985a29
diff --git a/__registry__/index.tsx b/__registry__/index.tsxindex 3c6b0a91..aaeca535 100644--- a/__registry__/index.tsx+++ b/__registry__/index.tsx@@ -1674,6 +1674,19 @@ export const Index: Record<string, any> = {subcategory: "undefined",chunks: [],},+ "icon-cloud-demo-3": {+ name: "icon-cloud-demo-3",+ type: "registry:example",+ registryDependencies: ["icon-cloud"],+ files: ["registry/default/example/icon-cloud-demo-3.tsx"],+ component: React.lazy(+ () => import("@/registry/default/example/icon-cloud-demo-3.tsx"),+ ),+ source: "",+ category: "undefined",+ subcategory: "undefined",+ chunks: [],+ },"gradual-spacing-demo": {name: "gradual-spacing-demo",type: "registry:example",diff --git a/config/docs.ts b/config/docs.tsindex 7868b29e..4e40aa5b 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -178,7 +178,7 @@ export const docsConfig: DocsConfig = {label: "",},{- title: "Interactive Icon Cloud",+ title: "Icon Cloud",href: `/docs/components/icon-cloud`,items: [],label: "",diff --git a/content/docs/components/icon-cloud.mdx b/content/docs/components/icon-cloud.mdxindex b91cdab7..867b06f7 100644--- a/content/docs/components/icon-cloud.mdx+++ b/content/docs/components/icon-cloud.mdx@@ -1,5 +1,5 @@----title: Interactive Icon Cloud+title: Icon Clouddate: 2024-05-24description: An interactive 3D tag cloud componentauthor: dillionverma@@ -28,12 +28,6 @@ npx shadcn@latest add "https://magicui.design/r/icon-cloud"<Steps>-<Step>Install the following dependencies:</Step>--```bash-npm install react-icon-cloud next-themes-```-<Step>Copy and paste the following code into your project.</Step><ComponentSource name="icon-cloud" />@@ -48,57 +42,13 @@ npm install react-icon-cloud next-themes<ComponentPreview name="icon-cloud-demo-2" />-## ⚠️ Warning+## With SVG Icons-> Avoid using the IconCloud component in parent components where the component interacts with hooks or undergoes frequent state changes. Such interactions may lead to unexpected behavior, such as continuous spinning.-> Consider creating a separate component for the section of your application that utilizes hooks or undergoes frequent state changes in parent component.+<ComponentPreview name="icon-cloud-demo-3" />## Props-### IconCloud--Displays a dynamic cloud of icons from the Simple Icons library based on provided slugs.-| Prop | type | default | description |-|:----------------:|:-----------------------------------------------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------:|-| imageArray | string[] | | An array of image URLs corresponding to the images you want to display. |-| iconSlugs | string[] | |An array of icon slugs corresponding to the icons you want to display. Each slug should match a supported icon from the Simple Icons library. |--### Cloud--There are a number of options for modifying the way the cloud looks and behaves. Go to https://www.goat1000.com/tagcanvas-options.php to see the list of all available options for your cloud.-| Prop | type | default | description |-|:--------------:|:-------------------------------------------------:|:-------:|:---------------------------------------------------------------:|-| canvasProps | HTMLAttributes < HTMLCanvasElement > \| undefined | {} | Attributes that will be passed to the underlying canvas element |-| children | Tag[] | [] | Tags rendered using the provided renderers |-| containerProps | HTMLAttributes < HTMLDivElement > \| undefined | {} | Attributes passed to the root div element |-| id | string \| number \| undefined | uuid | Should be provided when using SSR |-| maxSpeed | int | 0.04 | To adjust the rotation speed in idle state |-| minSpeed | int | 0.02 | To adjust the rotation speed when hovering |-| dragControl | boolean | false | Enable or disable the ability to drag and interact with the icon cloud. |-| dragThreshold | number | 4 | The number of pixels that the cursor must move to count as a drag instead of a click. |-| decel | number | 0.95 | Deceleration rate when mouse leaves canvas. |-| freezeDecel | boolean | false | Whether to freeze the cloud when dragging stops. |--### renderSimpleIcon--Used to create a tag for the Cloud component-| Prop | type | default | description |-|:----------------:|:-----------------------------------------------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------:|-| aProps | HTMLAttributes < HTMLAnchorElement > \| undefined | {} | Attributes passed to the underlying anchor element |-| bgHex | string \| undefined | '#fff' | The string hex of the background the icon will be rendered on. Ex: '#fff'. Used to determine if the min contrast ratio for the icons default color will be met |-| fallbackHex | string \| undefined | '#000' | The color of the icon if the minContrastRatio is not met Ex: '#000' |-| icon | any | undefined | The simple icon object you would like to render. Ex: import icon from "simple-icons/icons/javascript";-| imgProps | HTMLAttributes < HTMLImageElement > \| undefined | {} | Attributes passed to the underlying img element | |-| minContrastRatio | number \| undefined | 1 | 0 - 21 The min contrast ratio between icon and bgHex before the fallbackHex will be used for the icon color |-| size | number \| undefined | 42 | The size in px of the icon |--### fetchSimpleIcons--Used when you cant statically import simple icons during build time. Calling this will use `fetch` to get icons for each provided slug.-| Prop | type | default | description |-|:----------------:|:-----------------------------------------------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------:|-| slugs | string[] | | Slugs to fetch svgs and colors for. The return icons may be passed to renderSimpleIcon |--## Credits--- Credits to (https://github.com/teaguestockwell/react-icon-cloud)+| Prop | Type | Description | Default |+| ------ | ----------------- | ------------------------------------------ | ------- |+| icons | React.ReactNode[] | Array of icons to render in the cloud | [] |+| images | string[] | Array of image URLs to render in the cloud | [] |diff --git a/package.json b/package.jsonindex 4538a40f..6fc77754 100644--- a/package.json+++ b/package.json@@ -69,7 +69,6 @@"react-day-picker": "^8.9.1","react-dom": "18.3.1","react-hook-form": "^7.50.1",- "react-icon-cloud": "^4.1.6","react-tweet": "^3.2.1","schema-dts": "^1.1.2","sonner": "^1.5.0",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0bdd5443..02b39ab4 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -143,9 +143,6 @@ importers:react-hook-form:specifier: ^7.50.1version: 7.50.1([email protected])- react-icon-cloud:- specifier: ^4.1.6- version: 4.1.6([email protected])react-tweet:specifier: ^3.2.1@@ -528,10 +525,6 @@ packages:resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}engines: {node: '>=12'}- '@csstools/[email protected]':- resolution: {integrity: sha512-P7BVvddsP2Wl5v3drJ3ArzpdfXMqoZ/oHOV/yFiGFb3JQr9Z9UXZ9tnHAKJsO89lfprR1F9ExW3Yij21EjEBIA==}- engines: {node: '>=6.0.0'}-'@emotion/[email protected]':resolution: {integrity: sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==}@@ -4411,12 +4404,6 @@ packages:peerDependencies:react: ^16.8.0 || ^17 || ^18- resolution: {integrity: sha512-M19XUQjGpQQZD3kVQ8YxbMhM33Yx4vQFUPEurN2CajrzzUcoyiPqJnKDgCCkkL4nd3hemB4PgK2LVsHwEkFKdg==}- engines: {node: '>=22'}- peerDependencies:- react: '>=16'-resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==}@@ -5580,8 +5567,6 @@ snapshots:'@jridgewell/trace-mapping': 0.3.9optional: true- '@csstools/[email protected]': {}-'@emotion/[email protected]':dependencies:'@emotion/memoize': 0.7.4@@ -7814,7 +7799,7 @@ snapshots:eslint: 8.57.1eslint-import-resolver-node: 0.3.9eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected])- eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])+ eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected])eslint-plugin-jsx-a11y: 6.8.0([email protected])eslint-plugin-react: 7.33.2([email protected])eslint-plugin-react-hooks: 4.6.0([email protected])@@ -7841,8 +7826,8 @@ snapshots:debug: 4.3.4enhanced-resolve: 5.15.1eslint: 8.57.1- eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected])- eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])+ eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected])+ eslint-plugin-import: 2.29.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected])fast-glob: 3.3.2get-tsconfig: 4.7.5is-core-module: 2.13.1@@ -7853,7 +7838,7 @@ snapshots:- eslint-import-resolver-webpack- supports-color- [email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected]):+ [email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected]):dependencies:debug: 3.2.7optionalDependencies:@@ -7864,7 +7849,7 @@ snapshots:transitivePeerDependencies:- supports-color- [email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]):+ [email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected]):dependencies:array-includes: 3.1.7array.prototype.findlastindex: 1.2.4@@ -7874,7 +7859,7 @@ snapshots:doctrine: 2.1.0eslint: 8.57.1eslint-import-resolver-node: 0.3.9- eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected])+ eslint-module-utils: 2.8.1(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]([email protected]))([email protected]))([email protected])hasown: 2.0.1is-core-module: 2.13.1is-glob: 4.0.3@@ -10018,11 +10003,6 @@ snapshots:dependencies:react: 18.3.1- dependencies:- '@csstools/convert-colors': 2.0.0- react: 18.3.1-diff --git a/public/r/styles/default/icon-cloud.json b/public/r/styles/default/icon-cloud.jsonindex 285d895d..9a97dfd2 100644--- a/public/r/styles/default/icon-cloud.json+++ b/public/r/styles/default/icon-cloud.json@@ -8,7 +8,7 @@"files": [{"path": "magicui/icon-cloud.tsx",- "content": "\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useTheme } from \"next-themes\";\nimport {\n Cloud,\n fetchSimpleIcons,\n ICloud,\n renderSimpleIcon,\n SimpleIcon,\n} from \"react-icon-cloud\";\n\nexport type DynamicCloudProps = {\n iconSlugs?: string[]; // Made iconSlugs optional\n imageArray?: string[];\n};\n\nexport const cloudProps: Omit<ICloud, \"children\"> = {\n containerProps: {\n style: {\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n width: \"100%\",\n paddingTop: 40,\n },\n },\n options: {\n reverse: true,\n depth: 1,\n wheelZoom: false,\n imageScale: 2,\n activeCursor: \"default\",\n tooltip: \"native\",\n initial: [0.1, -0.1],\n clickToFront: 500,\n tooltipDelay: 0,\n outlineColour: \"#0000\",\n maxSpeed: 0.04,\n minSpeed: 0.02,\n // dragControl: false,\n },\n};\n\nexport const renderCustomIcon = (\n icon: SimpleIcon,\n theme: string,\n imageArray?: string[],\n) => {\n const bgHex = theme === \"light\" ? \"#f3f2ef\" : \"#080510\";\n const fallbackHex = theme === \"light\" ? \"#6e6e73\" : \"#ffffff\";\n const minContrastRatio = theme === \"dark\" ? 2 : 1.2;\n\n return renderSimpleIcon({\n icon,\n bgHex,\n fallbackHex,\n minContrastRatio,\n size: 42,\n aProps: {\n href: undefined,\n target: undefined,\n rel: undefined,\n onClick: (e: React.MouseEvent<HTMLAnchorElement>) => e.preventDefault(),\n },\n });\n};\n\ntype IconData = Awaited<ReturnType<typeof fetchSimpleIcons>>;\n\nexport default function IconCloud({\n iconSlugs = [], // Default to an empty array if not provided\n imageArray,\n}: DynamicCloudProps) {\n const [data, setData] = useState<IconData | null>(null);\n const { theme } = useTheme();\n\n useEffect(() => {\n if (iconSlugs.length > 0) {\n // Check if iconSlugs is not empty\n fetchSimpleIcons({ slugs: iconSlugs }).then(setData);\n }\n }, [iconSlugs]);\n\n const renderedIcons = useMemo(() => {\n if (!data) return null;\n\n return Object.values(data.simpleIcons).map((icon) =>\n renderCustomIcon(icon, theme || \"light\"),\n );\n }, [data, theme]);\n\n return (\n // @ts-ignore\n <Cloud {...cloudProps}>\n <>\n <>{renderedIcons}</>\n {imageArray &&\n imageArray.length > 0 &&\n imageArray.map((image, index) => {\n return (\n <a key={index} href=\"#\" onClick={(e) => e.preventDefault()}>\n <img height=\"42\" width=\"42\" alt=\"A globe\" src={image} />\n </a>\n );\n })}\n </>\n </Cloud>\n );\n}\n",+ "content": "\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { renderToString } from \"react-dom/server\";\nimport React from \"react\";\n\ninterface Icon {\n x: number;\n y: number;\n z: number;\n scale: number;\n opacity: number;\n id: number;\n}\n\ninterface IconCloudProps {\n icons?: React.ReactNode[];\n images?: string[];\n}\n\nfunction easeOutCubic(t: number): number {\n return 1 - Math.pow(1 - t, 3);\n}\n\nexport default function IconCloud({ icons, images }: IconCloudProps) {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const [iconPositions, setIconPositions] = useState<Icon[]>([]);\n const [rotation, setRotation] = useState({ x: 0, y: 0 });\n const [isDragging, setIsDragging] = useState(false);\n const [lastMousePos, setLastMousePos] = useState({ x: 0, y: 0 });\n const [mousePos, setMousePos] = useState({ x: 0, y: 0 });\n const [targetRotation, setTargetRotation] = useState<{\n x: number;\n y: number;\n startX: number;\n startY: number;\n distance: number;\n startTime: number;\n duration: number;\n } | null>(null);\n const animationFrameRef = useRef<number>();\n const rotationRef = useRef(rotation);\n const iconCanvasesRef = useRef<HTMLCanvasElement[]>([]);\n const imagesLoadedRef = useRef<boolean[]>([]);\n\n // Create icon canvases once when icons/images change\n useEffect(() => {\n if (!icons && !images) return;\n\n const items = icons || images || [];\n imagesLoadedRef.current = new Array(items.length).fill(false);\n\n const newIconCanvases = items.map((item, index) => {\n const offscreen = document.createElement(\"canvas\");\n offscreen.width = 40;\n offscreen.height = 40;\n const offCtx = offscreen.getContext(\"2d\");\n\n if (offCtx) {\n if (images) {\n // Handle image URLs directly\n const img = new Image();\n img.crossOrigin = \"anonymous\";\n img.src = items[index] as string;\n img.onload = () => {\n offCtx.clearRect(0, 0, offscreen.width, offscreen.height);\n\n // Create circular clipping path\n offCtx.beginPath();\n offCtx.arc(20, 20, 20, 0, Math.PI * 2);\n offCtx.closePath();\n offCtx.clip();\n\n // Draw the image\n offCtx.drawImage(img, 0, 0, 40, 40);\n\n imagesLoadedRef.current[index] = true;\n };\n } else {\n // Handle SVG icons\n offCtx.scale(0.4, 0.4);\n const svgString = renderToString(item as React.ReactElement);\n const img = new Image();\n img.src = \"data:image/svg+xml;base64,\" + btoa(svgString);\n img.onload = () => {\n offCtx.clearRect(0, 0, offscreen.width, offscreen.height);\n offCtx.drawImage(img, 0, 0);\n imagesLoadedRef.current[index] = true;\n };\n }\n }\n return offscreen;\n });\n\n iconCanvasesRef.current = newIconCanvases;\n }, [icons, images]);\n\n // Generate initial icon positions on a sphere\n useEffect(() => {\n const items = icons || images || [];\n const newIcons: Icon[] = [];\n const numIcons = items.length || 20;\n const phi = Math.PI * (3 - Math.sqrt(5));\n\n for (let i = 0; i < numIcons; i++) {\n const y = 1 - (i / (numIcons - 1)) * 2;\n const radius = Math.sqrt(1 - y * y);\n const theta = phi * i;\n\n const x = Math.cos(theta) * radius;\n const z = Math.sin(theta) * radius;\n\n newIcons.push({\n x: x * 100,\n y: y * 100,\n z: z * 100,\n scale: 1,\n opacity: 1,\n id: i,\n });\n }\n setIconPositions(newIcons);\n }, [icons, images]);\n\n // Handle mouse events\n const handleMouseDown = (e: React.MouseEvent<HTMLCanvasElement>) => {\n const rect = canvasRef.current?.getBoundingClientRect();\n if (!rect || !canvasRef.current) return;\n\n const x = e.clientX - rect.left;\n const y = e.clientY - rect.top;\n\n const ctx = canvasRef.current.getContext(\"2d\");\n if (!ctx) return;\n\n iconPositions.forEach((icon) => {\n const cosX = Math.cos(rotationRef.current.x);\n const sinX = Math.sin(rotationRef.current.x);\n const cosY = Math.cos(rotationRef.current.y);\n const sinY = Math.sin(rotationRef.current.y);\n\n const rotatedX = icon.x * cosY - icon.z * sinY;\n const rotatedZ = icon.x * sinY + icon.z * cosY;\n const rotatedY = icon.y * cosX + rotatedZ * sinX;\n\n const screenX = canvasRef.current!.width / 2 + rotatedX;\n const screenY = canvasRef.current!.height / 2 + rotatedY;\n\n const scale = (rotatedZ + 200) / 300;\n const radius = 20 * scale;\n const dx = x - screenX;\n const dy = y - screenY;\n\n if (dx * dx + dy * dy < radius * radius) {\n const targetX = -Math.atan2(\n icon.y,\n Math.sqrt(icon.x * icon.x + icon.z * icon.z),\n );\n const targetY = Math.atan2(icon.x, icon.z);\n\n const currentX = rotationRef.current.x;\n const currentY = rotationRef.current.y;\n const distance = Math.sqrt(\n Math.pow(targetX - currentX, 2) + Math.pow(targetY - currentY, 2),\n );\n\n const duration = Math.min(2000, Math.max(800, distance * 1000));\n\n setTargetRotation({\n x: targetX,\n y: targetY,\n startX: currentX,\n startY: currentY,\n distance,\n startTime: performance.now(),\n duration,\n });\n return;\n }\n });\n\n setIsDragging(true);\n setLastMousePos({ x: e.clientX, y: e.clientY });\n };\n\n const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {\n const rect = canvasRef.current?.getBoundingClientRect();\n if (rect) {\n const x = e.clientX - rect.left;\n const y = e.clientY - rect.top;\n setMousePos({ x, y });\n }\n\n if (isDragging) {\n const deltaX = e.clientX - lastMousePos.x;\n const deltaY = e.clientY - lastMousePos.y;\n\n rotationRef.current = {\n x: rotationRef.current.x + deltaY * 0.002,\n y: rotationRef.current.y + deltaX * 0.002,\n };\n\n setLastMousePos({ x: e.clientX, y: e.clientY });\n }\n };\n\n const handleMouseUp = () => {\n setIsDragging(false);\n };\n\n // Animation and rendering\n useEffect(() => {\n const canvas = canvasRef.current;\n const ctx = canvas?.getContext(\"2d\");\n if (!canvas || !ctx) return;\n\n const animate = () => {\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n\n const centerX = canvas.width / 2;\n const centerY = canvas.height / 2;\n const maxDistance = Math.sqrt(centerX * centerX + centerY * centerY);\n const dx = mousePos.x - centerX;\n const dy = mousePos.y - centerY;\n const distance = Math.sqrt(dx * dx + dy * dy);\n const speed = 0.003 + (distance / maxDistance) * 0.006;\n\n if (targetRotation) {\n const elapsed = performance.now() - targetRotation.startTime;\n const progress = Math.min(1, elapsed / targetRotation.duration);\n const easedProgress = easeOutCubic(progress);\n\n rotationRef.current = {\n x:\n targetRotation.startX +\n (targetRotation.x - targetRotation.startX) * easedProgress,\n y:\n targetRotation.startY +\n (targetRotation.y - targetRotation.startY) * easedProgress,\n };\n\n if (progress >= 1) {\n setTargetRotation(null);\n }\n } else if (!isDragging) {\n rotationRef.current = {\n x: rotationRef.current.x + (dy / canvas.height) * speed,\n y: rotationRef.current.y + (dx / canvas.width) * speed,\n };\n }\n\n iconPositions.forEach((icon, index) => {\n const cosX = Math.cos(rotationRef.current.x);\n const sinX = Math.sin(rotationRef.current.x);\n const cosY = Math.cos(rotationRef.current.y);\n const sinY = Math.sin(rotationRef.current.y);\n\n const rotatedX = icon.x * cosY - icon.z * sinY;\n const rotatedZ = icon.x * sinY + icon.z * cosY;\n const rotatedY = icon.y * cosX + rotatedZ * sinX;\n\n const scale = (rotatedZ + 200) / 300;\n const opacity = (rotatedZ + 200) / 300;\n\n ctx.save();\n ctx.translate(\n canvas.width / 2 + rotatedX,\n canvas.height / 2 + rotatedY,\n );\n ctx.scale(scale, scale);\n ctx.globalAlpha = Math.max(0.2, opacity);\n /* ctx.globalAlpha = 1; */\n\n if (icons || images) {\n // Only try to render icons/images if they exist\n if (\n iconCanvasesRef.current[index] &&\n imagesLoadedRef.current[index]\n ) {\n ctx.drawImage(iconCanvasesRef.current[index], -20, -20, 40, 40);\n }\n } else {\n // Show numbered circles if no icons/images are provided\n ctx.beginPath();\n ctx.arc(0, 0, 20, 0, Math.PI * 2);\n ctx.fillStyle = \"#4444ff\";\n ctx.fill();\n ctx.fillStyle = \"white\";\n ctx.textAlign = \"center\";\n ctx.textBaseline = \"middle\";\n ctx.font = \"16px Arial\";\n ctx.fillText(`${icon.id + 1}`, 0, 0);\n }\n\n ctx.restore();\n });\n animationFrameRef.current = requestAnimationFrame(animate);\n };\n\n animate();\n\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current);\n }\n };\n }, [icons, images, iconPositions, isDragging, mousePos, targetRotation]);\n\n return (\n <canvas\n ref={canvasRef}\n width={400}\n height={400}\n onMouseDown={handleMouseDown}\n onMouseMove={handleMouseMove}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n className=\"rounded-lg\"\n aria-label=\"Interactive 3D Icon Cloud\"\n role=\"img\"\n />\n );\n}\n","type": "registry:ui","target": ""}diff --git a/registry/default/example/icon-cloud-demo-2.tsx b/registry/default/example/icon-cloud-demo-2.tsxindex 1f28618a..a2cd8dbe 100644--- a/registry/default/example/icon-cloud-demo-2.tsx+++ b/registry/default/example/icon-cloud-demo-2.tsx@@ -1,4 +1,4 @@-import IconCloud from "@/registry/default/magicui/icon-cloud";+import { IconCloud } from "@/registry/default/magicui/icon-cloud";const images = ["https://images.unsplash.com/photo-1720048171230-c60d162f93a0?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",@@ -6,15 +6,22 @@ const images = ["https://plus.unsplash.com/premium_photo-1675297844586-534b030564e0?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D","https://plus.unsplash.com/premium_photo-1675555581018-7f1a352ff9a6?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D","https://images.unsplash.com/photo-1719937050517-68d4e2a1702e?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://images.unsplash.com/photo-1720048171230-c60d162f93a0?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675553988173-a5249b5815fe?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675297844586-534b030564e0?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675555581018-7f1a352ff9a6?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D","https://images.unsplash.com/photo-1719937050517-68d4e2a1702e?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",- "https://plus.unsplash.com/premium_photo-1674747904717-fec17671e235?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://images.unsplash.com/photo-1720048171230-c60d162f93a0?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675553988173-a5249b5815fe?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675297844586-534b030564e0?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",+ "https://plus.unsplash.com/premium_photo-1675555581018-7f1a352ff9a6?q=80&w=1964&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D","https://images.unsplash.com/photo-1719937050517-68d4e2a1702e?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",];export default function IconCloudDemo() {return (- <div className="relative flex size-full max-w-lg items-center justify-center overflow-hidden rounded-lg border bg-background px-20 pb-20 pt-8 ">- <IconCloud imageArray={images} />+ <div className="relative flex size-full max-w-lg items-center justify-center overflow-hidden rounded-lg border bg-background">+ <IconCloud images={images} /></div>);}diff --git a/registry/default/example/icon-cloud-demo-3.tsx b/registry/default/example/icon-cloud-demo-3.tsxnew file mode 100644index 00000000..ff6ef149--- /dev/null+++ b/registry/default/example/icon-cloud-demo-3.tsx@@ -0,0 +1,165 @@+import { IconCloud } from "@/registry/default/magicui/icon-cloud";++const Icons = {+ gitHub: () => (+ <svg width="100" height="100" viewBox="0 0 438.549 438.549">+ <path+ fill="currentColor"+ d="M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"+ />+ </svg>+ ),+ notion: () => (+ <svg+ width="100"+ height="100"+ viewBox="0 0 100 100"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M6.017 4.313l55.333 -4.087c6.797 -0.583 8.543 -0.19 12.817 2.917l17.663 12.443c2.913 2.14 3.883 2.723 3.883 5.053v68.243c0 4.277 -1.553 6.807 -6.99 7.193L24.467 99.967c-4.08 0.193 -6.023 -0.39 -8.16 -3.113L3.3 79.94c-2.333 -3.113 -3.3 -5.443 -3.3 -8.167V11.113c0 -3.497 1.553 -6.413 6.017 -6.8z"+ fill="#ffffff"+ />+ <path+ d="M61.35 0.227l-55.333 4.087C1.553 4.7 0 7.617 0 11.113v60.66c0 2.723 0.967 5.053 3.3 8.167l13.007 16.913c2.137 2.723 4.08 3.307 8.16 3.113l64.257 -3.89c5.433 -0.387 6.99 -2.917 6.99 -7.193V20.64c0 -2.21 -0.873 -2.847 -3.443 -4.733L74.167 3.143c-4.273 -3.107 -6.02 -3.5 -12.817 -2.917zM25.92 19.523c-5.247 0.353 -6.437 0.433 -9.417 -1.99L8.927 11.507c-0.77 -0.78 -0.383 -1.753 1.557 -1.947l53.193 -3.887c4.467 -0.39 6.793 1.167 8.54 2.527l9.123 6.61c0.39 0.197 1.36 1.36 0.193 1.36l-54.933 3.307 -0.68 0.047zM19.803 88.3V30.367c0 -2.53 0.777 -3.697 3.103 -3.893L86 22.78c2.14 -0.193 3.107 1.167 3.107 3.693v57.547c0 2.53 -0.39 4.67 -3.883 4.863l-60.377 3.5c-3.493 0.193 -5.043 -0.97 -5.043 -4.083zm59.6 -54.827c0.387 1.75 0 3.5 -1.75 3.7l-2.91 0.577v42.773c-2.527 1.36 -4.853 2.137 -6.797 2.137 -3.107 0 -3.883 -0.973 -6.21 -3.887l-19.03 -29.94v28.967l6.02 1.363s0 3.5 -4.857 3.5l-13.39 0.777c-0.39 -0.78 0 -2.723 1.357 -3.11l3.497 -0.97v-38.3L30.48 40.667c-0.39 -1.75 0.58 -4.277 3.3 -4.473l14.367 -0.967 19.8 30.327v-26.83l-5.047 -0.58c-0.39 -2.143 1.163 -3.7 3.103 -3.89l13.4 -0.78z"+ fill="#000000"+ fillRule="evenodd"+ clipRule="evenodd"+ />+ </svg>+ ),+ openai: () => (+ <svg+ width="100"+ height="100"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ className="fill-black dark:fill-white"+ >+ <path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z" />+ </svg>+ ),+ googleDrive: () => (+ <svg+ width="100"+ height="100"+ viewBox="0 0 87.3 78"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="m6.6 66.85 3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8h-27.5c0 1.55.4 3.1 1.2 4.5z"+ fill="#0066da"+ />+ <path+ d="m43.65 25-13.75-23.8c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0 -1.2 4.5h27.5z"+ fill="#00ac47"+ />+ <path+ d="m73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5h-27.502l5.852 11.5z"+ fill="#ea4335"+ />+ <path+ d="m43.65 25 13.75-23.8c-1.35-.8-2.9-1.2-4.5-1.2h-18.5c-1.6 0-3.15.45-4.5 1.2z"+ fill="#00832d"+ />+ <path+ d="m59.8 53h-32.3l-13.75 23.8c1.35.8 2.9 1.2 4.5 1.2h50.8c1.6 0 3.15-.45 4.5-1.2z"+ fill="#2684fc"+ />+ <path+ d="m73.4 26.5-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3l-13.75 23.8 16.15 28h27.45c0-1.55-.4-3.1-1.2-4.5z"+ fill="#ffba00"+ />+ </svg>+ ),+ whatsapp: () => (+ <svg+ width="100"+ height="100"+ viewBox="0 0 175.216 175.552"+ xmlns="http://www.w3.org/2000/svg"+ >+ <defs>+ <linearGradient+ id="b"+ x1="85.915"+ x2="86.535"+ y1="32.567"+ y2="137.092"+ gradientUnits="userSpaceOnUse"+ >+ <stop offset="0" stopColor="#57d163" />+ <stop offset="1" stopColor="#23b33a" />+ </linearGradient>+ <filter+ id="a"+ width="1.115"+ height="1.114"+ x="-.057"+ y="-.057"+ colorInterpolationFilters="sRGB"+ >+ <feGaussianBlur stdDeviation="3.531" />+ </filter>+ </defs>+ <path+ d="m54.532 138.45 2.235 1.324c9.387 5.571 20.15 8.518 31.126 8.523h.023c33.707 0 61.139-27.426 61.153-61.135.006-16.335-6.349-31.696-17.895-43.251A60.75 60.75 0 0 0 87.94 25.983c-33.733 0-61.166 27.423-61.178 61.13a60.98 60.98 0 0 0 9.349 32.535l1.455 2.312-6.179 22.558zm-40.811 23.544L24.16 123.88c-6.438-11.154-9.825-23.808-9.821-36.772.017-40.556 33.021-73.55 73.578-73.55 19.681.01 38.154 7.669 52.047 21.572s21.537 32.383 21.53 52.037c-.018 40.553-33.027 73.553-73.578 73.553h-.032c-12.313-.005-24.412-3.094-35.159-8.954zm0 0"+ fill="#b3b3b3"+ filter="url(#a)"+ />+ <path+ d="m12.966 161.238 10.439-38.114a73.42 73.42 0 0 1-9.821-36.772c.017-40.556 33.021-73.55 73.578-73.55 19.681.01 38.154 7.669 52.047 21.572s21.537 32.383 21.53 52.037c-.018 40.553-33.027 73.553-73.578 73.553h-.032c-12.313-.005-24.412-3.094-35.159-8.954z"+ fill="#ffffff"+ />+ <path+ d="M87.184 25.227c-33.733 0-61.166 27.423-61.178 61.13a60.98 60.98 0 0 0 9.349 32.535l1.455 2.312-6.179 22.559 23.146-6.069 2.235 1.324c9.387 5.571 20.15 8.518 31.126 8.524h.023c33.707 0 61.14-27.426 61.153-61.135a60.75 60.75 0 0 0-17.895-43.251 60.75 60.75 0 0 0-43.235-17.929z"+ fill="url(#linearGradient1780)"+ />+ <path+ d="M87.184 25.227c-33.733 0-61.166 27.423-61.178 61.13a60.98 60.98 0 0 0 9.349 32.535l1.455 2.313-6.179 22.558 23.146-6.069 2.235 1.324c9.387 5.571 20.15 8.517 31.126 8.523h.023c33.707 0 61.14-27.426 61.153-61.135a60.75 60.75 0 0 0-17.895-43.251 60.75 60.75 0 0 0-43.235-17.928z"+ fill="url(#b)"+ />+ <path+ d="M68.772 55.603c-1.378-3.061-2.828-3.123-4.137-3.176l-3.524-.043c-1.226 0-3.218.46-4.902 2.3s-6.435 6.287-6.435 15.332 6.588 17.785 7.506 19.013 12.718 20.381 31.405 27.75c15.529 6.124 18.689 4.906 22.061 4.6s10.877-4.447 12.408-8.74 1.532-7.971 1.073-8.74-1.685-1.226-3.525-2.146-10.877-5.367-12.562-5.981-2.91-.919-4.137.921-4.746 5.979-5.819 7.206-2.144 1.381-3.984.462-7.76-2.861-14.784-9.124c-5.465-4.873-9.154-10.891-10.228-12.73s-.114-2.835.808-3.751c.825-.824 1.838-2.147 2.759-3.22s1.224-1.84 1.836-3.065.307-2.301-.153-3.22-4.032-10.011-5.666-13.647"+ fill="#ffffff"+ fillRule="evenodd"+ />+ </svg>+ ),+};++export default function IconCloudDemo() {+ return (+ <div className="relative flex size-full max-w-lg items-center justify-center overflow-hidden rounded-lg border bg-background">+ <IconCloud+ icons={[+ <Icons.gitHub key="github" />,+ <Icons.notion key="notion" />,+ <Icons.openai key="openai" />,+ <Icons.googleDrive key="gdrive" />,+ <Icons.whatsapp key="whatsapp" />,+ <Icons.gitHub key="github2" />,+ <Icons.notion key="notion2" />,+ <Icons.openai key="openai2" />,+ <Icons.googleDrive key="gdrive2" />,+ <Icons.whatsapp key="whatsapp2" />,+ <Icons.gitHub key="github3" />,+ <Icons.notion key="notion3" />,+ <Icons.openai key="openai3" />,+ <Icons.googleDrive key="gdrive3" />,+ <Icons.whatsapp key="whatsapp3" />,+ <Icons.gitHub key="github4" />,+ <Icons.notion key="notion4" />,+ <Icons.openai key="openai4" />,+ <Icons.googleDrive key="gdrive4" />,+ <Icons.whatsapp key="whatsapp4" />,+ <Icons.notion key="notion4" />,+ <Icons.openai key="openai4" />,+ <Icons.googleDrive key="gdrive4" />,+ <Icons.whatsapp key="whatsapp4" />,+ ]}+ />+ </div>+ );+}diff --git a/registry/default/example/icon-cloud-demo.tsx b/registry/default/example/icon-cloud-demo.tsxindex e1b3e2e4..85f92b4d 100644--- a/registry/default/example/icon-cloud-demo.tsx+++ b/registry/default/example/icon-cloud-demo.tsx@@ -1,4 +1,4 @@-import IconCloud from "@/registry/default/magicui/icon-cloud";+import { IconCloud } from "@/registry/default/magicui/icon-cloud";const slugs = ["typescript",@@ -34,9 +34,13 @@ const slugs = [];export default function IconCloudDemo() {+ const images = slugs.map(+ (slug) => `https://cdn.simpleicons.org/${slug}/${slug}`,+ );+return (- <div className="relative flex size-full max-w-lg items-center justify-center overflow-hidden rounded-lg border bg-background px-20 pb-20 pt-8 ">- <IconCloud iconSlugs={slugs} />+ <div className="relative flex size-full max-w-lg items-center justify-center overflow-hidden rounded-lg border bg-background">+ <IconCloud images={images} /></div>);}diff --git a/registry/default/magicui/icon-cloud.tsx b/registry/default/magicui/icon-cloud.tsxindex 7104d90f..1e9ffc2e 100644--- a/registry/default/magicui/icon-cloud.tsx+++ b/registry/default/magicui/icon-cloud.tsx@@ -1,111 +1,324 @@-/* eslint-disable @next/next/no-img-element */"use client";-import { useEffect, useMemo, useState } from "react";-import { useTheme } from "next-themes";-import {- Cloud,- fetchSimpleIcons,- ICloud,- renderSimpleIcon,- SimpleIcon,-} from "react-icon-cloud";--export type DynamicCloudProps = {- iconSlugs?: string[]; // Made iconSlugs optional- imageArray?: string[];-};--export const cloudProps: Omit<ICloud, "children"> = {- containerProps: {- style: {- display: "flex",- justifyContent: "center",- alignItems: "center",- width: "100%",- paddingTop: 40,- },- },- options: {- reverse: true,- depth: 1,- wheelZoom: false,- imageScale: 2,- activeCursor: "default",- tooltip: "native",- initial: [0.1, -0.1],- clickToFront: 500,- tooltipDelay: 0,- outlineColour: "#0000",- maxSpeed: 0.04,- minSpeed: 0.02,- // dragControl: false,- },-};--export const renderCustomIcon = (- icon: SimpleIcon,- theme: string,- imageArray?: string[],-) => {- const bgHex = theme === "light" ? "#f3f2ef" : "#080510";- const fallbackHex = theme === "light" ? "#6e6e73" : "#ffffff";- const minContrastRatio = theme === "dark" ? 2 : 1.2;-- return renderSimpleIcon({- icon,- bgHex,- fallbackHex,- minContrastRatio,- size: 42,- aProps: {- href: undefined,- target: undefined,- rel: undefined,- onClick: (e: React.MouseEvent<HTMLAnchorElement>) => e.preventDefault(),- },- });-};--type IconData = Awaited<ReturnType<typeof fetchSimpleIcons>>;--export default function IconCloud({- iconSlugs = [], // Default to an empty array if not provided- imageArray,-}: DynamicCloudProps) {- const [data, setData] = useState<IconData | null>(null);- const { theme } = useTheme();+import React, { useEffect, useRef, useState } from "react";+import { renderToString } from "react-dom/server";+interface Icon {+ x: number;+ y: number;+ z: number;+ scale: number;+ opacity: number;+ id: number;+}++interface IconCloudProps {+ icons?: React.ReactNode[];+ images?: string[];+}++function easeOutCubic(t: number): number {+ return 1 - Math.pow(1 - t, 3);+}++export function IconCloud({ icons, images }: IconCloudProps) {+ const canvasRef = useRef<HTMLCanvasElement>(null);+ const [iconPositions, setIconPositions] = useState<Icon[]>([]);+ const [rotation, setRotation] = useState({ x: 0, y: 0 });+ const [isDragging, setIsDragging] = useState(false);+ const [lastMousePos, setLastMousePos] = useState({ x: 0, y: 0 });+ const [mousePos, setMousePos] = useState({ x: 0, y: 0 });+ const [targetRotation, setTargetRotation] = useState<{+ x: number;+ y: number;+ startX: number;+ startY: number;+ distance: number;+ startTime: number;+ duration: number;+ } | null>(null);+ const animationFrameRef = useRef<number>();+ const rotationRef = useRef(rotation);+ const iconCanvasesRef = useRef<HTMLCanvasElement[]>([]);+ const imagesLoadedRef = useRef<boolean[]>([]);++ // Create icon canvases once when icons/images change+ useEffect(() => {+ if (!icons && !images) return;++ const items = icons || images || [];+ imagesLoadedRef.current = new Array(items.length).fill(false);++ const newIconCanvases = items.map((item, index) => {+ const offscreen = document.createElement("canvas");+ offscreen.width = 40;+ offscreen.height = 40;+ const offCtx = offscreen.getContext("2d");++ if (offCtx) {+ if (images) {+ // Handle image URLs directly+ const img = new Image();+ img.crossOrigin = "anonymous";+ img.src = items[index] as string;+ img.onload = () => {+ offCtx.clearRect(0, 0, offscreen.width, offscreen.height);++ // Create circular clipping path+ offCtx.beginPath();+ offCtx.arc(20, 20, 20, 0, Math.PI * 2);+ offCtx.closePath();+ offCtx.clip();++ // Draw the image+ offCtx.drawImage(img, 0, 0, 40, 40);++ imagesLoadedRef.current[index] = true;+ };+ } else {+ // Handle SVG icons+ offCtx.scale(0.4, 0.4);+ const svgString = renderToString(item as React.ReactElement);+ const img = new Image();+ img.src = "data:image/svg+xml;base64," + btoa(svgString);+ img.onload = () => {+ offCtx.clearRect(0, 0, offscreen.width, offscreen.height);+ offCtx.drawImage(img, 0, 0);+ imagesLoadedRef.current[index] = true;+ };+ }+ }+ return offscreen;+ });++ iconCanvasesRef.current = newIconCanvases;+ }, [icons, images]);++ // Generate initial icon positions on a sphereuseEffect(() => {- if (iconSlugs.length > 0) {- // Check if iconSlugs is not empty- fetchSimpleIcons({ slugs: iconSlugs }).then(setData);+ const items = icons || images || [];+ const newIcons: Icon[] = [];+ const numIcons = items.length || 20;++ // Fibonacci sphere parameters+ const offset = 2 / numIcons;+ const increment = Math.PI * (3 - Math.sqrt(5));++ for (let i = 0; i < numIcons; i++) {+ const y = i * offset - 1 + offset / 2;+ const r = Math.sqrt(1 - y * y);+ const phi = i * increment;++ const x = Math.cos(phi) * r;+ const z = Math.sin(phi) * r;++ newIcons.push({+ x: x * 100,+ y: y * 100,+ z: z * 100,+ scale: 1,+ opacity: 1,+ id: i,+ });+ }+ setIconPositions(newIcons);+ }, [icons, images]);++ // Handle mouse events+ const handleMouseDown = (e: React.MouseEvent<HTMLCanvasElement>) => {+ const rect = canvasRef.current?.getBoundingClientRect();+ if (!rect || !canvasRef.current) return;++ const x = e.clientX - rect.left;+ const y = e.clientY - rect.top;++ const ctx = canvasRef.current.getContext("2d");+ if (!ctx) return;++ iconPositions.forEach((icon) => {+ const cosX = Math.cos(rotationRef.current.x);+ const sinX = Math.sin(rotationRef.current.x);+ const cosY = Math.cos(rotationRef.current.y);+ const sinY = Math.sin(rotationRef.current.y);++ const rotatedX = icon.x * cosY - icon.z * sinY;+ const rotatedZ = icon.x * sinY + icon.z * cosY;+ const rotatedY = icon.y * cosX + rotatedZ * sinX;++ const screenX = canvasRef.current!.width / 2 + rotatedX;+ const screenY = canvasRef.current!.height / 2 + rotatedY;++ const scale = (rotatedZ + 200) / 300;+ const radius = 20 * scale;+ const dx = x - screenX;+ const dy = y - screenY;++ if (dx * dx + dy * dy < radius * radius) {+ const targetX = -Math.atan2(+ icon.y,+ Math.sqrt(icon.x * icon.x + icon.z * icon.z),+ );+ const targetY = Math.atan2(icon.x, icon.z);++ const currentX = rotationRef.current.x;+ const currentY = rotationRef.current.y;+ const distance = Math.sqrt(+ Math.pow(targetX - currentX, 2) + Math.pow(targetY - currentY, 2),+ );++ const duration = Math.min(2000, Math.max(800, distance * 1000));++ setTargetRotation({+ x: targetX,+ y: targetY,+ startX: currentX,+ startY: currentY,+ distance,+ startTime: performance.now(),+ duration,+ });+ return;+ }+ });++ setIsDragging(true);+ setLastMousePos({ x: e.clientX, y: e.clientY });+ };++ const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {+ const rect = canvasRef.current?.getBoundingClientRect();+ if (rect) {+ const x = e.clientX - rect.left;+ const y = e.clientY - rect.top;+ setMousePos({ x, y });+ }++ if (isDragging) {+ const deltaX = e.clientX - lastMousePos.x;+ const deltaY = e.clientY - lastMousePos.y;++ rotationRef.current = {+ x: rotationRef.current.x + deltaY * 0.002,+ y: rotationRef.current.y + deltaX * 0.002,+ };++ setLastMousePos({ x: e.clientX, y: e.clientY });}- }, [iconSlugs]);+ };++ const handleMouseUp = () => {+ setIsDragging(false);+ };++ // Animation and rendering+ useEffect(() => {+ const canvas = canvasRef.current;+ const ctx = canvas?.getContext("2d");+ if (!canvas || !ctx) return;++ const animate = () => {+ ctx.clearRect(0, 0, canvas.width, canvas.height);++ const centerX = canvas.width / 2;+ const centerY = canvas.height / 2;+ const maxDistance = Math.sqrt(centerX * centerX + centerY * centerY);+ const dx = mousePos.x - centerX;+ const dy = mousePos.y - centerY;+ const distance = Math.sqrt(dx * dx + dy * dy);+ const speed = 0.003 + (distance / maxDistance) * 0.01;++ if (targetRotation) {+ const elapsed = performance.now() - targetRotation.startTime;+ const progress = Math.min(1, elapsed / targetRotation.duration);+ const easedProgress = easeOutCubic(progress);++ rotationRef.current = {+ x:+ targetRotation.startX ++ (targetRotation.x - targetRotation.startX) * easedProgress,+ y:+ targetRotation.startY ++ (targetRotation.y - targetRotation.startY) * easedProgress,+ };++ if (progress >= 1) {+ setTargetRotation(null);+ }+ } else if (!isDragging) {+ rotationRef.current = {+ x: rotationRef.current.x + (dy / canvas.height) * speed,+ y: rotationRef.current.y + (dx / canvas.width) * speed,+ };+ }++ iconPositions.forEach((icon, index) => {+ const cosX = Math.cos(rotationRef.current.x);+ const sinX = Math.sin(rotationRef.current.x);+ const cosY = Math.cos(rotationRef.current.y);+ const sinY = Math.sin(rotationRef.current.y);++ const rotatedX = icon.x * cosY - icon.z * sinY;+ const rotatedZ = icon.x * sinY + icon.z * cosY;+ const rotatedY = icon.y * cosX + rotatedZ * sinX;++ const scale = (rotatedZ + 200) / 300;+ const opacity = Math.max(0.2, Math.min(1, (rotatedZ + 150) / 200));++ ctx.save();+ ctx.translate(+ canvas.width / 2 + rotatedX,+ canvas.height / 2 + rotatedY,+ );+ ctx.scale(scale, scale);+ ctx.globalAlpha = opacity;++ if (icons || images) {+ // Only try to render icons/images if they exist+ if (+ iconCanvasesRef.current[index] &&+ imagesLoadedRef.current[index]+ ) {+ ctx.drawImage(iconCanvasesRef.current[index], -20, -20, 40, 40);+ }+ } else {+ // Show numbered circles if no icons/images are provided+ ctx.beginPath();+ ctx.arc(0, 0, 20, 0, Math.PI * 2);+ ctx.fillStyle = "#4444ff";+ ctx.fill();+ ctx.fillStyle = "white";+ ctx.textAlign = "center";+ ctx.textBaseline = "middle";+ ctx.font = "16px Arial";+ ctx.fillText(`${icon.id + 1}`, 0, 0);+ }++ ctx.restore();+ });+ animationFrameRef.current = requestAnimationFrame(animate);+ };- const renderedIcons = useMemo(() => {- if (!data) return null;+ animate();- return Object.values(data.simpleIcons).map((icon) =>- renderCustomIcon(icon, theme || "light"),- );- }, [data, theme]);+ return () => {+ if (animationFrameRef.current) {+ cancelAnimationFrame(animationFrameRef.current);+ }+ };+ }, [icons, images, iconPositions, isDragging, mousePos, targetRotation]);return (- // @ts-ignore- <Cloud {...cloudProps}>- <>- <>{renderedIcons}</>- {imageArray &&- imageArray.length > 0 &&- imageArray.map((image, index) => {- return (- <a key={index} href="#" onClick={(e) => e.preventDefault()}>- <img height="42" width="42" alt="A globe" src={image} />- </a>- );- })}- </>- </Cloud>+ <canvas+ ref={canvasRef}+ width={400}+ height={400}+ onMouseDown={handleMouseDown}+ onMouseMove={handleMouseMove}+ onMouseUp={handleMouseUp}+ onMouseLeave={handleMouseUp}+ className="rounded-lg"+ aria-label="Interactive 3D Icon Cloud"+ role="img"+ />);}diff --git a/registry/registry-examples.ts b/registry/registry-examples.tsindex 022de88a..f6b7f062 100644--- a/registry/registry-examples.ts+++ b/registry/registry-examples.ts@@ -390,6 +390,12 @@ export const examples: Registry = [registryDependencies: ["icon-cloud"],files: ["example/icon-cloud-demo-2.tsx"],},+ {+ name: "icon-cloud-demo-3",+ type: "registry:example",+ registryDependencies: ["icon-cloud"],+ files: ["example/icon-cloud-demo-3.tsx"],+ },{name: "gradual-spacing-demo",type: "registry:example",diff --git a/registry/registry-ui.ts b/registry/registry-ui.tsindex 199e0a8c..0a933012 100644--- a/registry/registry-ui.ts+++ b/registry/registry-ui.ts@@ -455,7 +455,7 @@ export const ui: Registry = [{name: "icon-cloud",type: "registry:ui",- dependencies: ["next-themes", "react-icon-cloud"],+ dependencies: [],files: ["magicui/icon-cloud.tsx"],},{