@hoangyell/gallery 1.2.1 → 1.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Gallery.astro +30 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoangyell/gallery",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Astro image gallery with lightbox, pyramid multi-row layout, and accessible controls.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/Gallery.astro CHANGED
@@ -12,6 +12,8 @@ export interface GalleryItemInput {
12
12
  src: string;
13
13
  alt?: string;
14
14
  fit?: ObjectFit;
15
+ width?: number;
16
+ height?: number;
15
17
  }
16
18
 
17
19
  export interface Props {
@@ -48,7 +50,23 @@ const {
48
50
  const rawItems = Array.isArray(Astro.props.items) ? Astro.props.items : [];
49
51
  const rawAlts = Array.isArray(Astro.props.alts) ? Astro.props.alts : [];
50
52
 
51
- type GalleryItem = { src: string; alt: string; fit: string };
53
+ type GalleryItem = {
54
+ src: string;
55
+ alt: string;
56
+ fit: string;
57
+ width: number;
58
+ height: number;
59
+ };
60
+
61
+ function defaultDimensions(
62
+ fitMode: ObjectFit,
63
+ orient: "landscape" | "portrait",
64
+ ): { width: number; height: number } {
65
+ if (orient === "portrait") return { width: 900, height: 1200 };
66
+ return fitMode === "contain"
67
+ ? { width: 1600, height: 900 }
68
+ : { width: 1200, height: 900 };
69
+ }
52
70
 
53
71
  function altFromUrl(url: string): string {
54
72
  try {
@@ -69,17 +87,22 @@ const resolvedFit: ObjectFit = explicitFit || defaultFit;
69
87
  const galleryItems: GalleryItem[] = rawItems
70
88
  .map((item, i) => {
71
89
  if (typeof item === "string") {
90
+ const dims = defaultDimensions(resolvedFit, orientation);
72
91
  return {
73
92
  src: item,
74
93
  alt: rawAlts[i] || altFromUrl(item),
75
94
  fit: String(resolvedFit),
95
+ ...dims,
76
96
  };
77
97
  }
78
98
  const itemFit = item?.fit || resolvedFit;
99
+ const dims = defaultDimensions(itemFit, orientation);
79
100
  return {
80
101
  src: item?.src || "",
81
102
  alt: item?.alt || rawAlts[i] || altFromUrl(item?.src || ""),
82
103
  fit: String(itemFit),
104
+ width: item?.width && item.width > 0 ? item.width : dims.width,
105
+ height: item?.height && item.height > 0 ? item.height : dims.height,
83
106
  };
84
107
  })
85
108
  .filter((item) => item.src !== "");
@@ -148,10 +171,12 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
148
171
  <img
149
172
  src={item.src}
150
173
  alt={item.alt}
174
+ width={item.width}
175
+ height={item.height}
151
176
  loading="lazy"
152
177
  decoding="async"
153
178
  class="hy-gallery-img"
154
- style={`object-fit: ${item.fit} !important;`}
179
+ style={`object-fit: ${item.fit} !important; aspect-ratio: auto ${item.width} / ${item.height};`}
155
180
  />
156
181
  </button>
157
182
  );
@@ -166,6 +191,7 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
166
191
  <style>
167
192
  /* ── Custom properties (override on .hy-gallery or :root) ── */
168
193
  .hy-gallery {
194
+ color-scheme: light dark;
169
195
  --hy-gallery-gap: 4px;
170
196
  --hy-gallery-radius: 1rem;
171
197
  --hy-gallery-bg: #f8fafc;
@@ -191,6 +217,7 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
191
217
  /* Explicit light theme on any ancestor wins over OS preference.
192
218
  Supports Tailwind-style `.light` class and `[data-theme="light"]`. */
193
219
  :where(.light, [data-theme="light"]) .hy-gallery {
220
+ color-scheme: light;
194
221
  --hy-gallery-bg: #f8fafc;
195
222
  --hy-gallery-overlay-bg: rgba(255, 255, 255, 0.7);
196
223
  --hy-gallery-accent: #2563eb;
@@ -202,6 +229,7 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
202
229
  /* Explicit dark theme on any ancestor wins over OS preference.
203
230
  Supports Tailwind-style `.dark` class and `[data-theme="dark"]`. */
204
231
  :where(.dark, [data-theme="dark"]) .hy-gallery {
232
+ color-scheme: dark;
205
233
  --hy-gallery-bg: #0f172a;
206
234
  --hy-gallery-overlay-bg: rgba(2, 6, 23, 0.8);
207
235
  --hy-gallery-accent: #60a5fa;
@@ -299,7 +327,6 @@ if (resolvedRows <= 1 || galleryItems.length <= 1) {
299
327
  padding: 0;
300
328
  object-fit: cover;
301
329
  object-position: center;
302
- aspect-ratio: auto;
303
330
  max-width: none;
304
331
  max-height: none;
305
332
  transform-origin: center;