@drawbridge/components 0.0.62 → 0.0.64
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/dist/video.js +32 -26
- package/dist/video.mjs +32 -26
- package/package.json +2 -2
package/dist/video.js
CHANGED
|
@@ -112,7 +112,7 @@ var ReactPlayer = (0, import_dynamic.default)(
|
|
|
112
112
|
ssr: false
|
|
113
113
|
}
|
|
114
114
|
);
|
|
115
|
-
var
|
|
115
|
+
var DEFER_FALLBACK_MS = 5e3;
|
|
116
116
|
var Video = ({
|
|
117
117
|
className,
|
|
118
118
|
controls = false,
|
|
@@ -140,6 +140,7 @@ var Video = ({
|
|
|
140
140
|
const [player, setPlayer] = (0, import_react.useState)();
|
|
141
141
|
const [videoUrl, setVideoUrl] = (0, import_react.useState)(hls ? hls : mp4);
|
|
142
142
|
const [mountPlayer, setMountPlayer] = (0, import_react.useState)(!defer);
|
|
143
|
+
const [posterPainted, setPosterPainted] = (0, import_react.useState)(false);
|
|
143
144
|
const [failed, setFailed] = (0, import_react.useState)(false);
|
|
144
145
|
(0, import_react.useEffect)(
|
|
145
146
|
() => {
|
|
@@ -152,33 +153,30 @@ var Video = ({
|
|
|
152
153
|
(0, import_react.useEffect)(
|
|
153
154
|
() => {
|
|
154
155
|
if (!defer || mountPlayer || typeof window === "undefined") return;
|
|
155
|
-
|
|
156
|
+
if (!poster) {
|
|
157
|
+
setMountPlayer(true);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
156
160
|
let idle;
|
|
157
161
|
const start = () => setMountPlayer(true);
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
timer = setTimeout(start, 500);
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
DEFER_MS
|
|
168
|
-
);
|
|
162
|
+
const soon = () => {
|
|
163
|
+
if ("requestIdleCallback" in window) {
|
|
164
|
+
idle = window.requestIdleCallback(start, { timeout: 300 });
|
|
165
|
+
} else {
|
|
166
|
+
idle = setTimeout(start, 100);
|
|
167
|
+
}
|
|
169
168
|
};
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
if (posterPainted) {
|
|
170
|
+
soon();
|
|
171
|
+
return () => {
|
|
172
|
+
if (idle && "cancelIdleCallback" in window) window.cancelIdleCallback(idle);
|
|
173
|
+
clearTimeout(idle);
|
|
174
|
+
};
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
clearTimeout(timer);
|
|
178
|
-
if (idle) window.cancelIdleCallback(idle);
|
|
179
|
-
};
|
|
176
|
+
const fallback = setTimeout(start, DEFER_FALLBACK_MS);
|
|
177
|
+
return () => clearTimeout(fallback);
|
|
180
178
|
},
|
|
181
|
-
[defer, mountPlayer]
|
|
179
|
+
[defer, mountPlayer, poster, posterPainted]
|
|
182
180
|
);
|
|
183
181
|
const inner = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react.Fragment, { children: [
|
|
184
182
|
mountPlayer && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -252,6 +250,14 @@ var Video = ({
|
|
|
252
250
|
className: "absolute inset-0 w-full h-full object-cover pointer-events-none",
|
|
253
251
|
decoding: "async",
|
|
254
252
|
...priority ? { fetchpriority: "high", loading: "eager" } : { loading: "lazy" },
|
|
253
|
+
onLoad: () => setPosterPainted(true),
|
|
254
|
+
// A cached poster can finish loading before React attaches
|
|
255
|
+
// onLoad, so check completeness on attach too — otherwise the
|
|
256
|
+
// exact case this optimises for (warm revisit) would fall
|
|
257
|
+
// through to the 5s fallback.
|
|
258
|
+
ref: (element) => {
|
|
259
|
+
if ((element == null ? void 0 : element.complete) && element.naturalWidth > 0) setPosterPainted(true);
|
|
260
|
+
},
|
|
255
261
|
src: poster
|
|
256
262
|
}
|
|
257
263
|
}
|
|
@@ -264,7 +270,7 @@ var Video = ({
|
|
|
264
270
|
// borrows the reserved gallery box's height and collapses to 0
|
|
265
271
|
// when the video is ready = a ~0.65 CLS. Overlaying it (the box
|
|
266
272
|
// already reserves its height) means removing it shifts nothing.
|
|
267
|
-
className: "absolute inset-0 flex justify-center items-center"
|
|
273
|
+
className: "absolute inset-0 flex justify-center items-center pointer-events-none"
|
|
268
274
|
},
|
|
269
275
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
270
276
|
loader_default,
|
|
@@ -283,7 +289,7 @@ var Video = ({
|
|
|
283
289
|
"div",
|
|
284
290
|
{
|
|
285
291
|
...{
|
|
286
|
-
className: "absolute inset-0 flex justify-center items-center"
|
|
292
|
+
className: "absolute inset-0 flex justify-center items-center pointer-events-none"
|
|
287
293
|
},
|
|
288
294
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
289
295
|
warning_default,
|
|
@@ -305,7 +311,7 @@ var Video = ({
|
|
|
305
311
|
"div",
|
|
306
312
|
{
|
|
307
313
|
...{
|
|
308
|
-
className
|
|
314
|
+
className: "relative " + className
|
|
309
315
|
},
|
|
310
316
|
children: inner
|
|
311
317
|
}
|
package/dist/video.mjs
CHANGED
|
@@ -16,7 +16,7 @@ var ReactPlayer = dynamic(
|
|
|
16
16
|
ssr: false
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
|
-
var
|
|
19
|
+
var DEFER_FALLBACK_MS = 5e3;
|
|
20
20
|
var Video = ({
|
|
21
21
|
className,
|
|
22
22
|
controls = false,
|
|
@@ -44,6 +44,7 @@ var Video = ({
|
|
|
44
44
|
const [player, setPlayer] = useState();
|
|
45
45
|
const [videoUrl, setVideoUrl] = useState(hls ? hls : mp4);
|
|
46
46
|
const [mountPlayer, setMountPlayer] = useState(!defer);
|
|
47
|
+
const [posterPainted, setPosterPainted] = useState(false);
|
|
47
48
|
const [failed, setFailed] = useState(false);
|
|
48
49
|
useEffect(
|
|
49
50
|
() => {
|
|
@@ -56,33 +57,30 @@ var Video = ({
|
|
|
56
57
|
useEffect(
|
|
57
58
|
() => {
|
|
58
59
|
if (!defer || mountPlayer || typeof window === "undefined") return;
|
|
59
|
-
|
|
60
|
+
if (!poster) {
|
|
61
|
+
setMountPlayer(true);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
60
64
|
let idle;
|
|
61
65
|
const start = () => setMountPlayer(true);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
timer = setTimeout(start, 500);
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
DEFER_MS
|
|
72
|
-
);
|
|
66
|
+
const soon = () => {
|
|
67
|
+
if ("requestIdleCallback" in window) {
|
|
68
|
+
idle = window.requestIdleCallback(start, { timeout: 300 });
|
|
69
|
+
} else {
|
|
70
|
+
idle = setTimeout(start, 100);
|
|
71
|
+
}
|
|
73
72
|
};
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
if (posterPainted) {
|
|
74
|
+
soon();
|
|
75
|
+
return () => {
|
|
76
|
+
if (idle && "cancelIdleCallback" in window) window.cancelIdleCallback(idle);
|
|
77
|
+
clearTimeout(idle);
|
|
78
|
+
};
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
clearTimeout(timer);
|
|
82
|
-
if (idle) window.cancelIdleCallback(idle);
|
|
83
|
-
};
|
|
80
|
+
const fallback = setTimeout(start, DEFER_FALLBACK_MS);
|
|
81
|
+
return () => clearTimeout(fallback);
|
|
84
82
|
},
|
|
85
|
-
[defer, mountPlayer]
|
|
83
|
+
[defer, mountPlayer, poster, posterPainted]
|
|
86
84
|
);
|
|
87
85
|
const inner = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
88
86
|
mountPlayer && /* @__PURE__ */ jsx(
|
|
@@ -156,6 +154,14 @@ var Video = ({
|
|
|
156
154
|
className: "absolute inset-0 w-full h-full object-cover pointer-events-none",
|
|
157
155
|
decoding: "async",
|
|
158
156
|
...priority ? { fetchpriority: "high", loading: "eager" } : { loading: "lazy" },
|
|
157
|
+
onLoad: () => setPosterPainted(true),
|
|
158
|
+
// A cached poster can finish loading before React attaches
|
|
159
|
+
// onLoad, so check completeness on attach too — otherwise the
|
|
160
|
+
// exact case this optimises for (warm revisit) would fall
|
|
161
|
+
// through to the 5s fallback.
|
|
162
|
+
ref: (element) => {
|
|
163
|
+
if ((element == null ? void 0 : element.complete) && element.naturalWidth > 0) setPosterPainted(true);
|
|
164
|
+
},
|
|
159
165
|
src: poster
|
|
160
166
|
}
|
|
161
167
|
}
|
|
@@ -168,7 +174,7 @@ var Video = ({
|
|
|
168
174
|
// borrows the reserved gallery box's height and collapses to 0
|
|
169
175
|
// when the video is ready = a ~0.65 CLS. Overlaying it (the box
|
|
170
176
|
// already reserves its height) means removing it shifts nothing.
|
|
171
|
-
className: "absolute inset-0 flex justify-center items-center"
|
|
177
|
+
className: "absolute inset-0 flex justify-center items-center pointer-events-none"
|
|
172
178
|
},
|
|
173
179
|
children: /* @__PURE__ */ jsx(
|
|
174
180
|
loader_default,
|
|
@@ -187,7 +193,7 @@ var Video = ({
|
|
|
187
193
|
"div",
|
|
188
194
|
{
|
|
189
195
|
...{
|
|
190
|
-
className: "absolute inset-0 flex justify-center items-center"
|
|
196
|
+
className: "absolute inset-0 flex justify-center items-center pointer-events-none"
|
|
191
197
|
},
|
|
192
198
|
children: /* @__PURE__ */ jsx(
|
|
193
199
|
warning_default,
|
|
@@ -209,7 +215,7 @@ var Video = ({
|
|
|
209
215
|
"div",
|
|
210
216
|
{
|
|
211
217
|
...{
|
|
212
|
-
className
|
|
218
|
+
className: "relative " + className
|
|
213
219
|
},
|
|
214
220
|
children: inner
|
|
215
221
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drawbridge/components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.64",
|
|
4
4
|
"exports": {
|
|
5
5
|
"./advertisement": {
|
|
6
6
|
"types": "./types/advertisement.d.ts",
|
|
@@ -355,7 +355,7 @@
|
|
|
355
355
|
"devDependencies": {
|
|
356
356
|
"@types/react": "18.0.0",
|
|
357
357
|
"tsup": "8.5.1",
|
|
358
|
-
"@drawbridge/drawbridge-agents": "0.1.
|
|
358
|
+
"@drawbridge/drawbridge-agents": "0.1.24"
|
|
359
359
|
},
|
|
360
360
|
"dependencies": {
|
|
361
361
|
"embla-carousel-fade": "8.6.0",
|