@aiquants/virtualscroll 0.1.0 → 0.2.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/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1105 -0
- package/dist/index.js.map +1 -0
- package/dist/src/ScrollBar.d.ts +30 -0
- package/dist/src/ScrollBar.d.ts.map +1 -0
- package/dist/src/ScrollPane.d.ts +42 -0
- package/dist/src/ScrollPane.d.ts.map +1 -0
- package/dist/src/VirtualScroll.d.ts +26 -0
- package/dist/src/VirtualScroll.d.ts.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/logger.d.ts +6 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/test-setup.d.ts +1 -0
- package/dist/src/test-setup.d.ts.map +1 -0
- package/dist/src/useFenwickMapTree.d.ts +324 -0
- package/dist/src/useFenwickMapTree.d.ts.map +1 -0
- package/dist/src/useHeightCache.d.ts +16 -0
- package/dist/src/useHeightCache.d.ts.map +1 -0
- package/dist/src/useLruCache.d.ts +16 -0
- package/dist/src/useLruCache.d.ts.map +1 -0
- package/dist/src/utils.d.ts +12 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/vite.config.d.ts +3 -0
- package/dist/vite.config.d.ts.map +1 -0
- package/package.json +7 -5
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class FenwickTree
|
|
3
|
+
* @classdesc Implements a Fenwick Tree (or Binary Indexed Tree).
|
|
4
|
+
* This data structure efficiently calculates prefix sums and performs updates in logarithmic time.
|
|
5
|
+
* It is particularly useful for virtual scrolling, where it can manage the offsets of variably sized items.
|
|
6
|
+
*
|
|
7
|
+
* @classdesc Fenwick Tree (バイナリインデックスツリー) の実装。
|
|
8
|
+
* このデータ構造は、接頭辞和の計算と更新を対数時間で効率的に実行。
|
|
9
|
+
* 可変サイズのアイテムのオフセットを管理できるため、特に仮想スクロールで有用。
|
|
10
|
+
*/
|
|
11
|
+
export declare class FenwickMapTree {
|
|
12
|
+
/**
|
|
13
|
+
* @private
|
|
14
|
+
* @property {Map<number, number>} tree - The Map storing the Fenwick tree structure, specifically the sums of deltas. It is 1-indexed.
|
|
15
|
+
* @property {Map<number, number>} tree - Fenwick Tree 構造を格納する Map。特に差分の合計を保持する。1-indexed。
|
|
16
|
+
*/
|
|
17
|
+
private tree;
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
* @property {Map<number, number>} deltas - The Map storing the differences (deltas) from the base value at each index.
|
|
21
|
+
* @property {Map<number, number>} deltas - 各インデックスにおける基準値との差分 (delta) を格納する Map。
|
|
22
|
+
*/
|
|
23
|
+
private deltas;
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* @property {number} size - The number of elements the tree manages.
|
|
27
|
+
* @property {number} size - ツリーが管理する要素数。
|
|
28
|
+
*/
|
|
29
|
+
private size;
|
|
30
|
+
/**
|
|
31
|
+
* @private
|
|
32
|
+
* @property {number} baseValue - The uniform base value for all elements, used to optimize memory.
|
|
33
|
+
* @property {number} baseValue - 全要素の均一な基準値。メモリ最適化のために使用。
|
|
34
|
+
*/
|
|
35
|
+
private baseValue;
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
* @property {((index: number) => number) | undefined} valueFn - A function to generate values, stored for lazy initialization.
|
|
39
|
+
* @property {((index: number) => number) | undefined} valueFn - 値を生成するための関数。遅延初期化のために保存される。
|
|
40
|
+
*/
|
|
41
|
+
private valueFn?;
|
|
42
|
+
private total?;
|
|
43
|
+
/**
|
|
44
|
+
* @constructor
|
|
45
|
+
* @description Initializes the Fenwick Tree.
|
|
46
|
+
* @description Fenwick Tree の初期化。
|
|
47
|
+
* @param {number} size - The total number of items.
|
|
48
|
+
* @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
|
|
49
|
+
* @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
|
|
50
|
+
*/
|
|
51
|
+
constructor(size: number, valueOrFn: number | ((index: number) => number), options?: {
|
|
52
|
+
sampleRange?: {
|
|
53
|
+
from: number;
|
|
54
|
+
to: number;
|
|
55
|
+
};
|
|
56
|
+
materialize?: boolean;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* @method reset
|
|
60
|
+
* @description Resets the Fenwick Tree with a new size and initial values.
|
|
61
|
+
* @description Fenwick Tree を新しいサイズと初期値でリセット。
|
|
62
|
+
* @param {number} size - The total number of items.
|
|
63
|
+
* @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
|
|
64
|
+
* @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
|
|
65
|
+
*/
|
|
66
|
+
reset(size: number, valueOrFn: number | ((index: number) => number), options?: {
|
|
67
|
+
sampleRange?: {
|
|
68
|
+
from: number;
|
|
69
|
+
to: number;
|
|
70
|
+
};
|
|
71
|
+
materialize?: boolean;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* @method setValueFn
|
|
75
|
+
* @description Updates the value function and re-initializes the tree.
|
|
76
|
+
* @description 値関数を更新し、ツリーを再初期化する。
|
|
77
|
+
* @param {number | ((index: number) => number)} valueOrFn - The new value for all elements, or a function to generate values.
|
|
78
|
+
*/
|
|
79
|
+
setValueFn(valueOrFn: number | ((index: number) => number)): void;
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
* @method _calculateMode
|
|
83
|
+
* @description Calculates the mode (most frequent value) within a given range of values generated by `valueFn`. If multiple modes exist, it returns their average. If no value appears more than once, it returns the median of the range. This approach helps determine a representative `baseValue` for the Fenwick tree, especially for data with high variance. It also returns the array of values generated within the range for reuse.
|
|
84
|
+
* @description `valueFn` によって生成される値の指定された範囲内の最頻値を計算する。最頻値が複数存在する場合は、それらの平均値を返す。どの値も複数回出現しない場合は、範囲の中央値を返す。このアプローチは、特に分散の大きいデータに対して、Fenwick Tree の代表的な `baseValue` を決定するのに役立つ。また、再利用のために範囲内で生成された値の配列も返す。
|
|
85
|
+
* @param {number} from - The starting index of the range (inclusive).
|
|
86
|
+
* @param {number} to - The ending index of the range (inclusive).
|
|
87
|
+
* @returns {{ mode: number; materializedValues: number[] }} An object containing the calculated mode and the array of generated values.
|
|
88
|
+
*/
|
|
89
|
+
private _calculateMode;
|
|
90
|
+
/**
|
|
91
|
+
* @method update
|
|
92
|
+
* @description Updates the value at a given index.
|
|
93
|
+
* @description 指定されたインデックスの値を更新。
|
|
94
|
+
* @param {number} index - The 0-based index to update.
|
|
95
|
+
* @param {number} value - The new value.
|
|
96
|
+
*/
|
|
97
|
+
update(index: number, value: number): number | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* @method updates
|
|
100
|
+
* @description Updates the values at given indices.
|
|
101
|
+
* @description 指定されたインデックスの値を更新。
|
|
102
|
+
* @param {{ index: number; value: number }[]} updates - An array of updates, each with an index and the new value.
|
|
103
|
+
*/
|
|
104
|
+
updates(updates: {
|
|
105
|
+
index: number;
|
|
106
|
+
value: number;
|
|
107
|
+
}[]): number | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* @method updateDelta
|
|
110
|
+
* @description Updates the delta at a given index and propagates the change through the tree.
|
|
111
|
+
* @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
|
|
112
|
+
* @param {number} index - The 0-based index to update.
|
|
113
|
+
* @param {number} change - The value to add to the delta at the given index.
|
|
114
|
+
*/
|
|
115
|
+
updateDelta(index: number, change: number): number | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* @method updateDeltas
|
|
118
|
+
* @description Updates the deltas at given indices and propagates the changes through the tree.
|
|
119
|
+
* @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
|
|
120
|
+
* @param {{ index: number; change: number }[]} updates - An array of updates, each with an index and the change to apply.
|
|
121
|
+
*/
|
|
122
|
+
updateDeltas(updates: {
|
|
123
|
+
index: number;
|
|
124
|
+
change: number;
|
|
125
|
+
}[]): number | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* @private
|
|
128
|
+
* @method _updateTree
|
|
129
|
+
* @description Updates the Fenwick tree and the total sum with a given change.
|
|
130
|
+
* @description Fenwick Tree と合計値を指定された変更で更新する。
|
|
131
|
+
* @param {number} index - The 0-based index that changed.
|
|
132
|
+
* @param {number} change - The change in value.
|
|
133
|
+
*/
|
|
134
|
+
private _updateTree;
|
|
135
|
+
/**
|
|
136
|
+
* @private
|
|
137
|
+
* @method _materialize
|
|
138
|
+
* @description Materializes the value at a specific index if it hasn't been already.
|
|
139
|
+
* @description 特定のインデックスの値がまだ具現化されていない場合に具現化する。
|
|
140
|
+
* @param {number} index - The 0-based index to materialize.
|
|
141
|
+
* @param {boolean} [updateTree=true] - Whether to update the Fenwick tree after materialization.
|
|
142
|
+
*/
|
|
143
|
+
private _materialize;
|
|
144
|
+
/**
|
|
145
|
+
* @method prefixSum
|
|
146
|
+
* @description Calculates the cumulative sum up to a given index (inclusive) in O(log n) time.
|
|
147
|
+
* @description 指定されたインデックスまでの累積和を O(log n) で計算。
|
|
148
|
+
* @param {number} index - The 0-based index to prefixSum up to.
|
|
149
|
+
* @param {object} [options] - Optional settings for materializing values.
|
|
150
|
+
* @param {object} [options.materializeOption] - Options to control materialization.
|
|
151
|
+
* @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
|
|
152
|
+
* @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
|
|
153
|
+
* @param {number} options.materializeOption.ranges.from - The starting index of the range.
|
|
154
|
+
* @param {number} options.materializeOption.ranges.to - The ending index of the range.
|
|
155
|
+
* @returns {{ cumulative: number; total: number | undefined; currentValue: number; safeIndex: number }} The cumulative sum of values from index 0 to the given index, the total sum, and the value at the given index.
|
|
156
|
+
*/
|
|
157
|
+
prefixSum(index: number, options?: {
|
|
158
|
+
materializeOption?: {
|
|
159
|
+
materialize: boolean;
|
|
160
|
+
ranges?: {
|
|
161
|
+
from: number;
|
|
162
|
+
to: number;
|
|
163
|
+
}[];
|
|
164
|
+
};
|
|
165
|
+
}): {
|
|
166
|
+
cumulative: number;
|
|
167
|
+
total: number | undefined;
|
|
168
|
+
currentValue: number;
|
|
169
|
+
safeIndex: number;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* @method get
|
|
173
|
+
* @description Gets the value at a specific index.
|
|
174
|
+
* @description 特定のインデックスの値を取得。
|
|
175
|
+
* @param {number} index - The 0-based index to get.
|
|
176
|
+
* @param {object} [options] - Optional settings for materializing values.
|
|
177
|
+
* @param {object} [options.materializeOption] - Options to control materialization.
|
|
178
|
+
* @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
|
|
179
|
+
* @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
|
|
180
|
+
* @param {number} options.materializeOption.ranges.from - The starting index of the range.
|
|
181
|
+
* @param {number} options.materializeOption.ranges.to - The ending index of the range.
|
|
182
|
+
* @returns {number} The value at the given index.
|
|
183
|
+
*/
|
|
184
|
+
get(index: number, options?: {
|
|
185
|
+
materializeOption?: {
|
|
186
|
+
materialize: boolean;
|
|
187
|
+
ranges?: {
|
|
188
|
+
from: number;
|
|
189
|
+
to: number;
|
|
190
|
+
}[];
|
|
191
|
+
};
|
|
192
|
+
}): number;
|
|
193
|
+
/**
|
|
194
|
+
* @method getTotal
|
|
195
|
+
* @description Gets the total sum of all values in the tree.
|
|
196
|
+
* @description ツリー内のすべての値の合計を取得。
|
|
197
|
+
* @param {object} [options] - Optional settings for materializing values.
|
|
198
|
+
* @param {object} [options.materializeOption] - Options to control materialization.
|
|
199
|
+
* @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
|
|
200
|
+
* @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
|
|
201
|
+
* @param {number} options.materializeOption.ranges.from - The starting index of the range.
|
|
202
|
+
* @param {number} options.materializeOption.ranges.to - The ending index of the range.
|
|
203
|
+
* @returns {number} The total sum of all values.
|
|
204
|
+
*/
|
|
205
|
+
getTotal(options?: {
|
|
206
|
+
materializeOption?: {
|
|
207
|
+
materialize: boolean;
|
|
208
|
+
ranges?: {
|
|
209
|
+
from: number;
|
|
210
|
+
to: number;
|
|
211
|
+
}[];
|
|
212
|
+
};
|
|
213
|
+
}): number;
|
|
214
|
+
/**
|
|
215
|
+
* @method rebuildTree
|
|
216
|
+
* @description Rebuilds the Fenwick Tree from the existing `baseValue` and `deltas`. This corrects any discrepancies in the tree's internal state, such as those caused by floating-point errors, by recalculating the tree structure and the total sum from the source `deltas`. This method does not re-materialize values from `valueFn`.
|
|
217
|
+
* @description 既存の `baseValue` と `deltas` から Fenwick Tree を再構築します。これにより、`deltas` からツリー構造と合計値を再計算することで、浮動小数点誤差などによって生じた内部状態の不一致を修正します。このメソッドは `valueFn` から値を再具現化しません。
|
|
218
|
+
* @param {object} [options] - Optional settings for rebuilding.
|
|
219
|
+
* @param {boolean} [options.materialize=false] - If true and `valueFn` is provided, re-materializes all values, recalculating `deltas` and `baseValue`.
|
|
220
|
+
*/
|
|
221
|
+
rebuildTree(options?: {
|
|
222
|
+
materialize?: boolean;
|
|
223
|
+
}): void;
|
|
224
|
+
/**
|
|
225
|
+
* @method calculateAccumulatedError
|
|
226
|
+
* @description Compares the cached total sum with a theoretical total calculated directly from the source values (`deltas` and `baseValue`, or `valueFn`). This helps detect any discrepancy in the tree's cached state, which might be caused by floating-point errors or other inconsistencies.
|
|
227
|
+
* @description キャッシュされている合計値と、元の値 (`deltas` と `baseValue`、または `valueFn`) から直接計算した理論上の合計値とを比較します。これにより、浮動小数点数の累積誤差やその他の不整合によって生じる可能性のある、ツリーのキャッシュ状態の不一致を検出できます。
|
|
228
|
+
* @returns {number} The difference between the cached total and the theoretical total.
|
|
229
|
+
*/
|
|
230
|
+
calculateAccumulatedError(): number;
|
|
231
|
+
/**
|
|
232
|
+
* @method changeSize
|
|
233
|
+
* @description Changes the size of the Fenwick Tree.
|
|
234
|
+
* @description Fenwick Tree のサイズを変更する。
|
|
235
|
+
* @param {number} newSize - The new size of the tree.
|
|
236
|
+
*/
|
|
237
|
+
changeSize(newSize: number): void;
|
|
238
|
+
/**
|
|
239
|
+
* @method getSize
|
|
240
|
+
* @description Gets the size of the tree.
|
|
241
|
+
* @description ツリーのサイズを取得。
|
|
242
|
+
* @returns {number} The total number of items.
|
|
243
|
+
*/
|
|
244
|
+
getSize(): number;
|
|
245
|
+
/**
|
|
246
|
+
* @method findIndexAtOrAfter
|
|
247
|
+
* @description Finds the first index where the cumulative sum is greater than or equal to a target value.
|
|
248
|
+
* @description 累積和がターゲット値以上になる最初のインデックスを検索。
|
|
249
|
+
* @param {number} target - The target cumulative sum.
|
|
250
|
+
* @param {object} [options] - Optional settings for materializing values.
|
|
251
|
+
* @param {object} [options.materializeOption] - Options to control materialization.
|
|
252
|
+
* @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
|
|
253
|
+
* @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
|
|
254
|
+
* @param {number} options.materializeOption.ranges.from - The starting index of the range.
|
|
255
|
+
* @param {number} options.materializeOption.ranges.to - The ending index of the range.
|
|
256
|
+
* @returns {{ index: number, total: number | undefined, cumulative: number | undefined, currentValue: number | undefined, safeIndex: number | undefined }} The 0-based index and the total sum, or -1 if not found.
|
|
257
|
+
*/
|
|
258
|
+
findIndexAtOrAfter(target: number, options?: {
|
|
259
|
+
materializeOption?: {
|
|
260
|
+
materialize: boolean;
|
|
261
|
+
ranges?: {
|
|
262
|
+
from: number;
|
|
263
|
+
to: number;
|
|
264
|
+
}[];
|
|
265
|
+
};
|
|
266
|
+
}): {
|
|
267
|
+
index: number;
|
|
268
|
+
total: number | undefined;
|
|
269
|
+
cumulative: number | undefined;
|
|
270
|
+
currentValue: number | undefined;
|
|
271
|
+
safeIndex: number | undefined;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* @method findIndexAtOrBefore
|
|
275
|
+
* @description Finds the last index where the cumulative sum is less than or equal to a target value.
|
|
276
|
+
* @description 累積和がターゲット値以下になる最後のインデックスを検索。
|
|
277
|
+
* @param {number} target - The target cumulative sum.
|
|
278
|
+
* @param {object} [options] - Optional settings for materializing values.
|
|
279
|
+
* @param {object} [options.materializeOption] - Options to control materialization.
|
|
280
|
+
* @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
|
|
281
|
+
* @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
|
|
282
|
+
* @param {number} options.materializeOption.ranges.from - The starting index of the range.
|
|
283
|
+
* @param {number} options.materializeOption.ranges.to - The ending index of the range.
|
|
284
|
+
* @returns {{ index: number, total: number | undefined, cumulative: number | undefined, currentValue: number | undefined, safeIndex: number | undefined }} The 0-based index and the total sum, or -1 if not found.
|
|
285
|
+
*/
|
|
286
|
+
findIndexAtOrBefore(target: number, options?: {
|
|
287
|
+
materializeOption?: {
|
|
288
|
+
materialize: boolean;
|
|
289
|
+
ranges?: {
|
|
290
|
+
from: number;
|
|
291
|
+
to: number;
|
|
292
|
+
}[];
|
|
293
|
+
};
|
|
294
|
+
}): {
|
|
295
|
+
index: number;
|
|
296
|
+
total: number | undefined;
|
|
297
|
+
cumulative: number | undefined;
|
|
298
|
+
currentValue: number | undefined;
|
|
299
|
+
safeIndex: number | undefined;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @hook useFenwickMapTree
|
|
304
|
+
* @description A React hook that creates and manages a `FenwickMapTree` instance.
|
|
305
|
+
* The tree instance is stable across re-renders. A new tree instance is created
|
|
306
|
+
* if `size` or `valueOrFn` changes.
|
|
307
|
+
* @description `FenwickMapTree` インスタンスを作成・管理する React フック。
|
|
308
|
+
* ツリーインスタンスは再レンダリングされても同一性を維持する。`size` または `valueOrFn` が
|
|
309
|
+
* 変更された場合に新しいインスタンスが作成される。
|
|
310
|
+
* @param {number} size - The total number of items.
|
|
311
|
+
* @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
|
|
312
|
+
* @param {number | ((index: number) => number)} valueOrFn - 全要素の均一な値、または値を生成する関数。不要なツリーの再作成を防ぐため、この関数は `useCallback` でメモ化すること。
|
|
313
|
+
* @param {{ sampleRange?: { from: number; to: number } }} [options] - Optional settings for initialization. To prevent unnecessary re-creations of the tree, memoize this object with `useMemo`.
|
|
314
|
+
* @param {{ sampleRange?: { from: number; to: number } }} [options] - 初期化時のオプション設定。不要なツリーの再作成を防ぐため、このオブジェクトは `useMemo` でメモ化すること。
|
|
315
|
+
* @returns {FenwickMapTree} The FenwickMapTree instance.
|
|
316
|
+
* @returns {FenwickMapTree} FenwickMapTree インスタンス。
|
|
317
|
+
*/
|
|
318
|
+
export declare const useFenwickMapTree: (size: number, valueOrFn: number | ((index: number) => number), options?: {
|
|
319
|
+
sampleRange?: {
|
|
320
|
+
from: number;
|
|
321
|
+
to: number;
|
|
322
|
+
};
|
|
323
|
+
}) => FenwickMapTree;
|
|
324
|
+
//# sourceMappingURL=useFenwickMapTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFenwickMapTree.d.ts","sourceRoot":"","sources":["../../src/useFenwickMapTree.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AACH,qBAAa,cAAc;IACvB;;;;OAIG;IACH,OAAO,CAAC,IAAI,CAAsB;IAElC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAsB;IAEpC;;;;OAIG;IACH,OAAO,CAAC,IAAI,CAAS;IAErB;;;;OAIG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,CAA2B;IAC3C,OAAO,CAAC,KAAK,CAAC,CAAQ;IAEtB;;;;;;;OAOG;gBACS,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,M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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* A custom hook that provides a cache for storing the heights of items, backed by an LRU cache.
|
|
3
|
+
* This helps in optimizing virtual scrolling by avoiding re-computation of item heights.
|
|
4
|
+
* The key is the item's index (number), and the value is its height (number).
|
|
5
|
+
*
|
|
6
|
+
* LRU キャッシュを利用して、アイテムの高さを保存するためのキャッシュを提供するカスタムフック。
|
|
7
|
+
* これにより、アイテムの高さの再計算を回避し、仮想スクロールを最適化します。
|
|
8
|
+
* キーはアイテムのインデックス (number)、値はその高さ (number) です。
|
|
9
|
+
*/
|
|
10
|
+
export declare const useHeightCache: () => {
|
|
11
|
+
get: (key: number) => number | undefined;
|
|
12
|
+
set: (key: number, value: number) => void;
|
|
13
|
+
has: (key: number) => boolean;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useHeightCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHeightCache.d.ts","sourceRoot":"","sources":["../../src/useHeightCache.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc;;;;;CAM1B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hook useLruCache
|
|
3
|
+
* @description A custom hook that provides a Least Recently Used (LRU) cache of a specified capacity.
|
|
4
|
+
* It returns an object with methods to interact with the cache (`get`, `set`, `has`, `clear`).
|
|
5
|
+
* @description 指定された容量の LRU (Least Recently Used) キャッシュを提供するカスタムフック。
|
|
6
|
+
* キャッシュを操作するためのメソッド (`get`, `set`, `has`, `clear`) を持つオブジェクトを返します。
|
|
7
|
+
* @param {number} capacity - The maximum capacity of the cache.
|
|
8
|
+
* @returns {{ get: (key: K) => V | undefined, set: (key: K, value: V) => void, has: (key: K) => boolean, clear: () => void }} An object with methods to interact with the cache.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useLruCache<K, V>(capacity: number): {
|
|
11
|
+
get: (key: K) => V | undefined;
|
|
12
|
+
set: (key: K, value: V) => void;
|
|
13
|
+
has: (key: K) => boolean;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useLruCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLruCache.d.ts","sourceRoot":"","sources":["../../src/useLruCache.ts"],"names":[],"mappings":"AA2HA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM;eAyBhB,CAAC,KAAG,CAAC,GAAG,SAAS;eAsBrC,CAAC,SAAS,CAAC;eAyCS,CAAC,KAAG,OAAO;;EAuB5C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a value between a minimum and maximum value.
|
|
3
|
+
*
|
|
4
|
+
* 指定された値が最小値と最大値の範囲内に収まるように調整。
|
|
5
|
+
*
|
|
6
|
+
* @param value The value to clamp. / クランプする値。
|
|
7
|
+
* @param min The minimum value. / 最小値。
|
|
8
|
+
* @param max The maximum value. / 最大値。
|
|
9
|
+
* @returns The clamped value. / クランプされた値。
|
|
10
|
+
*/
|
|
11
|
+
export declare const minmax: (value: number, min: number, max: number) => number;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAEhE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.config.d.ts","sourceRoot":"","sources":["../vite.config.ts"],"names":[],"mappings":";AAIA,wBA+BG"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/virtualscroll",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High-performance virtual scrolling component for React with variable item heights",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.js",
|
|
12
|
-
"
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.js"
|
|
13
15
|
}
|
|
14
16
|
},
|
|
15
17
|
"files": [
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
"LICENSE"
|
|
19
21
|
],
|
|
20
22
|
"scripts": {
|
|
21
|
-
"build": "vite build && vite build --config vite.config.cli.ts",
|
|
23
|
+
"build": "rimraf dist && vite build && vite build --config vite.config.cli.ts",
|
|
22
24
|
"dev": "vite build --watch",
|
|
23
25
|
"demo:dev": "cd demo && pnpm run dev",
|
|
24
26
|
"demo:build": "cd demo && pnpm run build",
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
"format": "biome format --write src",
|
|
33
35
|
"format:check": "biome format src",
|
|
34
36
|
"clean": "rimraf dist",
|
|
35
|
-
"prepublishOnly": "npm run clean && npm run typecheck && npm run build",
|
|
37
|
+
"prepublishOnly": "npm run clean && npm run typecheck && npm run test && npm run build",
|
|
36
38
|
"publish:patch": "npm version patch && npm publish",
|
|
37
39
|
"publish:minor": "npm version minor && npm publish",
|
|
38
40
|
"publish:major": "npm version major && npm publish"
|