@ludo.ninja/components 2.4.51 → 2.4.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,6 @@ import { TOpportunity } from './type';
2
2
  import { IProject } from "@ludo.ninja/api/build/graphql_tools/__generated__/opportunitiesHost/schema";
3
3
  import { Maybe } from "graphql/jsutils/Maybe";
4
4
  type OpportunityBackground = "green" | "blue" | "pink" | "orange" | "blue_pink" | "green_blue" | "yellow" | "blue_gray" | "gray";
5
- export declare const HEADER_BACKGROUNDS: OpportunityBackground[];
6
- export declare const HEADER_BACKGROUNDS_MAP: Record<string, OpportunityBackground>;
7
5
  export declare const OpportunityCard: ({ opportunity, toolsForRemove, headColorImage, }: {
8
6
  opportunity: TOpportunity & {
9
7
  project?: Maybe<Pick<IProject, "symbol" | "name" | "contract" | "originalMediaUrl" | "mediaUrl">>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OpportunityCard = exports.HEADER_BACKGROUNDS_MAP = exports.HEADER_BACKGROUNDS = void 0;
6
+ exports.OpportunityCard = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const useDislikeOpportunity_1 = require("../../api/server-opportunities/mutations/useDislikeOpportunity");
9
9
  const useLikeOpportunity_1 = require("../../api/server-opportunities/mutations/useLikeOpportunity");
@@ -11,6 +11,7 @@ const useOpenOpportunity_1 = __importDefault(require("../../api/server-opportuni
11
11
  const data_1 = __importDefault(require("../../entities/labelCreationType/data"));
12
12
  const vars_1 = require("../../fonts/vars");
13
13
  const OpportunityDropDown_1 = require("./OpportunityDropDown");
14
+ const generateCardSvgBackground_1 = require("./generateCardSvgBackground");
14
15
  const store_1 = require("../user/store");
15
16
  const heart_svg_1 = __importDefault(require("../../public/cards/heart"));
16
17
  const env_1 = require("../../store/env");
@@ -36,28 +37,6 @@ const moment_1 = __importDefault(require("moment/moment"));
36
37
  const react_1 = require("react");
37
38
  const sanitize_html_1 = __importDefault(require("sanitize-html"));
38
39
  const styled_components_1 = __importDefault(require("styled-components"));
39
- exports.HEADER_BACKGROUNDS = [
40
- "green",
41
- "blue",
42
- "pink",
43
- "orange",
44
- "blue_pink",
45
- "green_blue",
46
- "yellow",
47
- "blue_gray",
48
- "gray",
49
- ];
50
- exports.HEADER_BACKGROUNDS_MAP = {
51
- DePin: "green",
52
- GameFi: "pink",
53
- DeFi: "blue",
54
- MemeCoins: "orange",
55
- "All Projects": "blue_pink",
56
- "AI Agents": "green_blue",
57
- RWA: "yellow",
58
- Other: "blue_gray",
59
- "Token Graveyard": "gray",
60
- };
61
40
  const SWrapperLink = styled_components_1.default.a `
62
41
  position: relative;
63
42
  background-color: ${colors_2.WhiteColor};
@@ -95,7 +74,7 @@ const StyledCardHead = styled_components_1.default.div `
95
74
  display: flex;
96
75
  align-items: center;
97
76
 
98
- background-image: url("${({ backgroundImage }) => `${constants_1.staticLink}/background_images/${backgroundImage || exports.HEADER_BACKGROUNDS[0]}.svg`}");
77
+ background-image: url("${({ backgroundImage }) => backgroundImage}");
99
78
  background-size: cover;
100
79
  //.imgWrapper {
101
80
  // width: 100%;
@@ -361,9 +340,11 @@ const OpportunityCard = ({ opportunity, toolsForRemove, headColorImage, }) => {
361
340
  const sanitizedHtml = (0, sanitize_html_1.default)(opportunity?.description || "", {
362
341
  allowedTags: ["b", "i", "em", "strong", "br", "div"],
363
342
  });
364
- return ((0, jsx_runtime_1.jsxs)(SWrapperLink, { href: opportunityLink, target: "_blank", onClick: () => openOpportunityAction({ opportunityId: opportunity.opportunityId }), children: [(0, jsx_runtime_1.jsx)(StyledCardHead, { backgroundImage: headColorImage ||
365
- exports.HEADER_BACKGROUNDS_MAP[opportunity?.categoryName || "Other"] ||
366
- exports.HEADER_BACKGROUNDS_MAP["Other"], children: (0, jsx_runtime_1.jsx)(OpportunityName, { title: opportunity.name, children: opportunity.name }) }), (0, jsx_runtime_1.jsxs)(StyledCardContent, { children: [(0, jsx_runtime_1.jsx)("div", { className: "cardContent", children: (0, jsx_runtime_1.jsxs)("div", { className: "cardContentWrapper", children: [opportunity?.project && ((0, jsx_runtime_1.jsxs)(ProjectBlock, { children: [Boolean(opportunity?.project?.mediaUrl) && !isProjectIconErrorLoading && ((0, jsx_runtime_1.jsx)("img", { className: "icon", src: opportunity?.project?.mediaUrl
343
+ const svg = (0, generateCardSvgBackground_1.generateCardSvgBackground)(opportunity?.categoryName || "Other");
344
+ const backgroundImage = headColorImage
345
+ ? `${constants_1.staticLink}/background_images/${headColorImage}.svg`
346
+ : `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
347
+ return ((0, jsx_runtime_1.jsxs)(SWrapperLink, { href: opportunityLink, target: "_blank", onClick: () => openOpportunityAction({ opportunityId: opportunity.opportunityId }), children: [(0, jsx_runtime_1.jsx)(StyledCardHead, { backgroundImage: backgroundImage, children: (0, jsx_runtime_1.jsx)(OpportunityName, { title: opportunity.name, children: opportunity.name }) }), (0, jsx_runtime_1.jsxs)(StyledCardContent, { children: [(0, jsx_runtime_1.jsx)("div", { className: "cardContent", children: (0, jsx_runtime_1.jsxs)("div", { className: "cardContentWrapper", children: [opportunity?.project && ((0, jsx_runtime_1.jsxs)(ProjectBlock, { children: [Boolean(opportunity?.project?.mediaUrl) && !isProjectIconErrorLoading && ((0, jsx_runtime_1.jsx)("img", { className: "icon", src: opportunity?.project?.mediaUrl
367
348
  ? `${getMediaENVDomain()}/projects/${opportunity?.project.mediaUrl}`
368
349
  : opportunity?.project?.originalMediaUrl || "", alt: opportunity?.project?.name || opportunity?.projectContract, onError: () => {
369
350
  setIsProjectIconErrorLoading(true);
@@ -0,0 +1 @@
1
+ export declare const generateCardSvgBackground: (cardType: string, width?: number, height?: number) => string;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCardSvgBackground = void 0;
4
+ const djb2 = (str) => {
5
+ let h = 5381;
6
+ for (let i = 0; i < str.length; i++) {
7
+ h = ((h << 5) + h) ^ str.charCodeAt(i);
8
+ h = h >>> 0;
9
+ }
10
+ return h;
11
+ };
12
+ const fnv1a = (str) => {
13
+ let h = 0x811c9dc5;
14
+ for (let i = 0; i < str.length; i++) {
15
+ h ^= str.charCodeAt(i);
16
+ h = Math.imul(h, 0x01000193) >>> 0;
17
+ }
18
+ return h;
19
+ };
20
+ const unit = (n) => {
21
+ return (n >>> 0) / 0x100000000;
22
+ };
23
+ const hslToRgb = (h, s, l) => {
24
+ const sv = s / 100, lv = l / 100;
25
+ const c = (1 - Math.abs(2 * lv - 1)) * sv;
26
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
27
+ const m = lv - c / 2;
28
+ let r = 0, g = 0, b = 0;
29
+ if (h < 60) {
30
+ r = c;
31
+ g = x;
32
+ }
33
+ else if (h < 120) {
34
+ r = x;
35
+ g = c;
36
+ }
37
+ else if (h < 180) {
38
+ g = c;
39
+ b = x;
40
+ }
41
+ else if (h < 240) {
42
+ g = x;
43
+ b = c;
44
+ }
45
+ else if (h < 300) {
46
+ r = x;
47
+ b = c;
48
+ }
49
+ else {
50
+ r = c;
51
+ b = x;
52
+ }
53
+ return [Math.round((r + m) * 255), Math.round((g + m) * 255), Math.round((b + m) * 255)];
54
+ };
55
+ const toHex = (r, g, b) => {
56
+ return "#" + [r, g, b].map((v) => v.toString(16).padStart(2, "0").toUpperCase()).join("");
57
+ };
58
+ const getCardColors = (cardType) => {
59
+ const h1 = djb2(cardType), h2 = fnv1a(cardType), h3 = djb2(cardType + "\x00b"), h4 = fnv1a(cardType + "\x00c");
60
+ const baseHue = unit(h1) * 360;
61
+ const accentHue = (baseHue + 30 + unit(h2) * 60) % 360;
62
+ const isGrey = unit(h4) < 0.1;
63
+ const bgS = isGrey ? 10 + unit(h2) * 15 : 40 + unit(h2) * 40;
64
+ const bgL = isGrey ? 75 + unit(h3) * 10 : 78 + unit(h3) * 12;
65
+ const acS = isGrey ? 5 + unit(h3) * 10 : 85 + unit(h3) * 15;
66
+ const acL = isGrey ? 65 + unit(h1) * 10 : 55 + unit(h4) * 15;
67
+ const background = toHex(...hslToRgb(baseHue, bgS, bgL));
68
+ const accentHex = toHex(...hslToRgb(accentHue, acS, acL));
69
+ const alpha = Math.round(0.9 * 255)
70
+ .toString(16)
71
+ .toUpperCase();
72
+ return { background, accentHex, accent: accentHex + alpha };
73
+ };
74
+ const generateCardSvgBackground = (cardType, width = 252, height = 40) => {
75
+ const { background, accentHex } = BASE_LABEL_COLORS[cardType.toLowerCase()] || getCardColors(cardType);
76
+ const sid = cardType.replace(/[^a-zA-Z0-9]/g, "_");
77
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" fill="none">
78
+ <g clip-path="url(#c_${sid})">
79
+ <rect width="${width}" height="${height}" fill="${background}"/>
80
+ <g opacity="0.5" filter="url(#f_${sid})">
81
+ <ellipse cx="44.9994" cy="-28.3162" rx="113.177" ry="82.5021" transform="rotate(165.754 44.9994 -28.3162)" fill="${accentHex}" fill-opacity="0.9"/>
82
+ </g>
83
+ </g>
84
+ <defs>
85
+ <filter id="f_${sid}" x="-140.58" y="-187.016" width="371.159" height="317.399" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
86
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
87
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
88
+ <feGaussianBlur stdDeviation="37" result="effect1_foregroundBlur"/>
89
+ </filter>
90
+ <clipPath id="c_${sid}"><rect width="${width}" height="${height}" fill="white"/></clipPath>
91
+ </defs>
92
+ </svg>`;
93
+ };
94
+ exports.generateCardSvgBackground = generateCardSvgBackground;
95
+ const BASE_LABEL_COLORS = {
96
+ depin: { background: "#8DEC8A", accentHex: "#5EC1FF" },
97
+ gamefi: { background: "#DCAEFF", accentHex: "#FC58FF" },
98
+ defi: { background: "#A7ADFF", accentHex: "#58EBFF" },
99
+ memecoins: { background: "#FFD873", accentHex: "#FF5888" },
100
+ "all projects": { background: "#F4A7FF", accentHex: "#07DEFF" },
101
+ "ai agents": { background: "#8AE1F6", accentHex: "#4BED9C" },
102
+ rwa: { background: "#EBDEB4", accentHex: "#FFC328" },
103
+ other: { background: "#D0CDE1", accentHex: "#AA99F6" },
104
+ "token graveyard": { background: "#CECECE", accentHex: "#9E9E9E" },
105
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ludo.ninja/components",
3
- "version": "2.4.51",
3
+ "version": "2.4.52",
4
4
  "private": false,
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",