@aiquants/virtualscroll 3.8.2 → 3.9.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.
@@ -1,4 +1,5 @@
1
1
  import { default as React, ReactNode } from 'react';
2
+ import { DevicePixelSnapEdge } from './devicePixelGrid.ts';
2
3
  import { VirtualScrollLabelOverrides, VirtualScrollLocale } from './labels.ts';
3
4
  import { ScrollPaneProps } from './ScrollPane.tsx';
4
5
  import { useFenwickMapTree } from './useFenwickMapTree.ts';
@@ -21,6 +22,42 @@ export type VirtualScrollRange = {
21
22
  /** Total height of the scroll content / スクロールコンテンツの総高さ */
22
23
  totalHeight: number;
23
24
  };
25
+ /**
26
+ * Why VirtualScroll moved its scroll position on its own (see `VirtualScrollProps["onScrollAdjust"]`).
27
+ *
28
+ * - `"item-resize"`: `updateItemSize` changed the height of a row above the first visible row, and the position moved by
29
+ * the same delta, so the visible rows stay where they were.
30
+ * - `"reconciliation"`: a render found that `getItemHeight` returns a new height for a rendered row above the first
31
+ * visible row; the height reconciliation that follows the render (a microtask) moved the position by the same delta.
32
+ * - `"drift"`: after a size change (content, viewport, item count or insets) the pending alignment of the last
33
+ * `scrollToIndex` (or of `initialScrollAnchor`) was pinned again, in an effect after the commit.
34
+ * - `"re-issue"`: a compensation that the pane clamped against the previous content size was issued again once the new
35
+ * content size had committed, in an effect after the commit.
36
+ *
37
+ * VirtualScroll が自分でスクロール位置を動かした理由 (`VirtualScrollProps["onScrollAdjust"]` を参照)。
38
+ *
39
+ * - `"item-resize"`: `updateItemSize` が先頭の可視行より上の行の高さを変え、位置を同じ差だけ動かした (見えている行はその場に
40
+ * 留まる)。
41
+ * - `"reconciliation"`: 描画が、描いた行のうち先頭の可視行より上の行について `getItemHeight` の新しい高さを見つけ、描画の後の
42
+ * 高さの照合 (マイクロタスク) が位置を同じ差だけ動かした。
43
+ * - `"drift"`: 寸法の変化 (中身・ビューポート・件数・インセット) の後、最後の `scrollToIndex` (または `initialScrollAnchor`)
44
+ * の保留中の揃えを、確定の後の effect で留め直した。
45
+ * - `"re-issue"`: ペインが前の中身の寸法でクランプした補正を、新しい中身の寸法が確定した後の effect でもう一度発行した。
46
+ */
47
+ export type VirtualScrollAdjustmentCause = "item-resize" | "reconciliation" | "drift" | "re-issue";
48
+ /**
49
+ * One position change VirtualScroll made on its own (the argument of `VirtualScrollProps["onScrollAdjust"]`).
50
+ *
51
+ * VirtualScroll が自分で行った 1 回の位置の変化 (`VirtualScrollProps["onScrollAdjust"]` の引数)。
52
+ */
53
+ export type VirtualScrollAdjustment = {
54
+ /** The LOGICAL scroll position after the change — what `getScrollPosition()` returns at that moment / 変化の後の論理スクロール位置 (その時点の `getScrollPosition()` の値) */
55
+ readonly position: number;
56
+ /** The applied change in LOGICAL px: `position` minus the position before the change; never 0 / 適用した変化 (論理 px)。`position` から変化の前の位置を引いた値で、0 にはならない */
57
+ readonly delta: number;
58
+ /** Why the position moved / 位置が動いた理由 */
59
+ readonly cause: VirtualScrollAdjustmentCause;
60
+ };
24
61
  /**
25
62
  * Imperative handle of VirtualScroll. Every position it accepts or returns is in the
26
63
  * LOGICAL coordinate space (content px, insets excluded) — the same space as onScroll /
@@ -94,7 +131,15 @@ export type VirtualScrollHandle = {
94
131
  getContentSize: () => number;
95
132
  /** Viewport size / ビューポートの高さ。未接続時は -1 */
96
133
  getViewportSize: () => number;
97
- /** Scrolls to a specific item index / 指定したアイテムインデックスへスクロール */
134
+ /**
135
+ * Scrolls to a specific item index, landing exactly on the aligned position (clamped to the content). A `"top"`
136
+ * (default) or `"bottom"` alignment is remembered at that position, so the device-pixel snap of the items wrapper
137
+ * keeps the aligned edge there (see the README's device-pixel snapping section).
138
+ *
139
+ * 指定したアイテムインデックスへスクロールする処理。揃えた位置 (中身の範囲へクランプ) へ厳密に着地する。`"top"` (既定) と
140
+ * `"bottom"` の揃えはその位置で覚えるので、そこでは行ラッパーの装置の画素への揃えが揃えた端を守る (README の装置の画素への
141
+ * 揃えの節を参照)。
142
+ */
98
143
  scrollToIndex: (index: number, options?: {
99
144
  align?: "top" | "bottom" | "center";
100
145
  offset?: number;
@@ -123,10 +168,15 @@ export type VirtualScrollHandle = {
123
168
  * `getItemHeight(index)` must return the same `size`; `getItemHeight` is the source of truth,
124
169
  * so if it keeps returning the old value, rows inside the current rendering window (including
125
170
  * overscan) are reverted to the `getItemHeight` value by height reconciliation on the next render.
171
+ * When the item lies above the first visible row, the scroll position moves by the size change
172
+ * before this returns (layout-shift compensation), and `onScrollAdjust` reports it with the cause
173
+ * `"item-resize"`.
126
174
  *
127
175
  * 特定のアイテムのサイズを手動で更新。契約: 呼び出し後は `getItemHeight(index)` も同じ値を
128
176
  * 返すこと。`getItemHeight` が正であるため、旧値を返し続けると描画ウィンドウ (オーバースキャン
129
- * 含む) 内の行は次レンダーの高さ照合で `getItemHeight` の値へ巻き戻る。
177
+ * 含む) 内の行は次レンダーの高さ照合で `getItemHeight` の値へ巻き戻る。アイテムが先頭の可視行より
178
+ * 上にあるときは、戻る前にスクロール位置をサイズの変化だけ動かし (レイアウトシフトの補正)、
179
+ * `onScrollAdjust` が理由 `"item-resize"` で知らせる。
130
180
  */
131
181
  updateItemSize: (index: number, size: number) => void;
132
182
  };
@@ -329,6 +379,33 @@ export type VirtualScrollProps<T> = {
329
379
  testId?: string;
330
380
  onScroll?: (scrollPosition: number, totalHeight: number) => void;
331
381
  onRangeChange?: (range: VirtualScrollRange) => void;
382
+ /**
383
+ * Called synchronously, without throttling, each time VirtualScroll moves its scroll position on its own: a
384
+ * layout-shift compensation (`"item-resize"`, `"reconciliation"`), the re-pinning of a pending alignment
385
+ * (`"drift"`) or the second stage of a clamped compensation (`"re-issue"`) — see `VirtualScrollAdjustmentCause`.
386
+ * It runs after the change is complete, so `getScrollPosition()` and `getScrollAnchor()` read inside it already
387
+ * see the adjusted position and row heights. It never runs for scrolls that the user or the host start (wheel,
388
+ * drag, scrollbar, inertia, keyboard row navigation, `scrollTo` / `scrollBy` / `scrollToIndex` / `applyWheel`),
389
+ * nor for a change that leaves `getScrollPosition()` where it was.
390
+ *
391
+ * `onScroll` and `onRangeChange` report every position, but throttled and one frame later. A host that keeps its
392
+ * own scroll anchor by item identity (re-finding the first visible item by key after a list change) records that
393
+ * anchor from the range report and from its own scrolls; it must also record it from here, or a list change
394
+ * committed before the next range report restores a position VirtualScroll has already moved.
395
+ *
396
+ * VirtualScroll が自分でスクロール位置を動かすたびに、間引かず同期で呼ぶ関数。レイアウトシフトの補正
397
+ * (`"item-resize"`・`"reconciliation"`)、保留中の揃えの留め直し (`"drift"`)、クランプされた補正の二段目
398
+ * (`"re-issue"`) が対象 (`VirtualScrollAdjustmentCause` を参照)。変化を終えてから呼ぶので、中で読む
399
+ * `getScrollPosition()` と `getScrollAnchor()` は動かした後の位置と行の高さを返す。利用者やホストが始めた
400
+ * スクロール (ホイール・ドラッグ・スクロールバー・慣性・行のキーボード移動・`scrollTo` / `scrollBy` /
401
+ * `scrollToIndex` / `applyWheel`) と、`getScrollPosition()` を変えない変化では呼ばない。
402
+ *
403
+ * `onScroll` と `onRangeChange` はどの位置も知らせるが、間引いたうえで 1 フレーム遅れる。項目の同一性で自前の
404
+ * スクロールの錨を持つホスト (一覧の変化の後に先頭の可視項目をキーで探し直す) は、範囲の知らせと自分のスクロールで
405
+ * 錨を記録するが、ここでも記録すること。さもないと、次の範囲の知らせより前に確定した一覧の変化が、VirtualScroll が
406
+ * 既に動かした位置を巻き戻す。
407
+ */
408
+ onScrollAdjust?: (adjustment: VirtualScrollAdjustment) => void;
332
409
  /**
333
410
  * Opt-in `aria-live` region announcing the visible range to assistive technology (default:
334
411
  * none rendered). Virtualization removes off-screen rows from the DOM, so a screen-reader
@@ -534,26 +611,52 @@ export declare const MAX_RENDERED_ITEMS = 2000;
534
611
  */
535
612
  export declare const ANCHOR_REBASE_DISTANCE = 1048576;
536
613
  /**
537
- * Snaps a CSS-px offset to the device-pixel grid of a window: the nearest offset whose device-px value is a
538
- * whole number, `Math.round(cssPx × ratio) / ratio` (an exact half rounds toward +∞, as `Math.round` does). The items-wrapper translate goes through it: a composited layer moved by a fraction of a
539
- * device pixel is resampled as a whole (2-px outlines, gaps and rings smear across neighbouring device rows and
540
- * text blurs), while fractional layout positions inside the layer are painted on whole pixels already.
541
- * Idempotent: a snapped value snaps to itself. A non-finite `cssPx` propagates (`NaN` in, `NaN` out).
542
- * Module-level export (NOT in the package barrel).
614
+ * The viewport edge VirtualScroll aligned a row to, and the pane position at which that alignment holds. Module-level
615
+ * export (NOT in the package barrel), the parameter type of `resolveItemsWrapperSnapEdge`.
616
+ *
617
+ * VirtualScroll が行を揃えた表示域の端と、その揃えが成り立つペイン位置。モジュールレベル export (バレル非公開)。
618
+ * `resolveItemsWrapperSnapEdge` の引数の型。
619
+ */
620
+ export type AlignedEdge = {
621
+ /** `"start"` for a top alignment, `"end"` for a bottom alignment / 上端揃えは `"start"`、下端揃えは `"end"` */
622
+ readonly edge: "start" | "end";
623
+ /** Pane position (PANE coordinates) where the aligned row sits at that edge / 揃えた行がその端にあるペイン位置 (ペイン座標) */
624
+ readonly panePosition: number;
625
+ };
626
+ /**
627
+ * Chooses the edge the items-wrapper translate keeps when it is snapped to the device-pixel grid
628
+ * (`snapToDevicePixelGrid`), so that aligned content never loses part of its edge gutter to the snap:
629
+ *
630
+ * - `"start"` while the pane rests at position 0: the first row and the top inset keep their place.
631
+ * - `"end"` while the pane rests at its maximum position: the last row and the bottom inset keep theirs.
632
+ * - The edge of the remembered alignment while the pane is at the position where it holds: a row revealed by
633
+ * `scrollToIndex` with `align: "top"` (or the default) or `align: "bottom"`, kept through layout-shift compensation and
634
+ * drift correction.
635
+ * - `"none"` (nearest) everywhere else.
636
+ *
637
+ * Position 0 wins over the maximum position (a list that does not scroll stays top-aligned), and both win over a
638
+ * remembered alignment, since a clamp means that alignment was not reached. A position within `EDGE_POSITION_TOLERANCE`
639
+ * of one of these counts as that position. Module-level export (NOT in the package barrel).
640
+ *
641
+ * 行ラッパーの平行移動を装置の画素の格子へ揃えるとき (`snapToDevicePixelGrid`) に守る端を選ぶ処理。揃えた中身の端の余白を
642
+ * 丸めが削らないようにする。
643
+ *
644
+ * - ペインが位置 0 に止まっている間は `"start"`。最初の行と上のインセットがその場に留まる。
645
+ * - ペインが最大位置に止まっている間は `"end"`。最後の行と下のインセットがその場に留まる。
646
+ * - 覚えた揃えが成り立つ位置にペインがある間は、その揃えの端。`scrollToIndex` が `align: "top"` (既定を含む) か
647
+ * `align: "bottom"` で見せた行で、レイアウトシフトの補正とドリフト補正を通して保つ。
648
+ * - それ以外は `"none"` (最も近い格子点)。
543
649
  *
544
- * CSS px のオフセットをウィンドウの装置の画素の格子へ揃える処理。装置 px で整数になる最も近いオフセット
545
- * `Math.round(cssPx × ratio) / ratio` (ちょうど半分は `Math.round` どおり +∞ 側)。
546
- * 行ラッパーの平行移動はここを通す — 合成層を装置の画素の端数だけ動かすとブラウザは層全体を再標本化し
547
- * (2px の輪郭・隙間・輪が隣の装置の行へ滲み、文字もぼける)、層の中の端数のレイアウト位置は描画が既に画素へ
548
- * 揃えるため。冪等 (揃えた値はそのまま)。有限でない `cssPx` はそのまま伝わる (`NaN` は `NaN`)。
549
- * モジュールレベル export (バレル非公開)。
650
+ * 位置 0 は最大位置に勝ち (スクロールしない一覧は上端揃えのまま)、どちらも覚えた揃えに勝つ (クランプは揃えが届かなかった
651
+ * ことを意味する)。これらの位置から `EDGE_POSITION_TOLERANCE` 以内の位置はその位置とみなす。モジュールレベル export
652
+ * (バレル非公開)。
550
653
  *
551
- * @param cssPx - Offset in CSS px; negative and fractional values included / CSS px のオフセット (負・小数を含む)
552
- * @param ratio - Device px per CSS px of the window that paints the offset (its `devicePixelRatio`); a finite number > 0 / オフセットを描くウィンドウの CSS px あたりの装置 px (そのウィンドウの `devicePixelRatio`。0 より大きい有限数)
553
- * @returns The snapped offset in CSS px / 揃えたオフセット (CSS px)
554
- * @throws {RangeError} When `ratio` is not a finite number greater than 0 / `ratio` が 0 より大きい有限数でないとき
654
+ * @param panePosition - The pane position the wrapper is rendered at (PANE coordinates) / ラッパーを描くペイン位置 (ペイン座標)
655
+ * @param maxPanePosition - The pane's maximum position: content plus insets minus the viewport / ペインの最大位置 (中身とインセットの和からビューポートを引いた値)
656
+ * @param alignedEdge - The remembered alignment, or `null` / 覚えた揃え (無ければ `null`)
657
+ * @returns The edge the snapped translate keeps / 揃えた平行移動が守る端
555
658
  */
556
- export declare const snapToDevicePixelGrid: (cssPx: number, ratio: number) => number;
659
+ export declare const resolveItemsWrapperSnapEdge: (panePosition: number, maxPanePosition: number, alignedEdge: AlignedEdge | null) => DevicePixelSnapEdge;
557
660
  /**
558
661
  * Retrieves a high-resolution timestamp when available.
559
662
  *
@@ -1 +1 @@
1
- {"version":3,"file":"VirtualScroll.d.ts","sourceRoot":"","sources":["../src/VirtualScroll.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,KAAK,SAAS,EAAiH,MAAM,OAAO,CAAA;AACxK,OAAO,EAA8B,KAAK,2BAA2B,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEpH,OAAO,EAAmE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACxH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG1D;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B,6EAA6E;IAC7E,mBAAmB,EAAE,MAAM,CAAA;IAC3B,2EAA2E;IAC3E,iBAAiB,EAAE,MAAM,CAAA;IACzB,6FAA6F;IAC7F,iBAAiB,EAAE,MAAM,CAAA;IACzB,4FAA4F;IAC5F,eAAe,EAAE,MAAM,CAAA;IACvB,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAA;IACtB,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B;;;;;;;;;;;;;;;;;;OAkBG;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M,CAAA;IAC1B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA;CACjD,CAAA;AAuBD;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAA;AAEzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,UAAY,CAAA;AAe/C;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB,oGAAoG;IACpG,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAAA;IAC9B,0GAA0G;IAC1G,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAChC,CAAA;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,2BAA2B,GAAI,cAAc,MAAM,EAAE,iBAAiB,MAAM,EAAE,aAAa,WAAW,GAAG,IAAI,KAAG,mBAW5H,CAAA;AA8PD;;;;GAIG;AACH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,gBAAgB,MAAM,EAAE,cAAc,MAAM,EAAE,eAAe,MAAM,EAAE,UAAU,MAAM,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,aAAa,UAAU,CAAC,OAAO,iBAAiB,CAAC,EAAE,aAAa,MAAM;;;;;CAgI7O,CAAA;AA43DD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,EAAqC,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;CAAE,KAAK,KAAK,CAAC,YAAY,CAAA"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The edge a snapped offset keeps when the exact offset falls between two grid points, for an offset that translates
3
+ * content along an axis (a positive offset moves the content toward the end):
4
+ *
5
+ * - `"none"`: the nearest grid point, `Math.round` (an exact half rounds toward +∞).
6
+ * - `"end"`: the grid point at or before the exact offset, `Math.floor`. The content never moves toward the viewport end,
7
+ * so content aligned to the end (the last row at the maximum position, a row revealed with `align: "bottom"`) never
8
+ * crosses it.
9
+ * - `"start"`: the grid point at or after the exact offset, `Math.ceil`. The content never moves toward the viewport start,
10
+ * so content aligned to the start (the first row at position 0, a row revealed with `align: "top"`) never crosses it.
11
+ *
12
+ * 正確なオフセットが 2 つの格子点の間にあるとき、揃えたオフセットがどちらの端を守るか (中身を軸に沿って動かすオフセット。
13
+ * 正のオフセットは中身を終端側へ動かす)。
14
+ *
15
+ * - `"none"`: 最も近い格子点 (`Math.round`。ちょうど半分は +∞ 側)。
16
+ * - `"end"`: 正確なオフセット以下の格子点 (`Math.floor`)。中身は表示域の終端側へ動かないので、終端に揃えた中身
17
+ * (最大位置の最後の行・`align: "bottom"` で見せた行) は終端を越えない。
18
+ * - `"start"`: 正確なオフセット以上の格子点 (`Math.ceil`)。中身は表示域の始端側へ動かないので、始端に揃えた中身
19
+ * (位置 0 の最初の行・`align: "top"` で見せた行) は始端を越えない。
20
+ */
21
+ export type DevicePixelSnapEdge = "none" | "start" | "end";
22
+ /**
23
+ * Snaps a CSS-px offset to the device-pixel grid of a window toward `edge`: an offset whose device-px value is a whole
24
+ * number, at most one device pixel from the exact one (`"none"`: at most half a device pixel). A product within
25
+ * `ON_GRID_TOLERANCE_DEVICE_PX` of a whole number is on the grid already, whatever the edge, so the snap is idempotent
26
+ * for every edge and floating-point residue never moves the content by a whole device pixel. A non-finite `cssPx`
27
+ * propagates (`NaN` in, `NaN` out).
28
+ *
29
+ * CSS px のオフセットをウィンドウの装置の画素の格子へ `edge` の側で揃える処理。装置 px の値が整数になるオフセットで、
30
+ * 正確な値から装置の画素 1 つ未満 (`"none"` は半分以内)。整数から `ON_GRID_TOLERANCE_DEVICE_PX` 以内の積はどの端でも
31
+ * 既に格子上とみなすので、どの端でも冪等で、浮動小数点の残差が中身を装置の画素 1 つ分動かすことはない。有限でない
32
+ * `cssPx` はそのまま伝わる (`NaN` は `NaN`)。
33
+ *
34
+ * @param cssPx - Offset in CSS px; negative and fractional values included / CSS px のオフセット (負・小数を含む)
35
+ * @param ratio - Device px per CSS px of the window that paints the offset (its `devicePixelRatio`); a finite number > 0 / オフセットを描くウィンドウの CSS px あたりの装置 px (そのウィンドウの `devicePixelRatio`。0 より大きい有限数)
36
+ * @param edge - The edge the snapped offset keeps (see `DevicePixelSnapEdge`) / 揃えたオフセットが守る端 (`DevicePixelSnapEdge` を参照)
37
+ * @returns The snapped offset in CSS px / 揃えたオフセット (CSS px)
38
+ * @throws {RangeError} When `ratio` is not a finite number greater than 0 / `ratio` が 0 より大きい有限数でないとき
39
+ */
40
+ export declare const snapToDevicePixelGrid: (cssPx: number, ratio: number, edge: DevicePixelSnapEdge) => number;
41
+ /**
42
+ * The painting window's device-pixel ratio and the ref callback that confirms that window (see `usePaintingDevicePixelRatio`).
43
+ *
44
+ * 描くウィンドウの装置の画素比と、そのウィンドウを確かめる ref コールバック (`usePaintingDevicePixelRatio` を参照)。
45
+ */
46
+ export type PaintingDevicePixelRatio = {
47
+ /** The ratio, or `null` while no window is known (server rendering and hydration) / 比 (ウィンドウが分からない間 = サーバー描画とハイドレーションは `null`) */
48
+ readonly ratio: number | null;
49
+ /** Ref callback for the translated element / 平行移動する要素の ref コールバック */
50
+ readonly attach: (element: Element | null) => void;
51
+ };
52
+ /**
53
+ * Reads, during render, the device-pixel ratio of the window that paints an element, for snapping the element's translate
54
+ * (`snapToDevicePixelGrid`). Rule: the translate that reaches the screen is always snapped with the ratio of the window
55
+ * that paints the element. Render reads the ratio through `useSyncExternalStore` from the expected painting window — the
56
+ * realm's window (`readRealmWindow`) until the element has attached, since render cannot see the target document. The
57
+ * attach (`attach`, the element's ref callback) confirms it with the element's own window (`windowOf`): when they agree
58
+ * (an element rendered into its own window's document), the first commit is already snapped and nothing is scheduled in
59
+ * the commit phase; when they differ (an iframe or an opened window), the attach switches to that window; the update is
60
+ * scheduled in the commit phase, so React re-renders synchronously before the browser paints. Ratio changes re-render
61
+ * through the store subscription (`subscribeToDevicePixelRatio`), outside the commit phase. The server snapshot is
62
+ * `null`: server HTML and hydration carry the exact offset, replaced by the snapped one right after hydration.
63
+ *
64
+ * 要素の平行移動を揃えるため (`snapToDevicePixelGrid`)、要素を描くウィンドウの装置の画素比を描画の中で読むフック。規則は
65
+ * 「画面へ届く平行移動は、常に要素を描くウィンドウの比で揃っている」。描画は `useSyncExternalStore` で、描くと見込む
66
+ * ウィンドウから比を読む — 描画からは挿入先の文書が見えないので、要素が取り付くまではレルムのウィンドウ
67
+ * (`readRealmWindow`)。取り付け (`attach`。要素の ref コールバック) が要素自身のウィンドウ (`windowOf`) と突き合わせて
68
+ * 確かめ、一致すれば (自分のウィンドウの文書に描いた要素) 最初の確定から揃っていて確定の段では何も予約しない。違えば
69
+ * (iframe・開いたウィンドウ) 取り付けがそのウィンドウへ切り替え、この更新は確定の段で予約されるので、React はブラウザの
70
+ * paint の前に同期で描き直す。比の変化はストアの購読 (`subscribeToDevicePixelRatio`) で確定の段の外から描き直す。
71
+ * サーバーのスナップショットは `null` で、サーバーの HTML とハイドレーションは厳密なオフセットを持ち、ハイドレーションの
72
+ * 直後に揃えた値へ置き換わる。
73
+ *
74
+ * @param part - The element's name for the error, with the owning component (e.g. `"[VirtualScroll] the items wrapper"`) / 誤りに使う要素の名前 (持ち主の部品を含む)
75
+ * @returns The ratio and the ref callback / 比と ref コールバック
76
+ * @throws {Error} When the element attaches to a document without a window (see `windowOf`) / ウィンドウを持たない文書へ取り付いたとき (`windowOf` を参照)
77
+ */
78
+ export declare const usePaintingDevicePixelRatio: (part: string) => PaintingDevicePixelRatio;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The edge a snapped offset keeps when the exact offset falls between two grid points, for an offset that translates
3
+ * content along an axis (a positive offset moves the content toward the end):
4
+ *
5
+ * - `"none"`: the nearest grid point, `Math.round` (an exact half rounds toward +∞).
6
+ * - `"end"`: the grid point at or before the exact offset, `Math.floor`. The content never moves toward the viewport end,
7
+ * so content aligned to the end (the last row at the maximum position, a row revealed with `align: "bottom"`) never
8
+ * crosses it.
9
+ * - `"start"`: the grid point at or after the exact offset, `Math.ceil`. The content never moves toward the viewport start,
10
+ * so content aligned to the start (the first row at position 0, a row revealed with `align: "top"`) never crosses it.
11
+ *
12
+ * 正確なオフセットが 2 つの格子点の間にあるとき、揃えたオフセットがどちらの端を守るか (中身を軸に沿って動かすオフセット。
13
+ * 正のオフセットは中身を終端側へ動かす)。
14
+ *
15
+ * - `"none"`: 最も近い格子点 (`Math.round`。ちょうど半分は +∞ 側)。
16
+ * - `"end"`: 正確なオフセット以下の格子点 (`Math.floor`)。中身は表示域の終端側へ動かないので、終端に揃えた中身
17
+ * (最大位置の最後の行・`align: "bottom"` で見せた行) は終端を越えない。
18
+ * - `"start"`: 正確なオフセット以上の格子点 (`Math.ceil`)。中身は表示域の始端側へ動かないので、始端に揃えた中身
19
+ * (位置 0 の最初の行・`align: "top"` で見せた行) は始端を越えない。
20
+ */
21
+ export type DevicePixelSnapEdge = "none" | "start" | "end";
22
+ /**
23
+ * Snaps a CSS-px offset to the device-pixel grid of a window toward `edge`: an offset whose device-px value is a whole
24
+ * number, at most one device pixel from the exact one (`"none"`: at most half a device pixel). A product within
25
+ * `ON_GRID_TOLERANCE_DEVICE_PX` of a whole number is on the grid already, whatever the edge, so the snap is idempotent
26
+ * for every edge and floating-point residue never moves the content by a whole device pixel. A non-finite `cssPx`
27
+ * propagates (`NaN` in, `NaN` out).
28
+ *
29
+ * CSS px のオフセットをウィンドウの装置の画素の格子へ `edge` の側で揃える処理。装置 px の値が整数になるオフセットで、
30
+ * 正確な値から装置の画素 1 つ未満 (`"none"` は半分以内)。整数から `ON_GRID_TOLERANCE_DEVICE_PX` 以内の積はどの端でも
31
+ * 既に格子上とみなすので、どの端でも冪等で、浮動小数点の残差が中身を装置の画素 1 つ分動かすことはない。有限でない
32
+ * `cssPx` はそのまま伝わる (`NaN` は `NaN`)。
33
+ *
34
+ * @param cssPx - Offset in CSS px; negative and fractional values included / CSS px のオフセット (負・小数を含む)
35
+ * @param ratio - Device px per CSS px of the window that paints the offset (its `devicePixelRatio`); a finite number > 0 / オフセットを描くウィンドウの CSS px あたりの装置 px (そのウィンドウの `devicePixelRatio`。0 より大きい有限数)
36
+ * @param edge - The edge the snapped offset keeps (see `DevicePixelSnapEdge`) / 揃えたオフセットが守る端 (`DevicePixelSnapEdge` を参照)
37
+ * @returns The snapped offset in CSS px / 揃えたオフセット (CSS px)
38
+ * @throws {RangeError} When `ratio` is not a finite number greater than 0 / `ratio` が 0 より大きい有限数でないとき
39
+ */
40
+ export declare const snapToDevicePixelGrid: (cssPx: number, ratio: number, edge: DevicePixelSnapEdge) => number;
41
+ /**
42
+ * The painting window's device-pixel ratio and the ref callback that confirms that window (see `usePaintingDevicePixelRatio`).
43
+ *
44
+ * 描くウィンドウの装置の画素比と、そのウィンドウを確かめる ref コールバック (`usePaintingDevicePixelRatio` を参照)。
45
+ */
46
+ export type PaintingDevicePixelRatio = {
47
+ /** The ratio, or `null` while no window is known (server rendering and hydration) / 比 (ウィンドウが分からない間 = サーバー描画とハイドレーションは `null`) */
48
+ readonly ratio: number | null;
49
+ /** Ref callback for the translated element / 平行移動する要素の ref コールバック */
50
+ readonly attach: (element: Element | null) => void;
51
+ };
52
+ /**
53
+ * Reads, during render, the device-pixel ratio of the window that paints an element, for snapping the element's translate
54
+ * (`snapToDevicePixelGrid`). Rule: the translate that reaches the screen is always snapped with the ratio of the window
55
+ * that paints the element. Render reads the ratio through `useSyncExternalStore` from the expected painting window — the
56
+ * realm's window (`readRealmWindow`) until the element has attached, since render cannot see the target document. The
57
+ * attach (`attach`, the element's ref callback) confirms it with the element's own window (`windowOf`): when they agree
58
+ * (an element rendered into its own window's document), the first commit is already snapped and nothing is scheduled in
59
+ * the commit phase; when they differ (an iframe or an opened window), the attach switches to that window; the update is
60
+ * scheduled in the commit phase, so React re-renders synchronously before the browser paints. Ratio changes re-render
61
+ * through the store subscription (`subscribeToDevicePixelRatio`), outside the commit phase. The server snapshot is
62
+ * `null`: server HTML and hydration carry the exact offset, replaced by the snapped one right after hydration.
63
+ *
64
+ * 要素の平行移動を揃えるため (`snapToDevicePixelGrid`)、要素を描くウィンドウの装置の画素比を描画の中で読むフック。規則は
65
+ * 「画面へ届く平行移動は、常に要素を描くウィンドウの比で揃っている」。描画は `useSyncExternalStore` で、描くと見込む
66
+ * ウィンドウから比を読む — 描画からは挿入先の文書が見えないので、要素が取り付くまではレルムのウィンドウ
67
+ * (`readRealmWindow`)。取り付け (`attach`。要素の ref コールバック) が要素自身のウィンドウ (`windowOf`) と突き合わせて
68
+ * 確かめ、一致すれば (自分のウィンドウの文書に描いた要素) 最初の確定から揃っていて確定の段では何も予約しない。違えば
69
+ * (iframe・開いたウィンドウ) 取り付けがそのウィンドウへ切り替え、この更新は確定の段で予約されるので、React はブラウザの
70
+ * paint の前に同期で描き直す。比の変化はストアの購読 (`subscribeToDevicePixelRatio`) で確定の段の外から描き直す。
71
+ * サーバーのスナップショットは `null` で、サーバーの HTML とハイドレーションは厳密なオフセットを持ち、ハイドレーションの
72
+ * 直後に揃えた値へ置き換わる。
73
+ *
74
+ * @param part - The element's name for the error, with the owning component (e.g. `"[VirtualScroll] the items wrapper"`) / 誤りに使う要素の名前 (持ち主の部品を含む)
75
+ * @returns The ratio and the ref callback / 比と ref コールバック
76
+ * @throws {Error} When the element attaches to a document without a window (see `windowOf`) / ウィンドウを持たない文書へ取り付いたとき (`windowOf` を参照)
77
+ */
78
+ export declare const usePaintingDevicePixelRatio: (part: string) => PaintingDevicePixelRatio;
79
+ //# sourceMappingURL=devicePixelGrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devicePixelGrid.d.ts","sourceRoot":"","sources":["../src/devicePixelGrid.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAA;AAc1D;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,mBAAmB,KAAG,MAU/F,CAAA;AAgKD;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACnC,kIAAkI;IAClI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;CACrD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,MAAM,KAAG,wBAmC1D,CAAA"}