@aiquants/spreadsheet 0.17.1 → 0.17.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.
@@ -93,10 +93,11 @@ type UseHeaderResizeParams = {
93
93
  colBandRef: RefObject<HTMLElement | null>
94
94
  rowBandRef: RefObject<HTMLElement | null>
95
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
- * 帯の有無に依らない。
96
+ * The element whose computed font is the cells' base font (the body pane, the cells' parent): autofit measures with it,
97
+ * and with the letter and word spacing a hidden sample inside it computes for each measured font, so it works whether the
98
+ * header bands are shown or not.
99
+ * 計算済みの書体がセルの基本の書体になる要素 (セルの親の本体ペイン)。autofit はこれの書体と、この中の見えない見本が測る書体ごとに
100
+ * 計算する文字・語の間隔で測るので、見出しの帯の有無に依らない。
100
101
  */
101
102
  fontSourceRef: RefObject<HTMLElement | null>
102
103
  colAxis: AxisModel
@@ -346,12 +347,13 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
346
347
 
347
348
  /**
348
349
  * 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),
350
+ * canvas measurement in each cell's painted font over the cells' base font from fontSourceRef, bucketed by font key, with
351
+ * the letter and word spacing a hidden sample inside fontSourceRef computes for the bucket's font),
351
352
  * gated at `measureLimit` measured cells. No row to measure, no 2d context (jsdom) or an all-empty column set changes
352
353
  * nothing and still counts as a run (true).
353
354
  * 両方の autofit の入口が共有する計測の芯。`targets` を `measuredRows` の最も広い塗りの文字に合わせる (fontSourceRef のセルの
354
- * 基本の書体と間隔の上で、セルごとの塗りの書体で列ごとに canvas で測り、書体の鍵で束ねる)。測るセルは `measureLimit` まで。測る行が無い・
355
+ * 基本の書体の上で、セルごとの塗りの書体で列ごとに canvas で測り、書体の鍵で束ねる。文字・語の間隔は fontSourceRef の中の見えない
356
+ * 見本がバケットの書体で計算する値)。測るセルは `measureLimit` まで。測る行が無い・
355
357
  * 2d の文脈が無い (jsdom)・全部が空の列は何も変えずに走ったものとする (true)。
356
358
  *
357
359
  * @param targets - The columns to fit. 合わせる列。
@@ -388,10 +390,6 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
388
390
  return true // 実ブラウザでは常に成立 (jsdom は 2d 未実装 — 計測面は E2E がピン)
389
391
  }
390
392
  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
393
  // 既定フォント (書式なしセル) — 本体ペインの computed style のロングハンド合成 (セルは本体ペインの書体を継ぐ)
396
394
  const baseFont = `${baseStyle.fontStyle} ${baseStyle.fontWeight} ${baseStyle.fontSize} ${baseStyle.fontFamily}`
397
395
  // 見出しの行は書式でなくスタイルシートが太くする — 測る書体もセルと同じ太さにする。スタイルシートが読まれていなければ
@@ -429,10 +427,21 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
429
427
  }
430
428
  }
431
429
  }
432
- // バケット毎にフォントを 1 回設定して計測 (E2E は ctx.font 代入回数 ≤ 異なりフォント数 + 1 を数える)
430
+ // バケット毎にフォントを 1 回設定して計測 (E2E は ctx.font 代入回数 ≤ 異なりフォント数 + 1 を数える)。文字の間隔 (読み手の
431
+ // スタイルの上書きを含む。WCAG 1.4.12) も描くとおりに測る: canvas は CSS の間隔を受け継がず、上書きはふつう em で書かれて書体の
432
+ // 大きさに比例するため、本体ペインの中でバケットの書体を当てた見えない見本の計算値を読む (計算値の normal は間隔 0)
433
+ const probe = fontSource.ownerDocument.createElement("span")
434
+ probe.setAttribute("aria-hidden", "true")
435
+ probe.style.position = "absolute"
436
+ probe.style.visibility = "hidden"
437
+ fontSource.append(probe)
433
438
  const widestByCol = new Map<number, number>()
434
439
  for (const [font, cells] of buckets) {
435
440
  context.font = font
441
+ probe.style.font = font
442
+ const spacing = getComputedStyle(probe)
443
+ context.letterSpacing = spacing.letterSpacing === "normal" ? "0px" : spacing.letterSpacing
444
+ context.wordSpacing = spacing.wordSpacing === "normal" ? "0px" : spacing.wordSpacing
436
445
  for (const cell of cells) {
437
446
  const width = context.measureText(cell.text).width
438
447
  const widest = widestByCol.get(cell.col)
@@ -441,6 +450,7 @@ export const useHeaderResize = (params: UseHeaderResizeParams): HeaderResizeMach
441
450
  }
442
451
  }
443
452
  }
453
+ probe.remove()
444
454
  const entries: ResizeEntry[] = []
445
455
  for (const col of targets) {
446
456
  const widest = widestByCol.get(col)
@@ -122,8 +122,8 @@ type UseGridKeyboardParams = {
122
122
  ensureCellVisible: (cell: CellCoord) => void
123
123
  /**
124
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 画面ずつ進む。
125
+ * of the body the reader sees, so a grid taller than its page pages by a screenful. / ページ移動が進む高さ (論理 px。未計測は
126
+ * -1。v0.17.1)。グリッドの表示域を読み手に見えている本体の部分で切り詰めたもので、ページより高いグリッドも 1 画面ずつ進む。
127
127
  */
128
128
  pageExtent: () => number
129
129
  isEditing: () => boolean
@@ -397,10 +397,12 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
397
397
  * endpoint: active for reset moves, the extension corner for Shift+Page (an active
398
398
  * base would mis-land on tall selections AND identity-bail the 2nd keystroke). The
399
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.
400
+ * `pageExtent` (v0.17.1): the viewport cut to the part of the body the reader sees. A travel
401
+ * shorter than the base row (a tall row, a body barely seen) still moves one visible row (v0.17.2).
401
402
  * 基点行からの正確なページ移動先 (§9 — v0.1 の一様割り近似を Fenwick 幾何へ置換)。
402
403
  * 基点は移動する端点 (reset = active、Shift 系 = 伸長隅)。着地は構造的に可視 (§5.2)。
403
- * 進む高さは `pageExtent` (v0.17.1。表示域をページが見せる本体の部分で切り詰めたもの)。
404
+ * 進む高さは `pageExtent` (v0.17.1。表示域を読み手に見えている本体の部分で切り詰めたもの)。
405
+ * 基点の行より短い移動量 (高い行・わずかしか見えない本体) でも見える 1 行は進む (v0.17.2)。
404
406
  */
405
407
  const pageTargetRow = (baseRow: number, direction: "up" | "down"): number => {
406
408
  const p = paramsRef.current
@@ -410,7 +412,9 @@ export const useGridKeyboard = (params: UseGridKeyboardParams): void => {
410
412
  return stepVisible(p.rowAxis, baseRow, direction === "down" ? 1 : -1)
411
413
  }
412
414
  // indexAt は入力を [0, totalSize) へ内部クランプする — 端超過は最初 / 最後の可視行に解決
413
- return p.rowAxis.indexAt(p.rowAxis.offsetOf(baseRow) + (direction === "down" ? viewportH : -viewportH))
415
+ const target = p.rowAxis.indexAt(p.rowAxis.offsetOf(baseRow) + (direction === "down" ? viewportH : -viewportH))
416
+ // 下への移動量が基点の行の高さに届かないと着地は基点のまま — 押したキーが何もしないことにせず、見える 1 歩を進む
417
+ return target === baseRow ? stepVisible(p.rowAxis, baseRow, direction === "down" ? 1 : -1) : target
414
418
  }
415
419
 
416
420
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: §6.6.1 キーマップ表を 1 枚の平坦 dispatch として写経した契約実装 — 表の行 = コードの分岐を 1:1 で保つことが監査可能性の根拠であり、キー別関数へ分割すると表との突合が壊れる (ADR-9: 表が契約)
@@ -1132,7 +1132,7 @@
1132
1132
  * v0.9 凍結分割線 (計画 §2.4 — ADR-20 / ADR-24): 全凍結境界の強い Excel / Sheets 風の線。
1133
1133
  * consumer 面は CSS 変数 2 つだけ (--aqsp-divider-color / --aqsp-divider-width — パッケージは
1134
1134
  * 読むだけで書き手は consumer スタイルシート単独。色の既定は .aqsp-root の別名 --_aqsp-divider-color が 1 度だけ書く)。
1135
- * 既定は 2px の #858e9d (面と見出しの帯の両方に 3:1 — WCAG 1.4.11)。width 0px は逃げ道 — 象限別 fill 断片の継ぎ目が再露出し forced-colors も
1135
+ * 既定は 2px の #858e9d (面と見出しの帯の両方に 3:1 — WCAG 1.4.11。太さはどの倍率でも画面の上で変数の値以上 — 下の規則)。width 0px は逃げ道 — 象限別 fill 断片の継ぎ目が再露出し forced-colors も
1136
1136
  * 無描画 (意図的、README / 分冊 05 §8 登記)。位置 (leading 縁 0 / trailing 縁 0) と長さは
1137
1137
  * 各セグメントの静的インライン幾何 + ホストクリップが供給し、このブロックは太さと色だけを持つ。
1138
1138
  * pointer-events: none — バーは不活性で、リサイズの operand は帯側隣接ストリップ (ADR-20)。
@@ -1143,7 +1143,14 @@
1143
1143
  pointer-events: none;
1144
1144
  }
1145
1145
 
1146
- /* 縦線 (x 境界) は太さ = width、横線 (y 境界) は太さ = height (共有変数 1 本) */
1146
+ /*
1147
+ * 縦線 (x 境界) は太さ = width、横線 (y 境界) は太さ = height (共有変数 1 本)。ズームの包みが線ごと縮めるため、round() を
1148
+ * 解するブラウザでは太さを倍率で割って整数の px へ切り上げ、画面の上の太さを保つ (Excel / Sheets の分割線と同じく倍率に依らない)。
1149
+ * Chromium は箱の両端を包みの座標の整数の px へ寄せて塗るので、割っただけの端数の太さは置かれた位置で切り捨てか切り上げに化ける
1150
+ * (実測: 110 % で 1.1〜2.2 px)。整数の太さはどの位置でも同じに塗られ、見た目は変数の値以上・変数の値 + 倍率未満。round() の
1151
+ * 宣言は var() を含むため解さないブラウザでも構文の段では捨てられず、計算値の段で初期値 auto (幅 0) に化ける。それを避けて
1152
+ * @supports の中に置き、解さないブラウザは論理の px のまま (倍率ごと縮む) にする
1153
+ */
1147
1154
  .aqsp-freeze-divider-v {
1148
1155
  width: var(--aqsp-divider-width, 2px);
1149
1156
  }
@@ -1152,6 +1159,16 @@
1152
1159
  height: var(--aqsp-divider-width, 2px);
1153
1160
  }
1154
1161
 
1162
+ @supports (width: round(up, 1px, 1px)) {
1163
+ .aqsp-freeze-divider-v {
1164
+ width: round(up, calc(var(--aqsp-divider-width, 2px) / var(--_aqsp-zoom)), 1px);
1165
+ }
1166
+
1167
+ .aqsp-freeze-divider-h {
1168
+ height: round(up, calc(var(--aqsp-divider-width, 2px) / var(--_aqsp-zoom)), 1px);
1169
+ }
1170
+ }
1171
+
1155
1172
  /* forced-colors: 不透明な実線は再着色で生存する — CanvasText へ寄せるだけ (§2.4。凍結クリップの
1156
1173
  無装飾免除とは別物で、分割線は自前の規則を持つ) */
1157
1174
  @media (forced-colors: active) {