smart-glide-react 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/index.d.mts +241 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.js +436 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +421 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next.d.mts +21 -0
- package/dist/next.d.ts +21 -0
- package/dist/next.js +21 -0
- package/dist/next.js.map +1 -0
- package/dist/next.mjs +16 -0
- package/dist/next.mjs.map +1 -0
- package/dist/server.d.mts +112 -0
- package/dist/server.d.ts +112 -0
- package/dist/server.js +83 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +79 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shadi Shammaa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# smart-glide-react
|
|
2
|
+
|
|
3
|
+
> Official React & Next.js SDK for [Laravel Smart Glide](https://github.com/shammaa/laravel-smart-glide).
|
|
4
|
+
> Responsive images · Blur placeholders · AVIF/WebP auto-negotiation · JSON-LD SEO · Next.js ISR support.
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/smart-glide-react)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](../../LICENSE)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install smart-glide-react
|
|
16
|
+
# or
|
|
17
|
+
pnpm add smart-glide-react
|
|
18
|
+
# or
|
|
19
|
+
yarn add smart-glide-react
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### 1. Set up environment variables
|
|
27
|
+
|
|
28
|
+
```env
|
|
29
|
+
# .env.local (Next.js)
|
|
30
|
+
NEXT_PUBLIC_SMART_GLIDE_URL=https://your-laravel-app.com
|
|
31
|
+
NEXT_PUBLIC_SMART_GLIDE_DELIVERY_PATH=/img
|
|
32
|
+
NEXT_PUBLIC_SMART_GLIDE_DATA_PATH=/img-data
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Wrap your app with the Provider
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// app/layout.tsx (Next.js App Router)
|
|
39
|
+
import { SmartGlideProvider } from 'smart-glide-react';
|
|
40
|
+
|
|
41
|
+
export default function RootLayout({ children }) {
|
|
42
|
+
return (
|
|
43
|
+
<SmartGlideProvider
|
|
44
|
+
config={{ baseUrl: process.env.NEXT_PUBLIC_SMART_GLIDE_URL }}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</SmartGlideProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Use the component
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { SmartGlideImage } from 'smart-glide-react';
|
|
56
|
+
|
|
57
|
+
export default function ProductCard() {
|
|
58
|
+
return (
|
|
59
|
+
<SmartGlideImage
|
|
60
|
+
path="products/phone.jpg"
|
|
61
|
+
alt="Awesome Phone"
|
|
62
|
+
profile="hero"
|
|
63
|
+
responsive="retina"
|
|
64
|
+
width={800}
|
|
65
|
+
height={600}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## `<SmartGlideImage>`
|
|
74
|
+
|
|
75
|
+
The main image component — drop-in for `next/image` or a plain `<img>`.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<SmartGlideImage
|
|
79
|
+
// Required
|
|
80
|
+
path="home/hero.jpg"
|
|
81
|
+
alt="Hero banner"
|
|
82
|
+
|
|
83
|
+
// Profile & responsive
|
|
84
|
+
profile="hero" // named compression profile
|
|
85
|
+
responsive="fhd" // named responsive set | [640, 960, 1280] | false
|
|
86
|
+
|
|
87
|
+
// LCP / priority
|
|
88
|
+
priority // fetchpriority="high" + loading="eager"
|
|
89
|
+
|
|
90
|
+
// Blur placeholder
|
|
91
|
+
placeholder="blur" // show blurred LQIP while loading
|
|
92
|
+
blurPlaceholder // fetch blur data from API
|
|
93
|
+
|
|
94
|
+
// SEO
|
|
95
|
+
schema // emit JSON-LD <ImageObject> after <img>
|
|
96
|
+
|
|
97
|
+
// Layout
|
|
98
|
+
width={1600}
|
|
99
|
+
height={900}
|
|
100
|
+
aspectRatio="16 / 9"
|
|
101
|
+
|
|
102
|
+
// Extra Glide params
|
|
103
|
+
params={{ fit: 'crop', focus: 'center' }}
|
|
104
|
+
|
|
105
|
+
// Config override (if not using Provider)
|
|
106
|
+
baseUrl="https://api.example.com"
|
|
107
|
+
|
|
108
|
+
// All native <img> attributes
|
|
109
|
+
className="rounded-xl shadow"
|
|
110
|
+
style={{ objectFit: 'cover' }}
|
|
111
|
+
onLoad={() => console.log('loaded!')}
|
|
112
|
+
/>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Props
|
|
116
|
+
|
|
117
|
+
| Prop | Type | Default | Description |
|
|
118
|
+
|------|------|---------|-------------|
|
|
119
|
+
| `path` | `string` | **required** | Relative image path inside Smart Glide source |
|
|
120
|
+
| `alt` | `string` | **required** | Alt text (accessibility + SEO) |
|
|
121
|
+
| `profile` | `ImageProfile` | `"default"` | Named compression profile |
|
|
122
|
+
| `responsive` | `string \| number[] \| false` | `"retina"` | Breakpoints for `srcset` |
|
|
123
|
+
| `priority` | `boolean` | `false` | LCP image — high fetch priority + eager loading |
|
|
124
|
+
| `placeholder` | `"blur" \| "empty"` | `"empty"` | Blur LQIP while loading |
|
|
125
|
+
| `blurPlaceholder` | `boolean` | `false` | Fetch blur data URI from API |
|
|
126
|
+
| `schema` | `boolean` | `false` | Emit JSON-LD `ImageObject` |
|
|
127
|
+
| `aspectRatio` | `string` | — | CSS `aspect-ratio` value |
|
|
128
|
+
| `params` | `Record<string, string\|number>` | `{}` | Extra Glide params |
|
|
129
|
+
| `baseUrl` | `string` | env var | Laravel app base URL |
|
|
130
|
+
| `fetchOptions` | `RequestInit` | — | Options forwarded to `fetch()` |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## `<SmartGlidePicture>`
|
|
135
|
+
|
|
136
|
+
Render `<picture>` with multiple `<source>` breakpoints.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { SmartGlidePicture } from 'smart-glide-react';
|
|
140
|
+
|
|
141
|
+
<SmartGlidePicture
|
|
142
|
+
path="gallery/feature.jpg"
|
|
143
|
+
alt="Feature image"
|
|
144
|
+
sources={[
|
|
145
|
+
{
|
|
146
|
+
media: '(min-width: 1200px)',
|
|
147
|
+
widths: [1200],
|
|
148
|
+
params: { fit: 'crop', w: 1200, h: 675 },
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
media: '(min-width: 768px)',
|
|
152
|
+
widths: [900],
|
|
153
|
+
params: { w: 900, h: 506 },
|
|
154
|
+
},
|
|
155
|
+
]}
|
|
156
|
+
profile="default"
|
|
157
|
+
width={900}
|
|
158
|
+
height={506}
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## `<SmartGlideBackground>`
|
|
165
|
+
|
|
166
|
+
CSS background-image with responsive media queries.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { SmartGlideBackground } from 'smart-glide-react';
|
|
170
|
+
|
|
171
|
+
<SmartGlideBackground
|
|
172
|
+
path="banners/summit.jpg"
|
|
173
|
+
profile="hero"
|
|
174
|
+
responsive="hero"
|
|
175
|
+
aria-label="Annual summit banner"
|
|
176
|
+
className="h-screen"
|
|
177
|
+
>
|
|
178
|
+
<h1>Welcome</h1>
|
|
179
|
+
</SmartGlideBackground>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Hooks
|
|
185
|
+
|
|
186
|
+
### `useSmartGlide` — fetch from API
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useSmartGlide } from 'smart-glide-react';
|
|
190
|
+
|
|
191
|
+
function MyImage() {
|
|
192
|
+
const { src, srcset, sizes, blurDataUrl, isLoading, error } = useSmartGlide({
|
|
193
|
+
path: 'products/phone.jpg',
|
|
194
|
+
profile: 'hero',
|
|
195
|
+
responsive: 'retina',
|
|
196
|
+
blurPlaceholder: true,
|
|
197
|
+
schema: true,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (isLoading) return <Skeleton />;
|
|
201
|
+
if (error) return <ErrorState />;
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<img src={src} srcSet={srcset ?? undefined} sizes={sizes ?? undefined} alt="Phone" />
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `useSmartGlideStatic` — no API call
|
|
210
|
+
|
|
211
|
+
Builds URLs entirely client-side. **URLs are unsigned** — use only when `SMART_GLIDE_SECURE=false`.
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { useSmartGlideStatic } from 'smart-glide-react';
|
|
215
|
+
|
|
216
|
+
const { src, srcset, sizes } = useSmartGlideStatic({
|
|
217
|
+
path: 'products/phone.jpg',
|
|
218
|
+
profile: 'thumbnail',
|
|
219
|
+
responsive: [320, 640, 960],
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Server-Side Data Fetching (Next.js App Router)
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
// app/products/[id]/page.tsx — Server Component
|
|
229
|
+
import { fetchSmartGlideData } from 'smart-glide-react/server';
|
|
230
|
+
|
|
231
|
+
export default async function ProductPage({ params }) {
|
|
232
|
+
const image = await fetchSmartGlideData({
|
|
233
|
+
path: `products/${params.id}.jpg`,
|
|
234
|
+
profile: 'hero',
|
|
235
|
+
responsive: 'retina',
|
|
236
|
+
blurPlaceholder: true,
|
|
237
|
+
schema: true,
|
|
238
|
+
baseUrl: process.env.SMART_GLIDE_URL, // server-side env (no NEXT_PUBLIC_)
|
|
239
|
+
fetchOptions: { next: { revalidate: 3600 } }, // ISR
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<>
|
|
244
|
+
<img
|
|
245
|
+
src={image.src}
|
|
246
|
+
srcSet={image.srcset ?? undefined}
|
|
247
|
+
sizes={image.sizes ?? undefined}
|
|
248
|
+
alt={params.id}
|
|
249
|
+
/>
|
|
250
|
+
{image.schema && (
|
|
251
|
+
<script
|
|
252
|
+
type="application/ld+json"
|
|
253
|
+
dangerouslySetInnerHTML={{ __html: JSON.stringify(image.schema) }}
|
|
254
|
+
/>
|
|
255
|
+
)}
|
|
256
|
+
</>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Fetch multiple images in parallel
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
import { fetchSmartGlideMany } from 'smart-glide-react/server';
|
|
265
|
+
|
|
266
|
+
const [hero, thumb, avatar] = await fetchSmartGlideMany([
|
|
267
|
+
{ path: 'home/hero.jpg', profile: 'hero', responsive: 'fhd' },
|
|
268
|
+
{ path: 'home/thumb.jpg', profile: 'thumbnail', responsive: 'thumbnails' },
|
|
269
|
+
{ path: 'avatars/user.jpg', profile: 'profile_photo' },
|
|
270
|
+
], { baseUrl: process.env.SMART_GLIDE_URL });
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Next.js `Image` Loader
|
|
276
|
+
|
|
277
|
+
Route `next/image` through Smart Glide for auto WebP/AVIF.
|
|
278
|
+
|
|
279
|
+
**`next.config.ts`:**
|
|
280
|
+
```ts
|
|
281
|
+
const nextConfig = {
|
|
282
|
+
images: {
|
|
283
|
+
loader: 'custom',
|
|
284
|
+
loaderFile: './smart-glide-loader.ts',
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
export default nextConfig;
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**`smart-glide-loader.ts`** (project root):
|
|
291
|
+
```ts
|
|
292
|
+
export { smartGlideNextLoader as default } from 'smart-glide-react/next';
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Then use `next/image` normally — Smart Glide handles all resizing:
|
|
296
|
+
```tsx
|
|
297
|
+
import Image from 'next/image';
|
|
298
|
+
|
|
299
|
+
<Image src="products/phone.jpg" width={800} height={600} alt="Phone" />
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Available Profiles
|
|
305
|
+
|
|
306
|
+
| Profile | Dimensions | Use case |
|
|
307
|
+
|---------|-----------|----------|
|
|
308
|
+
| `default` | WebP q82 | Generic |
|
|
309
|
+
| `thumbnail` | 320×320 | Avatars, cards |
|
|
310
|
+
| `hero` | 1600×900 | Hero banners |
|
|
311
|
+
| `portrait` | 800×1200 | Faces, profiles |
|
|
312
|
+
| `square` | 600×600 | Grids |
|
|
313
|
+
| `profile_photo` | 400×400 | User avatars |
|
|
314
|
+
| `cover` | 2048×1152 | Cover art |
|
|
315
|
+
| `background` | 2560×1440 | Full backgrounds |
|
|
316
|
+
|
|
317
|
+
## Available Responsive Sets
|
|
318
|
+
|
|
319
|
+
| Name | Widths |
|
|
320
|
+
|------|--------|
|
|
321
|
+
| `hero` | 640, 960, 1280, 1600, 1920 |
|
|
322
|
+
| `thumbnails` | 240, 320, 480 |
|
|
323
|
+
| `square` | 320, 480, 640 |
|
|
324
|
+
| `portrait` | 480, 768, 1024 |
|
|
325
|
+
| `hd` | 960, 1280, 1600 |
|
|
326
|
+
| `fhd` | 1280, 1600, 1920, 2560 |
|
|
327
|
+
| `retina` | 640, 960, 1280, 1920, 2560 |
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
MIT © [Shadi Shammaa](https://github.com/shammaa)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
/** Named responsive presets available on the Laravel backend. */
|
|
5
|
+
type ResponsivePreset = 'hero' | 'thumbnails' | 'square' | 'portrait' | 'hd' | 'fhd' | 'retina' | (string & {});
|
|
6
|
+
/** Named image profiles available on the Laravel backend. */
|
|
7
|
+
type ImageProfile = 'default' | 'thumbnail' | 'hero' | 'portrait' | 'square' | 'profile_photo' | 'cover' | 'background' | (string & {});
|
|
8
|
+
/** Response shape returned by the `/img-data` API. */
|
|
9
|
+
interface SmartGlideData {
|
|
10
|
+
src: string;
|
|
11
|
+
srcset?: string | null;
|
|
12
|
+
sizes?: string | null;
|
|
13
|
+
widths?: number[];
|
|
14
|
+
blurDataUrl?: string | null;
|
|
15
|
+
schema?: Record<string, unknown> | null;
|
|
16
|
+
}
|
|
17
|
+
/** Options passed to `useSmartGlide` and lower-level helpers. */
|
|
18
|
+
interface SmartGlideOptions {
|
|
19
|
+
/** Relative path of the image (e.g. `"products/phone.jpg"`). */
|
|
20
|
+
path: string;
|
|
21
|
+
/**
|
|
22
|
+
* Base URL of your Laravel app (e.g. `"https://api.example.com"`).
|
|
23
|
+
* Defaults to the `NEXT_PUBLIC_SMART_GLIDE_URL` / `VITE_SMART_GLIDE_URL`
|
|
24
|
+
* environment variable when omitted.
|
|
25
|
+
*/
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
/** Named or custom compression profile (default: `"default"`). */
|
|
28
|
+
profile?: ImageProfile;
|
|
29
|
+
/**
|
|
30
|
+
* Responsive breakpoints:
|
|
31
|
+
* - `"hero"` — named preset
|
|
32
|
+
* - `[640, 960, 1280]` — custom widths
|
|
33
|
+
* - `false` — disable srcset
|
|
34
|
+
*/
|
|
35
|
+
responsive?: ResponsivePreset | number[] | false;
|
|
36
|
+
/** Fetch the blurred Base64 LQIP from the server. Enables `blurDataUrl`. */
|
|
37
|
+
blurPlaceholder?: boolean;
|
|
38
|
+
/** Request JSON-LD `ImageObject` data from the server. */
|
|
39
|
+
schema?: boolean;
|
|
40
|
+
/** Extra Glide transformation params (w, h, fit, focus, q…). */
|
|
41
|
+
params?: Record<string, string | number>;
|
|
42
|
+
/**
|
|
43
|
+
* Additional fetch options forwarded to the underlying `fetch()` call.
|
|
44
|
+
* (e.g. `{ next: { revalidate: 3600 } }` for Next.js ISR)
|
|
45
|
+
*/
|
|
46
|
+
fetchOptions?: RequestInit;
|
|
47
|
+
}
|
|
48
|
+
/** Props accepted by the `<SmartGlideImage>` component. */
|
|
49
|
+
interface SmartGlideImageProps extends SmartGlideOptions {
|
|
50
|
+
/** Alt text — required for accessibility and SEO. */
|
|
51
|
+
alt: string;
|
|
52
|
+
/**
|
|
53
|
+
* Mark this image as a Largest Contentful Paint candidate.
|
|
54
|
+
* Sets `fetchpriority="high"` + `loading="eager"`.
|
|
55
|
+
*/
|
|
56
|
+
priority?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Show a blurred low-quality placeholder while the full image loads.
|
|
59
|
+
*/
|
|
60
|
+
placeholder?: 'blur' | 'empty';
|
|
61
|
+
/** Inline aspect-ratio hint (e.g. `"16 / 9"`, `"1"`, `"4 / 3"`). */
|
|
62
|
+
aspectRatio?: string;
|
|
63
|
+
/** Width attribute for layout stability. */
|
|
64
|
+
width?: number;
|
|
65
|
+
/** Height attribute for layout stability. */
|
|
66
|
+
height?: number;
|
|
67
|
+
/** CSS class name. */
|
|
68
|
+
className?: string;
|
|
69
|
+
/** Inline styles. */
|
|
70
|
+
style?: React.CSSProperties;
|
|
71
|
+
/** Callback fired when the image fully loads. */
|
|
72
|
+
onLoad?: React.ReactEventHandler<HTMLImageElement>;
|
|
73
|
+
/** Callback fired on image error. */
|
|
74
|
+
onError?: React.ReactEventHandler<HTMLImageElement>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A full-featured, SEO-optimised `<img>` component backed by Laravel Smart Glide.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* <SmartGlideImage
|
|
82
|
+
* path="products/phone.jpg"
|
|
83
|
+
* alt="Awesome Phone"
|
|
84
|
+
* profile="hero"
|
|
85
|
+
* responsive="retina"
|
|
86
|
+
* />
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* <SmartGlideImage
|
|
90
|
+
* path="home/hero.jpg"
|
|
91
|
+
* alt="Hero banner"
|
|
92
|
+
* profile="hero"
|
|
93
|
+
* priority
|
|
94
|
+
* placeholder="blur"
|
|
95
|
+
* blurPlaceholder
|
|
96
|
+
* schema
|
|
97
|
+
* width={1600}
|
|
98
|
+
* height={900}
|
|
99
|
+
* />
|
|
100
|
+
*/
|
|
101
|
+
declare const SmartGlideImage: React.ForwardRefExoticComponent<SmartGlideImageProps & React.RefAttributes<HTMLImageElement>>;
|
|
102
|
+
interface SmartGlidePictureSource {
|
|
103
|
+
media?: string;
|
|
104
|
+
widths?: number[];
|
|
105
|
+
responsive?: string | number[];
|
|
106
|
+
params?: Record<string, string | number>;
|
|
107
|
+
type?: string;
|
|
108
|
+
}
|
|
109
|
+
interface SmartGlidePictureProps extends SmartGlideImageProps {
|
|
110
|
+
sources?: SmartGlidePictureSource[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* `<picture>` component with multiple `<source>` breakpoints
|
|
114
|
+
* plus a Smart Glide powered `<img>` fallback.
|
|
115
|
+
*/
|
|
116
|
+
declare const SmartGlidePicture: React.ForwardRefExoticComponent<SmartGlidePictureProps & React.RefAttributes<HTMLImageElement>>;
|
|
117
|
+
interface SmartGlideBackgroundProps extends SmartGlideOptions {
|
|
118
|
+
children?: React.ReactNode;
|
|
119
|
+
className?: string;
|
|
120
|
+
style?: React.CSSProperties;
|
|
121
|
+
'aria-label'?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* CSS background-image container backed by Smart Glide.
|
|
125
|
+
*/
|
|
126
|
+
declare const SmartGlideBackground: React.FC<SmartGlideBackgroundProps>;
|
|
127
|
+
|
|
128
|
+
interface SmartGlideConfig {
|
|
129
|
+
/** Base URL of your Laravel application (e.g. `"https://api.example.com"`). */
|
|
130
|
+
baseUrl?: string;
|
|
131
|
+
/** Delivery path prefix (default: `"/img"`). */
|
|
132
|
+
deliveryPath?: string;
|
|
133
|
+
/** Data API path prefix (default: `"/img-data"`). */
|
|
134
|
+
dataPath?: string;
|
|
135
|
+
/** Default image profile to apply when none is specified. */
|
|
136
|
+
defaultProfile?: string;
|
|
137
|
+
/** Default responsive set name or widths. */
|
|
138
|
+
defaultResponsive?: string | number[];
|
|
139
|
+
/** Emit JSON-LD `ImageObject` by default for all images. */
|
|
140
|
+
defaultSchema?: boolean;
|
|
141
|
+
}
|
|
142
|
+
declare function useSmartGlideConfig(): SmartGlideConfig;
|
|
143
|
+
interface SmartGlideProviderProps {
|
|
144
|
+
config: SmartGlideConfig;
|
|
145
|
+
children: React.ReactNode;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Wrap your application (or part of it) with `<SmartGlideProvider>` to
|
|
149
|
+
* configure Smart Glide globally. Individual components/hooks can still
|
|
150
|
+
* override any option locally.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // app/layout.tsx (Next.js App Router)
|
|
154
|
+
* import { SmartGlideProvider } from 'smart-glide-react';
|
|
155
|
+
*
|
|
156
|
+
* export default function RootLayout({ children }) {
|
|
157
|
+
* return (
|
|
158
|
+
* <SmartGlideProvider config={{ baseUrl: process.env.NEXT_PUBLIC_API_URL }}>
|
|
159
|
+
* {children}
|
|
160
|
+
* </SmartGlideProvider>
|
|
161
|
+
* );
|
|
162
|
+
* }
|
|
163
|
+
*/
|
|
164
|
+
declare function SmartGlideProvider({ config, children }: SmartGlideProviderProps): react_jsx_runtime.JSX.Element;
|
|
165
|
+
|
|
166
|
+
interface UseSmartGlideResult {
|
|
167
|
+
/** Final signed delivery URL (ready for `<img src>`). */
|
|
168
|
+
src: string;
|
|
169
|
+
/** Responsive srcset string. */
|
|
170
|
+
srcset: string | null;
|
|
171
|
+
/** Sizes attribute. */
|
|
172
|
+
sizes: string | null;
|
|
173
|
+
/** Base64 LQIP blur data URI for placeholder. */
|
|
174
|
+
blurDataUrl: string | null;
|
|
175
|
+
/** JSON-LD ImageObject schema data. */
|
|
176
|
+
schema: Record<string, unknown> | null;
|
|
177
|
+
/** True while fetching from the API. */
|
|
178
|
+
isLoading: boolean;
|
|
179
|
+
/** Error if the fetch failed. */
|
|
180
|
+
error: Error | null;
|
|
181
|
+
/** Manually re-fetch the data. */
|
|
182
|
+
refetch: () => void;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Fetch Smart Glide image data from the Laravel API.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* const { src, srcset, sizes, blurDataUrl } = useSmartGlide({
|
|
189
|
+
* path: 'products/phone.jpg',
|
|
190
|
+
* profile: 'hero',
|
|
191
|
+
* responsive: 'retina',
|
|
192
|
+
* blurPlaceholder: true,
|
|
193
|
+
* baseUrl: process.env.NEXT_PUBLIC_API_URL,
|
|
194
|
+
* });
|
|
195
|
+
*/
|
|
196
|
+
declare function useSmartGlide(options: SmartGlideOptions): UseSmartGlideResult;
|
|
197
|
+
interface UseSmartGlideStaticResult {
|
|
198
|
+
src: string;
|
|
199
|
+
srcset: string;
|
|
200
|
+
sizes: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Build image URLs entirely client-side — no API fetch required.
|
|
204
|
+
* Ideal for Next.js App Router with `generateStaticParams` or ISR.
|
|
205
|
+
*
|
|
206
|
+
* NOTE: URLs generated here are **unsigned**. Use this only in development
|
|
207
|
+
* or when `SMART_GLIDE_SECURE=false` on your Laravel backend.
|
|
208
|
+
* For signed URLs, use `useSmartGlide` or server-side data fetching.
|
|
209
|
+
*/
|
|
210
|
+
declare function useSmartGlideStatic(options: SmartGlideOptions): UseSmartGlideStaticResult;
|
|
211
|
+
|
|
212
|
+
/** Resolve the base URL from options or environment variables. */
|
|
213
|
+
declare function resolveBaseUrl(baseUrl?: string): string;
|
|
214
|
+
/** Resolve the delivery path prefix (default: `/img`). */
|
|
215
|
+
declare function resolveDeliveryPath(deliveryPath?: string): string;
|
|
216
|
+
/** Resolve the data API path prefix (default: `/img-data`). */
|
|
217
|
+
declare function resolveDataPath(dataPath?: string): string;
|
|
218
|
+
/** Build a single Smart Glide delivery URL (unsigned — for preview/dev). */
|
|
219
|
+
declare function buildDeliveryUrl(path: string, params?: Record<string, string | number>, options?: {
|
|
220
|
+
baseUrl?: string;
|
|
221
|
+
deliveryPath?: string;
|
|
222
|
+
}): string;
|
|
223
|
+
/** Build the JSON data API URL for a given path. */
|
|
224
|
+
declare function buildDataUrl(path: string, options: SmartGlideOptions & {
|
|
225
|
+
deliveryPath?: string;
|
|
226
|
+
dataPath?: string;
|
|
227
|
+
}): string;
|
|
228
|
+
declare function resolveWidths(responsive?: string | number[] | false | null): number[];
|
|
229
|
+
/**
|
|
230
|
+
* Build srcset and sizes strings entirely client-side
|
|
231
|
+
* (no API call — for use with Next.js custom loader or static generation).
|
|
232
|
+
*/
|
|
233
|
+
declare function buildSrcSet(path: string, params?: Record<string, string | number>, widths?: number[], options?: {
|
|
234
|
+
baseUrl?: string;
|
|
235
|
+
deliveryPath?: string;
|
|
236
|
+
}): {
|
|
237
|
+
srcset: string;
|
|
238
|
+
sizes: string;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export { type ImageProfile, type ResponsivePreset, SmartGlideBackground, type SmartGlideBackgroundProps, type SmartGlideConfig, type SmartGlideData, SmartGlideImage, type SmartGlideImageProps, type SmartGlideOptions, SmartGlidePicture, type SmartGlidePictureProps, type SmartGlidePictureSource, SmartGlideProvider, type SmartGlideProviderProps, type UseSmartGlideResult, type UseSmartGlideStaticResult, buildDataUrl, buildDeliveryUrl, buildSrcSet, resolveBaseUrl, resolveDataPath, resolveDeliveryPath, resolveWidths, useSmartGlide, useSmartGlideConfig, useSmartGlideStatic };
|