@fringeworks/react-defer-rendering 0.8.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.ja.md +319 -0
- package/README.md +319 -0
- package/_usePromiseState.cjs +42 -0
- package/_usePromiseState.d.cts +11 -0
- package/_usePromiseState.d.mts +12 -0
- package/_usePromiseState.mjs +40 -0
- package/_virtual/_rolldown/runtime.cjs +29 -0
- package/constants.cjs +14 -0
- package/constants.d.cts +15 -0
- package/constants.d.mts +15 -0
- package/constants.mjs +12 -0
- package/index.cjs +46 -0
- package/index.d.cts +31 -0
- package/index.d.mts +31 -0
- package/index.mjs +32 -0
- package/package.json +91 -0
- package/types.cjs +0 -0
- package/types.d.cts +82 -0
- package/types.d.mts +82 -0
- package/types.mjs +1 -0
- package/useDeferUntilAsyncComplete/index.cjs +5 -0
- package/useDeferUntilAsyncComplete/index.d.cts +3 -0
- package/useDeferUntilAsyncComplete/index.d.mts +3 -0
- package/useDeferUntilAsyncComplete/index.mjs +5 -0
- package/useDeferUntilAsyncComplete/types.cjs +0 -0
- package/useDeferUntilAsyncComplete/types.d.cts +7 -0
- package/useDeferUntilAsyncComplete/types.d.mts +7 -0
- package/useDeferUntilAsyncComplete/types.mjs +1 -0
- package/useDeferUntilAsyncComplete/useDeferUntilAsyncComplete.cjs +20 -0
- package/useDeferUntilAsyncComplete/useDeferUntilAsyncComplete.d.cts +14 -0
- package/useDeferUntilAsyncComplete/useDeferUntilAsyncComplete.d.mts +15 -0
- package/useDeferUntilAsyncComplete/useDeferUntilAsyncComplete.mjs +20 -0
- package/useDeferUntilBreakpoint/index.cjs +5 -0
- package/useDeferUntilBreakpoint/index.d.cts +3 -0
- package/useDeferUntilBreakpoint/index.d.mts +3 -0
- package/useDeferUntilBreakpoint/index.mjs +5 -0
- package/useDeferUntilBreakpoint/types.cjs +0 -0
- package/useDeferUntilBreakpoint/types.d.cts +20 -0
- package/useDeferUntilBreakpoint/types.d.mts +20 -0
- package/useDeferUntilBreakpoint/types.mjs +1 -0
- package/useDeferUntilBreakpoint/useDeferUntilBreakpoint.cjs +44 -0
- package/useDeferUntilBreakpoint/useDeferUntilBreakpoint.d.cts +14 -0
- package/useDeferUntilBreakpoint/useDeferUntilBreakpoint.d.mts +15 -0
- package/useDeferUntilBreakpoint/useDeferUntilBreakpoint.mjs +42 -0
- package/useDeferUntilCallThreshold/index.cjs +5 -0
- package/useDeferUntilCallThreshold/index.d.cts +3 -0
- package/useDeferUntilCallThreshold/index.d.mts +3 -0
- package/useDeferUntilCallThreshold/index.mjs +5 -0
- package/useDeferUntilCallThreshold/types.cjs +0 -0
- package/useDeferUntilCallThreshold/types.d.cts +23 -0
- package/useDeferUntilCallThreshold/types.d.mts +23 -0
- package/useDeferUntilCallThreshold/types.mjs +1 -0
- package/useDeferUntilCallThreshold/useDeferUntilCallThreshold.cjs +55 -0
- package/useDeferUntilCallThreshold/useDeferUntilCallThreshold.d.cts +13 -0
- package/useDeferUntilCallThreshold/useDeferUntilCallThreshold.d.mts +14 -0
- package/useDeferUntilCallThreshold/useDeferUntilCallThreshold.mjs +55 -0
- package/useDeferUntilChange/index.cjs +5 -0
- package/useDeferUntilChange/index.d.cts +3 -0
- package/useDeferUntilChange/index.d.mts +3 -0
- package/useDeferUntilChange/index.mjs +5 -0
- package/useDeferUntilChange/types.cjs +0 -0
- package/useDeferUntilChange/types.d.cts +7 -0
- package/useDeferUntilChange/types.d.mts +7 -0
- package/useDeferUntilChange/types.mjs +1 -0
- package/useDeferUntilChange/useDeferUntilChange.cjs +30 -0
- package/useDeferUntilChange/useDeferUntilChange.d.cts +14 -0
- package/useDeferUntilChange/useDeferUntilChange.d.mts +15 -0
- package/useDeferUntilChange/useDeferUntilChange.mjs +28 -0
- package/useDeferUntilDate/index.cjs +5 -0
- package/useDeferUntilDate/index.d.cts +3 -0
- package/useDeferUntilDate/index.d.mts +3 -0
- package/useDeferUntilDate/index.mjs +5 -0
- package/useDeferUntilDate/types.cjs +0 -0
- package/useDeferUntilDate/types.d.cts +7 -0
- package/useDeferUntilDate/types.d.mts +7 -0
- package/useDeferUntilDate/types.mjs +1 -0
- package/useDeferUntilDate/useDeferUntilDate.cjs +21 -0
- package/useDeferUntilDate/useDeferUntilDate.d.cts +14 -0
- package/useDeferUntilDate/useDeferUntilDate.d.mts +15 -0
- package/useDeferUntilDate/useDeferUntilDate.mjs +21 -0
- package/useDeferUntilIntersected/index.cjs +5 -0
- package/useDeferUntilIntersected/index.d.cts +3 -0
- package/useDeferUntilIntersected/index.d.mts +3 -0
- package/useDeferUntilIntersected/index.mjs +5 -0
- package/useDeferUntilIntersected/types.cjs +0 -0
- package/useDeferUntilIntersected/types.d.cts +31 -0
- package/useDeferUntilIntersected/types.d.mts +31 -0
- package/useDeferUntilIntersected/types.mjs +1 -0
- package/useDeferUntilIntersected/useDeferUntilIntersected.cjs +60 -0
- package/useDeferUntilIntersected/useDeferUntilIntersected.d.cts +14 -0
- package/useDeferUntilIntersected/useDeferUntilIntersected.d.mts +15 -0
- package/useDeferUntilIntersected/useDeferUntilIntersected.mjs +58 -0
- package/useDeferUntilOnReady/index.cjs +5 -0
- package/useDeferUntilOnReady/index.d.cts +3 -0
- package/useDeferUntilOnReady/index.d.mts +3 -0
- package/useDeferUntilOnReady/index.mjs +5 -0
- package/useDeferUntilOnReady/types.cjs +0 -0
- package/useDeferUntilOnReady/types.d.cts +23 -0
- package/useDeferUntilOnReady/types.d.mts +23 -0
- package/useDeferUntilOnReady/types.mjs +1 -0
- package/useDeferUntilOnReady/useDeferUntilOnReady.cjs +42 -0
- package/useDeferUntilOnReady/useDeferUntilOnReady.d.cts +13 -0
- package/useDeferUntilOnReady/useDeferUntilOnReady.d.mts +14 -0
- package/useDeferUntilOnReady/useDeferUntilOnReady.mjs +40 -0
- package/useDeferUntilReady/index.cjs +5 -0
- package/useDeferUntilReady/index.d.cts +3 -0
- package/useDeferUntilReady/index.d.mts +3 -0
- package/useDeferUntilReady/index.mjs +5 -0
- package/useDeferUntilReady/types.cjs +0 -0
- package/useDeferUntilReady/types.d.cts +7 -0
- package/useDeferUntilReady/types.d.mts +7 -0
- package/useDeferUntilReady/types.mjs +1 -0
- package/useDeferUntilReady/useDeferUntilReady.cjs +60 -0
- package/useDeferUntilReady/useDeferUntilReady.d.cts +15 -0
- package/useDeferUntilReady/useDeferUntilReady.d.mts +16 -0
- package/useDeferUntilReady/useDeferUntilReady.mjs +58 -0
- package/useDeferUntilRender/index.cjs +5 -0
- package/useDeferUntilRender/index.d.cts +3 -0
- package/useDeferUntilRender/index.d.mts +3 -0
- package/useDeferUntilRender/index.mjs +5 -0
- package/useDeferUntilRender/types.cjs +0 -0
- package/useDeferUntilRender/types.d.cts +25 -0
- package/useDeferUntilRender/types.d.mts +25 -0
- package/useDeferUntilRender/types.mjs +1 -0
- package/useDeferUntilRender/useDeferUntilRender.cjs +53 -0
- package/useDeferUntilRender/useDeferUntilRender.d.cts +14 -0
- package/useDeferUntilRender/useDeferUntilRender.d.mts +15 -0
- package/useDeferUntilRender/useDeferUntilRender.mjs +51 -0
- package/useDeferUntilResolved/index.cjs +5 -0
- package/useDeferUntilResolved/index.d.cts +3 -0
- package/useDeferUntilResolved/index.d.mts +3 -0
- package/useDeferUntilResolved/index.mjs +5 -0
- package/useDeferUntilResolved/types.cjs +0 -0
- package/useDeferUntilResolved/types.d.cts +7 -0
- package/useDeferUntilResolved/types.d.mts +7 -0
- package/useDeferUntilResolved/types.mjs +1 -0
- package/useDeferUntilResolved/useDeferUntilResolved.cjs +21 -0
- package/useDeferUntilResolved/useDeferUntilResolved.d.cts +14 -0
- package/useDeferUntilResolved/useDeferUntilResolved.d.mts +15 -0
- package/useDeferUntilResolved/useDeferUntilResolved.mjs +21 -0
- package/useDeferUntilScrolled/index.cjs +5 -0
- package/useDeferUntilScrolled/index.d.cts +3 -0
- package/useDeferUntilScrolled/index.d.mts +3 -0
- package/useDeferUntilScrolled/index.mjs +5 -0
- package/useDeferUntilScrolled/types.cjs +0 -0
- package/useDeferUntilScrolled/types.d.cts +29 -0
- package/useDeferUntilScrolled/types.d.mts +29 -0
- package/useDeferUntilScrolled/types.mjs +1 -0
- package/useDeferUntilScrolled/useDeferUntilScrolled.cjs +94 -0
- package/useDeferUntilScrolled/useDeferUntilScrolled.d.cts +14 -0
- package/useDeferUntilScrolled/useDeferUntilScrolled.d.mts +15 -0
- package/useDeferUntilScrolled/useDeferUntilScrolled.mjs +91 -0
- package/useDeferUntilTimeout/index.cjs +5 -0
- package/useDeferUntilTimeout/index.d.cts +3 -0
- package/useDeferUntilTimeout/index.d.mts +3 -0
- package/useDeferUntilTimeout/index.mjs +5 -0
- package/useDeferUntilTimeout/types.cjs +0 -0
- package/useDeferUntilTimeout/types.d.cts +7 -0
- package/useDeferUntilTimeout/types.d.mts +7 -0
- package/useDeferUntilTimeout/types.mjs +1 -0
- package/useDeferUntilTimeout/useDeferUntilTimeout.cjs +40 -0
- package/useDeferUntilTimeout/useDeferUntilTimeout.d.cts +14 -0
- package/useDeferUntilTimeout/useDeferUntilTimeout.d.mts +15 -0
- package/useDeferUntilTimeout/useDeferUntilTimeout.mjs +37 -0
- package/useDeferUntilTrue/index.cjs +5 -0
- package/useDeferUntilTrue/index.d.cts +3 -0
- package/useDeferUntilTrue/index.d.mts +3 -0
- package/useDeferUntilTrue/index.mjs +5 -0
- package/useDeferUntilTrue/types.cjs +0 -0
- package/useDeferUntilTrue/types.d.cts +7 -0
- package/useDeferUntilTrue/types.d.mts +7 -0
- package/useDeferUntilTrue/types.mjs +1 -0
- package/useDeferUntilTrue/useDeferUntilTrue.cjs +20 -0
- package/useDeferUntilTrue/useDeferUntilTrue.d.cts +14 -0
- package/useDeferUntilTrue/useDeferUntilTrue.d.mts +15 -0
- package/useDeferUntilTrue/useDeferUntilTrue.mjs +20 -0
- package/useDeferUntilWebFontReady/index.cjs +5 -0
- package/useDeferUntilWebFontReady/index.d.cts +3 -0
- package/useDeferUntilWebFontReady/index.d.mts +3 -0
- package/useDeferUntilWebFontReady/index.mjs +5 -0
- package/useDeferUntilWebFontReady/types.cjs +0 -0
- package/useDeferUntilWebFontReady/types.d.cts +49 -0
- package/useDeferUntilWebFontReady/types.d.mts +49 -0
- package/useDeferUntilWebFontReady/types.mjs +1 -0
- package/useDeferUntilWebFontReady/useDeferUntilWebFontReady.cjs +93 -0
- package/useDeferUntilWebFontReady/useDeferUntilWebFontReady.d.cts +16 -0
- package/useDeferUntilWebFontReady/useDeferUntilWebFontReady.d.mts +17 -0
- package/useDeferUntilWebFontReady/useDeferUntilWebFontReady.mjs +90 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
const require_useDeferUntilTrue_useDeferUntilTrue = require('../useDeferUntilTrue/useDeferUntilTrue.cjs');
|
|
5
|
+
require('../useDeferUntilTrue/index.cjs');
|
|
6
|
+
let _fringeworks_react_utils_hooks_useIsMounted = require("@fringeworks/react-utils/hooks/useIsMounted");
|
|
7
|
+
_fringeworks_react_utils_hooks_useIsMounted = require_runtime.__toESM(_fringeworks_react_utils_hooks_useIsMounted, 1);
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let _fringeworks_utils_timer_debounce = require("@fringeworks/utils/timer/debounce");
|
|
10
|
+
_fringeworks_utils_timer_debounce = require_runtime.__toESM(_fringeworks_utils_timer_debounce, 1);
|
|
11
|
+
|
|
12
|
+
//#region src/useDeferUntilScrolled/useDeferUntilScrolled.tsx
|
|
13
|
+
/**
|
|
14
|
+
* 縦または横スクロール位置に基づいて描画を遅延させるhook
|
|
15
|
+
* @param target 描画対象のノード
|
|
16
|
+
* @param elementRef 基準となる要素の参照(参照自体がnull/undefinedの場合は待たずに描画する)
|
|
17
|
+
* @param options オプション
|
|
18
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
19
|
+
*/
|
|
20
|
+
function useDeferUntilScrolled(target, elementRef, options = {}) {
|
|
21
|
+
const defaultRootRef = (0, react.useRef)(null);
|
|
22
|
+
const { rootRef = defaultRootRef, rootMargin = 0, detectionDelay = 100, preserveOnceReady, direction = "vertical", initialCondition = false, ...opts } = options;
|
|
23
|
+
const [condition, setCondition] = (0, react.useState)(!elementRef || initialCondition);
|
|
24
|
+
const isMounted = (0, _fringeworks_react_utils_hooks_useIsMounted.default)();
|
|
25
|
+
const isFirstRun = (0, react.useRef)(true);
|
|
26
|
+
(0, react.useEffect)(() => {
|
|
27
|
+
const isFirst = isFirstRun.current;
|
|
28
|
+
isFirstRun.current = false;
|
|
29
|
+
if (!elementRef) {
|
|
30
|
+
setCondition(true);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!isFirst) setCondition(false);
|
|
34
|
+
const element = elementRef.current;
|
|
35
|
+
if (!element) return;
|
|
36
|
+
const container = rootRef.current;
|
|
37
|
+
const scrollTarget = container ?? window;
|
|
38
|
+
const getRootBounds = () => {
|
|
39
|
+
if (container) {
|
|
40
|
+
const rect = container.getBoundingClientRect();
|
|
41
|
+
const top = rect.top + container.clientTop;
|
|
42
|
+
const left = rect.left + container.clientLeft;
|
|
43
|
+
return {
|
|
44
|
+
top,
|
|
45
|
+
left,
|
|
46
|
+
bottom: top + container.clientHeight,
|
|
47
|
+
right: left + container.clientWidth
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const viewport = document.documentElement;
|
|
51
|
+
return {
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
bottom: viewport.clientHeight,
|
|
55
|
+
right: viewport.clientWidth
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const checkVisible = () => {
|
|
59
|
+
const rect = element.getBoundingClientRect();
|
|
60
|
+
const bounds = getRootBounds();
|
|
61
|
+
return direction === "vertical" ? rect.top - rootMargin < bounds.bottom && rect.bottom + rootMargin >= bounds.top : rect.left - rootMargin < bounds.right && rect.right + rootMargin >= bounds.left;
|
|
62
|
+
};
|
|
63
|
+
if (checkVisible()) {
|
|
64
|
+
setCondition(true);
|
|
65
|
+
if (preserveOnceReady) return;
|
|
66
|
+
}
|
|
67
|
+
const debouncedHandleScroll = (0, _fringeworks_utils_timer_debounce.default)(() => {
|
|
68
|
+
if (!isMounted()) return;
|
|
69
|
+
const isVisible = checkVisible();
|
|
70
|
+
setCondition(isVisible);
|
|
71
|
+
if (preserveOnceReady && isVisible) scrollTarget.removeEventListener("scroll", debouncedHandleScroll);
|
|
72
|
+
}, detectionDelay);
|
|
73
|
+
scrollTarget.addEventListener("scroll", debouncedHandleScroll, { passive: true });
|
|
74
|
+
return () => {
|
|
75
|
+
debouncedHandleScroll.cancel();
|
|
76
|
+
scrollTarget.removeEventListener("scroll", debouncedHandleScroll);
|
|
77
|
+
};
|
|
78
|
+
}, [
|
|
79
|
+
elementRef,
|
|
80
|
+
elementRef?.current,
|
|
81
|
+
rootRef.current,
|
|
82
|
+
rootMargin,
|
|
83
|
+
detectionDelay,
|
|
84
|
+
direction,
|
|
85
|
+
preserveOnceReady
|
|
86
|
+
]);
|
|
87
|
+
return require_useDeferUntilTrue_useDeferUntilTrue(target, condition, {
|
|
88
|
+
preserveOnceReady,
|
|
89
|
+
...opts
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
module.exports = useDeferUntilScrolled;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.cjs";
|
|
2
|
+
import { UseDeferUntilScrolledOptions } from "./types.cjs";
|
|
3
|
+
import { ReactNode, RefObject } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilScrolled/useDeferUntilScrolled.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 縦または横スクロール位置に基づいて描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param elementRef 基準となる要素の参照(参照自体がnull/undefinedの場合は待たずに描画する)
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilScrolled<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, elementRef: RefObject<HTMLElement | null | undefined> | null | undefined, options?: UseDeferUntilScrolledOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
export = useDeferUntilScrolled;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.mjs";
|
|
2
|
+
import { UseDeferUntilScrolledOptions } from "./types.mjs";
|
|
3
|
+
import { ReactNode, RefObject } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilScrolled/useDeferUntilScrolled.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 縦または横スクロール位置に基づいて描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param elementRef 基準となる要素の参照(参照自体がnull/undefinedの場合は待たずに描画する)
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilScrolled<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, elementRef: RefObject<HTMLElement | null | undefined> | null | undefined, options?: UseDeferUntilScrolledOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useDeferUntilScrolled as default };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import useDeferUntilTrue from "../useDeferUntilTrue/useDeferUntilTrue.mjs";
|
|
4
|
+
import "../useDeferUntilTrue/index.mjs";
|
|
5
|
+
import useIsMounted from "@fringeworks/react-utils/hooks/useIsMounted";
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import debounce from "@fringeworks/utils/timer/debounce";
|
|
8
|
+
|
|
9
|
+
//#region src/useDeferUntilScrolled/useDeferUntilScrolled.tsx
|
|
10
|
+
/**
|
|
11
|
+
* 縦または横スクロール位置に基づいて描画を遅延させるhook
|
|
12
|
+
* @param target 描画対象のノード
|
|
13
|
+
* @param elementRef 基準となる要素の参照(参照自体がnull/undefinedの場合は待たずに描画する)
|
|
14
|
+
* @param options オプション
|
|
15
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
16
|
+
*/
|
|
17
|
+
function useDeferUntilScrolled(target, elementRef, options = {}) {
|
|
18
|
+
const defaultRootRef = useRef(null);
|
|
19
|
+
const { rootRef = defaultRootRef, rootMargin = 0, detectionDelay = 100, preserveOnceReady, direction = "vertical", initialCondition = false, ...opts } = options;
|
|
20
|
+
const [condition, setCondition] = useState(!elementRef || initialCondition);
|
|
21
|
+
const isMounted = useIsMounted();
|
|
22
|
+
const isFirstRun = useRef(true);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const isFirst = isFirstRun.current;
|
|
25
|
+
isFirstRun.current = false;
|
|
26
|
+
if (!elementRef) {
|
|
27
|
+
setCondition(true);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!isFirst) setCondition(false);
|
|
31
|
+
const element = elementRef.current;
|
|
32
|
+
if (!element) return;
|
|
33
|
+
const container = rootRef.current;
|
|
34
|
+
const scrollTarget = container ?? window;
|
|
35
|
+
const getRootBounds = () => {
|
|
36
|
+
if (container) {
|
|
37
|
+
const rect = container.getBoundingClientRect();
|
|
38
|
+
const top = rect.top + container.clientTop;
|
|
39
|
+
const left = rect.left + container.clientLeft;
|
|
40
|
+
return {
|
|
41
|
+
top,
|
|
42
|
+
left,
|
|
43
|
+
bottom: top + container.clientHeight,
|
|
44
|
+
right: left + container.clientWidth
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const viewport = document.documentElement;
|
|
48
|
+
return {
|
|
49
|
+
top: 0,
|
|
50
|
+
left: 0,
|
|
51
|
+
bottom: viewport.clientHeight,
|
|
52
|
+
right: viewport.clientWidth
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const checkVisible = () => {
|
|
56
|
+
const rect = element.getBoundingClientRect();
|
|
57
|
+
const bounds = getRootBounds();
|
|
58
|
+
return direction === "vertical" ? rect.top - rootMargin < bounds.bottom && rect.bottom + rootMargin >= bounds.top : rect.left - rootMargin < bounds.right && rect.right + rootMargin >= bounds.left;
|
|
59
|
+
};
|
|
60
|
+
if (checkVisible()) {
|
|
61
|
+
setCondition(true);
|
|
62
|
+
if (preserveOnceReady) return;
|
|
63
|
+
}
|
|
64
|
+
const debouncedHandleScroll = debounce(() => {
|
|
65
|
+
if (!isMounted()) return;
|
|
66
|
+
const isVisible = checkVisible();
|
|
67
|
+
setCondition(isVisible);
|
|
68
|
+
if (preserveOnceReady && isVisible) scrollTarget.removeEventListener("scroll", debouncedHandleScroll);
|
|
69
|
+
}, detectionDelay);
|
|
70
|
+
scrollTarget.addEventListener("scroll", debouncedHandleScroll, { passive: true });
|
|
71
|
+
return () => {
|
|
72
|
+
debouncedHandleScroll.cancel();
|
|
73
|
+
scrollTarget.removeEventListener("scroll", debouncedHandleScroll);
|
|
74
|
+
};
|
|
75
|
+
}, [
|
|
76
|
+
elementRef,
|
|
77
|
+
elementRef?.current,
|
|
78
|
+
rootRef.current,
|
|
79
|
+
rootMargin,
|
|
80
|
+
detectionDelay,
|
|
81
|
+
direction,
|
|
82
|
+
preserveOnceReady
|
|
83
|
+
]);
|
|
84
|
+
return useDeferUntilTrue(target, condition, {
|
|
85
|
+
preserveOnceReady,
|
|
86
|
+
...opts
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { useDeferUntilScrolled as default };
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UseDeferUntilTrueOptions } from "../useDeferUntilTrue/types.cjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/useDeferUntilTimeout/types.d.ts
|
|
5
|
+
type UseDeferUntilTimeoutOptions<P extends ReactNode = ReactNode> = UseDeferUntilTrueOptions<P>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { UseDeferUntilTimeoutOptions };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UseDeferUntilTrueOptions } from "../useDeferUntilTrue/types.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/useDeferUntilTimeout/types.d.ts
|
|
5
|
+
type UseDeferUntilTimeoutOptions<P extends ReactNode = ReactNode> = UseDeferUntilTrueOptions<P>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { UseDeferUntilTimeoutOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
const require_useDeferUntilTrue_useDeferUntilTrue = require('../useDeferUntilTrue/useDeferUntilTrue.cjs');
|
|
5
|
+
require('../useDeferUntilTrue/index.cjs');
|
|
6
|
+
let _fringeworks_react_utils_hooks_useIsMounted = require("@fringeworks/react-utils/hooks/useIsMounted");
|
|
7
|
+
_fringeworks_react_utils_hooks_useIsMounted = require_runtime.__toESM(_fringeworks_react_utils_hooks_useIsMounted, 1);
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let _fringeworks_utils_timer_setTimeoutExtended = require("@fringeworks/utils/timer/setTimeoutExtended");
|
|
10
|
+
_fringeworks_utils_timer_setTimeoutExtended = require_runtime.__toESM(_fringeworks_utils_timer_setTimeoutExtended, 1);
|
|
11
|
+
|
|
12
|
+
//#region src/useDeferUntilTimeout/useDeferUntilTimeout.tsx
|
|
13
|
+
/**
|
|
14
|
+
* 指定の時間が経過するまで描画を遅延させるhook
|
|
15
|
+
* @param target 描画対象のノード
|
|
16
|
+
* @param defer 遅延させる時間(ms)(null/undefinedの場合は待たずに描画する)
|
|
17
|
+
* @param options オプション
|
|
18
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
19
|
+
*/
|
|
20
|
+
function useDeferUntilTimeout(target, defer, options = {}) {
|
|
21
|
+
const [condition, setCondition] = (0, react.useState)(defer == null || defer <= 0);
|
|
22
|
+
const isMounted = (0, _fringeworks_react_utils_hooks_useIsMounted.default)();
|
|
23
|
+
(0, react.useEffect)(() => {
|
|
24
|
+
if (defer == null || defer <= 0) {
|
|
25
|
+
setCondition(true);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setCondition(false);
|
|
29
|
+
const cancel = (0, _fringeworks_utils_timer_setTimeoutExtended.default)(() => {
|
|
30
|
+
if (isMounted()) setCondition(true);
|
|
31
|
+
}, defer);
|
|
32
|
+
return () => {
|
|
33
|
+
cancel();
|
|
34
|
+
};
|
|
35
|
+
}, [defer]);
|
|
36
|
+
return require_useDeferUntilTrue_useDeferUntilTrue(target, condition, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
module.exports = useDeferUntilTimeout;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.cjs";
|
|
2
|
+
import { UseDeferUntilTimeoutOptions } from "./types.cjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilTimeout/useDeferUntilTimeout.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 指定の時間が経過するまで描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param defer 遅延させる時間(ms)(null/undefinedの場合は待たずに描画する)
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilTimeout<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, defer: number | null | undefined, options?: UseDeferUntilTimeoutOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
export = useDeferUntilTimeout;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.mjs";
|
|
2
|
+
import { UseDeferUntilTimeoutOptions } from "./types.mjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilTimeout/useDeferUntilTimeout.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 指定の時間が経過するまで描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param defer 遅延させる時間(ms)(null/undefinedの場合は待たずに描画する)
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilTimeout<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, defer: number | null | undefined, options?: UseDeferUntilTimeoutOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useDeferUntilTimeout as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import useDeferUntilTrue from "../useDeferUntilTrue/useDeferUntilTrue.mjs";
|
|
4
|
+
import "../useDeferUntilTrue/index.mjs";
|
|
5
|
+
import useIsMounted from "@fringeworks/react-utils/hooks/useIsMounted";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import setTimeoutExtended from "@fringeworks/utils/timer/setTimeoutExtended";
|
|
8
|
+
|
|
9
|
+
//#region src/useDeferUntilTimeout/useDeferUntilTimeout.tsx
|
|
10
|
+
/**
|
|
11
|
+
* 指定の時間が経過するまで描画を遅延させるhook
|
|
12
|
+
* @param target 描画対象のノード
|
|
13
|
+
* @param defer 遅延させる時間(ms)(null/undefinedの場合は待たずに描画する)
|
|
14
|
+
* @param options オプション
|
|
15
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
16
|
+
*/
|
|
17
|
+
function useDeferUntilTimeout(target, defer, options = {}) {
|
|
18
|
+
const [condition, setCondition] = useState(defer == null || defer <= 0);
|
|
19
|
+
const isMounted = useIsMounted();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (defer == null || defer <= 0) {
|
|
22
|
+
setCondition(true);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setCondition(false);
|
|
26
|
+
const cancel = setTimeoutExtended(() => {
|
|
27
|
+
if (isMounted()) setCondition(true);
|
|
28
|
+
}, defer);
|
|
29
|
+
return () => {
|
|
30
|
+
cancel();
|
|
31
|
+
};
|
|
32
|
+
}, [defer]);
|
|
33
|
+
return useDeferUntilTrue(target, condition, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useDeferUntilTimeout as default };
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeferRenderingOptionsBase } from "../types.cjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/useDeferUntilTrue/types.d.ts
|
|
5
|
+
type UseDeferUntilTrueOptions<P extends ReactNode = ReactNode> = DeferRenderingOptionsBase<P>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { UseDeferUntilTrueOptions };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeferRenderingOptionsBase } from "../types.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/useDeferUntilTrue/types.d.ts
|
|
5
|
+
type UseDeferUntilTrueOptions<P extends ReactNode = ReactNode> = DeferRenderingOptionsBase<P>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { UseDeferUntilTrueOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_constants = require('../constants.cjs');
|
|
4
|
+
const require_useDeferUntilReady_useDeferUntilReady = require('../useDeferUntilReady/useDeferUntilReady.cjs');
|
|
5
|
+
require('../useDeferUntilReady/index.cjs');
|
|
6
|
+
|
|
7
|
+
//#region src/useDeferUntilTrue/useDeferUntilTrue.tsx
|
|
8
|
+
/**
|
|
9
|
+
* 条件がtrueになるまで描画を遅延させるhook
|
|
10
|
+
* @param target 描画対象のノード
|
|
11
|
+
* @param condition 条件
|
|
12
|
+
* @param options オプション
|
|
13
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
14
|
+
*/
|
|
15
|
+
function useDeferUntilTrue(target, condition, options = {}) {
|
|
16
|
+
return require_useDeferUntilReady_useDeferUntilReady(target, condition ? require_constants.RenderingState.ready : require_constants.RenderingState.pending, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
module.exports = useDeferUntilTrue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.cjs";
|
|
2
|
+
import { UseDeferUntilTrueOptions } from "./types.cjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilTrue/useDeferUntilTrue.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 条件がtrueになるまで描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param condition 条件
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilTrue<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, condition: boolean | null | undefined, options?: UseDeferUntilTrueOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
export = useDeferUntilTrue;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DeferRenderingResult } from "../types.mjs";
|
|
2
|
+
import { UseDeferUntilTrueOptions } from "./types.mjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/useDeferUntilTrue/useDeferUntilTrue.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 条件がtrueになるまで描画を遅延させるhook
|
|
8
|
+
* @param target 描画対象のノード
|
|
9
|
+
* @param condition 条件
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
12
|
+
*/
|
|
13
|
+
declare function useDeferUntilTrue<T extends ReactNode, P extends ReactNode = ReactNode>(target: T, condition: boolean | null | undefined, options?: UseDeferUntilTrueOptions<P>): DeferRenderingResult<T | P>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useDeferUntilTrue as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { RenderingState } from "../constants.mjs";
|
|
4
|
+
import useDeferUntilReady from "../useDeferUntilReady/useDeferUntilReady.mjs";
|
|
5
|
+
import "../useDeferUntilReady/index.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/useDeferUntilTrue/useDeferUntilTrue.tsx
|
|
8
|
+
/**
|
|
9
|
+
* 条件がtrueになるまで描画を遅延させるhook
|
|
10
|
+
* @param target 描画対象のノード
|
|
11
|
+
* @param condition 条件
|
|
12
|
+
* @param options オプション
|
|
13
|
+
* @returns state('pending', 'ready')と状態に応じたノード
|
|
14
|
+
*/
|
|
15
|
+
function useDeferUntilTrue(target, condition, options = {}) {
|
|
16
|
+
return useDeferUntilReady(target, condition ? RenderingState.ready : RenderingState.pending, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useDeferUntilTrue as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UseDeferUntilWebFontReadyOptions, WebFont, WebFontTarget, WebFontTargets } from "./types.cjs";
|
|
2
|
+
import useDeferUntilWebFontReady from "./useDeferUntilWebFontReady.cjs";
|
|
3
|
+
export { type UseDeferUntilWebFontReadyOptions, type WebFont, type WebFontTarget, type WebFontTargets, useDeferUntilWebFontReady as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UseDeferUntilWebFontReadyOptions, WebFont, WebFontTarget, WebFontTargets } from "./types.mjs";
|
|
2
|
+
import useDeferUntilWebFontReady from "./useDeferUntilWebFontReady.mjs";
|
|
3
|
+
export { type UseDeferUntilWebFontReadyOptions, type WebFont, type WebFontTarget, type WebFontTargets, useDeferUntilWebFontReady as default };
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RenderingState } from "../constants.cjs";
|
|
2
|
+
import { UseDeferUntilReadyOptions } from "../useDeferUntilReady/types.cjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { WebFontMatchOptions } from "@fringeworks/web-font-observer";
|
|
5
|
+
|
|
6
|
+
//#region src/useDeferUntilWebFontReady/types.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 太さ等を指定して待つWebフォント
|
|
9
|
+
*/
|
|
10
|
+
type WebFont = WebFontMatchOptions & {
|
|
11
|
+
/**
|
|
12
|
+
* フォントファミリー
|
|
13
|
+
*/
|
|
14
|
+
family: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 待つWebフォント\
|
|
18
|
+
* フォントファミリーのみで良い場合は文字列で指定できる
|
|
19
|
+
*/
|
|
20
|
+
type WebFontTarget = string | WebFont;
|
|
21
|
+
/**
|
|
22
|
+
* 待つWebフォントの指定\
|
|
23
|
+
* 複数のWebフォントを待つ場合は配列で指定する。配列内のnull/undefinedは無視される
|
|
24
|
+
*/
|
|
25
|
+
type WebFontTargets = WebFontTarget | readonly (WebFontTarget | null | undefined)[];
|
|
26
|
+
type UseDeferUntilWebFontReadyOptions<P extends ReactNode = ReactNode, E extends ReactNode = ReactNode> = UseDeferUntilReadyOptions<P, E> & {
|
|
27
|
+
/**
|
|
28
|
+
* Webフォントが利用可能にならなかった場合に失敗とみなすまでの時間(ミリ秒)\
|
|
29
|
+
* Webフォントごとに適用されるが、すべて並行して待つため実質的に全体の待ち時間となる\
|
|
30
|
+
* デフォルトはブラウザがWebフォントを待つ時間(block period)の推奨値と同じ3000ms
|
|
31
|
+
* @default 3000
|
|
32
|
+
*/
|
|
33
|
+
timeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Webフォントをロードする関数\
|
|
36
|
+
* 完了後にWebフォントの確認が行われる。待つWebフォントが変わった時のみ呼ばれる
|
|
37
|
+
* @param signal 待機が不要になった時に中断されるAbortSignal
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
loader?: (signal: AbortSignal) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* SSR時など、実際のWebフォント読み込み状態を判定できない環境での初期状態\
|
|
43
|
+
* デフォルトは'pending'
|
|
44
|
+
* @default 'pending'
|
|
45
|
+
*/
|
|
46
|
+
initialState?: RenderingState;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { UseDeferUntilWebFontReadyOptions, WebFont, WebFontTarget, WebFontTargets };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RenderingState } from "../constants.mjs";
|
|
2
|
+
import { UseDeferUntilReadyOptions } from "../useDeferUntilReady/types.mjs";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { WebFontMatchOptions } from "@fringeworks/web-font-observer";
|
|
5
|
+
|
|
6
|
+
//#region src/useDeferUntilWebFontReady/types.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* 太さ等を指定して待つWebフォント
|
|
9
|
+
*/
|
|
10
|
+
type WebFont = WebFontMatchOptions & {
|
|
11
|
+
/**
|
|
12
|
+
* フォントファミリー
|
|
13
|
+
*/
|
|
14
|
+
family: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 待つWebフォント\
|
|
18
|
+
* フォントファミリーのみで良い場合は文字列で指定できる
|
|
19
|
+
*/
|
|
20
|
+
type WebFontTarget = string | WebFont;
|
|
21
|
+
/**
|
|
22
|
+
* 待つWebフォントの指定\
|
|
23
|
+
* 複数のWebフォントを待つ場合は配列で指定する。配列内のnull/undefinedは無視される
|
|
24
|
+
*/
|
|
25
|
+
type WebFontTargets = WebFontTarget | readonly (WebFontTarget | null | undefined)[];
|
|
26
|
+
type UseDeferUntilWebFontReadyOptions<P extends ReactNode = ReactNode, E extends ReactNode = ReactNode> = UseDeferUntilReadyOptions<P, E> & {
|
|
27
|
+
/**
|
|
28
|
+
* Webフォントが利用可能にならなかった場合に失敗とみなすまでの時間(ミリ秒)\
|
|
29
|
+
* Webフォントごとに適用されるが、すべて並行して待つため実質的に全体の待ち時間となる\
|
|
30
|
+
* デフォルトはブラウザがWebフォントを待つ時間(block period)の推奨値と同じ3000ms
|
|
31
|
+
* @default 3000
|
|
32
|
+
*/
|
|
33
|
+
timeout?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Webフォントをロードする関数\
|
|
36
|
+
* 完了後にWebフォントの確認が行われる。待つWebフォントが変わった時のみ呼ばれる
|
|
37
|
+
* @param signal 待機が不要になった時に中断されるAbortSignal
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
loader?: (signal: AbortSignal) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* SSR時など、実際のWebフォント読み込み状態を判定できない環境での初期状態\
|
|
43
|
+
* デフォルトは'pending'
|
|
44
|
+
* @default 'pending'
|
|
45
|
+
*/
|
|
46
|
+
initialState?: RenderingState;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { UseDeferUntilWebFontReadyOptions, WebFont, WebFontTarget, WebFontTargets };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|