@aiquants/virtualscroll 1.18.0 → 1.18.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.
- package/README.md +85 -16
- package/dist/ScrollBar.d.cts +100 -0
- package/dist/ScrollBar.d.ts.map +1 -0
- package/dist/ScrollPane.d.cts +93 -0
- package/dist/ScrollPane.d.ts.map +1 -0
- package/dist/TapScrollCircle.d.cts +62 -0
- package/dist/TapScrollCircle.d.ts.map +1 -0
- package/dist/VirtualScroll.d.cts +155 -0
- package/dist/{src/VirtualScroll.d.ts → VirtualScroll.d.ts} +46 -3
- package/dist/VirtualScroll.d.ts.map +1 -0
- package/dist/cli.js +97 -24
- package/dist/cli.server.d.cts +13 -0
- package/dist/cli.server.d.ts +14 -0
- package/dist/cli.server.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/{src/index.d.ts → index.d.cts} +9 -10
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1862 -1352
- package/dist/{src/logger.d.ts → logger.d.cts} +48 -1
- package/dist/logger.d.ts +146 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/tapScrollCircleSampleVisual.d.cts +2 -0
- package/dist/tapScrollCircleSampleVisual.d.ts.map +1 -0
- package/dist/{src/useFenwickMapTree.d.ts → useFenwickMapTree.d.cts} +138 -16
- package/dist/useFenwickMapTree.d.ts +451 -0
- package/dist/useFenwickMapTree.d.ts.map +1 -0
- package/dist/useHeightCache.d.cts +15 -0
- package/dist/useHeightCache.d.ts.map +1 -0
- package/dist/{src/useLruCache.d.ts → useLruCache.d.cts} +8 -2
- package/dist/useLruCache.d.ts +24 -0
- package/dist/useLruCache.d.ts.map +1 -0
- package/dist/{src/utils.d.ts → utils.d.cts} +3 -1
- package/dist/utils.d.ts +15 -0
- package/dist/{src/utils.d.ts.map → utils.d.ts.map} +1 -1
- package/package.json +12 -6
- package/dist/src/ScrollBar.d.ts.map +0 -1
- package/dist/src/ScrollPane.d.ts.map +0 -1
- package/dist/src/TapScrollCircle.d.ts.map +0 -1
- package/dist/src/VirtualScroll.d.ts.map +0 -1
- package/dist/src/cli.server.d.ts +0 -2
- package/dist/src/cli.server.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/tapScrollCircleSampleVisual.d.ts.map +0 -1
- package/dist/src/useFenwickMapTree.d.ts.map +0 -1
- package/dist/src/useHeightCache.d.ts.map +0 -1
- package/dist/src/useLruCache.d.ts.map +0 -1
- package/dist/virtualscroll.css +0 -1
- package/dist/vite.config.d.ts +0 -3
- package/dist/vite.config.d.ts.map +0 -1
- /package/dist/{src/ScrollBar.d.ts → ScrollBar.d.ts} +0 -0
- /package/dist/{src/ScrollPane.d.ts → ScrollPane.d.ts} +0 -0
- /package/dist/{src/TapScrollCircle.d.ts → TapScrollCircle.d.ts} +0 -0
- /package/dist/{src/tapScrollCircleSampleVisual.d.ts → tapScrollCircleSampleVisual.d.ts} +0 -0
- /package/dist/{src/useHeightCache.d.ts → useHeightCache.d.ts} +0 -0
|
@@ -29,7 +29,18 @@ export interface ILogger {
|
|
|
29
29
|
/**
|
|
30
30
|
* @class Logger
|
|
31
31
|
* @description A wrapper class for handling logging with levels and prefixes.
|
|
32
|
+
*
|
|
33
|
+
* Lazy-argument contract: any function passed as a log argument is treated as a
|
|
34
|
+
* lazy-evaluation thunk and is invoked (with no arguments) only when the level
|
|
35
|
+
* is enabled. To log a function itself as a value, wrap it as `() => fn`.
|
|
36
|
+
* If invoking the thunk throws (e.g. a class constructor or a failing thunk),
|
|
37
|
+
* the original function value is logged as-is instead of crashing the caller.
|
|
32
38
|
* @description レベルとプレフィックスを使用したログ記録を処理するためのラッパークラス。
|
|
39
|
+
*
|
|
40
|
+
* 遅延評価の契約: ログ引数に渡された関数は遅延評価 thunk とみなし、レベルが有効な場合のみ
|
|
41
|
+
* 引数なしで呼び出す。関数そのものを値としてログしたい場合は `() => fn` とラップすること。
|
|
42
|
+
* thunk の呼び出しが throw した場合 (class や失敗する thunk) は、呼び出し元をクラッシュ
|
|
43
|
+
* させずに元の関数値をそのまま出力する仕様。
|
|
33
44
|
*/
|
|
34
45
|
export declare class Logger implements ILogger {
|
|
35
46
|
private level;
|
|
@@ -85,6 +96,43 @@ export declare class Logger implements ILogger {
|
|
|
85
96
|
* @param {string} prefix - The new prefix.
|
|
86
97
|
*/
|
|
87
98
|
setPrefix(prefix: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* @method isEnabled
|
|
101
|
+
* @description Returns whether the given level would be emitted at the current level (static instance).
|
|
102
|
+
* @description 指定したレベルが現在のログレベルで出力されるかどうかを返します(静的インスタンス)。
|
|
103
|
+
* @param {LogLevel} level - The level to query. / 問い合わせるレベル。
|
|
104
|
+
* @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
|
|
105
|
+
*/
|
|
106
|
+
static isEnabled(level: LogLevel): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* @method isEnabled
|
|
109
|
+
* @description Returns whether the given level would be emitted at the current level.
|
|
110
|
+
* @description 指定したレベルが現在のログレベルで出力されるかどうかを返します。
|
|
111
|
+
*
|
|
112
|
+
* ホットパスで呼び出し側が引数(オブジェクト生成・DOM 読み取り等)を組み立てる前に
|
|
113
|
+
* ガードするために使う。抑制時は引数評価を丸ごと省ける。
|
|
114
|
+
*
|
|
115
|
+
* @param {LogLevel} level - The level to query. / 問い合わせるレベル。
|
|
116
|
+
* @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
|
|
117
|
+
*/
|
|
118
|
+
isEnabled(level: LogLevel): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Resolves a possibly-lazy log argument.
|
|
121
|
+
* If the argument is a function it is treated as a thunk and invoked only when the
|
|
122
|
+
* level is enabled; if the invocation throws (class constructors cannot be called
|
|
123
|
+
* without `new`, or the thunk itself fails), the original function value is
|
|
124
|
+
* returned as-is so the log call never crashes the caller and still emits something.
|
|
125
|
+
* To log a function as a value, wrap it as `() => fn`.
|
|
126
|
+
* 遅延評価される可能性のあるログ引数を解決する処理。
|
|
127
|
+
*
|
|
128
|
+
* 関数が渡された場合はサンク (thunk) とみなし、レベルが有効なとき「だけ」呼び出す。
|
|
129
|
+
* これにより呼び出し側は `logger.debug(() => ({ ...expensive }))` のように書け、
|
|
130
|
+
* レベル抑制時にはオブジェクト生成や DOM 読み取りを回避できる。
|
|
131
|
+
* 呼び出しが throw した場合 (class は `new` なしで呼べず TypeError、または thunk 自体の失敗) は、
|
|
132
|
+
* ログ呼び出しが呼び出し元をクラッシュさせないよう元の関数値をそのまま返す (握り潰さず出力は残る)。
|
|
133
|
+
* 関数を値としてログしたい場合は `() => fn` とラップする。非関数値はそのまま素通しするため後方互換。
|
|
134
|
+
*/
|
|
135
|
+
private static resolveLazy;
|
|
88
136
|
private formatMessage;
|
|
89
137
|
static debug(message?: unknown, ...optionalParams: unknown[]): void;
|
|
90
138
|
debug(message?: unknown, ...optionalParams: unknown[]): void;
|
|
@@ -95,4 +143,3 @@ export declare class Logger implements ILogger {
|
|
|
95
143
|
static error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
96
144
|
error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
97
145
|
}
|
|
98
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils/logger
|
|
3
|
+
* @description Logger utility for consistent log management across the library.
|
|
4
|
+
* @description ライブラリ全体で一貫したログ管理を行うためのロガーユーティリティ。
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @enum LogLevel
|
|
8
|
+
* @description Log levels for filtering output.
|
|
9
|
+
* @description 出力をフィルタリングするためのログレベル。
|
|
10
|
+
*/
|
|
11
|
+
export declare enum LogLevel {
|
|
12
|
+
DEBUG = 0,
|
|
13
|
+
INFO = 1,
|
|
14
|
+
WARN = 2,
|
|
15
|
+
ERROR = 3,
|
|
16
|
+
NONE = 4
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @interface ILogger
|
|
20
|
+
* @description Interface for a logger object compatible with Console.
|
|
21
|
+
* @description Console と互換性のあるロガーオブジェクトのインターフェース。
|
|
22
|
+
*/
|
|
23
|
+
export interface ILogger {
|
|
24
|
+
debug(message?: unknown, ...optionalParams: unknown[]): void;
|
|
25
|
+
info(message?: unknown, ...optionalParams: unknown[]): void;
|
|
26
|
+
warn(message?: unknown, ...optionalParams: unknown[]): void;
|
|
27
|
+
error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @class Logger
|
|
31
|
+
* @description A wrapper class for handling logging with levels and prefixes.
|
|
32
|
+
*
|
|
33
|
+
* Lazy-argument contract: any function passed as a log argument is treated as a
|
|
34
|
+
* lazy-evaluation thunk and is invoked (with no arguments) only when the level
|
|
35
|
+
* is enabled. To log a function itself as a value, wrap it as `() => fn`.
|
|
36
|
+
* If invoking the thunk throws (e.g. a class constructor or a failing thunk),
|
|
37
|
+
* the original function value is logged as-is instead of crashing the caller.
|
|
38
|
+
* @description レベルとプレフィックスを使用したログ記録を処理するためのラッパークラス。
|
|
39
|
+
*
|
|
40
|
+
* 遅延評価の契約: ログ引数に渡された関数は遅延評価 thunk とみなし、レベルが有効な場合のみ
|
|
41
|
+
* 引数なしで呼び出す。関数そのものを値としてログしたい場合は `() => fn` とラップすること。
|
|
42
|
+
* thunk の呼び出しが throw した場合 (class や失敗する thunk) は、呼び出し元をクラッシュ
|
|
43
|
+
* させずに元の関数値をそのまま出力する仕様。
|
|
44
|
+
*/
|
|
45
|
+
export declare class Logger implements ILogger {
|
|
46
|
+
private level;
|
|
47
|
+
private prefix;
|
|
48
|
+
private impl;
|
|
49
|
+
/**
|
|
50
|
+
* @constructor
|
|
51
|
+
* @param {LogLevel} [level=LogLevel.WARN] - The minimum log level to output.
|
|
52
|
+
* @param {string} [prefix="[virtualscroll]"] - The prefix to add to all log messages.
|
|
53
|
+
* @param {ILogger} [impl=console] - The implementation to use for logging.
|
|
54
|
+
*/
|
|
55
|
+
constructor(level?: LogLevel, prefix?: string, impl?: ILogger);
|
|
56
|
+
private static instance;
|
|
57
|
+
/**
|
|
58
|
+
* @method setLevel
|
|
59
|
+
* @description Updates the current log level for the static instance.
|
|
60
|
+
* @description 静的インスタンスの現在のログレベルを更新します。
|
|
61
|
+
* @param {LogLevel} level - The new log level.
|
|
62
|
+
*/
|
|
63
|
+
static setLevel(level: LogLevel): void;
|
|
64
|
+
/**
|
|
65
|
+
* @method setLevel
|
|
66
|
+
* @description Updates the current log level.
|
|
67
|
+
* @description 現在のログレベルを更新します。
|
|
68
|
+
* @param {LogLevel} level - The new log level.
|
|
69
|
+
*/
|
|
70
|
+
setLevel(level: LogLevel): void;
|
|
71
|
+
/**
|
|
72
|
+
* @method setImplementation
|
|
73
|
+
* @description Updates the logger implementation for the static instance.
|
|
74
|
+
* @description 静的インスタンスのロガーの実装を更新します。
|
|
75
|
+
* @param {ILogger} impl - The new logger implementation.
|
|
76
|
+
*/
|
|
77
|
+
static setImplementation(impl: ILogger): void;
|
|
78
|
+
/**
|
|
79
|
+
* @method setImplementation
|
|
80
|
+
* @description Updates the logger implementation.
|
|
81
|
+
* @description ロガーの実装を更新します。
|
|
82
|
+
* @param {ILogger} impl - The new logger implementation.
|
|
83
|
+
*/
|
|
84
|
+
setImplementation(impl: ILogger): void;
|
|
85
|
+
/**
|
|
86
|
+
* @method setPrefix
|
|
87
|
+
* @description Updates the log prefix for the static instance.
|
|
88
|
+
* @description 静的インスタンスのログのプレフィックスを更新します。
|
|
89
|
+
* @param {string} prefix - The new prefix.
|
|
90
|
+
*/
|
|
91
|
+
static setPrefix(prefix: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* @method setPrefix
|
|
94
|
+
* @description Updates the log prefix.
|
|
95
|
+
* @description ログのプレフィックスを更新します。
|
|
96
|
+
* @param {string} prefix - The new prefix.
|
|
97
|
+
*/
|
|
98
|
+
setPrefix(prefix: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* @method isEnabled
|
|
101
|
+
* @description Returns whether the given level would be emitted at the current level (static instance).
|
|
102
|
+
* @description 指定したレベルが現在のログレベルで出力されるかどうかを返します(静的インスタンス)。
|
|
103
|
+
* @param {LogLevel} level - The level to query. / 問い合わせるレベル。
|
|
104
|
+
* @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
|
|
105
|
+
*/
|
|
106
|
+
static isEnabled(level: LogLevel): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* @method isEnabled
|
|
109
|
+
* @description Returns whether the given level would be emitted at the current level.
|
|
110
|
+
* @description 指定したレベルが現在のログレベルで出力されるかどうかを返します。
|
|
111
|
+
*
|
|
112
|
+
* ホットパスで呼び出し側が引数(オブジェクト生成・DOM 読み取り等)を組み立てる前に
|
|
113
|
+
* ガードするために使う。抑制時は引数評価を丸ごと省ける。
|
|
114
|
+
*
|
|
115
|
+
* @param {LogLevel} level - The level to query. / 問い合わせるレベル。
|
|
116
|
+
* @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
|
|
117
|
+
*/
|
|
118
|
+
isEnabled(level: LogLevel): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Resolves a possibly-lazy log argument.
|
|
121
|
+
* If the argument is a function it is treated as a thunk and invoked only when the
|
|
122
|
+
* level is enabled; if the invocation throws (class constructors cannot be called
|
|
123
|
+
* without `new`, or the thunk itself fails), the original function value is
|
|
124
|
+
* returned as-is so the log call never crashes the caller and still emits something.
|
|
125
|
+
* To log a function as a value, wrap it as `() => fn`.
|
|
126
|
+
* 遅延評価される可能性のあるログ引数を解決する処理。
|
|
127
|
+
*
|
|
128
|
+
* 関数が渡された場合はサンク (thunk) とみなし、レベルが有効なとき「だけ」呼び出す。
|
|
129
|
+
* これにより呼び出し側は `logger.debug(() => ({ ...expensive }))` のように書け、
|
|
130
|
+
* レベル抑制時にはオブジェクト生成や DOM 読み取りを回避できる。
|
|
131
|
+
* 呼び出しが throw した場合 (class は `new` なしで呼べず TypeError、または thunk 自体の失敗) は、
|
|
132
|
+
* ログ呼び出しが呼び出し元をクラッシュさせないよう元の関数値をそのまま返す (握り潰さず出力は残る)。
|
|
133
|
+
* 関数を値としてログしたい場合は `() => fn` とラップする。非関数値はそのまま素通しするため後方互換。
|
|
134
|
+
*/
|
|
135
|
+
private static resolveLazy;
|
|
136
|
+
private formatMessage;
|
|
137
|
+
static debug(message?: unknown, ...optionalParams: unknown[]): void;
|
|
138
|
+
debug(message?: unknown, ...optionalParams: unknown[]): void;
|
|
139
|
+
static info(message?: unknown, ...optionalParams: unknown[]): void;
|
|
140
|
+
info(message?: unknown, ...optionalParams: unknown[]): void;
|
|
141
|
+
static warn(message?: unknown, ...optionalParams: unknown[]): void;
|
|
142
|
+
warn(message?: unknown, ...optionalParams: unknown[]): void;
|
|
143
|
+
static error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
144
|
+
error(message?: unknown, ...optionalParams: unknown[]): void;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,oBAAY,QAAQ;IAChB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;CACX;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACpB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC5D,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC3D,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC3D,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAC/D;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,MAAO,YAAW,OAAO;IAClC,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,IAAI,CAAS;IAErB;;;;;OAKG;gBACS,KAAK,GAAE,QAAwB,EAAE,MAAM,GAAE,MAA0B,EAAE,IAAI,GAAE,OAAiB;IAMxG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAuD;IAE9E;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAItC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B;;;;;OAKG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAI7C;;;;;OAKG;IACH,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAItC;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAItC;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAI1C;;;;;;;;;;OAUG;IACH,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAInC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAc1B,OAAO,CAAC,aAAa;IAOrB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAInE,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM5D,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAIlE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM3D,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAIlE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAM3D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAInE,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;CAK/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tapScrollCircleSampleVisual.d.ts","sourceRoot":"","sources":["../src/tapScrollCircleSampleVisual.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAA8B,MAAM,uBAAuB,CAAA;AAI7F,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAgEzF,CAAA"}
|
|
@@ -26,6 +26,20 @@ type ValueUpdate = {
|
|
|
26
26
|
* @classdesc Fenwick Tree (バイナリインデックスツリー) の実装。
|
|
27
27
|
* このデータ構造は、接頭辞和の計算と更新を対数時間で効率的に実行。
|
|
28
28
|
* 可変サイズのアイテムのオフセットを管理できるため、特に仮想スクロールで有用。
|
|
29
|
+
*
|
|
30
|
+
* @remarks Memory: exact offsets are the design priority, so every materialized/updated row keeps
|
|
31
|
+
* an entry in `tree` and `deltas`. Memory therefore grows with the number of materialized elements,
|
|
32
|
+
* not with `size`. Rows equal to `baseValue` are pruned (zero-delta), but there is no eviction of
|
|
33
|
+
* measured deltas — evicting one would silently snap that row back to the estimated `baseValue` and
|
|
34
|
+
* corrupt `total`, which is incompatible with the exact-offset guarantee. If a hard memory ceiling
|
|
35
|
+
* is required, discard off-screen measured heights in the consumer layer (e.g. an LRU height cache)
|
|
36
|
+
* and let those rows fall back to the estimate there, rather than inside this tree.
|
|
37
|
+
* @remarks メモリ: 厳密オフセットを設計上の最優先とするため、具現化/更新された行はすべて `tree` と
|
|
38
|
+
* `deltas` にエントリを保持する。よってメモリは `size` ではなく具現化済み要素数に比例して増える。
|
|
39
|
+
* `baseValue` と一致する行は zero-delta 枝刈りされるが、計測済み delta の evict は行わない。evict すると
|
|
40
|
+
* その行が黙って推定値 `baseValue` へ戻り `total` が破損し、厳密オフセット保証と両立しないためである。
|
|
41
|
+
* ハードなメモリ上限が必要な場合は、この木の内部ではなく消費側 (LRU 高さキャッシュ等) で可視域外の
|
|
42
|
+
* 実測値を破棄し、そこで既定推定へ委ねる設計とすること。
|
|
29
43
|
*/
|
|
30
44
|
export declare class FenwickMapTree {
|
|
31
45
|
/**
|
|
@@ -76,8 +90,15 @@ export declare class FenwickMapTree {
|
|
|
76
90
|
});
|
|
77
91
|
/**
|
|
78
92
|
* @method reset
|
|
79
|
-
* @description Resets the Fenwick Tree with a new size and initial values.
|
|
80
|
-
*
|
|
93
|
+
* @description Resets the Fenwick Tree with a new size and initial values. The size is
|
|
94
|
+
* normalized on entry (non-finite/negative sizes collapse to 0, fractions are truncated).
|
|
95
|
+
* When `valueOrFn` is a function, all sampling/materialization values are computed and
|
|
96
|
+
* validated (finite-only) before the tree state is mutated, so a `valueFn` returning
|
|
97
|
+
* NaN/Infinity throws while leaving the previous tree state intact instead of a half-built one.
|
|
98
|
+
* @description Fenwick Tree を新しいサイズと初期値でリセット。size は入口で正規化する
|
|
99
|
+
* (非有限/負は 0 に縮退、小数は切り捨て)。`valueOrFn` が関数の場合、サンプリング/具現化の値は
|
|
100
|
+
* 木の状態を変異させる前に計算・検証 (有限数のみ) するため、NaN/Infinity を返す `valueFn` は
|
|
101
|
+
* throw しつつ木を半構築で残さず直前の状態を無傷に保つ方針。
|
|
81
102
|
* @param {number} size - The total number of items.
|
|
82
103
|
* @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
|
|
83
104
|
* @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
|
|
@@ -101,14 +122,35 @@ export declare class FenwickMapTree {
|
|
|
101
122
|
}): void;
|
|
102
123
|
/**
|
|
103
124
|
* @private
|
|
104
|
-
* @method
|
|
105
|
-
* @description
|
|
106
|
-
* @description `valueFn`
|
|
125
|
+
* @method _collectValidatedValues
|
|
126
|
+
* @description Evaluates `valueFn` over the inclusive `[from, to]` range and returns the values, throwing on any non-finite result. Validation happens here, before any tree mutation, so a poisoned `valueFn` can never leave the tree half-built.
|
|
127
|
+
* @description `valueFn` を閉区間 `[from, to]` で評価して値配列を返す。非有限値は throw で拒否。検証を木の変異前 (このメソッド内) で行うことで、汚染された `valueFn` が木を半構築のまま残す事態の防止。
|
|
128
|
+
* @param {(index: number) => number} valueFn - The value-generating function to evaluate.
|
|
107
129
|
* @param {number} from - The starting index of the range (inclusive).
|
|
108
130
|
* @param {number} to - The ending index of the range (inclusive).
|
|
109
|
-
* @returns {
|
|
131
|
+
* @returns {number[]} The validated (finite-only) values in index order.
|
|
132
|
+
*/
|
|
133
|
+
private static _collectValidatedValues;
|
|
134
|
+
/**
|
|
135
|
+
* @private
|
|
136
|
+
* @method _modeOrMedian
|
|
137
|
+
* @description Reduces a sample of generated values to a single representative height: the mode when it is frequent enough to be trustworthy, otherwise the median. A value is only accepted as the mode when its frequency exceeds 20% of the sample; this prevents periodic or near-uniform data (where sampling bias can make an arbitrary value momentarily frequent) from picking an unrepresentative base. Multiple co-modes are averaged.
|
|
138
|
+
* @description サンプル値を 1 つの代表的な高さへ縮約する。信頼できるほど頻出する場合は最頻値を、そうでなければ中央値を返す。最頻値はサンプルの 20% を超える頻度のときのみ採用し、周期的/ほぼ一様なデータ (サンプリング偏りで任意の値が一時的に頻出しうる) が非代表値を選ぶのを防ぐ。同率最頻値が複数ある場合は平均する。
|
|
139
|
+
* @param {number[]} values - The sampled values (mutated in place by sorting).
|
|
140
|
+
* @returns {number} The representative base value.
|
|
141
|
+
*/
|
|
142
|
+
private static _modeOrMedian;
|
|
143
|
+
/**
|
|
144
|
+
* @private
|
|
145
|
+
* @method _sampleBaseValueStrided
|
|
146
|
+
* @description Estimates `baseValue` by evaluating `valueFn` at up to `sampleCount` points spread across the entire `[0, size-1]` range, then reducing them via `_modeOrMedian`. Spanning the whole list (rather than a fixed head window) makes the majority height win even when the first items are atypical (hero/heading rows). The stride uses `ceil(size / sampleCount)` so the samples always span the whole range — `floor` would collapse to stride 1 for `sampleCount < size < 2 * sampleCount` and only ever look at the head. The stride is also forced odd to avoid aliasing against common even-period layouts (e.g. alternating or 20-row cycles), which a stride that shares a factor with the period would otherwise collapse into a single residue. For a uniform list every sample is identical, so the estimate is unchanged. Non-finite sample values throw before any state is touched.
|
|
147
|
+
* @description `valueFn` を `[0, size-1]` 全域に散らした最大 `sampleCount` 点で評価し、`_modeOrMedian` で縮約して `baseValue` を推定する。先頭固定ウィンドウではなくリスト全体を跨ぐことで、先頭が非典型 (ヒーロー/見出し行) でも多数派の高さが選ばれる。ストライドは `ceil(size / sampleCount)` を用いて常に全域を跨がせる (`floor` だと `sampleCount < size < 2 * sampleCount` で stride=1 に潰れ先頭しか見ない盲点が生じる)。さらに奇数へ強制し、周期と公約数を持つストライドがサンプルを 1 剰余類へ潰してしまう周期レイアウト (交互・20行周期など) とのエイリアシングを避ける。一様リストでは全サンプルが同一なので推定値は不変。非有限のサンプル値は状態を変異させる前に throw で拒否。
|
|
148
|
+
* @param {(index: number) => number} valueFn - The value-generating function to sample.
|
|
149
|
+
* @param {number} size - The total number of items the tree will manage.
|
|
150
|
+
* @param {number} sampleCount - Maximum number of points to evaluate.
|
|
151
|
+
* @returns {number} The estimated base value.
|
|
110
152
|
*/
|
|
111
|
-
private
|
|
153
|
+
private static _sampleBaseValueStrided;
|
|
112
154
|
/**
|
|
113
155
|
* @method update
|
|
114
156
|
* @description Updates the value at a given index.
|
|
@@ -126,16 +168,16 @@ export declare class FenwickMapTree {
|
|
|
126
168
|
updates(updates: ValueUpdate[]): number | undefined;
|
|
127
169
|
/**
|
|
128
170
|
* @method updateDelta
|
|
129
|
-
* @description Updates the delta at a given index and propagates the change through the tree.
|
|
130
|
-
* @description
|
|
171
|
+
* @description Updates the delta at a given index and propagates the change through the tree. A change that would make the effective value (`baseValue` + delta) negative is rejected with an error, mirroring the negative-value rejection of `update`/`updates`.
|
|
172
|
+
* @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。適用後の実効値 (`baseValue` + delta) が負になる変更は `update`/`updates` の負値拒否と対称に throw で拒否する方針。
|
|
131
173
|
* @param {number} index - The 0-based index to update.
|
|
132
174
|
* @param {number} change - The value to add to the delta at the given index.
|
|
133
175
|
*/
|
|
134
176
|
updateDelta(index: number, change: number): number | undefined;
|
|
135
177
|
/**
|
|
136
178
|
* @method updateDeltas
|
|
137
|
-
* @description Updates the deltas at given indices and propagates the changes through the tree.
|
|
138
|
-
* @description
|
|
179
|
+
* @description Updates the deltas at given indices and propagates the changes through the tree. All entries are validated up front (atomicity): out-of-range or non-integer indices, non-finite changes, and changes whose resulting effective value (`baseValue` + delta) would turn negative are rejected with an error before anything is applied. Negative effective values would break the monotonic prefix sums that `_descend`/`_findIndexLarge` rely on.
|
|
180
|
+
* @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。全件を先に検証してから適用する (アトミック性): 範囲外/非整数の index、非有限の change、適用後の実効値 (`baseValue` + delta) が負になる変更はいずれも適用前に throw で拒否。負の実効値は `_descend`/`_findIndexLarge` が前提とする累積和の単調性を破壊するため。
|
|
139
181
|
* @param {DeltaUpdate[]} updates - An array of updates, each with an index and the change to apply.
|
|
140
182
|
*/
|
|
141
183
|
updateDeltas(updates: DeltaUpdate[]): number | undefined;
|
|
@@ -168,8 +210,8 @@ export declare class FenwickMapTree {
|
|
|
168
210
|
/**
|
|
169
211
|
* @private
|
|
170
212
|
* @method _materialize
|
|
171
|
-
* @description Materializes the value at a specific index if it hasn't been already.
|
|
172
|
-
* @description
|
|
213
|
+
* @description Materializes the value at a specific index if it hasn't been already. A non-finite `valueFn` result throws before any mutation, symmetric with the update-path validation, so the tree is never poisoned.
|
|
214
|
+
* @description 特定のインデックスの値がまだ具現化されていない場合に具現化する。`valueFn` の非有限な返値は変異前に throw で拒否 (update 系の検証と対称) し、木を汚染させない方針。
|
|
173
215
|
* @param {number} index - The 0-based index to materialize.
|
|
174
216
|
* @param {boolean} [updateTree=true] - Whether to update the Fenwick tree after materialization.
|
|
175
217
|
*/
|
|
@@ -195,6 +237,16 @@ export declare class FenwickMapTree {
|
|
|
195
237
|
* @returns {{ index: number; total: number | undefined; cumulative: number | undefined; currentValue: number | undefined; safeIndex: number | undefined }} Binary search result.
|
|
196
238
|
*/
|
|
197
239
|
private _findIndex;
|
|
240
|
+
/**
|
|
241
|
+
* @private
|
|
242
|
+
* @method _descend
|
|
243
|
+
* @description Performs a single bitwise descent over the current tree state, returning the candidate index for the boundary condition without mutating the tree.
|
|
244
|
+
* @description 現在の木の状態に対してビット降下を 1 回実行し、木を変異させずに境界条件の候補インデックスを返す。
|
|
245
|
+
* @param {number} target - Target cumulative value.
|
|
246
|
+
* @param {boolean} chooseLowerBound - When true, finds the smallest index meeting or exceeding the target; otherwise finds the largest index not exceeding it.
|
|
247
|
+
* @returns {number} The candidate index (may be out of range when no index satisfies the condition).
|
|
248
|
+
*/
|
|
249
|
+
private _descend;
|
|
198
250
|
/**
|
|
199
251
|
* Executes a binary search using bigint arithmetic for extremely large sizes.
|
|
200
252
|
*
|
|
@@ -251,11 +303,59 @@ export declare class FenwickMapTree {
|
|
|
251
303
|
calculateAccumulatedError(): number;
|
|
252
304
|
/**
|
|
253
305
|
* @method changeSize
|
|
254
|
-
* @description Changes the size of the Fenwick Tree.
|
|
255
|
-
*
|
|
306
|
+
* @description Changes the size of the Fenwick Tree. Only tail growth/shrink is modelled: this
|
|
307
|
+
* method receives a size delta, not an index mapping, so it assumes items are appended to or
|
|
308
|
+
* removed from the tail. Existing rows keep their index-to-height association. It therefore
|
|
309
|
+
* cannot represent a middle insertion/deletion — after such a structural change the index↔height
|
|
310
|
+
* mapping is no longer preserved and the tree's deltas would apply to the wrong rows. Consumers
|
|
311
|
+
* that insert or remove items in the middle must instead reset the tree (see
|
|
312
|
+
* `useFenwickMapTree`'s `resetOnValueFnChange`, surfaced as `resetOnGetItemHeightChange` in
|
|
313
|
+
* VirtualScroll) or remount the component with a new `key`.
|
|
314
|
+
* @description Fenwick Tree のサイズを変更する。モデル化するのは末尾の伸長/縮小のみ: 本メソッドは
|
|
315
|
+
* サイズ差分のみを受け取りインデックスの対応表は受け取らないため、要素は末尾に追加/末尾から削除
|
|
316
|
+
* されると仮定する。既存行は index↔高さ の対応を保つ。したがって中間挿入/削除は表現できず、その
|
|
317
|
+
* ような構造変更の後は index↔高さ の対応が保存されず、木の delta が誤った行へ適用されてしまう。
|
|
318
|
+
* 中間で要素を挿入/削除する消費側は、代わりに木をリセットするか (`useFenwickMapTree` の
|
|
319
|
+
* `resetOnValueFnChange`。VirtualScroll では `resetOnGetItemHeightChange` として公開) 、新しい
|
|
320
|
+
* `key` でコンポーネントを再マウントすること。
|
|
321
|
+
* @remarks Validation: a non-finite `newSize` (NaN/Infinity) throws because it would poison
|
|
322
|
+
* `size`/`total` irrecoverably. Fractional sizes are truncated and negative sizes collapse to 0,
|
|
323
|
+
* matching the normalization rule of `reset`.
|
|
324
|
+
* @remarks 検証: 非有限の `newSize` (NaN/Infinity) は `size`/`total` を復旧不能に汚染するため
|
|
325
|
+
* throw。小数は切り捨て、負値は 0 に縮退 (`reset` の正規化規則と同一)。
|
|
256
326
|
* @param {number} newSize - The new size of the tree.
|
|
257
327
|
*/
|
|
258
328
|
changeSize(newSize: number): void;
|
|
329
|
+
/**
|
|
330
|
+
* @private
|
|
331
|
+
* @method _minCoveredLowBound
|
|
332
|
+
* @description Computes `min(t - lowestSetBit(t))` over the newly-activated node range `t in (oldSize, newSize]`. Any delta whose 1-based tree index is at or below this bound cannot be covered by any newly-activated node and can be skipped during an incremental grow.
|
|
333
|
+
* @description 新規有効化ノード範囲 `t in (oldSize, newSize]` にわたる `min(t - lowestSetBit(t))` を算出する。1 始まりの木インデックスがこの下限以下の delta はどの新規ノードにも覆われないため、増分伸長時にスキップできる。
|
|
334
|
+
* @param {number} oldSize - The previous size (exclusive lower bound of the new node range).
|
|
335
|
+
* @param {number} newSize - The new size (inclusive upper bound of the new node range).
|
|
336
|
+
* @returns {number} The minimum left boundary `t - lowestSetBit(t)` of the newly-activated nodes.
|
|
337
|
+
*/
|
|
338
|
+
private static _minCoveredLowBound;
|
|
339
|
+
/**
|
|
340
|
+
* @private
|
|
341
|
+
* @method _propagateDeltaToGrownNodes
|
|
342
|
+
* @description Propagates a single delta into the tree nodes newly activated by a tail growth, i.e. parent-chain nodes in `(oldSize, newSize]`.
|
|
343
|
+
* @description 末尾伸長で新規有効化されたノード ((oldSize, newSize] にある親チェーンノード) へ単一 delta を伝播する。
|
|
344
|
+
* @param {number} index - The 0-based delta index.
|
|
345
|
+
* @param {number} delta - The delta value to propagate.
|
|
346
|
+
* @param {number} oldSize - The previous size.
|
|
347
|
+
* @param {number} newSize - The new (larger) size.
|
|
348
|
+
*/
|
|
349
|
+
private _propagateDeltaToGrownNodes;
|
|
350
|
+
/**
|
|
351
|
+
* @private
|
|
352
|
+
* @method _growSize
|
|
353
|
+
* @description Extends the tree to a larger size incrementally, propagating existing deltas into newly-activated higher-order tree nodes only. Candidate deltas are narrowed via `_minCoveredLowBound`, so a typical `+1` tail append costs amortized O(log n) instead of O(D log n) (D = number of materialized deltas).
|
|
354
|
+
* @description ツリーを末尾方向に増分的に拡張する。既存 delta を新たに有効化された上位ノードにのみ伝播する。候補 delta は `_minCoveredLowBound` で絞り込むため、通常の +1 末尾追記は O(D log n) (D = 具現化済み delta 数) ではなく償却 O(log n) で済む。
|
|
355
|
+
* @param {number} oldSize - The previous size.
|
|
356
|
+
* @param {number} newSize - The new (larger) size.
|
|
357
|
+
*/
|
|
358
|
+
private _growSize;
|
|
259
359
|
/**
|
|
260
360
|
* @method getSize
|
|
261
361
|
* @description Gets the size of the tree.
|
|
@@ -308,6 +408,29 @@ export declare class FenwickMapTree {
|
|
|
308
408
|
* @description `FenwickMapTree` インスタンスを作成・管理する React フック。
|
|
309
409
|
* ツリーインスタンスは再レンダリングされても同一性を維持する。`size` または `valueOrFn` が
|
|
310
410
|
* 変更された場合に新しいインスタンスが作成される。
|
|
411
|
+
*
|
|
412
|
+
* @remarks Structural changes: `size` changes are treated as tail append/remove (see
|
|
413
|
+
* `FenwickMapTree.changeSize`). If a `size`/`itemCount` change actually reflects a middle
|
|
414
|
+
* insertion or deletion, the `valueOrFn` index↔height association is not preserved by an
|
|
415
|
+
* incremental resize; set `resetOnValueFnChange` to `true` (so the tree fully re-samples on
|
|
416
|
+
* every `valueOrFn` change) or remount with a new `key` when the list structure changes.
|
|
417
|
+
* @remarks 構造変更: `size` 変更は末尾追加/削除として扱う (`FenwickMapTree.changeSize` 参照)。
|
|
418
|
+
* `size`/`itemCount` の変更が実は中間挿入/削除を表す場合、増分リサイズでは `valueOrFn` の
|
|
419
|
+
* index↔高さ 対応が保存されないため、`resetOnValueFnChange` を `true` にする (毎回の `valueOrFn`
|
|
420
|
+
* 変更で木を全面再サンプリング) か、リスト構造変更時に新しい `key` で再マウントすること。
|
|
421
|
+
*
|
|
422
|
+
* @remarks Render-phase design constraint: this hook applies tree changes synchronously during
|
|
423
|
+
* render (not in an effect) because VirtualScroll reads `getTotal()` synchronously right after a
|
|
424
|
+
* size change. A consequence is that React concurrent's discarded renders are not undone — a
|
|
425
|
+
* shrink (deltas deletion) is irreversible if the render is thrown away. To stay safe, always pass
|
|
426
|
+
* a memoized `options`/`sampleRange` (e.g. `useMemo`) and a memoized `valueOrFn` (e.g. `useCallback`)
|
|
427
|
+
* so an unstable reference does not trigger a destructive reset every render.
|
|
428
|
+
* @remarks render フェーズの設計上の制約: 本フックはツリー変更を effect ではなく render 中に同期的に
|
|
429
|
+
* 適用する。VirtualScroll がサイズ変更直後に `getTotal()` を同期的に読む契約に依存するためである。
|
|
430
|
+
* 結果として React concurrent の破棄されたレンダーは巻き戻されず、縮小 (deltas 削除) はレンダーが
|
|
431
|
+
* 破棄されると不可逆になる。安全のため `options`/`sampleRange` は必ずメモ化して渡し (`useMemo`)、
|
|
432
|
+
* `valueOrFn` もメモ化する (`useCallback`) こと。不安定な参照は毎レンダーの破壊的 reset を招く。
|
|
433
|
+
*
|
|
311
434
|
* @param {number} size - The total number of items.
|
|
312
435
|
* @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
|
|
313
436
|
* @param {number | ((index: number) => number)} valueOrFn - 全要素の均一な値、または値を生成する関数。不要なツリーの再作成を防ぐため、この関数は `useCallback` でメモ化すること。
|
|
@@ -325,4 +448,3 @@ export declare const useFenwickMapTree: (size: number, valueOrFn: number | ((ind
|
|
|
325
448
|
resetOnValueFnChange?: boolean;
|
|
326
449
|
}) => FenwickMapTree;
|
|
327
450
|
export {};
|
|
328
|
-
//# sourceMappingURL=useFenwickMapTree.d.ts.map
|