@aiquants/spreadsheet 0.16.1 → 0.17.1

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.
@@ -25,7 +25,10 @@
25
25
  * byte-identical (sign +1, guide `offsetOf + pendingSize`, both writers). Column autofit
26
26
  * measures the union `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)` (each
27
27
  * filtered by sizeOf > 0 — ADR-21, band counts from a judgment-time `getFrozenSize()` read)
28
- * and the measured-cell budget gate counts band rows.
28
+ * and the measured-cell budget gate counts band rows. v0.17: autofit measures with the cells' base
29
+ * font, read from the body pane (`fontSourceRef`), so the keyboard twin and the imperative all-rows
30
+ * fit (`autofitColumnsInAllRows` — every row of the named columns, no fan-out, gated at
31
+ * maxOperationCells measured cells) work whether the header bands are shown or not.
29
32
  *
30
33
  * ヘッダーリサイズ / unhide 機械 (§7 PT-1)。単一フックが両帯を結線 (§7.4 の機械勘定 = 1)。
31
34
  * 帯へ wire-once の native capture pointerdown を 1 本 (ストリップはリスナーを持たない —
@@ -49,7 +52,10 @@
49
52
  * 即時書込) が予定動く辺 `offsetOf(index) + initialSize − pendingSize` に置く。leading パスは
50
53
  * byte 恒等 (符号 +1、ガイド `offsetOf + pendingSize`、両書き手)。列 autofit の測定行集合は
51
54
  * 和集合 `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)` (各 sizeOf > 0 —
52
- * ADR-21。帯件数は判断時 `getFrozenSize()` 読み)、計測セル予算ゲートは帯行を算入する。
55
+ * ADR-21。帯件数は判断時 `getFrozenSize()` 読み)、計測セル予算ゲートは帯行を算入する。v0.17: autofit はセルの
56
+ * 基本の書体を本体ペイン (`fontSourceRef`) から読むので、キーの双子と命令の全部の行の合わせ
57
+ * (`autofitColumnsInAllRows` — 名指した列の全部の行、ファンアウトなし、測るセルは maxOperationCells まで) は
58
+ * 見出しの帯の有無に依らず働く。
53
59
  */
54
60
 
55
61
  import type { VirtualGridHandle } from "@aiquants/virtualscroll"
@@ -86,6 +92,13 @@ type UseHeaderResizeParams = {
86
92
  enabled: boolean
87
93
  colBandRef: RefObject<HTMLElement | null>
88
94
  rowBandRef: RefObject<HTMLElement | null>
95
+ /**
96
+ * The element whose computed font is the cells' base font (the body pane, the cells' parent): autofit measures with it
97
+ * and its letter and word spacing, so it works whether the header bands are shown or not.
98
+ * 計算済みの書体がセルの基本の書体になる要素 (セルの親の本体ペイン)。autofit はこれの書体と文字・語の間隔で測るので、見出しの
99
+ * 帯の有無に依らない。
100
+ */
101
+ fontSourceRef: RefObject<HTMLElement | null>
89
102
  colAxis: AxisModel
90
103
  rowAxis: AxisModel
91
104
  viewStore: ViewStore
@@ -119,25 +132,25 @@ type UseHeaderResizeParams = {
119
132
  }
120
133
 
121
134
  /**
122
- * The canvas `font` shorthand of a painted format over the band's computed style: italic /
123
- * bold / pt size (× 4/3 px, like cellPaint) / family from the format, the band's values
124
- * otherwise. Interned per format object (the paint intern keeps one object per distinct
135
+ * The canvas `font` shorthand of a painted format over the cells' base computed style (the body
136
+ * pane's): italic / bold / pt size (× 4/3 px, like cellPaint) / family from the format, the base
137
+ * values otherwise. Interned per format object (the paint intern keeps one object per distinct
125
138
  * painted format, so this is one string per distinct font).
126
- * 塗り書式の canvas `font` 短縮形 (帯の computed style の上に italic / bold / pt サイズ (× 4/3 px —
127
- * cellPaint と同式) / フォント族を重ねる)。書式 object 毎に intern (塗り intern が書式毎に 1 object を
128
- * 保つので、異なりフォント毎に 1 文字列)。
139
+ * 塗り書式の canvas `font` 短縮形 (セルの基本の computed style — 本体ペインのもの — の上に italic / bold /
140
+ * pt サイズ (× 4/3 px — cellPaint と同式) / フォント族を重ねる)。書式 object 毎に intern (塗り intern が書式毎に
141
+ * 1 object を保つので、異なりフォント毎に 1 文字列)。
129
142
  */
130
- const fontKeyOf = (painted: CellFormat, fontKeys: WeakMap<CellFormat, string>, bandStyle: Pick<CSSStyleDeclaration, "fontStyle" | "fontWeight" | "fontSize" | "fontFamily">): string => {
143
+ const fontKeyOf = (painted: CellFormat, fontKeys: WeakMap<CellFormat, string>, baseStyle: Pick<CSSStyleDeclaration, "fontStyle" | "fontWeight" | "fontSize" | "fontFamily">): string => {
131
144
  const cached = fontKeys.get(painted)
132
145
  if (cached !== undefined) {
133
146
  return cached
134
147
  }
135
148
  // 真偽値は厳密 true のみ (fail-soft — cellPaint と同じ判定)
136
- const style = painted.italic === true ? "italic" : bandStyle.fontStyle
137
- const weight = painted.bold === true ? "bold" : bandStyle.fontWeight
138
- // pt は cellPaint と同じ × 4/3 で px へ (非有限 / 非正は帯の既定のまま)
139
- const size = typeof painted.fontSize === "number" && Number.isFinite(painted.fontSize) && painted.fontSize > 0 ? `${(painted.fontSize * 4) / 3}px` : bandStyle.fontSize
140
- const family = typeof painted.fontFamily === "string" && painted.fontFamily !== "" ? painted.fontFamily : bandStyle.fontFamily
149
+ const style = painted.italic === true ? "italic" : baseStyle.fontStyle
150
+ const weight = painted.bold === true ? "bold" : baseStyle.fontWeight
151
+ // pt は cellPaint と同じ × 4/3 で px へ (非有限 / 非正は基本の書体の既定のまま)
152
+ const size = typeof painted.fontSize === "number" && Number.isFinite(painted.fontSize) && painted.fontSize > 0 ? `${(painted.fontSize * 4) / 3}px` : baseStyle.fontSize
153
+ const family = typeof painted.fontFamily === "string" && painted.fontFamily !== "" ? painted.fontFamily : baseStyle.fontFamily
141
154
  const font = `${style} ${weight} ${size} ${family}`
142
155
  fontKeys.set(painted, font)
143
156
  return font
@@ -184,6 +197,14 @@ export type HeaderResizeMachine = SelectionEngine & {
184
197
  stepTrack: (axis: "row" | "col", index: number, direction: 1 | -1) => boolean
185
198
  /** Fits column `index` to its content, as the strip double-click does (false when renderCell is set). / 列 `index` を中身に合わせる (ストリップのダブルクリックと同じ。renderCell があれば false)。 */
186
199
  autofitColumn: (index: number) => boolean
200
+ /**
201
+ * Fits the listed columns to the widest text of every row (no fan-out; hidden columns keep their width), gated at
202
+ * maxOperationCells measured cells (false after onOperationRejected; false when renderCell is set or no font source is
203
+ * mounted).
204
+ * 名指した列を全部の行で最も広い文字に合わせる (ファンアウトなし。隠した列は幅を保つ)。測るセルは maxOperationCells まで
205
+ * (超えると onOperationRejected の後に false。renderCell があるか書体の元が未装着なら false)。
206
+ */
207
+ autofitColumnsInAllRows: (columns: readonly number[]) => boolean
187
208
  }
188
209
 
189
210
  /**
@@ -323,44 +344,29 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
323
344
  [collectTargets, applyEntries],
324
345
  )
325
346
 
326
- /** Column autofit (§7.3 / v0.8 §4.2.10 / ADR-21): per-column canvas measurement over the union of both frozen bands and the visible window — `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)`, each filtered by sizeOf > 0 — in each cell's painted font, bucketed by font key. / 列 autofit (§7.3 / v0.8 §4.2.10 / ADR-21): 両凍結帯 + 可視ウィンドウの和集合 `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)` (各 sizeOf > 0) をセルの塗りフォントで計測、フォントキーでバケット化。 */
327
- const autofitColumns = useCallback(
328
- (band: HTMLElement, pressedIndex: number): boolean => {
347
+ /**
348
+ * The measuring core of both autofit entries: fits `targets` to the widest painted text of `measuredRows` (per-column
349
+ * canvas measurement in each cell's painted font over the cells' base font and spacing from fontSourceRef, bucketed by
350
+ * font key),
351
+ * gated at `measureLimit` measured cells. No row to measure, no 2d context (jsdom) or an all-empty column set changes
352
+ * nothing and still counts as a run (true).
353
+ * 両方の autofit の入口が共有する計測の芯。`targets` を `measuredRows` の最も広い塗りの文字に合わせる (fontSourceRef のセルの
354
+ * 基本の書体と間隔の上で、セルごとの塗りの書体で列ごとに canvas で測り、書体の鍵で束ねる)。測るセルは `measureLimit` まで。測る行が無い・
355
+ * 2d の文脈が無い (jsdom)・全部が空の列は何も変えずに走ったものとする (true)。
356
+ *
357
+ * @param targets - The columns to fit. 合わせる列。
358
+ * @param measuredRows - The rows to measure, each with a size above 0. 測る行 (どれも大きさ 0 より大きい)。
359
+ * @param measureLimit - The most measured cells. 測るセルの上限。
360
+ * @param pressedIndex - The pressed track for the §7.2 zero-guard, or null for an imperative fit. §7.2 の 0 化ガードの押下トラック (命令の合わせでは null)。
361
+ * @returns Whether the fit ran (false after a refusal or without a mounted font source). 走ったか (拒んだとき・書体の元が未装着なら false)。
362
+ */
363
+ const fitColumns = useCallback(
364
+ (targets: readonly number[], measuredRows: readonly number[], measureLimit: number, pressedIndex: number | null): boolean => {
329
365
  const p = paramsRef.current
330
- const targets = collectTargets("col", pressedIndex)
331
- if (targets === null) {
366
+ const fontSource = p.fontSourceRef.current
367
+ if (fontSource === null) {
332
368
  return false
333
369
  }
334
- // 帯件数は判断時ハンドル読み (ADR-21 / ADR-19 の判断時規律 — getFrozenSize().rows /
335
- // .trailingRows はエンジンクランプ済み実効値)。装着前 (null) は帯集合なし — 測定集合が
336
- // 窓のみに縮む v0.8 恒等の能力分岐 (値代替フォールバックではない)
337
- const handle = p.handleRef.current
338
- const frozenSize = handle === null ? null : handle.getFrozenSize()
339
- const leadingRows = frozenSize === null ? 0 : frozenSize.rows
340
- const trailingRows = frozenSize === null ? 0 : frozenSize.trailingRows
341
- // 測定行集合 = [0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount) の順序付き
342
- // 和集合 (ADR-21 — v0.9 §4.14)。幅 0 行は計測しない (sizeOf > 0 フィルタ)、重複は Set で
343
- // 去重 (R = T = 0 は窓のみ = v0.8 恒等)
344
- const { rowStart, rowEnd } = p.viewStore.get()
345
- const last = Math.min(rowEnd, p.rowAxis.count - 1)
346
- const measuredRows: number[] = []
347
- const seen = new Set<number>()
348
- const pushRow = (row: number): void => {
349
- if (!seen.has(row) && p.rowAxis.sizeOf(row) > 0) {
350
- seen.add(row)
351
- measuredRows.push(row)
352
- }
353
- }
354
- for (let row = 0; row < leadingRows; row += 1) {
355
- pushRow(row)
356
- }
357
- for (let row = rowStart; row <= last; row += 1) {
358
- pushRow(row)
359
- }
360
- // 末尾帯の開始 = rowCount − T_eff (エンジンクランプ済みのため常に ≥ R_eff ≥ 0 — §1.2)
361
- for (let row = p.rowAxis.count - trailingRows; row < p.rowAxis.count; row += 1) {
362
- pushRow(row)
363
- }
364
370
  // 計測対象の可視行がゼロ (全帯 + 窓が非表示) は no-op — Excel も計測対象
365
371
  // なしでは幅を変えない (0 計測 → 9px 潰しの破壊を作らない。R1(B) 所見)
366
372
  // 測る行が無い / 測る書体が無い / 全空列は「当てるものが無い」実行で、拒否ではない (true)
@@ -368,30 +374,32 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
368
374
  return true
369
375
  }
370
376
  // 上限ゲートは計測セル数単位 (§7.3 — トラック数単位では 16k 列 × 可視 40 行が素通り
371
- // する)。上限は autofit 専用の低い係数 (§13 (e) の設計返却 — 実測根拠は定数 docstring)。
372
- // 帯行も算入する (ADR-21 — measuredRows が帯行を含む)
377
+ // する)。帯行も算入する (ADR-21 — measuredRows が帯行を含む)
373
378
  const measuredCells = targets.length * measuredRows.length
374
- const measureLimit = Math.floor(p.maxOperationCells / AUTOFIT_MEASURE_DIVISOR)
375
379
  if (measuredCells > measureLimit) {
376
380
  p.onOperationRejected?.("resize", measuredCells, "limit")
377
381
  return false
378
382
  }
379
- // canvas 生成 + computed font 取得はジェスチャ 1 回につき 1 度 (§7.3)。font は
383
+ // canvas 生成 + computed font 取得は合わせ 1 回につき 1 度 (§7.3)。font は
380
384
  // ロングハンド合成の単一経路 (Firefox は font ショートハンドの computed 値を空で
381
385
  // 返すため、合成だけが全ブラウザで決定的)
382
386
  const context = document.createElement("canvas").getContext("2d")
383
387
  if (context === null) {
384
388
  return true // 実ブラウザでは常に成立 (jsdom は 2d 未実装 — 計測面は E2E がピン)
385
389
  }
386
- const bandStyle = getComputedStyle(band)
387
- // 既定フォント (書式なしセル) — 帯の computed style のロングハンド合成
388
- const baseFont = `${bandStyle.fontStyle} ${bandStyle.fontWeight} ${bandStyle.fontSize} ${bandStyle.fontFamily}`
390
+ const baseStyle = getComputedStyle(fontSource)
391
+ // 文字の間隔 (読み手のスタイルの上書きを含む。WCAG 1.4.12) も描くとおりに測る。canvas は CSS の間隔を受け継がず、
392
+ // 計算値の normal は間隔 0 のこと
393
+ context.letterSpacing = baseStyle.letterSpacing === "normal" ? "0px" : baseStyle.letterSpacing
394
+ context.wordSpacing = baseStyle.wordSpacing === "normal" ? "0px" : baseStyle.wordSpacing
395
+ // 既定フォント (書式なしセル) — 本体ペインの computed style のロングハンド合成 (セルは本体ペインの書体を継ぐ)
396
+ const baseFont = `${baseStyle.fontStyle} ${baseStyle.fontWeight} ${baseStyle.fontSize} ${baseStyle.fontFamily}`
389
397
  // 見出しの行は書式でなくスタイルシートが太くする — 測る書体もセルと同じ太さにする。スタイルシートが読まれていなければ
390
- // 見出しの行も帯と同じ太さで描かれるので、帯の太さがそのまま実際の描画の値
391
- const headerWeight = bandStyle.getPropertyValue("--_aqsp-header-row-font-weight").trim()
392
- const headerStyle = { fontStyle: bandStyle.fontStyle, fontWeight: headerWeight === "" ? bandStyle.fontWeight : headerWeight, fontSize: bandStyle.fontSize, fontFamily: bandStyle.fontFamily }
398
+ // 見出しの行も本体と同じ太さで描かれるので、本体の太さがそのまま実際の描画の値
399
+ const headerWeight = baseStyle.getPropertyValue("--_aqsp-header-row-font-weight").trim()
400
+ const headerStyle = { fontStyle: baseStyle.fontStyle, fontWeight: headerWeight === "" ? baseStyle.fontWeight : headerWeight, fontSize: baseStyle.fontSize, fontFamily: baseStyle.fontFamily }
393
401
  const headerFont = `${headerStyle.fontStyle} ${headerStyle.fontWeight} ${headerStyle.fontSize} ${headerStyle.fontFamily}`
394
- // CF は幅に効く規則 (bold / italic 設定) と stopIfTrue の障壁だけを 1 ジェスチャ 1 回抽出し列毎に
402
+ // CF は幅に効く規則 (bold / italic 設定) と stopIfTrue の障壁だけを 1 回の合わせで 1 回抽出し列毎に
395
403
  // スライスする (実測 155 → 56 ms)。障壁を残すため走査は塗りと同じ位置で止まり bold / italic が
396
404
  // 厳密一致する。getConditionalFormats は getCellFormat を要する (root がマウント時に保証)
397
405
  const cfRules = p.adapter.getConditionalFormats === undefined ? null : widthRelevantRules(p.adapter.getConditionalFormats())
@@ -411,7 +419,7 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
411
419
  // 塗り書式 (base ⊕ 幅に効く CF) — raw は既読なので thunk は再読しない
412
420
  const painted = p.adapter.getCellFormat === undefined ? undefined : resolvePaintedFormat(p.adapter, colIndex, memo, row, col, () => raw)
413
421
  const isHeaderRow = row < p.headerRows
414
- const font = painted === undefined ? (isHeaderRow ? headerFont : baseFont) : isHeaderRow ? fontKeyOf(painted, headerFontKeys, headerStyle) : fontKeyOf(painted, fontKeys, bandStyle)
422
+ const font = painted === undefined ? (isHeaderRow ? headerFont : baseFont) : isHeaderRow ? fontKeyOf(painted, headerFontKeys, headerStyle) : fontKeyOf(painted, fontKeys, baseStyle)
415
423
  const text = formatCellValue(raw, painted === undefined ? undefined : painted.value)
416
424
  const bucket = buckets.get(font)
417
425
  if (bucket === undefined) {
@@ -446,7 +454,51 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
446
454
  }
447
455
  return applyEntries("col", entries, pressedIndex)
448
456
  },
449
- [collectTargets, applyEntries],
457
+ [applyEntries],
458
+ )
459
+
460
+ /** Column autofit (§7.3 / v0.8 §4.2.10 / ADR-21): per-column canvas measurement over the union of both frozen bands and the visible window — `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)`, each filtered by sizeOf > 0 — in each cell's painted font, bucketed by font key. / 列 autofit (§7.3 / v0.8 §4.2.10 / ADR-21): 両凍結帯 + 可視ウィンドウの和集合 `[0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount)` (各 sizeOf > 0) をセルの塗りフォントで計測、フォントキーでバケット化。 */
461
+ const autofitColumns = useCallback(
462
+ (pressedIndex: number): boolean => {
463
+ const p = paramsRef.current
464
+ const targets = collectTargets("col", pressedIndex)
465
+ if (targets === null) {
466
+ return false
467
+ }
468
+ // 帯件数は判断時ハンドル読み (ADR-21 / ADR-19 の判断時規律 — getFrozenSize().rows /
469
+ // .trailingRows はエンジンクランプ済み実効値)。装着前 (null) は帯集合なし — 測定集合が
470
+ // 窓のみに縮む v0.8 恒等の能力分岐 (値代替フォールバックではない)
471
+ const handle = p.handleRef.current
472
+ const frozenSize = handle === null ? null : handle.getFrozenSize()
473
+ const leadingRows = frozenSize === null ? 0 : frozenSize.rows
474
+ const trailingRows = frozenSize === null ? 0 : frozenSize.trailingRows
475
+ // 測定行集合 = [0, R_eff) ∪ [rowStart, rowEnd] ∪ [rowCount − T_eff, rowCount) の順序付き
476
+ // 和集合 (ADR-21 — v0.9 §4.14)。幅 0 行は計測しない (sizeOf > 0 フィルタ)、重複は Set で
477
+ // 去重 (R = T = 0 は窓のみ = v0.8 恒等)
478
+ const { rowStart, rowEnd } = p.viewStore.get()
479
+ const last = Math.min(rowEnd, p.rowAxis.count - 1)
480
+ const measuredRows: number[] = []
481
+ const seen = new Set<number>()
482
+ const pushRow = (row: number): void => {
483
+ if (!seen.has(row) && p.rowAxis.sizeOf(row) > 0) {
484
+ seen.add(row)
485
+ measuredRows.push(row)
486
+ }
487
+ }
488
+ for (let row = 0; row < leadingRows; row += 1) {
489
+ pushRow(row)
490
+ }
491
+ for (let row = rowStart; row <= last; row += 1) {
492
+ pushRow(row)
493
+ }
494
+ // 末尾帯の開始 = rowCount − T_eff (エンジンクランプ済みのため常に ≥ R_eff ≥ 0 — §1.2)
495
+ for (let row = p.rowAxis.count - trailingRows; row < p.rowAxis.count; row += 1) {
496
+ pushRow(row)
497
+ }
498
+ // 上限は autofit 専用の低い係数 (§13 (e) の設計返却 — 実測根拠は定数 docstring)。帯行も算入する (ADR-21)
499
+ return fitColumns(targets, measuredRows, Math.floor(p.maxOperationCells / AUTOFIT_MEASURE_DIVISOR), pressedIndex)
500
+ },
501
+ [collectTargets, fitColumns],
450
502
  )
451
503
 
452
504
  const stepTrack = useCallback(
@@ -473,20 +525,42 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
473
525
  const autofitColumn = useCallback(
474
526
  (index: number): boolean => {
475
527
  const p = paramsRef.current
476
- const band = p.colBandRef.current
477
- // renderCell のカスタム DOM は measureText で測れない (帯のダブルクリックと同じ逸脱) — 帯の未装着は測る書体が無い
478
- if (!p.autofitEnabled || band === null) {
528
+ // renderCell のカスタム DOM は measureText で測れない (帯のダブルクリックと同じ逸脱)。書体の元の未装着は芯が false を返す
529
+ if (!p.autofitEnabled) {
479
530
  return false
480
531
  }
481
532
  // 隠れた列は隠れたまま (戻すのは再表示だけ) — 走ったが何も変えない
482
533
  if (p.colAxis.sizeOf(index) === 0) {
483
534
  return true
484
535
  }
485
- return autofitColumns(band, index)
536
+ return autofitColumns(index)
486
537
  },
487
538
  [autofitColumns],
488
539
  )
489
540
 
541
+ const autofitColumnsInAllRows = useCallback(
542
+ (columns: readonly number[]): boolean => {
543
+ const p = paramsRef.current
544
+ if (!p.autofitEnabled) {
545
+ return false
546
+ }
547
+ // 隠れた列は隠れたまま (戻すのは再表示だけ)。重複は 1 回
548
+ const targets = [...new Set(columns)].filter((col) => p.colAxis.sizeOf(col) > 0)
549
+ if (targets.length === 0) {
550
+ return true
551
+ }
552
+ const measuredRows: number[] = []
553
+ for (let row = 0; row < p.rowAxis.count; row += 1) {
554
+ if (p.rowAxis.sizeOf(row) > 0) {
555
+ measuredRows.push(row)
556
+ }
557
+ }
558
+ // ホストが一度だけ呼ぶ合わせなので、上限は操作の予算そのもの (画面の操作の 1/4 の係数は打鍵ごとの応答のためのもの)
559
+ return fitColumns(targets, measuredRows, p.maxOperationCells, null)
560
+ },
561
+ [fitColumns],
562
+ )
563
+
490
564
  const { enabled, colBandRef, rowBandRef } = params
491
565
  useEffect(() => {
492
566
  const colBand = colBandRef.current
@@ -680,7 +754,7 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
680
754
  }
681
755
  return
682
756
  }
683
- autofitColumns(band, hit.index)
757
+ autofitColumns(hit.index)
684
758
  }
685
759
 
686
760
  const onLostPointerCapture = (event: PointerEvent) => {
@@ -717,6 +791,7 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
717
791
  () => ({
718
792
  stepTrack,
719
793
  autofitColumn,
794
+ autofitColumnsInAllRows,
720
795
  isDragging: () => draggingRef.current,
721
796
  // リサイズ / unhide は選択矩形を配送しない — 配送モードは常に加算
722
797
  getDragMode: (): "add" | "subtract" | "point" => "add",
@@ -728,6 +803,6 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
728
803
  },
729
804
  cancelDrag: cleanupDrag,
730
805
  }),
731
- [cleanupDrag, stepTrack, autofitColumn],
806
+ [cleanupDrag, stepTrack, autofitColumn, autofitColumnsInAllRows],
732
807
  )
733
808
  }
package/src/index.ts CHANGED
@@ -122,5 +122,5 @@ export { NoteTip, type NoteTipProps } from "./popover/NoteTip.tsx"
122
122
  // PopoverContext.anchorRect の型 (層座標系の矩形) — 配置エンジン placePopover 本体は非公開のまま
123
123
  export type { PopoverRect } from "./popover/placement.ts"
124
124
  export type { CommentPopoverContext, LinkPopoverContext, ListPopoverContext, MessagePopoverContext, NotePopoverContext, NoteTipContext, PopoverContext, PopoverKind, PopoverOverrides } from "./popover/usePopovers.ts"
125
- export { DEFAULT_CUSTOM_COLORS, type ScrollToCellOptions, Spreadsheet, type SpreadsheetHandle, type SpreadsheetProps } from "./Spreadsheet.tsx"
125
+ export { DEFAULT_CUSTOM_COLORS, type ScrollToCellOptions, Spreadsheet, type SpreadsheetContentSize, type SpreadsheetHandle, type SpreadsheetProps } from "./Spreadsheet.tsx"
126
126
  export type { SelectionState } from "./selection/selectionState.ts"
@@ -120,6 +120,12 @@ type UseGridKeyboardParams = {
120
120
  setSelection: (next: SelectionState) => void
121
121
  moveActive: (input: MoveActiveInput) => void
122
122
  ensureCellVisible: (cell: CellCoord) => void
123
+ /**
124
+ * The height a page move travels, in logical px, or -1 while unmeasured (v0.17.1): the grid's viewport cut to the part
125
+ * of the body the page shows, so a grid taller than its page pages by a screenful. / ページ移動が進む高さ (論理 px。未計測は
126
+ * -1。v0.17.1)。グリッドの表示域をページが見せる本体の部分で切り詰めたもので、ページより高いグリッドも 1 画面ずつ進む。
127
+ */
128
+ pageExtent: () => number
123
129
  isEditing: () => boolean
124
130
  requestCommit: () => boolean
125
131
  startEdit: (mode: "edit" | "replace") => void
@@ -390,13 +396,15 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
390
396
  * approximation replaced by Fenwick geometry; O(log n)). The base is the MOVING
391
397
  * endpoint: active for reset moves, the extension corner for Shift+Page (an active
392
398
  * base would mis-land on tall selections AND identity-bail the 2nd keystroke). The
393
- * landing is structurally visible (indexAt skips zero-size tracks — §5.2).
399
+ * landing is structurally visible (indexAt skips zero-size tracks — §5.2). The travel is
400
+ * `pageExtent` (v0.17.1): the viewport cut to the part of the body the page shows.
394
401
  * 基点行からの正確なページ移動先 (§9 — v0.1 の一様割り近似を Fenwick 幾何へ置換)。
395
402
  * 基点は移動する端点 (reset = active、Shift 系 = 伸長隅)。着地は構造的に可視 (§5.2)。
403
+ * 進む高さは `pageExtent` (v0.17.1。表示域をページが見せる本体の部分で切り詰めたもの)。
396
404
  */
397
405
  const pageTargetRow = (baseRow: number, direction: "up" | "down"): number => {
398
406
  const p = paramsRef.current
399
- const viewportH = handleRef.current?.getViewportSize().height ?? -1
407
+ const viewportH = p.pageExtent()
400
408
  if (viewportH <= 0) {
401
409
  // ペイン未計測 (番兵 -1 / 高さ 0) はページ幾何が定義できない — 可視 1 歩へ縮退
402
410
  return stepVisible(p.rowAxis, baseRow, direction === "down" ? 1 : -1)
@@ -111,6 +111,28 @@
111
111
  width: 100%;
112
112
  height: 100%;
113
113
  transform-origin: 0 0;
114
+ /* 包みの中の倍率 (倍率が 1 でないときは部品がインラインの style で上書きする)。包みの中で縮む線の太さを見た目で保つために読む */
115
+ --_aqsp-zoom: 1;
116
+ }
117
+
118
+ /* 見出し (列の記号・行の番号・角) を出さないグリッド (headings={false}): 格子の 2 本の帯を 0 にし、本体を根の左上から始める */
119
+ .aqsp-root[data-aqsp-headings-hidden] .aqsp-zoom {
120
+ grid-template-columns: 0 minmax(0, 1fr);
121
+ grid-template-rows: 0 minmax(0, 1fr);
122
+ }
123
+
124
+ /*
125
+ * キーの移動で選んだセルをページの中で見せる印 (位置と大きさは revealCellInPage が書く)。根の直下でズームの包みの外に置き、見えず
126
+ * 押せない。scrollIntoView は可視性に依らず箱の位置へスクロールする
127
+ */
128
+ .aqsp-reveal {
129
+ position: absolute;
130
+ top: 0;
131
+ left: 0;
132
+ width: 0;
133
+ height: 0;
134
+ pointer-events: none;
135
+ visibility: hidden;
114
136
  }
115
137
 
116
138
  .aqsp-corner {
@@ -365,11 +387,19 @@
365
387
  mix-blend-mode: multiply;
366
388
  }
367
389
 
390
+ /*
391
+ * 選んだセルの枠 (キーボードの焦点の見え方。WCAG 2.4.13): ズームの包みの中で倍率ごと縮むため、太さを倍率で割り、整数の px へ
392
+ * 切り上げる。ブラウザは border の太さを整数の px へ切り捨てるので、割っただけでは 3 px を下回る段がある (2 倍で 1 px = 見た目 2 px)。
393
+ * 見た目の太さは 3 CSS px 以上・3 + 倍率 未満。セルの内側の 3 px の帯の面積 6(W + H) − 36 は、焦点の無いセルの 2 px の周の面積
394
+ * 4(W + H) + 16 を W + H ≥ 26 で上回り (倍率 25 % の 25 × 6 px のセルでも 150 ≥ 140)、帯が太くても面積は減らない。round() を
395
+ * 解さないブラウザでは太さの宣言が無効になり、初期値の 3 px (倍率ごと縮む) に戻る
396
+ */
368
397
  .aqsp-active-frame {
369
398
  position: absolute;
370
399
  top: 0;
371
400
  left: 0;
372
- border: 2px solid var(--_aqsp-accent);
401
+ border: 3px solid var(--_aqsp-accent);
402
+ border-width: round(up, calc(3px / var(--_aqsp-zoom)), 1px);
373
403
  box-sizing: border-box;
374
404
  }
375
405
 
@@ -1102,7 +1132,7 @@
1102
1132
  * v0.9 凍結分割線 (計画 §2.4 — ADR-20 / ADR-24): 全凍結境界の強い Excel / Sheets 風の線。
1103
1133
  * consumer 面は CSS 変数 2 つだけ (--aqsp-divider-color / --aqsp-divider-width — パッケージは
1104
1134
  * 読むだけで書き手は consumer スタイルシート単独。色の既定は .aqsp-root の別名 --_aqsp-divider-color が 1 度だけ書く)。
1105
- * 既定は 2px の #9ca3af (gray-400 — 既存全罫線より 1 段濃い)。width 0px は逃げ道 — 象限別 fill 断片の継ぎ目が再露出し forced-colors も
1135
+ * 既定は 2px の #858e9d (面と見出しの帯の両方に 3:1 — WCAG 1.4.11)。width 0px は逃げ道 — 象限別 fill 断片の継ぎ目が再露出し forced-colors も
1106
1136
  * 無描画 (意図的、README / 分冊 05 §8 登記)。位置 (leading 縁 0 / trailing 縁 0) と長さは
1107
1137
  * 各セグメントの静的インライン幾何 + ホストクリップが供給し、このブロックは太さと色だけを持つ。
1108
1138
  * pointer-events: none — バーは不活性で、リサイズの operand は帯側隣接ストリップ (ADR-20)。