|
1 | 1 | <script> |
2 | | - import { browser } from "$app/environment"; |
3 | 2 | import Button from "$lib/components/Button.svelte"; |
4 | 3 | import Loader from "$lib/components/Loader.svelte"; |
5 | 4 | import ProgressBar from "$lib/components/ProgressBar.svelte"; |
6 | | - import { colourScheme } from "$lib/store"; |
7 | 5 | import { checkImageExists } from "$lib/utils"; |
8 | | - import { afterUpdate, onMount } from "svelte"; |
9 | 6 | import { locale } from "svelte-i18n"; |
10 | 7 |
|
11 | 8 | export let project; |
12 | 9 | export let href; |
13 | 10 |
|
14 | 11 | let currencyOptions = { style: "currency", currency: "USD", maximumFractionDigits: 0 }; |
15 | | - let cardImageContainer; |
16 | | - let canvasWidth = 0; |
17 | | - let canvasHeight = 0; |
18 | | - let isMobile = false; |
19 | | - let redrawKey = 0; // To force component redraw |
20 | | -
|
21 | | - /** |
22 | | - * Predefined Color Palettes |
23 | | - * |
24 | | - * Instead of dynamically generating colors, we use curated lists of pastel colors |
25 | | - * that provide consistent, aesthetically pleasing visuals: |
26 | | - * |
27 | | - * - darkPastels: Used as backgrounds in light mode |
28 | | - * - lightPastels: Used as backgrounds in dark mode |
29 | | - * |
30 | | - * Foreground colors are simplified: |
31 | | - * - Light mode: White with 0.5 alpha |
32 | | - * - Dark mode: Black with 0.5 alpha |
33 | | - */ |
34 | | -
|
35 | | - // List of 12 dark pastel colors for light mode backgrounds - in RGB format |
36 | | - const darkPastels = [ |
37 | | - [142, 85, 114], // Dark mauve |
38 | | - [76, 109, 129], // Slate blue |
39 | | - [110, 76, 125], // Plum |
40 | | - [84, 120, 108], // Pine |
41 | | - [87, 125, 90], // Forest green |
42 | | - [138, 97, 65], // Cinnamon |
43 | | - [93, 93, 105], // Pewter |
44 | | - [125, 90, 60], // Russet |
45 | | - [120, 71, 80], // Rusty rose |
46 | | - [72, 99, 118], // Steel blue |
47 | | - [117, 96, 54], // Bronze |
48 | | - [95, 83, 121] // Dusty purple |
49 | | - ]; |
50 | | -
|
51 | | - // List of 12 light pastel colors for dark mode backgrounds - in RGB format |
52 | | - const lightPastels = [ |
53 | | - [245, 213, 226], // Light pink |
54 | | - [209, 231, 245], // Baby blue |
55 | | - [215, 241, 217], // Mint |
56 | | - [245, 226, 204], // Peach |
57 | | - [230, 213, 245], // Lavender |
58 | | - [225, 225, 235], // Platinum |
59 | | - [241, 227, 207], // Cream |
60 | | - [209, 238, 230], // Seafoam |
61 | | - [245, 215, 219], // Blush |
62 | | - [217, 233, 244], // Powder blue |
63 | | - [238, 232, 205], // Beige |
64 | | - [226, 219, 241] // Periwinkle |
65 | | - ]; |
66 | | -
|
67 | | - // Foreground colors will always be white/black with alpha |
68 | | - const fgColors = { |
69 | | - light: [0, 0, 0], |
70 | | - dark: [255, 255, 255] |
71 | | - }; |
72 | | -
|
73 | | - // Select a random index for the color palettes (0-11) |
74 | | - const colorIndex = Math.floor(Math.random() * 12); |
75 | | -
|
76 | | - // Create effect parameters (keeping some of the existing logic for visual variety) |
77 | | - const effectParams = { |
78 | | - linesCount: 10, |
79 | | - stroke: 1, |
80 | | - strokeAlpha: 50, |
81 | | - }; |
82 | | -
|
83 | | - // Background colors based on the randomly selected index |
84 | | - const bgColors = { |
85 | | - light: lightPastels[colorIndex], |
86 | | - dark: darkPastels[colorIndex] |
87 | | - }; |
88 | | -
|
89 | | - // Calculate dimensions based on container width and device size |
90 | | - const calculateDimensions = () => { |
91 | | - if (!cardImageContainer || !browser) return; |
92 | | -
|
93 | | - // Get the container width |
94 | | - const containerWidth = cardImageContainer.clientWidth; |
95 | | - const newIsMobile = window.innerWidth < 768; // Matches the md: breakpoint in Tailwind |
96 | | -
|
97 | | - // Only update if dimensions actually changed |
98 | | - if (canvasWidth !== containerWidth || isMobile !== newIsMobile) { |
99 | | - canvasWidth = containerWidth; |
100 | | - isMobile = newIsMobile; |
101 | | -
|
102 | | - // Set height based on aspect ratio |
103 | | - if (isMobile) { |
104 | | - // Square aspect ratio (1:1) for mobile |
105 | | - canvasHeight = containerWidth; |
106 | | - } else { |
107 | | - // Video aspect ratio (16:9) for larger screens |
108 | | - canvasHeight = containerWidth * (9 / 16); |
109 | | - } |
110 | | -
|
111 | | - // Increment redraw key to force DynamicBg to reinitialize |
112 | | - redrawKey++; |
113 | | - } |
114 | | - } |
115 | 12 |
|
116 | 13 | const imageExists = async () => await checkImageExists(project.image) ? true : false; |
117 | 14 |
|
118 | | - onMount(() => { |
119 | | - if (browser) { |
120 | | - calculateDimensions(); |
121 | | - window.addEventListener("resize", calculateDimensions); |
122 | | -
|
123 | | - return () => { |
124 | | - window.removeEventListener("resize", calculateDimensions); |
125 | | - }; |
126 | | - } |
127 | | - }); |
128 | | -
|
129 | | - afterUpdate(() => { |
130 | | - if (browser) { |
131 | | - calculateDimensions(); |
132 | | - } |
133 | | - }); |
134 | | -
|
135 | | - console.log(project); |
136 | | -
|
137 | | - $: progress = Math.min(project.donations.progress, 100); |
138 | | -
|
139 | | - // Recalculate dimensions when the window resizes |
140 | | - $: if (browser && typeof window !== "undefined") { |
141 | | - window.innerWidth; // This creates a dependency on window.innerWidth |
142 | | - setTimeout(calculateDimensions, 0); // Schedule recalculation |
143 | | - } |
144 | | -
|
145 | | - // Trigger redraw when color scheme changes |
146 | | - $: if ($colourScheme) { |
147 | | - redrawKey++; // Force redraw when color scheme changes |
148 | | - } |
| 15 | + $: progress = Math.min(project.donations?.progress || 0, 100); |
149 | 16 | </script> |
150 | 17 |
|
151 | 18 | <div class="group"> |
152 | 19 | <div class="card"> |
153 | | - <div class="card-image" bind:this={cardImageContainer}> |
| 20 | + <div class="card-image"> |
154 | 21 | {#await project.image && imageExists()} |
155 | 22 | <Loader /> |
156 | 23 | {:then} |
|
186 | 53 | {/if} |
187 | 54 | {#if project.button && href} |
188 | 55 | <div class="button-container"> |
189 | | - <Button text={project.button.text} highlight={true} icon="donate" iconSize={24} textSize="lg" {href} /> |
| 56 | + <Button text={project.button.text} highlight={true} icon="info" iconSize={20} textSize="md" {href} /> |
190 | 57 | </div> |
191 | 58 | {/if} |
192 | 59 | </div> |
|
0 commit comments