|
| 1 | +import React from "react"; |
| 2 | +import classNames from "classnames"; |
| 3 | +import { Speaker } from "types/con"; |
| 4 | + |
| 5 | +interface SpeakerImageProps { |
| 6 | + image: string; |
| 7 | + placeholder?: string; |
| 8 | + hoverable?: boolean; |
| 9 | + big?: boolean; |
| 10 | + speaker: Speaker; |
| 11 | +} |
| 12 | + |
| 13 | +function nameToAngle(name: string): number { |
| 14 | + // Calcule l'angle (en degrés) de 0 à 360 |
| 15 | + let hash = 0; |
| 16 | + for (let i = 0; i < name.length; i++) { |
| 17 | + hash += name.charCodeAt(i); |
| 18 | + } |
| 19 | + let angle = hash % 360; |
| 20 | + |
| 21 | + // Plages interdites (en degrés) |
| 22 | + const forbiddenZones: [number, number][] = [ |
| 23 | + [60, 120], |
| 24 | + [240, 300], |
| 25 | + ]; |
| 26 | + |
| 27 | + // Corrige si dans une zone interdite |
| 28 | + for (const [start, end] of forbiddenZones) { |
| 29 | + if (angle >= start && angle < end) { |
| 30 | + angle = end; // Déplace à la fin de la zone interdite |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + return angle * (Math.PI / 180); |
| 35 | +} |
| 36 | + |
| 37 | +function nameToSize(name: string, min = 10, max = 30) { |
| 38 | + let hash = 0; |
| 39 | + for (let i = 0; i < name.length; i++) { |
| 40 | + hash += (i + 1) * name.charCodeAt(i); |
| 41 | + } |
| 42 | + const range = max - min; |
| 43 | + return min + (hash % range); |
| 44 | +} |
| 45 | + |
| 46 | +function cssPositionOnCircle(angle: number) { |
| 47 | + // angle en radians |
| 48 | + return { |
| 49 | + x: `calc(50% + ${Math.cos(angle) * 50}%)`, |
| 50 | + y: `calc(50% + ${Math.sin(angle) * 50}%)`, |
| 51 | + x2: `calc(50% + ${Math.cos(angle + Math.PI) * 50}%)`, |
| 52 | + y2: `calc(50% + ${Math.sin(angle + Math.PI) * 50}%)`, |
| 53 | + }; |
| 54 | +} |
| 55 | + |
| 56 | +export default function SpeakerImage({ |
| 57 | + image, |
| 58 | + placeholder, |
| 59 | + big = false, |
| 60 | + hoverable = true, |
| 61 | + speaker, |
| 62 | +}: SpeakerImageProps) { |
| 63 | + if (speaker.edition === "2025") { |
| 64 | + const { name } = speaker; |
| 65 | + const angle = nameToAngle(name); |
| 66 | + const size = nameToSize(name); |
| 67 | + const pos = cssPositionOnCircle(angle); |
| 68 | + return ( |
| 69 | + <> |
| 70 | + <svg width="0" height="0"> |
| 71 | + <clipPath id={`clip-${speaker.id}`} clipPathUnits="objectBoundingBox"> |
| 72 | + <path |
| 73 | + d={ |
| 74 | + speaker.path || |
| 75 | + "M1,0 H0 V0.55125 H0.13225 c-0.00475,0.02385,-0.00725,0.0485,-0.00725,0.07375 c0,0.2071,0.1679,0.375,0.375,0.375 s0.375,-0.1679,0.375,-0.375 c0,-0.02525,-0.0025,-0.0499,-0.00725,-0.07375 H1 V0 Z" |
| 76 | + } |
| 77 | + /> |
| 78 | + </clipPath> |
| 79 | + </svg> |
| 80 | + <div |
| 81 | + className={classNames( |
| 82 | + "w-full h-full relative bg-white rounded-full transition-all duration-500", |
| 83 | + hoverable && "group-hover:bg-blue-light " |
| 84 | + )} |
| 85 | + > |
| 86 | + <div |
| 87 | + className={classNames( |
| 88 | + "relative w-full h-full before:absolute before:w-[110%] before:h-[110%] before:left-1/2 before:top-1/2 before:-translate-x-1/2 before:-translate-y-1/2 before:pointer-events-none before:transition-all before:bg-circle before:bg-no-repeat before:duration-700 before:ease-out", |
| 89 | + hoverable && "group-hover:before:rotate-45" |
| 90 | + )} |
| 91 | + > |
| 92 | + <div |
| 93 | + className="aspect-square overflow-hidden w-[calc(400%/3)] pointer-events-none max-w-none absolute z-10 bottom-0 left-1/2 -translate-x-1/2" |
| 94 | + style={{ clipPath: `url(#clip-${speaker.id})` }} |
| 95 | + > |
| 96 | + <img |
| 97 | + src={image} |
| 98 | + className={classNames( |
| 99 | + "w-full h-full transition-all duration-500 will-change-transform origin-center", |
| 100 | + big && "scale-110", |
| 101 | + hoverable && "group-hover:-rotate-2 group-hover:scale-110 " |
| 102 | + )} |
| 103 | + alt="" |
| 104 | + /> |
| 105 | + </div> |
| 106 | + <div |
| 107 | + className={classNames( |
| 108 | + "absolute aspect-square -translate-x-1/2 -translate-y-1/2 transition-all duration-700", |
| 109 | + big && "scale-[150%]", |
| 110 | + hoverable && "group-hover:scale-[200%]" |
| 111 | + )} |
| 112 | + style={{ |
| 113 | + left: pos.x, |
| 114 | + top: pos.y, |
| 115 | + width: `${size}%`, |
| 116 | + }} |
| 117 | + > |
| 118 | + <div |
| 119 | + className={classNames( |
| 120 | + "bg-pink/20 animate-float rounded-full size-full", |
| 121 | + big && "scale-[150%]" |
| 122 | + )} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + <div |
| 126 | + className={classNames( |
| 127 | + "absolute z-20 aspect-square -translate-x-1/2 -translate-y-1/2 transition-all duration-700", |
| 128 | + hoverable && "group-hover:scale-[40%]" |
| 129 | + )} |
| 130 | + style={{ |
| 131 | + left: pos.x2, |
| 132 | + top: pos.y2, |
| 133 | + width: `${50 - size}%`, |
| 134 | + }} |
| 135 | + > |
| 136 | + <div |
| 137 | + className={classNames( |
| 138 | + "bg-blue/30 animate-float2 rounded-full size-full", |
| 139 | + big && "scale-[60%]" |
| 140 | + )} |
| 141 | + /> |
| 142 | + </div> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + </> |
| 146 | + ); |
| 147 | + } |
| 148 | +} |
0 commit comments