@bentoo/react-lazy 0.2.2 → 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.
@@ -0,0 +1,416 @@
1
+ import oe, { useRef as C, useState as L, useEffect as I, Suspense as ae } from "react";
2
+ var S = { exports: {} }, T = {};
3
+ var M;
4
+ function se() {
5
+ if (M) return T;
6
+ M = 1;
7
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), s = /* @__PURE__ */ Symbol.for("react.fragment");
8
+ function i(u, n, o) {
9
+ var c = null;
10
+ if (o !== void 0 && (c = "" + o), n.key !== void 0 && (c = "" + n.key), "key" in n) {
11
+ o = {};
12
+ for (var l in n)
13
+ l !== "key" && (o[l] = n[l]);
14
+ } else o = n;
15
+ return n = o.ref, {
16
+ $$typeof: t,
17
+ type: u,
18
+ key: c,
19
+ ref: n !== void 0 ? n : null,
20
+ props: o
21
+ };
22
+ }
23
+ return T.Fragment = s, T.jsx = i, T.jsxs = i, T;
24
+ }
25
+ var k = {};
26
+ var q;
27
+ function ue() {
28
+ return q || (q = 1, process.env.NODE_ENV !== "production" && (function() {
29
+ function t(e) {
30
+ if (e == null) return null;
31
+ if (typeof e == "function")
32
+ return e.$$typeof === re ? null : e.displayName || e.name || null;
33
+ if (typeof e == "string") return e;
34
+ switch (e) {
35
+ case A:
36
+ return "Fragment";
37
+ case G:
38
+ return "Profiler";
39
+ case V:
40
+ return "StrictMode";
41
+ case Z:
42
+ return "Suspense";
43
+ case Q:
44
+ return "SuspenseList";
45
+ case ee:
46
+ return "Activity";
47
+ }
48
+ if (typeof e == "object")
49
+ switch (typeof e.tag == "number" && console.error(
50
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
+ ), e.$$typeof) {
52
+ case w:
53
+ return "Portal";
54
+ case B:
55
+ return e.displayName || "Context";
56
+ case X:
57
+ return (e._context.displayName || "Context") + ".Consumer";
58
+ case H:
59
+ var r = e.render;
60
+ return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
61
+ case K:
62
+ return r = e.displayName || null, r !== null ? r : t(e.type) || "Memo";
63
+ case O:
64
+ r = e._payload, e = e._init;
65
+ try {
66
+ return t(e(r));
67
+ } catch {
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ function s(e) {
73
+ return "" + e;
74
+ }
75
+ function i(e) {
76
+ try {
77
+ s(e);
78
+ var r = !1;
79
+ } catch {
80
+ r = !0;
81
+ }
82
+ if (r) {
83
+ r = console;
84
+ var a = r.error, f = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
+ return a.call(
86
+ r,
87
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
+ f
89
+ ), s(e);
90
+ }
91
+ }
92
+ function u(e) {
93
+ if (e === A) return "<>";
94
+ if (typeof e == "object" && e !== null && e.$$typeof === O)
95
+ return "<...>";
96
+ try {
97
+ var r = t(e);
98
+ return r ? "<" + r + ">" : "<...>";
99
+ } catch {
100
+ return "<...>";
101
+ }
102
+ }
103
+ function n() {
104
+ var e = g.A;
105
+ return e === null ? null : e.getOwner();
106
+ }
107
+ function o() {
108
+ return Error("react-stack-top-frame");
109
+ }
110
+ function c(e) {
111
+ if ($.call(e, "key")) {
112
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
113
+ if (r && r.isReactWarning) return !1;
114
+ }
115
+ return e.key !== void 0;
116
+ }
117
+ function l(e, r) {
118
+ function a() {
119
+ F || (F = !0, console.error(
120
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
+ r
122
+ ));
123
+ }
124
+ a.isReactWarning = !0, Object.defineProperty(e, "key", {
125
+ get: a,
126
+ configurable: !0
127
+ });
128
+ }
129
+ function m() {
130
+ var e = t(this.type);
131
+ return z[e] || (z[e] = !0, console.error(
132
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
+ )), e = this.props.ref, e !== void 0 ? e : null;
134
+ }
135
+ function v(e, r, a, f, j, P) {
136
+ var d = a.ref;
137
+ return e = {
138
+ $$typeof: R,
139
+ type: e,
140
+ key: r,
141
+ props: a,
142
+ _owner: f
143
+ }, (d !== void 0 ? d : null) !== null ? Object.defineProperty(e, "ref", {
144
+ enumerable: !1,
145
+ get: m
146
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
147
+ configurable: !1,
148
+ enumerable: !1,
149
+ writable: !0,
150
+ value: 0
151
+ }), Object.defineProperty(e, "_debugInfo", {
152
+ configurable: !1,
153
+ enumerable: !1,
154
+ writable: !0,
155
+ value: null
156
+ }), Object.defineProperty(e, "_debugStack", {
157
+ configurable: !1,
158
+ enumerable: !1,
159
+ writable: !0,
160
+ value: j
161
+ }), Object.defineProperty(e, "_debugTask", {
162
+ configurable: !1,
163
+ enumerable: !1,
164
+ writable: !0,
165
+ value: P
166
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
167
+ }
168
+ function y(e, r, a, f, j, P) {
169
+ var d = r.children;
170
+ if (d !== void 0)
171
+ if (f)
172
+ if (te(d)) {
173
+ for (f = 0; f < d.length; f++)
174
+ x(d[f]);
175
+ Object.freeze && Object.freeze(d);
176
+ } else
177
+ console.error(
178
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
+ );
180
+ else x(d);
181
+ if ($.call(r, "key")) {
182
+ d = t(e);
183
+ var p = Object.keys(r).filter(function(ne) {
184
+ return ne !== "key";
185
+ });
186
+ f = 0 < p.length ? "{key: someKey, " + p.join(": ..., ") + ": ...}" : "{key: someKey}", U[d + f] || (p = 0 < p.length ? "{" + p.join(": ..., ") + ": ...}" : "{}", console.error(
187
+ `A props object containing a "key" prop is being spread into JSX:
188
+ let props = %s;
189
+ <%s {...props} />
190
+ React keys must be passed directly to JSX without using spread:
191
+ let props = %s;
192
+ <%s key={someKey} {...props} />`,
193
+ f,
194
+ d,
195
+ p,
196
+ d
197
+ ), U[d + f] = !0);
198
+ }
199
+ if (d = null, a !== void 0 && (i(a), d = "" + a), c(r) && (i(r.key), d = "" + r.key), "key" in r) {
200
+ a = {};
201
+ for (var N in r)
202
+ N !== "key" && (a[N] = r[N]);
203
+ } else a = r;
204
+ return d && l(
205
+ a,
206
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
+ ), v(
208
+ e,
209
+ d,
210
+ a,
211
+ n(),
212
+ j,
213
+ P
214
+ );
215
+ }
216
+ function x(e) {
217
+ _(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === O && (e._payload.status === "fulfilled" ? _(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
218
+ }
219
+ function _(e) {
220
+ return typeof e == "object" && e !== null && e.$$typeof === R;
221
+ }
222
+ var b = oe, R = /* @__PURE__ */ Symbol.for("react.transitional.element"), w = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), V = /* @__PURE__ */ Symbol.for("react.strict_mode"), G = /* @__PURE__ */ Symbol.for("react.profiler"), X = /* @__PURE__ */ Symbol.for("react.consumer"), B = /* @__PURE__ */ Symbol.for("react.context"), H = /* @__PURE__ */ Symbol.for("react.forward_ref"), Z = /* @__PURE__ */ Symbol.for("react.suspense"), Q = /* @__PURE__ */ Symbol.for("react.suspense_list"), K = /* @__PURE__ */ Symbol.for("react.memo"), O = /* @__PURE__ */ Symbol.for("react.lazy"), ee = /* @__PURE__ */ Symbol.for("react.activity"), re = /* @__PURE__ */ Symbol.for("react.client.reference"), g = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, $ = Object.prototype.hasOwnProperty, te = Array.isArray, h = console.createTask ? console.createTask : function() {
223
+ return null;
224
+ };
225
+ b = {
226
+ react_stack_bottom_frame: function(e) {
227
+ return e();
228
+ }
229
+ };
230
+ var F, z = {}, D = b.react_stack_bottom_frame.bind(
231
+ b,
232
+ o
233
+ )(), W = h(u(o)), U = {};
234
+ k.Fragment = A, k.jsx = function(e, r, a) {
235
+ var f = 1e4 > g.recentlyCreatedOwnerStacks++;
236
+ return y(
237
+ e,
238
+ r,
239
+ a,
240
+ !1,
241
+ f ? Error("react-stack-top-frame") : D,
242
+ f ? h(u(e)) : W
243
+ );
244
+ }, k.jsxs = function(e, r, a) {
245
+ var f = 1e4 > g.recentlyCreatedOwnerStacks++;
246
+ return y(
247
+ e,
248
+ r,
249
+ a,
250
+ !0,
251
+ f ? Error("react-stack-top-frame") : D,
252
+ f ? h(u(e)) : W
253
+ );
254
+ };
255
+ })()), k;
256
+ }
257
+ var J;
258
+ function le() {
259
+ return J || (J = 1, process.env.NODE_ENV === "production" ? S.exports = se() : S.exports = ue()), S.exports;
260
+ }
261
+ var E = le();
262
+ const Y = ({
263
+ root: t = null,
264
+ rootMargin: s = "0px",
265
+ threshold: i = 0.1,
266
+ triggerOnce: u = !0
267
+ }) => {
268
+ const n = C(null), [o, c] = L(!1);
269
+ return I(() => {
270
+ const l = n.current;
271
+ if (!l) return;
272
+ const m = new IntersectionObserver(([v]) => {
273
+ v.isIntersecting ? (c(!0), u && m.unobserve(v.target)) : u || c(!1);
274
+ }, { root: t, rootMargin: s, threshold: i });
275
+ return m.observe(l), () => {
276
+ m.unobserve(l), m.disconnect();
277
+ };
278
+ }, [t, s, i, u]), { ref: n, visible: o };
279
+ }, fe = ({
280
+ onVisible: t,
281
+ root: s = null,
282
+ rootMargin: i = "0px",
283
+ threshold: u = 0.1,
284
+ triggerOnce: n = !0
285
+ }) => {
286
+ const o = C(null), c = C(!1);
287
+ return I(() => {
288
+ const l = o.current;
289
+ if (!l) return;
290
+ const m = new IntersectionObserver(([v]) => {
291
+ v.isIntersecting && ((!c.current || !n) && (t(), c.current = !0), n && m.unobserve(v.target));
292
+ }, { root: s, rootMargin: i, threshold: u });
293
+ return m.observe(l), () => {
294
+ m.unobserve(l), m.disconnect();
295
+ };
296
+ }, [t, s, i, u, n]), { ref: o };
297
+ };
298
+ function de({
299
+ children: t,
300
+ fallback: s = null,
301
+ className: i,
302
+ style: u,
303
+ root: n,
304
+ rootMargin: o,
305
+ threshold: c,
306
+ triggerOnce: l
307
+ }) {
308
+ const { ref: m, visible: v } = Y({ root: n, rootMargin: o, threshold: c, triggerOnce: l });
309
+ return /* @__PURE__ */ E.jsx("div", { ref: m, className: i, style: u, children: v ? t : s });
310
+ }
311
+ function me({
312
+ children: t,
313
+ fallback: s = null
314
+ }) {
315
+ const { ref: i, visible: u } = Y({});
316
+ return /* @__PURE__ */ E.jsx("div", { ref: i, children: u && /* @__PURE__ */ E.jsx(ae, { fallback: s, children: t }) });
317
+ }
318
+ const ie = ({ src: t, visible: s }) => {
319
+ const [i, u] = L(!1), [n, o] = L(!1);
320
+ function c() {
321
+ o(!0);
322
+ }
323
+ return I(() => {
324
+ if (!s || !t) return;
325
+ const l = new Image();
326
+ l.src = t, l.onload = () => {
327
+ u(!0);
328
+ };
329
+ }, [s, t]), {
330
+ handleLoad: c,
331
+ loaded: n,
332
+ shouldLoad: i
333
+ };
334
+ };
335
+ function ve({
336
+ src: t,
337
+ alt: s,
338
+ placeholder: i,
339
+ blur: u = !1,
340
+ fadeInDuration: n = 300,
341
+ width: o,
342
+ height: c,
343
+ style: l,
344
+ ImageComponent: m = "img",
345
+ ...v
346
+ }) {
347
+ const { ref: y, visible: x } = Y({}), { loaded: _, handleLoad: b, shouldLoad: R } = ie({ src: t, visible: x }), w = m !== "img";
348
+ return /* @__PURE__ */ E.jsxs("div", { style: {
349
+ position: "relative",
350
+ overflow: "hidden",
351
+ width: o,
352
+ height: c
353
+ }, children: [
354
+ i && !_ && /* @__PURE__ */ E.jsx(
355
+ "img",
356
+ {
357
+ src: i,
358
+ alt: s,
359
+ "aria-hidden": !0,
360
+ style: {
361
+ position: "absolute",
362
+ inset: 0,
363
+ width: "100%",
364
+ height: "100%",
365
+ objectFit: "cover",
366
+ filter: u ? "blur(20px)" : "none",
367
+ transform: u ? "scale(1.1)" : void 0
368
+ }
369
+ }
370
+ ),
371
+ w ? /* @__PURE__ */ E.jsx(
372
+ m,
373
+ {
374
+ src: R ? t : "",
375
+ alt: s,
376
+ width: o,
377
+ height: c,
378
+ onLoad: b,
379
+ style: {
380
+ opacity: _ ? 1 : 0,
381
+ transition: `opacity ${n}ms ease`,
382
+ ...l
383
+ },
384
+ ...v
385
+ }
386
+ ) : /* @__PURE__ */ E.jsx(
387
+ "img",
388
+ {
389
+ ref: y,
390
+ src: R ? t : void 0,
391
+ alt: s,
392
+ loading: "lazy",
393
+ width: o,
394
+ height: c,
395
+ onLoad: b,
396
+ style: {
397
+ opacity: _ ? 1 : 0,
398
+ transition: `opacity ${n}ms ease`,
399
+ width: "100%",
400
+ height: "100%",
401
+ objectFit: "cover",
402
+ display: "block",
403
+ ...l
404
+ },
405
+ ...v
406
+ }
407
+ )
408
+ ] });
409
+ }
410
+ export {
411
+ de as LazyComponent,
412
+ ve as LazyImage,
413
+ me as LazySuspense,
414
+ Y as useLazy,
415
+ fe as useLazyCallback
416
+ };
package/package.json CHANGED
@@ -1,53 +1,64 @@
1
1
  {
2
2
  "name": "@bentoo/react-lazy",
3
- "author": {
4
- "name": "Manuel Bento",
5
- "email": "manuelbentomb.223@hotmail.com"
6
- },
3
+ "version": "1.0.0",
7
4
  "private": false,
8
- "version": "0.2.2",
9
5
  "type": "module",
10
- "module": "./dist/index.js",
6
+ "main": "./dist/index.cjs.js",
7
+ "module": "./dist/index.esm.js",
11
8
  "types": "./dist/index.d.ts",
12
9
  "files": [
13
- "/dist"
10
+ "dist"
14
11
  ],
15
12
  "exports": {
16
13
  ".": {
17
- "import": "./dist/index.js",
18
- "require": "./dist/index.js",
19
- "types": "./dist/index.d.ts"
14
+ "import": "./dist/index.esm.js",
15
+ "require": "./dist/index.cjs.js"
20
16
  }
21
17
  },
22
18
  "scripts": {
23
- "build": "tsc && vite build",
24
- "lint": "eslint ."
19
+ "build:ts": "tsc --emitDeclarationOnly",
20
+ "build:esm": "vite build --config vite.config.ts",
21
+ "build": "npm run build:ts && npm run build:esm",
22
+ "lint": "eslint . --ext .ts,.tsx",
23
+ "publish:one": "npm run build && npm publish --access public",
24
+ "publish:confirm": "npm run build && node scripts/publish.js"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=18",
28
+ "react-dom": ">=18"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^25.3.3",
32
+ "@types/react": "^19.2.14",
33
+ "@types/react-dom": "^19.2.3",
34
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
35
+ "@typescript-eslint/parser": "^8.56.1",
36
+ "@vitejs/plugin-react": "^5.1.4",
37
+ "eslint": "^10.0.2",
38
+ "eslint-plugin-react-hooks": "^7.0.1",
39
+ "typescript": "^5.9.3",
40
+ "vite": "^7.3.1",
41
+ "vite-plugin-dts": "^4.5.4"
25
42
  },
43
+ "keywords": [
44
+ "react",
45
+ "nextjs",
46
+ "lazy-loading",
47
+ "react-lazy",
48
+ "react-lazy-load"
49
+ ],
26
50
  "repository": {
27
51
  "type": "git",
28
- "url": "https://github.com/manuelbento19/react-lazy.git"
52
+ "url": "git+https://github.com/manuelbento19/react-lazy.git"
29
53
  },
30
- "dependencies": {
31
- "react": "^18.3.1",
32
- "react-dom": "^18.3.1",
33
- "vite-plugin-dts": "^4.2.1"
54
+ "bugs": {
55
+ "url": "https://github.com/manuelbento19/react-lazy/issues"
34
56
  },
35
- "devDependencies": {
36
- "@eslint/js": "^9.9.0",
37
- "@types/node": "^22.5.5",
38
- "@types/react": "^18.3.3",
39
- "@types/react-dom": "^18.3.0",
40
- "@vitejs/plugin-react": "^4.3.1",
41
- "eslint": "^9.9.0",
42
- "eslint-plugin-react-hooks": "^5.1.0-rc.0",
43
- "eslint-plugin-react-refresh": "^0.4.9",
44
- "globals": "^15.9.0",
45
- "typescript": "^5.5.3",
46
- "typescript-eslint": "^8.0.1",
47
- "vite": "^5.4.1"
57
+ "homepage": "https://github.com/manuelbento19/react-lazy#readme",
58
+ "author": {
59
+ "name": "Manuel Bento",
60
+ "email": "manuelbentomb.223@hotmail.com"
48
61
  },
49
- "keywords": [
50
- "react","nextjs",
51
- "lazy-loading","react-lazy","react-lazy-load"
52
- ]
53
- }
62
+ "license": "MIT",
63
+ "sideEffects": false
64
+ }